MinGW的gdb调试
#include <stdio.h>
void swap(int *a,int *b){
int temp = *a;
*a = *b;
*b = temp;
}
int main(void)
{
int a=,b=;
swap(&a,&b);
printf("a = %d ,b = %d\n",a,b);
return ;
}
要支持调试,在编译时要加入-g选项,编译命令:
gcc -g test.c -o test.exe
gdb调试加载文件:
gdb test.exe
出现gdb命令行:
GNU gdb (GDB) 7.6.
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 "mingw32".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from D:\mypro\C\test.exe...done.
(gdb)
gdb调试命令表:
| 命令 | 解释 | 简写 |
| file | 加载一个可执行文件,也可以在运行gdb的时候加载,两种方法都不会运行程序。 | 无 |
| list | 列出可执行源码的一部分,通常在程序开始运行前执行,用来设置断点。 | l |
| next | 单步调试,不进入函数。 | n |
| step | 单步执行,进入函数。 | s |
| run | 运行加载了的程序。 | r |
| continue | 继续执行程序。 | c |
| quit | 退出调试。 | q |
| printf | 输出指定的变量的值,变量要在程序运行处可见。 | p |
| break | 设置断点。 | b |
| info break | 查看断点的信息。 | i b |
| delete | 删除断点。 | d |
| watch | 监视一个变量的值,一旦发生变化,程序将会被暂停执行。 | wa |
| help | 查看gdb的帮助信息。 | h |
1.l命令,列出部分代码:
(gdb) l
void swap(int *a,int *b){
int temp = *a;
*a = *b;
*b = temp;
}
int main(void)
{
int a=,b=;
(gdb)
继续输入l命令可以继续列出后面的代码,直到文件里代码列完
(gdb) l
swap(&a, &b);
printf("a = %d ,b = %d\n",a,b);
return ;
}(gdb) l
(gdb) Line number out of range; test.c has lines.
2.start命令,开始运行,会停到main入口处:
(gdb) start
Temporary breakpoint at 0x401491: file test.c, line .
Starting program: D:\mypro\C/test.exe
[New Thread .0x18c4]
[New Thread .0x2418] Temporary breakpoint , main () at test.c:
int a=,b=;
3.n命令:单步调试,不进入函数,跳到第12行:
(gdb) n
swap(&a,&b);
4.s命令:单步调试,进入函数,跳到第4行:
(gdb) s
swap (a=0x61ff2c, b=0x61ff28) at test.c:
int temp = *a;
5.b命令设置断点(b + 第n行代码的行数):
(gdb) b
Breakpoint at 0x401478: file test.c, line .
6.r命令,运行程序,直到下一个断点就停:
The program being debugged has been started already.
Start it from the beginning? (y or n)
...
Breakpoint , swap (a=0x61ff2c, b=0x61ff28) at test.c:
*b = temp;
7.p命令,输出制定的变量的值,变量要在程序运行处可见:
(gdb) p *a
$ =
(gdb) p *b
$ =
(gdb) p a
$ = (int *) 0x61ff2c
(gdb) p b
$ = (int *) 0x61ff28
next一下,再看b的值:
(gdb) n
}
(gdb) p *b
$ =
8.i b命令,查看断点信息:
(gdb) i b
Num Type Disp Enb Address What
breakpoint keep y 0x00401478 in swap at test.c:
breakpoint already hit time
9.d命令,删除断点,不加断点位置即删除所有断点:
(gdb) d
Delete all breakpoints? (y or n) [answered Y; input not from terminal]
(gdb) i b
No breakpoints or watchpoints.
10.没有断点后,再试一下r命令,可以看到,执行完了程序:
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) [answered Y; input not from terminal]
error return ../../gdb-7.6./gdb/windows-nat.c: was
Starting program: D:\mypro\C/test.exe
[New Thread .0x1460]
[New Thread .0x5e0]
a = ,b =
[Inferior (process ) exited normally]
11.q命令,退出gdb:
(gdb) q
MinGW的gdb调试的更多相关文章
- 为DEV C++/CodeBlock配置gdb调试遇到的问题
DEV C++和CodeBlock都只是一个IDE,不能编译调试,需要自己配置MINGW和gdb调试 1.MINGW 在这下载mingw-get-setup.exe安装即可. https://sour ...
- GDB 调试 ---转 比较全的东东
转自 程序人生:http://www.programlife.net/gdb-manual.html Linux 包含了一个叫gdb 的GNU 调试程序.gdb 是一个用来调试C和C++程序的强力调试 ...
- GDB调试教程
简介 GDB(GNU debugger)是GNU开源组织发布的一个强大的UNIX下的程序调试工具.可以使用它通过命令行的方式调试程序.它使你能在程序运行时观察程序的内部结构和内存的使用情况.你也可以使 ...
- GDB调试手册[转]
Linux 包含了一个叫gdb 的GNU 调试程序.gdb 是一个用来调试C和C++程序的强力调试器.它使你能在程序运行时观察程序的内部结构和内存的使用情况.以下是 gdb 所提供的一些功能:它使你能 ...
- GDB调试命令小结
1.启动调试 前置条件:编译生成执行码时带上 -g,如果使用Makefile,通过给CFLAGS指定-g选项,否则调试时没有符号信息.gdb program //最常用的用gdb启动程序,开始调试的方 ...
- GDB调试汇编堆栈过程分析
GDB调试汇编堆栈过程分析 分析过程 这是我的C源文件:click here 使用gcc - g example.c -o example -m32指令在64位的机器上产生32位汇编,然后使用gdb ...
- gdb调试器的使用
想要使用gdb调试程序的话,首先需要gcc -g main.c -o test 然后运行gdb test对程序进行调试 l (小写的l,是list的首字母),用以列出程序 回车 是运行上一个命令 ...
- 20145212——GDB调试汇编堆栈过程分析
GDB调试汇编堆栈过程分析 测试代码 #include <stdio.h> short val = 1; int vv = 2; int g(int xxx) { return xxx + ...
- gdb调试PHP扩展错误
有时候,使用PHP的第三方扩展之后,可能会发生一些错误,这个时候,可能就需要更底层的方式追踪调试程序发生错误的地方和原因,熟悉linux下C编程的肯定不陌生gdb 首先,使用ulimit -c命令,查 ...
随机推荐
- 解决Navicat Premium 12 连接oracle数据库出现ORA-28547的问题
1. 出现的问题... 下午工作时想连接Oracle数据库,使用的是Navicat Premium 12 . 数据库地址.用户名.密码.端口号都没有问题,但出现了ORA-28547:connectio ...
- TableView,自定义TableViewCell
自定义Table 原理: http://blog.jobbole.com/67272/ http://www.cnblogs.com/wangxiaofeinin/p/3532831.html 补充: ...
- Go第一篇之轻松入门
Go语言简介 Go语言简史 Go 语言(或 Golang)是 Google 在 2007 年开发的一种开源编程语言,于 2009 年 11 月 10 日向全球公布.Go 是非常年轻的一门语言,它的主要 ...
- Source not found :Edit Source Lookup Path 解决方案
作者原创,转载请注明转载地址 在eclipse中用debug调试的时候,出现了以下问题,很是尴尬,经常碰到,所以有必要进行总结一下: 对该问题有两种解决方案, 一种比较文明:解决方法可参考如下网址: ...
- HashMap和LinkedHashMap的比较使用
由于现在项目中用到了LinkedHashMap,并不是太熟悉就到网上搜了一下. import java.util.HashMap; import java.util.Iterator; impor ...
- HDU 6103 Kirinriki(尺取法)
http://acm.hdu.edu.cn/showproblem.php?pid=6103 题意: 给出一个字符串,在其中找两串互不重叠的子串,计算它们之间的dis值,要求dis值小于等于m,求能选 ...
- MVC ---- EF的安装于卸载
先卸载EF:Uninstall-Package EntityFramework -Force 在安装EF5.0:Install-Package EntityFramework –Version 5.0 ...
- Could not find a package configuration file provided by "ecl_build",.................couldn't find required component 'ecl_build'
sudo apt-get install ros-kinetic-ecl-build
- c++ 二分法查找(binary_search)
#include <iostream> // cout #include <algorithm> // binary_search, sort #include <vec ...
- vs2010_相关目录
1. C:\Program Files\Microsoft SDKs\Windows\v7.0A 2.创建了 C:\Program Files\Microsoft Visual Studio 9.0 ...