Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: base/debug/stack_trace_posix.cc

Issue 1997153002: libchrome: Several upstreamable fixes from libchrome Base URL: https://chromium.googlesource.com/a/chromium/src.git@master
Patch Set: Also fix unit tests Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/debug/stack_trace.h" 5 #include "base/debug/stack_trace.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <signal.h> 9 #include <signal.h>
10 #include <stddef.h> 10 #include <stddef.h>
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 // The prefix used for mangled symbols, per the Itanium C++ ABI: 59 // The prefix used for mangled symbols, per the Itanium C++ ABI:
60 // http://www.codesourcery.com/cxx-abi/abi.html#mangling 60 // http://www.codesourcery.com/cxx-abi/abi.html#mangling
61 const char kMangledSymbolPrefix[] = "_Z"; 61 const char kMangledSymbolPrefix[] = "_Z";
62 62
63 // Characters that can be used for symbols, generated by Ruby: 63 // Characters that can be used for symbols, generated by Ruby:
64 // (('a'..'z').to_a+('A'..'Z').to_a+('0'..'9').to_a + ['_']).join 64 // (('a'..'z').to_a+('A'..'Z').to_a+('0'..'9').to_a + ['_']).join
65 const char kSymbolCharacters[] = 65 const char kSymbolCharacters[] =
66 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"; 66 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
67 #endif // !defined(USE_SYMBOLIZE) && defined(__GLIBCXX__) 67 #endif // !defined(USE_SYMBOLIZE) && defined(__GLIBCXX__)
68 68
69 #if !defined(USE_SYMBOLIZE) 69 #if !defined(__UCLIBC__) && !defined(USE_SYMBOLIZE)
danakj 2016/05/23 02:59:54 Can you explain?
Luis Héctor Chávez 2016/05/24 15:27:52 DemangleSymbols is only used when neither __UCLIBC
70 // Demangles C++ symbols in the given text. Example: 70 // Demangles C++ symbols in the given text. Example:
71 // 71 //
72 // "out/Debug/base_unittests(_ZN10StackTraceC1Ev+0x20) [0x817778c]" 72 // "out/Debug/base_unittests(_ZN10StackTraceC1Ev+0x20) [0x817778c]"
73 // => 73 // =>
74 // "out/Debug/base_unittests(StackTrace::StackTrace()+0x20) [0x817778c]" 74 // "out/Debug/base_unittests(StackTrace::StackTrace()+0x20) [0x817778c]"
75 void DemangleSymbols(std::string* text) { 75 void DemangleSymbols(std::string* text) {
76 // Note: code in this function is NOT async-signal safe (std::string uses 76 // Note: code in this function is NOT async-signal safe (std::string uses
77 // malloc internally). 77 // malloc internally).
78 78
79 #if defined(__GLIBCXX__) && !defined(__UCLIBC__) 79 #if defined(__GLIBCXX__)
80 80
81 std::string::size_type search_from = 0; 81 std::string::size_type search_from = 0;
82 while (search_from < text->size()) { 82 while (search_from < text->size()) {
83 // Look for the start of a mangled symbol, from search_from. 83 // Look for the start of a mangled symbol, from search_from.
84 std::string::size_type mangled_start = 84 std::string::size_type mangled_start =
85 text->find(kMangledSymbolPrefix, search_from); 85 text->find(kMangledSymbolPrefix, search_from);
86 if (mangled_start == std::string::npos) { 86 if (mangled_start == std::string::npos) {
87 break; // Mangled symbol not found. 87 break; // Mangled symbol not found.
88 } 88 }
89 89
(...skipping 16 matching lines...) Expand all
106 // Insert the demangled symbol. 106 // Insert the demangled symbol.
107 text->insert(mangled_start, demangled_symbol.get()); 107 text->insert(mangled_start, demangled_symbol.get());
108 // Next time, we'll start right after the demangled symbol we inserted. 108 // Next time, we'll start right after the demangled symbol we inserted.
109 search_from = mangled_start + strlen(demangled_symbol.get()); 109 search_from = mangled_start + strlen(demangled_symbol.get());
110 } else { 110 } else {
111 // Failed to demangle. Retry after the "_Z" we just found. 111 // Failed to demangle. Retry after the "_Z" we just found.
112 search_from = mangled_start + 2; 112 search_from = mangled_start + 2;
113 } 113 }
114 } 114 }
115 115
116 #endif // defined(__GLIBCXX__) && !defined(__UCLIBC__) 116 #else
danakj 2016/05/23 02:59:54 comment on what this is #else-ing
Luis Héctor Chávez 2016/05/24 15:27:52 Done.
117
danakj 2016/05/23 02:59:54 no need for the whitespace
Luis Héctor Chávez 2016/05/24 15:27:52 Done.
118 // Avoid an unused warning.
119 (void)text;
120
danakj 2016/05/23 02:59:54 ditto
Luis Héctor Chávez 2016/05/24 15:27:52 Done.
121 #endif // defined(__GLIBCXX__)
117 } 122 }
118 #endif // !defined(USE_SYMBOLIZE) 123 #endif // !defined(__UCLIBC__) && !defined(USE_SYMBOLIZE)
119 124
120 class BacktraceOutputHandler { 125 class BacktraceOutputHandler {
121 public: 126 public:
122 virtual void HandleOutput(const char* output) = 0; 127 virtual void HandleOutput(const char* output) = 0;
123 128
124 protected: 129 protected:
125 virtual ~BacktraceOutputHandler() {} 130 virtual ~BacktraceOutputHandler() {}
126 }; 131 };
127 132
128 #if !defined(__UCLIBC__) 133 #if !defined(__UCLIBC__)
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 *ptr = *start; 809 *ptr = *start;
805 *start++ = ch; 810 *start++ = ch;
806 } 811 }
807 return buf; 812 return buf;
808 } 813 }
809 814
810 } // namespace internal 815 } // namespace internal
811 816
812 } // namespace debug 817 } // namespace debug
813 } // namespace base 818 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698