博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
using gdb to debug c program
阅读量:6165 次
发布时间:2019-06-21

本文共 1981 字,大约阅读时间需要 6 分钟。

#include 
static void display(int i, int *ptr);int main(void) { int x = 5; int *xptr = &x; printf("In main():\n"); printf(" x is %d and is stored at %p.\n", x, &x); printf(" xptr points to %p which holds %d.\n", xptr, *xptr); display(x, xptr); return 0;}void display(int z, int *zptr) { printf("In display():\n"); printf(" z is %d and is stored at %p.\n", z, &z); printf(" zptr points to %p which holds %d.\n", zptr, *zptr);}
 
 

使用上面的file, 比方 test.c

1, 编译。 gcc -g -o testx test.c

2, 执行。 gdb testx

GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1

Copyright (C) 2014 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 "i686-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 testx...done.
(gdb)

3, 设置断点。 gdb> b 8

Breakpoint 1 at 0x8048472: file test.c, line 8.

4, 设置断点2。 gdb> b 10

Breakpoint 2 at 0x80484ac: file test.c, line 10.

5, 运行。

gdb> run

Starting program: /home/wang/mytest/gdbtest/testx 

In main():
Breakpoint 1, main () at test.c:8
8   printf("   x is %d and is stored at %p.\n", x, &x);

6, 继续。 gdb> c

Continuing.

   x is 5 and is stored at 0xbfffeb58.
   xptr points to 0xbfffeb58 which holds 5.
Breakpoint 2, main () at test.c:10
10   display(x, xptr);

7, 继续。 gdb> c

Continuing.

In display():
   z is 5 and is stored at 0xbfffeb40.
   zptr points to 0xbfffeb58 which holds 5.
[Inferior 1 (process 11616) exited normally]

9, for step, using step

10, for backtrace, using bt

转载地址:http://hnuba.baihongyu.com/

你可能感兴趣的文章
机器学习-泛化能力
查看>>
css溢出机制探究
查看>>
vue中如何实现后台管理系统的权限控制
查看>>
关于angularjs过滤器的理解
查看>>
vue 使用html2canvas将DOM转化为图片
查看>>
angular编辑-初始化变量失败
查看>>
jQuery源码解析之Data
查看>>
React Native Cannot read property 'bindings' of null (null)) 解决!
查看>>
Android 实现锚点定位
查看>>
leetcode-139-Word Break
查看>>
改变世界的七大NLP技术,你了解多少?(上)
查看>>
基于 HTML5 OpenLayers3 实现 GIS 电信资源管理系统
查看>>
SQLAlchemy的简单使用
查看>>
列出a,b,c的所有4位数排序可能。如:abca,abcb,abcc,acba(面试题)
查看>>
preact源码分析,有毒
查看>>
vue 实现 ios 原生picker 效果及vue使用腾讯地图获取当前位置
查看>>
MongoDB基本操作
查看>>
this的指向(附面试题)
查看>>
less学习笔记
查看>>
算法题解:从字符串中查找最长的回文子串(搜索最佳结果的一般方法)
查看>>