c语言之gdb调试。
1.此文档演示如何使用gdb调试c语言代码。
代码如下:
#include <stdio.h>
/*函数声明*/
void digui(int n); int main()
{
int n=;
digui(n);
return ;
} void digui(int n)
{
printf("level1-value of %d\n",n);
if(n>){
digui(n-);
}
printf("level2-value of %d\n",n);
}
2.编译debug模式下的程序,编译方式如下:
[zsd@TOMCAT ~]$ gcc -g test03.c -o test03debug
3.进入gdb的debug模式,如下:
[zsd@TOMCAT ~]$ gdb test03debug
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-.el6_4.)
Copyright (C) Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 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".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/zsd/test03debug...done.
(gdb)
4.gdb模式下,list命令,查看源代码:
(gdb) list
#include <stdio.h>
/*函数声明*/
void digui(int n); int main()
{
int n=;
digui(n);
return ;
}
(gdb) void digui(int n)
{
printf("level1-value of %d\n",n);
if(n>){
digui(n-);
}
printf("level2-value of %d\n",n);
}
5.list的相关命令,如下:
(gdb) set listsize //设置显示行数
(gdb) show listsize; //查看显示行数
Number of source lines gdb will list by default is .
(gdb) list , //显示1~20行的源代码
#include <stdio.h>
/*函数声明*/
void digui(int n); int main()
{
int n=;
digui(n);
return ;
} void digui(int n)
{
printf("level1-value of %d\n",n);
if(n>){
digui(n-);
}
printf("level2-value of %d\n",n);
}
6.设置断点。
个人思路:由于希望研究递归函数的过程,所以对目前程序的16行和18行,设置断点。操作如下:
(gdb) break //设置16行的断点
Breakpoint at 0x40050c: file test03.c, line .
(gdb) break //设置18行的断点
Breakpoint at 0x400519: file test03.c, line .
(gdb) info breakpoints //查看断点信息
Num Type Disp Enb Address What
breakpoint keep y 0x000000000040050c in digui at test03.c:
breakpoint keep y 0x0000000000400519 in digui at test03.c:18 删除断点的命令:(这里不执行,只是告知断点的方式)
(gdb) clear 16
(gdb) clear
7.开始调试程序
(gdb) run //开始执行调试程序
Starting program: /home/zsd/test03debug
level1-value of Breakpoint , digui (n=) at test03.c:
digui(n-); //停止到设置在第一个断点,程序在第16行暂停。
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.132.el6.x86_64
(gdb) contiune //continue命令,是在碰到断点的情况下,停止
Undefined command: "contiune". Try "help".
(gdb) continue
Continuing.
level1-value of Breakpoint , digui (n=) at test03.c:
digui(n-); //第二次碰到断点,程序停止,依次递推
(gdb) continue
Continuing.
level1-value of Breakpoint , digui (n=) at test03.c:
digui(n-);
(gdb) continue
Continuing.
level1-value of Breakpoint , digui (n=) at test03.c:
digui(n-);
(gdb) continue
Continuing.
level1-value of Breakpoint , digui (n=) at test03.c:
digui(n-);
(gdb) continue
Continuing.
level1-value of Breakpoint , digui (n=) at test03.c:
digui(n-);
(gdb) continue
Continuing.
level1-value of Breakpoint , digui (n=) at test03.c:
digui(n-);
(gdb) continue
Continuing.
level1-value of Breakpoint , digui (n=) at test03.c:
digui(n-);
(gdb) continue
Continuing.
level1-value of Breakpoint , digui (n=) at test03.c:
printf("level2-value of %d\n",n);
(gdb) continue
Continuing.
level2-value of Breakpoint , digui (n=) at test03.c:
printf("level2-value of %d\n",n);
(gdb) continue
Continuing.
level2-value of Breakpoint , digui (n=) at test03.c:
printf("level2-value of %d\n",n);
(gdb) continue
Continuing.
level2-value of Breakpoint , digui (n=) at test03.c:
printf("level2-value of %d\n",n);
(gdb) continue
Continuing.
level2-value of Breakpoint , digui (n=) at test03.c:
printf("level2-value of %d\n",n);
(gdb) continue
Continuing.
level2-value of Breakpoint , digui (n=) at test03.c:
printf("level2-value of %d\n",n);
(gdb) continue
Continuing.
level2-value of Breakpoint , digui (n=) at test03.c:
printf("level2-value of %d\n",n);
(gdb) continue
Continuing.
level2-value of Breakpoint , digui (n=) at test03.c:
printf("level2-value of %d\n",n);
(gdb) continue
Continuing.
level2-value of Breakpoint , digui (n=) at test03.c:
printf("level2-value of %d\n",n);
(gdb) continue
Continuing.
level2-value of Program exited normally.
run,开始运行程序;
continue,程序暂停时继续运行程序的命令;
print 变量名或表达式,打印该变量或者该表达式的值。whatis 变量名或者表达式,可以显示该变量或表达式的数据类型。
print 变量=值,这种形式还可以给对应的变量赋值;类似的还有set variable 变量=值。作用和用print赋值相同。
next,继续执行下一条语句;还有一条命令step,与之类似,不同的是,当下一条语句遇到函数调用的时候,next不会跟踪进入函数,而是继续执行下面的语句,而step命令则会跟踪进入函数内部。
c语言之gdb调试。的更多相关文章
- 使用GDB调试Go语言
用Go语言已经有一段时间了,总结一下如何用GDB来调试它! ps:网上有很多文章都有描述,但是都不是很全面,这里将那些方法汇总一下 GDB简介 GDB是GNU开源组织发布的⼀一个强⼤大的UNIX下的 ...
- 【嵌入式开发】C语言 命令行参数 函数指针 gdb调试
. 作者 : 万境绝尘 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/21551397 | http://www.hanshul ...
- C语言 命令行参数 函数指针 gdb调试
. 作者 : 万境绝尘 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/21551397 | http://www.hanshul ...
- linux下的C语言开发(gdb调试)
原文: http://blog.csdn.net/feixiaoxing/article/details/7199643 用gdb调试多进程的程序会遇到困难,gdb只能跟踪一个进程(默认是跟踪父进程) ...
- 20145223《信息安全系统设计基础》 GDB调试汇编堆栈过程分析
20145223<信息安全系统设计基础> GDB调试汇编堆栈过程分析 分析的c语言源码 生成汇编代码--命令:gcc -g example.c -o example -m32 进入gdb调 ...
- GDB调试汇编堆栈
GDB调试汇编堆栈 分析过程 C语言源代码 int g(int x) { return x+6; } int f(int x) { return g(x+1); } int main(void) { ...
- GDB调试汇编分析
GDB调试汇编分析 代码 本次实践我参照了许多先做了的同学的博客,有卢肖明,高其,张梓靖同学.代码借用的是卢肖明同学的代码进行调试运行. GCC编译 使用gcc -g gdbtest.c -o gdb ...
- Linux下GDB调试
GDB 是一个强大的命令行调试工具.大家知道命令行的强大就是在于,其可以形成执行 序列,形成脚本.UNIX 下的软件全是命令行的,这给程序开发提供了极大的便利,命令行 软件的优势在于, 他们可以非常容 ...
- 20145311利用gdb调试汇编代码
利用GDB调试汇编代码 首先编写c语言原代码,我使用的是同学分析过的代码 #include<stdio.h>short addend1 = 1;static int addend2 = 2 ...
随机推荐
- C#找不到ConfigurationManager类
c#添加了Configuration;后,竟然找不到 ConfigurationManager 这个类,后来才发现:虽然引用了using System.Configuration;这个包,但是还是不行 ...
- [GIT] 更新.repo目录
cd .repo/manifests/ git co -f git pull
- Web版需求征集系统所得1,servlet中获取checkbox复选框的值
servlet中获取checkbox复选框的值 </tr> <tr> <td align="right">研究类型</td> < ...
- composer 实现自动加载原理
简介 一般在框架中都会用到composer工具,用它来管理依赖.其中composer有类的自动加载机制,可以加载composer下载的库中的所有的类文件.那么composer的自动加载机制是怎么实现的 ...
- C# CreateParams的使用(解决闪屏问题)
<转载自:https://blog.csdn.net/xpwang/article/details/53427479> 窗体和控件的属性CreateParams(这真的是一个属性)很神奇, ...
- 计算CPU的MIPS
如图: MIPS=主频/CPI*(10^6), 其中CPI的计算公式为CPI=总的时钟周期数/总的指令数 CPI=(0.5a*2+0.2a*3+0.1a*4+0.2a*5)/a=3
- 格式化数据保留两位小数,输入格式为 :xxx,xx,,,,x,,(x为浮点数)
/** * 格式化字符串 */ static String dataFormat(String data){ String formatedData = ""; // 浮点数正则表 ...
- dx.jar文件问题,有没有同学知道怎么解决呀,这一步没法解决,后面就没办法跟着做了
Java Code 123456789101112 dx.jar文件问题,有没有同学知道怎么解决呀,这一步没法解决 - test] Unknown error: Unable to build: ...
- Oracle数据库备份及还原
Oracle数据库备份 1:找到Oracle安装路径我的就是默认C盘 C:\app\wdjqc\admin\orcl\adump 2:执行文件:back.bat 文件内容如下: @echo off ...
- [Swift]LeetCode354. 俄罗斯套娃信封问题 | Russian Doll Envelopes
You have a number of envelopes with widths and heights given as a pair of integers (w, h). One envel ...