Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

start gdb using a pid

Tags:

c

process

gdb

dbx

In general i see the process's pid which is running in the background and start dbx on that process using the command dbx -a <pid>

similarly how could i do it using gdb?

like image 517
Vijay Avatar asked Jan 28 '10 05:01

Vijay


People also ask

How do I start GDB?

Use the run command to start your program under gdb. You must first specify the program name (except on VxWorks) with an argument to gdb (see Getting In and Out of gdb), or by using the file or exec-file command (see Commands to Specify Files).

How run GDB in Linux?

To start the debugger of the above gfg executable file, enter the command gdb gfg. It opens the gdb console of the current program, after printing the version information. run [args] : This command runs the current executable file.

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.


2 Answers

In addition to the previous you can directly use

gdb -p <pid> 
like image 91
zakkak Avatar answered Oct 10 '22 10:10

zakkak


There are two ways.

From the command line, include the pid as an argument after the executable name:

gdb /path/to/prog PID 

From within gdb, you can use the attach command:

gdb /path/to/prog gdb> attach PID 

While the specifying on the command line is more concise, there is a slight risk that if you have a core file that has a name that is the same as the pid (i.e. for pid 2345, the core file would have to be named "2345") then gdb will open the core file. Admittedly, the chance of this happening is minuscule.

like image 21
R Samuel Klatchko Avatar answered Oct 10 '22 08:10

R Samuel Klatchko