#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. LN : leetcode 513 Find Bottom Left Tree Value

    lc 513 Find Bottom Left Tree Value 513 Find Bottom Left Tree Value Given a binary tree, find the lef ...

  2. [Windows Server 2003] 初识Windows Server 2003

    ★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com ★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频. ★ 本节我们将带领大家:初次见识W ...

  3. Java学习1_一些基础1——16.5.4

    每个java程序中都必须有一个main方法,格式为: public class ClassName { public static void main(String[] args) { program ...

  4. CAD使用SetxDataDouble写数据(网页版)

    主要用到函数说明: MxDrawEntity::SetxDataDouble 写一个Double扩展数据,详细说明如下: 参数 说明 [in] BSTR val 字符串值 szAppName 扩展数据 ...

  5. Ubuntu搭建LAMP开发环境

    1.安装Apache sudo apt-get install apache2 测试: 浏览器访问 (如:http://localhost),出现It Works!网页. 查看状态: service ...

  6. Oracle中的COALESCE,NVL,NVL2,NULLIF函数

    http://jingyan.baidu.com/article/fa4125acaf898e28ac7092b9.html

  7. [Python数据结构] 使用 Circular List实现Queue

    [Python数据结构] 使用 Circular List实现Queue 1. Queue队列,又称为伫列(queue),是先进先出(FIFO, First-In-First-Out)的线性表.在具体 ...

  8. 移动端placeholder不能垂直居中解决方案

    1.问题描述 问题如图:手机端placeholder文字偏上,垂直方向不居中,input光标显示偏上解决IE下不支持placeholder属性 2.解决方案 css .phoneNumber inpu ...

  9. Java 中 break和 continue 的使用方法及区别

    break break可用于循环和switch...case...语句中. 用于switch...case中: 执行完满足case条件的内容内后结束switch,不执行下面的语句. eg: publi ...

  10. 洛谷 1894 [USACO4.2]完美的牛栏The Perfect Stall

    [题解] 其实是个二分图最大匹配的模板题,直接上匈牙利算法就好了. #include<cstdio> #include<algorithm> #define N 1010 #d ...