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 ...
随机推荐
- 【hive】hive表很大的时候查询报错问题
线上hive使用环境出现了一个奇怪的问题,跑一段时间就报如下错误: FAILED: SemanticException MetaException(message:Exception thrown w ...
- jquery滚轮事件
// jquery 兼容的滚轮事件 $(document).on("mousewheel DOMMouseScroll", function (e) { var delta = ( ...
- Ubuntu 16.04安装Kate文本编辑工具
Kate支持很多语言,比如NASM,比SBL3低那么一点,但是比Gedit好. 安装: sudo apt-get install kate 启动: 额外配置: 1.安装Kwrite sudo apt- ...
- shim和polyfill有什么区别
在JavaScript的世界里,有两个词经常被提到,shim和polyfill.它们指的都是什么,又有什么区别? 一个shim是一个库,它将一个新的API引入到一个旧的环境中,而且仅靠旧环境中已有的手 ...
- tensorboard在windows系统浏览器显示空白的解决
一个简单的using_tensorboard.py程序,如下: #using_tensorboard.py import tensorflow as tf a = tf.constant(10,nam ...
- Shell script之How to write
Write shell script: 1) Editor like vi or mcedi 2) Set execute permission for your script chmod perm ...
- Android Measure 体系简单总结
Android对View的测量是半协商半强制半模糊半具体的. 测量过程中的两套尺寸体系: [半强制] ParentView**约束ChildView: **MeasureSpec(通过measure ...
- Intel Processor Exception Handling
当一个进程的行为超出预期时,系统将把它kill掉. On Intel IA-32 and Intel 64 architecture processors, each architecturally- ...
- java_IO_2
1.字节流 InputStream(抽象类) package ioStudy; import java.io.File; import java.io.FileInputStream; import ...
- 【INSERT】逐行提交、批量提交及极限提速方法
在Oracle数据库中,不是提交越频繁越好.恰恰相反,批量提交可以得到更好的性能.这篇文章给大家简单展示一下在Oracle数据库中逐行提交于批量提交两者之间的性能差别.最后再给出一种可以极大改变性能的 ...