Skip to content

Commit

Permalink
Limit fetching the current thread name to OS that have at least libpt…
Browse files Browse the repository at this point in the history
…hread-330.201.1
  • Loading branch information
kstenerud committed Jun 20, 2022
1 parent ae3a3d8 commit 6398f26
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 5 deletions.
13 changes: 9 additions & 4 deletions Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSCrashReport.c
Original file line number Diff line number Diff line change
Expand Up @@ -928,10 +928,15 @@ void bsg_kscrw_i_writeThread(const BSG_KSCrashReportWriter *const writer,
isCrashedThread);
writer->addBooleanElement(writer, BSG_KSCrashField_CurrentThread,
isSelfThread);
if (isSelfThread) {
char buff[100];
bsg_ksmachgetThreadName(thread, buff, sizeof(buff));
writer->addStringElement(writer, BSG_KSCrashField_Name, buff);

// Fetching the current thread name is only safe as of libpthread-330.201.1
// which was used in ios+tvos 12 and macos 10.14
if(__builtin_available(iOS 12.0, tvOS 12.0, macOS 10.14, *)) {
if (isSelfThread) {
char buff[100];
bsg_ksmachgetThreadName(thread, buff, sizeof(buff));
writer->addStringElement(writer, BSG_KSCrashField_Name, buff);
}
}
if (isCrashedThread && machineContext != NULL) {
bsg_kscrw_i_writeStackOverflow(writer, BSG_KSCrashField_Stack,
Expand Down
3 changes: 2 additions & 1 deletion Bugsnag/KSCrash/Source/KSCrash/Recording/Tools/BSG_KSMach.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ pthread_t bsg_ksmachpthreadFromMachThread(const thread_t thread) {

bool bsg_ksmachgetThreadName(const thread_t thread, char *const buffer,
size_t bufLength) {
// WARNING: This implementation is only async-safe for the current thread!
// WARNING: This implementation is only async-safe for the current thread
// as of libpthread-330.201.1, and is still unsafe for other threads.

const pthread_t pthread = pthread_from_mach_thread_np(thread);
if (pthread == NULL) {
Expand Down
8 changes: 8 additions & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,18 @@ def skip_below(os, version)
skip_below('ios', 11)
end

Before('@skip_below_ios_12') do |scenario|
skip_below('ios', 12)
end

Before('@skip_below_ios_13') do |scenario|
skip_below('ios', 13)
end

Before('@skip_below_macos_10_14') do |scenario|
skip_below('macos', 10.14)
end

Before('@skip_below_macos_10_15') do |scenario|
skip_below('macos', 10.15)
end
Expand Down
32 changes: 32 additions & 0 deletions features/unhandled_cpp_exception.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ Feature: Thrown C++ exceptions are captured by Bugsnag
And the event "severity" equals "error"
And the event "unhandled" is true
And the event "severityReason.type" equals "unhandledException"

@skip_below_macos_10_14
@skip_below_ios_12
Scenario: Throwing a C++ exception and get thread name
When I run "CxxExceptionScenario" and relaunch the crashed app
And I configure Bugsnag for "CxxExceptionScenario"
And I wait to receive an error
Then the error is valid for the error reporting API
And the event "threads.0.name" equals "потік"

Scenario: Throwing a C++ exception with unhandled override
Expand All @@ -28,6 +36,14 @@ Feature: Thrown C++ exceptions are captured by Bugsnag
And the event "unhandled" is false
And the event "severityReason.unhandledOverridden" is true
And the event "severityReason.type" equals "unhandledException"

@skip_below_macos_10_14
@skip_below_ios_12
Scenario: Throwing a C++ exception with unhandled override and get thread name
When I run "CxxExceptionOverrideScenario" and relaunch the crashed app
And I configure Bugsnag for "CxxExceptionOverrideScenario"
And I wait to receive an error
Then the error is valid for the error reporting API
And the event "threads.0.name" equals "BSG MAIN THREAD"

Scenario: Throwing without an exception
Expand All @@ -38,6 +54,14 @@ Feature: Thrown C++ exceptions are captured by Bugsnag
And the exception "errorClass" equals "std::terminate"
And the exception "message" equals "throw may have been called without an exception"
And the "method" of stack frame 2 equals "-[CxxBareThrowScenario run]"

@skip_below_macos_10_14
@skip_below_ios_12
Scenario: Throwing without an exception and get thread name
When I run "CxxBareThrowScenario" and relaunch the crashed app
And I configure Bugsnag for "CxxBareThrowScenario"
And I wait to receive an error
Then the error is valid for the error reporting API
And the event "threads.0.name" equals "œ´¨ø“‘"

Scenario: Causing an unexpected event
Expand All @@ -48,4 +72,12 @@ Feature: Thrown C++ exceptions are captured by Bugsnag
And the exception "errorClass" equals "std::terminate"
And the exception "message" equals "throw may have been called without an exception"
And the "method" of stack frame 4 equals "-[CxxUnexpectedScenario run]"

@skip_below_macos_10_14
@skip_below_ios_12
Scenario: Causing an unexpected event and get thread name
When I run "CxxUnexpectedScenario" and relaunch the crashed app
And I configure Bugsnag for "CxxUnexpectedScenario"
And I wait to receive an error
Then the error is valid for the error reporting API
And the event "threads.0.name" equals "BSG MAIN THREAD"
16 changes: 16 additions & 0 deletions features/unhandled_nsexception.feature
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ Feature: Uncaught NSExceptions are captured by Bugsnag
And the event "severity" equals "error"
And the event "unhandled" is true
And the event "severityReason.type" equals "unhandledException"

@skip_below_macos_10_14
@skip_below_ios_12
Scenario: Throw a NSException and get thread name
When I run "ObjCExceptionScenario" and relaunch the crashed app
And I configure Bugsnag for "ObjCExceptionScenario"
And I wait to receive an error
Then the error is valid for the error reporting API
And the event "threads.0.name" equals "BSG MAIN THREAD"

Scenario: Throw a NSException with unhandled override
Expand All @@ -38,4 +46,12 @@ Feature: Uncaught NSExceptions are captured by Bugsnag
And the event "unhandled" is false
And the event "severityReason.unhandledOverridden" is true
And the event "severityReason.type" equals "unhandledException"

@skip_below_macos_10_14
@skip_below_ios_12
Scenario: Throw a NSException with unhandled override and get thread name
When I run "ObjCExceptionOverrideScenario" and relaunch the crashed app
And I configure Bugsnag for "ObjCExceptionOverrideScenario"
And I wait to receive an error
Then the error is valid for the error reporting API
And the event "threads.0.name" equals "メインスレッド"

0 comments on commit 6398f26

Please sign in to comment.