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

Move strings into a table so this doesn't cause issues for our scripts. #8

Open
wants to merge 1 commit into
base: backtrace
Choose a base branch
from
Open
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
125 changes: 75 additions & 50 deletions Source/PLCrashReport.m
Original file line number Diff line number Diff line change
Expand Up @@ -264,29 +264,33 @@ - (Plcrash__CrashReport *) decodeCrashData: (NSData *) data error: (NSError **)

/* Verify that the crash log is sufficently large */
if (sizeof(struct PLCrashReportFileHeader) >= [data length]) {
populate_nserror(outError, PLCrashReporterErrorCrashReportInvalid, NSLocalizedString(@"Could not decode truncated crash log",
@"Crash log decoding error message"));
populate_nserror(outError, PLCrashReporterErrorCrashReportInvalid, NSLocalizedStringFromTable(@"Could not decode truncated crash log",
@"PLCrashReporter",
@"Crash log decoding error message"));
return NULL;
}

/* Check the file magic */
if (memcmp(header->magic, PLCRASH_REPORT_FILE_MAGIC, strlen(PLCRASH_REPORT_FILE_MAGIC)) != 0) {
populate_nserror(outError, PLCrashReporterErrorCrashReportInvalid,NSLocalizedString(@"Could not decode invalid crash log header",
@"Crash log decoding error message"));
populate_nserror(outError, PLCrashReporterErrorCrashReportInvalid,NSLocalizedStringFromTable(@"Could not decode invalid crash log header",
@"PLCrashReporter",
@"Crash log decoding error message"));
return NULL;
}

/* Check the version */
if(header->version != PLCRASH_REPORT_FILE_VERSION) {
populate_nserror(outError, PLCrashReporterErrorCrashReportInvalid, [NSString stringWithFormat: NSLocalizedString(@"Could not decode unsupported crash report version: %d",
@"Crash log decoding message"), header->version]);
populate_nserror(outError, PLCrashReporterErrorCrashReportInvalid, [NSString stringWithFormat: NSLocalizedStringFromTable(@"Could not decode unsupported crash report version: %d",
@"PLCrashReporter",
@"Crash log decoding message"), header->version]);
return NULL;
}

Plcrash__CrashReport *crashReport = plcrash__crash_report__unpack(NULL, [data length] - sizeof(struct PLCrashReportFileHeader), header->data);
if (crashReport == NULL) {
populate_nserror(outError, PLCrashReporterErrorCrashReportInvalid, NSLocalizedString(@"An unknown error occured decoding the crash report",
@"Crash log decoding error message"));
populate_nserror(outError, PLCrashReporterErrorCrashReportInvalid, NSLocalizedStringFromTable(@"An unknown error occured decoding the crash report",
@"PLCrashReporter",
@"Crash log decoding error message"));
return NULL;
}

Expand Down Expand Up @@ -316,15 +320,17 @@ - (PLCrashReportSystemInfo *) extractSystemInfo: (Plcrash__CrashReport__SystemIn
/* Validate */
if (systemInfo == NULL) {
populate_nserror(outError, PLCrashReporterErrorCrashReportInvalid,
NSLocalizedString(@"Crash report is missing System Information section",
@"Missing sysinfo in crash report"));
NSLocalizedStringFromTable(@"Crash report is missing System Information section",
@"PLCrashReporter",
@"Missing sysinfo in crash report"));
return nil;
}

if (systemInfo->os_version == NULL) {
populate_nserror(outError, PLCrashReporterErrorCrashReportInvalid,
NSLocalizedString(@"Crash report is missing System Information OS version field",
@"Missing sysinfo operating system in crash report"));
NSLocalizedStringFromTable(@"Crash report is missing System Information OS version field",
@"PLCrashReporter",
@"Missing sysinfo operating system in crash report"));
return nil;
}

Expand Down Expand Up @@ -362,8 +368,9 @@ - (PLCrashReportProcessorInfo *) extractProcessorInfo: (Plcrash__CrashReport__Pr
/* Validate */
if (processorInfo == NULL) {
populate_nserror(outError, PLCrashReporterErrorCrashReportInvalid,
NSLocalizedString(@"Crash report is missing processor info section",
@"Missing processor info in crash report"));
NSLocalizedStringFromTable(@"Crash report is missing processor info section",
@"PLCrashReporter",
@"Missing processor info in crash report"));
return nil;
}

Expand Down Expand Up @@ -411,8 +418,9 @@ - (PLCrashReportProcessorInfo *) synthesizeProcessorInfoFromArchitecture: (Plcra

default:
populate_nserror(outError, PLCrashReporterErrorCrashReportInvalid,
NSLocalizedString(@"Crash report has an unknown architecture",
@"Unknown architecture in crash report"));
NSLocalizedStringFromTable(@"Crash report has an unknown architecture",
@"PLCrashReporter",
@"Unknown architecture in crash report"));
return nil;
}

