編寫代碼
#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文章
11517瀏覽量
213982 -
調試
+關注
關注
7文章
613瀏覽量
34762 -
代碼
+關注
關注
30文章
4901瀏覽量
70847 -
gdb
+關注
關注
0文章
60瀏覽量
13611
發布評論請先 登錄
相關推薦
熱點推薦
嵌入式Linux的GDB調試環境建立
嵌入式Linux的GDB調試環境由Host和Target兩部分組成,Host端使用arm-linux-gdb,Target Board端使用gdbserver。這樣,應
發表于 04-02 14:33
?671次閱讀
嵌入式Linux系統的GDB遠程調試的實現
stub是嵌入式系統中的一段代碼,作為宿主機GDB和目標機調試程序間的一個媒介而存在。 就 目前而言,嵌入式Linux
發表于 04-02 14:38
?544次閱讀
Linux應用的GDB調試的原理及過程分析
GDB調試是應用程序在開發板上運行,然后在PC機上對開發板上得應用程序進行調試,PC機運行GDB,開發板上運行GDBServer。在應用程序
發表于 03-05 09:44
?3586次閱讀

嵌入式Linux GDB調試環境搭建與使用
這里寫目錄標題簡介在Ubuntu下簡單體驗GDB嵌入式GDB移植GDB 常用命令參考網絡通信設置注意事項簡介Linux系統常用
發表于 11-01 17:59
?8次下載

Linux嵌入式 gdb VSCode圖形化調試教程
文章目錄介紹GDB簡介交叉編譯器的gdb介紹在學習單片機的時候我們可以通過集成式IDE 來進行調試,比如MDK、IAR 等。在嵌入式linux
發表于 11-02 12:21
?15次下載

OpenHarmony系統使用gdb調試init
。如果能使用gdb調試init,會極大的提高定位效率。 本文簡單描述了一下L2二次啟動的系統如何使用gdb調試init 首先將
在ubuntu中調試GDB
的 gcc 編譯器即可,注意需要加 -g 選項,才能使用 gdb 調試 arm-linux-gnueabihf-gcc gdbtest .c -o gdbtest -g //編譯測試程序,注意-g 選項

GDB調試如何進行變量查看
argc $3 = 1(gdb) print str $4 = 0x4006c8 "Hello World" 查看內存: examine(簡寫為x)可以用來查看內存地址中的值。語法如下: x / [n] [f] [u] addr 其中: 單元類型常見有如下: 示例: (
linux用gdb調試遇到函數調用怎么辦?
。 要順利進行函數調用的調試,首先需要準備好代碼和符號表。在編譯代碼時,需要加上 `-g` 參數來生成調試信息。這樣編譯器會在可執行文件中嵌入符號表,以供
評論