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

Bug 300096

Summary: [expressions][run control][cdi] DSF is missing certain debug actions from editor's context menu
Product: [Tools] CDT Reporter: Navid Mehregani <nmehrega>
Component: cdt-debug-dsfAssignee: Marc Khouzam <marc.khouzam>
Status: RESOLVED FIXED QA Contact: Pawel Piech <pawel.1.piech>
Severity: enhancement    
Priority: P3 CC: john.cortell, ken.ryall, malaperle, marc.khouzam, pawel.1.piech
Version: 6.0Flags: john.cortell: review+
Target Milestone: 7.0   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Snapshot
none
Preliminary fix
marc.khouzam: iplog-
Final fix
marc.khouzam: iplog-
Further fix marc.khouzam: iplog-

Description Navid Mehregani CLA 2010-01-19 14:02:11 EST
- Start a DSF debug session
- Right click in the editor.  Notice the following debug actions are missing (these are all available in CDI-GDB):

  o Run to line
  o Move to line
  o Resume at line
  o Add Watch Expression...

Please see snapshot for more details.

I use the above actions quite frequently (especially 'Add Watch Expression').  When reading over code in editor, users want to see the value of an expression right away and this action makes it really convenient for them to do that.

The following bugzilla entries have been filed in the past regarding some of these actions:

bug#249165: Resume at line
bug#249162: Move to line (or Set PC here)

However, I couldn't find any bugzilla entries for the other actions.
Comment 1 Navid Mehregani CLA 2010-01-19 14:03:11 EST
Created attachment 156549 [details]
Snapshot
Comment 2 Marc Khouzam CLA 2010-02-11 10:06:20 EST
The DSF Disassembly view is also missing:
  o Run to line
  o Move to line
  o Resume at line

It should be relatively easy to fix both the editor and DSF Disassembly view at the same time.

Note that the DSF Disassembly view targetID is "#DisassemblyPartContext"
Comment 3 Marc Khouzam CLA 2010-02-11 16:01:15 EST
The missing "Add Watch Expression..." is being tracked by Bug 274951 so I will not do it as part of this bug.
Comment 4 Marc Khouzam CLA 2010-02-12 15:44:52 EST
Created attachment 159033 [details]
Preliminary fix

This patch adds the missing menus to the editor.
I still have to do the Disassembly view.
Comment 5 Marc Khouzam CLA 2010-02-12 21:35:11 EST
Created attachment 159054 [details]
Final fix

This fix is actually pretty simple.  The patch seems large because I've updated the MoveToLineActionDelegate and ResumeAtLineActionDelegate to match the latest RunToLineActionDelegate from the platform.

Also, I've copied EvaluationContextManager from cdt.debug.ui to a cdt.dsf.gdb.ui specific version that checks for a DSF debugger.  This class may be interesting in DSF itself.

