www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21770] New: Wrong breakpoint location for gdb

https://issues.dlang.org/show_bug.cgi?id=21770

          Issue ID: 21770
           Summary: Wrong breakpoint location for gdb
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: hsteoh quickfur.ath.cx

-------------
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!

--
Mar 25