<div dir="ltr">Sorry for being late to reply, I was investigating what you advised to me. And with all your informations and some (really) hard time I succeeded to register the unwinding information (not the way you think) and have a clear callstack ! it feels good !<br><br><a class="gmail_plusreply" id="m_4528560093764755308plusReplyChip-0" href="mailto:rnk@google.com" target="_blank">@Reid Kleckner</a> <br>After looking deeper, I don't understand why this bug is open for such a long time as everything is here to fix it : the unwinding process is completely implemented in LLVM and is enabled by adding llvm::Attribute::UWTable to llvm::Function instances. <br>The only thing missing is the calls to RtlAddFunctionTable. They should be added to the default
MCJIT or OrcJIT
memory manager (maybe with an option to enable/disable them), simply by tracking memory requested for allocation of ".pdata" and ".xdata" sections and calling RtlAddFunctionTable on notifyObjectLoaded. I don't know who is responsible for this, but that might be an easy win for a great feature completion (this is nice to avoid the user having to understand all this machinery by themselves...)<br><br>In my case, I can't call RtlAddFunctionTable because I inject my code into a fake .DLL (for PDB hotreload purpose) which already have its static function table. <br>To explain my process (for other devs willing to suffer like I did) :<br> If debugging is required by the user, I switch from MCJITMemoryManager to a home-made DllMemoryManager which :<br>- loads a dummy .DLL consisting of empty .text .rdata (including .xdata) and .pdata sections, without relocations.<br>- allocates memory inside the loaded .DLL address range (the dll has been hacked for WRITE access)
<br>- unload the .DLL <br>- generate a PDB<br>- *INTERESTING PART* : rewrites PDATA and XDATA sections with the one emitted by LLVM (fixing virtual address inside the image).<br>- writes the .DLL back on disk<br>- make PDB file match .DLL file (GUID)<br>- reload the .DLL (it reloads at same position 100% of the time in my case, I might be lucky but I'm ok with it) so that visual studio detects it and load the matching PDB.<br><br>All of this process was painful but it works and I can build and rebuild my language on-the-fly while debugging it alongside with native code inside Visual Studio. You might wonder why not generate a real .dll and reload it ? Because I can't predict where the functions will be reloaded inside memory and I need to keep "reflection" of the JIT symbols. (+ it's slower and requires a lot of work on the mangle/link/pdb dependency sides).<br><br>@Jameson : Thanks for your feedback, it helped me to identify .xdata and .pdata sections for unwind stuff ! <br>Are you sure that unwinding info is not enough for you to make it debuggable ? I personally removed the "no-frame-pointer-elim" and it keeps working well, I keep seeing my full callstack (maybe
is it only useful on x86 ?), because Win64 does not use RBP to walk the stack at all, all is done with unwind infos apparently.<br>PDB are not concerned at all with all of this, I thought it might but no...<br><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le dim. 1 mars 2020 à 05:54, Jameson Nash <<a href="mailto:vtjnash@gmail.com" target="_blank">vtjnash@gmail.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">I've always just hacked support for this in to the various JITs (for JuliaLang, in our debuginfo.cpp file), by setting the no-frame-pointer-optim flag in the IR, then creating and populating a dummy unwind description object in the .text section, and registering that dynamically. Some day I hope to actually just register the .pdata/.xdata sections with the unwinder.<div><br></div><div>PDBs are a bit different though, since the above steps work well for gdb, but generally I find that WinDbg is less willing or able to be given JIT-frame information from LLVM. (I assume somehow it can be done, for dotNET. I just don't know how.)</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Feb 29, 2020 at 11:07 PM Reid Kleckner via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Yes, I think <a href="https://bugs.llvm.org/show_bug.cgi?id=24233" target="_blank">https://bugs.llvm.org/show_bug.cgi?id=24233</a> needs to be implemented to fix this.<div><br></div><div>The Windows x64 unwinder doesn't generally look at frame pointers. We would need to register unwind info to make this work. What you see is fairly typical of attempting to unwind the stack when unwind info is missing.</div><div><br></div><div>PDBs shouldn't generally enter into the picture.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Feb 29, 2020 at 8:14 AM Vivien Millet via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><p style="margin:0px 0px 1em;padding:0px;border:0px;font-variant-numeric:inherit;font-variant-east-asian:inherit;font-stretch:inherit;line-height:inherit;font-family:Arial,"Helvetica Neue",Helvetica,sans-serif;font-size:15px;vertical-align:baseline;box-sizing:inherit;clear:both;color:rgb(36,39,41)">Hi,<br><br>I'm using IR and MCJIT to compile a script language. I debug it with on the fly generated .pdb files. During debugging, almost each time I step into a function, I loose information about calling function inside the visual studio callstack view or I have a bunch of pure addresses in the callstack in between the current function and the calling function, for example :</p><pre style="margin-top:0px;margin-bottom:1em;padding:12px 8px;border:0px;font-variant-numeric:inherit;font-variant-east-asian:inherit;font-stretch:inherit;line-height:inherit;font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace,sans-serif;font-size:13px;vertical-align:baseline;box-sizing:inherit;width:auto;max-height:600px;overflow:auto;border-radius:3px;color:rgb(36,39,41)"><code style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace,sans-serif;vertical-align:baseline;box-sizing:inherit;white-space:inherit">MyJit.dll!MyCurrentFunction()
[0x1234567887654321]
[0x8765432112345678]
MyJit.dll!MyCallingFunction()
...
</code></pre><p style="margin:0px 0px 1em;padding:0px;border:0px;font-variant-numeric:inherit;font-variant-east-asian:inherit;font-stretch:inherit;line-height:inherit;font-family:Arial,"Helvetica Neue",Helvetica,sans-serif;font-size:15px;vertical-align:baseline;box-sizing:inherit;clear:both;color:rgb(36,39,41)">It looks like visual studio get lost while walking up stack.<br>Does anyone know where it could come from ? <br></p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-variant-numeric:inherit;font-variant-east-asian:inherit;font-stretch:inherit;line-height:inherit;font-family:Arial,"Helvetica Neue",Helvetica,sans-serif;font-size:15px;vertical-align:baseline;box-sizing:inherit;clear:both;color:rgb(36,39,41)">I have disabled all optimisations (among them is the omit-frame-pointer).</p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-variant-numeric:inherit;font-variant-east-asian:inherit;font-stretch:inherit;line-height:inherit;font-family:Arial,"Helvetica Neue",Helvetica,sans-serif;font-size:15px;vertical-align:baseline;box-sizing:inherit;clear:both;color:rgb(36,39,41)">I have seen this bug here : <a href="https://bugs.llvm.org/show_bug.cgi?id=24233" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;box-sizing:inherit" target="_blank">https://bugs.llvm.org/show_bug.cgi?id=24233</a> which is quite similar but it is quite old now, and since the proposed patch has been posted, the code in RuntimeDyldCOFFX86_64.h has changed and it is difficult for me to know if it has really been fixed since or not.</p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-variant-numeric:inherit;font-variant-east-asian:inherit;font-stretch:inherit;line-height:inherit;font-family:Arial,"Helvetica Neue",Helvetica,sans-serif;font-size:15px;vertical-align:baseline;box-sizing:inherit;clear:both;color:rgb(36,39,41)">Could it be related to the way IR CreateAlloca are used to build local variables ? Could it be related to missing informations inside the PDB ? (I don't know if there is stack related information inside PDB files to ensure good stack walking).<br><br>Thanks.<br><br>Vivien</p></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>
</blockquote></div>