Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I switch between different processes fork() ed in gdb?

Tags:

c

fork

gdb

I'm debugging such a multiple process application,

how can I switch between the fork()ed processes?

like image 288
wireshark Avatar asked Jun 03 '11 06:06

wireshark


People also ask

How do I set Follow Fork mode?

If you want to follow the child process instead of the parent process, use the command set follow-fork-mode . Set the debugger response to a program call of fork or vfork . A call to fork or vfork creates a new process.

How do I go to a specific function in GDB?

To execute one line of code, type "step" or "s". If the line to be executed is a function call, gdb will step into that function and start executing its code one line at a time. If you want to execute the entire function with one keypress, type "next" or "n".

How do I detach a process in GDB?

When you have finished debugging the attached process, you can use the detach command to release it from GDB control. Detaching the process continues its execution. After the detach command, that process and GDB become completely independent once more, and you are ready to attach another process or start one with run .


1 Answers

Show all the processes.

(gdb) info inferiors 
  Num  Description       Executable        
  1    process 1000      /tmp/a.out 
* 2    <null>            /tmp/a.out  # current attach inferior

Switch between different processes.

(gdb) inferior 1
[Switching to inferior 1 [process 1000] (/tmp/a.out)]
[Switching to thread 1.1 (LWP 1000)]
like image 52
thomascp Avatar answered Oct 07 '22 18:10

thomascp