Bug 21770 – Wrong breakpoint location for gdb

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2021-03-26T04:26:17Z
Last change time
2024-12-13T19:15:31Z
Keywords
DebugInfo
Assigned to
No Owner
Creator
hsteoh
Moved to GitHub: dmd#19898 →

Comments

Comment #0 by hsteoh — 2021-03-26T04:26:17Z
------------- import std; void fun(void delegate() dg) { dg(); } void main() { int x = 123; string y = "abc"; writeln(y); fun({ x++; y ~= "d"; }); } ------------- Compile with `dmd -g prog.d`. In gdb, set a breakpoint for prog.main: ------------- (gdb) break prog.main Breakpoint 1 at 0xe1c34: file prog.d, line 10. (gdb) run Starting program: /tmp/prog [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". abc Breakpoint 1, prog.main().__lambda3() (__capture=0x7ffff7cad000) at prog.d:10 10 x++; (gdb) ------------- This is wrong; the breakpoint for prog.main should break at the `writeln` line, or one of the variable initializers. But instead, it breaks inside the delegate body. A backtrace shows that `fun` has already been called. Expected behaviour: breaking at a function should break at the beginning of the function, not in the middle, and certainly not inside the body of a delegate!
Comment #1 by lucien.perregaux — 2021-04-18T20:41:26Z
There is two bugs: 1. `break prog.main` should say `Function "prog.main" not defined.` (because of https://issues.dlang.org/show_bug.cgi?id=21160), but it breaks somewhere else (end of f() in this case) --- void main() { int x = 123; void f() { x++; } } --- Removing `f()` produce `Function "prog.main" not defined.` ("normal" behaviour). 2. Using `writeln` writes wrong data in the dwarf debug infos. --- import std.stdio; void main() { writeln("x"); } --- `llvm-dwarfdump prog`: -- error: unexpected end of data at offset 0x804 while reading [0x15, 0x4d1d) error: unexpected end of data at offset 0x804 while reading [0x15, 0x4d1d) 0x00000789: DW_TAG_subprogram DW_AT_sibling (0x00000852) DW_AT_name ("std.exception.bailOut!(std.exception.ErrnoException).bailOut") DW_AT_MIPS_linkage_name ("_D3std9exception__T7bailOutHTCQBcQBb14ErrnoExceptionZQBiFNfAyamMAxaZv") DW_AT_decl_file ("phobos/std/exception.d") DW_AT_decl_line (512) DW_AT_low_pc (0x000000000004db00) DW_AT_high_pc (0x000000000004db7c) DW_AT_frame_base (0x00000214: [0x000000000004db00, 0x000000000004db01): DW_OP_breg7 RSP+8 [0x000000000004db01, 0x000000000004db03): DW_OP_breg7 RSP+16 [0x000000000004db03, 0x000000000004db7c): DW_OP_breg6 RBP+16) 0x00000828: DW_TAG_formal_parameter DW_AT_name ("msg") DW_AT_type (0x000004f0 "_Array_char") DW_AT_artificial (0x00) DW_AT_location (DW_OP_fbreg -64) --- Something in bailOut is not correctly emitted / not supported.
Comment #2 by robert.schadek — 2024-12-13T19:15:31Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19898 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB