#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. [ HAOI 2008 ] 圆上的整点

    \(\\\) Description 给出一个整数 \(r\) ,求圆 \(x^2+y^2=r^2\) 上的整点数. \(r\le 2\times 10^9\) \(\\\) Solution 神题. ...

  2. ubantu MongoDB安装

    转 https://blog.csdn.net/flyfish111222/article/details/51886787 本博文介绍了MongoDB,并详细指引读者在Ubuntu下MongoDB的 ...

  3. Ubantu下 docker的安装

    另一种方法 1.切换到root权限或者用sudo 2.升级source列表并保证https和ca证书成功安装 # apt-get update # apt-get install apt-transp ...

  4. Struts工作机制

    Struts工作机制? 为什么要使用Struts?工作机制:Struts的工作流程:在web应用启动时就会加载初始化ActionServlet,ActionServlet从struts-config. ...

  5. Server 2008 R2 事件查看器实现日志分析

    在 windows server 2008 R2 中,可以通过点击 "开始" -> "管理工具" -> "事件查看器" ,来打开 ...

  6. vue具体页面跳转传参方式

    1.写数据,可以使用“.”,”[]”,以及setItems(key,value);3种方式. 例如: localStorage.name = proe;//设置name为" proe &qu ...

  7. java生成excel

    package test.poi; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStream; ...

  8. HDU_1561_The more, The Better_树型dp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1561 The more, The Better Time Limit: 6000/2000 MS (J ...

  9. C# HttpWebRequest Post Get 请求数据

    Post请求 1 //data 2 string cookieStr = "Cookie信息"; 3 string postData = string.Format("u ...

  10. localStorage前端存储数据

    <!DOCTYPE html> <html> <head> <title>localStorage演示</title> <meta c ...