-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add helper function for C++ exception formatting #16343
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
3cf21a0
Wrote format_exception function and hard coded inclusion into system_…
hoodmane 2ea06c8
Add Javascript wrapper, miscellaneous cleanup
hoodmane 693f677
Fix formatting
hoodmane 95ef456
No need for exportedAsmFunction
hoodmane 103dca8
Use withStackSave
hoodmane cc31016
Free the right thing
hoodmane 5ca4f18
Use stackAlloc({{{ POINTER_SIZE }}});
hoodmane aa15cc8
Remove accidental change
hoodmane 493e22f
Add final newline to format_exception.cpp
hoodmane c7d1267
Add emscripten_ prefix to format_exception
hoodmane 0231037
Add format_exception.cpp to libcxxabi
hoodmane af456b1
Use withStackSave correctly
hoodmane e233943
Remove libformatexception library
hoodmane 83a1a4a
Various fixes
hoodmane 5e765ab
Add test
hoodmane 1235600
Remove addresses from test comparison
hoodmane a83007e
Try to fix test
hoodmane 5f19ef5
Fix wasm-exceptions test
hoodmane 86b703b
Fix test
hoodmane a773e9b
Fix INCLUDE_FULL_LIBRARY test
hoodmane 16f160d
Fix flake8
hoodmane fbcf6da
Formatting fixes from sbc100
hoodmane 8ad7932
Fix test
hoodmane 68c129e
Return char* instead of returning by value to avoid stackAlloc
hoodmane c11d036
Remove FORMAT_EXCEPTION_SUPPORT setting
hoodmane 9c0b0a6
Address more review comments
hoodmane 439c09f
Address more review comments
hoodmane 77376ea
Remove unneeded setting
hoodmane 8dad972
Add formatException to EXPORTED_FUNCTIONS rather than EXPORTED_RUNTIM…
hoodmane dcc15f5
Edits from code review
hoodmane File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "cxa_exception.h" | ||
#include "cxxabi.h" | ||
#include <stdio.h> | ||
#include <typeinfo> | ||
|
||
#ifdef __USING_EMSCRIPTEN_EXCEPTIONS__ | ||
|
||
extern "C" { | ||
|
||
int __cxa_can_catch(const std::type_info* catchType, | ||
const std::type_info* excpType, | ||
void** thrown); | ||
|
||
char* emscripten_format_exception(void* exc_ptr) { | ||
__cxxabiv1::__cxa_exception* exc_info = | ||
(__cxxabiv1::__cxa_exception*)exc_ptr - 1; | ||
std::type_info* exc_type = exc_info->exceptionType; | ||
const char* exc_name = exc_type->name(); | ||
|
||
int status = 0; | ||
char* demangled_buf = __cxxabiv1::__cxa_demangle(exc_name, 0, 0, &status); | ||
if (status == 0 && demangled_buf) { | ||
exc_name = demangled_buf; | ||
} | ||
|
||
int can_catch = __cxa_can_catch(&typeid(std::exception), exc_type, &exc_ptr); | ||
char* result = NULL; | ||
if (can_catch) { | ||
const char* exc_what = ((std::exception*)exc_ptr)->what(); | ||
asprintf(&result, "Cpp Exception %s: %s", exc_name, exc_what); | ||
} else { | ||
asprintf(&result, | ||
"Cpp Exception: The exception is an object of type '%s' at " | ||
"address %p which does not inherit from std::exception", | ||
exc_name, | ||
exc_ptr); | ||
} | ||
|
||
if (demangled_buf) { | ||
free(demangled_buf); | ||
} | ||
return result; | ||
} | ||
} | ||
|
||
#endif // __USING_EMSCRIPTEN_EXCEPTIONS__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add
@with_both_eh_sjlj
to this test?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then you can also remove
DISABLE_EXCEPTION_CATCHING
below.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't work with wasm-exceptions. I am not sure how to make it work with
wasm-exceptions
, if you like I can look into it. It would probably be entertaining. But I think it should be a separate PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, can you open a bug about that so that we remember to get it fixed. I imagine @aheejin will want it to work for sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opened #16380 which is where I got stuck in the wasm-exceptions case.