GDB调试C++

GDB官网

配合小神仙视频食用佳
https://www.bilibili.com/video/BV1EK411g7Li?from=search&seid=10155295298944448370&spm_id_from=333.337.0.0

常用的GDB命令

Here are some of the most frequently needed GDB commands:

   break [file:]function
       Set a breakpoint at function (in file).

   run [arglist]
       Start your program (with arglist, if specified).

   bt  Backtrace: display the program stack.

   print expr
       Display the value of an expression.

   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.

   edit [file:]function
       look at the program line where it is presently stopped.

   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.

   help [name]
       Show information about GDB command name, or general information about using GDB.

   quit
       Exit from GDB.
gcc -g test.c    # 编译带gdb调试的二进制文件
gdb ./a.out		# gdb运行二进制文件
run r 					# 运行二进制文件
quit q				#推出gdb调试

list 						# 查看源代码
break b 			# 打断点
             b 	main()					#在函数名字为main()的地方打断点
             b    10									#在代码的第10行打断点
             info b 								# 查看断点
next n 												# 调试下一行
info b 												# 查看断点情况
step 													# 进入引用的函数内部进行调试
  1. shell 去掉我们终端的命令
  2. 日志功能命令
set logging on

断点的分类

  • watchpoint 观察变量的值是否发生变化
 watch *(变量的地址) 						# 设置watchpoint
 info watchpoints							# 查看当前的watchpoint
 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值