編寫代碼
#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
參數(shù):
gcc helloworld.c -o hellowrld -g
啟動調(diào)試
$ 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 < ----------------------------- 不帶參數(shù)運行
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 < ----------------------------- 帶參數(shù)運行
Starting program: /home/zhuzhg/helloworld China
Hello World China!
result = 5050
[Inferior 1 (process 1071086) exited normally]
(gdb)
-
Linux
+關(guān)注
關(guān)注
87文章
11496瀏覽量
213225 -
調(diào)試
+關(guān)注
關(guān)注
7文章
611瀏覽量
34613 -
代碼
+關(guān)注
關(guān)注
30文章
4893瀏覽量
70443 -
gdb
+關(guān)注
關(guān)注
0文章
60瀏覽量
13567
發(fā)布評論請先 登錄
使用GDB調(diào)試Linux應(yīng)用程序
嵌入式Linux的GDB調(diào)試環(huán)境建立
嵌入式Linux系統(tǒng)的GDB遠(yuǎn)程調(diào)試的實現(xiàn)
Linux應(yīng)用的GDB調(diào)試的原理及過程分析

嵌入式Linux GDB調(diào)試環(huán)境搭建與使用

Linux嵌入式 gdb VSCode圖形化調(diào)試教程

OpenHarmony系統(tǒng)使用gdb調(diào)試init
嵌入式Linux GDB是什么

在ubuntu中調(diào)試GDB

在板子中調(diào)試GDB的方法

GDB調(diào)試如何進(jìn)行變量查看
GDB調(diào)試工具的原理

評論