<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div><br></div>It appears that I've found a very curious effect where if I JIT a function that throws an exception and I use "call" to call it the throw fails despite there being a "catch" clause on the stack. But if I use “invoke” it works fine!<div><br></div><div> If I call the function (@cc_invoke) that throws a “core::CatchThrow” exception like this:</div><div><pre class="line-pre" style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; margin-top: 0px; margin-bottom: 0px; width: 748px; color: rgb(51, 51, 51); line-height: 16px;"><div class="line" id="file-gistfile1-txt-LC1" style="box-sizing: border-box;">call void @cc_invoke({ {}*, i64 }* %result-ptr, {}* %3, i64 2, {}* %4, {}* %5, {}* null, {}* null, {}* null)
</div><div class="line" id="file-gistfile1-txt-LC2" style="box-sizing: border-box;">;; Comment out the next two lines and   
</div><div class="line" id="file-gistfile1-txt-LC3" style="box-sizing: border-box;">;    to label %return0 unwind label %landing-pad1
</div><div class="line" id="file-gistfile1-txt-LC4" style="box-sizing: border-box;">;return0:</div><div class="line" id="file-gistfile1-txt-LC6" style="box-sizing: border-box;">ret void
</div><div class="line" id="file-gistfile1-txt-LC7" style="box-sizing: border-box;"> 
</div><div class="line" id="file-gistfile1-txt-LC8" style="box-sizing: border-box;">landing-pad1:                                     ; No predecessors!
</div><div class="line" id="file-gistfile1-txt-LC9" style="box-sizing: border-box;">  %6 = landingpad { i8*, i32 } personality i32 (...)* @__gxx_personality_v0
</div><div class="line" id="file-gistfile1-txt-LC10" style="box-sizing: border-box;">          cleanup
</div><div class="line" id="file-gistfile1-txt-LC11" style="box-sizing: border-box;">  resume { i8*, i32 } %6
</div><div class="line" id="file-gistfile1-txt-LC12" style="box-sizing: border-box;">}</div></pre><div><br></div></div><div>It fails with: libc++abi.dylib: terminating with uncaught exception of type core::CatchThrow</div><div><br></div><div>If instead I convert the “call” into an “invoke” and hook in a dummy landing-pad like this:</div><div><br></div><div><pre class="line-pre" style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; margin-top: 0px; margin-bottom: 0px; width: 748px; color: rgb(51, 51, 51); line-height: 16px;"><div class="line" id="file-gistfile1-txt-LC1" style="box-sizing: border-box;">invoke void @cc_invoke({ {}*, i64 }* %result-ptr, {}* %3, i64 2, {}* %4, {}* %5, {}* null, {}* null, {}* null)
</div><div class="line" id="file-gistfile1-txt-LC2" style="box-sizing: border-box;">    to label %return0 unwind label %landing-pad1
</div><div class="line" id="file-gistfile1-txt-LC3" style="box-sizing: border-box;">return0:
</div><div class="line" id="file-gistfile1-txt-LC4" style="box-sizing: border-box;">  ret void
</div><div class="line" id="file-gistfile1-txt-LC5" style="box-sizing: border-box;"> 
</div><div class="line" id="file-gistfile1-txt-LC6" style="box-sizing: border-box;">landing-pad1:                                     ; No predecessors!
</div><div class="line" id="file-gistfile1-txt-LC7" style="box-sizing: border-box;">  %6 = landingpad { i8*, i32 } personality i32 (...)* @__gxx_personality_v0
</div><div class="line" id="file-gistfile1-txt-LC8" style="box-sizing: border-box;">          cleanup
</div><div class="line" id="file-gistfile1-txt-LC9" style="box-sizing: border-box;">  resume { i8*, i32 } %6
</div><div class="line" id="file-gistfile1-txt-LC10" style="box-sizing: border-box;">}</div></pre><div><br></div><div>The CatchThrow exception is caught and everything works fine!  I don’t need to call the caller or any outer function with “invoke” except for in the function that has the landing pad that recognizes core::CatchThrow.</div><div><br></div><div>I don’t see anything in the Itanium ABI that says I need to call the function that throws an exception with “invoke” to get exception handling to work!</div><div><br></div><div>Does anyone have any ideas what I might be doing wrong?</div><div><br></div><div><br></div><br></div><div><br></div><div><br></div><div><br></div><div><br><div><div>On Apr 9, 2015, at 6:59 PM, Lang Hames <<a href="mailto:lhames@gmail.com">lhames@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">Hi Christian,<div><br></div><div>Andy's already covered the major points, but you could consider filing a bug at <a href="http://llvm.org/bugs">http://llvm.org/bugs</a> too, especially if you've got a small test-case that demonstrates the issue. Exception handling hasn't been a priority in the past, but as more people adopt LLVM's JIT APIs I suspect it will get more attention, and bug reports will help us figure out what needs doing. </div><div><br></div><div>Cheers,</div><div>Lang.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 9, 2015 at 11:43 AM, Kaylor, Andrew <span dir="ltr"><<a href="mailto:andrew.kaylor@intel.com" target="_blank">andrew.kaylor@intel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div lang="EN-US" link="blue" vlink="purple">
<div><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Hi Christian,<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">I suspect that at least some of the details depend on what platform you’re working on.  I believe that MCJIT attempts to register eh frame information for either
 MachO or ELF objects (though for some ELF platforms nothing actually happens).  What happens to it after that is a darker area, at least for me.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Apparently there was a GDB command that did just what you want -- “info catch” -- but I had never used it and it has been removed.  It’s too bad because it
 sounds like a nice feature.  It was supposed to dump a list of catch handlers for whatever frame you’re looking at.  I suspect, however, that it would have just confirmed that your catch handler isn’t properly hooked up without being helpful in figuring out
 why.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">You could try debugging the RuntimeDyld code that registers eh frames and see if that looks right.  RuntimeDyld::registerEHFrames() might be a helpful starting
 point.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">-Andy<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<div>
