From 2e0e2234b9e9d7d82c4c3c20396bdf8f18007e6c Mon Sep 17 00:00:00 2001 From: mmentovai Date: Thu, 31 May 2007 19:44:52 +0000 Subject: Allow building with -pedantic (#186). r=ted.mielczarek http://groups.google.com/group/google-breakpad-dev/browse_thread/thread/6aa39d7f0ffa3c42 git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@183 4c0a9323-5329-0410-9bdc-e9ce6186880e --- src/google_breakpad/common/minidump_format.h | 65 ++++++++----- src/google_breakpad/common/minidump_size.h | 107 +++++++++++++++++++++ src/google_breakpad/processor/minidump_processor.h | 6 +- src/google_breakpad/processor/symbol_supplier.h | 2 +- 4 files changed, 153 insertions(+), 27 deletions(-) create mode 100644 src/google_breakpad/common/minidump_size.h (limited to 'src/google_breakpad') diff --git a/src/google_breakpad/common/minidump_format.h b/src/google_breakpad/common/minidump_format.h index 9606dff9..bf95d7d0 100644 --- a/src/google_breakpad/common/minidump_format.h +++ b/src/google_breakpad/common/minidump_format.h @@ -44,6 +44,12 @@ * writing affected structures, MD_*_SIZE macros are provided where needed, * containing the useful size of the structures without padding. * + * Structures that are defined by Microsoft to contain a zero-length array + * are instead defined here to contain an array with one element, as + * zero-length arrays are forbidden by standard C and C++. In these cases, + * *_minsize constants are provided to be used in place of sizeof. For a + * cleaner interface to these sizes when using C++, see minidump_size.h. + * * These structures are also sufficient to populate minidump files. * * These definitions may be extended to support handling minidump files @@ -67,6 +73,7 @@ #ifndef GOOGLE_BREAKPAD_COMMON_MINIDUMP_FORMAT_H__ #define GOOGLE_BREAKPAD_COMMON_MINIDUMP_FORMAT_H__ +#include #include "google_breakpad/common/breakpad_types.h" @@ -502,9 +509,11 @@ typedef enum { typedef struct { u_int32_t length; /* Length of buffer in bytes (not characters), * excluding 0-terminator */ - u_int16_t buffer[0]; /* UTF-16-encoded, 0-terminated */ + u_int16_t buffer[1]; /* UTF-16-encoded, 0-terminated */ } MDString; /* MINIDUMP_STRING */ +static const size_t MDString_minsize = offsetof(MDString, buffer[0]); + typedef struct { u_int32_t thread_id; @@ -519,9 +528,12 @@ typedef struct { typedef struct { u_int32_t number_of_threads; - MDRawThread threads[0]; + MDRawThread threads[1]; } MDRawThreadList; /* MINIDUMP_THREAD_LIST */ +static const size_t MDRawThreadList_minsize = offsetof(MDRawThreadList, + threads[0]); + typedef struct { u_int64_t base_of_image; @@ -576,19 +588,25 @@ typedef struct { MDCVHeader cv_header; u_int32_t signature; /* time_t debug information created */ u_int32_t age; /* revision of PDB file */ - u_int8_t pdb_file_name[0]; /* Pathname or filename of PDB file */ + u_int8_t pdb_file_name[1]; /* Pathname or filename of PDB file */ } MDCVInfoPDB20; +static const size_t MDCVInfoPDB20_minsize = offsetof(MDCVInfoPDB20, + pdb_file_name[0]); + #define MD_CVINFOPDB20_SIGNATURE 0x3031424e /* cvHeader.signature = '01BN' */ typedef struct { u_int32_t cv_signature; MDGUID signature; /* GUID, identifies PDB file */ u_int32_t age; /* Identifies incremental changes to PDB file */ - u_int8_t pdb_file_name[0]; /* Pathname or filename of PDB file, + u_int8_t pdb_file_name[1]; /* Pathname or filename of PDB file, * 0-terminated 8-bit character data (UTF-8?) */ } MDCVInfoPDB70; +static const size_t MDCVInfoPDB70_minsize = offsetof(MDCVInfoPDB70, + pdb_file_name[0]); + #define MD_CVINFOPDB70_SIGNATURE 0x53445352 /* cvSignature = 'SDSR' */ /* In addition to the two CodeView record formats above, used for linking @@ -618,21 +636,30 @@ typedef struct { u_int32_t length; /* Length of entire MDImageDebugMisc structure */ u_int8_t unicode; /* True if data is multibyte */ u_int8_t reserved[3]; - u_int8_t data[0]; + u_int8_t data[1]; } MDImageDebugMisc; /* IMAGE_DEBUG_MISC */ +static const size_t MDImageDebugMisc_minsize = offsetof(MDImageDebugMisc, + data[0]); + typedef struct { u_int32_t number_of_modules; - MDRawModule modules[0]; + MDRawModule modules[1]; } MDRawModuleList; /* MINIDUMP_MODULE_LIST */ +static const size_t MDRawModuleList_minsize = offsetof(MDRawModuleList, + modules[0]); + typedef struct { u_int32_t number_of_memory_ranges; - MDMemoryDescriptor memory_ranges[0]; + MDMemoryDescriptor memory_ranges[1]; } MDRawMemoryList; /* MINIDUMP_MEMORY_LIST */ +static const size_t MDRawMemoryList_minsize = offsetof(MDRawMemoryList, + memory_ranges[0]); + #define MD_EXCEPTION_MAXIMUM_PARAMETERS 15 @@ -848,7 +875,7 @@ typedef enum { /* EXC_GPFLT */ /* EXC_I386_PGFLT = 14: should not occur in user space */ /* EXC_I386_EXTERRFLT = 16: mapped to EXC_ARITHMETIC/EXC_I386_EXTERR */ - MD_EXCEPTION_CODE_MAC_X86_ALIGNMENT_FAULT = 17, + MD_EXCEPTION_CODE_MAC_X86_ALIGNMENT_FAULT = 17 /* EXC_ALIGNFLT (for vector operations) */ /* EXC_I386_ENOEXTFLT = 32: should be handled by the kernel */ /* EXC_I386_ENDPERR = 33: should not occur */ @@ -885,13 +912,9 @@ typedef struct { u_int16_t processor_level; /* x86: 5 = 586, 6 = 686, ... */ u_int16_t processor_revision; /* x86: 0xMMSS, where MM=model, * SS=stepping */ - union { - u_int16_t reserved0; - struct { - u_int8_t number_of_processors; - u_int8_t product_type; /* Windows: VER_NT_* from WinNT.h */ - }; - }; + + u_int8_t number_of_processors; + u_int8_t product_type; /* Windows: VER_NT_* from WinNT.h */ /* The next 5 fields are from the OSVERSIONINFO structure as returned * by GetVersionEx */ @@ -907,13 +930,9 @@ typedef struct { * (sw_vers -buildVersion). * Linux: uname -srvmo */ - union { - u_int32_t reserved1; - struct { - u_int16_t suite_mask; /* Windows: VER_SUITE_* from WinNT.h */ - u_int16_t reserved2; - }; - }; + u_int16_t suite_mask; /* Windows: VER_SUITE_* from WinNT.h */ + u_int16_t reserved2; + MDCPUInformation cpu; } MDRawSystemInfo; /* MINIDUMP_SYSTEM_INFO */ @@ -947,7 +966,7 @@ typedef enum { /* The following values are Breakpad-defined. */ MD_OS_UNIX = 0x8000, /* Generic Unix-ish */ MD_OS_MAC_OS_X = 0x8101, /* Mac OS X/Darwin */ - MD_OS_LINUX = 0x8201, /* Linux */ + MD_OS_LINUX = 0x8201 /* Linux */ } MDOSPlatform; diff --git a/src/google_breakpad/common/minidump_size.h b/src/google_breakpad/common/minidump_size.h new file mode 100644 index 00000000..01b42a2b --- /dev/null +++ b/src/google_breakpad/common/minidump_size.h @@ -0,0 +1,107 @@ +// 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. */ + +// minidump_size.h: Provides a C++ template for programmatic access to +// the sizes of various types defined in minidump_format.h. +// +// Author: Mark Mentovai + +#ifndef GOOGLE_BREAKPAD_COMMON_MINIDUMP_SIZE_H__ +#define GOOGLE_BREAKPAD_COMMON_MINIDUMP_SIZE_H__ + +#include + +#include "google_breakpad/common/minidump_format.h" + +namespace google_breakpad { + +template +class minidump_size { + public: + static size_t size() { return sizeof(T); } +}; + +// Explicit specializations for variable-length types. The size returned +// for these should be the size for an object without its variable-length +// section. + +template<> +class minidump_size { + public: + static size_t size() { return MDString_minsize; } +}; + +template<> +class minidump_size { + public: + static size_t size() { return MDRawThreadList_minsize; } +}; + +template<> +class minidump_size { + public: + static size_t size() { return MDCVInfoPDB20_minsize; } +}; + +template<> +class minidump_size { + public: + static size_t size() { return MDCVInfoPDB70_minsize; } +}; + +template<> +class minidump_size { + public: + static size_t size() { return MDImageDebugMisc_minsize; } +}; + +template<> +class minidump_size { + public: + static size_t size() { return MDRawModuleList_minsize; } +}; + +template<> +class minidump_size { + public: + static size_t size() { return MDRawMemoryList_minsize; } +}; + +// Explicit specialization for MDRawModule, for which sizeof may include +// tail-padding on some architectures but not others. + +template<> +class minidump_size { + public: + static size_t size() { return MD_MODULE_SIZE; } +}; + +} // namespace google_breakpad + +#endif /* GOOGLE_BREAKPAD_COMMON_MINIDUMP_SIZE_H__ */ diff --git a/src/google_breakpad/processor/minidump_processor.h b/src/google_breakpad/processor/minidump_processor.h index 9e7ea191..fc0024bc 100644 --- a/src/google_breakpad/processor/minidump_processor.h +++ b/src/google_breakpad/processor/minidump_processor.h @@ -46,9 +46,9 @@ class MinidumpProcessor { public: // Return type for Process() enum ProcessResult { - PROCESS_OK, // the minidump was processed successfully - PROCESS_ERROR, // there was an error processing the minidump - PROCESS_INTERRUPTED, // processing was interrupted by the SymbolSupplier + PROCESS_OK, // the minidump was processed successfully + PROCESS_ERROR, // there was an error processing the minidump + PROCESS_INTERRUPTED // processing was interrupted by the SymbolSupplier }; // Initializes this MinidumpProcessor. supplier should be an diff --git a/src/google_breakpad/processor/symbol_supplier.h b/src/google_breakpad/processor/symbol_supplier.h index 8fc88a66..0459c8aa 100644 --- a/src/google_breakpad/processor/symbol_supplier.h +++ b/src/google_breakpad/processor/symbol_supplier.h @@ -52,7 +52,7 @@ class SymbolSupplier { FOUND, // stops processing the minidump immediately - INTERRUPT, + INTERRUPT }; virtual ~SymbolSupplier() {} -- cgit v1.2.1