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?
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).
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.
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.
In addition to the previous you can directly use
gdb -p <pid>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With