Skip to content

Commit b87555b

Browse files
committed
fix: Remove symbolication that causes deadlocks
1 parent 22af3fc commit b87555b

File tree

9 files changed

+15
-106
lines changed

9 files changed

+15
-106
lines changed

Sources/Sentry/SentryCrashStackEntryMapper.m

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,36 +25,15 @@ - (SentryFrame *)sentryCrashStackEntryToSentryFrame:(SentryCrashStackEntry)stack
2525
{
2626
SentryFrame *frame = [[SentryFrame alloc] init];
2727

28-
if (stackEntry.symbolAddress != 0) {
29-
frame.symbolAddress = sentry_formatHexAddressUInt64(stackEntry.symbolAddress);
30-
}
31-
3228
frame.instructionAddress = sentry_formatHexAddressUInt64(stackEntry.address);
3329

34-
if (stackEntry.symbolName != NULL) {
35-
frame.function = [NSString stringWithCString:stackEntry.symbolName
36-
encoding:NSUTF8StringEncoding];
37-
}
38-
39-
// If there is no symbolication, because debug was disabled
40-
// we get image from the cache.
41-
if (stackEntry.imageAddress == 0 && stackEntry.imageName == NULL) {
42-
SentryBinaryImageInfo *info = [SentryDependencyContainer.sharedInstance.binaryImageCache
43-
imageByAddress:(uint64_t)stackEntry.address];
44-
45-
frame.imageAddress = sentry_formatHexAddressUInt64(info.address);
46-
frame.package = info.name;
47-
frame.inApp = @([self.inAppLogic isInApp:info.name]);
48-
} else {
49-
frame.imageAddress = sentry_formatHexAddressUInt64(stackEntry.imageAddress);
30+
// Get image from the cache.
31+
SentryBinaryImageInfo *info = [SentryDependencyContainer.sharedInstance.binaryImageCache
32+
imageByAddress:(uint64_t)stackEntry.address];
5033

51-
if (stackEntry.imageName != NULL) {
52-
NSString *imageName = [NSString stringWithCString:stackEntry.imageName
53-
encoding:NSUTF8StringEncoding];
54-
frame.package = imageName;
55-
frame.inApp = @([self.inAppLogic isInApp:imageName]);
56-
}
57-
}
34+
frame.imageAddress = sentry_formatHexAddressUInt64(info.address);
35+
frame.package = info.name;
36+
frame.inApp = @([self.inAppLogic isInApp:info.name]);
5837

5938
return frame;
6039
}

Sources/Sentry/SentryDefaultThreadInspector.m

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ @interface SentryDefaultThreadInspector ()
3232
// async-signal-safe.
3333
unsigned int
3434
getStackEntriesFromThread(SentryCrashThread thread, struct SentryCrashMachineContext *context,
35-
SentryCrashStackEntry *buffer, unsigned int maxEntries, bool asyncUnsafeSymbolicate)
35+
SentryCrashStackEntry *buffer, unsigned int maxEntries)
3636
{
3737
sentrycrashmc_getContextForThread(thread, context, NO);
3838
SentryCrashStackCursor stackCursor;
@@ -43,10 +43,8 @@ @interface SentryDefaultThreadInspector ()
4343
while (stackCursor.advanceCursor(&stackCursor)) {
4444
if (entries == maxEntries)
4545
break;
46-
if (asyncUnsafeSymbolicate == false || stackCursor.symbolicate(&stackCursor)) {
47-
buffer[entries] = stackCursor.stackEntry;
48-
entries++;
49-
}
46+
buffer[entries] = stackCursor.stackEntry;
47+
entries++;
5048
}
5149

5250
return entries;
@@ -56,12 +54,10 @@ @implementation SentryDefaultThreadInspector
5654

5755
- (id)initWithStacktraceBuilder:(SentryStacktraceBuilder *)stacktraceBuilder
5856
andMachineContextWrapper:(id<SentryCrashMachineContextWrapper>)machineContextWrapper
59-
symbolicate:(BOOL)symbolicate
6057
{
6158
if (self = [super init]) {
6259
self.stacktraceBuilder = stacktraceBuilder;
6360
self.machineContextWrapper = machineContextWrapper;
64-
self.symbolicate = symbolicate;
6561
}
6662
return self;
6763
}
@@ -75,13 +71,11 @@ - (instancetype)initWithOptions:(SentryOptions *_Nullable)options
7571
[[SentryCrashStackEntryMapper alloc] initWithInAppLogic:inAppLogic];
7672
SentryStacktraceBuilder *stacktraceBuilder =
7773
[[SentryStacktraceBuilder alloc] initWithCrashStackEntryMapper:crashStackEntryMapper];
78-
stacktraceBuilder.symbolicate = options.debug;
7974

8075
id<SentryCrashMachineContextWrapper> machineContextWrapper =
8176
[[SentryCrashDefaultMachineContextWrapper alloc] init];
8277
return [self initWithStacktraceBuilder:stacktraceBuilder
83-
andMachineContextWrapper:machineContextWrapper
84-
symbolicate:options.debug];
78+
andMachineContextWrapper:machineContextWrapper];
8579
}
8680

