GDB User Book


本文最后更新于:2017年10月18日 晚上

G++

g++ -o [Output program name] [CPP Source file] -g -Wall -Wl,--stack=128000

$For​$ $example:​$

g++ -o a a.cpp -g -Wall -Wl,stack=128000

$Or:$

g++ [CPP Source file] -o [Output program name] -g -Wall -Wl,--stack=128000

If you want to use $gdb$ ,-g must be added.

GDB

Input

$Use:$

gdb [Output program name]

To load your program that will be debugged.

When you in $gdb$ and your program won’t be loaded because you may give a wrong name or other reasons.You can use it in $gdb$.

(gdb) file [Output program name]

Breakpoints

When $gdb$ load your program succesfully,you can make $breakpoints$.

$Use:$

(gdb) breakpoints [Line number]

To make it Simpler,you can use:

(gdb) b [Line number]

$Also:$

(gdb) b [Function name]

$For$ $example:$

(gdb) b dfs

If you want your program stop when some conditions are true.Use:

(gdb) b 23 if cnt == 223

Debugging

When you have set breakpoints,Use run to start your program:

(gdb) r

When program stop at a breakpoint,you can usenext:

(gdb) n

To run your program step by step,but it won’t go into function that you call.

If you want to go into function that you call,use step:

(gdb) s

If you don’t want to run your program step by step,you want to go to the next breakpoint faster,Use continue:

(gdb) c

If you want see some Variables,Use:

(gdb) p [Variable name]

To see this Variable just once,if you want it exists until you kill the program,Use:

(gdb) display [Variable name]

Variable will be outputted with debugging information.

When you want to reboot program,or don’t want to debug.Use:

(gdb) kill

When you want to exit $gdb$:

(gdb) q
By:spaceskynet

文章作者: SpaceSkyNet
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 SpaceSkyNet !
  目录
评论