#include <stdio.h>
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

using gdb to debug c program的更多相关文章

  1. Use GDB to debug a C++ program called from a shell script

    解决了我一个大问题!!! http://stackoverflow.com/questions/5048112/use-gdb-to-debug-a-c-program-called-from-a-s ...

  2. [Advance] How to debug a program (上)

    Tool GDB Examining Memory (data or in machine instructions) You can use the command x (for “examine” ...

  3. gdb远程debug A syntax error in expression, near `variable)'.

    今天调试有个linux环境的应用时,gdb提示A syntax error in expression, near `variable)'.,最后经查,gdb版本过低(比如7.2)或者源代码不匹配所致 ...

  4. Rocket - debug - TLDebugModuleInner - Program Buffer Access

    https://mp.weixin.qq.com/s/EJVqw7JPjjaib68tENl5AQ 简单介绍TLDebugModuleInner中的Program Buffer Access. 1. ...

  5. Rocket - debug - TLDebugModuleInner - Program Buffer

    https://mp.weixin.qq.com/s/kjhJJ3moRQzxHt6pJOXEgg 简单介绍TLDebugModuleInner中Program Buffer寄存器的实现. 1. pr ...

  6. 信息安全实验一:buffer-overflow

    title: buffer-overflow date: 2016-01-10 14:17:17 categories: information-security tags: buffer-overf ...

  7. Linux GDB Debug

    http://blog.jobbole.com/107925/ gdb 调试入门,大牛写的高质量指南 http://blog.jobbole.com/107759/ gdb是the GNU Debug ...

  8. 使用gcc -g编译,gdb调试时仍然存在“no debug symbols found”的错误

    今天为调试一段代码,使用gcc将程序用-g选项重新编译.但是使用gdb进行debug时,仍然出现“no debug symbols found”的错误.仔细检查了一下Makefile,原来后面定义的连 ...

  9. mac上eclipse用gdb调试(转)

    mac上eclipse用gdb调试 With its new OS release, Apple has discontinued the use of GDB in OS X. Since 2005 ...

随机推荐

  1. jsp学习笔记 - 内置对象 pageContext

    1.pageContext几乎可以操作所有的页面内置对象 pageContext.getRequest();    得到的对象只是属于ServletRequest类,httpServletReques ...

  2. mysql 性能优化索引、缓存、分表、分布式实现方式。

    系统针对5000台终端测试结果 索引 目标:优化查询速度3秒以内 需要优化.尽量避免使用select * 来查询对象.使用到哪些属性值就查询出哪些使用即可 首页页面: 设备-组织查询 优化 避免使用s ...

  3. Codeforces_766_D_(并查集)

    D. Mahmoud and a Dictionary time limit per test 4 seconds memory limit per test 256 megabytes input ...

  4. Codeforces_766_C_(dp)

    C. Mahmoud and a Message time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  5. Java_数组1_16.5.12

    声明整型数组a: int[] a; 这时,只声明了变量a,还应该使用new运算符创建数组: int[] a=new int [100];(数组长度不要求是一个常量:new int[n]会创建一个长度为 ...

  6. POJ_1611_The Suspect

    The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 25149   Accepted: 12329 De ...

  7. WINVER WIN32 WINNT

    WINVER 和 _WIN32_WINNT 请在WINDOWS.H前定义 从 Visual C++ 2008 开始,Visual C++ 不支持面向 Windows 95.Windows 98.Win ...

  8. Xamarin绑定ios静态库

    以下是官方的步骤介绍,我就不再一步步解释了 https://docs.microsoft.com/zh-cn/xamarin/ios/platform/binding-objective-c/walk ...

  9. RabbitMQ系列(三)--Java API

    基于java使用RabbitMQ 框架:SpringBoot1.5.14.RELEASE maven依赖: <dependency> <groupId>com.rabbitmq ...

  10. thinkphp 5.0 “No input file specified”问题

    最近在用thinkphp5.0,想要试一下强制路由模式,却发现一直报错, 在网上一通乱找,最后发现是因为不能正确识别path_info造成的, 解决方案就是在 public目录下修改 ".h ...