GDB -x 选项

转载 2011年01月17日 14:26:00

http://hi.baidu.com/wrap/blog/item/910b4709841f1dc53bc76306.html

 

How to use gdb to catch exit situation for programs

Some times, our programs exit after running about days or months without any log information left for us to debug. It's really headache to determine where program is exit, unless enough logs are printed. Then that's the question: how can we resolve it now?

Here is a tips to do this:

We want to get the back-trace of function2 as it's exit with 1.
====================================
hickey@ubuntu:~/test$ cat exit.c
#include <stdlib.h>
int
function1(int i){
//abort();
}

int
function2(int i){
exit(1);
abort();
}
int
main() {

function1(1);
function2(2);
abort();
}
====================================

GDB file:
====================================
hickey@ubuntu:~/test$ cat gdb.ini
set logging on
handle SIGHUP nostop
handle SIGPIPE noprint nostop
b main
r
b _exit
c
bt full
quit
====================================

Result:
====================================
hickey@ubuntu:~/test$ gdb ./a.out -x gdb.ini
GNU gdb 6.8-debian
Copyright (C) 2008 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 "x86_64-linux-gnu"...
Breakpoint 1 at 0x40056e: file exit.c, line 16.

Breakpoint 1, main () at exit.c:16
16        function1(1);
Breakpoint 2 at 0x7fd1f7d7c090

Breakpoint 2, 0x00007fd1f7d7c090 in _exit () from /lib/libc.so.6
#0  0x00007fd1f7d7c090 in _exit () from /lib/libc.so.6
No symbol table info available.
#1  0x00007fd1f7d0a765 in exit () from /lib/libc.so.6
No symbol table info available.
#2  0x000000000040056a in function2 (i=2) at exit.c:10
No locals.
#3  0x0000000000400582 in main () at exit.c:17
No locals.
The program is running.  Exit anyway? (y or n) [answered Y; input not from terminal]
====================================

Another question, if we want to use gdb to attach an existing gdb that already attached with an application's pid, the solution is attach gdb with gdb and the attach application pid again:
====================================

1) gdb <gdb> <gdb_pid> in terminal
hickey@d001:~$ gdb gdb 12409

2) attach application pid
(gdb) attach 12415
A program is being debugged already.  Kill it? (y or n) y
Attaching to program: /usr/bin/gdb, process 12415
0x00000000004005d6 in ?? ()
(gdb) bt

3) then you got it with gdb
====================================

相关文章推荐

gcc命令与gdb命令常用选项

gcc命令用法: gcc [选项] [文件名]选项: -o filename:指定输出文件名称(含路径,可相对,可绝对) -c:只编译不链接,可生成目标文件 -S:只编译不汇编,生成汇编代码 -E:...

gdb命令和常用选项

用 gdb 调试 GCC 程序      Linux 包含了一个叫 gdb 的 GNU 调试程序. gdb 是一个用来调试     C 和 C++ 程序的强力调试器. 它使你能在程序运行时观察程序...

intel dpdk api makefile 编译选项修改 和 gdb 调试

声明:此文档只做学习交流使用,请勿用作其他商业用途 author:朝阳_tony E-mail : linzhaolover@gmail.com Create Date: 2013-8-6 17:07...

qtcreator-gdb-7.2-mingw-x86

  • 2016-05-18 00:21
  • 12.63MB
  • 下载

华为荣耀5X(畅玩版 全网通)USB调试模式如何开启教程(开发者模式 开发者选项打开)

作者:程序员小冰,CSDN博客:http://blog.csdn.net/qq_21376985, 前一段时间,公司买了一款华为荣耀畅玩版5X全网通,进行测试。发现 拿usb数据线连接PC电脑,无...

X.264常规选项设置

  • 2013-04-19 16:44
  • 22KB
  • 下载

Linux2.6.19.x内核编译配置选项详解

转载于:http://lamp.linux.gov.cn/Linux/kernel_options.html作者:金步国Code maturity level options代码成熟度选项Prompt...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)