Add logging to minidump processor (#82). First part: logging infrastructure

and messages for minidump.cc and minidump_processor.cc.  r=bryner.

http://groups.google.com/group/google-breakpad-dev/browse_thread/thread/b056994d675f623c


git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@169 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
mmentovai 2007-05-17 18:34:37 +00:00
parent 95be2b659e
commit af3c43f00e
15 changed files with 2049 additions and 1437 deletions

104
src/processor/logging.cc Normal file
View file

@ -0,0 +1,104 @@
// Copyright (c) 2007, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// logging.cc: Breakpad logging
//
// See logging.h for documentation.
//
// Author: Mark Mentovai
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "processor/logging.h"
#include "processor/pathname_stripper.h"
namespace google_breakpad {
LogStream::LogStream(std::ostream &stream, Severity severity,
const char *file, int line)
: stream_(stream) {
time_t clock;
time(&clock);
struct tm tm_struct;
localtime_r(&clock, &tm_struct);
char time_string[20];
strftime(time_string, sizeof(time_string), "%Y-%m-%d %H:%M:%S", &tm_struct);
const char *severity_string = "UNKNOWN_SEVERITY";
switch (severity) {
case SEVERITY_INFO:
severity_string = "INFO";
break;
case SEVERITY_ERROR:
severity_string = "ERROR";
break;
}
stream_ << time_string << ": " << PathnameStripper::File(file) << ":" <<
line << ": " << severity_string << ": ";
}
LogStream::~LogStream() {
stream_ << std::endl;
}
std::string HexString(u_int32_t number) {
char buffer[11];
snprintf(buffer, sizeof(buffer), "0x%x", number);
return std::string(buffer);
}
std::string HexString(u_int64_t number) {
char buffer[19];
snprintf(buffer, sizeof(buffer), "0x%llx", number);
return std::string(buffer);
}
std::string HexString(int number) {
char buffer[19];
snprintf(buffer, sizeof(buffer), "0x%x", number);
return std::string(buffer);
}
int ErrnoString(std::string *error_string) {
assert(error_string);
// strerror isn't necessarily thread-safe. strerror_r would be preferrable,
// but GNU libc uses a nonstandard strerror_r by default, which returns a
// char* (rather than an int success indicator) and doesn't necessarily
// use the supplied buffer.
error_string->assign(strerror(errno));
return errno;
}
} // namespace google_breakpad

140
src/processor/logging.h Normal file
View file

@ -0,0 +1,140 @@
// Copyright (c) 2007, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// logging.h: Breakpad logging
//
// Breakpad itself uses Breakpad logging with statements of the form:
// BPLOG(severity) << "message";
// severity may be INFO, ERROR, or other values defined in this file.
//
// BPLOG is an overridable macro so that users can customize Breakpad's
// logging. Left at the default, logging messages are sent to stderr along
// with a timestamp and the source code location that produced a message.
// The streams may be changed by redefining BPLOG_*_STREAM, the logging
// behavior may be changed by redefining BPLOG_*, and the entire logging
// system may be overridden by redefining BPLOG(severity). These
// redefinitions may be passed to the preprocessor as a command-line flag
// (-D).
//
// If an additional header is required to override Breakpad logging, it can
// be specified by the BP_LOGGING_INCLUDE macro. If defined, this header
// will #include the header specified by that macro.
//
// Author: Mark Mentovai
#ifndef PROCESSOR_LOGGING_H__
#define PROCESSOR_LOGGING_H__
#include <iostream>
#include <string>
#include "google_breakpad/common/breakpad_types.h"
#ifdef BP_LOGGING_INCLUDE
#include BP_LOGGING_INCLUDE
#endif // BP_LOGGING_INCLUDE
namespace google_breakpad {
class LogStream {
public:
enum Severity {
SEVERITY_INFO,
SEVERITY_ERROR,
};
// Begin logging a message to the stream identified by |stream|, at the
// indicated severity. The file and line parameters should be set so as to
// identify the line of source code that is producing a message.
LogStream(std::ostream &stream, Severity severity,
const char *file, int line);
// Finish logging by printing a newline and flushing the output stream.
~LogStream();
template<typename T> std::ostream& operator<<(const T &t) {
return stream_ << t;
}
private:
std::ostream &stream_;
// Disallow copy constructor and assignment operator
explicit LogStream(const LogStream &that);
void operator=(const LogStream &that);
};
// This class is used to explicitly ignore values in the conditional logging
// macros. This avoids compiler warnings like "value computed is not used"
// and "statement has no effect".
class LogMessageVoidify {
public:
LogMessageVoidify() {}
// This has to be an operator with a precedence lower than << but higher
// than ?:
void operator&(std::ostream &) {}
};
// Returns number formatted as a hexadecimal string, such as "0x7b".
std::string HexString(u_int32_t number);
std::string HexString(u_int64_t number);
std::string HexString(int number);
// Returns the error code as set in the global errno variable, and sets
// error_string, a required argument, to a string describing that error
// code.
int ErrnoString(std::string *error_string);
} // namespace google_breakpad
#ifndef BPLOG
#define BPLOG(severity) BPLOG_ ## severity
#endif // BPLOG
#ifndef BPLOG_INFO
#ifndef BPLOG_INFO_STREAM
#define BPLOG_INFO_STREAM std::clog
#endif // BPLOG_INFO_STREAM
#define BPLOG_INFO LogStream(BPLOG_INFO_STREAM, LogStream::SEVERITY_INFO, \
__FILE__, __LINE__)
#endif // BPLOG_INFO
#ifndef BPLOG_ERROR
#ifndef BPLOG_ERROR_STREAM
#define BPLOG_ERROR_STREAM std::cerr
#endif // BPLOG_ERROR_STREAM
#define BPLOG_ERROR LogStream(BPLOG_ERROR_STREAM, LogStream::SEVERITY_ERROR, \
__FILE__, __LINE__)
#endif // BPLOG_ERROR
#define BPLOG_IF(severity, condition) \
!(condition) ? (void) 0 : LogMessageVoidify() & BPLOG(severity)
#endif // PROCESSOR_LOGGING_H__

