gdb调试

在需要gdb对程序进行调试时,首先,我们需要在编译时将调试信息加入到可执行文件中。我们可以使用编译器中的-g参数来实现。
如:
gcc -g hello.c -o hello
g++ -g hello.cpp -o hello
如果没有加入调试信息,将看不到程序的函数名、变量名,所代替的全是运行时的

我们可以通过gdb <program> program来启动gdb,program是可执行文件(注:一般是加了调试信息的可执行文件 =>即编译时加了-g参数编译的)
同时,gdb可以同时调试一个运行的程序和core文件,其中,core是非法执行后core dump后产生的文件
gdb <program> core
gdb还可以调试一个服务程序,如果是一个服务程序,我们可以指定服务程序运行时的进程ID,gdb会自动的attach上去,并调试它。
gdb <program> <PID>

在启动gdb时,我们可以使用参数,对于具体的参数,我们可以在gdb中使用help语句查看,如下

List of classes of commands:
aliases-- Aliases of other commands
breakpoints -- Making program stop at certain points
data--Examining data
files -- Specifying and examining files
internals -- Maintenance commands
obscure-- Obscure features
running--Running the program
stack-- Examining the stack
status -- Status inquiries
support--Support facilities
tracepoints-Tracing of program execution without stopping the program
user-defined --User-defined commands
Type "help" followed by a class name for a list of commands in that class.
Type "help" followed by command name for full documentation.
Command name abbreviations are allowed if unambiguous.(gdb)

键入“help”,后跟一个类名,表示该类中的命令列表。
如:help data
在这里插入图片描述
键入“help”,然后键入命令名,以获得完整的文档。
如果没有歧义,则允许使用命令名缩写。(gdb)
如:help print
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值