microsoft / plcrashreporter

Reliable, open-source crash reporting for iOS, macOS and tvOS
Other
2.9k stars 538 forks source link

Unknown Objective C Exception: instrumentation could not capture original exception. #324

Open ManoharaReddyP opened 2 months ago

ManoharaReddyP commented 2 months ago

Description

We are using C++ library in our swift project which has below functions

void CPPTerminateSetHandler(CPPExceptionHandler handler) { set_terminate(handler); }

I want to understand is there anyway to block this C++ termination handler, or say, is there any way to expose the original NSException.

Currently getting below error message: Unknown Objective C Exception: instrumentation could not capture original exception. instead of displaying original

Repro Steps

Please list the steps used to reproduce your issue.

  1. Create sample cpp project and add above lines in cpp
  2. Add this as dependency to sample app and call cpp functions

    DemoLib.setCplusplusTerminateHandler { print("Hello, Exception!") }

Details

  1. Which SDK version are you using? 1.11.0

  2. Which OS version did you experience the issue on? 15.2 but seems like it's reproduce in all version

  3. Which CocoaPods/Carthage/Xcode version are you using? -> SPM

  4. What device version did you see this error on? Were you using an emulator or a physical device? -> Simualtor

  5. What language are you using?

    • Objective C
    • Swift
  6. What third party libraries are you using? No

IlyaBausovAkvelon commented 1 month ago

Hi, thank you for reporting! Do you disable Xcode's debugger? What is the class CPPExceptionHandler? What does it do? How do you use PLCrashReporter in this particular scenario?

ManoharaReddyP commented 1 month ago

Hi @IlyaBausovAkvelon,

No we did't disabled Xcode debugger

CPPExceptionHandler is a mechanism typically used in cross-platform mobile applications to handle C++ exceptions that occur in native code, particularly in environments where Objective-C, Swift is used as the main application code but C++ library imported for some functionality. in this case exception being thrown from c++ using below code

(void)setCplusplusTerminateHandler:(CPPExceptionHandler)handler { CPPTerminateSetHandler(handler); }

that library being used in Objective-C project where we use PLCrashReporter to fetch crash reports and show meaning full info but seems like PLCrashreporter does't handle this exception it shown message like below

Screenshot 2024-10-04 at 3 20 48 PM
IlyaBausovAkvelon commented 1 month ago

Hi @ManoharaReddyP, First of all, you should disable Xcode's debugger to make the PLCrashReporter to work with your project.

Could you please provide us with simple demo application to reproduce this issue?

ManoharaReddyP commented 1 month ago

Hi @IlyaBausovAkvelon,

Please find the sample library (https://github.com/RockyCognizant/CPPDemoLib) which has code that I mentioned above and import in sample project and call like below which results into crash and see if PLcrashreporter is able to capture info.

DemoLib.setCplusplusTerminateHandler { print("Hello, Exception!") }

IlyaBausovAkvelon commented 2 weeks ago

@ManoharaReddyP thank you for demo. Could you please tell us did turning off the debugger helped?

ManoharaReddyP commented 2 weeks ago

Hi @IlyaBausovAkvelon,

This is happening even after disabling debugger. Did you get a chance to try to reproduce the issue with disabling debugger with above code?

DmitriyKirakosyan commented 1 week ago

@ManoharaReddyP , PLCrashReporter has limitations working with C++ exceptions, especially if the c++ library is linked dynamically. It may miss expected information in call stacks, depending on type of exception.

If you want to handle the C++ exception manually, you can define a handler in C++ file and get information about the exception using std::current_exception() and std::rethrow_exception(ptr).