5

I have running process but it's executable file has got deleted. If I try to attach gdb I got following error

/home/vivek/binary/releases/20120328101511/bin/app.exe (deleted): No such file or directory.

How can I attach gdb to this process ?

Sample Test case: Source code:

#include<stdio.h>
#include<stdlib.h>
int main(){
  for (;;){
    printf("Sleeping");
    sleep(1);
  }
}

compile it

 gcc main.cc -o a.out
 gcc main.cc -o b.out

Run ./a.out

Now from different terminal delete a.out. And fire gdb attach pgrep a.out file b.out It doesn't work.

GDB shows following error:

/tmp/temp/a.out (deleted): No such file or directory.
A program is being debugged already.  Kill it? (y or n) n
Program not killed.
Vivek Goel
  • 22,942
  • 29
  • 114
  • 186

2 Answers2

9

Try using /proc/<pid>/exe as the executable. It appears as a symbolic link these days, however, in the past it was possible to extract the deleted executable from it.

See Detecting deleted executables.

We can use following command to attach gdb

gdb <path-to-binary> <pid>
Vivek Goel
  • 22,942
  • 29
  • 114
  • 186
Maxim Egorushkin
  • 131,725
  • 17
  • 180
  • 271
2

You can't. GDB needs the symbol data that's in the executable and is not being loaded by the OS when running the program.

littleadv
  • 20,100
  • 2
  • 36
  • 50