<div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0in 0in 0in"><p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> <a href="mailto:llvmdev-bounces@cs.uiuc.edu" target="_blank">llvmdev-bounces@cs.uiuc.edu</a> [mailto:<a href="mailto:llvmdev-bounces@cs.uiuc.edu" target="_blank">llvmdev-bounces@cs.uiuc.edu</a>]
<b>On Behalf Of </b>Christian Schafmeister<br>
<b>Sent:</b> Wednesday, April 08, 2015 10:09 PM<br>
<b>To:</b> LLVM Developers Mailing List<br>
<b>Subject:</b> [LLVMdev] Looking for advice on how to debug a problem with C++ style exception handling code that my compiler generates.<u></u><u></u></span></p>
</div>
</div><div><div class="h5"><p class="MsoNormal"><u></u> <u></u></p>
<div><p class="MsoNormal"><u></u> <u></u></p>
</div>
<div><p class="MsoNormal">Hi,<u></u><u></u></p>
</div>
<div><p class="MsoNormal"><u></u> <u></u></p>
</div>
<div><p class="MsoNormal">I’m looking for advice on how to debug a problem with my exception handling code.  <u></u><u></u></p>
</div>
<div><p class="MsoNormal">I’m asking a specific question here - but general advice on how to debug something like this would be greatly appreciated.<u></u><u></u></p>
</div>
<div><p class="MsoNormal"><u></u> <u></u></p>
</div><p class="MsoNormal">Is there any way to get a list of landing pad clauses that are active at a particular point in a program?<br>
I'd like to get something like a backtrace but listing all active landing pad clauses. The typeids of the C++ types <br>
I'm trying to debug a problem where an exception that I'm throwing is not being caught.   <u></u><u></u></p>
<div><p class="MsoNormal">I'm generating JITed code with LLVM and landing pads and I've got shared libraries - lots of things going on that could potentially be going wrong.<u></u><u></u></p>
</div>
<div><p class="MsoNormal"><u></u> <u></u></p>
</div>
<div><p class="MsoNormal">A list of the pointer values like @_ZTIN4core9DynamicGoE is what I’m looking for.  Then I could compare that to the typeids that I know should be in that list.<u></u><u></u></p>
</div>
<div><p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<div><p class="MsoNormal"><span style="font-family:Courier">"(TRY-0).landing-pad":                            ; preds = %"(TRY-0).normal-dest14", %"(TRY-0).tagbody-B-1", %"(TRY-0).normal-dest10", %"(TRY-0).normal-dest9", %"(TRY-0).normal-dest8", %"(TRY-0).normal-dest",
 %"(TRY-0).tagbody-#:G1621-0"</span><u></u><u></u></p>
