1

如何调试在 Linux 上启动二进制文件导致的分段错误?该二进制文件没有可用的源代码。

如何知道导致段错误的二进制文件进行的系统调用。是否有任何调试实用程序可能会有所帮助?

4

2 回答 2

6

对你有strace your-program帮助吗?它将打印程序调用的所有系统调用的列表。

样本输出

% strace true

.

    2 2 [主] 真 (2064) ***************************************** *****
   83 85 [main] true (2064) 程序名称:C:\cygwin\bin\true.exe (windows pid 2064)
   44 129 [main] true (2064) 操作系统版本:Windows NT-6.1
   36 165 [主] 真(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:堆基数 0x20000000,堆顶 0x20000000,堆大小 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: 在 0x60FE0000 为“foo”打开用户共享
   17 585 [main] true 2064 user_info::create: 用户共享版本 6467403B
   36 621 [main] true 2064 fhandler_pipe::create: name \\.\dir\cygwin-c5e39b7a9d22bafb-2064-sigwait,大小 164,模式 PIPE_TYPE_MESSAGE
   51 672 [main] true 2064 fhandler_pipe::create: 管道读取句柄 0x84
   16 688 [main] true 2064 fhandler_pipe::create: CreateFile: 名称 \\.\dir\cygwin-c5e39b7a9d22bafb-2064-sigwait
   35 723 [main] true 2064 fhandler_pipe::create: 管道写入句柄 0x88
   23 746 [main] true 2064 dll_crt0_0:完成 dll_crt0_0 初始化


于 2013-07-05T07:37:15.787 回答
6

除了建议的内容之外,您还可以执行以下操作:

运行ulimit -c unlimited以启用核心转储,然后运行您的应用程序。

在发生段错误时,它应该进行核心转储。

然后你可以运行gdb your_app core并在 gdb run中运行backtrace。也许它是用调试符号编译的,所以你实际上得到了相当多的信息。

于 2013-07-05T07:42:01.110 回答