Bug 498782 - [debug] synchronize selection between the Debug View and gdb
Summary: [debug] synchronize selection between the Debug View and gdb
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-debug-dsf-gdb (show other bugs)
Version: Next   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-07-28 11:02 EDT by Marc Dumais CLA
Modified: 2020-09-04 15:24 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marc Dumais CLA 2016-07-28 11:02:45 EDT
With the upcoming improved GDB debug console, it will become more important that the Debug View selection be kept in sync with the state of the GDB used as back-end, and vice versa. 

This will make the workflow better, for users who want to use both the CDT UI and the console, in a complementary way, for debugging.
Comment 1 Eclipse Genie CLA 2016-08-19 06:41:23 EDT
New Gerrit change created: https://git.eclipse.org/r/79336
Comment 2 Eclipse Genie CLA 2016-08-19 06:51:07 EDT
New Gerrit change created: https://git.eclipse.org/r/79337
Comment 3 Eclipse Genie CLA 2016-08-19 06:59:20 EDT
New Gerrit change created: https://git.eclipse.org/r/79339
Comment 4 Eclipse Genie CLA 2016-10-28 09:28:24 EDT
New Gerrit change created: https://git.eclipse.org/r/84099
Comment 5 Eclipse Genie CLA 2016-11-09 22:51:44 EST
New Gerrit change created: https://git.eclipse.org/r/84775
Comment 8 Marc Khouzam CLA 2016-11-14 21:33:28 EST
To support the full GDB console, we need to use mi-async (used to be called 'target-async') with all-stop mode.  With mi-async, CDT is able to and does send commands to GDB when the inferior is running.  The patch is under review now at https://git.eclipse.org/r/#/c/84382/

With mi-async, when testing an automatic remote session with all-stop, Alvaro and I tried leaving the inferior running.  In that case, the thread node was still being shown and when selecting it, we noticed that gdb was rejecting the -thread-select command.

This does not happen with non-stop.

To reproduce:
1- apply the review mentioned above (unless it has been committed already)
2- launch an automatic debug session with GDB 7.12 and all-stop
3- resume the program from CDT and let it continue to run
4- select the thread

We saw the following error:
936,592 [MI]  55-thread-select 1
936,593 [MI]  &"Cannot execute this command while the target is running.\n"
936,593 [MI]  &"Use the \"interrupt\" command to stop the target\n"
936,593 [MI]  &"and then try again.\n"
936,593 [MI]  55^error,msg="Cannot execute this command while the target is running.\nUse the \"inte\
rrupt\" command to stop the target\nand then try again."
936,594 [MI]  (gdb) 

!ENTRY org.eclipse.cdt.dsf 4 10005 2016-11-14 17:02:16.594
!MESSAGE Request for monitor: 'RequestMonitor (org.eclipse.cdt.dsf.gdb.internal.ui.sync.GdbDebugContextSyncManager$1$1@541a390b): Status ERROR: org.eclipse.cdt.dsf.gdb code=10004 Failed to execute MI command:
-thread-select 1
Error message from debugger back end:
Cannot execute this command while the target is running.\nUse the "interrupt" command to stop the target\nand then try again. java.lang.Exception: Cannot execute this command while the target is running.\nUse the "interrupt" command to stop the target\nand then try again.' resulted in an error.
!SUBENTRY 1 org.eclipse.cdt.dsf.gdb 4 10004 2016-11-14 17:02:16.594
!MESSAGE Failed to execute MI command:
-thread-select 1
Error message from debugger back end:
Cannot execute this command while the target is running.\nUse the "interrupt" command to stop the target\nand then try again.
!STACK 0
java.lang.Exception: Cannot execute this command while the target is running.\nUse the "interrupt" command to stop the target\nand then try again.
	at org.eclipse.cdt.dsf.mi.service.command.AbstractMIControl$RxThread.processMIOutput(AbstractMIControl.java:941)
	at org.eclipse.cdt.dsf.mi.service.command.AbstractMIControl$RxThread.run(AbstractMIControl.java:770)
Comment 9 Marc Dumais CLA 2016-11-15 08:42:34 EST
(In reply to Marc Khouzam from comment #8)
> With mi-async, when testing an automatic remote session with all-stop,
> Alvaro and I tried leaving the inferior running.  In that case, the thread
> node was still being shown and when selecting it, we noticed that gdb was
> rejecting the -thread-select command.

I am able to reproduce this. But I wonder if it's really an issue. In all-stop, while the target is running, it's not permitted to switch thread. So the same thing happens if the user tries to change thread from the console. 

One thing that would make the synchronization work better in all-stop is if the thread selected, when suspending execution, would be the one that ends-up selected, once the suspend has happened. Here are the traces of the suspend; we can see that we do specify the selected thread (3 in this case).

879,657 116-exec-interrupt --thread 3
879,657 116^done
879,658 (gdb) 
879,658 ~"\nThread "
879,658 ~"1 \"multipleThreads\" received signal SIGINT, Interrupt.\n"
879,660 ~"0x00007ffff75b3dfd in nanosleep () from target:/lib/x86_64-linux-gnu/libc.so.6\n"
879,660 *stopped,reason="signal-received",signal-name="SIGINT",signal-meaning="Interrupt",frame={add\
r="0x00007ffff75b3dfd",func="nanosleep",args=[],from="target:/lib/x86_64-linux-gnu/libc.so.6"},threa\
d-id="1",stopped-threads="all",core="3"

However, the GDB stopped notification we get says that the thread id is "1", so we end-up selecting that one.
Comment 10 Marc Khouzam CLA 2016-11-15 08:54:58 EST
(In reply to Marc Dumais from comment #9)
> (In reply to Marc Khouzam from comment #8)
> > With mi-async, when testing an automatic remote session with all-stop,
> > Alvaro and I tried leaving the inferior running.  In that case, the thread
> > node was still being shown and when selecting it, we noticed that gdb was
> > rejecting the -thread-select command.
> 
> I am able to reproduce this. But I wonder if it's really an issue. In
> all-stop, while the target is running, it's not permitted to switch thread.
> So the same thing happens if the user tries to change thread from the
> console. 

Right.  Can we simply silence the errors by not sending the command in that case?

> One thing that would make the synchronization work better in all-stop is if
> the thread selected, when suspending execution, would be the one that
> ends-up selected, once the suspend has happened. Here are the traces of the
> suspend; we can see that we do specify the selected thread (3 in this case).
> 
> 879,657 116-exec-interrupt --thread 3
> 879,657 116^done
> 879,658 (gdb) 
> 879,658 ~"\nThread "
> 879,658 ~"1 \"multipleThreads\" received signal SIGINT, Interrupt.\n"
> 879,660 ~"0x00007ffff75b3dfd in nanosleep () from
> target:/lib/x86_64-linux-gnu/libc.so.6\n"
> 879,660
> *stopped,reason="signal-received",signal-name="SIGINT",signal-
> meaning="Interrupt",frame={add\
> r="0x00007ffff75b3dfd",func="nanosleep",args=[],from="target:/lib/x86_64-
> linux-gnu/libc.so.6"},threa\
> d-id="1",stopped-threads="all",core="3"
> 
> However, the GDB stopped notification we get says that the thread id is "1",
> so we end-up selecting that one.

Yes, I noticed that too.  When hitting a breakpoint it works as expected, meaning that if thread 3 hits a breakpoint, the *stopped event shows thread 3 and we select it.  But for interrupt, it is always thread 1.  This would be an enhancement for GDB though.