Update crash_report tool and internal classes to reflect change to ProcessState (Issue #116)

git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@110 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
waylonis 2007-01-24 00:28:24 +00:00
parent d31c8b0292
commit 4b987df62b
4 changed files with 37 additions and 56 deletions

View file

@ -47,6 +47,7 @@
#include "google_airbag/processor/minidump_processor.h" #include "google_airbag/processor/minidump_processor.h"
#include "google_airbag/processor/process_state.h" #include "google_airbag/processor/process_state.h"
#include "google_airbag/processor/stack_frame_cpu.h" #include "google_airbag/processor/stack_frame_cpu.h"
#include "google_airbag/processor/system_info.h"
#include "processor/pathname_stripper.h" #include "processor/pathname_stripper.h"
#include "processor/scoped_ptr.h" #include "processor/scoped_ptr.h"
#include "processor/simple_symbol_supplier.h" #include "processor/simple_symbol_supplier.h"
@ -67,6 +68,7 @@ using google_airbag::scoped_ptr;
using google_airbag::StackFrame; using google_airbag::StackFrame;
using google_airbag::StackFramePPC; using google_airbag::StackFramePPC;
using google_airbag::StackFrameX86; using google_airbag::StackFrameX86;
using google_airbag::SystemInfo;
typedef struct { typedef struct {
NSString *minidumpPath; NSString *minidumpPath;
@ -99,7 +101,7 @@ static void PrintStack(const CallStack *stack, const string &cpu) {
printf("%-*s", maxStr, buffer); printf("%-*s", maxStr, buffer);
u_int64_t instruction = frame->instruction; u_int64_t instruction = frame->instruction;
// PPC only: Adjust the instruction to match that of Crash reporter. The // PPC only: Adjust the instruction to match that of Crash reporter. The
// instruction listed is actually the return address. See the detailed // instruction listed is actually the return address. See the detailed
// comments in stackwalker_ppc.cc for more information. // comments in stackwalker_ppc.cc for more information.
if (cpu == "ppc" && frame_index) if (cpu == "ppc" && frame_index)
@ -186,25 +188,12 @@ static void PrintRegisters(const CallStack *stack, const string &cpu) {
static void Start(Options *options) { static void Start(Options *options) {
string minidump_file([options->minidumpPath fileSystemRepresentation]); string minidump_file([options->minidumpPath fileSystemRepresentation]);
// Guess that the symbols are for our default architecture
const NXArchInfo *localArchInfo = NXGetLocalArchInfo();
string arch = "ppc";
if (!localArchInfo)
return;
if (localArchInfo->cputype & CPU_ARCH_ABI64)
arch = ((localArchInfo->cputype & ~CPU_ARCH_ABI64) == CPU_TYPE_X86) ?
"x86_64" : "ppc64";
else
arch = (localArchInfo->cputype == CPU_TYPE_X86) ? "x86" : "ppc";
BasicSourceLineResolver resolver; BasicSourceLineResolver resolver;
string search_dir = options->searchDir ? string search_dir = options->searchDir ?
[options->searchDir fileSystemRepresentation] : ""; [options->searchDir fileSystemRepresentation] : "";
scoped_ptr<OnDemandSymbolSupplier> symbol_supplier( scoped_ptr<OnDemandSymbolSupplier> symbol_supplier(
new OnDemandSymbolSupplier(arch, search_dir)); new OnDemandSymbolSupplier(search_dir));
scoped_ptr<MinidumpProcessor> scoped_ptr<MinidumpProcessor>
minidump_processor(new MinidumpProcessor(symbol_supplier.get(), &resolver)); minidump_processor(new MinidumpProcessor(symbol_supplier.get(), &resolver));
ProcessState process_state; ProcessState process_state;
if (minidump_processor->Process(minidump_file, &process_state) != if (minidump_processor->Process(minidump_file, &process_state) !=
@ -213,19 +202,8 @@ static void Start(Options *options) {
return; return;
} }
string cpu = process_state.cpu(); const SystemInfo *system_info = process_state.system_info();
// If the minidump is different than the default architecture string cpu = system_info->cpu;
if (cpu != arch) {
symbol_supplier.reset(new OnDemandSymbolSupplier(cpu, search_dir));
minidump_processor.reset(new MinidumpProcessor(symbol_supplier.get(),
&resolver));
if (minidump_processor->Process(minidump_file, &process_state) !=
MinidumpProcessor::PROCESS_OK) {
fprintf(stderr, "MinidumpProcessor::Process failed\n");
return;
}
}
// Convert the time to a string // Convert the time to a string
u_int32_t time_date_stamp = process_state.time_date_stamp(); u_int32_t time_date_stamp = process_state.time_date_stamp();
@ -235,9 +213,8 @@ static void Start(Options *options) {
strftime(timestr, 20, "%Y-%m-%d %H:%M:%S", &timestruct); strftime(timestr, 20, "%Y-%m-%d %H:%M:%S", &timestruct);
printf("Date: %s GMT\n", timestr); printf("Date: %s GMT\n", timestr);
string cpu_info = process_state.cpu_info(); printf("Operating system: %s (%s)\n", system_info->os.c_str(),
printf("Operating system: %s (%s)\n", process_state.os().c_str(), system_info->os_version.c_str());
process_state.os_version().c_str());
printf("Architecture: %s\n", cpu.c_str()); printf("Architecture: %s\n", cpu.c_str());
if (process_state.crashed()) { if (process_state.crashed()) {

View file

@ -17,6 +17,7 @@
9B3904960B2E52D90059FABE /* basic_source_line_resolver.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 9B3904940B2E52D90059FABE /* basic_source_line_resolver.h */; }; 9B3904960B2E52D90059FABE /* basic_source_line_resolver.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 9B3904940B2E52D90059FABE /* basic_source_line_resolver.h */; };
9B3904970B2E52D90059FABE /* source_line_resolver_interface.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 9B3904950B2E52D90059FABE /* source_line_resolver_interface.h */; }; 9B3904970B2E52D90059FABE /* source_line_resolver_interface.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 9B3904950B2E52D90059FABE /* source_line_resolver_interface.h */; };
9B3904990B2E52FD0059FABE /* basic_source_line_resolver.cc in Sources */ = {isa = PBXBuildFile; fileRef = 9B3904980B2E52FD0059FABE /* basic_source_line_resolver.cc */; }; 9B3904990B2E52FD0059FABE /* basic_source_line_resolver.cc in Sources */ = {isa = PBXBuildFile; fileRef = 9B3904980B2E52FD0059FABE /* basic_source_line_resolver.cc */; };
9B44619E0B66C66B00BBB817 /* system_info.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 9B44619D0B66C66B00BBB817 /* system_info.h */; };
9BDF172C0B1B8B2400F8391B /* call_stack.cc in Sources */ = {isa = PBXBuildFile; fileRef = 9BDF172A0B1B8B2400F8391B /* call_stack.cc */; }; 9BDF172C0B1B8B2400F8391B /* call_stack.cc in Sources */ = {isa = PBXBuildFile; fileRef = 9BDF172A0B1B8B2400F8391B /* call_stack.cc */; };
9BDF172D0B1B8B2400F8391B /* minidump_processor.cc in Sources */ = {isa = PBXBuildFile; fileRef = 9BDF172B0B1B8B2400F8391B /* minidump_processor.cc */; }; 9BDF172D0B1B8B2400F8391B /* minidump_processor.cc in Sources */ = {isa = PBXBuildFile; fileRef = 9BDF172B0B1B8B2400F8391B /* minidump_processor.cc */; };
9BDF17410B1B8B9A00F8391B /* minidump.cc in Sources */ = {isa = PBXBuildFile; fileRef = 9BDF173F0B1B8B9A00F8391B /* minidump.cc */; }; 9BDF17410B1B8B9A00F8391B /* minidump.cc in Sources */ = {isa = PBXBuildFile; fileRef = 9BDF173F0B1B8B9A00F8391B /* minidump.cc */; };
@ -63,6 +64,7 @@
9BE650B30B52FE3000611104 /* file_id.h in CopyFiles */, 9BE650B30B52FE3000611104 /* file_id.h in CopyFiles */,
9BE650B50B52FE3000611104 /* macho_id.h in CopyFiles */, 9BE650B50B52FE3000611104 /* macho_id.h in CopyFiles */,
9BE650B70B52FE3000611104 /* macho_walker.h in CopyFiles */, 9BE650B70B52FE3000611104 /* macho_walker.h in CopyFiles */,
9B44619E0B66C66B00BBB817 /* system_info.h in CopyFiles */,
); );
runOnlyForDeploymentPostprocessing = 1; runOnlyForDeploymentPostprocessing = 1;
}; };
@ -80,6 +82,7 @@
9B3904940B2E52D90059FABE /* basic_source_line_resolver.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = basic_source_line_resolver.h; sourceTree = "<group>"; }; 9B3904940B2E52D90059FABE /* basic_source_line_resolver.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = basic_source_line_resolver.h; sourceTree = "<group>"; };
9B3904950B2E52D90059FABE /* source_line_resolver_interface.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = source_line_resolver_interface.h; sourceTree = "<group>"; }; 9B3904950B2E52D90059FABE /* source_line_resolver_interface.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = source_line_resolver_interface.h; sourceTree = "<group>"; };
9B3904980B2E52FD0059FABE /* basic_source_line_resolver.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = basic_source_line_resolver.cc; path = ../../../processor/basic_source_line_resolver.cc; sourceTree = SOURCE_ROOT; }; 9B3904980B2E52FD0059FABE /* basic_source_line_resolver.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = basic_source_line_resolver.cc; path = ../../../processor/basic_source_line_resolver.cc; sourceTree = SOURCE_ROOT; };
9B44619D0B66C66B00BBB817 /* system_info.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = system_info.h; sourceTree = "<group>"; };
9BDF16F90B1B8ACD00F8391B /* airbag_types.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = airbag_types.h; sourceTree = "<group>"; }; 9BDF16F90B1B8ACD00F8391B /* airbag_types.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = airbag_types.h; sourceTree = "<group>"; };
9BDF16FA0B1B8ACD00F8391B /* minidump_format.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = minidump_format.h; sourceTree = "<group>"; }; 9BDF16FA0B1B8ACD00F8391B /* minidump_format.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = minidump_format.h; sourceTree = "<group>"; };
9BDF16FC0B1B8ACD00F8391B /* call_stack.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = call_stack.h; sourceTree = "<group>"; }; 9BDF16FC0B1B8ACD00F8391B /* call_stack.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = call_stack.h; sourceTree = "<group>"; };
@ -191,7 +194,6 @@
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
9B3904940B2E52D90059FABE /* basic_source_line_resolver.h */, 9B3904940B2E52D90059FABE /* basic_source_line_resolver.h */,
9B3904950B2E52D90059FABE /* source_line_resolver_interface.h */,
9BDF16FC0B1B8ACD00F8391B /* call_stack.h */, 9BDF16FC0B1B8ACD00F8391B /* call_stack.h */,
9B35FEE20B2675F9008DE8C7 /* code_module.h */, 9B35FEE20B2675F9008DE8C7 /* code_module.h */,
9B35FEE30B2675F9008DE8C7 /* code_modules.h */, 9B35FEE30B2675F9008DE8C7 /* code_modules.h */,
@ -199,10 +201,12 @@
9BDF16FE0B1B8ACD00F8391B /* minidump.h */, 9BDF16FE0B1B8ACD00F8391B /* minidump.h */,
9BDF16FF0B1B8ACD00F8391B /* minidump_processor.h */, 9BDF16FF0B1B8ACD00F8391B /* minidump_processor.h */,
9BDF17000B1B8ACD00F8391B /* process_state.h */, 9BDF17000B1B8ACD00F8391B /* process_state.h */,
9B3904950B2E52D90059FABE /* source_line_resolver_interface.h */,
9BDF17010B1B8ACD00F8391B /* stack_frame.h */, 9BDF17010B1B8ACD00F8391B /* stack_frame.h */,
9BDF17020B1B8ACD00F8391B /* stack_frame_cpu.h */, 9BDF17020B1B8ACD00F8391B /* stack_frame_cpu.h */,
9BDF17030B1B8ACD00F8391B /* stackwalker.h */, 9BDF17030B1B8ACD00F8391B /* stackwalker.h */,
9BDF17040B1B8ACD00F8391B /* symbol_supplier.h */, 9BDF17040B1B8ACD00F8391B /* symbol_supplier.h */,
9B44619D0B66C66B00BBB817 /* system_info.h */,
); );
path = processor; path = processor;
sourceTree = "<group>"; sourceTree = "<group>";

