Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to attach a process in gdb

Tags:

unix

gdb

I have a simple C program that forks a process and then runs an executable.

I want to attach the child process to gdb.

I run the main program in a console and open another console to find the pid of the child process, then I start gdb with the following command:

gdb attach 12271 

where 12271 is the child process id, but the attach fails with:

No such file or directory. 

Any idea why?

like image 609
as3rdaccount Avatar asked Jan 17 '13 01:01

as3rdaccount


People also ask

How do I attach a GDB to a running thread?

Just run a program with s few threads, run gdb and before running attach PROCESS_PID run strace in another console. You must see ptrace (PTRACE_ATTACH) for each thread. Show activity on this post. ptrace PTRACE_ATTACH sends SIGSTOP to the process which suspends the whole process i.e. all threads.


1 Answers

Try one of these:

gdb -p 12271 gdb /path/to/exe 12271  gdb /path/to/exe (gdb) attach 12271 
like image 175
Employed Russian Avatar answered Oct 11 '22 12:10

Employed Russian