编写代码
#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
+关注
关注
88文章
11628浏览量
217948 -
调试
+关注
关注
7文章
623浏览量
35378 -
代码
+关注
关注
30文章
4941浏览量
73136 -
gdb
+关注
关注
0文章
61浏览量
13816
发布评论请先 登录
相关推荐
热点推荐
嵌入式Linux的GDB调试环境建立
嵌入式Linux的GDB调试环境由Host和Target两部分组成,Host端使用arm-linux-gdb,Target Board端使用gdbserver。这样,应
发表于 04-02 14:33
•1207次阅读
嵌入式Linux系统的GDB远程调试的实现
stub是嵌入式系统中的一段代码,作为宿主机GDB和目标机调试程序间的一个媒介而存在。 就 目前而言,嵌入式Linux
发表于 04-02 14:38
•641次阅读
Linux应用的GDB调试的原理及过程分析
GDB调试是应用程序在开发板上运行,然后在PC机上对开发板上得应用程序进行调试,PC机运行GDB,开发板上运行GDBServer。在应用程序
发表于 03-05 09:44
•3684次阅读
嵌入式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` 参数来生成调试信息。这样编译器会在可执行文件中嵌入符号表,以供

Linux系统中如何进行GDB调试
评论