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

Bug 338545

Summary: [Memory Browser] view doesn't update contents of memory tabs when debug context changes
Product: [Tools] CDT Reporter: Norman Yee <normankyee>
Component: cdt-memoryAssignee: cdt-debug-inbox <cdt-debug-inbox>
Status: ASSIGNED --- QA Contact: Jonah Graham <jonah>
Severity: normal    
Priority: P3 CC: alvaro.sanchez-leon, cdtdoug, jonah, marc.khouzam, Randy.Rohrbach
Version: 7.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
See Also: https://git.eclipse.org/r/84701
Whiteboard:
Attachments:
Description Flags
Patch for the bug fix.
none
Updated patch. Fixes a bug in which only the selected memory tab was updated. Now if you have multiple tabs, all tabs are updated.
none
Updated patch. Fixes bug in which the tab's rendering type wasn't preserved when the tab was updated..
none
Updated patch. It wasn't disposing the renderings and memory blocks properly. none

Description Norman Yee CLA 2011-03-01 10:20:19 EST
Build Identifier: I20110127-2034

After I launch a multi-core launch configuration, open a memory browser to view the memory contents in one of the cores, and then switch contexts in the debug view (e.g., switch from core A to core B), the memory contents in the memory browser view isn't updated for the new context.

I looked at the memory browser source code and updateTab() is eventually called from MemoryBrowser.debugContextChanged(), but updateTab() just saves the new context and doesn't fetch the memory for the new context and update the rendering.

Reproducible: Always

Steps to Reproduce:
1. launch a multi-core launch configuration (I am using our custom DSF debugger plugin)
2. in the debug view, select core A
3. open the memory browser view
4. type an address and click go to view some memory in core A
5. in the debug view, select core B.  the memory browser view is still showing the contents of core A.  it should be showing the contents of core B.
Comment 1 Norman Yee CLA 2011-03-01 10:23:10 EST
Created attachment 190041 [details]
Patch for the bug fix.
Comment 2 Norman Yee CLA 2011-03-03 15:38:37 EST
Created attachment 190307 [details]
Updated patch.  Fixes a bug in which only the selected memory tab was updated.  Now if you have multiple tabs, all tabs are updated.
Comment 3 Pawel Piech CLA 2011-03-03 18:20:55 EST
Randy, do you know if something has changed here?
Comment 4 Norman Yee CLA 2011-03-07 09:55:56 EST
Created attachment 190551 [details]
Updated patch.  Fixes bug in which the tab's rendering type wasn't preserved when the tab was updated..
Comment 5 Randy Rohrbach CLA 2011-03-07 13:04:13 EST
Folks

   I am using the latest from HEAD and I do not see this behavior. For 
   different debuggees, I see different list of expressions ( this  is
   work I applied from Alain Lee ). But I see the Memory Browser react
   to the selection changes in what seems appropriate manner,  keeping 
   the selected TABS on a per context basis. I looked at the patch and
   it seems OK in itself. I will apply it to my local space and see if
   it compiles and seems to work. 

   But I am not seeing the same negative behavior as described before,
   in this bugzilla. Could someone who does supply a short "Webex"  or
   some other recording of it occuring.

Randy
Comment 6 Marc Khouzam CLA 2011-03-07 13:20:31 EST
Here is what I do:

1- start a app with two threads with GDB (I used 7.2)
2- both threads run code that use a local variable with the same name (say 'i')
3- interrupt execution and select frame of thread 1 where 'i' is visible
4- open memory browser (not memory view) and put '&i' as the address
5- select thread 2 on the frame that has its own 'i' visible
=> I don't see the memory browser change.  If I press Go on the existing tab (with '&i'), then it changes.
Comment 7 Randy Rohrbach CLA 2011-03-07 13:50:28 EST
OK, I see the difference. I am using multiple launches, each with a single core.
Not a single launch with Multiple contexts.
Randy
Comment 8 Norman Yee CLA 2011-03-08 16:23:47 EST
Created attachment 190701 [details]
Updated patch.  It wasn't disposing the renderings and memory blocks properly.
Comment 9 Norman Yee CLA 2011-03-09 12:47:19 EST
Comment on attachment 190701 [details]
Updated patch.  It wasn't disposing the renderings and memory blocks properly.

This patch seems to cause a "Widget is diposed" exception, after I grabbed the latest CDT sources so I'm rolling it back.
Comment 10 Eclipse Genie CLA 2016-11-08 16:24:08 EST
New Gerrit change created: https://git.eclipse.org/r/84701
Comment 11 Jonah Graham CLA 2016-11-26 05:34:27 EST
On reviewing this fix and the bug I believe that there is a misunderstanding on my part as to the purpose of this bug.

Option 1) Changing debug context shows the wrong contents for the given address. That is the memory contents are wrong.

Option 2) The expressions is not reevaluated on changing context, so even though the memory contents are correct, the view is not showing the address of interest anymore. Comment 6 has steps for this option. 

