diff --git a/Bugsnag/Client/BugsnagClient.m b/Bugsnag/Client/BugsnagClient.m index 386b1867e..73215e52c 100644 --- a/Bugsnag/Client/BugsnagClient.m +++ b/Bugsnag/Client/BugsnagClient.m @@ -641,28 +641,37 @@ - (NSString *)context { // MARK: - Notify +// Prevent the compiler from inlining or optimizing, which would reduce +// the number of bugsnag-only stack entries and mess up our pruning. +// We have to do it this way because you can't mark Objective-C methods noinline or optnone. +// We leave it externable to further dissuade the optimizer. +__attribute__((optnone)) +void bsg_notifyErrorOrException(BugsnagClient *self, id errorOrException, BugsnagOnErrorBlock block) { + [self notifyErrorOrException:errorOrException block:block]; +} + // note - some duplication between notifyError calls is required to ensure // the same number of stackframes are used for each call. // see notify:handledState:block for further info - (void)notifyError:(NSError *)error { bsg_log_debug(@"%s %@", __PRETTY_FUNCTION__, error); - [self notifyErrorOrException:error block:nil]; + bsg_notifyErrorOrException(self, error, nil); } - (void)notifyError:(NSError *)error block:(BugsnagOnErrorBlock)block { bsg_log_debug(@"%s %@", __PRETTY_FUNCTION__, error); - [self notifyErrorOrException:error block:block]; + bsg_notifyErrorOrException(self, error, block); } - (void)notify:(NSException *)exception { bsg_log_debug(@"%s %@", __PRETTY_FUNCTION__, exception); - [self notifyErrorOrException:exception block:nil]; + bsg_notifyErrorOrException(self, exception, nil); } - (void)notify:(NSException *)exception block:(BugsnagOnErrorBlock)block { bsg_log_debug(@"%s %@", __PRETTY_FUNCTION__, exception); - [self notifyErrorOrException:exception block:block]; + bsg_notifyErrorOrException(self, exception, block); } // MARK: - Notify (Internal) @@ -731,9 +740,10 @@ - (void)notifyErrorOrException:(id)errorOrException block:(BugsnagOnErrorBlock)b * * 1. +[Bugsnag notifyError:block:] * 2. -[BugsnagClient notifyError:block:] - * 3. -[BugsnagClient notify:handledState:block:] + * 3. bsg_notifyErrorOrException() + * 4. -[BugsnagClient notifyErrorOrException:block:] */ - NSUInteger depth = 3; + NSUInteger depth = 4; if (!callStack.count) { // If the NSException was not raised by the Objective-C runtime, it will be missing a call stack. diff --git a/CHANGELOG.md b/CHANGELOG.md index cb65bc1d6..04c6a8950 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ Changelog ### Bug fixes +* Prevent inlining of Bugsnag stack trace entries that are marked to be pruned away (to promote a consistent number of those frames). + [1661](https://github.com/bugsnag/bugsnag-cocoa/pull/1661) + * Fix off-by-1 error when fetching register values on arm64 that could potentially run off the array. [1635](https://github.com/bugsnag/bugsnag-cocoa/pull/1635)