Expand All @@ -431,8 +439,9 @@ - (PLCrashReportMachineInfo *) extractMachineInfo: (Plcrash__CrashReport__Machin
/* Validate */
if (machineInfo == NULL) {
populate_nserror(outError, PLCrashReporterErrorCrashReportInvalid,
NSLocalizedString(@"Crash report is missing Machine Information section",
@"Missing machine_info in crash report"));
NSLocalizedStringFromTable(@"Crash report is missing Machine Information section",
@"PLCrashReporter",
@"Missing machine_info in crash report"));
return nil;
}

Expand Down Expand Up @@ -465,24 +474,27 @@ - (PLCrashReportApplicationInfo *) extractApplicationInfo: (Plcrash__CrashReport
/* Validate */
if (applicationInfo == NULL) {
populate_nserror(outError, PLCrashReporterErrorCrashReportInvalid,
NSLocalizedString(@"Crash report is missing Application Information section",
@"Missing app info in crash report"));
NSLocalizedStringFromTable(@"Crash report is missing Application Information section",
@"PLCrashReporter",
@"Missing app info in crash report"));
return nil;
}

/* Identifier available? */
if (applicationInfo->identifier == NULL) {
populate_nserror(outError, PLCrashReporterErrorCrashReportInvalid,
NSLocalizedString(@"Crash report is missing Application Information app identifier field",
@"Missing app identifier in crash report"));
NSLocalizedStringFromTable(@"Crash report is missing Application Information app identifier field",
@"PLCrashReporter",
@"Missing app identifier in crash report"));
return nil;
}

/* Version available? */
if (applicationInfo->version == NULL) {
populate_nserror(outError, PLCrashReporterErrorCrashReportInvalid,
NSLocalizedString(@"Crash report is missing Application Information app version field",
@"Missing app version in crash report"));
NSLocalizedStringFromTable(@"Crash report is missing Application Information app version field",
@"PLCrashReporter",
@"Missing app version in crash report"));
return nil;
}

Expand Down Expand Up @@ -510,8 +522,9 @@ - (PLCrashReportProcessInfo *) extractProcessInfo: (Plcrash__CrashReport__Proces
/* Validate */
if (processInfo == NULL) {
populate_nserror(outError, PLCrashReporterErrorCrashReportInvalid,
NSLocalizedString(@"Crash report is missing Process Information section",
@"Missing process info in crash report"));
NSLocalizedStringFromTable(@"Crash report is missing Process Information section",
@"PLCrashReporter",
@"Missing process info in crash report"));
return nil;
}

Expand Down Expand Up @@ -556,8 +569,9 @@ - (PLCrashReportProcessInfo *) extractProcessInfo: (Plcrash__CrashReport__Proces
- (PLCrashReportSymbolInfo *) extractSymbolInfo: (Plcrash__CrashReport__Symbol *) symbol error: (NSError **) outError {
if (symbol == NULL) {
populate_nserror(outError, PLCrashReporterErrorCrashReportInvalid,
NSLocalizedString(@"Crash report is missing symbol information",
@"Missing symbol info in crash report"));
NSLocalizedStringFromTable(@"Crash report is missing symbol information",
@"PLCrashReporter",
@"Missing symbol info in crash report"));
return nil;
}

Expand All @@ -575,8 +589,9 @@ - (PLCrashReportStackFrameInfo *) extractStackFrameInfo: (Plcrash__CrashReport__
/* There should be at least one thread */
if (stackFrame == NULL) {
populate_nserror(outError, PLCrashReporterErrorCrashReportInvalid,
NSLocalizedString(@"Crash report is missing stack frame information",
@"Missing stack frame info in crash report"));
NSLocalizedStringFromTable(@"Crash report is missing stack frame information",
@"PLCrashReporter",
@"Missing stack frame info in crash report"));
return nil;
}

Expand All @@ -598,8 +613,9 @@ - (NSArray *) extractThreadInfo: (Plcrash__CrashReport *) crashReport error: (NS
/* There should be at least one thread */
if (crashReport->n_threads == 0) {
populate_nserror(outError, PLCrashReporterErrorCrashReportInvalid,
NSLocalizedString(@"Crash report is missing thread state information",
@"Missing thread info in crash report"));
NSLocalizedStringFromTable(@"Crash report is missing thread state information",
@"PLCrashReporter",
@"Missing thread info in crash report"));
return nil;
}

Expand Down Expand Up @@ -655,8 +671,9 @@ - (NSArray *) extractImageInfo: (Plcrash__CrashReport *) crashReport error: (NSE
/* There should be at least one image */
if (crashReport->n_binary_images == 0) {
populate_nserror(outError, PLCrashReporterErrorCrashReportInvalid,
NSLocalizedString(@"Crash report is missing binary image information",
@"Missing image info in crash report"));
NSLocalizedStringFromTable(@"Crash report is missing binary image information",
@"PLCrashReporter",
@"Missing image info in crash report"));
return nil;
}

Expand Down Expand Up @@ -710,24 +727,27 @@ - (PLCrashReportExceptionInfo *) extractExceptionInfo: (Plcrash__CrashReport__Ex
/* Validate */
if (exceptionInfo == NULL) {
populate_nserror(outError, PLCrashReporterErrorCrashReportInvalid,
NSLocalizedString(@"Crash report is missing Exception Information section",
@"Missing appinfo in crash report"));
NSLocalizedStringFromTable(@"Crash report is missing Exception Information section",
@"PLCrashReporter",
@"Missing appinfo in crash report"));
return nil;
}

/* Name available? */
if (exceptionInfo->name == NULL) {
populate_nserror(outError, PLCrashReporterErrorCrashReportInvalid,
NSLocalizedString(@"Crash report is missing exception name field",
@"Missing appinfo operating system in crash report"));
NSLocalizedStringFromTable(@"Crash report is missing exception name field",
@"PLCrashReporter",
@"Missing appinfo operating system in crash report"));
return nil;
}

