From 704f41ec901c419f8c321742114b415e6f5ceacc Mon Sep 17 00:00:00 2001 From: Ivan Penkov Date: Tue, 30 Aug 2016 14:00:56 -0700 Subject: [PATCH] This change allows compiling the google-breakpad code using a global ::string class instead of std::string. For more details take a look at common/using_std_string.h BUG= Change-Id: I11f1ce697be23e13f12ea8f0468bbe02fa63c967 Reviewed-on: https://chromium-review.googlesource.com/378159 Reviewed-by: Mark Mentovai --- src/common/dwarf/elf_reader.cc | 4 +-- src/common/linux/file_id.cc | 3 +- src/processor/proc_maps_linux.cc | 7 +++-- src/processor/proc_maps_linux_unittest.cc | 3 +- src/processor/stackwalk_common.cc | 8 ++--- src/processor/symbolic_constants_win.cc | 5 ++-- src/tools/linux/md2core/minidump-2-core.cc | 35 +++++++++++----------- 7 files changed, 34 insertions(+), 31 deletions(-) diff --git a/src/common/dwarf/elf_reader.cc b/src/common/dwarf/elf_reader.cc index 56847c31..4135a51a 100644 --- a/src/common/dwarf/elf_reader.cc +++ b/src/common/dwarf/elf_reader.cc @@ -47,7 +47,8 @@ #include "third_party/musl/include/elf.h" #include "elf_reader.h" -//#include "using_std_string.h" +#include "common/using_std_string.h" + // EM_AARCH64 is not defined by elf.h of GRTE v3 on x86. // TODO(dougkwan): Remove this when v17 is retired. #if !defined(EM_AARCH64) @@ -74,7 +75,6 @@ //DEFINE_bool(elfreader_process_dynsyms, true, // "Activate PLT function processing"); -using std::string; using std::vector; namespace { diff --git a/src/common/linux/file_id.cc b/src/common/linux/file_id.cc index 02207758..311e0302 100644 --- a/src/common/linux/file_id.cc +++ b/src/common/linux/file_id.cc @@ -45,10 +45,9 @@ #include "common/linux/elfutils.h" #include "common/linux/linux_libc_support.h" #include "common/linux/memory_mapped_file.h" +#include "common/using_std_string.h" #include "third_party/lss/linux_syscall_support.h" -using std::string; - namespace google_breakpad { // Used in a few places for backwards-compatibility. diff --git a/src/processor/proc_maps_linux.cc b/src/processor/proc_maps_linux.cc index 0cd3772e..3c0dea25 100644 --- a/src/processor/proc_maps_linux.cc +++ b/src/processor/proc_maps_linux.cc @@ -12,6 +12,7 @@ #include #include +#include "common/using_std_string.h" #include "processor/logging.h" #if defined(OS_ANDROID) && !defined(__LP64__) @@ -25,7 +26,7 @@ namespace google_breakpad { -bool ParseProcMaps(const std::string& input, +bool ParseProcMaps(const string& input, std::vector* regions_out) { std::vector regions; @@ -33,8 +34,8 @@ bool ParseProcMaps(const std::string& input, // this point in time. // Split the string by newlines. - std::vector lines; - std::string l = ""; + std::vector lines; + string l = ""; for (size_t i = 0; i < input.size(); i++) { if (input[i] != '\n' && input[i] != '\r') { l.push_back(input[i]); diff --git a/src/processor/proc_maps_linux_unittest.cc b/src/processor/proc_maps_linux_unittest.cc index 1ff4b031..466f2345 100644 --- a/src/processor/proc_maps_linux_unittest.cc +++ b/src/processor/proc_maps_linux_unittest.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "breakpad_googletest_includes.h" +#include "common/using_std_string.h" #include "google_breakpad/processor/proc_maps_linux.h" namespace { @@ -227,7 +228,7 @@ TEST(ProcMapsTest, ParseProcMapsEmptyString) { // - File name has whitespaces. TEST(ProcMapsTest, ParseProcMapsWeirdCorrectInput) { std::vector regions; - const std::string kContents = + const string kContents = "00400000-0040b000 r-xp 00000000 fc:00 2106562 " " /bin/cat\r\n" "7f53b7dad000-7f53b7f62000 r-xp 00000000 fc:00 263011 " diff --git a/src/processor/stackwalk_common.cc b/src/processor/stackwalk_common.cc index d8950fe2..704039f3 100644 --- a/src/processor/stackwalk_common.cc +++ b/src/processor/stackwalk_common.cc @@ -112,10 +112,10 @@ static string StripSeparator(const string &original) { } // PrintStackContents prints the stack contents of the current frame to stdout. -static void PrintStackContents(const std::string &indent, +static void PrintStackContents(const string &indent, const StackFrame *frame, const StackFrame *prev_frame, - const std::string &cpu, + const string &cpu, const MemoryRegion *memory, const CodeModules* modules, SourceLineResolverInterface *resolver) { @@ -181,7 +181,7 @@ static void PrintStackContents(const std::string &indent, // Print data in hex. const int kBytesPerRow = 16; - std::string data_as_string; + string data_as_string; for (int i = 0; i < kBytesPerRow; ++i, ++address) { uint8_t value = 0; if (address < stack_end && @@ -607,7 +607,7 @@ static void PrintStack(const CallStack *stack, // Print stack contents. if (output_stack_contents && frame_index + 1 < frame_count) { - const std::string indent(" "); + const string indent(" "); PrintStackContents(indent, frame, stack->frames()->at(frame_index + 1), cpu, memory, modules, resolver); } diff --git a/src/processor/symbolic_constants_win.cc b/src/processor/symbolic_constants_win.cc index 8f142a76..a6ee26a2 100644 --- a/src/processor/symbolic_constants_win.cc +++ b/src/processor/symbolic_constants_win.cc @@ -36,14 +36,15 @@ #include #include "common/stdio_wrapper.h" +#include "common/using_std_string.h" #include "google_breakpad/common/breakpad_types.h" #include "google_breakpad/common/minidump_exception_win32.h" #include "processor/symbolic_constants_win.h" namespace google_breakpad { -std::string NTStatusToString(uint32_t ntstatus) { - std::string reason; +string NTStatusToString(uint32_t ntstatus) { + string reason; // The content of this switch was created from ntstatus.h in the 8.1 SDK with // // egrep '#define [A-Z_0-9]+\s+\(\(NTSTATUS\)0xC[0-9A-F]+L\)' ntstatus.h diff --git a/src/tools/linux/md2core/minidump-2-core.cc b/src/tools/linux/md2core/minidump-2-core.cc index 322bbad6..6f637845 100644 --- a/src/tools/linux/md2core/minidump-2-core.cc +++ b/src/tools/linux/md2core/minidump-2-core.cc @@ -49,6 +49,7 @@ #include "common/linux/memory_mapped_file.h" #include "common/minidump_type_helper.h" #include "common/scoped_ptr.h" +#include "common/using_std_string.h" #include "google_breakpad/common/breakpad_types.h" #include "google_breakpad/common/minidump_format.h" #include "third_party/lss/linux_syscall_support.h" @@ -97,7 +98,7 @@ typedef MDTypeHelper::MDRawLinkMap MDRawLinkMap; static const MDRVA kInvalidMDRVA = static_cast(-1); static bool verbose; -static std::string g_custom_so_basedir; +static string g_custom_so_basedir; static int usage(const char* argv0) { fprintf(stderr, "Usage: %s [-v] \n", argv0); @@ -203,8 +204,8 @@ struct CrashedProcess { uint32_t permissions; uint64_t start_address, end_address, offset; - std::string filename; - std::string data; + string filename; + string data; }; std::map mappings; @@ -238,9 +239,9 @@ struct CrashedProcess { prpsinfo prps; - std::map signatures; + std::map signatures; - std::string dynamic_data; + string dynamic_data; MDRawDebug debug; std::vector link_map; }; @@ -597,8 +598,8 @@ ParseMaps(CrashedProcess* crashinfo, const MinidumpMemoryRange& range) { ptr < range.data() + range.length();) { const uint8_t* eol = (uint8_t*)memchr(ptr, '\n', range.data() + range.length() - ptr); - std::string line((const char*)ptr, - eol ? eol - ptr : range.data() + range.length() - ptr); + string line((const char*)ptr, + eol ? eol - ptr : range.data() + range.length() - ptr); ptr = eol ? eol + 1 : range.data() + range.length(); unsigned long long start, stop, offset; char* permissions = NULL; @@ -875,17 +876,17 @@ ParseModuleStream(CrashedProcess* crashinfo, const MinidumpMemoryRange& range, record->signature.data4[2], record->signature.data4[3], record->signature.data4[4], record->signature.data4[5], record->signature.data4[6], record->signature.data4[7]); - std::string filename = + string filename = full_file.GetAsciiMDString(rawmodule->module_name_rva); size_t slash = filename.find_last_of('/'); - std::string basename = slash == std::string::npos ? - filename : filename.substr(slash + 1); + string basename = slash == string::npos ? + filename : filename.substr(slash + 1); if (strcmp(guid, "00000000-0000-0000-0000-000000000000")) { - std::string prefix; + string prefix; if (!g_custom_so_basedir.empty()) prefix = g_custom_so_basedir; else - prefix = std::string("/var/lib/breakpad/") + guid + "-" + basename; + prefix = string("/var/lib/breakpad/") + guid + "-" + basename; crashinfo->signatures[rawmodule->base_of_image] = prefix + basename; } @@ -904,7 +905,7 @@ ParseModuleStream(CrashedProcess* crashinfo, const MinidumpMemoryRange& range, } static void -AddDataToMapping(CrashedProcess* crashinfo, const std::string& data, +AddDataToMapping(CrashedProcess* crashinfo, const string& data, uintptr_t addr) { for (std::map::iterator iter = crashinfo->mappings.begin(); @@ -960,7 +961,7 @@ AugmentMappings(CrashedProcess* crashinfo, for (unsigned i = 0; i < crashinfo->threads.size(); ++i) { const CrashedProcess::Thread& thread = crashinfo->threads[i]; AddDataToMapping(crashinfo, - std::string((char *)thread.stack, thread.stack_length), + string((char *)thread.stack, thread.stack_length), thread.stack_addr); } @@ -968,7 +969,7 @@ AugmentMappings(CrashedProcess* crashinfo, // the beginning of the address space, as this area should always be // available. static const uintptr_t start_addr = 4096; - std::string data; + string data; struct r_debug debug = { 0 }; debug.r_version = crashinfo->debug.version; debug.r_brk = (ElfW(Addr))crashinfo->debug.brk; @@ -988,11 +989,11 @@ AugmentMappings(CrashedProcess* crashinfo, link_map.l_ld = (ElfW(Dyn)*)iter->ld; link_map.l_prev = prev; prev = (struct link_map*)(start_addr + data.size()); - std::string filename = full_file.GetAsciiMDString(iter->name); + string filename = full_file.GetAsciiMDString(iter->name); // Look up signature for this filename. If available, change filename // to point to GUID, instead. - std::map::const_iterator guid = + std::map::const_iterator guid = crashinfo->signatures.find((uintptr_t)iter->addr); if (guid != crashinfo->signatures.end()) { filename = guid->second;