<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">HI all,<div class=""><br class=""></div><div class="">Here in the JUCE team, we are working on porting the <a href="https://www.juce.com/releases/projucer-juce-4" class="">Projucer</a> C++ live coding engine to Windows. Our main challenge now is <span style="background-color: rgb(255, 255, 255);" class="">how to catch C++ exceptions in runtime-compiled code on Windows. This doesn’t work for us and we’re quite stuck at this point. </span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><br class=""></span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class="">I recently had a chat about this with Chandler Carruth at C++Now. Chandler suggested that we post our problem to this mailing list, and that perhaps Reid Kleckner and/or other people here may have some hints. Any ideas would be highly appreciated!</span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><br class=""></span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class="">In our case the RaiseException API function does not find the correct catch pad, which may be caused by a ThrowInfo structure handed to _CxxThrowException being empty. Apart from getting this right, is there anything else we possibly miss? Windows API functions to be called for registering catch pads or so?<br class=""><br class="">Some more details:<br class="">We're using Clang for compiling C++ code at runtime and the ORC libraries to load and execute it in our application, which is itself compiled with MSVC. We work with the release_38 branches of LLVM and Clang.<br class=""><br class="">Static compilation of a simple test program with try/catch and throw works fine. When compiling the same code at runtime and loading it with the ORC libraries, every throw results in an unhandled exception. The point of interest seems to be the throw handler for C++ exceptions (throw.cpp):<br class=""><br class=""><font face="Menlo" class="">__declspec(noreturn) extern "C" void __stdcall<br class="">_CxxThrowException(void* pExceptionObject, _ThrowInfo* pThrowInfo)<br class="">{<br class="">    ...<br class="">    RaiseException( ThisException.ExceptionCode,<br class="">                    ThisException.ExceptionFlags,<br class="">                    ThisException.NumberParameters,<br class="">                    (PULONG_PTR)&ThisException.params );<br class="">}</font><br class=""><br class="">For some reason the call to RaiseException does not find or consider the existing catch handler correctly. Comparing execution states when entering the function between the two cases, static- vs. runtime-compiled, turns out that pThrowInfo points to nulled memory in the runtime-compiled case, while it has some data in the static-compiled case. Detailed information about the types can be found here: </span><span style="background-color: rgb(255, 255, 255);" class=""> </span><a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://www.openrce.org/articles/full_view/21">http://www.openrce.org/articles/full_view/21</a><span style="background-color: rgb(255, 255, 255);" class="">. Most</span><span style="background-color: rgb(255, 255, 255);" class=""> </span><span style="background-color: rgb(255, 255, 255);" class="">likely the "attributes" and "pCatchableTypeArray" members are required for RaiseException to resolve the correct catch pad?</span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><br class="">To find out why the ThrowInfo structure is empty in the runtime-compiled case, we compared what happens during code generation. It looks like CodeGenFunction::EmitCXXThrowExpr is the relevant function here and it does the right thing, i.e. generating the global variable for the ThrowInfo in MicrosoftCXXABI::emitThrow. Also the WinEHPrepare pass is running correctly as it seems. Is there any extra work to do (at runtime/link-time?) for filling this data structure? Any idea what else to check?<br class=""><br class="">Our Clang language options do include: Exceptions, CXXExceptions, RTTI, RTTIData</span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><br class=""></span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class="">Please reply to my colleague Stefan Gränitz (in Cc) who is in charge of this project. Any kind of help or ideas would be really awesome.</span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><br class=""></span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class="">Many thanks!</span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class="">Timur</span></div><div class=""><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="gmail_default" style="font-family: arial, helvetica, sans-serif;"><div dir="ltr" style="font-family: arial, sans-serif; font-size: 13px;" class=""><p class=""><span style="font-family: Helvetica; font-size: 12px;" class="">-- </span></p><div class="gmail_signature" style="font-family: Helvetica; font-size: 12px;"><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div style="font-family: Arial, sans-serif;" class=""><font face="Arial" color="#444444" class=""><b class="">Timur Doumler</b></font></div><div class=""><div dir="ltr" class=""><font color="#444444" face="Arial" class=""><b class="">JUCE Senior Software Engineer</b></font></div></div></div></div></div></div><p class=""><i style="font-size: 12.8px; color: rgb(26, 26, 26); font-family: Arial;" class=""><a href="http://www.roli.com/" target="_blank" class="">ROLI</a> extends the journey of music creation to everyone. The <a href="http://www.roli.com/press/reviews " class="">acclaimed </a><a href="http://www.roli.com/products/seaboard-grand" target="_blank" class="">Seaboard GRAND</a> and <a href="http://www.roli.com/products/seaboard-rise" class="">Seaboard RISE</a> redefine how expressive and versatile an electronic musical instrument can be. Our groundbreaking software <a href="http://www.roli.com/equator" target="_blank" class="">Equator</a> opens up new dimensions of sonic expression, and is built with <a href="http://www.juce.com/" target="_blank" class="">JUCE</a>, ROLI’s proprietary coding platform, and the leading C++ framework for audio applications globally. <a href="http://www.blend.io/" target="_blank" class="">Blend</a> enables everyone to seamlessly collaborate, share, and remix their music. And <a href="http://www.roli.com/noise" target="_blank" class="">NOISE</a> is the most expressive app ever made — see for yourself: <a href="https://itunes.apple.com/app/noise-5d/id1011132019?ls=1&mt=8" target="_blank" class="">download it now for free!</a></i></p></div></div><div class="gmail_signature"><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><font color="#444444" face="Arial" class=""><b class=""><br class=""></b></font></div><div class=""><font color="#444444" face="Arial" size="2" class="">Mobile: +44 (0) 7539 947960</font></div><div class=""><font color="#444444" face="Arial" size="2" class="">Office: +44 (0) 2072 542155</font></div><div class=""><font color="#444444" face="Arial" size="2" class=""><br class=""></font></div><div class=""><font color="#444444" face="Arial" size="2" class="">ROLI </font></div><div class=""><font color="#444444" face="Arial" size="2" class="">2 Glebe Rd, London E8 4BD</font></div><div class=""><font color="#444444" face="Arial" size="2" class=""><a href="http://www.roli.com" target="_blank" class="">www.roli.com</a></font></div></div></div></div></div></div></div></div></div>
</div>
<br class=""></div></body></html>