View file

@ -45,20 +45,17 @@ class MinidumpModule;
class OnDemandSymbolSupplier : public SymbolSupplier { class OnDemandSymbolSupplier : public SymbolSupplier {
public: public:
// |architecture| should be one of ppc, i386, x86, ppc64, x86_64
// |search_dir| is the directory to search for alternative symbols with // |search_dir| is the directory to search for alternative symbols with
// the same name as the module in the minidump // the same name as the module in the minidump
OnDemandSymbolSupplier(const string &architecture, const string &search_dir); OnDemandSymbolSupplier(const string &search_dir);
virtual ~OnDemandSymbolSupplier() {} virtual ~OnDemandSymbolSupplier() {}
// Returns the path to the symbol file for the given module. // Returns the path to the symbol file for the given module.
virtual SymbolResult GetSymbolFile(const CodeModule *module, virtual SymbolResult GetSymbolFile(const CodeModule *module,
const SystemInfo *system_info,
string *symbol_file); string *symbol_file);
protected: protected:
// Return symbols for this architecture
string architecture_;
// Search directory // Search directory
string search_dir_; string search_dir_;
@ -84,7 +81,8 @@ class OnDemandSymbolSupplier : public SymbolSupplier {
// Generate the airbag symbol file for |module|. Return true if successful. // Generate the airbag symbol file for |module|. Return true if successful.
// File is generated in /tmp. // File is generated in /tmp.
bool GenerateSymbolFile(const CodeModule *module); bool GenerateSymbolFile(const CodeModule *module,
const SystemInfo *system_info);
}; };
} // namespace google_airbag } // namespace google_airbag

