Gdb,如何使用打印?

时间:2014-09-27 00:21:55

标签: debugging gdb sparc

有人可以解释这个"还要打印出程序中关键点的特定寄存器(使用p)的内容,以表明它正在按预期工作。 &#34 ;? 我试过(gdb)p,但我一直得到"历史是空的

  

(gdb)ni

     

0x000106d0 in loop()

     

1:x / i $ pc

     

0x106d0:调用0x2089c< .mul @ plt>

     

0x106d4:mov%l1,%o1

     

(gdb)p

     

历史是空的。

1 个答案:

答案 0 :(得分: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.
  

//此命令将提供有关所有寄存器的信息

(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
  

//现在我们可以使用“p”命令打印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)