Skip to content

Commit

Permalink
Use Function Starts data for symbolication
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdowell committed Oct 20, 2021
1 parent ab997b6 commit 7ad6212
Show file tree
Hide file tree
Showing 14 changed files with 255 additions and 277 deletions.
42 changes: 20 additions & 22 deletions Bugsnag.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

48 changes: 25 additions & 23 deletions Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSCrashReport.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "BSG_KSBacktrace_Private.h"
#include "BSG_KSCrashReportFields.h"
#include "BSG_KSCrashReportVersion.h"
#include "BSG_KSDynamicLinker.h"
#include "BSG_KSFileUtils.h"
#include "BSG_KSJSONCodec.h"
#include "BSG_KSMach.h"
Expand All @@ -43,7 +42,9 @@
#include "BSG_KSLogger.h"
#include "BSG_KSCrashContext.h"
#include "BSG_KSCrashSentry.h"
#include "BSG_Symbolicate.h"

#include <mach-o/loader.h>
#include <sys/time.h>

#ifdef __arm64__
Expand Down Expand Up @@ -530,22 +531,22 @@ void bsg_kscrw_i_logCrashType(
* @param dlInfo Information about the nearest symbols to the address.
*/
void bsg_kscrw_i_logBacktraceEntry(const int entryNum, const uintptr_t address,
const Dl_info *const dlInfo) {
struct bsg_symbolicate_result *dlInfo) {
char faddrBuff[20];
char saddrBuff[20];

const char *fname = bsg_ksfulastPathEntry(dlInfo->dli_fname);
const char *fname = bsg_ksfulastPathEntry(dlInfo->image->name);
if (fname == NULL) {
sprintf(faddrBuff, BSG_POINTER_FMT, (uintptr_t)dlInfo->dli_fbase);
sprintf(faddrBuff, BSG_POINTER_FMT, (uintptr_t)dlInfo->image->header);
fname = faddrBuff;
}

uintptr_t offset = address - (uintptr_t)dlInfo->dli_saddr;
const char *sname = dlInfo->dli_sname;
uintptr_t offset = address - (uintptr_t)dlInfo->function_address;
const char *sname = dlInfo->function_name;
if (sname == NULL) {
sprintf(saddrBuff, BSG_POINTER_SHORT_FMT, (uintptr_t)dlInfo->dli_fbase);
sprintf(saddrBuff, BSG_POINTER_SHORT_FMT, (uintptr_t)dlInfo->image->header);
sname = saddrBuff;
offset = address - (uintptr_t)dlInfo->dli_fbase;
offset = address - (uintptr_t)dlInfo->image->header;
}

BSG_KSLOGBASIC_ALWAYS(BSG_TRACE_FMT, entryNum, fname, address, sname,
Expand All @@ -562,7 +563,7 @@ void bsg_kscrw_i_logBacktrace(const uintptr_t *const backtrace,
const int backtraceLength,
const int skippedEntries) {
if (backtraceLength > 0) {
Dl_info symbolicated[backtraceLength];
struct bsg_symbolicate_result symbolicated[backtraceLength];
bsg_ksbt_symbolicate(backtrace, symbolicated, backtraceLength,
skippedEntries);

Expand Down Expand Up @@ -726,23 +727,24 @@ void bsg_kscrw_i_writeAddressReferencedByString(
*/
void bsg_kscrw_i_writeBacktraceEntry(
const BSG_KSCrashReportWriter *const writer, const char *const key,
const uintptr_t address, const Dl_info *const info) {
const uintptr_t address, struct bsg_symbolicate_result *info) {
writer->beginObject(writer, key);
{
if (info->dli_saddr != NULL) {
if (info->dli_fname != NULL) {
writer->addStringElement(writer, BSG_KSCrashField_ObjectName,
bsg_ksfulastPathEntry(info->dli_fname));
}
if (info->image && info->image->header) {
writer->addUIntegerElement(writer, BSG_KSCrashField_ObjectAddr,
(uintptr_t)info->dli_fbase);
if (info->dli_sname != NULL) {
const char *sname = info->dli_sname;
writer->addStringElement(writer, BSG_KSCrashField_SymbolName,
sname);
}
(uintptr_t)info->image->header);
}
if (info->image && info->image->name) {
writer->addStringElement(writer, BSG_KSCrashField_ObjectName,
bsg_ksfulastPathEntry(info->image->name));
}
if (info->function_address) {
writer->addUIntegerElement(writer, BSG_KSCrashField_SymbolAddr,
(uintptr_t)info->dli_saddr);
info->function_address);
}
if (info->function_name) {
writer->addStringElement(writer, BSG_KSCrashField_SymbolName,
info->function_name);
}
writer->addUIntegerElement(writer, BSG_KSCrashField_InstructionAddr,
address);
Expand Down Expand Up @@ -773,7 +775,7 @@ void bsg_kscrw_i_writeBacktrace(const BSG_KSCrashReportWriter *const writer,
writer->beginArray(writer, BSG_KSCrashField_Contents);
{
if (backtraceLength > 0) {
Dl_info symbolicated[backtraceLength];
struct bsg_symbolicate_result symbolicated[backtraceLength];
bsg_ksbt_symbolicate(backtrace, symbolicated, backtraceLength,
skippedEntries);

Expand Down
3 changes: 2 additions & 1 deletion Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSSystemInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

#import "BSG_KSSystemInfo.h"
#import "BSG_KSSystemInfoC.h"
#import "BSG_KSDynamicLinker.h"
#import "BSG_KSMachHeaders.h"
#import "BSG_KSJSONCodecObjC.h"
#import "BSG_KSMach.h"
Expand All @@ -41,6 +40,8 @@
#import "BSG_KSCrash.h"

#import <CommonCrypto/CommonDigest.h>
#import <mach-o/dyld.h>

#if BSG_PLATFORM_IOS || BSG_PLATFORM_TVOS
#import "BSGUIKit.h"
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ extern "C" {

#include <sys/_structs.h>

#ifdef __LP64__
#define BSG_STRUCT_NLIST struct nlist_64
#else
#define BSG_STRUCT_NLIST struct nlist
#endif

#ifdef __arm64__
#define BSG_STRUCT_MCONTEXT_L _STRUCT_MCONTEXT64
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

#include "BSG_KSBacktrace_Private.h"

#include "BSG_KSDynamicLinker.h"
#include "BSG_KSMach.h"

/**
Expand Down Expand Up @@ -225,17 +224,17 @@ int bsg_ksbt_backtraceSelf(uintptr_t *const backtraceBuffer,
}

void bsg_ksbt_symbolicate(const uintptr_t *const backtraceBuffer,
Dl_info *const symbolsBuffer, const int numEntries,
struct bsg_symbolicate_result *symbolsBuffer, const int numEntries,
const int skippedEntries) {
int i = 0;

if (!skippedEntries && i < numEntries) {
bsg_ksdldladdr(backtraceBuffer[i], &symbolsBuffer[i]);
bsg_symbolicate(backtraceBuffer[i], &symbolsBuffer[i]);
i++;
}

for (; i < numEntries; i++) {
bsg_ksdldladdr(CALL_INSTRUCTION_FROM_RETURN_ADDRESS(backtraceBuffer[i]),
bsg_symbolicate(CALL_INSTRUCTION_FROM_RETURN_ADDRESS(backtraceBuffer[i]),
&symbolsBuffer[i]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
extern "C" {
#endif

#include <dlfcn.h>
#include "BSG_Symbolicate.h"

#include <mach/mach.h>
#include <pthread.h>

Expand Down Expand Up @@ -98,7 +99,7 @@ int bsg_ksbt_backtraceSelf(uintptr_t *backtraceBuffer, int maxEntries);
* backtrace.
*/
void bsg_ksbt_symbolicate(const uintptr_t *backtraceBuffer,
Dl_info *symbolsBuffer, int numEntries,
struct bsg_symbolicate_result *symbolsBuffer, int numEntries,
int skippedEntries);

#ifdef __cplusplus
Expand Down
109 changes: 0 additions & 109 deletions Bugsnag/KSCrash/Source/KSCrash/Recording/Tools/BSG_KSDynamicLinker.c

This file was deleted.

This file was deleted.

27 changes: 0 additions & 27 deletions Bugsnag/KSCrash/Source/KSCrash/Recording/Tools/BSG_KSMachHeaders.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "BSG_KSMachHeaders.h"

#include "BSG_KSDynamicLinker.h"
#include "BSG_KSLogger.h"
#include "BSG_KSMach.h"

Expand Down Expand Up @@ -252,32 +251,6 @@ uintptr_t bsg_mach_headers_first_cmd_after_header(const struct mach_header *cons
}
}

uintptr_t bsg_mach_headers_image_at_base_of_image_index(const struct mach_header *const header) {
// Look for a segment command and return the file image address.
uintptr_t cmdPtr = bsg_mach_headers_first_cmd_after_header(header);
if (cmdPtr == 0) {
return 0;
}
for (uint32_t i = 0; i < header->ncmds; i++) {
const struct load_command *loadCmd = (struct load_command *)cmdPtr;
if (loadCmd->cmd == LC_SEGMENT) {
const struct segment_command *segmentCmd =
(struct segment_command *)cmdPtr;
if (strcmp(segmentCmd->segname, SEG_LINKEDIT) == 0) {
return segmentCmd->vmaddr - segmentCmd->fileoff;
}
} else if (loadCmd->cmd == LC_SEGMENT_64) {
const struct segment_command_64 *segmentCmd =
(struct segment_command_64 *)cmdPtr;
if (strcmp(segmentCmd->segname, SEG_LINKEDIT) == 0) {
return (uintptr_t)(segmentCmd->vmaddr - segmentCmd->fileoff);
}
}
cmdPtr += loadCmd->cmdsize;
}

return 0;
}
static uintptr_t bsg_mach_header_info_get_section_addr_named(const BSG_Mach_Header_Info *header, const char *name) {
uintptr_t cmdPtr = bsg_mach_headers_first_cmd_after_header(header->header);
if (!cmdPtr) {
Expand Down
Loading

0 comments on commit 7ad6212

Please sign in to comment.