gdb命令小抄

來源:互聯網
上載者:User
本文轉自: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

[Copy to clipboard] [ - ]

CODE:

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命令增加如下

[Copy to clipboard] [ - ]

CODE:

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.