Provide for logging initialization routines (#179). r=bryner

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


git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@177 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
mmentovai 2007-05-25 18:04:17 +00:00
parent 1ef60aaa6c
commit 32b802dba3
11 changed files with 61 additions and 15 deletions

View File

@ -36,6 +36,7 @@
#include "processor/address_map-inl.h" #include "processor/address_map-inl.h"
#include "processor/linked_ptr.h" #include "processor/linked_ptr.h"
#include "processor/logging.h"
#define ASSERT_TRUE(condition) \ #define ASSERT_TRUE(condition) \
if (!(condition)) { \ if (!(condition)) { \
@ -189,5 +190,7 @@ static bool RunTests() {
} // namespace } // namespace
int main(int argc, char **argv) { int main(int argc, char **argv) {
BPLOG_INIT(&argc, &argv);
return RunTests() ? 0 : 1; return RunTests() ? 0 : 1;
} }

View File

@ -33,6 +33,7 @@
#include "google_breakpad/processor/code_module.h" #include "google_breakpad/processor/code_module.h"
#include "google_breakpad/processor/stack_frame.h" #include "google_breakpad/processor/stack_frame.h"
#include "processor/linked_ptr.h" #include "processor/linked_ptr.h"
#include "processor/logging.h"
#include "processor/scoped_ptr.h" #include "processor/scoped_ptr.h"
#include "processor/stack_frame_info.h" #include "processor/stack_frame_info.h"
@ -202,6 +203,8 @@ static bool RunTests() {
} // namespace } // namespace
int main(int argc, char **argv) { int main(int argc, char **argv) {
BPLOG_INIT(&argc, &argv);
if (!RunTests()) { if (!RunTests()) {
return 1; return 1;
} }

View File

@ -35,6 +35,8 @@
#include "processor/contained_range_map-inl.h" #include "processor/contained_range_map-inl.h"
#include "processor/logging.h"
#define ASSERT_TRUE(condition) \ #define ASSERT_TRUE(condition) \
if (!(condition)) { \ if (!(condition)) { \
@ -255,5 +257,7 @@ static bool RunTests() {
int main(int argc, char **argv) { int main(int argc, char **argv) {
BPLOG_INIT(&argc, &argv);
return RunTests() ? 0 : 1; return RunTests() ? 0 : 1;
} }

View File

@ -46,6 +46,12 @@
// be specified by the BP_LOGGING_INCLUDE macro. If defined, this header // be specified by the BP_LOGGING_INCLUDE macro. If defined, this header
// will #include the header specified by that macro. // will #include the header specified by that macro.
// //
// If any initialization is needed before logging, it can be performed by
// a function called through the BPLOG_INIT macro. Each main function of
// an executable program in the Breakpad processor library calls
// BPLOG_INIT(&argc, &argv); before any logging can be performed; define
// BPLOG_INIT appropriately if initialization is required.
//
// Author: Mark Mentovai // Author: Mark Mentovai
#ifndef PROCESSOR_LOGGING_H__ #ifndef PROCESSOR_LOGGING_H__
@ -114,6 +120,10 @@ int ErrnoString(std::string *error_string);
} // namespace google_breakpad } // namespace google_breakpad
#ifndef BPLOG_INIT
#define BPLOG_INIT(pargc, pargv)
#endif // BPLOG_INIT
#ifndef BPLOG #ifndef BPLOG
#define BPLOG(severity) BPLOG_ ## severity #define BPLOG(severity) BPLOG_ ## severity
#endif // BPLOG #endif // BPLOG
@ -122,19 +132,22 @@ int ErrnoString(std::string *error_string);
#ifndef BPLOG_INFO_STREAM #ifndef BPLOG_INFO_STREAM
#define BPLOG_INFO_STREAM std::clog #define BPLOG_INFO_STREAM std::clog
#endif // BPLOG_INFO_STREAM #endif // BPLOG_INFO_STREAM
#define BPLOG_INFO LogStream(BPLOG_INFO_STREAM, LogStream::SEVERITY_INFO, \ #define BPLOG_INFO google_breakpad::LogStream(BPLOG_INFO_STREAM, \
__FILE__, __LINE__) google_breakpad::LogStream::SEVERITY_INFO, \
__FILE__, __LINE__)
#endif // BPLOG_INFO #endif // BPLOG_INFO
#ifndef BPLOG_ERROR #ifndef BPLOG_ERROR
#ifndef BPLOG_ERROR_STREAM #ifndef BPLOG_ERROR_STREAM
#define BPLOG_ERROR_STREAM std::cerr #define BPLOG_ERROR_STREAM std::cerr
#endif // BPLOG_ERROR_STREAM #endif // BPLOG_ERROR_STREAM
#define BPLOG_ERROR LogStream(BPLOG_ERROR_STREAM, LogStream::SEVERITY_ERROR, \ #define BPLOG_ERROR google_breakpad::LogStream(BPLOG_ERROR_STREAM, \
__FILE__, __LINE__) google_breakpad::LogStream::SEVERITY_ERROR, \
__FILE__, __LINE__)
#endif // BPLOG_ERROR #endif // BPLOG_ERROR
#define BPLOG_IF(severity, condition) \ #define BPLOG_IF(severity, condition) \
!(condition) ? (void) 0 : LogMessageVoidify() & BPLOG(severity) !(condition) ? (void) 0 : \
google_breakpad::LogMessageVoidify() & BPLOG(severity)
#endif // PROCESSOR_LOGGING_H__ #endif // PROCESSOR_LOGGING_H__

View File

@ -35,6 +35,7 @@
#include <cstdio> #include <cstdio>
#include "google_breakpad/processor/minidump.h" #include "google_breakpad/processor/minidump.h"
#include "processor/logging.h"
namespace { namespace {
@ -50,7 +51,7 @@ using google_breakpad::MinidumpBreakpadInfo;
static bool PrintMinidumpDump(const char *minidump_file) { static bool PrintMinidumpDump(const char *minidump_file) {
Minidump minidump(minidump_file); Minidump minidump(minidump_file);
if (!minidump.Read()) { if (!minidump.Read()) {
fprintf(stderr, "minidump.Read() failed\n"); BPLOG(ERROR) << "minidump.Read() failed";
return false; return false;
} }
minidump.Print(); minidump.Print();
@ -60,7 +61,7 @@ static bool PrintMinidumpDump(const char *minidump_file) {
MinidumpThreadList *thread_list = minidump.GetThreadList(); MinidumpThreadList *thread_list = minidump.GetThreadList();
if (!thread_list) { if (!thread_list) {
++errors; ++errors;
printf("minidump.GetThreadList() failed\n"); BPLOG(ERROR) << "minidump.GetThreadList() failed";
} else { } else {
thread_list->Print(); thread_list->Print();
} }
@ -68,7 +69,7 @@ static bool PrintMinidumpDump(const char *minidump_file) {
MinidumpModuleList *module_list = minidump.GetModuleList(); MinidumpModuleList *module_list = minidump.GetModuleList();
if (!module_list) { if (!module_list) {
++errors; ++errors;
printf("minidump.GetModuleList() failed\n"); BPLOG(ERROR) << "minidump.GetModuleList() failed";
} else { } else {
module_list->Print(); module_list->Print();
} }
@ -76,15 +77,14 @@ static bool PrintMinidumpDump(const char *minidump_file) {
MinidumpMemoryList *memory_list = minidump.GetMemoryList(); MinidumpMemoryList *memory_list = minidump.GetMemoryList();
if (!memory_list) { if (!memory_list) {
++errors; ++errors;
printf("minidump.GetMemoryList() failed\n"); BPLOG(ERROR) << "minidump.GetMemoryList() failed";
} else { } else {
memory_list->Print(); memory_list->Print();
} }
MinidumpException *exception = minidump.GetException(); MinidumpException *exception = minidump.GetException();
if (!exception) { if (!exception) {
// Exception info is optional, so don't treat this as an error. BPLOG(INFO) << "minidump.GetException() failed";
printf("minidump.GetException() failed\n");
} else { } else {
exception->Print(); exception->Print();
} }
@ -92,7 +92,7 @@ static bool PrintMinidumpDump(const char *minidump_file) {
MinidumpSystemInfo *system_info = minidump.GetSystemInfo(); MinidumpSystemInfo *system_info = minidump.GetSystemInfo();
if (!system_info) { if (!system_info) {
++errors; ++errors;
printf("minidump.GetSystemInfo() failed\n"); BPLOG(ERROR) << "minidump.GetSystemInfo() failed";
} else { } else {
system_info->Print(); system_info->Print();
} }
@ -100,7 +100,7 @@ static bool PrintMinidumpDump(const char *minidump_file) {
MinidumpMiscInfo *misc_info = minidump.GetMiscInfo(); MinidumpMiscInfo *misc_info = minidump.GetMiscInfo();
if (!misc_info) { if (!misc_info) {
++errors; ++errors;
printf("minidump.GetMiscInfo() failed\n"); BPLOG(ERROR) << "minidump.GetMiscInfo() failed";
} else { } else {
misc_info->Print(); misc_info->Print();
} }
@ -108,7 +108,7 @@ static bool PrintMinidumpDump(const char *minidump_file) {
MinidumpBreakpadInfo *breakpad_info = minidump.GetBreakpadInfo(); MinidumpBreakpadInfo *breakpad_info = minidump.GetBreakpadInfo();
if (!breakpad_info) { if (!breakpad_info) {
// Breakpad info is optional, so don't treat this as an error. // Breakpad info is optional, so don't treat this as an error.
printf("minidump.GetBreakpadInfo() failed\n"); BPLOG(INFO) << "minidump.GetBreakpadInfo() failed";
} else { } else {
breakpad_info->Print(); breakpad_info->Print();
} }
@ -119,6 +119,8 @@ static bool PrintMinidumpDump(const char *minidump_file) {
} // namespace } // namespace
int main(int argc, char **argv) { int main(int argc, char **argv) {
BPLOG_INIT(&argc, &argv);
if (argc != 2) { if (argc != 2) {
fprintf(stderr, "usage: %s <file>\n", argv[0]); fprintf(stderr, "usage: %s <file>\n", argv[0]);
return 1; return 1;

View File

@ -40,6 +40,7 @@
#include "google_breakpad/processor/process_state.h" #include "google_breakpad/processor/process_state.h"
#include "google_breakpad/processor/stack_frame.h" #include "google_breakpad/processor/stack_frame.h"
#include "google_breakpad/processor/symbol_supplier.h" #include "google_breakpad/processor/symbol_supplier.h"
#include "processor/logging.h"
#include "processor/scoped_ptr.h" #include "processor/scoped_ptr.h"
namespace { namespace {
@ -204,6 +205,8 @@ static bool RunTests() {
} // namespace } // namespace
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
BPLOG_INIT(&argc, &argv);
if (!RunTests()) { if (!RunTests()) {
return 1; return 1;
} }

View File

@ -45,6 +45,7 @@
#include "google_breakpad/processor/minidump_processor.h" #include "google_breakpad/processor/minidump_processor.h"
#include "google_breakpad/processor/process_state.h" #include "google_breakpad/processor/process_state.h"
#include "google_breakpad/processor/stack_frame_cpu.h" #include "google_breakpad/processor/stack_frame_cpu.h"
#include "processor/logging.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"
@ -416,7 +417,7 @@ static bool PrintMinidumpProcess(const string &minidump_file,
ProcessState process_state; ProcessState process_state;
if (minidump_processor.Process(minidump_file, &process_state) != if (minidump_processor.Process(minidump_file, &process_state) !=
MinidumpProcessor::PROCESS_OK) { MinidumpProcessor::PROCESS_OK) {
fprintf(stderr, "MinidumpProcessor::Process failed\n"); BPLOG(ERROR) << "MinidumpProcessor::Process failed";
return false; return false;
} }
@ -438,6 +439,8 @@ static void usage(const char *program_name) {
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
BPLOG_INIT(&argc, &argv);
if (argc < 2) { if (argc < 2) {
usage(argv[0]); usage(argv[0]);
return 1; return 1;

View File

@ -28,6 +28,7 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "processor/pathname_stripper.h" #include "processor/pathname_stripper.h"
#include "processor/logging.h"
#define ASSERT_TRUE(condition) \ #define ASSERT_TRUE(condition) \
if (!(condition)) { \ if (!(condition)) { \
@ -78,5 +79,7 @@ static bool RunTests() {
} // namespace } // namespace
int main(int argc, char **argv) { int main(int argc, char **argv) {
BPLOG_INIT(&argc, &argv);
return RunTests() ? 0 : 1; return RunTests() ? 0 : 1;
} }

View File

@ -39,6 +39,7 @@
#include "google_breakpad/common/breakpad_types.h" #include "google_breakpad/common/breakpad_types.h"
#include "google_breakpad/processor/memory_region.h" #include "google_breakpad/processor/memory_region.h"
#include "processor/logging.h"
namespace { namespace {
@ -296,5 +297,7 @@ static bool RunTests() {
int main(int argc, char **argv) { int main(int argc, char **argv) {
BPLOG_INIT(&argc, &argv);
return RunTests() ? 0 : 1; return RunTests() ? 0 : 1;
} }

View File

@ -38,6 +38,7 @@
#include "processor/range_map-inl.h" #include "processor/range_map-inl.h"
#include "processor/linked_ptr.h" #include "processor/linked_ptr.h"
#include "processor/logging.h"
#include "processor/scoped_ptr.h" #include "processor/scoped_ptr.h"
@ -487,5 +488,7 @@ static bool RunTests() {
int main(int argc, char **argv) { int main(int argc, char **argv) {
BPLOG_INIT(&argc, &argv);
return RunTests() ? 0 : 1; return RunTests() ? 0 : 1;
} }

View File

@ -61,6 +61,7 @@
#include "google_breakpad/processor/memory_region.h" #include "google_breakpad/processor/memory_region.h"
#include "google_breakpad/processor/stack_frame.h" #include "google_breakpad/processor/stack_frame.h"
#include "google_breakpad/processor/stack_frame_cpu.h" #include "google_breakpad/processor/stack_frame_cpu.h"
#include "processor/logging.h"
#include "processor/scoped_ptr.h" #include "processor/scoped_ptr.h"
using google_breakpad::BasicSourceLineResolver; using google_breakpad::BasicSourceLineResolver;
@ -292,6 +293,8 @@ static bool Recursor(unsigned int depth, unsigned int parent_callers) {
// be inlined anyway. // be inlined anyway.
int main(int argc, char** argv) __attribute__((noinline)); int main(int argc, char** argv) __attribute__((noinline));
int main(int argc, char** argv) { int main(int argc, char** argv) {
BPLOG_INIT(&argc, &argv);
return Recursor(RECURSION_DEPTH, CountCallerFrames()) ? 0 : 1; return Recursor(RECURSION_DEPTH, CountCallerFrames()) ? 0 : 1;
} }
@ -302,8 +305,11 @@ int main(int argc, char** argv) {
int main(int argc, char **argv) { int main(int argc, char **argv) {
BPLOG_INIT(&argc, &argv);
// "make check" interprets an exit status of 77 to mean that the test is // "make check" interprets an exit status of 77 to mean that the test is
// not supported. // not supported.
BPLOG(ERROR) << "Selftest not supported here";
return 77; return 77;
} }