2014-09-27 94 views
0

有人可以解释这个“也打印出你的程序中的关键点的特定寄存器的内容(使用p),以表明它正在按预期工作。”? 我试过(GDB)p,但我不断收到“历史是空Gdb,如何使用打印?

(GDB)NI

环路0x000106d0()

1:X/I $ PC

0x106d0:致电0x2089c < .mul @ PLT>

0x106d4:MOV%L1,01%

(gdb)p

历史记录为空。

回答

1
$ gdb -q ./output 
(gdb) break main 
Breakpoint 1 at 0x400846: file test_lambda.cpp, line 11. 
(gdb) run 
Starting program: /home/mantosh/practice/notesofprogramming/gcc4.9/output 
[Thread debugging using libthread_db enabled] 
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". 

Breakpoint 1, main() at test_lambda.cpp:11 
11  foo(); 

//每当你只需要输入命令 “P”,它会检查上次使用的命令 。正如我们 不使用“P”随时在我们这个特定的程序调试会话,它显示了 消息“历史记录为空” //

(gdb) p 
The history is empty. 

//此命令将给予信息使用 “p” 命令所有寄存器

(gdb) info registers 
rax   0x7ffff73a3548 140737341175112 
rbx   0x0 0 
rcx   0x60 96 
rdx   0x7fffffffe1b8 140737488347576 
rsi   0x7fffffffe1a8 140737488347560 
rdi   0x1 1 
rbp   0x7fffffffe0c0 0x7fffffffe0c0 
rsp   0x7fffffffe0c0 0x7fffffffe0c0 
r8    0x7ffff7dd8240 140737351877184 
r9    0x7ffff7dbddb0 140737351769520 
r10   0x7fffffffddf0 140737488346608 
r11   0x7ffff7023880 140737337505920 
r12   0x4006f0 4196080 
r13   0x7fffffffe1a0 140737488347552 
r14   0x0 0 
r15   0x0 0 
rip   0x400846 0x400846 <main()+4> 
eflags   0x246 [ PF ZF IF ] 
cs    0x33 51 
ss    0x2b 43 
ds    0x0 0 
es    0x0 0 
fs    0x0 0 
gs    0x0 0 

//现在我们可以打印RIP(指令指针)。 在此之后,如果我们 继续调试我们的程序,我们只需键入“p”,它将打印“rip” ,因为这是在调试过程中上次在命令“p”中传递的参数。

(gdb) p $rip 
$1 = (void (*)(void)) 0x400846 <main()+4> 
(gdb) step 
foo() at test_lambda.cpp:4 
4  int x = 10; 
(gdb) p 
$2 = (void (*)(void)) 0x400846 <main()+4> 
(gdb) step 
5  int y= 20; 
(gdb) p 
$3 = (void (*)(void)) 0x400846 <main()+4> 
(gdb) n 
6  x = x + y; 
(gdb) p 
$4 = (void (*)(void)) 0x400846 <main()+4> 
(gdb) n 
7  std::cout<<x<<std::endl; 
(gdb) p 
$5 = (void (*)(void)) 0x400846 <main()+4> 
(gdb) c 
Continuing. 
30 
[Inferior 1 (process 3226) exited normally] 
(gdb)