首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GDB核心转储:崩溃后恢复argc argv值

GDB核心转储:崩溃后恢复argc argv值
EN

Stack Overflow用户
提问于 2011-08-11 02:10:00
回答 2查看 2.5K关注 0票数 2

在应用程序崩溃后,是否有可能恢复main的argv和argc参数的精确值?

我只需要在Linux上使用应用程序core-dump和gdb调试器。

EN

回答 2

Stack Overflow用户

发布于 2011-08-11 02:24:44

是,如果应用程序是使用调试信息编译的。在gdb中打开核心转储,找到包含main函数的框架。然后转到此帧并打印argvargc的值。下面是gdb会话示例。

代码语言:javascript
复制
[root@localhost ~]# gdb ./a.out core.2020
GNU gdb (GDB) 7.2
Copyright (C) 2010 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-pc-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /root/a.out...done.
[New Thread 2020]

warning: Can't read pathname for load map: Input/output error.
Reading symbols from /usr/lib/libstdc++.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libstdc++.so.6
Reading symbols from /lib/libm.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib/libm.so.6
Reading symbols from /lib/libgcc_s.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib/libgcc_s.so.1
Reading symbols from /lib/libc.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /lib/ld-linux.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib/ld-linux.so.2
Core was generated by `./a.out'.
Program terminated with signal 6, Aborted.
#0  0x0027b424 in __kernel_vsyscall ()
(gdb) bt
#0  0x0027b424 in __kernel_vsyscall ()
#1  0x00b28b91 in raise () from /lib/libc.so.6
#2  0x00b2a46a in abort () from /lib/libc.so.6
#3  0x007d3397 in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib/libstdc++.so.6
#4  0x007d1226 in ?? () from /usr/lib/libstdc++.so.6
#5  0x007d1263 in std::terminate() () from /usr/lib/libstdc++.so.6
#6  0x007d13a2 in __cxa_throw () from /usr/lib/libstdc++.so.6
#7  0x08048940 in main (argv=1, argc=0xbfcf1754) at test.cpp:14
(gdb) f 7
#7  0x08048940 in main (argv=1, argc=0xbfcf1754) at test.cpp:14
14              throw std::runtime_error("123");
(gdb) p argv
$1 = 1
(gdb) p argc
$2 = (char **) 0xbfcf1754
(gdb)
票数 2
EN

Stack Overflow用户

发布于 2011-08-11 02:21:17

看起来你需要从基础开始..!!

使用-g标志编译你的应用程序代码,确保你没有剥离它。

假设我想编译hello.c

代码语言:javascript
复制
gcc -c -g hello.c -o hello.o
gcc hello.o -o hello

现在,如果您不想调试

代码语言:javascript
复制
ulimit -c unlimited
./hello

当应用程序崩溃时,将生成一个核心文件。

要检查核心文件,请执行以下操作

代码语言:javascript
复制
"gdb ./hello core.$$$" this will list you your stack.

您还可以选择调试镜像gdb hello

在互联网上有很多关于GDB的东西,一定要浏览一下。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7015648

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档