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 ...
随机推荐
- Spinner实现列表下拉功能
public class MainActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener { ...
- struts2之通配符映射
系统有n多个请求时候,不可能以一个action对应一个映射.可以用通配符映射将成百上千请求简化成一个通用映射. 通配符映射规则:1.若找到多个匹配,没有通配符的将胜出. 2.若指定的动作不存在,str ...
- magento 购物车 首页 显示
如何将购物车显示在你的首页 1.复制代码:<!--new block --> <block type="checkout/cart_sideb ...
- CAD从二进流加载数据(com接口VB语言)
主要用到函数说明: MxDrawXCustomFunction::ReadBinStreamEx 从二进流加载数据,详细说明如下: 参数 说明 IMxDrawBinStream* pBinStream ...
- PHP填坑
这里记录下最近PHP踩过的坑,很多都是语法性错误 (1)函数结尾忘记加: 例如匿名函数 <?php $show = function($value){ echo $value."你好& ...
- 查询条件中,不进sql语句 也不进后台bug
前端代码:本来代码中少写了value="1",后来加上value值之后,可以正常进方法 <div class="row"> <label cl ...
- [转]SAS盘和SATA盘之间的区别
很多人一提到SAS盘和SATA盘之后,首先想到的是接口方面的区别,SAS的接口速度比SATA高很多,所以认为SAS盘要比SATA盘快,性能高.其实,接口方面的区别并不是主要的,只是很小的一方面.那么, ...
- 关于MD5解密网站。www.cmd5.com
第一次听说这个网站,本人的名字居然也能够被解密,而且还是需要付费取得明文! 大家知道,md5加密是我们常用的加密方式,这个加密方式的好处在于不可逆.而且任何环境下算出的密文应该都是相同的,所以在大家登 ...
- <SpringMvc>入门二 常用注解
1.@RequestMapping @Target({ElementType.METHOD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME ...
- linux基础常用语句--新手
查询:ls查看全部内容:ls -n删除:rm -rf 文件名创建目录: mkdir解压:rpm -验证是否安装:rpm -p 文件名rpm -ivh --nodeps 不需要前置条件的安装查询当前路径 ...