File diff suppressed because it is too large Load diff

View file

@ -33,6 +33,7 @@
#include "google_breakpad/processor/call_stack.h"
#include "google_breakpad/processor/minidump.h"
#include "google_breakpad/processor/process_state.h"
#include "processor/logging.h"
#include "processor/scoped_ptr.h"
#include "processor/stackwalker_x86.h"
@ -48,19 +49,23 @@ MinidumpProcessor::~MinidumpProcessor() {
MinidumpProcessor::ProcessResult MinidumpProcessor::Process(
const string &minidump_file, ProcessState *process_state) {
BPLOG(INFO) << "Processing minidump in file " << minidump_file;
Minidump dump(minidump_file);
if (!dump.Read()) {
BPLOG(ERROR) << "Minidump " << minidump_file << " could not be read";
return PROCESS_ERROR;
}
process_state->Clear();
const MDRawHeader *header = dump.header();
BPLOG_IF(ERROR, !header) << "Minidump " << minidump_file << " has no header";
assert(header);
process_state->time_date_stamp_ = header->time_date_stamp;
GetCPUInfo(&dump, &process_state->system_info_);
GetOSInfo(&dump, &process_state->system_info_);
bool has_cpu_info = GetCPUInfo(&dump, &process_state->system_info_);
bool has_os_info = GetOSInfo(&dump, &process_state->system_info_);
u_int32_t dump_thread_id = 0;
bool has_dump_thread = false;
@ -93,24 +98,45 @@ MinidumpProcessor::ProcessResult MinidumpProcessor::Process(
MinidumpThreadList *threads = dump.GetThreadList();
if (!threads) {
BPLOG(ERROR) << "Minidump " << minidump_file << " has no thread list";
return PROCESS_ERROR;
}
BPLOG(INFO) << "Minidump " << minidump_file << " has " <<
(has_cpu_info ? "" : "no ") << "CPU info, " <<
(has_os_info ? "" : "no ") << "OS info, " <<
(breakpad_info != NULL ? "" : "no ") << "Breakpad info, " <<
(exception != NULL ? "" : "no ") << "exception, " <<
(module_list != NULL ? "" : "no ") << "module list, " <<
(threads != NULL ? "" : "no ") << "thread list, " <<
(has_dump_thread ? "" : "no ") << "dump thread, and " <<
(has_requesting_thread ? "" : "no ") << "requesting thread";
bool found_requesting_thread = false;
unsigned int thread_count = threads->thread_count();
for (unsigned int thread_index = 0;
thread_index < thread_count;
++thread_index) {
char thread_string_buffer[64];
snprintf(thread_string_buffer, sizeof(thread_string_buffer), "%d/%d",
thread_index, thread_count);
string thread_string = minidump_file + ":" + thread_string_buffer;
MinidumpThread *thread = threads->GetThreadAtIndex(thread_index);
if (!thread) {
BPLOG(ERROR) << "Could not get thread for " << thread_string;
return PROCESS_ERROR;
}
u_int32_t thread_id;
if (!thread->GetThreadID(&thread_id)) {
BPLOG(ERROR) << "Could not get thread ID for " << thread_string;
return PROCESS_ERROR;
}
thread_string += " id " + HexString(thread_id);
BPLOG(INFO) << "Looking at thread " << thread_string;
// If this thread is the thread that produced the minidump, don't process
// it. Because of the problems associated with a thread producing a
// dump of itself (when both its context and its stack are in flux),
@ -124,6 +150,7 @@ MinidumpProcessor::ProcessResult MinidumpProcessor::Process(
if (has_requesting_thread && thread_id == requesting_thread_id) {
if (found_requesting_thread) {
// There can't be more than one requesting thread.
BPLOG(ERROR) << "Duplicate requesting thread: " << thread_string;
return PROCESS_ERROR;
}
@ -150,6 +177,7 @@ MinidumpProcessor::ProcessResult MinidumpProcessor::Process(
MinidumpMemoryRegion *thread_memory = thread->GetMemory();
if (!thread_memory) {
BPLOG(ERROR) << "No memory region for " << thread_string;
return PROCESS_ERROR;
}
@ -169,11 +197,14 @@ MinidumpProcessor::ProcessResult MinidumpProcessor::Process(
supplier_,
resolver_));
if (!stackwalker.get()) {
BPLOG(ERROR) << "No stackwalker for " << thread_string;
return PROCESS_ERROR;
}
scoped_ptr<CallStack> stack(new CallStack());
if (!stackwalker->Walk(stack.get())) {
BPLOG(INFO) << "Processing interrupted by stackwalker (missing " <<
"symbols?) at " << thread_string;
return PROCESS_INTERRUPTED;
}
process_state->threads_.push_back(stack.release());
@ -182,9 +213,13 @@ MinidumpProcessor::ProcessResult MinidumpProcessor::Process(
// If a requesting thread was indicated, it must be present.
if (has_requesting_thread && !found_requesting_thread) {
// Don't mark as an error, but invalidate the requesting thread
BPLOG(ERROR) << "Minidump indicated requesting thread " <<
HexString(requesting_thread_id) << ", not found in " <<
minidump_file;
process_state->requesting_thread_ = -1;
}
BPLOG(INFO) << "Processed " << minidump_file;
return PROCESS_OK;
}
@ -204,7 +239,7 @@ static const MDRawSystemInfo* GetSystemInfo(Minidump *dump,
}
// static
void MinidumpProcessor::GetCPUInfo(Minidump *dump, SystemInfo *info) {
bool MinidumpProcessor::GetCPUInfo(Minidump *dump, SystemInfo *info) {
assert(dump);
assert(info);
@ -214,7 +249,7 @@ void MinidumpProcessor::GetCPUInfo(Minidump *dump, SystemInfo *info) {
MinidumpSystemInfo *system_info;
const MDRawSystemInfo *raw_system_info = GetSystemInfo(dump, &system_info);
if (!raw_system_info)
return;
return false;
switch (raw_system_info->processor_architecture) {
case MD_CPU_ARCHITECTURE_X86: {
@ -248,10 +283,12 @@ void MinidumpProcessor::GetCPUInfo(Minidump *dump, SystemInfo *info) {
break;
}
}
return true;
}
// static
void MinidumpProcessor::GetOSInfo(Minidump *dump, SystemInfo *info) {
bool MinidumpProcessor::GetOSInfo(Minidump *dump, SystemInfo *info) {
assert(dump);
assert(info);
@ -262,7 +299,7 @@ void MinidumpProcessor::GetOSInfo(Minidump *dump, SystemInfo *info) {
MinidumpSystemInfo *system_info;
const MDRawSystemInfo *raw_system_info = GetSystemInfo(dump, &system_info);
if (!raw_system_info)
return;
return false;
info->os_short = system_info->GetOS();
@ -309,6 +346,8 @@ void MinidumpProcessor::GetOSInfo(Minidump *dump, SystemInfo *info) {
info->os_version.append(" ");
info->os_version.append(*csd_version);
}
return true;
}
// static
@ -375,6 +414,7 @@ string MinidumpProcessor::GetCrashReason(Minidump *dump, u_int64_t *address) {
break;
default:
reason.append(flags_string);
BPLOG(INFO) << "Unknown exception reason " << reason;
break;
}
break;
@ -403,6 +443,7 @@ string MinidumpProcessor::GetCrashReason(Minidump *dump, u_int64_t *address) {
break;
default:
reason.append(flags_string);
BPLOG(INFO) << "Unknown exception reason " << reason;
break;
}
break;
@ -429,12 +470,14 @@ string MinidumpProcessor::GetCrashReason(Minidump *dump, u_int64_t *address) {
break;
default:
reason.append(flags_string);
BPLOG(INFO) << "Unknown exception reason " << reason;
break;
}
break;
}
default:
reason.append(flags_string);
BPLOG(INFO) << "Unknown exception reason " << reason;
break;
}
break;
@ -471,6 +514,7 @@ string MinidumpProcessor::GetCrashReason(Minidump *dump, u_int64_t *address) {
reason.append("EXC_PPC_ALTIVECASSIST");
default:
reason.append(flags_string);
BPLOG(INFO) << "Unknown exception reason " << reason;
break;
}
break;
@ -503,12 +547,14 @@ string MinidumpProcessor::GetCrashReason(Minidump *dump, u_int64_t *address) {
break;
default:
reason.append(flags_string);
BPLOG(INFO) << "Unknown exception reason " << reason;
break;
}
break;
}
default:
reason.append(flags_string);
BPLOG(INFO) << "Unknown exception reason " << reason;
break;
}
break;
@ -529,6 +575,7 @@ string MinidumpProcessor::GetCrashReason(Minidump *dump, u_int64_t *address) {
break;
default:
reason.append(flags_string);
BPLOG(INFO) << "Unknown exception reason " << reason;
break;
}
break;
@ -542,6 +589,7 @@ string MinidumpProcessor::GetCrashReason(Minidump *dump, u_int64_t *address) {
break;
default:
reason.append(flags_string);
BPLOG(INFO) << "Unknown exception reason " << reason;
break;
}
break;
@ -556,12 +604,14 @@ string MinidumpProcessor::GetCrashReason(Minidump *dump, u_int64_t *address) {
break;
default:
reason.append(flags_string);
BPLOG(INFO) << "Unknown exception reason " << reason;
break;
}
break;
}
default:
reason.append(flags_string);
BPLOG(INFO) << "Unknown exception reason " << reason;
break;
}
break;
@ -668,7 +718,16 @@ string MinidumpProcessor::GetCrashReason(Minidump *dump, u_int64_t *address) {
case MD_EXCEPTION_CODE_WIN_POSSIBLE_DEADLOCK:
reason = "EXCEPTION_POSSIBLE_DEADLOCK";
break;
default:
BPLOG(INFO) << "Unknown exception reason " << reason;
break;
}
break;
}
default: {
BPLOG(INFO) << "Unknown exception reason " << reason;
break;
}
}