/* Reason available? */
if (exceptionInfo->reason == NULL) {
populate_nserror(outError, PLCrashReporterErrorCrashReportInvalid,
NSLocalizedString(@"Crash report is missing exception reason field",
@"Missing appinfo operating system in crash report"));
NSLocalizedStringFromTable(@"Crash report is missing exception reason field",
@"PLCrashReporter",
@"Missing appinfo operating system in crash report"));
return nil;
}

Expand Down Expand Up @@ -767,24 +787,27 @@ - (PLCrashReportSignalInfo *) extractSignalInfo: (Plcrash__CrashReport__Signal *
/* Validate */
if (signalInfo == NULL) {
populate_nserror(outError, PLCrashReporterErrorCrashReportInvalid,
NSLocalizedString(@"Crash report is missing Signal Information section",
@"Missing appinfo in crash report"));
NSLocalizedStringFromTable(@"Crash report is missing Signal Information section",
@"PLCrashReporter",
@"Missing appinfo in crash report"));
return nil;
}

/* Name available? */
if (signalInfo->name == NULL) {
populate_nserror(outError, PLCrashReporterErrorCrashReportInvalid,
NSLocalizedString(@"Crash report is missing signal name field",
@"Missing appinfo operating system in crash report"));
NSLocalizedStringFromTable(@"Crash report is missing signal name field",
@"PLCrashReporter",
@"Missing appinfo operating system in crash report"));
return nil;
}

/* Code available? */
if (signalInfo->code == NULL) {
populate_nserror(outError, PLCrashReporterErrorCrashReportInvalid,
NSLocalizedString(@"Crash report is missing signal code field",
@"Missing appinfo operating system in crash report"));
NSLocalizedStringFromTable(@"Crash report is missing signal code field",
@"PLCrashReporter",
@"Missing appinfo operating system in crash report"));
return nil;
}

Expand All @@ -804,16 +827,18 @@ - (PLCrashReportMachExceptionInfo *) extractMachExceptionInfo: (Plcrash__CrashRe
/* Validate */
if (machExceptionInfo == NULL) {
populate_nserror(outError, PLCrashReporterErrorCrashReportInvalid,
NSLocalizedString(@"Crash report is missing Mach Exception Information section",
@"Missing mach exception info in crash report"));
NSLocalizedStringFromTable(@"Crash report is missing Mach Exception Information section",
@"PLCrashReporter",
@"Missing mach exception info in crash report"));
return nil;
}

/* Sanity check; there should really only ever be 2 */
if (machExceptionInfo->n_codes > UINT8_MAX) {
populate_nserror(outError, PLCrashReporterErrorCrashReportInvalid,
NSLocalizedString(@"Crash report includes too many Mach Exception codes",
@"Invalid mach exception info in crash report"));
NSLocalizedStringFromTable(@"Crash report includes too many Mach Exception codes",
@"PLCrashReporter",
@"Invalid mach exception info in crash report"));
return nil;
}

Expand Down
4 changes: 2 additions & 2 deletions Source/PLCrashReporter.m
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ - (NSData *) generateLiveReportWithThread: (thread_t) thread exception: (NSExcep

int fd = mkstemp(path);
if (fd < 0) {
plcrash_populate_posix_error(outError, errno, NSLocalizedString(@"Failed to create temporary path", @"Error opening temporary output path"));
plcrash_populate_posix_error(outError, errno, NSLocalizedStringFromTable(@"Failed to create temporary path", @"PLCrashReporter", @"Error opening temporary output path"));
free(path);

return nil;
Expand Down Expand Up @@ -773,7 +773,7 @@ - (NSData *) generateLiveReportWithThread: (thread_t) thread exception: (NSExcep
data = [NSData dataWithContentsOfFile: [NSString stringWithUTF8String: path]];
if (data == nil) {
/* This should only happen if our data is deleted out from under us */
plcrash_populate_error(outError, PLCrashReporterErrorUnknown, NSLocalizedString(@"Unable to open live crash report for reading", nil), nil);
plcrash_populate_error(outError, PLCrashReporterErrorUnknown, NSLocalizedStringFromTable(@"Unable to open live crash report for reading", @"PLCrashReporter", nil), nil);
goto cleanup;
}

Expand Down