8781
- (SentryStacktrace *)stacktraceForCurrentThreadAsyncUnsafe
@@ -144,8 +138,6 @@ - (SentryStacktrace *)stacktraceForCurrentThreadAsyncUnsafe
144138
thread_act_array_t suspendedThreads = NULL;
145139
mach_msg_type_number_t numSuspendedThreads = 0;
146140

147-
bool symbolicate = self.symbolicate;
148-
149141
// SentryThreadInspector is crashing when there is too many threads.
150142
// We add a limit of 70 threads because in test with up to 100 threads it seems fine.
151143
// We are giving it an extra safety margin.
@@ -165,7 +157,7 @@ - (SentryStacktrace *)stacktraceForCurrentThreadAsyncUnsafe
165157
for (int i = 0; i < numSuspendedThreads; i++) {
166158
if (suspendedThreads[i] != currentThread) {
167159
int numberOfEntries = getStackEntriesFromThread(suspendedThreads[i], context,
168-
threadsInfos[i].stackEntries, MAX_STACKTRACE_LENGTH, symbolicate);
160+
threadsInfos[i].stackEntries, MAX_STACKTRACE_LENGTH);
169161
threadsInfos[i].stackLength = numberOfEntries;
170162
} else {
171163
// We can't use 'getStackEntriesFromThread' to retrieve stack frames from the

Sources/Sentry/SentryStacktraceBuilder.m

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ - (id)initWithCrashStackEntryMapper:(SentryCrashStackEntryMapper *)crashStackEnt
2424
{
2525
if (self = [super init]) {
2626
self.crashStackEntryMapper = crashStackEntryMapper;
27-
self.symbolicate = NO;
2827
}
2928
return self;
3029
}
@@ -41,10 +40,8 @@ - (SentryStacktrace *)retrieveStacktraceFromCursor:(SentryCrashStackCursor)stack
4140
// skip the marker frame
4241
continue;
4342
}
44-
if (self.symbolicate == NO || stackCursor.symbolicate(&stackCursor)) {
45-
frame = [self.crashStackEntryMapper mapStackEntryWithCursor:stackCursor];
46-
[frames addObject:frame];
47-
}
43+
frame = [self.crashStackEntryMapper mapStackEntryWithCursor:stackCursor];
44+
[frames addObject:frame];
4845
}
4946

5047
return [SentryStacktraceBuilder buildStacktraceFromFrames:frames];
@@ -96,7 +93,6 @@ - (nullable SentryStacktrace *)buildStacktraceForCurrentThreadAsyncUnsafe
9693
SENTRY_LOG_DEBUG(@"Building async-unsafe stack trace...");
9794
SentryCrashStackCursor stackCursor;
9895
sentrycrashsc_initSelfThread(&stackCursor, 0);
99-
stackCursor.symbolicate = sentrycrashsymbolicator_symbolicate_async_unsafe;
10096
return [self retrieveStacktraceFromCursor:stackCursor];
10197
}
10298

Sources/Sentry/include/SentryDefaultThreadInspector.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
1515
SENTRY_NO_INIT
1616

1717
- (id)initWithStacktraceBuilder:(SentryStacktraceBuilder *)stacktraceBuilder
18-
andMachineContextWrapper:(id<SentryCrashMachineContextWrapper>)machineContextWrapper
19-
symbolicate:(BOOL)symbolicate;
18+
andMachineContextWrapper:(id<SentryCrashMachineContextWrapper>)machineContextWrapper;
2019

2120
- (instancetype)initWithOptions:(SentryOptions *_Nullable)options;
2221

Sources/Sentry/include/SentryStacktraceBuilder.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ NS_ASSUME_NONNULL_BEGIN
1515
@interface SentryStacktraceBuilder : NSObject
1616
SENTRY_NO_INIT
1717

18-
/**
19-
* Whether the stack trace frames should be fully symbolicated
20-
* or only contain instruction address and binary image.
21-
*/
22-
@property (nonatomic) BOOL symbolicate;
23-
2418
- (id)initWithCrashStackEntryMapper:(SentryCrashStackEntryMapper *)crashStackEntryMapper;
2519

