#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. Linux shell命令之cat

    cat:查看文件的内容.连接文件.创建一个或多个文件和重定向输出到终端或文件  用法:cat [选项] [文件] 1. $ cat hello.txt 显示hello.txt文本文件中的内容 2. $ ...

  2. 往文件内写入内容(java)

    新建个工具类,并标记成静态的,方便调用. package util; import java.io.File;import java.io.FileOutputStream; public class ...

  3. Flask Web 发送邮件单文件

    import os from flask import Flask, render_template, session, redirect, url_for from flask_script imp ...

  4. java读取03、07版EXCEL

    03版excel,需要用到jxl.jar这个jar包 package test.poi; import java.io.File; import java.io.IOException; import ...

  5. 服务器 获取用户 真实ip

    在有代理的情况下,因为要代替客户端去访问服务器,所以,当请求包经过反向代理后,在代理服务器这里这个IP数据包的IP包头做了修改,最终后端WEB服务器得到的数据包的头部源IP地址是代理服务器的IP地址. ...

  6. block: cfq 学习01

    CFQ,即Completely Fair Queueing绝对公平调度器,力图为竞争块设备使用权的所有进程分配一个等同的时间片,在调度器分配给进程的时间片内,进程可以将其读写请求发送给底层块设备,当进 ...

  7. 一个简单的java年龄计算器

    制作一个如下图年龄计算器 根据题目,我做了一个由Calendar类以及年月日各相减得到的年龄,当然正确的方法不止一个,以下为我的源代码和结果截图: package com.Date; import j ...

  8. c++函数进阶

    c++扩展了c语言的函数功能.通过将incline关键字用于函数定义,并在首次调用该函数前提供其函数定义,可以使得c++编译器将该函数视为内联函数.也就是说,编译器不是让程序跳到独立的代码段,以执行函 ...

  9. C++/C union使用记一下锅

    //首先,学习编程一定要记得加几个群或者加几个讨论组,因为这样你才能不断地进步还有吵架/滑稽 记一下 关于使用union结构体时遇到的一些坑 To zero-initialize an object ...

  10. Object类型转换为String类型

    1. Object.toString() 1 obj.toString() 注意:必须保证Object不是null值,否则将抛出NullPointerException异常. 2. (String)O ...