On 5/5/23 15:09, Tom Tromey wrote:
>>>>>> "Tom" == Tom de Vries via Gdb-patches <gdb-patches@sourceware.org> writes:
>
> Tom> Modify the dap input format to allow a WAIT_FOR_EVENTS line:
> Tom> ...
> Tom> Content-Length: 54
> Tom> WAIT_FOR_EVENTS: 1
> Tom> {"seq": 1, "type": "request", "command": "initialize"}
> Tom> Content-Length: 163
> Tom> ...
> Tom> that ensures that we wait for a specific amount of events before continuing
> Tom> to process input.
>
> I don't understand the use for this.
The idea is that I'm trying to reproduce gdb.dap test-cases outside the
test-suite, and I need something to play the role of _dap_wait_for_event.
Otherwise, I sent requests before I have an acknowledgement that
expected events due to previous requests have occurred.
More concretely, let's run gdb.dap/bt-nodebug.exp.
Now, we copy the gdb.in.1 to use as input:
...
$ cp leap-15-4/build/gdb/testsuite/outputs/gdb.dap/bt-nodebug/gdb.in.1
gdb.in
...
Let's use it as described in the cover letter:
...
$ gdb -q -iex "set debug dap-log-file dap.log" -i dap < gdb.in
Content-Length: 473
{"request_seq": 1, "type": "response", "command": "initialize", "body":
{"supportsTerminateRequest": true, "supportTerminateDebuggee": true,
"supportsFunctionBreakpoints": true, "supportsInstructionBreakpoints":
true, "supportsDelayedStackTraceLoading": true,
"supportsDisassembleRequest": true, "supportsConfigurationDoneRequest":
true, "supportsReadMemoryRequest": true, "supportsWriteMemoryRequest":
true, "supportsSteppingGranularity": true}, "success": true, "seq":
1}Content-Length: 51
{"type": "event", "event": "initialized", "seq": 2}Content-Length: 86
{"request_seq": 2, "type": "response", "command": "launch", "success":
true, "seq": 3}Content-Length: 299
{"type": "event", "event": "breakpoint", "body": {"reason": "new",
"breakpoint": {"id": 1, "verified": true, "source": {"name":
"bt-main.c", "path":
"/data/vries/gdb/binutils-gdb.git/gdb/testsuite/gdb.dap/bt-main.c",
"sourceReference": 0}, "line": 23, "instructionReference": "0x4004ab"}},
"seq": 4}Content-Length: 337
{"request_seq": 3, "type": "response", "command":
"setFunctionBreakpoints", "body": {"breakpoints": [{"id": 1, "verified":
true, "source": {"name": "bt-main.c", "path":
"/data/vries/gdb/binutils-gdb.git/gdb/testsuite/gdb.dap/bt-main.c",
"sourceReference": 0}, "line": 23, "instructionReference":
"0x4004ab"}]}, "success": true, "seq": 5}Content-Length: 97
{"request_seq": 4, "type": "response", "command": "configurationDone",
"success": true, "seq": 6}Content-Length: 186
{"type": "event", "event": "output", "body": {"category": "stdout",
"output": "Breakpoint 1 at 0x4004ab: file
/data/vries/gdb/src/gdb/testsuite/gdb.dap/bt-main.c, line 23.\n"},
"seq": 7}Content-Length: 92
{"type": "event", "event": "thread", "body": {"reason": "started",
"threadId": 1}, "seq": 8}Content-Length: 137
{"request_seq": 5, "type": "response", "command": "stackTrace", "body":
{"stackFrames": [], "totalFrames": 0}, "success": true, "seq":
9}Content-Length: 91
{"request_seq": 6, "type": "response", "command": "disconnect",
"success": true, "seq": 10}$
...
As we can see the backtrace is empty.
After playing with this a few times, we get instead:
...
$ gdb -q -iex "set debug dap-log-file dap.log" -i dap < gdb.in
Content-Length: 473
{"request_seq": 1, "type": "response", "command": "initialize", "body":
{"supportsTerminateRequest": true, "supportTerminateDebuggee": true,
"supportsFunctionBreakpoints": true, "supportsInstructionBreakpoints":
true, "supportsDelayedStackTraceLoading": true,
"supportsDisassembleRequest": true, "supportsConfigurationDoneRequest":
true, "supportsReadMemoryRequest": true, "supportsWriteMemoryRequest":
true, "supportsSteppingGranularity": true}, "success": true, "seq":
1}Content-Length: 51
{"type": "event", "event": "initialized", "seq": 2}Content-Length: 86
{"request_seq": 2, "type": "response", "command": "launch", "success":
true, "seq": 3}Content-Length: 299
{"type": "event", "event": "breakpoint", "body": {"reason": "new",
"breakpoint": {"id": 1, "verified": true, "source": {"name":
"bt-main.c", "path":
"/data/vries/gdb/binutils-gdb.git/gdb/testsuite/gdb.dap/bt-main.c",
"sourceReference": 0}, "line": 23, "instructionReference": "0x4004ab"}},
"seq": 4}Content-Length: 186
{"type": "event", "event": "output", "body": {"category": "stdout",
"output": "Breakpoint 1 at 0x4004ab: file
/data/vries/gdb/src/gdb/testsuite/gdb.dap/bt-main.c, line 23.\n"},
"seq": 5}Content-Length: 337
{"request_seq": 3, "type": "response", "command":
"setFunctionBreakpoints", "body": {"breakpoints": [{"id": 1, "verified":
true, "source": {"name": "bt-main.c", "path":
"/data/vries/gdb/binutils-gdb.git/gdb/testsuite/gdb.dap/bt-main.c",
"sourceReference": 0}, "line": 23, "instructionReference":
"0x4004ab"}]}, "success": true, "seq": 6}Content-Length: 97
{"request_seq": 4, "type": "response", "command": "configurationDone",
"success": true, "seq": 7}Content-Length: 92
{"type": "event", "event": "thread", "body": {"reason": "started",
"threadId": 1}, "seq": 8}Content-Length: 303
{"type": "event", "event": "breakpoint", "body": {"reason": "changed",
"breakpoint": {"id": 1, "verified": true, "source": {"name":
"bt-main.c", "path":
"/data/vries/gdb/binutils-gdb.git/gdb/testsuite/gdb.dap/bt-main.c",
"sourceReference": 0}, "line": 23, "instructionReference": "0x4004ab"}},
"seq": 9}Content-Length: 149
{"type": "event", "event": "stopped", "body": {"threadId": 1,
"allThreadsStopped": true, "hitBreakpointIds": [1], "reason":
"breakpoint"}, "seq": 10}Content-Length: 685
{"request_seq": 5, "type": "response", "command": "stackTrace", "body":
{"stackFrames": [{"id": 0, "name": "function_breakpoint_here", "line":
23, "column": 0, "instructionPointerReference": "0x4004ab", "source":
{"name": "bt-main.c", "path":
"/data/vries/gdb/src/gdb/testsuite/gdb.dap/bt-main.c",
"sourceReference": 0}}, {"id": 1, "name": "no_debug_info", "line": 0,
"column": 0, "instructionPointerReference": "0x4004c7"}, {"id": 2,
"name": "main", "line": 27, "column": 0, "instructionPointerReference":
"0x4004b7", "source": {"name": "bt-main.c", "path":
"/data/vries/gdb/src/gdb/testsuite/gdb.dap/bt-main.c",
"sourceReference": 0}}], "totalFrames": 3}, "success": true, "seq":
11}Content-Length: 91
{"request_seq": 6, "type": "response", "command": "disconnect",
"success": true, "seq": 12}$
...
As we can see the backtrace is now not empty.
The WAIT_FOR_EVENTS bit ensures that we get a non-empty backtrace each time.
Thanks,
- Tom