Bug 412547 - Selection is lost when stepping over "pthread_create" for gdbserver sessions
Summary: Selection is lost when stepping over "pthread_create" for gdbserver sessions
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-debug-dsf-gdb (show other bugs)
Version: 8.2   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 8.3.0   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact: Marc Khouzam CLA
URL:
Whiteboard:
Keywords:
: 423898 (view as bug list)
Depends on:
Blocks:
 
Reported: 2013-07-08 15:31 EDT by Nobody - feel free to take it CLA
Modified: 2014-01-13 14:58 EST (History)
3 users (show)

See Also:


Attachments
Test project. (31.71 KB, application/gzip)
2013-07-09 11:36 EDT, Nobody - feel free to take it CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nobody - feel free to take it CLA 2013-07-08 15:31:08 EDT
When debugging a multi-threaded application using gdbserver and stepping over "pthread_create" the newly created thread causes the change of selection from the stepping thread to the "target" element. This doesn't happen when debugging the same application locally.
The difference is the order in which the "running", "thread-created" and "stopped" events appear in GDB.

In case of the local session the order is
1. running
2. thread-created
3. stopped

For remote sessions
1. running
2. stopped
3. thread-created
Comment 1 Nobody - feel free to take it CLA 2013-07-09 11:36:18 EDT
Created attachment 233282 [details]
Test project.

Attaching a test case.
Comment 2 Nobody - feel free to take it CLA 2013-07-09 16:15:32 EDT
Currently the threads are displayed in the Debug view in the same order as they are fetched from GDB: the first thread appears at the bottom of the list and each newly created thread is added to the top of the list. Reversing this order makes the problem disappear. Moreover, only the first thread remains expanded when stepping, while currently the top thread gets expanded too.
Interestingly the threads are sorted in "MIThreadListIdsInfo" but not in "MIThreadInfoInfo". I have pushed a simple patch that adds sorting to "MIThreadInfoInfo" to Gerrit - https://git.eclipse.org/r/#/c/14415/.
Marc, could you please review?
Comment 3 Marc Khouzam CLA 2013-07-10 16:43:44 EDT
(In reply to comment #2)
> Currently the threads are displayed in the Debug view in the same order as
> they are fetched from GDB: the first thread appears at the bottom of the
> list and each newly created thread is added to the top of the list.
> Reversing this order makes the problem disappear. 

I can see the problem too.

Making this reverse order change is kind of a big deal though, as it changes the behaviour quite visibly for the user.

If there was a simpler solution that kept the same order, that would be easiest.  If, on the other hand, sorting the threads is something we feel is better for the user, then we can go that way, but I don't think we should make this decision without considering the impacts.

Do you actually find the proposed solution better, if we ignore the selection bug?
Comment 4 Nobody - feel free to take it CLA 2013-07-10 16:59:10 EDT
(In reply to comment #3)
> (In reply to comment #2)
> > Currently the threads are displayed in the Debug view in the same order as
> > they are fetched from GDB: the first thread appears at the bottom of the
> > list and each newly created thread is added to the top of the list.
> > Reversing this order makes the problem disappear. 
> 
> I can see the problem too.
> 
> Making this reverse order change is kind of a big deal though, as it changes
> the behaviour quite visibly for the user.
> 
> If there was a simpler solution that kept the same order, that would be
> easiest.  If, on the other hand, sorting the threads is something we feel is
> better for the user, then we can go that way, but I don't think we should
> make this decision without considering the impacts.
> 
> Do you actually find the proposed solution better, if we ignore the
> selection bug?

I do think that displaying the threads in order of their appearance is better. The other side effect of this patch is the newly created threads are not expanded, the view is more compact and no unnecessary editor tabs are opened.
Also, as I already mentioned, the debugger versions that use "-thread-list-ids" are sorted.
There is a chance that it's a bug in GDB, that the "thread-created" event should appear before the "stopped" event as it does for the local version.
Comment 5 Marc Khouzam CLA 2013-07-12 10:06:01 EDT
(In reply to comment #4)

> I do think that displaying the threads in order of their appearance is
> better. The other side effect of this patch is the newly created threads are
> not expanded, the view is more compact and no unnecessary editor tabs are
> opened.

> Also, as I already mentioned, the debugger versions that use
> "-thread-list-ids" are sorted.

Doh!
Looks like the reverse order of threads we see with newer GDB version is a bug in CDT, as described in Bug 225996.

Ok then, based on that, let's go with the ordering with new threads at the bottom.
To track this better can we open a new bug about the ordering?  I find the current bug to be a side-effect only of the real change you are making.

Also, what do you think about sorting the threads in the services instead of the MI output files?  It sounds more future-proof to me.
Comment 6 Nobody - feel free to take it CLA 2013-08-06 14:02:17 EDT
(In reply to comment #5)
> Also, what do you think about sorting the threads in the services instead of
> the MI output files?  It sounds more future-proof to me.

My first intention was to do the sorting in the services and it is the right thing to do. The problem is "MIThreadInfoInfo" is used in so many places it is hard to track whether we really need to do the sorting or not. I also did it in the same way as it is done for MIThreadListIds.
Comment 7 Frank Morauf CLA 2013-12-12 06:31:04 EST
*** Bug 423898 has been marked as a duplicate of this bug. ***
Comment 8 Marc Khouzam CLA 2014-01-03 13:55:06 EST
Mikhail, should we commit the fix you posted for this bug?
Comment 9 Nobody - feel free to take it CLA 2014-01-03 14:32:59 EST
(In reply to Marc Khouzam from comment #8)
> Mikhail, should we commit the fix you posted for this bug?

We haven't agreed on where to do the sorting. If you are OK with my patch then yes.
Comment 10 Marc Khouzam CLA 2014-01-03 14:40:01 EST
(In reply to Mikhail Khodjaiants from comment #9)
> (In reply to Marc Khouzam from comment #8)
> > Mikhail, should we commit the fix you posted for this bug?
> 
> We haven't agreed on where to do the sorting. If you are OK with my patch
> then yes.

I'm ok with it.  We've delayed this long enough :)
Comment 11 Nobody - feel free to take it CLA 2014-01-03 15:17:22 EST
(In reply to Marc Khouzam from comment #10)
> (In reply to Mikhail Khodjaiants from comment #9)
> > (In reply to Marc Khouzam from comment #8)
> > > Mikhail, should we commit the fix you posted for this bug?
> > 
> > We haven't agreed on where to do the sorting. If you are OK with my patch
> > then yes.
> 
> I'm ok with it.  We've delayed this long enough :)

Thanks. I'll update the patch in Gerrit and apply it.
Comment 12 Nobody - feel free to take it CLA 2014-01-13 14:58:00 EST
Checked in. Thanks Marc.