編寫代碼
#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)
聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。
舉報投訴
-
Linux
+關(guān)注
關(guān)注
87文章
11469瀏覽量
212911 -
調(diào)試
+關(guān)注
關(guān)注
7文章
608瀏覽量
34545 -
代碼
+關(guān)注
關(guān)注
30文章
4891瀏覽量
70308 -
gdb
+關(guān)注
關(guān)注
0文章
60瀏覽量
13551
發(fā)布評論請先 登錄
相關(guān)推薦
熱點推薦
使用GDB調(diào)試Linux應(yīng)用程序
本篇講解使用GDB調(diào)試Linux應(yīng)用程序,以下以 `hellowld.c` 為例介紹 GDB 的調(diào)試入門。
發(fā)表于 06-27 15:48
?571次閱讀
嵌入式Linux的GDB調(diào)試環(huán)境建立
嵌入式Linux的GDB調(diào)試環(huán)境由Host和Target兩部分組成,Host端使用arm-linux-gdb,Target Board端使用gdbserver。這樣,應(yīng)
發(fā)表于 04-02 14:33
?637次閱讀
嵌入式Linux系統(tǒng)的GDB遠(yuǎn)程調(diào)試的實現(xiàn)
stub是嵌入式系統(tǒng)中的一段代碼,作為宿主機GDB和目標(biāo)機調(diào)試程序間的一個媒介而存在。 就 目前而言,嵌入式Linux
發(fā)表于 04-02 14:38
?521次閱讀
Linux應(yīng)用的GDB調(diào)試的原理及過程分析
GDB調(diào)試是應(yīng)用程序在開發(fā)板上運行,然后在PC機上對開發(fā)板上得應(yīng)用程序進(jìn)行調(diào)試,PC機運行GDB,開發(fā)板上運行GDBServer。在應(yīng)用程序
發(fā)表于 03-05 09:44
?3565次閱讀

嵌入式Linux GDB調(diào)試環(huán)境搭建與使用
這里寫目錄標(biāo)題簡介在Ubuntu下簡單體驗GDB嵌入式GDB移植GDB 常用命令參考網(wǎng)絡(luò)通信設(shè)置注意事項簡介Linux系統(tǒng)常用
發(fā)表于 11-01 17:59
?8次下載

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

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

在板子中調(diào)試GDB的方法
系統(tǒng),比如 ubuntu、centos 等,我們可以直接運行 gdb 來調(diào)試程序。但是嵌入式中芯片性能一般比較弱,所以直接在嵌入式系統(tǒng)

GDB調(diào)試如何進(jìn)行變量查看
argc $3 = 1(gdb) print str $4 = 0x4006c8 "Hello World" 查看內(nèi)存: examine(簡寫為x)可以用來查看內(nèi)存地址中的值。語法如下: x / [n] [f] [u] addr 其中: 單元類型常見有如下: 示例: (
GDB調(diào)試工具的原理
了。 1.2 執(zhí)行中進(jìn)程調(diào)試 如果想對一個已經(jīng)執(zhí)行的進(jìn)程進(jìn)行調(diào)試,那么就要在gdb這個父進(jìn)程中調(diào)用ptrace(PTRACE_ATTA

linux用gdb調(diào)試遇到函數(shù)調(diào)用怎么辦?
。 要順利進(jìn)行函數(shù)調(diào)用的調(diào)試,首先需要準(zhǔn)備好代碼和符號表。在編譯代碼時,需要加上 `-g` 參數(shù)來生成調(diào)試信息。這樣編譯器會在可執(zhí)行文件中嵌入符號表,以供
如何使用linux下gdb來調(diào)試python程序
如何使用linux下gdb來調(diào)試python程序? 在Linux下,可以使用GDB(GNU調(diào)試器
評論