首页 > 数据库技术 > 详细

gdb命令

时间:2017-02-19 21:28:40      阅读:222      评论:0      收藏:0      [点我收藏+]

如果要进行gdb调试,需要在编译的时候加上-g或-ggdb参数。

 

调试步骤举例:

1、生成调试的对象:g++ -g -o a.out test.cpp

2、启动gdb的方式:

gdb    [-help] [-nx] [-q] [-batch] [-cd=dir] [-f] [-b bps] [-tty=dev] [-s symfile] [-e prog] [-se prog] [-c core] [-x cmds] [-d dir] [prog[core|procID]]

-q:‘‘Quiet’’.  Do not print the introductory and copyright messages.  These messages are also suppressed in batch mode

-core=file/-c file:Use file file as a core dump to examine,指定core文件

-directory=directory/-d directory:Add directory to the path to search for source files,指定的路径搜索源文件

 

启动例子:

gdb a.out

gdb a.out a.core

gdb a.out pid(进程号)

 

gdb的命令:

break [file:]function:Set a breakpoint at function (in file),简写为b,设置断点,例如:b test.cpp:Output

run arglist:以arglist启动程序,也可以不要arglist,例如:run -O “/data/bin_data/”

backtrace: display the program stack,简写bt,打印栈信息

print expr:Display the value of an expression,简写为p,打印表达式值

c:Continue running your program (after stopping, e.g. at a breakpoint),运行到下一个断点

next:Execute next program line (after stopping); step over any function calls in the line,可以简写为n,下一行

list [file:]function:type the text of the program in the vicinity of where it is presently stopped.打印函数上下的代码

step:Execute next program line (after stopping); step into any function calls in the line.单步调试,一行中有函数,会跟进去

set var:设置变量的值

start:执行程序,停在main第一行语句前等待

quit:退出gdb调试,简写q

 

调试core文件:

gdb exe文件 -c core文件

 

更多的gdb命令可以在进入gdb后,输入help去查找。//TODO

 

gdb命令

原文:http://www.cnblogs.com/yuanbuku/p/6416768.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!