【问题标题】:How do i a debug exec* = -1 ENOENT?我如何调试 exec* = -1 ENOENT?
【发布时间】:2018-02-26 13:10:29
【问题描述】:

我正在从程序集构建这个二进制文件,并尝试将它(可能很糟糕)与 libc 链接。但是我的程序无法启动,execve 可能无法找到某些东西。如何调试?

$ file ctime
ctime: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 3.2.0, not stripped

$ strace -f ./ctime
execve("./ctime", ["./ctime"], [/* 19 vars */]) = -1 ENOENT (No such file or directory)
fstat64(2, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0
write(2, "strace: exec: No such file or di"..., 40strace: exec: No such file or directory
) = 40
getpid()                                = 13784
exit_group(1)                           = ?
+++ exited with 1 +++

$ gdb ./ctime
GNU gdb (Raspbian 7.12-6) 7.12.0.20161007-git
Reading symbols from ./ctime...done.
(gdb) r
Starting program: ./ctime
/bin/bash: ./ctime: No such file or directory
During startup program exited with code 127.

【问题讨论】:

    标签: linux gdb exec strace


    【解决方案1】:

    如何调试它?

    man execve 中查看 ENOENT 错误的 ERRORS 部分:

    ENOENT The file filename or a script or ELF interpreter does not
          exist, or a shared library needed for the file or interpreter
          cannot be found.
    

    此错误最可能的原因之一是:“ELF 解释器不存在”。使用此命令查看二进制文件中 ELF 解释器的当前路径:

    readelf -l ctime | grep "Requesting program interpreter"
    

    很可能是您的程序在启动时找不到。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-25
      • 2015-02-25
      • 1970-01-01
      相关资源
      最近更新 更多