6

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
  • 367
  • 1
  • 4
  • 13
  • Welcome to SO. Please review [MCVE]. – 2785528 Jun 24 '16 at 22:04
  • Do you really build your program "test" in "/usr/local/sbin"? On my ubuntu system, that folder is owned by root, and takes root privileges to work in. You need a very good reason to risk working with root privileges. Please tell us how you compiled your program. The error you are getting says the 'test' executable is not found. So you need to find it, or build it. – 2785528 Jun 24 '16 at 22:05
  • What's the output of `file /usr/local/sbin/test` ? – Mark Plotnick Jun 24 '16 at 22:29
  • @DOUGLASO.MOEN "/usr/local/sbin" was just one of the locations i tried – humme1 Jun 25 '16 at 08:43
  • @Mark output was "Reading symbols from /usr/bin/test...(no debugging symbols found)...done." – humme1 Jun 25 '16 at 08:49
  • Anyway an answer down there resolved the problem – humme1 Jun 25 '16 at 08:50

4 Answers4

9

/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, ...
Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • Thanks a lot! That was really the case.64-bit system without 32-bit runtime support. Works fine now. – humme1 Jun 25 '16 at 08:54
  • @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? – PMat Sep 26 '17 at 22:11
  • @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. – Employed Russian Sep 26 '17 at 22:49
  • @EmployedRussian. Yes i am on a 64-bit linux and /lib64/ld-linux-x86-64.so.2 exists on my machine. – PMat Sep 26 '17 at 23:03
  • @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 – PMat Sep 26 '17 at 23:06
  • @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. – Employed Russian Sep 26 '17 at 23:08
  • @EmployedRussian sure https://stackoverflow.com/questions/46437172/gdb-failed-to-load-so-files-even-and-errors-no-such-file-or-directory – PMat Sep 26 '17 at 23:19
  • @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 Oct 28 '17 at 02:09
  • @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 – Lokesh Sanapalli Oct 28 '17 at 02:10
0

This worked for me: export SHELL = path

as in your case:

export SHELL=/usr/local/sbin/test

0

It may help you. Allow all users to execute the file like this before gdb.

chmod +x file 
-2

I had the same problem on centos7, and solved it by installing gdb8.1.

Jiri Tousek
  • 12,211
  • 5
  • 29
  • 43
sun
  • 183
  • 1
  • 5