gdb調試小結

來源:互聯網
上載者:User

標籤:step   退出   http   修改   開始   ignore   語句   啟動   tar   

一、啟動調試

 測試程式

  1 #include<iostream>  2 using namespace std;  3 class AA  4 {  5     void f(){}  6 };  7 int main()  8 {  9     cout<<sizeof(AA)<<endl; 10     AA a; 11     cout<<sizeof(a); 12     return 0; 13 }

g++/gcc 命令加-g表示使用了gdb調試:

 file+產生的可執行檔(test):匯入調試檔案

 

二、常用調試命令(斷點調試)

r 開始執行(run),如果有斷點則直至第一個斷點(break)

b 設定斷點

b num(行號)

b function(函數名)

tb 斷點位置 設定臨時斷點(只生效一次)

i b 檢查斷點資訊

b 斷點位置 if 條件  設定條件斷點

ignore bnum count 表示接下來的count編號為bnum的斷點忽略。

d 斷點編號 刪除斷點(delete)

c 斷點之後繼續執行到下一個斷點(continue)

n 單步運行(next)

s 進入函數(step) 

finish 執行至退出函數

start 停留在main函數的第一條語句

p 參數 列印參數資訊

info 檔案/函數 檔案/函數資訊

 三 、設定觀察點

修改了一下測試檔案

  1 #include<iostream>  2 using namespace std;  3 class AA  4 {  5     void f(){}  6 };  7 int main()  8 {  9     int b=1; 10     for(int i=1;i<10;i++) 11         b++; 12     cout<<sizeof(AA)<<endl; 13     AA a; 14     cout<<sizeof(a); 15     return 0; 16 }

 watch 觀察點 (遇到變數值變化,程式就會停下來)

 i watch 查看觀察點

d 序號 刪除觀察點

 四、退出

 q

 

gdb調試小結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.