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命令,查 ...
随机推荐
- IDEA 插件-码云
插件安装 最新插件版本: 2018.3.1.(2019-01-10 发布)注意:码云 IDEA 插件已由 gitosc 更名为 gitee.新版插件 gitee 菜单已经和 git 菜单合并 通过「插 ...
- 【转载】浅谈JavaScript,let和var定义变量的区别
了解JS与ES5与ES6区别 JS语言 JavaScript一种动态类型.弱类型.基于原型的客户端脚本语言,用来给HTML网页增加动态功能. 动态: 在运行时确定数据类型.变量使用之前不需要类型声明, ...
- 将Sublime Text 添加到鼠标右键菜单的教程方法
安装notepad++软件,在菜单右键自动会添加“edit with notepad++"的选项,那么怎么将Sublime Text 添加到鼠标右键菜单呢?下面是我的操作过程,希望有帮助! ...
- Inversion of Control Containers and the Dependency Injection pattern
https://martinfowler.com/articles/injection.html One of the entertaining things about the enterprise ...
- [异常记录-13]Web Deploy发布:An error occurred when the request was processed on the remote computer
大概搜了一下这个报错,大家的情况各不相同,但应该是 Web Deploy 安装导致的没错了... 建议粗暴解决, 卸载后重新安装 Web Deploy 时,不要选那个经典还是典型的安装选项,选自定义 ...
- ASP.NET Web API 2入门
1.全局配置 Web API 2之前是这样的配置的: protected void Application_Start() { //未实现特性路由 WebApiConfig.Register(Glob ...
- 03_Flume多节点Failover实践
1.实践场景 模拟上游Flume Agent在发送event时的故障切换 (failover) 1)初始:上游Agent向active的下游节点Collector1传递event 2)Collecto ...
- hdu 1788 最小公倍数(这题面。。。)
Chinese remainder theorem again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 ...
- pandas 处理数据中NaN数据
使用dropna()函数去掉NaN的行或列 import pandas as pd import pickle import numpy as np dates = pd.date_range() d ...
- 使用rviz 查看远程主机
一.安装好ros环境 https://www.cnblogs.com/sea-stream/p/9809590.html 二.配置参数 vim ~/.bashrc #输入内容 export ROS_H ...