(gdb) b 8 Breakpoint 1 at 0x40158a: file test.cpp, line 8. (gdb) r Starting program: D:\Desktop\test\test.exe [New Thread 9208.0x1860] [New Thread 9208.0x2f0c] [New Thread 9208.0x299c] [New Thread 9208.0x1bdc]
Thread 1 hit Breakpoint 1, main () at test.cpp:8 8 show(); (gdb) bt #0 main () at test.cpp:8 (gdb) info r rip rip 0x40158a 0x40158a <main()+13> (gdb) info r rsp rsp 0x61fe00 0x61fe00 (gdb) info r rbp rbp 0x61fe20 0x61fe20 (gdb)
(gdb) x /x $rip 0x40158a <main()+13>: 0xffffc1e8 (gdb) x /x $rbp 0x61fe20: 0x00621960 (gdb) x /x $rsp 0x61fe00: 0x00000008
和上面的info得到的信息没多大区别,然后进行函数调用,step进入函数:
1 2 3 4 5 6 7 8 9 10 11 12
(gdb) step show () at test.cpp:3 3 void show(){ (gdb) bt #0 show () at test.cpp:3 #1 0x000000000040158f in main () at test.cpp:8 (gdb) info r rip rip 0x401550 0x401550 <show()> (gdb) x /x $rbp 0x61fe20: 0x0000000000621960 (gdb) x /x $rsp 0x61fdf8: 0x000000000040158f
(gdb) next [New Thread 9208.0x1260] Hello, world. 5 } (gdb) next main () at test.cpp:9 9 return 0; (gdb) info r rip rip 0x40158f 0x40158f <main()+18> (gdb) info r rbp rbp 0x61fe20 0x61fe20 (gdb) info r rsp rsp 0x61fe00 0x61fe00 (gdb)
(gdb) b 9 Breakpoint 1 at 0x4015a4: file test.cpp, line 9. (gdb) r Starting program: D:\Desktop\test\test.exe [New Thread 5704.0x19fc] [New Thread 5704.0x3f6c] [New Thread 5704.0x1020] [New Thread 5704.0x4d1c]
Thread 1 hit Breakpoint 1, main () at test.cpp:9 9 show("Jack"); (gdb) frame #0 main () at test.cpp:9 9 show("Jack"); (gdb) step show (name="Jack") at test.cpp:5 5 std::cout << "Hello, " << name << std::endl; (gdb) frame #0 show (name="Jack") at test.cpp:5 5 std::cout << "Hello, " << name << std::endl; (gdb) info args name = "Jack" (gdb) info locals No locals. (gdb)
(gdb) frame #0 main () at test.cpp:10 10 show(name); (gdb) info locals name = "Jack" (gdb) step show (name="Jack") at test.cpp:5 5 std::cout << "Hello, " << name << std::endl; (gdb) info args name = "Jack" (gdb) info locals No locals. (gdb)
Thread 1 hit Breakpoint 1, main () at test.cpp:10 10 show(name); (gdb) info locals name = "Jack" (gdb) step show (name="Jack") at test.cpp:5 5 std::cout << "Hello, " << name << std::endl; (gdb) info args name = "Jack" (gdb) info locals No locals. (gdb)
PS D:\Desktop\test> gcc -c test.c -o test.o PS D:\Desktop\test> nm test.o 0000000000000000 b .bss 0000000000000000 d .data 0000000000000000 p .pdata 0000000000000000 r .rdata$zzz 0000000000000000 t .text 0000000000000000 r .xdata U __main 0000000000000002 T main 0000000000000000 T show PS D:\Desktop\test>
PS D:\Desktop\test> nm test.o 0000000000000000 b .bss 0000000000000000 d .ctors 0000000000000000 d .data 0000000000000000 p .pdata 0000000000000000 r .rdata 0000000000000000 r .rdata$zzz 0000000000000000 t .text 0000000000000000 r .xdata U __main 000000000000001a t __tcf_0 0000000000000071 t _GLOBAL__sub_I__Z4showv 0000000000000035 t _Z41__static_initialization_and_destruction_0ii 0000000000000000 T _Z4showv U _ZNSt8ios_base4InitC1Ev U _ZNSt8ios_base4InitD1Ev 0000000000000000 r _ZStL19piecewise_construct 0000000000000000 b _ZStL8__ioinit U atexit 0000000000000002 T main PS D:\Desktop\test>
PS D:\Desktop\test> g++ -c test.cpp -o test.o PS D:\Desktop\test> nm test.o | findstr show 0000000000000000 p .pdata$_ZN1A5show4Ev 0000000000000000 t .text$_ZN1A5show4Ev 0000000000000000 r .xdata$_ZN1A5show4Ev 0000000000000089 t _GLOBAL__sub_I__Z5show1v 0000000000000000 T _Z5show1v 0000000000000002 T _Z5show2i 0000000000000000 T _ZN1A5show4Ev 000000000000000c T _ZN2nb5show3Ev PS D:\Desktop\test> c++filt.exe _ZN1A5show4Ev A::show4()
(gdb) b 10 Breakpoint 1 at 0x40155d: file test.cpp, line 10. (gdb) r Starting program: D:\Desktop\test\test.exe [New Thread 15048.0x4d34] [New Thread 15048.0x83c] [New Thread 15048.0x4d90] [New Thread 15048.0x3644]
Thread 1 hit Breakpoint 1, main () at test.cpp:10 10 a.show4(); (gdb) info locals a = {<No data fields>} (gdb) print a $1 = {<No data fields>} (gdb) step A::show4 (this=0x8) at test.cpp:5 5 void show4(){} (gdb) bt #0 A::show4 (this=0x8) at test.cpp:5 #1 0x0000000000401569 in main () at test.cpp:10 (gdb) info locals No locals. (gdb) info args this = 0x8 (gdb)
(gdb) print A::a $1 = 0 (gdb) info locals No frame selected. (gdb) b 12 Breakpoint 1 at 0x40155d: file test.cpp, line 12. (gdb) r Starting program: D:\Desktop\test\test.exe [New Thread 14800.0xe24] [New Thread 14800.0x4c40] [New Thread 14800.0x27a8] [New Thread 14800.0x208c]
Thread 1 hit Breakpoint 1, main () at test.cpp:12 12 A::set(); (gdb) info locals No locals. (gdb) step A::set () at test.cpp:6 6 static void set(){a = 10;} (gdb) info args No arguments. (gdb) info locals No locals. (gdb) print a $2 = 0 (gdb) next main () at test.cpp:13 13 return 0;