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命令,查 ...
 
随机推荐
- Python3基础 file open+write 对不存在的txt进行创建与写入
			
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
 - windows下如何解决chrome浏览器左下角总提示'Downloading proxy script'的问题
			
答:关掉LAN settings中的Automatically detect settings选项和Use automatic configuration script选项,如下图
 - 2017年人工智能相关会议论文阅读笔记 (已添加ISSCC17,慢慢补充中)
			
ISSCC 2017 Session14 Deep Learning Processors: 关于Deep Learning Processors的Slides笔记,主要参考了[1]中的笔记,自己根据 ...
 - springmvc-自定义消息转换器
			
最近的项目没有用到这个,先把自己自学跑通的例子先帖出来,供自己以后参考吧! 如有不对地方望指出! 一.自定义类实现AbstractHttpMessageConverter package com.dz ...
 - git的软件安装
			
1.Git for Winodws 1.*的版本 https://github.com/msysgit/msysgit/releases 2.*的版本 https://github.com/g ...
 - Codeforces Round #429 (Div. 2)
			
A. Generous Kefa One day Kefa found n baloons. For convenience, we denote color of i-th baloon as ...
 - 【深度学习】Pytorch 学习笔记
			
目录 Pytorch Leture 05: Linear Rregression in the Pytorch Way Logistic Regression 逻辑回归 - 二分类 Lecture07 ...
 - js文字转移效果
			
这个例子算是有点样子的. 思路: 字符串操作.左框里面先是预设的.点击按钮时截取左框中的字符串的前一个字符到右框里的字符串后面,以此循环.点击按钮时按钮变为灰色,在循环完成后恢复.计数的总数(右边)是 ...
 - Java DateUtil,日期整理
			
import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; imp ...
 - Flutter学习笔记(三)-- 事件交互和State管理
			
先来看看准备界面: image.png 目标是修改图中红色实线框中的喜欢和不喜欢的五角星的修改,以及数字的修改. 在修改之前,有必要先了解一些相关的信息. 知识点 前面简单的提到过,有些Widget是 ...