Commit 00cc658f

00cc658fd7d3Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified

Description

Emit a #line for a method's prologue so gdb maps it to the .rb

A breakpoint on a compiled method (break sp_foo) landed in the generated C prologue (the signature + SP_GC_SAVE + local decls, which carried no #line), and since spinel deletes the temp .c after compiling, gdb reported "out.c: No such file". Only the method body had #line directives, so you had to step past the prologue before the Ruby source appeared.

Emit a #line at the def line just before the method signature, so the whole function -- prologue included -- maps to the .rb. Now break sp_foo lands on the def line and next/step walk the Ruby source directly; the generated C never needs to be kept. So --line-map (default on) + -g/--debug is enough to debug against the Ruby source -- no --save-temps needed (#1261).

The directive is gated on --line-map (g_line_map) and generates no code: --no-line-map output is byte-identical, optcarrot/bench/test unaffected.

Refs #1261

Co-Authored-By: Claude Opus 4.8 [email protected]

Details

Commit
00cc658fd7d3
Parent
bd1ea603e462

src/codegen.cmodifiedView file

@@ -423,6 +423,12 @@
423423 return;
424424 }
425425 inherit_transplant_locals(c, s);
426+ /* Map the whole function (signature + SP_GC_SAVE prologue + local decls,
427+ before the first body stmt) to the `def` line, so a breakpoint on the method
428+ lands on the .rb source rather than the generated C -- which is deleted after
429+ compile, so gdb couldn't find it. With this, --line-map / -g is enough to
430+ debug against the Ruby source; no need to keep the generated C (#1261). */
431+ emit_line_directive(c, s->def_node, b);
426432 emit_method_signature(c, s, b);
427433 buf_puts(b, " {\n");
428434 buf_puts(b, " SP_GC_SAVE();\n");