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

Bug 311059

Summary: [launch] Process list shown during attach launch with gdb 6.8 has bogus entries
Product: [Tools] CDT Reporter: John Cortell <john.cortell>
Component: cdt-debug-dsf-gdbAssignee: John Cortell <john.cortell>
Status: RESOLVED FIXED QA Contact: Marc Khouzam <marc.khouzam>
Severity: normal    
Priority: P3 CC: marc.khouzam, pawel.1.piech
Version: 7.0Flags: marc.khouzam: review+
Target Milestone: 7.0   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Fix
john.cortell: iplog-, john.cortell: review+
Temporarily revert second half of fix
marc.khouzam: iplog-
Maybe better temporary fix marc.khouzam: iplog-

Description John Cortell CLA 2010-04-29 12:40:01 EDT
In my testing of attach launches, I noticed something bizarre with DSF-GDB and gdb 6.8. The program I was trying to attach to was called "sleep". I know there was only one such process running in the system, yet three "sleep" entries showed up in the process list dialog when I launched the attach session. 

This ended up being an interesting little combination of problems. 

The first was hard to catch in the code, The first appeared to be merely an inefficiency, but it turned out to have integrity consequences. The DSF service that returns the list of running processes natively ends up making redundant low level queries. That's not just inefficient. The list of processes running on a system tends to be in constant flux. Transient processes are constantly coming and going. The first query is used to cache the data, the second is used to respond to the request. So, later on, when the dialog ends up trying to display the names for the PIDs, we end up using data from two snapshots, and the two are not the same.

The second problem is that GDBProcesses.getExecutionData() ends up assuming that if the PID isn't found in its map, it should just use the binary filename. But that assumes the caller has requested the data for the inferior, which is not necessarily the case.
Comment 1 John Cortell CLA 2010-04-29 12:41:17 EDT
Created attachment 166519 [details]
Fix
Comment 2 John Cortell CLA 2010-04-29 12:42:14 EDT
Committed to HEAD. Marc, please review.
Comment 3 Marc Khouzam CLA 2010-04-29 13:01:28 EDT
!^%#$&%$!@#^$ 
ProcessList.getProcessList() does the work again every time?!?!

When you see an interface "IProcessList.getProcessList()" doesn't it give the impression is just a simple getter?  That method should have been called "generateProcessList()".

Anyway.
Great find John!

So, with this new information, couldn't we only request the IProcessList once and call getProcessList() each time we want a new list, instead of fetching IProcessList again?  Not a big deal though.

