2013-07-05 30 views
0

如何调试在Linux上启动二进制文件引起的分段错误? 该二进制文件没有可用的源代码。一旦二进制启动就会出现分段错误

如何知道导致seg故障的二进制文件所做的系统调用。是否有任何可能有助于调试的实用工具?

+1

您可以尝试使用[valgrind](http://valgrind.org/info/tools.html#memcheck)运行可执行文件并查看它是否报告任何明显问题 –

+0

您正在运行的实际程序是什么? –

+0

我不同意reasosn来关闭它。 – alk

回答

5

strace your-program是否有帮助,它会打印出您的程序调用的所有系统调用的列表。

样本输出

% strace true 

 
    2  2 [main] true (2064) ********************************************** 
    83  85 [main] true (2064) Program name: C:\cygwin\bin\true.exe (windows pid 2064) 
    44  129 [main] true (2064) OS version: Windows NT-6.1 
    36  165 [main] true (2064) ********************************************** 
    145  310 [main] true (2064) sigprocmask: 0 = sigprocmask (0, 0x6123D468, 0x610FBA10) 
    183  493 [main] true 2064 open_shared: name shared.5, n 5, shared 0x60FF0000 (wanted 0x60FF0000), h 0x70, *m 6 
    27  520 [main] true 2064 heap_init: heap base 0x20000000, heap top 0x20000000, heap size 0x18000000 (402653184) 
    30  550 [main] true 2064 open_shared: name foo, n 1, shared 0x60FE0000 (wanted 0x60FE0000), h 0x68, *m 6 
    18  568 [main] true 2064 user_info::create: opening user shared for 'foo' at 0x60FE0000 
    17  585 [main] true 2064 user_info::create: user shared version 6467403B 
    36  621 [main] true 2064 fhandler_pipe::create: name \\.\dir\cygwin-c5e39b7a9d22bafb-2064-sigwait, size 164, mode PIPE_TYPE_MESSAGE 
    51  672 [main] true 2064 fhandler_pipe::create: pipe read handle 0x84 
    16  688 [main] true 2064 fhandler_pipe::create: CreateFile: name \\.\dir\cygwin-c5e39b7a9d22bafb-2064-sigwait 
    35  723 [main] true 2064 fhandler_pipe::create: pipe write handle 0x88 
    23  746 [main] true 2064 dll_crt0_0: finished dll_crt0_0 initialization 


5

除了什么被建议你也可以做到以下几点:

运行ulimit -c unlimited使核心倾倒,然后运行你的应用程序。

在segfaulting它应该做一个核心转储。

然后你可以运行gdb your_app core,在gdb里面运行backtrace。也许它是用调试符号编译的,所以你实际上获得了很多信息。