View file

@ -33,6 +33,7 @@
#include "google_airbag/processor/basic_source_line_resolver.h" #include "google_airbag/processor/basic_source_line_resolver.h"
#include "google_airbag/processor/minidump.h" #include "google_airbag/processor/minidump.h"
#include "google_airbag/processor/system_info.h"
#include "processor/pathname_stripper.h" #include "processor/pathname_stripper.h"
#include "on_demand_symbol_supplier.h" #include "on_demand_symbol_supplier.h"
@ -44,28 +45,28 @@ using std::string;
using google_airbag::OnDemandSymbolSupplier; using google_airbag::OnDemandSymbolSupplier;
using google_airbag::PathnameStripper; using google_airbag::PathnameStripper;
using google_airbag::SymbolSupplier; using google_airbag::SymbolSupplier;
using google_airbag::SystemInfo;
OnDemandSymbolSupplier::OnDemandSymbolSupplier(const string &architecture, OnDemandSymbolSupplier::OnDemandSymbolSupplier(const string &search_dir)
const string &search_dir) : search_dir_(search_dir) {
: architecture_(architecture),
search_dir_(search_dir) {
} }
SymbolSupplier::SymbolResult SymbolSupplier::SymbolResult
OnDemandSymbolSupplier::GetSymbolFile(const CodeModule *module, OnDemandSymbolSupplier::GetSymbolFile(const CodeModule *module,
const SystemInfo *system_info,
string *symbol_file) { string *symbol_file) {
string path(GetModuleSymbolFile(module)); string path(GetModuleSymbolFile(module));
if (path.empty()) { if (path.empty()) {
if (!GenerateSymbolFile(module)) if (!GenerateSymbolFile(module, system_info))
return NOT_FOUND; return NOT_FOUND;
path = GetModuleSymbolFile(module); path = GetModuleSymbolFile(module);
} }
if (path.empty()) if (path.empty())
return NOT_FOUND; return NOT_FOUND;
*symbol_file = path; *symbol_file = path;
return FOUND; return FOUND;
} }
@ -127,16 +128,17 @@ static float GetFileModificationTime(const char *path) {
if (stat(path, &file_stat) == 0) if (stat(path, &file_stat) == 0)
result = (float)file_stat.st_mtimespec.tv_sec + result = (float)file_stat.st_mtimespec.tv_sec +
(float)file_stat.st_mtimespec.tv_nsec / 1.0e9; (float)file_stat.st_mtimespec.tv_nsec / 1.0e9;
return result; return result;
} }
bool OnDemandSymbolSupplier::GenerateSymbolFile(const CodeModule *module) { bool OnDemandSymbolSupplier::GenerateSymbolFile(const CodeModule *module,
const SystemInfo *system_info) {
bool result = true; bool result = true;
string name = GetNameForModule(module); string name = GetNameForModule(module);
string module_path = GetLocalModulePath(module); string module_path = GetLocalModulePath(module);
NSString *symbol_path = [NSString stringWithFormat:@"/tmp/%s.%s.sym", NSString *symbol_path = [NSString stringWithFormat:@"/tmp/%s.%s.sym",
name.c_str(), architecture_.c_str()]; name.c_str(), system_info->cpu.c_str()];
if (module_path.empty()) if (module_path.empty())
return false; return false;
@ -146,11 +148,11 @@ bool OnDemandSymbolSupplier::GenerateSymbolFile(const CodeModule *module) {
BOOL generate_file = YES; BOOL generate_file = YES;
if ([[NSFileManager defaultManager] fileExistsAtPath:symbol_path]) { if ([[NSFileManager defaultManager] fileExistsAtPath:symbol_path]) {
// Check if the module file is newer than the saved symbols // Check if the module file is newer than the saved symbols
float cache_time = float cache_time =
GetFileModificationTime([symbol_path fileSystemRepresentation]); GetFileModificationTime([symbol_path fileSystemRepresentation]);
float module_time = float module_time =
GetFileModificationTime(module_path.c_str()); GetFileModificationTime(module_path.c_str());
if (cache_time > module_time) if (cache_time > module_time)
generate_file = NO; generate_file = NO;
} }
@ -160,7 +162,7 @@ bool OnDemandSymbolSupplier::GenerateSymbolFile(const CodeModule *module) {
stringWithFileSystemRepresentation:module_path.c_str() stringWithFileSystemRepresentation:module_path.c_str()
length:module_path.length()]; length:module_path.length()];
DumpSymbols *dump = [[DumpSymbols alloc] initWithContentsOfFile:module_str]; DumpSymbols *dump = [[DumpSymbols alloc] initWithContentsOfFile:module_str];
const char *archStr = architecture_.c_str(); const char *archStr = system_info->cpu.c_str();
if ([dump setArchitecture:[NSString stringWithUTF8String:archStr]]) { if ([dump setArchitecture:[NSString stringWithUTF8String:archStr]]) {
[dump writeSymbolFile:symbol_path]; [dump writeSymbolFile:symbol_path];
} else { } else {