Also, you'll need to apply the same fix to you path of bug 310914 where you have one instance of calling getProcessList() in a loop.
Comment 4 Marc Khouzam CLA 2010-04-29 13:06:12 EDT
(In reply to comment #3)

> Also, you'll need to apply the same fix to you path of bug 310914 where you
> have one instance of calling getProcessList() in a loop.

Sorry, I was wrong about that.  The line
  for (IProcessInfo procInfo : list.getProcessList()) {
only makes the call once.
Comment 5 John Cortell CLA 2010-04-29 14:08:45 EDT
(In reply to comment #3)
> !^%#$&%$!@#^$ 
> ProcessList.getProcessList() does the work again every time?!?!
> 
> When you see an interface "IProcessList.getProcessList()" doesn't it give the
> impression is just a simple getter?  That method should have been called
> "generateProcessList()".

The interface was poorly named. No doubt about it.

> So, with this new information, couldn't we only request the IProcessList once
> and call getProcessList() each time we want a new list, instead of fetching
> IProcessList again?  Not a big deal though.

Hell, why isn't CCorePlugin.getProcessList() caching the instance? I guess since finding the provider is based on an extension point, and since  plugins are loaded dynamically, in theory there could be use case where we'd want to not assume that looking for it once is sufficient. I don't know. I have a feeling this is called so infrequently that it may not be worth risking a regression, even if it is unlikely.
Comment 6 Marc Khouzam CLA 2010-04-29 14:11:59 EDT
(In reply to comment #5)
> Hell, why isn't CCorePlugin.getProcessList() caching the instance? I guess
> since finding the provider is based on an extension point, and since  plugins
> are loaded dynamically, in theory there could be use case where we'd want to
> not assume that looking for it once is sufficient. I don't know. I have a
> feeling this is called so infrequently that it may not be worth risking a
> regression, even if it is unlikely.

Agreed.  Safer is better.
Comment 7 Marc Khouzam CLA 2010-04-29 14:37:30 EDT
Created attachment 166544 [details]
Temporarily revert second half of fix

(In reply to comment #0)

> The second problem is that GDBProcesses.getExecutionData() ends up assuming
> that if the PID isn't found in its map, it should just use the binary filename.
> But that assumes the caller has requested the data for the inferior, which is
> not necessarily the case.

The fix for that part does not work because of Bug 305385

I had to commit the attached patch to make things work again.
Comment 8 John Cortell CLA 2010-04-29 14:43:30 EDT
(In reply to comment #7)
> Created an attachment (id=166544) [details]
> Temporarily revert second half of fix
> 
> (In reply to comment #0)
> 
> > The second problem is that GDBProcesses.getExecutionData() ends up assuming
> > that if the PID isn't found in its map, it should just use the binary filename.
> > But that assumes the caller has requested the data for the inferior, which is
> > not necessarily the case.
> 
> The fix for that part does not work because of Bug 305385
> 
> I had to commit the attached patch to make things work again.

The inferior pid not being available is turning out to be quite a pain. There are two interrupt scenarios that are blocked with DSF-GDB because of it. And I don't like that this method you've reverted returns the project binary name no matter what unrecognized PID you give it. That can be pretty misleading. At least if it returns "unknown", it's not so bad. Can't the hack be moved higher up?
Comment 9 Marc Khouzam CLA 2010-04-29 14:46:53 EDT
(In reply to comment #8)

> The inferior pid not being available is turning out to be quite a pain. There
> are two interrupt scenarios that are blocked with DSF-GDB because of it. And I
> don't like that this method you've reverted returns the project binary name no
> matter what unrecognized PID you give it. That can be pretty misleading. At
> least if it returns "unknown", it's not so bad. Can't the hack be moved higher
> up?

what do you mean by higher up?
Comment 10 John Cortell CLA 2010-04-29 14:53:53 EDT
(In reply to comment #9)
> (In reply to comment #8)
> 
> > The inferior pid not being available is turning out to be quite a pain. There
> > are two interrupt scenarios that are blocked with DSF-GDB because of it. And I
> > don't like that this method you've reverted returns the project binary name no
> > matter what unrecognized PID you give it. That can be pretty misleading. At
> > least if it returns "unknown", it's not so bad. Can't the hack be moved higher
> > up?
> 
> what do you mean by higher up?

The caller (or somewhere up the callstack). If he gets an unknown process name, and he knows its the inferior, he should use the binary name. Of course, we are talking about a hack, here. I just think the hack where it is now is dangerous. Again, it tripped me up. I was seeing three 'sleep' processes and scratching my head. If I had seen a sleep process and two "unknown" ones, I would have done less scratching :-)
Comment 11 Marc Khouzam CLA 2010-05-03 09:11:12 EDT
Created attachment 166771 [details]
Maybe better temporary fix

How about this fix until bug 305385 is resolved?
I didn't commit it yet.
Comment 12 John Cortell CLA 2010-05-03 09:43:06 EDT
(In reply to comment #11)
> Created an attachment (id=166771) [details]
> Maybe better temporary fix
> 
> How about this fix until bug 305385 is resolved?
> I didn't commit it yet.

OK. I'm going to try to get to the bottom of this inferior PID thing this week if you don't have time. I know I punted last time but maybe I'll see things clearer this time around.
Comment 13 John Cortell CLA 2010-05-19 15:29:04 EDT
(In reply to comment #11)
> Created an attachment (id=166771) [details]
> Maybe better temporary fix
> 
> How about this fix until bug 305385 is resolved?
> I didn't commit it yet.

Mark, now that we have a patch for bug 305385, can you validate that this temporary fix is no longer necessary and back it out?
Comment 14 Marc Khouzam CLA 2010-05-21 08:43:15 EDT
(In reply to comment #13)
> (In reply to comment #11)
> > Created an attachment (id=166771) [details] [details]
> > Maybe better temporary fix
> > 
> > How about this fix until bug 305385 is resolved?
> > I didn't commit it yet.
> 
> Mark, now that we have a patch for bug 305385, can you validate that this
> temporary fix is no longer necessary and back it out?

We've had to pull out the fix for bug 305385 and it has been shelved due to low-value but high-risk.
Comment 15 CDT Genie CLA 2010-07-28 15:24:28 EDT
*** cdt cvs genie on behalf of jcortell ***
Bug 311059: Process list shown during attach launch with gdb 6.8 has bogus entries

[*] GDBProcesses.java 1.4 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBProcesses.java?root=Tools_Project&r1=1.3&r2=1.4
Comment 16 CDT Genie CLA 2010-07-28 15:24:35 EDT
*** cdt cvs genie on behalf of mkhouzam ***
 Bug 311059: workaround for another bug (305385) which is not fixed yet.

[*] GDBProcesses.java 1.5 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBProcesses.java?root=Tools_Project&r1=1.4&r2=1.5