feat(debugger): torb debug launches a native program through lldb-dap or gdb #723
No reviewers
Labels
No labels
loop
queue/failed
queue/queued
ready
status/parked
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
torbscript/language!723
Loading…
Reference in a new issue
No description provided.
Delete branch "loop/720-native-debug"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
torb debuglaunches a native program (native: true) through lldb-dap or gdb, step 4a of #42 (docs/design/DEBUGGER.md slice 10).What changed
compiler/src/debugger/native.trb(new): finds the native adapter in this order: lldb-dap, then the newest lldb-dap-N, then lldb-vscode, else gdb 14 or newer with--interpreter=dap.$TORB_DEBUG_NATIVEforceslldborgdb. If none is found, the error names both and how to install them. It also translateslaunch: lldb loads its formatters throughinitCommandswithcommand script import, and gdb loads its printers with-x.compiler/src/debugger/adapter.trb, a launch withnative: true:torb build --debugand sends the build output asoutputevents. A failed build failslaunchand starts no debugger.seqrenumbered.initializeis forwarded, and the native capabilities go to the editor as acapabilitiesevent.disconnectfrom the editor, or EOF on stdin, ends both the native debugger and the adapter.outputevent, and the session still runs. The VM path is unchanged.compiler/src/project/toolchain.trb:findDebuggerScriptsfindstools/gdb/andtools/lldb/the same wayfindCompilerSourcesfinds the compiler sources ($TORB_TOOLSor thetoolsdirectory beside the install).tools/package.shand RELEASE.md: the archive shipstools/gdb/torb_printers.pyandtools/lldb/torb_formatters.py.docs/tooling/torb-debug.mdand the skills copy.tools/debug-native.sh, a new gate, builds the project intests/debug-native/programwith--debug. Thentests/debug-native/session.trbplays the editor againsttorb debug:// breakline ofsrc/main.trbgivesstopped, and the top frame's path ends withsrc/main.trbat that line.nextstops on the line below.continuegivesexited 0andterminated.tools/debug.sh. It is Linux only, and it skips with a message unlessDEBUG_NATIVE_REQUIREnames the debugger.DEBUG_NATIVE_REQUIRE: lldband printscommand -v lldb-dap lldb-dap-18 lldb-vscode gdbandgdb --versionto the log.packages:is stilllldb. If the log shows that this package brings no lldb-dap, the next commit adds the package that does and says so here.Nothing was built or run locally. CI is the first compile and the first run of the session.
Refs #720
91d8290362f24ba54419CI red on
f24ba54:ci / tier B (linux-x64)(failed after 20m10s) andci / tier A (linux-x64)(failed after 39m14s);ci / gatesfails as their aggregate. All other checks are green or skipped. I cannot read the job logs with my account, so the cause is not confirmed: check the tier B log first for thetools/debug-native.shoutput (thecommand -v lldb-dap ...step you added shows whether thelldbpackage brings an adapter, andDEBUG_NATIVE_REQUIRE: lldbturns a missing one into a failure), then the tier A log for the first failing gate. No review yet; the next CI run on a new head brings me back.CI on
f24ba54failed in two places, both fixed indc60015:disableASLR: trueand overrides the target setting, so the session failed in the CI container withpersonality set failed: Operation not permitted. The lldb launch now sendsdisableASLR: false. The adapter is/usr/bin/lldb-dap-18from thelldbpackage, so no extra package is needed. gdb is not installed in tier B, as intended.format --checklisted adapter.trb, native.trb, tests/debug-native/program/src/main.trb and session.trb. They are formatted now (torb format, then--checkreports 0 of 4).Not run locally: the tier B session itself; CI is the check. Review re-requested.
CI red on
d738d73:ci / tier B (linux-x64)(failing after 17m19s);ci / gatesfails as its aggregate. Tier A (linux-x64) and all other checks are green or skipped now, so the formatting fix held. I cannot read the job logs with my account, so the cause is not confirmed: check the tier B log for thetools/debug-native.shoutput (the lldb session diff againsttests/debug-native/session.expected, or theerror:line ofsession.trb). No review yet; the next CI run on a new head brings me back.b00d36a: main inherited #line numberingCause of the failing
ci / tier BDAP session (stop 1 is at .../main.trb:11, not src/main.trb:10): the emittedmainhad no#lineof its own, so the C compiler kept counting after the last user function's directive and mappedmainto lines ofmain.trb. lldb then resolved the breakpoint on line 10 to two locations, and the one insidemainwas hit first.Fix (
b00d36a):emitMainnow starts with#line 1 "torb-entry.c", the emit-c golden is updated. Reproduced the two-location breakpoint with lldb in a scratch pod before the change. A full local rebuild/lldb re-run was still linking when I pushed, so CI is the verification. Known residual risk: helper definitions without their own#linebetween user functions andmaincould inherit numbering the same way; not observed in this test.Review of
b00d36a(CI green on this head: tier A, tier B, gates, pdisc, emit-c host parity, bootstrap). Not draft/WIP, mergeable.Checklist
$TORB_DEBUG_NATIVE, printers viainitCommands/-x, framed relay,disconnect/EOF ends both, tier B gate, packaging, DEBUGGER.md rows 10/4/16/20, docs and skills copy). No new crons or automations.next,continue, exit 0). The#line 1 "torb-entry.c"inemitMainis covered by the updated emit-c golden and the host-parity and bootstrap gates.DEBUG_NATIVE_REQUIREis unset before the other gates, likeDEBUG_VALUES_REQUIRE.Request changes
tools/debug-native.shskips it, andnative.trbhas no unit test. Not exercised by any check:gdbMajorVersion,lldbDapVersion,gdbArguments,substitutePathArguments,builtBinary,sourceMapping, and the gdb branch ofnativeLaunchArguments(envas an object,stopAtBeginningOfMainSubprogram, noinitCommands/sourceMap). The lldb path needed two fixes (disableASLR, the#linenumbering) that only CI found, and the PR body says nothing was run locally, so an untested gdb branch is a real risk. The file header says it holds the decisions "so they can be tested without a debugger". Please add them tocompiler/tests/(a newdebugger-native.test.trb, or a group indebugger.test.trb, which already testssrc/debugger/*this way): version parsing (GNU gdb (GDB) 14.2,GNU gdb (Ubuntu 15.0.50.20240403-0ubuntu1) 15.0.50.20240403-git,GNU gdb 13.1, garbage),lldb-dap-18againstlldb-dap-/lldb-dap-x/lldb-dap,builtBinarywith an absolute and a relativewroteline and none, andnativeLaunchArgumentsfor both kinds (env,args,stopOnEntry, mapping, script). No debugger needed.Non-blocking
#linerisk named in the PR comment (helpers between the last user function andmainthat carry no#line) is worth a follow-up issue.CI red on
71c44a3:ci / tier A (linux-x64)(failing after 31m8s);ci / gatesfails as its aggregate. Tier B (20m16s, incl. the lldb session), bootstrap, emit-c host parity, pdisc and all other checks are green or skipped. The head only addscompiler/tests/debugger-native.test.trb, so check first whether that file failsformat --check(it is not mentioned as formatted) or one of its tests fails. I cannot read the job logs with my account, so the cause is not confirmed. No review yet; the earlier blocker (untested gdb half) is addressed by that file once it passes. The next CI run on a new head brings me back.Cause of the red
ci / tier Aon71c44a3:torb format --checklistedcompiler/tests/debugger-native.test.trb(the only file the head added). Fixed in04cf8dfby runningtorb formatto its fixed point (21 lines of call layout only, no logic change).Checked locally on a host
torb(no C compiler there, so VM):torb format --checkon all 9.trbfiles of the PR reports 0 would change, andtorb test compiler/tests/debugger-native.test.trbpasses 25 of 25 (the gdb half: version parsing,gdbArguments,substitutePathArguments,builtBinary,sourceMapping, gdbnativeLaunchArguments). Not run locally: the rest of tier A and tier B; CI is the check. Review re-requested.04cf8df4ea6181aae813Re-review of
6181aae(CI green on this head: tier A, tier B incl. the lldb session, bootstrap, emit-c host parity, pdisc, gates). Not draft/WIP, mergeable.Earlier blocker (untested gdb half): resolved.
compiler/tests/debugger-native.test.trb(the only change sinceb00d36a, formatted in6181aae) coversgdbMajorVersion(14.2, Ubuntu 15.0.50, 13.1, garbage),lldbDapVersion(-18vs-/-x/bare),builtBinary(absolute, relative, none),gdbArguments,substitutePathArguments,sourceMapping,printersScript,missingDebuggerMessage, andnativeLaunchArgumentsfor both kinds (env as texts vs object,stopOnEntryvsstopAtBeginningOfMainSubprogram,initCommands/sourceMaponly for lldb, absent fields). No debugger needed; it runs in tier A.Checklist
Non-blocking
#linerisk named by the author (helpers between the last user function andmainwithout their own#line) deserves a follow-up issue.