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

[Plat-12269] Prevent inlining of stack trace entries that are going to be pruned #1661

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
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
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
Loading