2011-08-10 25 views
2

在应用程序崩溃后,是否可以恢复主体的argv和argc参数的确切值?GDB核心转储:崩溃后恢复argc argv值

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

+0

最简单的方法就是别人做任何事情之前写argc'的'和一些文件中的值'argv',如果你那么在乎他们 –

回答

1

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

用-g标志编译你的应用程序代码,确保你不要去掉它。

说,如果我想编译的hello.c

gcc -c -g hello.c -o hello.o 
gcc hello.o -o hello 

现在如果你不想调试

ulimit -c unlimited 
./hello 

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

要检查核心文件

"gdb ./hello core.$$$" this will list you your stack. 

,你也可以选择调试图像 GDB你好

有超过约GDB互联网了很多东西,也通过他们去。

+0

是的,刚上去,通过回溯到主,你可以做'打印argc','x/4s * argv'或任何你想要的。 – user786653

2

是的,如果应用程序编译与调试信息。在gdb中打开core dump并找到包含main函数的框架。然后转到此框并输出argvargc的值。这里是示例gdb会话。

[[email protected] ~]# 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

也可以为非调试版本恢复argc和argv。如果这是OP真正需要的,我可以写出来。 –

+0

@雇用俄语:我会有兴趣知道!我有一个非调试核心转储,我想看看argv。 – misterbee

+0

@misterbee问这个问题,我会回答;-)请注意,答案是架构特定的,所以一定要说'x86_64',或'i686',或其他什么。 –