分离后附加到不同的程序
attach to a different program after detach
我在 emacs 中使用了 gud-gdb。首先,我附加到一个program1的PID 29514
(gdb) attach 29514
Attaching to program: program1
...
然后分离出来。
(gdb) detach
Detaching from program: program1, process 29514
然后我想用 pid 4917 编写另一个程序 program2。
(gdb) attach 4917
Attaching to program: program1, process 4917
Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done.
0x00007fbfc52604c0 in ?? ()
我们看到 GDB 仍然想使用 program1。有没有办法让gdb清除最后一个分离的程序?
我使用当前的主干 GDB 重现了此行为。
我认为这是一个错误:documentation 说:
"When you use attach, the debugger finds the program running in the process
first by looking in the current working directory, then (if the program
is not found) ..."
没有区分第一次和第二次attach,也没有说如果新进程与旧进程运行不同的程序,GDB将不会再次找到该程序。
您可以使用 file
命令解决此问题:
(gdb) attach $PID1
...
(gdb) detach
(gdb) file prog2 # you shouldn't have to do this
(gdb) attach $PID2 # works fine
我在 emacs 中使用了 gud-gdb。首先,我附加到一个program1的PID 29514
(gdb) attach 29514
Attaching to program: program1
...
然后分离出来。
(gdb) detach
Detaching from program: program1, process 29514
然后我想用 pid 4917 编写另一个程序 program2。
(gdb) attach 4917
Attaching to program: program1, process 4917
Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done.
0x00007fbfc52604c0 in ?? ()
我们看到 GDB 仍然想使用 program1。有没有办法让gdb清除最后一个分离的程序?
我使用当前的主干 GDB 重现了此行为。
我认为这是一个错误:documentation 说:
"When you use attach, the debugger finds the program running in the process
first by looking in the current working directory, then (if the program
is not found) ..."
没有区分第一次和第二次attach,也没有说如果新进程与旧进程运行不同的程序,GDB将不会再次找到该程序。
您可以使用 file
命令解决此问题:
(gdb) attach $PID1
...
(gdb) detach
(gdb) file prog2 # you shouldn't have to do this
(gdb) attach $PID2 # works fine