Committed to HEAD.
Comment 6 Marc Khouzam CLA 2010-02-12 21:39:15 EST
John, can you review this change?  I'm trying to spread the reviews, and I think this one is something you have seen in CDI
Comment 7 John Cortell CLA 2010-02-15 11:49:13 EST
(In reply to comment #6)
> John, can you review this change?  I'm trying to spread the reviews, and I
> think this one is something you have seen in CDI

Marc, I tried Move to Line and it has a quirk. The relocated PC arrow does not appear at the new location unless I select the frame in the Debug view. The arrow disappears from the previous location, just doesn't appear in the new location.

Resume at Line has the same issue, but not Run to Line. It's a strange coincidence that the buggy behavior is in the delegates you updated and not in the one you didn't, so I'll let you investigate this before I review the changes.
Comment 8 Marc Khouzam CLA 2010-02-16 08:39:43 EST
(In reply to comment #7)
> (In reply to comment #6)
> > John, can you review this change?  I'm trying to spread the reviews, and I
> > think this one is something you have seen in CDI
> 
> Marc, I tried Move to Line and it has a quirk. The relocated PC arrow does not
> appear at the new location unless I select the frame in the Debug view. The
> arrow disappears from the previous location, just doesn't appear in the new
> location.

Thanks for trying it.

I wasn't able to reproduce this so I guess I don't understand what you mean.  What steps do you exactly do?  What I do is:

1- launch DSF-GDB
2- select a new line in the editor
3- right-click and select move-to-line

But I'm not sure when you don't have the frame selected.
Comment 9 John Cortell CLA 2010-02-16 09:01:24 EST
On Windows...
1. Launch DSF session
2. Program stops at main. Select the main frame in the Debug view if not already selected.
3. In the editor, right click on a line further down in main()
4. Select Move to Line
The PC arrow in the editor disappears from where it was but doesn't show up where you requested it move to.
5. Click on the main() frame in the Debug view. 
PC arrow now shows up in the editor, at the new location.
Comment 10 Marc Khouzam CLA 2010-02-16 09:30:28 EST
(In reply to comment #9)
> On Windows...
> 1. Launch DSF session
> 2. Program stops at main. Select the main frame in the Debug view if not
> already selected.
> 3. In the editor, right click on a line further down in main()
> 4. Select Move to Line
> The PC arrow in the editor disappears from where it was but doesn't show up
> where you requested it move to.
> 5. Click on the main() frame in the Debug view. 
> PC arrow now shows up in the editor, at the new location.

Thanks John.  I see this now.  It only happens with GDB's older than 7.0.  I had see this problem and I thought I had fixed it.  Maybe something fell out of my patch :-O

I'll let you know when it fixed.
Comment 11 Marc Khouzam CLA 2010-02-16 11:11:01 EST
John, do you have the platform debug plugins checked-out?
Surprisingly, when I close those two plugins, things work again.  Can you try?
Comment 12 John Cortell CLA 2010-02-16 11:23:28 EST
(In reply to comment #11)
> John, do you have the platform debug plugins checked-out?
> Surprisingly, when I close those two plugins, things work again.  Can you try?

Indeed, I do. And yes, when I close those plugins, the problem goes away. This may call for doing a diff between M5 and HEAD of those platform sources to see what change may be causing this.
Comment 13 Marc Khouzam CLA 2010-02-16 11:25:56 EST
(In reply to comment #12)
> (In reply to comment #11)
> > John, do you have the platform debug plugins checked-out?
> > Surprisingly, when I close those two plugins, things work again.  Can you try?
> 
> Indeed, I do. And yes, when I close those plugins, the problem goes away. This
> may call for doing a diff between M5 and HEAD of those platform sources to see
> what change may be causing this.

Sigh... That's what I did for CDT, when I ran out of things that were different, and closed my platform plugins :-)
I'll try diffing the platform.
Comment 14 Marc Khouzam CLA 2010-02-16 14:10:40 EST
(In reply to comment #13)

The problem was introduced in bug 299958 but I have not idea why.
I'm hoping Pawel will know?
Comment 15 Pawel Piech CLA 2010-02-16 19:54:12 EST
(In reply to comment #14)
> The problem was introduced in bug 299958 but I have not idea why.
> I'm hoping Pawel will know?
After investigating a bit, I think the problem is on the GDB side.  

In short: 
The reason the IP is never painted, is because the "move to line" operation does not generate a suspended event for a thread.  It does generate a suspended event for the process, which causes the view to refresh the contents, but its not enough to cause the selection in the view.  Bug 299958 fixed an issue (among other things) where a selection event was being generated way too often.  This bug was introduced in 3.6 M4.

The long explanation:
The debug view has historically painted the IP in editor in response to a stack frame being selected in Debug view, either as a result of a suspended event on a thread or by user action.  This behavior works well in most scenarios, but it's particularly buggy when it comes to handling the "Set PC to Here" action.  I've spent many hours fixing this behavior in our product (when it was not DSF based), but there were always some edge cases where it didn't work, because we were generating an artificial running/suspend event pair at the high level... which didn't always clear the caches as needed.  

The simplest way to fix this would be for MIRunControl to track on which thread the set-pc-to-here action was performed, and add this information to the container suspended event.  


A more sophisticated way to fix this would be to override platform's handling of when the IP is painted in the editor.  Then you could customize it so that it re-paints the IP upon a container-suspended-event without a trigger thread.  Doing this would also allow us to fix bug 225919.
Comment 16 Marc Khouzam CLA 2010-02-24 15:23:08 EST
Created attachment 160115 [details]
Further fix

(In reply to comment #15)
> (In reply to comment #14)
> > The problem was introduced in bug 299958 but I have not idea why.
> > I'm hoping Pawel will know?
> After investigating a bit, I think the problem is on the GDB side.

Thanks a lot Pawel for your explanation, it helped a lot.

> The simplest way to fix this would be for MIRunControl to track on which thread
> the set-pc-to-here action was performed, and add this information to the
> container suspended event.  

The attached patch does this.  I was able to extract the thread context from the context that was used to perform the CLI command ('jump').

However, the problem remains when doing a RunControl command from the gdb console, such as 'next'.  In this case, we don't have the current context.

Is there a way to obtain the current debug context when I'm not in a UI plugin?

> A more sophisticated way to fix this would be to override platform's handling
> of when the IP is painted in the editor.  Then you could customize it so that
> it re-paints the IP upon a container-suspended-event without a trigger thread. 
> Doing this would also allow us to fix bug 225919.

I posted a patch for bug 225919 to get this started.  We already override Platform's handling of the IP stuff in DsfSourceDisplayAdapter, but I think we have to agree on how we want to handle the IP before making big changes.  I'll leave this for bug 225919.
Comment 17 Marc Khouzam CLA 2010-02-24 15:28:38 EST
John, you can now review this bug :-)
Comment 18 Marc Khouzam CLA 2010-02-25 08:58:24 EST
MoveToLine still does not work perfectly in the case of multi-threaded programs.  I'm tracking the problem with bug 302597.

The current bug is actually properly solved since it is just about making the actions available in the menu
Comment 19 John Cortell CLA 2010-02-25 11:06:25 EST
(In reply to comment #18)
I'll be reviewing it this morning
Comment 20 Marc Khouzam CLA 2010-02-25 11:13:29 EST
(In reply to comment #19)
> (In reply to comment #18)
> I'll be reviewing it this morning

I just realized this bug is marked as DSF.  My solution is only for DSF-GDB.

I can move it to DSF if Pawel agrees.
Comment 21 Pawel Piech CLA 2010-02-25 13:36:48 EST
(In reply to comment #20)
> I can move it to DSF if Pawel agrees.
+1
Comment 22 John Cortell CLA 2010-02-25 14:18:06 EST
(In reply to comment #17)
> John, you can now review this bug :-)

Looks good. I just have the following minor comments:

1. Is there a practical advantage to calling IAdapterManager.hasAdapter() before calling IAdapterManager.loadAdapter()?

2. Class fields explicitly initialized to null (default value) is a personal pet peeve of  mine. They are unnecessary, but more importantly, they are a nuisance when stepping into the construction of the object.

3. I believe the use a WorkbenchJob is preferable to calling Disaply.asyncExec().
Comment 23 John Cortell CLA 2010-02-25 14:19:59 EST
(In reply to comment #21)
> (In reply to comment #20)
> > I can move it to DSF if Pawel agrees.
> +1

But we are planning on updating the solution to no be GDB specific, right? (The discussion Warren started)
Comment 24 Marc Khouzam CLA 2010-02-25 14:23:44 EST
(In reply to comment #23)
> (In reply to comment #21)
> > (In reply to comment #20)
> > > I can move it to DSF if Pawel agrees.
> > +1
> 
> But we are planning on updating the solution to no be GDB specific, right? (The
> discussion Warren started)

I thought we just wanted to move classes from DSF-GDB to DSF.  Is there more to do for Warren's request?
Comment 25 John Cortell CLA 2010-02-25 15:03:52 EST
(In reply to comment #24)
> (In reply to comment #23)
> > (In reply to comment #21)
> > > (In reply to comment #20)
> > > > I can move it to DSF if Pawel agrees.
> > > +1
> > 
> > But we are planning on updating the solution to no be GDB specific, right? (The
> > discussion Warren started)
> 
> I thought we just wanted to move classes from DSF-GDB to DSF.  Is there more to
> do for Warren's request?

Never mind. I think I might have misinterpreted your question to Pawel. 

Regardless, we are doing more than just moving classes, right? We talked about creating an IRunControl2 and using that instead of an MI specific DSF interface.
Comment 26 Marc Khouzam CLA 2010-02-25 15:15:45 EST
(In reply to comment #25)
> Regardless, we are doing more than just moving classes, right? We talked about
> creating an IRunControl2 and using that instead of an MI specific DSF
> interface.

True.
But we are crossing bugs :-)  The patch of this bug just deals with menus.  The actual performing of the moveToLine et al operations are in another bug, that should also be moved to DSF.
Comment 27 John Cortell CLA 2010-02-25 15:18:43 EST
> True.
> But we are crossing bugs :-)  The patch of this bug just deals with menus.  The
> actual performing of the moveToLine et al operations are in another bug, that
> should also be moved to DSF.

Ah...
Comment 28 Ken Ryall CLA 2010-02-25 16:01:01 EST
(In reply to comment #27)
> > True.
> > But we are crossing bugs :-)  The patch of this bug just deals with menus.  The
> > actual performing of the moveToLine et al operations are in another bug, that
> > should also be moved to DSF.
> 
> Ah...

That's bug 303968, working on it now.
Comment 29 Marc Khouzam CLA 2010-02-26 08:13:21 EST
(In reply to comment #28)
> (In reply to comment #27)
> > > True.
> > > But we are crossing bugs :-)  The patch of this bug just deals with menus.  The
> > > actual performing of the moveToLine et al operations are in another bug, that
> > > should also be moved to DSF.
> > 
> > Ah...
> 
> That's bug 303968, working on it now.

I'm not completely clear about this.  Will bug 303968 also cover moving the current bug changes to DSF?
Comment 30 Marc Khouzam CLA 2010-02-26 08:59:38 EST
(In reply to comment #18)
> MoveToLine still does not work perfectly in the case of multi-threaded
> programs.  I'm tracking the problem with bug 302597.

Just a note that bug 302597 has been resolved.
Comment 31 Marc Khouzam CLA 2010-02-26 09:17:39 EST
(In reply to comment #22)
> (In reply to comment #17)
> > John, you can now review this bug :-)
> 
> Looks good. I just have the following minor comments:

Thanks

> 1. Is there a practical advantage to calling IAdapterManager.hasAdapter()
> before calling IAdapterManager.loadAdapter()?

I copied it from that platform but I'm not familiar with this stuff.

> 2. Class fields explicitly initialized to null (default value) is a personal
> pet peeve of  mine. They are unnecessary, but more importantly, they are a
> nuisance when stepping into the construction of the object.

I never thought about it this way.  I'm from a C/C++ background where it was important to initialize fields.  Is it a general practice in Java to not initialize fields to their default value?  You have a point about the nuisance so I'll adopt that approach from now on.  Thanks
 
> 3. I believe the use a WorkbenchJob is preferable to calling
> Disaply.asyncExec().

I copied it from the platform.  Is there a reason why you recommend WorkbenchJob instead?
Comment 32 John Cortell CLA 2010-02-26 11:16:25 EST
(In reply to comment #31)
> > 2. Class fields explicitly initialized to null (default value) is a personal
> > pet peeve of  mine. They are unnecessary, but more importantly, they are a
> > nuisance when stepping into the construction of the object.
> 
> I never thought about it this way.  I'm from a C/C++ background where it was
> important to initialize fields.  Is it a general practice in Java to not
> initialize fields to their default value?  You have a point about the nuisance
> so I'll adopt that approach from now on.  Thanks

Most Java code I see follows that practice (not explicitly initializing fields to defaults). It helps keep clutter to a minimum, and makes debugging less cumbersome.

> > 3. I believe the use a WorkbenchJob is preferable to calling
> > Disaply.asyncExec().
> 
> I copied it from the platform.  Is there a reason why you recommend
> WorkbenchJob instead?

WorkbenchJob adds shutdown protection. Years ago I asked Darin why the platform debug code has Display.asycExec calls instead of WorkbenchJobs, and he said it's probably because the code I was looking at was written before WorkbenchJob was available (3.0) :-)
Comment 33 John Cortell CLA 2010-03-01 12:09:49 EST
Thanks for addressing my points.