Bug 31433 - [gdb/dap] Cancel generates StoppedEvent with reason signal
Summary: [gdb/dap] Cancel generates StoppedEvent with reason signal
Status: NEW
Alias: None
Product: gdb
Classification: Unclassified
Component: dap (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-02-29 11:07 UTC by Tom de Vries
Modified: 2024-02-29 15:45 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tom de Vries 2024-02-29 11:07:38 UTC
Consider this bit from gdb.dap/pause.exp dap.log:
...
READ: <<<{"seq": 6, "type": "request", "command": "pause", "arguments": {"threadId": 1}}>>>
WROTE: <<<{"request_seq": 6, "type": "response", "command": "pause", "success": true}>>>
WROTE: <<<{"type": "event", "event": "module", "body": {"reason": "new", "module": {"id": "/lib64/ld-linux-x86-64.so.2", "name": "/lib64/ld-linux-x86-64.so.2", "path": "/lib64/ld-linux-x86-64.so.2"}}}>>>
WROTE: <<<{"type": "event", "event": "module", "body": {"reason": "new", "module": {"id": "system-supplied DSO at 0x7ffff7fcf000", "name": "system-supplied DSO at 0x7ffff7fcf000"}}}>>>
_suppress_cont case
+++ interrupt -a
entering _on_stop: <gdb.SignalEvent object at 0x7f947089c708>
   details: {'reason': 'signal-received', 'signal-name': 'SIGINT', 'signal-meaning': 'Interrupt'}
WROTE: <<<{"type": "event", "event": "stopped", "body": {"threadId": 1, "allThreadsStopped": true, "reason": "pause"}}>>>
...

So the client requests a pause, which is translated into an "interrupt -a".  When the interrupt arrives, it's processed by _on_stop, and generates a stopped event with reason "pause".

Now consider:
...
READ: <<<{"seq": 8, "type": "request", "command": "evaluate", "arguments": {"expression": "continue", "context": "repl"}}>>>
WROTE: <<<{"type": "event", "event": "continued", "body": {"threadId": 1, "allThreadsContinued": true}}>>>
READ: <<<{"seq": 9, "type": "request", "command": "cancel", "arguments": {"requestId": 8}}>>>
WROTE: <<<{"type": "event", "event": "module", "body": {"reason": "new", "module": {"id": "/lib64/libm.so.6", "name": "/lib64/libm.so.6", "path": "/lib64/libm.so.6"}}}>>>
WROTE: <<<{"type": "event", "event": "module", "body": {"reason": "new", "module": {"id": "/lib64/libc.so.6", "name": "/lib64/libc.so.6", "path": "/lib64/libc.so.6"}}}>>>
entering _on_stop: <gdb.SignalEvent object at 0x7f947089c708>
   details: {'reason': 'signal-received', 'signal-name': 'SIGINT', 'signal-meaning': 'Interrupt'}
WROTE: <<<{"type": "event", "event": "stopped", "body": {"threadId": 1, "allThreadsStopped": true, "reason": "signal"}}>>>
WROTE: <<<{"request_seq": 8, "type": "response", "command": "evaluate", "body": {"result": "Continuing.\n", "variablesReference": 0}, "success": true}>>>
WROTE: <<<{"request_seq": 9, "type": "response", "command": "cancel", "success": true}>>>
...

The client requests a continue, followed by a cancel.  The cancel is translated into a gdb.interrupt.  When the interrupt arrives, it's processed by _on_stop, and generates a stopped event with reason "signal".

I wonder if the reason should be "cancel" or some such, to allow the client to differentiate between events generated by a cancel, and external signal events.
Comment 1 Tom Tromey 2024-02-29 15:45:28 UTC
> I wonder if the reason should be "cancel" or some such, to allow the client to
> differentiate between events generated by a cancel, and external signal events.

FWIW we can have it do anything.  Even "signal" isn't specified
explicitly:

    reason: 'step' | 'breakpoint' | 'exception' | 'pause' | 'entry' | 'goto'
        | 'function breakpoint' | 'data breakpoint' | 'instruction breakpoint'
        | string;

That's from:

https://microsoft.github.io/debug-adapter-protocol/specification#Events_Stopped