Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 336889

Summary: Re-attaching to a different binary does not work well with GDB <= 7.1
Product: [Tools] CDT Reporter: Marc Khouzam <marc.khouzam>
Component: cdt-debug-dsf-gdbAssignee: Project Inbox <cdt-debug-dsf-gdb-inbox>
Status: NEW --- QA Contact: Jonah Graham <jonah>
Severity: minor    
Priority: P3 CC: cdtdoug, pawel.1.piech
Version: 8.0   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Marc Khouzam CLA 2011-02-10 21:37:32 EST
When doing a local attach, we could allow the user to detach from the current process and attach to it again or to another process.

The detach action does not behave very well in that use-case.

This applies to all GDB versions (except maybe 7.2 where it may already be fixed because we handle multi-process)
Comment 1 Marc Khouzam CLA 2011-05-04 22:37:23 EDT
The detaching seems to work properly.  However, attaching to a different process after a detah does not seem to work properly.  When we do a local attach, we don't specify the binary but instead let GDB figure it out itself.  However, after a detach, if we attach again, GDB seems to re-use the same binary as for the first attach, even though it is attached to another process altogether.

I think we would need to explicitly set the binary in this case, like we do for non-attach session.

Note that this problem only happen for GDB < 7.2.  There is no problem for 7.2 probably because when we do an attach, we use a brand new inferior, which allows GDB to choose a new binary.
Comment 2 Marc Khouzam CLA 2011-05-04 22:42:29 EDT
(In reply to comment #1)
 
> I think we would need to explicitly set the binary in this case, like we do for
> non-attach session.

Setting the binary would require us to ask the user which binary to use.  A better solution would be to 'unset' the current GDB binary, which would allow GDB to automatically choose the new one. To do this, we can simply set the binary to nothing.

Just to make sure things are clear, this is how to reproduce the problem:
- start an attach session with GDB <= 7.1
- attach to any process
- detach from the process with the disconnect button
- press the connect button and choose a process with a _different_ binary
=> notice that the stack frame shows the old binary code, although the values of variables are from the new binary executing (with names from the old binary)
Comment 3 Marc Khouzam CLA 2011-05-04 22:57:47 EDT
Besides resetting the binary in GDB, we also need to stopTrackingBreakpoints because on the re-attach we will try to startTracking them again.
Comment 4 Marc Khouzam CLA 2011-05-04 23:00:26 EDT
Since this problem is only for GDB versions before 7.2, I won't spend more time on it.  With GDB 7.2 it works properly.