Skip to content
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

ios: bugfix for wrong userInfo #68

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions ios/ReactNativeExceptionHandler.m
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@
#import "ReactNativeExceptionHandler.h"

#import <mach-o/dyld.h>

// CONSTANTS
NSString * const RNUncaughtExceptionHandlerSignalExceptionName = @"RNUncaughtExceptionHandlerSignalExceptionName";
NSString * const RNUncaughtExceptionHandlerSignalKey = @"RNUncaughtExceptionHandlerSignalKey";
NSString * const RNUncaughtExceptionHandlerAddressesKey = @"RNUncaughtExceptionHandlerAddressesKey";
volatile int32_t RNUncaughtExceptionCount = 0;
const int32_t RNUncaughtExceptionMaximum = 10;
const NSInteger RNUncaughtExceptionHandlerSkipAddressCount = 4;
const NSInteger RNUncaughtExceptionHandlerReportAddressCount = 5;
const NSInteger RNUncaughtExceptionHandlerSkipAddressCount = 0;
const NSInteger RNUncaughtExceptionHandlerReportAddressCount = 15;


void getSlide(long* pheader,long* pslide) {
for (uint32_t i = 0; i < _dyld_image_count(); i++) {
if (_dyld_get_image_header(i)->filetype == MH_EXECUTE) {
long slide = _dyld_get_image_vmaddr_slide(i);
const struct mach_header* header = _dyld_get_image_header(i);
if(pheader)*pheader=header;
if(pslide)*pslide=slide;

return;
}
}
}

long letMeCrash(){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also please remove these test functions as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I have opened a new PR.
I had thought that only the commits before opening are visible, so I commit my own modify after open it, but it's not the truth. now I make a special branch for this, hope it's ok this time~

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by the way , except those test functions, getting and saving the slide is useful for symbol address translation, would you like it to be merged?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I want to merge everything except the test functions

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove only the test functions.

int* p = 1234;
*p = 1;
return 0;
}
long funcImyourDD(){ if(RNUncaughtExceptionCount%2) printf("funcImyourDD11");else printf("funcImyourDD22"); return letMeCrash();}
long funcFuckyourBB(){ if(RNUncaughtExceptionCount%2) printf("funcFuckyourBB11");else printf("funcFuckyourBB22"); return RNUncaughtExceptionCount+funcImyourDD();}
long funcAreyouSB(){ if(RNUncaughtExceptionCount%2) printf("funcAreyouSB11");else printf("funcAreyouSB22"); return RNUncaughtExceptionCount+funcFuckyourBB();}

@implementation ReactNativeExceptionHandler

Expand Down Expand Up @@ -59,8 +81,9 @@ - (dispatch_queue_t)methodQueue
// ====================================

RCT_EXPORT_MODULE();

// METHOD TO INITIALIZE THE EXCEPTION HANDLER AND SET THE JS CALLBACK BLOCK
RCT_EXPORT_METHOD(raiseTestNativeError) { NSLog(@"RAISING A TEST EXCEPTION"); [NSException raise:@"TEST EXCEPTION" format:@"THIS IS A TEST EXCEPTION"]; }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned on the issue before . I dont think we should add raiseTestNative Error as part of this module. Could you please remove these.

RCT_EXPORT_METHOD(raiseTestNativeErrorCXX) { NSLog(@"RAISING A TEST EXCEPTION"); funcAreyouSB(); }
// METHOD TO INITIALIZE THE EXCEPTION HANDLER AND SET THE JS CALLBACK BLOCK
RCT_EXPORT_METHOD(setHandlerforNativeException:(RCTResponseSenderBlock)callback)
{
jsErrorCallbackBlock = ^(NSException *exception, NSString *readeableException){
Expand Down Expand Up @@ -199,10 +222,7 @@ void SignalHandler(int signal)
[NSString stringWithFormat:
NSLocalizedString(@"Signal %d was raised.", nil),
signal]
userInfo:
[NSDictionary
dictionaryWithObject:[NSNumber numberWithInt:signal]
forKey:RNUncaughtExceptionHandlerSignalKey]]
userInfo:userInfo]
waitUntilDone:YES];
}

Expand All @@ -219,6 +239,10 @@ + (NSArray *)backtrace

int i;
NSMutableArray *backtrace = [NSMutableArray arrayWithCapacity:frames];

long header=0,slide=0;
getSlide(&header, &slide);
[backtrace addObject:[NSString stringWithFormat:@"slideheader: 0x%X",header]];
for (
i = RNUncaughtExceptionHandlerSkipAddressCount;
i < RNUncaughtExceptionHandlerSkipAddressCount +
Expand Down