- Hide private symbols (we'll link the private implementations into the unit tests directly, for lack of a better option).

- Implement basic crash log parsing.


git-svn-id: https://plcrashreporter.googlecode.com/svn/trunk@80 25172300-ee46-11dd-abe2-393a09110dd0
This commit is contained in:
landonf@OFFICE.PLAUSIBLELABS.COM 2008-12-11 03:22:07 +00:00
Родитель 5accc242cf
Коммит 294d67e361
5 изменённых файлов: 124 добавлений и 60 удалений

Просмотреть файл

@ -63,6 +63,21 @@
059672510EF074EF008A0601 /* libprotobuf-c-MacOSX.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 059671E90EF04706008A0601 /* libprotobuf-c-MacOSX.a */; };
059672520EF074F6008A0601 /* libprotobuf-c-iPhoneOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 059671E70EF04706008A0601 /* libprotobuf-c-iPhoneOS.a */; };
059672530EF07519008A0601 /* libprotobuf-c-iPhoneSimulator.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 059671E80EF04706008A0601 /* libprotobuf-c-iPhoneSimulator.a */; };
059674780EF0BA03008A0601 /* crash_report.proto in Sources */ = {isa = PBXBuildFile; fileRef = 059670C70EEFAC3A008A0601 /* crash_report.proto */; };
059674790EF0BA07008A0601 /* crash_report.proto in Sources */ = {isa = PBXBuildFile; fileRef = 059670C70EEFAC3A008A0601 /* crash_report.proto */; };
059674880EF0BB4A008A0601 /* PLCrashLogWriter.c in Sources */ = {isa = PBXBuildFile; fileRef = 059670260EEF6B1A008A0601 /* PLCrashLogWriter.c */; };
059674890EF0BB4D008A0601 /* PLCrashLogWriter.c in Sources */ = {isa = PBXBuildFile; fileRef = 059670260EEF6B1A008A0601 /* PLCrashLogWriter.c */; };
0596748B0EF0BB5C008A0601 /* PLCrashFrameWalker.c in Sources */ = {isa = PBXBuildFile; fileRef = 059666DB0EEDDFB8008A0601 /* PLCrashFrameWalker.c */; };
0596748C0EF0BB5C008A0601 /* PLCrashFrameWalker_i386.c in Sources */ = {isa = PBXBuildFile; fileRef = 059667590EEDECA7008A0601 /* PLCrashFrameWalker_i386.c */; };
0596748D0EF0BB5C008A0601 /* PLCrashFrameWalker_arm.c in Sources */ = {isa = PBXBuildFile; fileRef = 05966A1B0EEE5280008A0601 /* PLCrashFrameWalker_arm.c */; };
0596748E0EF0BB63008A0601 /* PLCrashFrameWalker.c in Sources */ = {isa = PBXBuildFile; fileRef = 059666DB0EEDDFB8008A0601 /* PLCrashFrameWalker.c */; };
0596748F0EF0BB63008A0601 /* PLCrashFrameWalker_i386.c in Sources */ = {isa = PBXBuildFile; fileRef = 059667590EEDECA7008A0601 /* PLCrashFrameWalker_i386.c */; };
059674900EF0BB63008A0601 /* PLCrashFrameWalker_arm.c in Sources */ = {isa = PBXBuildFile; fileRef = 05966A1B0EEE5280008A0601 /* PLCrashFrameWalker_arm.c */; };
059674970EF0BBB4008A0601 /* PLCrashLogWriter.c in Sources */ = {isa = PBXBuildFile; fileRef = 059670260EEF6B1A008A0601 /* PLCrashLogWriter.c */; };
059674980EF0BBB4008A0601 /* PLCrashFrameWalker.c in Sources */ = {isa = PBXBuildFile; fileRef = 059666DB0EEDDFB8008A0601 /* PLCrashFrameWalker.c */; };
059674990EF0BBB4008A0601 /* PLCrashFrameWalker_i386.c in Sources */ = {isa = PBXBuildFile; fileRef = 059667590EEDECA7008A0601 /* PLCrashFrameWalker_i386.c */; };
0596749A0EF0BBB4008A0601 /* PLCrashFrameWalker_arm.c in Sources */ = {isa = PBXBuildFile; fileRef = 05966A1B0EEE5280008A0601 /* PLCrashFrameWalker_arm.c */; };
0596749B0EF0BBB4008A0601 /* crash_report.proto in Sources */ = {isa = PBXBuildFile; fileRef = 059670C70EEFAC3A008A0601 /* crash_report.proto */; };
05CD314D0EE9364B000FDE88 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 05CD314C0EE9364B000FDE88 /* InfoPlist.strings */; };
05CD318B0EE93A90000FDE88 /* CrashReporter.h in Headers */ = {isa = PBXBuildFile; fileRef = 05CD31890EE93A90000FDE88 /* CrashReporter.h */; };
05CD318C0EE93A90000FDE88 /* CrashReporter.m in Sources */ = {isa = PBXBuildFile; fileRef = 05CD318A0EE93A90000FDE88 /* CrashReporter.m */; };
@ -140,6 +155,30 @@
);
script = "cd \"${INPUT_FILE_DIR}\" && \"${SRCROOT}/Dependencies/protobuf-2.0.3/bin/protoc-c\" --c_out=\"${DERIVED_FILES_DIR}\" \"${INPUT_FILE_NAME}\"";
};
0596747A0EF0BA2F008A0601 /* PBXBuildRule */ = {
isa = PBXBuildRule;
compilerSpec = com.apple.compilers.proxy.script;
filePatterns = "*.proto";
fileType = pattern.proxy;
isEditable = 1;
outputFiles = (
"$(INPUT_FILE_BASE).pb-c.c",
"$(INPUT_FILE_BASE).pb-c.h",
);
script = "cd \"${INPUT_FILE_DIR}\" && \"${SRCROOT}/Dependencies/protobuf-2.0.3/bin/protoc-c\" --c_out=\"${DERIVED_FILES_DIR}\" \"${INPUT_FILE_NAME}\"";
};
0596747B0EF0BA2F008A0601 /* PBXBuildRule */ = {
isa = PBXBuildRule;
compilerSpec = com.apple.compilers.proxy.script;
filePatterns = "*.proto";
fileType = pattern.proxy;
isEditable = 1;
outputFiles = (
"$(INPUT_FILE_BASE).pb-c.c",
"$(INPUT_FILE_BASE).pb-c.h",
);
script = "cd \"${INPUT_FILE_DIR}\" && \"${SRCROOT}/Dependencies/protobuf-2.0.3/bin/protoc-c\" --c_out=\"${DERIVED_FILES_DIR}\" \"${INPUT_FILE_NAME}\"";
};
/* End PBXBuildRule section */
/* Begin PBXContainerItemProxy section */
@ -248,7 +287,6 @@
059670250EEF6B1A008A0601 /* PLCrashLogWriter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PLCrashLogWriter.h; sourceTree = "<group>"; };
059670260EEF6B1A008A0601 /* PLCrashLogWriter.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = PLCrashLogWriter.c; sourceTree = "<group>"; };
0596702D0EEF6B51008A0601 /* PLCrashLogWriterTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PLCrashLogWriterTests.m; sourceTree = "<group>"; };
059670310EEF6B9A008A0601 /* PLCrashLog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PLCrashLog.h; sourceTree = "<group>"; };
059670C70EEFAC3A008A0601 /* crash_report.proto */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = crash_report.proto; path = Resources/crash_report.proto; sourceTree = "<group>"; };
059670E60EEFADA6008A0601 /* protoc */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; path = protoc; sourceTree = "<group>"; };
059670EB0EEFADA6008A0601 /* code_generator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = code_generator.h; sourceTree = "<group>"; };
@ -401,7 +439,6 @@
059670210EEF5459008A0601 /* Log */ = {
isa = PBXGroup;
children = (
059670310EEF6B9A008A0601 /* PLCrashLog.h */,
059670250EEF6B1A008A0601 /* PLCrashLogWriter.h */,
059670260EEF6B1A008A0601 /* PLCrashLogWriter.c */,
0596702D0EEF6B51008A0601 /* PLCrashLogWriterTests.m */,
@ -778,6 +815,7 @@
05CD32B50EE940C8000FDE88 /* Simulator Run Tests */,
);
buildRules = (
0596747A0EF0BA2F008A0601 /* PBXBuildRule */,
);
dependencies = (
05CD32F30EE94153000FDE88 /* PBXTargetDependency */,
@ -796,6 +834,7 @@
05CD33220EE94439000FDE88 /* Frameworks */,
);
buildRules = (
0596747B0EF0BA2F008A0601 /* PBXBuildRule */,
);
dependencies = (
054F50E90EEC50B30034B184 /* PBXTargetDependency */,
@ -984,6 +1023,11 @@
05CD33A30EE94931000FDE88 /* PLCrashSignalHandlerTests.m in Sources */,
059666E30EEDDFCC008A0601 /* PLCrashFrameWalkerTests.m in Sources */,
0596702E0EEF6B51008A0601 /* PLCrashLogWriterTests.m in Sources */,
059674880EF0BB4A008A0601 /* PLCrashLogWriter.c in Sources */,
0596748E0EF0BB63008A0601 /* PLCrashFrameWalker.c in Sources */,
0596748F0EF0BB63008A0601 /* PLCrashFrameWalker_i386.c in Sources */,
059674900EF0BB63008A0601 /* PLCrashFrameWalker_arm.c in Sources */,
059674790EF0BA07008A0601 /* crash_report.proto in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -997,6 +1041,11 @@
05CD33A40EE94931000FDE88 /* PLCrashSignalHandlerTests.m in Sources */,
059666E50EEDDFCC008A0601 /* PLCrashFrameWalkerTests.m in Sources */,
0596702F0EEF6B51008A0601 /* PLCrashLogWriterTests.m in Sources */,
059674890EF0BB4D008A0601 /* PLCrashLogWriter.c in Sources */,
0596748B0EF0BB5C008A0601 /* PLCrashFrameWalker.c in Sources */,
0596748C0EF0BB5C008A0601 /* PLCrashFrameWalker_i386.c in Sources */,
0596748D0EF0BB5C008A0601 /* PLCrashFrameWalker_arm.c in Sources */,
059674780EF0BA03008A0601 /* crash_report.proto in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -1010,6 +1059,11 @@
05CD33A50EE94931000FDE88 /* PLCrashSignalHandlerTests.m in Sources */,
059666E40EEDDFCC008A0601 /* PLCrashFrameWalkerTests.m in Sources */,
059670300EEF6B51008A0601 /* PLCrashLogWriterTests.m in Sources */,
059674970EF0BBB4008A0601 /* PLCrashLogWriter.c in Sources */,
059674980EF0BBB4008A0601 /* PLCrashFrameWalker.c in Sources */,
059674990EF0BBB4008A0601 /* PLCrashFrameWalker_i386.c in Sources */,
0596749A0EF0BBB4008A0601 /* PLCrashFrameWalker_arm.c in Sources */,
0596749B0EF0BBB4008A0601 /* crash_report.proto in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

Просмотреть файл

@ -10,9 +10,3 @@ _PLCrashReporterErrorDomain
# PLCrashSignalHandler
*_PLCrashSignalHandler
# PLCrashFrame (Private API, Unit Tested)
_plframe_*
# PLCrashWriter (Private API, Unit Tested)
_plcrash_writer_*

Просмотреть файл

@ -1,23 +0,0 @@
/*
* PLCrashLog.h
* CrashReporter
*
* Created by Landon Fuller on 12/9/08.
* Copyright 2008 Plausible Labs Cooperative, Inc.. All rights reserved.
*
*/
/**
* @internal
* @defgroup plcrash_log Crash Log Format
* @ingroup plcrash_internal
*
* Implements Crash Log encoding and decoding
*
* @{
*/
/**
* @} plcrash_log
*/

Просмотреть файл

@ -11,7 +11,6 @@
#import <string.h>
#import <stdbool.h>
#import "PLCrashLog.h"
#import "PLCrashLogWriter.h"
#import "PLCrashAsync.h"
@ -24,7 +23,6 @@
*
* @{
*/
#if 0
static ssize_t writen (int fd, const uint8_t *buf, size_t len) {
const uint8_t *p;
size_t left;
@ -42,15 +40,14 @@ static ssize_t writen (int fd, const uint8_t *buf, size_t len) {
PLCF_DEBUG("Error occured writing to crash log: %s", strerror(errno));
return -1;
}
left -= written;
p += written;
}
left -= written;
p += written;
}
return written;
}
#endif
/**
* Initialize a new crash log writer instance. This fetches all necessary environment
@ -89,9 +86,11 @@ plcrash_error_t plcrash_writer_init (plcrash_writer_t *writer, const char *path)
* and thread dump.
*/
plcrash_error_t plcrash_writer_report (plcrash_writer_t *writer, siginfo_t *siginfo, ucontext_t *crashctx) {
uint8_t buffer[] = { 0, 1 };
writen(writer->fd, buffer, sizeof(buffer));
return PLCRASH_ENOTSUP;
return PLCRASH_ESUCCESS;
}
/**

Просмотреть файл

@ -10,14 +10,17 @@
#import "PLCrashLogWriter.h"
#import "PLCrashFrameWalker.h"
#import <sys/stat.h>
#import <sys/mman.h>
#include <fcntl.h>
#import "crash_report.pb-c.h"
@interface PLCrashLogWriterTests : SenTestCase {
@private
/* Path to crash log */
NSString *_logPath;
/* Writer instance */
plcrash_writer_t _writer;
/* Test thread */
plframe_test_thead_t _thr_args;
}
@ -28,9 +31,8 @@
@implementation PLCrashLogWriterTests
- (void) setUp {
/* Init the writer */
/* Create a temporary log path */
_logPath = [NSTemporaryDirectory() stringByAppendingString: [[NSProcessInfo processInfo] globallyUniqueString]];
STAssertEquals(PLCRASH_ESUCCESS, plcrash_writer_init(&_writer, [_logPath UTF8String]), @"Initialization failed");
/* Create the test thread */
plframe_test_thread_spawn(&_thr_args);
@ -39,35 +41,73 @@
- (void) tearDown {
NSError *error;
/* Close the writer and delete the file */
STAssertEquals(PLCRASH_ESUCCESS, plcrash_writer_close(&_writer), @"Close failed");
/* Delete the file */
STAssertTrue([[NSFileManager defaultManager] removeItemAtPath: _logPath error: &error], @"Could not remove log file");
/* Stop the test thread */
plframe_test_thread_stop(&_thr_args);
}
- (void) testInit {
STAssertGreaterThanOrEqual(_writer.fd, 0, @"File descriptor was not opened");
// check a crash report's system info
- (void) checkSystemInfo: (Plausible__Crashreport__CrashReport__SystemInfo *) systemInfo {
STAssertNotNULL(systemInfo, @"No system info available");
}
- (void) testWriteReport {
siginfo_t info;
plframe_cursor_t cursor;
/* Initialze a faux-siginfo instance */
info.si_addr = 0x0;
info.si_errno = 0;
info.si_pid = getpid();
info.si_uid = getuid();
info.si_code = SEGV_MAPERR;
info.si_signo = SIGSEGV;
info.si_status = 0;
/* Steal the test thread's stack for iteration */
plframe_cursor_thread_init(&cursor, pthread_mach_thread_np(_thr_args.thread));
plcrash_writer_t writer;
plcrash_writer_report(&_writer, &info, cursor.uap);
/* Initialze faux crash data */
{
info.si_addr = 0x0;
info.si_errno = 0;
info.si_pid = getpid();
info.si_uid = getuid();
info.si_code = SEGV_MAPERR;
info.si_signo = SIGSEGV;
info.si_status = 0;
/* Steal the test thread's stack for iteration */
plframe_cursor_thread_init(&cursor, pthread_mach_thread_np(_thr_args.thread));
}
/* Initialize a writer */
STAssertEquals(PLCRASH_ESUCCESS, plcrash_writer_init(&writer, [_logPath UTF8String]), @"Initialization failed");
/* Write the crash report */
STAssertEquals(PLCRASH_ESUCCESS, plcrash_writer_report(&writer, &info, cursor.uap), @"Crash log failed");
/* Close it */
plcrash_writer_close(&writer);
/* Try reading it back in */
int infd;
void *buf;
struct stat statbuf;
{
STAssertEquals(0, stat([_logPath UTF8String], &statbuf), @"fstat failed");
infd = open([_logPath UTF8String], O_RDONLY);
STAssertGreaterThan(infd, 0, @"Could not open log file");
buf = mmap(NULL, statbuf.st_size, PROT_READ, MAP_PRIVATE, infd, 0);
STAssertNotNULL(buf, @"Could not map pages");
}
/* Try to read the crash report */
Plausible__Crashreport__CrashReport *crashReport;
crashReport = plausible__crashreport__crash_report__unpack(&protobuf_c_system_allocator, statbuf.st_size, buf);
STAssertNotNULL(crashReport, @"Could not decode crash report");
/* Test the report */
[self checkSystemInfo: crashReport->system_info];
if (crashReport != NULL)
protobuf_c_message_free_unpacked((ProtobufCMessage *) crashReport, &protobuf_c_system_allocator);
close(infd);
STAssertEquals(0, munmap(buf, statbuf.st_size), @"Could not unmap pages: %s", strerror(errno));
}
@end