学会gdb的使用

2018/08/08 linux

工欲善其事,必先利其器。gdb作为一个高效的debug工具,必学之!

GDB操作

  • 设置参数调试
    gdb prog
    set args -l a -C abc
    r
    // 或者
    gdb prog
    r -l a -C abc
    
  • 断点
    info b   // show information for breakpoint
    b 10   // set line10 breakpoint 
    delete [n]  // delete all breakpoints [or breakpoint n]
    
  • 基本调试
    c  // continue until next breakpoint
    n  // next code
    s  // step into function or code block
    p  // print variable
    st  // start run and stop ad firt code in main
    watch //watch variable during running time
    bt // watch info of invoking heap
    l n // list 10 lines of code at center of line n
    disp  // display variable once stop
    

后话

Bug是程序猿最不愿见到的,掌握了gdb,就再也不怕bug啦!

参考

Search

    欢迎关注我的微信号

    想摘月亮的老刘

    Table of Contents