Re: dmd demangle

2017-08-31 Thread Arun Chandrasekaran via Digitalmars-d
On Thursday, 31 August 2017 at 03:58:14 UTC, Michael V. Franklin 
wrote:



Just getting unresolved symbols?


Yeah, I was just wondering what if the output can be readable, 
given that dmd is the one that invokes ld. Would be much more 
human readable without piping through ddemangle. Thanks.


Re: dmd demangle

2017-08-30 Thread Michael V. Franklin via Digitalmars-d
On Thursday, 31 August 2017 at 02:51:25 UTC, Arun Chandrasekaran 
wrote:


I was looking at src/ddmd/link.d, has the below that reads the 
output of ld.


Ah, right you are.  My apologies.

It'd probably be simple enough to have that demangling on by 
default.  Maybe I'll give it a go later today.  What's your use 
case? Just getting unresolved symbols?


Mike




Re: dmd demangle

2017-08-30 Thread Arun Chandrasekaran via Digitalmars-d
On Thursday, 31 August 2017 at 02:31:24 UTC, Michael V. Franklin 
wrote:
On Thursday, 31 August 2017 at 02:20:00 UTC, Arun 
Chandrasekaran wrote:
Just a thought. Can dmd demangle the symbols before spitting 
the output of ld to stderr?


dmd doesn't print the output of ld to stderr, ld does.

I believe binutils has some support for D symbol demangling 
thanks to the GDC folks.  I tried it once:  
http://forum.dlang.org/post/bdmsrcczmizevhxor...@forum.dlang.org


So I think you need to find a way to pass --demangle=dlang to 
ld.

 Maybe `dmd program.d -L--demangle=dlang`?

Mike


Thanks Mike.

I was looking at src/ddmd/link.d, has the below that reads the 
output of ld. So I was wondering if we can plugin the demangle 
logic in this function. Nevertheless, good to know the linker 
already supports it.


```
private int findNoMainError(int fd)
{
version (OSX)
{
static __gshared const(char)* nmeErrorMessage = 
"\"__Dmain\", referenced from:";

}
else
{
static __gshared const(char)* nmeErrorMessage = 
"undefined reference to `_Dmain'";

}
FILE* stream = fdopen(fd, "r");
if (stream is null)
return -1;
const(size_t) len = 64 * 1024 - 1;
char[len + 1] buffer; // + '\0'
size_t beg = 0, end = len;
bool nmeFound = false;
for (;;)
{
// read linker output
const(size_t) n = fread([beg], 1, len - beg, 
stream);

if (beg + n < len && ferror(stream))
return -1;
buffer[(end = beg + n)] = '\0';
// search error message, stop at last complete line
const(char)* lastSep = strrchr(buffer.ptr, '\n');
if (lastSep)
buffer[(end = lastSep - [0])] = '\0';
if (strstr([0], nmeErrorMessage))
nmeFound = true;
if (lastSep)
buffer[end++] = '\n';
if (fwrite([0], 1, end, stderr) < end)
return -1;
if (beg + n < len && feof(stream))
break;
// copy over truncated last line
memcpy([0], [end], (beg = len - end));
}
return nmeFound ? 1 : 0;
}
```


Re: dmd demangle

2017-08-30 Thread ketmar via Digitalmars-d

Arun Chandrasekaran wrote:

Just a thought. Can dmd demangle the symbols before spitting the output 
of ld to stderr?


p.s.: redirecting output to ddemangle may work too, as ddemange will try to 
detect mangled DMD names, and won't modify other text. this way you can, 
for example, demangle names in valgrind output.


Re: dmd demangle

2017-08-30 Thread ketmar via Digitalmars-d

Arun Chandrasekaran wrote:

Just a thought. Can dmd demangle the symbols before spitting the output 
of ld to stderr?


no need to ;-) just add this to DFLAGS in dmd.conf, "Envirnment" section:

-L--demangle=dlang

so, it should look something like this:

..
[Environment]
DFLAGS= -L--demangle=dlang
..

due to hard work of Iain Buclaw, gdb and binutils (ld, objdump, etc.) are 
able to demangle DMD names.


note that new DMD version *may* include slightly changed mangling scheme, so 
the latest betas *may* produce "undecipherable" names.


Re: dmd demangle

2017-08-30 Thread Michael V. Franklin via Digitalmars-d
On Thursday, 31 August 2017 at 02:20:00 UTC, Arun Chandrasekaran 
wrote:
Just a thought. Can dmd demangle the symbols before spitting 
the output of ld to stderr?


dmd doesn't print the output of ld to stderr, ld does.

I believe binutils has some support for D symbol demangling 
thanks to the GDC folks.  I tried it once:  
http://forum.dlang.org/post/bdmsrcczmizevhxor...@forum.dlang.org


So I think you need to find a way to pass --demangle=dlang to ld. 
 Maybe `dmd program.d -L--demangle=dlang`?


Mike