<div dir="ltr">OTOH a disassembler is not a compiler.  It's just a debugging aid.  While it's conceptually nice that llvm-c-test --disassemble produces the same outputs on all platforms, it's not as important as being able to do perfect cross compilation.<div>
<br></div><div>Is there a way to structure this so that the symbolization is delegated to the user of the C API, or is that too disruptive?</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jan 3, 2014 at 3:37 PM, David Majnemer <span dir="ltr"><<a href="mailto:david.majnemer@gmail.com" target="_blank">david.majnemer@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Unless I am mistaken, the correct thing to do would be to provide an implementation of symbol demangling within LLVM itself.<div>
This way we could demangle Itanium-style symbols without relying on ::abi::__cxa_demangle and MSVC-style symbols without relying on ::UnDecorateSymbolName.</div>
<div><br></div><div>Relying on the host's ABI details to help disassemble code for a target seems like the wrong approach.</div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">
On Fri, Jan 3, 2014 at 12:06 PM, Howard Hinnant <span dir="ltr"><<a href="mailto:hhinnant@apple.com" target="_blank">hhinnant@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">abi::__cxa_demangle and <cxxabi.h> are part of the Itanium ABI.  MS doesn't support this unofficial standard.  Sorry, I don't know how to demangle names on Windows.  I believe that their <a href="http://type_info.name" target="_blank">type_info.name</a>() returns an demangled name.  But I don't know that this info helps.<br>


<span><font color="#888888"><br>
Howard<br>
</font></span><div><div><br>
On Jan 3, 2014, at 3:02 PM, Kevin Enderby <<a href="mailto:enderby@apple.com" target="_blank">enderby@apple.com</a>> wrote:<br>
<br>
> Hi Reid,<br>
><br>
> Sorry about that.  I'll revert my change.<br>
><br>
> Not sure the best way to get this done if an ifdef is not acceptable.  Maybe Howard or others will have better suggestions.<br>
><br>
> It does not have any tests as this is used by darwin's otool(1) that links with the llvm disassembler.  We have had this problem with this part of the disassembler since day one.  So I'm not sure the best way to address that either.<br>


><br>
> Kev<br>
><br>
> On Jan 3, 2014, at 11:54 AM, Reid Kleckner <<a href="mailto:rnk@google.com" target="_blank">rnk@google.com</a>> wrote:<br>
><br>
>> Microsoft doesn't ship a <cxxabi.h> header:<br>
>> <a href="http://lab.llvm.org:8011/builders/lld-x86_64-win7/builds/5504/steps/build_Lld/logs/stdio" target="_blank">http://lab.llvm.org:8011/builders/lld-x86_64-win7/builds/5504/steps/build_Lld/logs/stdio</a><br>


>> MCExternalSymbolizer.cpp(16): fatal error C1083: Cannot open include file: 'cxxabi.h': No such file or directory<br>
>><br>
>> I'm not familiar with this code, but it seems bad to make the result of LLVMDisasmInstruction dependent on the target platform, so throwing this behind a quick ifdef isn't necessarily right either.<br>
>><br>
>> This also doesn't have any tests.<br>
>><br>
>><br>
>> On Fri, Jan 3, 2014 at 11:33 AM, Kevin Enderby <<a href="mailto:enderby@apple.com" target="_blank">enderby@apple.com</a>> wrote:<br>
>> Author: enderby<br>
>> Date: Fri Jan  3 13:33:09 2014<br>
>> New Revision: 198441<br>
>><br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=198441&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=198441&view=rev</a><br>
>> Log:<br>
>> For disassembly when adding a symbolic operand that is a C++<br>
>> symbol name, also put the human readable name in a comment.<br>
>><br>
>> Also fix a bug in LLVMDisasmInstruction() that was not flushing<br>
>> the raw_svector_ostream for the disassembled instruction string<br>
>> before copying it to the output buffer that was causing truncation<br>
>> of the output.<br>
>><br>
>> rdar://10173828<br>
>><br>
>> Modified:<br>
>>     llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp<br>
>>     llvm/trunk/lib/MC/MCExternalSymbolizer.cpp<br>
>><br>
>> Modified: llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp?rev=198441&r1=198440&r2=198441&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp?rev=198441&r1=198440&r2=198441&view=diff</a><br>


>> ==============================================================================<br>
>> --- llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp (original)<br>
>> +++ llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp Fri Jan  3 13:33:09 2014<br>
>> @@ -298,6 +298,7 @@ size_t LLVMDisasmInstruction(LLVMDisasmC<br>
>>        emitLatency(DC, Inst);<br>
>><br>
>>      emitComments(DC, FormattedOS);<br>
>> +    OS.flush();<br>
>><br>
>>      assert(OutStringSize != 0 && "Output buffer cannot be zero size");<br>
>>      size_t OutputSize = std::min(OutStringSize-1, InsnStr.size());<br>
>><br>
>> Modified: llvm/trunk/lib/MC/MCExternalSymbolizer.cpp<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCExternalSymbolizer.cpp?rev=198441&r1=198440&r2=198441&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCExternalSymbolizer.cpp?rev=198441&r1=198440&r2=198441&view=diff</a><br>


>> ==============================================================================<br>
>> --- llvm/trunk/lib/MC/MCExternalSymbolizer.cpp (original)<br>
>> +++ llvm/trunk/lib/MC/MCExternalSymbolizer.cpp Fri Jan  3 13:33:09 2014<br>
>> @@ -13,6 +13,7 @@<br>
>>  #include "llvm/MC/MCInst.h"<br>
>>  #include "llvm/Support/raw_ostream.h"<br>
>>  #include <cstring><br>
>> +#include <cxxabi.h><br>
>><br>
>>  using namespace llvm;<br>
>><br>
>> @@ -56,6 +57,14 @@ bool MCExternalSymbolizer::tryAddingSymb<br>
>>      if (Name) {<br>
>>        <a href="http://SymbolicOp.AddSymbol.Name" target="_blank">SymbolicOp.AddSymbol.Name</a> = Name;<br>
>>        SymbolicOp.AddSymbol.Present = true;<br>
>> +      // If Name is a C++ symbol name put the human readable name in a comment.<br>
>> +      if (strncmp(Name, "__Z", 3) == 0) {<br>
>> +        char *demangled = abi::__cxa_demangle(Name + 1, 0, 0, 0);<br>
>> +       if (demangled) {<br>
>> +          cStream << demangled;<br>
>> +          free(demangled);<br>
>> +        }<br>
>> +      }<br>
>>      }<br>
>>      // For branches always create an MCExpr so it gets printed as hex address.<br>
>>      else if (IsBranch) {<br>
>><br>
>><br>
>> _______________________________________________<br>
>> llvm-commits mailing list<br>
>> <a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
>> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
>><br>
><br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</div></div></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
<br></blockquote></div><br></div>