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
 

你可能感兴趣的:(c++,c++,linux,开发语言)