linux-c/c++調試利器gdb、ddd小試

來源:互聯網
上載者:User

標籤:

linux-c/c++調試利器gdb、ddd小試

原文連結: http://deepfuture.iteye.com/blog/749148

部落格分類:
  • C++/C/lisp
CC++C#LinuxUbuntu 

一、gdb,在shell視窗調試

main.c內容:

main.c

#include <stdio.h>

int main() 

{

int y=0;

for (int i=0;i<10;i++){

   y+=i;

}

return 0;

}

深未來技術原創文章,如轉載,請註明來源http://deepfuture.iteye.com/ 

編譯:

 

[email protected]:~/test$ gcc -ggdb -std=c99 -o main main.c

 

啟動gdb

1、gdb 執行檔案名稱

 

[email protected]:~/test$ gdb main

GNU gdb (GDB) 7.1-ubuntu

Copyright (C) 2010 Free Software Foundation, Inc.

License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software: you are free to change and redistribute it.

There is NO WARRANTY, to the extent permitted by law.  Type "show copying"

and "show warranty" for details.

This GDB was configured as "i486-linux-gnu".

For bug reporting instructions, please see:

<http://www.gnu.org/software/gdb/bugs/>...

Reading symbols from /home/deepfuture/test/main...done.

2、list為列出原始碼

(gdb) list

1

2 #include <stdio.h>

3 int main() 

4 {

5 int y=0;

6 for (int i=0;i<10;i++){

7   y+=i;

8 }

9 return 0;

10 }

3、運行(gdb) runStarting program: /home/deepfuture/test/main  Program exited normally.4、退出gdb(gdb) quit5、啟動gdb後,再設定要載入的檔案(gdb) file mainReading symbols from /home/deepfuture/test/main...done. 6、設定斷點,,使用break行號 (gdb) listwarning: Source file is more recent than executable.12 #include <stdio.h>3 int main() 4 {5 int y=0;6 for (int i=0;i<10;i++){7   y+=i;8 }9 return 0;10 } (gdb) break 7Breakpoint 1 at 0x80483ca: file main.c, line 7. 7、運行,run(gdb) runStarting program: /home/deepfuture/test/main  Breakpoint 1, main () at main.c:77   y+=i;8、離開這個斷點,繼續運行(gdb) cContinuing.9、監視變數(gdb) watch yHardware watchpoint 2: y10、檢查變數變化(gdb) cContinuing.Hardware watchpoint 2: y Old value = 1New value = 3main () at main.c:66 for (int i=0;i<10;i++){(gdb) cContinuing. Breakpoint 1, main () at main.c:77   y+=i;(gdb) cContinuing.Hardware watchpoint 2: y Old value = 3New value = 6main () at main.c:66 for (int i=0;i<10;i++){  二、ddd,使用可以在選擇行或某變數後,watch,break等按鈕,很方便右中部的面板是一些流程調試

 圖形方式調試   

 

linux-c/c++調試利器gdb、ddd小試

聯繫我們

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