2013-07-05 34 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。也許它是用調試符號編譯的,所以你實際上獲得了很多信息。