using gdb to debug c program
#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的更多相关文章
- 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 ...
- [Advance] How to debug a program (上)
Tool GDB Examining Memory (data or in machine instructions) You can use the command x (for “examine” ...
- gdb远程debug A syntax error in expression, near `variable)'.
今天调试有个linux环境的应用时,gdb提示A syntax error in expression, near `variable)'.,最后经查,gdb版本过低(比如7.2)或者源代码不匹配所致 ...
- Rocket - debug - TLDebugModuleInner - Program Buffer Access
https://mp.weixin.qq.com/s/EJVqw7JPjjaib68tENl5AQ 简单介绍TLDebugModuleInner中的Program Buffer Access. 1. ...
- Rocket - debug - TLDebugModuleInner - Program Buffer
https://mp.weixin.qq.com/s/kjhJJ3moRQzxHt6pJOXEgg 简单介绍TLDebugModuleInner中Program Buffer寄存器的实现. 1. pr ...
- 信息安全实验一:buffer-overflow
title: buffer-overflow date: 2016-01-10 14:17:17 categories: information-security tags: buffer-overf ...
- Linux GDB Debug
http://blog.jobbole.com/107925/ gdb 调试入门,大牛写的高质量指南 http://blog.jobbole.com/107759/ gdb是the GNU Debug ...
- 使用gcc -g编译,gdb调试时仍然存在“no debug symbols found”的错误
今天为调试一段代码,使用gcc将程序用-g选项重新编译.但是使用gdb进行debug时,仍然出现“no debug symbols found”的错误.仔细检查了一下Makefile,原来后面定义的连 ...
- mac上eclipse用gdb调试(转)
mac上eclipse用gdb调试 With its new OS release, Apple has discontinued the use of GDB in OS X. Since 2005 ...
随机推荐
- [ HAOI 2008 ] 圆上的整点
\(\\\) Description 给出一个整数 \(r\) ,求圆 \(x^2+y^2=r^2\) 上的整点数. \(r\le 2\times 10^9\) \(\\\) Solution 神题. ...
- javascript异步下载 Promise实现
一般下载都是直接打开一个链接就行.var URL = 'XXXX';window.open(URL)其实这样会有些问题:1. 浏览器禁止打开新窗口,导致无法下载 那么怎么解决呢?这样: <a h ...
- Python之Pandas中Series、DataFrame实践
Python之Pandas中Series.DataFrame实践 1. pandas的数据结构Series 1.1 Series是一种类似于一维数组的对象,它由一组数据(各种NumPy数据类型)以及一 ...
- Python学习日记之中文支持
解决中文输出错误 在开头添加 # -*- coding: utf-8 -*- 即可
- JNDI链接SQLServer数据库步骤
1.配置context.xml文件 在我们的WebRoot目录下,就是和WEB-INF同级的目录下,新建一个META-INF的目录(假如不存在),在该目录下创建一个context.xml文件,并且在c ...
- centos上安装supervisor来管理dotnetcore等应用程序
supervisor 介绍: 这是一款用python编写的进程管理工具,可以守护他管理的所有进程,防止异常退出,以及提供一个可视化的web界面来手动管理,打开关闭重启各种应用,界面如下: 关于在cen ...
- 北大ACM(POJ1020-Anniversary Cake)
Question:http://poj.org/problem?id=1020 问题点:DFS. Memory: 260K Time: 47MS Language: C++ Result: Accep ...
- 15年第六届蓝桥杯第七题_(string)
手链样式 小明有3颗红珊瑚,4颗白珊瑚,5颗黄玛瑙.他想用它们串成一圈作为手链,送给女朋友.现在小明想知道:如果考虑手链可以随意转动或翻转,一共可以有多少不同的组合样式呢? 请你提交该整数.不要填写任 ...
- View Programming Guide for iOS
https://developer.apple.com/library/archive/documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/Wi ...
- 413 Request Entity Too Large报错处理
修改nginx配置 这是最简单的一个做法,着报错原因是nginx不允许上传配置过大的文件,那么件把nginx的上传大小配置调高就好. 1.打开nginx主配置文件nginx.conf,一般在 ...