gdb During startup program exited with code 127

15,939

/bin/bash: /usr/local/sbin/test: No such file or directory

There are two common causes of this:

  1. the file /usr/local/sbin/test doesn't exist
  2. the file does exist, is a dynamically linked executable, and the ELF interpreter that it specifies does not exist.

For #1, the answer is obvious: you need a file to debug.

For #2, you can find out which ELF interpreter the file requires like so:

readelf -l /usr/local/sbin/test | grep interpreter

You likely have a 32-bit binary pointing to /lib/ld-linux.so.2 on a 64-bit system without 32-bit runtime support installed. Depending on the distribution you are using, something like sudo apt-get install libc6:i386 should do the trick.


Recent versions of the file command also print the interpreter:

file ./a.out 
./a.out: ELF 32-bit LSB executable, ... interpreter /lib/ld-linux.so.2, ...
Share:
15,939

Related videos on Youtube

humme1
Author by

humme1

Updated on September 15, 2022

Comments

  • humme1
    humme1 over 1 year

    Wanted to use gdb as a debugger in Linux Debian. Trying to run a binary I get this:

    (gdb) r
    Starting program: /usr/local/sbin/test 
    /bin/bash: /usr/local/sbin/test: No such file or directory
    During startup program exited with code 127.
    (gdb) 
    

    I guess it's supposed to be elementary. But I googled a lot and most common answer is

    $ export SHELL=/bin/bash
    

    This doesn't help. I also tried to change PATH for binaries execution, tried to run from different directory... Still the same.

    Could you please help me with that?

  • humme1
    humme1 almost 8 years
    Thanks a lot! That was really the case.64-bit system without 32-bit runtime support. Works fine now.
  • PMat
    PMat over 6 years
    @humme1 I have the same problem, but mine is 64bit binary so the output of above command is [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]. Any idea?
  • Employed Russian
    Employed Russian over 6 years
    @PMat Are you running this binary on a 64-bit Linux system? Approximately nothing should work on it if ld-linux-x86-64.so.2 is missing.
  • PMat
    PMat over 6 years
    @EmployedRussian. Yes i am on a 64-bit linux and /lib64/ld-linux-x86-64.so.2 exists on my machine.
  • PMat
    PMat over 6 years
    @EmployedRussian that was confusing, I installed the above package anyways, now gdb loads the binary but it says can't find the so files even though there are in the solib-search-path
  • Employed Russian
    Employed Russian over 6 years
    @PMat You should probably ask a separate question, with details of what is installed on your system, what exactly you observe, whether the program runs outside of GDB, etc. etc.
  • PMat
    PMat over 6 years
  • Lokesh Sanapalli
    Lokesh Sanapalli over 6 years
    @EmployedRussian Hi, struggling with same problem, libc6:i386 is already installed, set SHELL env, build-essential is already the latest version. Tried everything, but nothing worked out. Please help
  • Lokesh Sanapalli
    Lokesh Sanapalli over 6 years
    @PMat Hi, struggling with same problem, libc6:i386 is already installed, set SHELL env, build-essential is already the latest version. Tried everything, but nothing worked out. Please help