編寫代碼
#include < stdio.h >
int main(int argc, char **argv)
{
int i;
int result = 0;
if(1 >= argc)
{
printf("Helloworld.n");
}
printf("Hello World %s!n",argv[1]);
for(i = 1; i <= 100; i++) {
result += i;
}
printf("result = %dn", result );
return 0;
}
編譯時加上 -g
參數:
gcc helloworld.c -o hellowrld -g
啟動調試
$ gdb helloWorld
GNU gdb (GDB) Red Hat Enterprise Linux 8.2-12.el8
Copyright (C) 2018 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 "x86_64-redhat-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
< http://www.gnu.org/software/gdb/bugs/ >.
Find the GDB manual and other documentation resources online at:
< http://www.gnu.org/software/gdb/documentation/ >.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from helloworld...done.
(gdb) run < ----------------------------- 不帶參數運行
Starting program: /home/zhuzhg/helloworld
Missing separate debuginfos, use: yum debuginfo-install glibc-2.28-101.el8.x86_64
helloworld.
result = 5050
[Inferior 1 (process 1069013) exited normally]
(gdb) run China < ----------------------------- 帶參數運行
Starting program: /home/zhuzhg/helloworld China
Hello World China!
result = 5050
[Inferior 1 (process 1071086) exited normally]
(gdb)
-
Linux
+關注
關注
87文章
11345瀏覽量
210404 -
調試
+關注
關注
7文章
589瀏覽量
34064 -
代碼
+關注
關注
30文章
4828瀏覽量
69055 -
gdb
+關注
關注
0文章
60瀏覽量
13349
發布評論請先 登錄
相關推薦
嵌入式Linux的GDB調試環境建立
嵌入式Linux系統的GDB遠程調試的實現
Linux應用的GDB調試的原理及過程分析
![<b class='flag-5'>Linux</b>應用的<b class='flag-5'>GDB</b><b class='flag-5'>調試</b>的原理及過程分析](https://file.elecfans.com/web1/M00/B5/54/pIYBAF5gWW-ARv_SAABcEAzxVmk577.png)
嵌入式Linux GDB調試環境搭建與使用
![嵌入式<b class='flag-5'>Linux</b> <b class='flag-5'>GDB</b><b class='flag-5'>調試</b>環境搭建與使用](https://file.elecfans.com/web1/M00/D9/4E/pIYBAF_1ac2Ac0EEAABDkS1IP1s689.png)
Linux嵌入式 gdb VSCode圖形化調試教程
![<b class='flag-5'>Linux</b>嵌入式 <b class='flag-5'>gdb</b> VSCode圖形化<b class='flag-5'>調試</b>教程](https://file.elecfans.com/web1/M00/D9/4E/pIYBAF_1ac2Ac0EEAABDkS1IP1s689.png)
OpenHarmony系統使用gdb調試init
在ubuntu中調試GDB
![在ubuntu<b class='flag-5'>中</b><b class='flag-5'>調試</b><b class='flag-5'>GDB</b>](https://file1.elecfans.com/web2/M00/8D/FD/wKgaomTCKxCAGEqwAAAJmUuGa5Q744.jpg)
評論