如何在gdb中附加多个正在运行的进程?

时间:2014-12-17 14:02:10

标签: c unix gdb

如何在gdb中附加多个正在运行的进程? 将进程附加到gdb,gdb无法附加第二个进程。

1 个答案:

答案 0 :(得分:10)

你可以添加另一个劣等。

以下是gdb会话示例:

ks@ks-comp:~$ sleep 1d &
[1] 2917
ks@ks-comp:~$ 
ks@ks-comp:~$ sleep 2d &
[2] 2919
ks@ks-comp:~$ 
ks@ks-comp:~$ gdb -q
(gdb) attach 2919
Attaching to process 2919
Reading symbols from /bin/sleep...(no debugging symbols found)...done.
Reading symbols from /lib/x86_64-linux-gnu/libc.so.6...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/libc-2.19.so...done.
done.
Loaded symbols for /lib/x86_64-linux-gnu/libc.so.6
Reading symbols from /lib64/ld-linux-x86-64.so.2...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/ld-2.19.so...done.
done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
0x00007f81492999a0 in __nanosleep_nocancel () at ../sysdeps/unix/syscall-template.S:81
81  ../sysdeps/unix/syscall-template.S: No such file or directory.
(gdb) add-inferior 
Added inferior 2
(gdb) inferior 2
[Switching to inferior 2 [<null>] (<noexec>)]
(gdb) attach 2917
Attaching to process 2917
Reading symbols from /bin/sleep...(no debugging symbols found)...done.
Reading symbols from /lib/x86_64-linux-gnu/libc.so.6...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/libc-2.19.so...done.
done.
Loaded symbols for /lib/x86_64-linux-gnu/libc.so.6
Reading symbols from /lib64/ld-linux-x86-64.so.2...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/ld-2.19.so...done.
done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
0x00007f159f0d29a0 in __nanosleep_nocancel () at ../sysdeps/unix/syscall-template.S:81
81  ../sysdeps/unix/syscall-template.S: No such file or directory.
(gdb) i inferiors 
  Num  Description       Executable        
* 2    process 2917      /bin/sleep        
  1    process 2919      /bin/sleep        
(gdb) 

请参阅Debugging Multiple Inferiors and Programs