GDB调试器的总结(调试linux c)

GDB调试器总结.

 

.启动GDB
  $gdb [-q]  program [core]
 
  -q    启动时不显示版本信息等
  core   内存转储文件
  program  需要调试的可执行程序
  
 
.断点相关
 1)设置断点
 (gdb) b   funname    #可以在某个函数名处中断,如 b main        则在main函数入口处中断
       b   line       #可以在指定的源码某行号处中断, 如 b 32
       b   26  if i = 15   #当变量i等于15时在第26行中断

 2)列出所有断点
 (gdb) info b
       Num Type           Disp  Enb  Address    What
       1   breakpoint     keep   y   0x0804949c in main at getmail.c:416
       breakpoint already hit 1 time

 3)删除断点
 (gdb) d   [NoOfBreakpoints]    #删除指定断点号的断点,如果不指定,则删除所有断点

 
.运行程序
 (gdb) run  参数列表             #以指定的参数(以空格为分隔符)运行程序如run www.800hr.com 80 main.php
 

.断点后继续运行
 (gdb) c


.断点处单步运行
 (gdb) s 或 n                 #输入一次s或n时,如果接下来继续单步运行直接按 回车即可


.列出[断点处]的函数调用关系树
 (gdb) bt
  其中#0号的函数被#1号的函数调用, #1号的函数被#2号的函数调用


.列出当前运行前后的几行代码
 (gdb) l (L的小写,不是数字1)

.列出指定变量的类型
 (gdb) whatis  varname       #列出变量varname的类型,可能输出如下 type=struct strct*

.列出结构体的定义
 (gdb) ptype  structvarname  #列出名为structvarname的变量对应结构体的定义
  struct ...{
      ...
  };


.改变变量的值
 (gdb) set variable  varname=value       #给变量varname赋值value

.列出变量的值
 (gdb) p $varname
       p $i-1
       p array@10         #列出数组array的前10个元素值
       p array[1]@5       #列出从第1个到第5个的元素值

.遍历函数栈
 (gdb) where
       其中#0号的函数被#1号的函数调用, #1号的函数被#2号的函数调用
       用up可以上移一个栈

.与shell交互
 (gdb) shell cmaname     #运行shell命令如 shell pwd 列出当前目录


.单独执行某个函数
 (gdb) call funcname(arg1, arg2, arg3,....)


.变量的作用域
 (gdb) p  'file1.c'::varname
       p  'file2.c'::varname

 

[上面原词]
p         print            Display the value of an expression
b         breakpoints      Set a breakpoint at function (in file)
l         list             type the text of the program in the vicinity of where it is presently stopped
s         tracepoints     
bt        Backtrace        display the program stack
d         deletepoints
 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值