ldc-developers / ldc

The LLVM-based D Compiler.
http://wiki.dlang.org/LDC
Other
1.21k stars 261 forks source link

Debugging string mixins using -mixin doesn't switch files #3015

Open rainers opened 5 years ago

rainers commented 5 years ago

When using -mixin=... to dump mixins to another file, stepping through the code in a debugger doesn't switch to the generated file. Instead it jumps to the respective line number in the source file, e.g.

module WindowsApp1;
import std.stdio;

enum s = q{int a = 0;
int z = 1;
int y = a + z;
a = y + z;
};

void main()
{
    int b = 4;
    mixin(s);
    b = a + b;
}

generates these line numbers:

 0000:00000000-00000042, flags = 0001, fileid = 00000000

     10:0                00000000     12:2                0000000C
    106:1                00000013    107:1                0000001A
    108:1                00000021    109:1                0000002A
     14:2                00000033     15:1                0000003C
kinke commented 5 years ago

Well, that's a front-end issue wrt. Loc, isn't it?

rainers commented 5 years ago

I don't think so. dmd generates OMF with different filenames, but with holes. See https://issues.dlang.org/show_bug.cgi?id=19719

rainers commented 5 years ago

File information is probably lost in instructions like https://github.com/ldc-developers/ldc/blob/master/gen/dibuilder.cpp#L1208. For a mixin, no scope should be created, so an intermediate new scope is probably not good enough.

kinke commented 5 years ago

Mixed-in statements as in your example should probably have the mixin module itself as DI scope. I'm not sure LLVM wouldn't choke on something like that, as we may escape from a regular scopes hierarchy (DIFile -> namespaces/aggregates/templates... -> DISubprogram -> lexical blocks) directly to some line in another DIFile. LLVM must account for inlining, so file changes inside a single function are probably safe, but jumping to something outside any DISubprogram might be trouble.