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

Bug 248636

Summary: [memory] Memory service does not properly use the MemoryContext to select the proper process
Product: [Tools] CDT Reporter: Marc Khouzam <marc.khouzam>
Component: cdt-debug-dsf-gdbAssignee: Pawel Piech <pawel.1.piech>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: cdtdoug, dd.general-inbox, pawel.1.piech
Version: 0 DD 1.1Flags: cdtdoug: iplog-
Target Milestone: DD 1.1   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
Original suggested fix
none
Propposed fix
none
Final fix
cdtdoug: iplog-
Improved fix cdtdoug: iplog-

Description Marc Khouzam CLA 2008-09-25 14:00:14 EDT
This bug addresses bug 241317 comment #1 and bug 241317 comment #2, which basically say that before sending Memory MI commands to GDB, the proper process must be selected/specified.
Comment 1 Marc Khouzam CLA 2008-10-07 09:51:04 EDT
Created attachment 114416 [details]
Original suggested fix

This patch has AbstractMIControl check if the context of a command is a container, and then choose a threadId belonging to that container.

I don't like this solution anymore :-)
1- they way to find a threadId is basically to get the list of threads within a process.  We already have this functionality; the problem is that for AbstractMIcontrol to use it, it needs a synchronous call to get those threadIds.  So, this patch introduces a synchronous getExecutionContexts().  This is not nice, I think.

2- This solution adds a --thread to every command that applies to a process.  However, I just realized that -exec-continue and -exec-interrupt will eventually have a --thread-group option to continue/interrupt a process.  The --thread flag is also valid for those two commands to continue/interrupt a single thread.  So, in this case, AbstractMIControl needs to behave differently, sigh...

Mutli-process is still evolving in MI and I'm hoping that these inconsistencies will be fixed.  Until then though, I find it quite difficult to reach an elegant solution.  Therefore, I will not apply this patch (which I attached for reference), but will instead write a patch that is tailored specifically to the memory commands.  Once multi-process extends to other commands, we can revisit this solution.
Comment 2 Pawel Piech CLA 2008-10-07 11:50:37 EDT
Wow, that's too bad.  At least you're discovering these things early on while they can still be corrected in GDB.
Comment 3 Marc Khouzam CLA 2008-10-07 16:29:57 EDT
Created attachment 114481 [details]
Propposed fix

This relatively small patch adds the --thread option to the two memory commands only which solved issue number 2 of comment #1.

As for issue 1 of comment #1, I couldn't get rid of it just yet ubt with M3 approaching I really didn't like this change in interface.

So, I thought I should make the interface change in a provisional interface, like a new IGDBProcesses.  To make all this happen, I had to override the MIMemory service with GDBMemory and GDBMemory_7_0.

The nice thing about this change is that the only non-provisional file that changes is MIMemory.

The JUnit tests pass, and I ran some successful tests on my multi-process GDB.

Opinions are appreciated.

P.S. I hesitated between two options within this design; the other option I looked at was to instead of giving an ExecutionContext to the Memory MI commands, I would continue to give a MemoryContext, and add a parameter for the threadId.  Doing it like that changes both MIDataReadMemory and MIDataWriteMemory, but it allows to keep the methods within the MemoryCache to only accept a MemoryDMContext instead of a generic IDMContext.  I didn't choose that option to avoid changing the two MI command classes, but I am still ambivalent about it.
Comment 4 Marc Khouzam CLA 2008-10-09 15:20:12 EDT
Created attachment 114708 [details]
Final fix

This is the fix I committed.
It should be easy to adapt once GDB stabilizes.
Comment 5 Marc Khouzam CLA 2008-10-09 15:22:57 EDT
Fixed.
Pawel, can you verify?
Comment 6 Pawel Piech CLA 2008-10-10 13:10:53 EDT
Reviewed.
Comment 7 Marc Khouzam CLA 2008-10-10 16:06:18 EDT
Created attachment 114833 [details]
Improved fix

I didn't like the fact that I had to make the MemoryCache visible to fix this bug.  I would have preferred to minimize the API changes.

So, this patch simply moves the methods I needed out of the memory cache so they could be overriden more easily.  Those methods did not really need to be in the memory cache anyway.  In my opinion, the memory cache does too much, which will lead to having to override it, as we had to here.  But for the sake of stability, I only moved what I needed out of the memory cache.  The memory cache is back to being private, and I was able to get rid of the ackward setMemoryCache() method.

JUnit tests all pass.

Committed.

Pawel, maybe you can have a quick look?
Comment 8 Pawel Piech CLA 2008-10-10 16:20:19 EDT
(In reply to comment #7)
Looks fine on a quick glance.

> ...  In my opinion, the memory cache does too much,
> which will lead to having to override it, as we had to here....

I agree.
Comment 9 Pawel Piech CLA 2009-01-07 15:58:55 EST
DD 1.1 reelased!