If the problem you are seeing is Option 1, then the bug is actually not in the Memory Browser, but in the DSF model. The Memory Browser changes the visible tab folder based on the instance of IMemoryBlockRetrieval received by MemoryBrowser.updateTab(IMemoryBlockRetrieval, Object, String[]). Two threads on the same process share the same IMemoryBlockRetrieval, two different processes have their own IMemoryBlockRetrieval.

The MemoryBlockRetrievalManager is responsible for creating IMemoryBlockRetrieval for each context requiring its own unique one. The code in MemoryBlockRetrievalManager.eventDispatched(IStartedDMEvent) creates a new IMemoryBlockRetrieval for each IMemoryDMContext that is started in the debug session.

Norman, if the problem is Option 1, can you confirm that DMContexts with different memories are getting unique IMemoryDMContexts? If each core has its own DMContext, ensure that the core implements IMemoryDMContext. I have seen a situation (not in CDT code) where multi-cores are modelled in DMCs with a container DMC implementing IMemoryDMContext and the container contains the individual core's contexts. That would lead to this problem.


If the desire is to fix Option 2, then the current fix in https://git.eclipse.org/r/#/c/84701/2 fixes both of these cases by fully reevaluating the memory contents by repopulating everything. However, this comes at significant expense as "walking" the stack becomes very slow instead of nearly instantaneous. This is because each click on a stack frame is a change in DMContext. As a result a better solution for this is needed.

Thanks, Jonah
Comment 12 Marc Khouzam CLA 2016-11-26 06:13:02 EST
Jonah is right.

If we consider option 1, the IMemoryDMContext is associated to a process (GDBContainerDMC_7_4) because in our model all threads share the same memory.  So if the cores mentioned in this bug are modelled as threads, then the memory browser will not change when selecting a different core-thread.

Alvaro had worked on a patch to optionally move the IMemoryDMContext to the thread level for the case of cores.

As for option 2 (which was me confusing the original issue), when we deal with expressions, we evaluate them to an address and then keep that exact address as the memory shown.  This even happens after you restart eclipse.  I've never really like that but to fix it we need to address this root problem is pretty much forgetting that we are dealing with an expression.

My guess is that Norman's problem is option 1.

Alvaro, do you know what happened to the patch that moves the IMemoryDMC to the threads?
Comment 13 Norman Yee CLA 2016-12-09 14:05:15 EST
Thanks Jonah and Marc for feedback!

In our debug model, cores are modeled as threads and each core can have multiple memory spaces with each memory space having its own memory DM context.  From what Marc was saying, this would explain why we're not seeing the memory contents update when we click on a different core.

Jonah> Norman, if the problem is Option 1, can you confirm that DMContexts with different memories are getting unique IMemoryDMContexts? If each core has its own DMContext, ensure that the core implements IMemoryDMContext.

Yes, each memory space has its own unique IMemoryDMContext but our cores can't implement IMemoryDMContext because each core contains multiple memory spaces.

Marc> Alvaro had worked on a patch to optionally move the IMemoryDMContext to the thread level for the case of cores.

Would Alvaro's patch fix the problem we're seeing?
Comment 14 Alvaro Sanchez-Leon CLA 2016-12-09 15:52:52 EST
(In reply to Norman Yee from comment #13)
> Thanks Jonah and Marc for feedback!
> 
> In our debug model, cores are modeled as threads and each core can have
> multiple memory spaces with each memory space having its own memory DM
> context.  From what Marc was saying, this would explain why we're not seeing
> the memory contents update when we click on a different core.
> 
> Jonah> Norman, if the problem is Option 1, can you confirm that DMContexts
> with different memories are getting unique IMemoryDMContexts? If each core
> has its own DMContext, ensure that the core implements IMemoryDMContext.
> 
> Yes, each memory space has its own unique IMemoryDMContext but our cores
> can't implement IMemoryDMContext because each core contains multiple memory
> spaces.
> 
> Marc> Alvaro had worked on a patch to optionally move the IMemoryDMContext
> to the thread level for the case of cores.
> 
> Would Alvaro's patch fix the problem we're seeing?

I have an internal implementation similar to the one mentioned by Norman in  the sense that each core is modeled as a thread, then there are multiple memory spaces that apply to each core, so far it seems similar... 
  However this internal implementation allows you to either switch the  IMemoryDMContext to the thread level or to the process level, this is not currently a perfect solution as we may also have shared memory spaces between the cores..  The solution still works but you have the inconvenience to treat shared memory spaces as local causing it to not remember monitors, current location, etc.. 

  I had started looking into a different solution where we can allow IMemoryDMContext to be assigned to the thread level or process level depending on the memory space, I unfortunately have not had the change to go back to this effort but it would be great to know if this model would fit other targets.
Comment 15 Jonah Graham CLA 2017-04-05 04:54:05 EDT
From conversation on cdt-dev[1] I said:

Alvaro, would you be able to open source the code mentioned [1]?
Perhaps if it was open sourced Andrew and Norman could adapt it for
general purpose and contribute that back to CDT?


[1] http://dev.eclipse.org/mhonarc/lists/cdt-dev/msg31935.html