Skip to content
Merged
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
26 changes: 18 additions & 8 deletions platform/swift/source/reports/DiagnosticEventReporter.m
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,8 @@ static id object_for_key(NSDictionary *dict, NSString *key, Class klass) {
return [str cStringUsingEncoding:NSUTF8StringEncoding];
}

static uint32_t crashed_thread_index(NSArray *stacks) {
for (uint32_t index = 0; index < stacks.count; index++) {
if ([number_for_key(stacks[index], @"threadAttributed") boolValue]) {
return index;
}
}
return 0; // first thread is crashed thread if none attributed
static NSDictionary *thread_root_frame(NSDictionary *thread) {
return [array_for_key(thread, @"callStackRootFrames") firstObject];
}

static uint64_t count_frames(NSDictionary *rootFrame) {
Expand All @@ -130,14 +125,29 @@ static uint64_t count_frames(NSDictionary *rootFrame) {
return count;
}

static uint32_t crashed_thread_index(NSArray *stacks) {
for (uint32_t index = 0; index < stacks.count; index++) {
if ([number_for_key(stacks[index], @"threadAttributed") boolValue]) {
return index;
}
}
for (uint32_t index = 0; index < stacks.count; index++) {
if (count_frames(thread_root_frame(stacks[index])) > 0) {
return index; // grab first thread with frames if none attributed
}
}

return 0; // first thread is crashed thread if none contain frames
}

static void serialize_error_threads(BDProcessorHandle handle, NSDictionary *crash, NSString *name, NSString *reason) {
NSMutableSet <NSString *>* images = [NSMutableSet new];
NSArray *call_stacks = dict_for_key(crash, @"callStackTree")[@"callStacks"];
uint32_t crashed_index = crashed_thread_index(call_stacks);

for (uint32_t thread_index = 0; thread_index < call_stacks.count; thread_index++) {
NSDictionary *thread = call_stacks[thread_index];
NSDictionary *frame = [array_for_key(thread, @"callStackRootFrames") firstObject];
NSDictionary *frame = thread_root_frame(thread);
uint64_t frame_count = count_frames(frame);
BDStackFrame *stack = frame_count
? (BDStackFrame *)calloc(frame_count, sizeof(BDStackFrame))
Expand Down
Loading