gdb常用命令(gdb common commands)

常用命令(common commands)

  • 编译待调试源文件(compile the source files for debug)

    public@public:~$ gcc source.c -g -Wall -o binaryfile.out // for *.c files


  • 开启调试模式(begin debug)

    public@public:~$ gdb binaryfile.out
    or
    public@public:~$ gdb
    public@public:~$ file binaryfile.out


  • 打断点(breaking point)

    (gdb) break 10 // breaking point in line 10
    or
    (gdb) break functionname // breaking point in the function
    (gdb) break [where] if n==6 // breaking point in where when n equal to 6


  • 查看断点信息(show breaking point)

    (gdb) info breakpoints
    you will see the info like this:
    Num Type Disp Enb Address What
    1 breakpoint keep n 0x080484c8 in func at test.c:6
    2 breakpoint keep y 0x080484d1 in func at test.c:7
    stop only if n==6
    3 breakpoint keep y 0x080484c1 in func at test.c:5


  • 取消断点(disable breaking point)

    (gdb) disable breakingpointnumber
    like this:
    (gdb) disable 1 // disable the breaking point is 1


  • 恢复断点(enable breaking point)

    (gdb) enable breakingpointnumber
    like this:
    (gdb) enable 1 // enable the breaking point is 1


  • 删除断点(delete the breaking point)

    (gdb) clear breakingpointnumber // delete breaking point number
    like this:
    (gdb) clear 1 // delete the breaking point is 1
    (gdb) clear functionname // delete the breaking point of this function


  • 继续运行至下一断点(running to the next breaking point)

    (gdb) continue


  • 打印信息(print the info)

    (gdb) print var
    (gdb) print n


  • 执行下一条语句,只执行一条,不进入函数内部(execute the next statement)

    (gdb) next


  • 步进语句,会进入函数内部(step the next statement)

    (gdb) step


  • 显示源文件内容(show source file)

    (gdb) list beginlinenumber,endlinenumber
    or
    (gdb) list filename:beginlinenumber,endlinenumber
    like this:
    (gdb) list 5,10 // show the 5 to 10 line


  • 设置参数(set arguments)

    进入调试程序后:
    (gdb) set args arguments_values


  • 退出(quit the gdb)

    (gdb) quit


调试多线程

显示线程信息

info threads // show the thread where is running if the symbol * front the line

切换线程

thread THREAD_ID

让所有线程执行同一命令或者让指定线程执行同一命令

thread apply THREAD_ID1 THREAD_ID2 backtrace // show thread1 thread2 stack information
thread apply all backtrace // show everyone thread stack information

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值