2620
/**

Sources/SentryCrash/Recording/SentryCrashReport.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -799,20 +799,6 @@ writeBacktrace(const SentryCrashReportWriter *const writer, const char *const ke
799799
while (stackCursor->advanceCursor(stackCursor)) {
800800
writer->beginObject(writer, NULL);
801801
{
802-
if (stackCursor->symbolicate(stackCursor)) {
803-
if (stackCursor->stackEntry.imageName != NULL) {
804-
writer->addStringElement(writer, SentryCrashField_ObjectName,
805-
sentrycrashfu_lastPathEntry(stackCursor->stackEntry.imageName));
806-
}
807-
writer->addUIntegerElement(writer, SentryCrashField_ObjectAddr,
808-
stackCursor->stackEntry.imageAddress);
809-
if (stackCursor->stackEntry.symbolName != NULL) {
810-
writer->addStringElement(writer, SentryCrashField_SymbolName,
811-
stackCursor->stackEntry.symbolName);
812-
}
813-
writer->addUIntegerElement(writer, SentryCrashField_SymbolAddr,
814-
stackCursor->stackEntry.symbolAddress);
815-
}
816802
writer->addUIntegerElement(
817803
writer, SentryCrashField_InstructionAddr, stackCursor->stackEntry.address);
818804
}

Sources/SentryCrash/Recording/Tools/SentryCrashStackCursor.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,12 @@ sentrycrashsc_resetCursor(SentryCrashStackCursor *cursor)
4646
cursor->state.currentDepth = 0;
4747
cursor->state.hasGivenUp = false;
4848
cursor->stackEntry.address = 0;
49-
cursor->stackEntry.imageAddress = 0;
50-
cursor->stackEntry.imageName = NULL;
51-
cursor->stackEntry.symbolAddress = 0;
52-
cursor->stackEntry.symbolName = NULL;
5349
}
5450

5551
void
5652
sentrycrashsc_initCursor(SentryCrashStackCursor *cursor,
5753
void (*resetCursor)(SentryCrashStackCursor *), bool (*advanceCursor)(SentryCrashStackCursor *))
5854
{
59-
cursor->symbolicate = sentrycrashsymbolicator_symbolicate_async_unsafe_sentryDlAddr;
6055
cursor->advanceCursor = advanceCursor != NULL ? advanceCursor : g_advanceCursor;
6156
cursor->resetCursor = resetCursor != NULL ? resetCursor : sentrycrashsc_resetCursor;
6257
cursor->resetCursor(cursor);

Sources/SentryCrash/Recording/Tools/SentryCrashStackCursor.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,6 @@ extern "C" {
4646
typedef struct {
4747
/** Current address in the stack trace. */
4848
uintptr_t address;
49-
50-
/** The name (if any) of the binary image the current address falls
51-
* inside. */
52-
const char *imageName;
53-
54-
/** The starting address of the binary image the current address falls
55-
* inside. */
56-
uintptr_t imageAddress;
57-
58-
/** The name (if any) of the closest symbol to the current address. */
59-
const char *symbolName;
60-
61-
/** The address of the closest symbol to the current address. */
62-
uintptr_t symbolAddress;
6349
} SentryCrashStackEntry;
6450

6551
typedef struct SentryCrashStackCursor {
@@ -79,10 +65,6 @@ typedef struct SentryCrashStackCursor {
7965
/** Advance the cursor to the next stack entry. */
8066
bool (*advanceCursor)(struct SentryCrashStackCursor *);
8167

82-
/** Attempt to symbolicate the current address, filling in the fields in
83-
* stackEntry. */
84-
bool (*symbolicate)(struct SentryCrashStackCursor *);
85-
8668
/** Internal context-specific information. */
8769
void *context[SentryCrashSC_CONTEXT_SIZE];
8870
} SentryCrashStackCursor;

Sources/SentryCrash/Recording/Tools/SentryCrashSymbolicator.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ static bool
5454
symbolicate_internal(SentryCrashStackCursor *cursor, bool useDlAddr)
5555
{
5656
if (cursor->stackEntry.address == SentryCrashSC_ASYNC_MARKER) {
57-
cursor->stackEntry.imageAddress = 0;
58-
cursor->stackEntry.imageName = 0;
59-
cursor->stackEntry.symbolAddress = 0;
60-
cursor->stackEntry.symbolName = "__sentrycrash__async_marker__";
57+
6158
return true;
6259
}
6360

@@ -75,18 +72,7 @@ symbolicate_internal(SentryCrashStackCursor *cursor, bool useDlAddr)
7572
CALL_INSTRUCTION_FROM_RETURN_ADDRESS(cursor->stackEntry.address), &symbolsBuffer);
7673
}
7774

78-
if (symbols_succeed) {
79-
cursor->stackEntry.imageAddress = (uintptr_t)symbolsBuffer.dli_fbase;
80-
cursor->stackEntry.imageName = symbolsBuffer.dli_fname;
81-
cursor->stackEntry.symbolAddress = (uintptr_t)symbolsBuffer.dli_saddr;
82-
cursor->stackEntry.symbolName = symbolsBuffer.dli_sname;
83-
return true;
84-
}
8575

86-
cursor->stackEntry.imageAddress = 0;
87-
cursor->stackEntry.imageName = 0;
88-
cursor->stackEntry.symbolAddress = 0;
89-
cursor->stackEntry.symbolName = 0;
9076
return false;
9177
}
9278

0 commit comments

Comments
 (0)