</div>
<div><p class="MsoNormal"><span style="font-family:Courier">  %14 = landingpad { i8*, i32 } personality i32 (...)* @__gxx_personality_v0</span><u></u><u></u></p>
</div>
<div><p class="MsoNormal"><span style="font-family:Courier">          catch i8* @_ZTIN4core9DynamicGoE</span><u></u><u></u></p>
</div>
<div><p class="MsoNormal"><span style="font-family:Courier">          catch i8* @_ZTIN4core10ReturnFromE, !dbg !26</span><u></u><u></u></p>
</div>
<div><p class="MsoNormal"><span style="font-family:Courier">  %15 = extractvalue { i8*, i32 } %14, 0, !dbg !26</span><u></u><u></u></p>
</div>
<div><p class="MsoNormal"><span style="font-family:Courier">  %16 = extractvalue { i8*, i32 } %14, 1, !dbg !26</span><u></u><u></u></p>
</div>
<div><p class="MsoNormal"><span style="font-family:Courier">  %17 = call i32 @llvm.eh.typeid.for(i8* @_ZTIN4core9DynamicGoE), !dbg !26</span><u></u><u></u></p>
</div>
<div><p class="MsoNormal"><span style="font-family:Courier">  %18 = icmp eq i32 %16, %17, !dbg !26</span><u></u><u></u></p>
</div>
<div><p class="MsoNormal"><span style="font-family:Courier">  br i1 %18, label %"(TRY-0).handler-block14470", label %"(TRY-0).dispatch-header19", !dbg !26</span><u></u><u></u></p>
</div>
</div>
<div><p class="MsoNormal"><u></u> <u></u></p>
</div>
<div><p class="MsoNormal"><span style="font-family:"Arial","sans-serif"">I’m getting this error when I throw a core::Unwind exception and I’m certain that there is a landing pad with that clause.</span><u></u><u></u></p>
</div>
<div><p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<div><p class="MsoNormal"><span style="font-family:Courier">libc++abi.dylib: terminating with uncaught exception of type core::Unwind</span><u></u><u></u></p>
</div>
<div><p class="MsoNormal"><span style="font-family:Courier">../../src/gctools/<a href="http://memorymanagement.cc/" target="_blank">memoryManagement.cc</a>:75 Trapped SIGABRT - starting debugger</span><u></u><u></u></p>
</div>
<div><p class="MsoNormal"><span style="font-family:Courier">ABORT was called!!!!!!!!!!!!</span><u></u><u></u></p>
</div>
<div><p class="MsoNormal"><span style="font-family:Courier"><u></u> <u></u></span></p>
</div>
</div>
<div><p class="MsoNormal"><u></u> <u></u></p>
</div>
<div><p class="MsoNormal">I’ve written a Common Lisp compiler that uses LLVM as the backend and it interoperates with C++ code and I use C++ exception handling for non-local exits.<u></u><u></u></p>
</div>
</div></div></div>
</div>

<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu/" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div></body></html>