Skip to content

Improve C++ Exception Handling with Fishhook #4517

@philipphofmann

Description

@philipphofmann

We could use fishhook to enhance C++ exception. Currently, the Sentry SDK uses dlsym to look up __cxa_throw.

orig_cxa_throw = (cxa_throw_type)dlsym(RTLD_NEXT, "__cxa_throw");

This approach falls short in applications with multiple dynamic libraries, as exceptions thrown in those separate modules aren’t caught by the main exception handler, but it works fine when Sentry is linked statically into the same module.

By using fishhook, which allows functions to be “hooked” by name as they are loaded across various modules, we could dynamically find and intercept all instances of __cxa_throw, even in different dynamic libraries. This would provide more comprehensive and consistent exception handling across an app’s runtime, regardless of the number of C++ modules or how they’re linked.

We used fishhook in the past for trying to get async stacktraces (#998), but we removed it again because it was not working reliably. The problem wasn't fishhook, but how we used it. We now use backtrace_async for async stacktrace in Swift.

This could maybe help with:

Metadata

Metadata

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions