Commit 392f33b2
392f33b212f9Merged
Ori Pekelman <[email protected]> · 5 months ago · 4 files · ~4 modified
Description
Add --debug / -g mode: #line directives for native-debugger stepping
Roadmap item 1 from the spinel-dev debuggability notes: let gdb/lldb step through the original Ruby source of a compiled program, instead of landing in generated C.
The notes assumed codegen already had per-node line numbers. It did not: the parser only stamped a line on SourceLineNode (LINE) and UnsupportedNode, both into @nd_value -- a slot also overloaded for integer /float literal values, numbered-param max, etc. So there was no reliable per-node line to read. This adds one in a dedicated slot.
- spinel_parse.c: when SPINEL_DEBUG=1, flatten() stamps every node with a
node_linefield (same pm_newline_list_line lookup the existing cases use). Gated, so the AST text format is byte-for-byte unchanged otherwise. - compiler_helpers.rb: load
node_lineinto a dedicated @nd_line array (never @nd_value). - spinel_codegen.rb: @debug from SPINEL_DEBUG; emit
#line N "src.rb"before each statement (compile_stmt) and before the method tail/implicit -return expression (compile_body_return_inner); suppress consecutive duplicates. In debug builds, method_linkage_named never promotes tostatic inline, so every method stays a real, steppable frame. - spinel:
--debug(forces -O0, adds -g, exports SPINEL_DEBUG=1) and-g(debug info + #line, leaves -O as-is).
Verified with lldb: break src.rb:N resolves, Ruby locals print as
lv_, step advances by Ruby line, and backtrace reconstructs Ruby
frames (sp_add <- main) -- the last without the item-4 shadow stack.
Non-debug output is unchanged (0 #line, inline promotion intact, no
node_line in the AST). Kept on the ori fork; no PR against matz/spinel.
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 392f33b212f9
- Parent
- e9b946576a44
compiler_helpers.rbmodifiedView file
@nd_type = Array.new(n, "") @nd_name = Array.new(n, "") @nd_value = Array.new(n, 0) @nd_line = Array.new(n, 0) @nd_content = Array.new(n, "") @nd_flags = Array.new(n, 0) @nd_operator = Array.new(n, "") # location in the compile error. @nd_value[nid] = val end # Debug builds only (SPINEL_DEBUG=1): the parser stamps every node # with its 1-based source line in a dedicated slot so codegen can # emit `#line` directives. Kept separate from @nd_value, which is # overloaded for integer/float literal values, numbered-param max, etc. if field == "node_line" @nd_line[nid] = val end end def set_ref_field(nid, field, ref_id)spinelmodifiedView file
Loading diff…
spinel_codegen.rbmodifiedView file
Loading diff…
spinel_parse.cmodifiedView file
Loading diff…