Skip to content

Commit

Permalink
Merge pull request #1661 from bugsnag/PLAT-12269-stack-trace-pruning
Browse files Browse the repository at this point in the history
[Plat-12269] Prevent inlining of stack trace entries that are going to be pruned
  • Loading branch information
kstenerud authored Jun 18, 2024
2 parents 0cb6388 + c1a4f5f commit 56a3622
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
22 changes: 16 additions & 6 deletions Bugsnag/Client/BugsnagClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 56a3622

Please sign in to comment.