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

Fix handled stacktrace generation #348

Merged
merged 7 commits into from
May 21, 2019
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

## 5.22.1 (2019-05-20)

* Fix handled stacktrace generation
[#348](https://github.com/bugsnag/bugsnag-cocoa/pull/348)

## 5.22.0 (2019-05-09)

This release disables background out-of-memory termination reporting by default,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,23 @@ void bsg_kscrashsentry_reportUserException(const char *name,
BSG_KSLOG_WARN("User-reported exception sentry is not installed. "
"Exception has not been recorded.");
} else {
// We want these variables to persist until the onCrash
// call later
int callstackCount = 100;
uintptr_t callstack[callstackCount];

bsg_kscrashsentry_beginHandlingCrash(bsg_g_context);

if (bsg_g_context->suspendThreadsForUserReported) {
BSG_KSLOG_DEBUG("Suspending all threads");
bsg_kscrashsentry_suspendThreads();
}


if (stackAddresses != NULL && stackLength > 0) {
bsg_g_context->stackTrace = stackAddresses;
bsg_g_context->stackTraceLength = (int)stackLength;
} else {
BSG_KSLOG_DEBUG("Fetching call stack.");
int callstackCount = 100;
uintptr_t callstack[callstackCount];
callstackCount = backtrace((void **)callstack, callstackCount);
if (callstackCount <= 0) {
BSG_KSLOG_ERROR("backtrace() returned call stack length of %d",
Expand Down
3 changes: 3 additions & 0 deletions features/handled_errors.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Scenario: Override errorClass and message from a notifyError() callback
And the exception "errorClass" equals "Bar"
And the exception "message" equals "Foo"
And the event "device.time" is within 30 seconds of the current timestamp
And the stack trace is an array with 22 stack frames

Scenario: Reporting an NSError
When I run "HandledErrorScenario"
Expand All @@ -17,6 +18,7 @@ Scenario: Reporting an NSError
And the payload field "events" is an array with 1 element
And the exception "errorClass" equals "NSError"
And the exception "message" equals "The operation couldn’t be completed. (HandledErrorScenario error 100.)"
And the stack trace is an array with 22 stack frames

Scenario: Reporting a handled exception
When I run "HandledExceptionScenario"
Expand All @@ -27,6 +29,7 @@ Scenario: Reporting a handled exception
And the payload field "events" is an array with 1 element
And the exception "errorClass" equals "HandledExceptionScenario"
And the exception "message" equals "Message: HandledExceptionScenario"
And the stack trace is an array with 22 stack frames

Scenario: Reporting a handled exception's stacktrace
When I run "NSExceptionShiftScenario"
Expand Down
5 changes: 5 additions & 0 deletions features/steps/ios_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,8 @@
end
assert_not_nil(match, "No crumb matches the provided message")
end

Then("the stack trace is an array with {int} stack frames") do |expected_length|
stack_trace = read_key_path(find_request(0)[:body], "events.0.exceptions.0.stacktrace")
assert_equal(stack_trace.length, expected_length)
end