gdb命令小抄

本文轉自:http://blog.chinaunix.net/u/28499/showart_1154662.html
作者:gawk

在精華區看到gdb的文章,
http://www.chinaunix.net/index.p ... read.php?tid=150524
內容太多,我做了一個小抄
歡迎大家補充

1.按TAB鍵兩次會將命令或者函數名補齊

2.設置斷點
  break function
  break linenum
  break +offset  當前行號前offset行
  break -offset  當前行號後offset行
  break *address 運行內存地址處停止
  break          下一行
  break ... if condition ...可以是上述參數

3.設置觀察點
  watch  expr     變量有變化停止
  rwatch expr     變量被讀停止
  awatch expr     變量被讀寫時停止

4.設置捕捉點
  catch event
  event有如下:
  throw  catch  exec  fork vfork load unload

Raised signals may be caught:
        catch signal              - all signals
        catch signal <signame>    - a particular signal
Raised exceptions may be caught:
        catch throw               - all exceptions, when thrown
        catch throw <exceptname>  - a particular exception, when thrown
        catch catch               - all exceptions, when caught
        catch catch <exceptname>  - a particular exception, when caught
Thread or process events may be caught:
        catch thread_start        - any threads, just after creation
        catch thread_exit         - any threads, just before expiration
        catch thread_join         - any threads, just after joins
Process events may be caught:
        catch start               - any processes, just after creation
        catch exit                - any processes, just before expiration
        catch fork                - calls to fork()
        catch vfork               - calls to vfork()
        catch exec                - calls to exec()
Dynamically-linked library events may be caught:
        catch load                - loads of any library
        catch load <libname>      - loads of a particular library
        catch unload              - unloads of any library
        catch unload <libname>    - unloads of a particular library
The act of your program's execution stopping may also be caught:
        catch stop
C++ exceptions may be caught:
        catch throw               - all exceptions, when thrown
        catch catch               - all exceptions, when caught

4.停止條件維護
  可以用condition命令來修改斷點的條件,目前只有break watch支持if
  condition <bnum> <expression>
  condition <bnum> 清除停止條件

5.爲停止點設定運行命令
  可以用commands命令來設置
  commands <bnum>
  .....
  end

6.其他有用的指令
  finish 運行程序,直到當前函數完成
  until或u運行程序直到退出循環體,用在for或者while上,比較方便
x命令增加如下

Examine memory: x/FMT ADDRESS.
ADDRESS is an expression for the memory address to examine.
FMT is a repeat count followed by a format letter and a size letter.
Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),
  t(binary), f(float), a(address), i(instruction), c(char) and s(string).
Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).
The specified number of objects of the specified size are printed
according to the format.

Defaults for format and size letters are those previously used.
Default count is 1.  Default address is following last thing printed
with this command or "print".

-----------------------------------------------------------------------
參考資料:
gdb help
http://bbs.chinaunix.net/thread-150524-1-1.html
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章