demangle tool

R a at b.com
Fri Apr 10 03:19:05 PDT 2009


Hurm. I thought one of the things D had over C++ was that with aliases such complex error messages can be avoided. While D still seems to be better off than C++ I guess something like this is unavoidable with metaprogramming?

Andrei Alexandrescu Wrote:

> I wrote a simple utility (at the bottom of this message) that may help 
> debugging link-time errors. It reads lines from stdin and writes them 
> with DMD symbols, if any, demangled.
> 
> For example, here's what you see if you add "alias field this;" to Tuple 
> in std.typecons and try to build the "new, new" Phobos:
> 
> obj/posix/debug/unittest/std/file.o: In function 
> `_D3std4file14__T5slurpTiTdZ5slurpFAyaxAaZAS3std8typecons14__T5TupleTiTdZ5Tuple':
> /home/andrei/code/dmd/phobos/std/file.d:1772: undefined reference to 
> `_D3std8typecons14__T5TupleTiTdZ5Tuple6__initZ'
> /home/andrei/code/dmd/phobos/std/file.d:1781: undefined reference to 
> `_D3std5array51__T8AppenderTAS3std8typecons14__T5TupleTiTdZ5TupleZ8Appender3putMFxS3std8typecons14__T5TupleTiTdZ5TupleZv'
> obj/posix/debug/unittest/std/file.o: In function 
> `_D3std5array88__T8appenderTAS3std8typecons14__T5TupleTiTdZ5TupleTS3std8typecons14__T5TupleTiTdZ5TupleZ8appenderFPAS3std8typecons14__T5TupleTiTdZ5TupleZS3std5array51__T8AppenderTAS3std8typecons14__T5TupleTiTdZ5TupleZ8Appender':
> /home/andrei/code/dmd/phobos/std/array.d:578: undefined reference to 
> `_D3std5array51__T8AppenderTAS3std8typecons14__T5TupleTiTdZ5TupleZ8Appender6__ctorMFNcPAS3std8typecons14__T5TupleTiTdZ5TupleZS3std5array51__T8AppenderTAS3std8typecons14__T5TupleTiTdZ5TupleZ8Appender'
> obj/posix/debug/unittest/std/file.o: In function 
> `_D3std8typecons14__T5tupleTiTdZ5tupleFidZS3std8typecons14__T5TupleTiTdZ5Tuple':
> /home/andrei/code/dmd/phobos/std/typecons.d:515: undefined reference to 
> `_D3std8typecons14__T5TupleTiTdZ5Tuple6__initZ'
> collect2: ld returned 1 exit status
> --- errorlevel 1
> 
> However, if you use "make |& ./demangle.d", you see:
> 
> obj/posix/debug/unittest/std/file.o: In function `struct 
> std.typecons.Tuple!(int, double).Tuple[] std.file.slurp!(int, 
> double).slurp(immutable(char)[], const(char[]))':
> /home/andrei/code/dmd/phobos/std/file.d:1772: undefined reference to `Z 
> std.typecons.Tuple!(int, double).Tuple.__init'
> /home/andrei/code/dmd/phobos/std/file.d:1781: undefined reference to 
> `void std.array.Appender!(struct std.typecons.Tuple!(int, 
> double).Tuple[]).Appender.put(const(struct std.typecons.Tuple!(int, 
> double).Tuple))'
> obj/posix/debug/unittest/std/file.o: In function `struct 
> std.array.Appender!(struct std.typecons.Tuple!(int, 
> double).Tuple[]).Appender std.array.appender!(struct 
> std.typecons.Tuple!(int, double).Tuple[], struct 
> std.typecons.Tuple!(int, double).Tuple).appender(struct 
> std.typecons.Tuple!(int, double).Tuple[]*)':
> /home/andrei/code/dmd/phobos/std/array.d:578: undefined reference to 
> `_D3std5array51__T8AppenderTAS3std8typecons14__T5TupleTiTdZ5TupleZ8Appender6__ctorMFNcPAS3std8typecons14__T5TupleTiTdZ5TupleZS3std5array51__T8AppenderTAS3std8typecons14__T5TupleTiTdZ5TupleZ8Appender'
> obj/posix/debug/unittest/std/file.o: In function `struct 
> std.typecons.Tuple!(int, double).Tuple std.typecons.tuple!(int, 
> double).tuple(int, double)':
> /home/andrei/code/dmd/phobos/std/typecons.d:515: undefined reference to 
> `Z std.typecons.Tuple!(int, double).Tuple.__init'
> collect2: ld returned 1 exit status
> --- errorlevel 1
> make: *** [obj/posix/debug/unittest/std/file] Error 1
> 
> The line wraps are all garbled, but you get the idea: all symbols quoted 
> `like this' have been demangled appropriately. Below is the source of 
> the demangle script:
> 
> #!/home/andrei/bin/rdmd
> import std.algorithm, std.demangle, std.getopt, std.stdio;
> 
> void main(string[] args)
> {
>      string lSep = "`", rSep = "'";
>      getopt(args, "lsep", &lSep, "rsep", &rSep);
>      foreach (line; stdin.byLine())
>      {
>          auto sym = find(line, lSep);
>          if (!sym.length)
>          {
>              writeln(line);
>              continue;
>          }
>          sym = sym[1 .. $];
>          auto before = line[0 .. $ - sym.length];
>          sym = sym[0 .. $ - find(sym, rSep).length];
>          auto after = line[before.length + sym.length .. $];
>          writeln(before, demangle(sym.idup), after);
>      }
> }
> 
> 
> Hope this helps someone,
> 
> Andrei




More information about the Digitalmars-d mailing list