MCPcopy Create free account
hub / github.com/apache/brpc / ProcessBacktrace

Function ProcessBacktrace

src/butil/debug/stack_trace_posix.cc:149–202  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

147#endif // defined(USE_SYMBOLIZE)
148
149void ProcessBacktrace(void *const *trace,
150 size_t size,
151 BacktraceOutputHandler* handler) {
152 // NOTE: This code MUST be async-signal safe (it's used by in-process
153 // stack dumping signal handler). NO malloc or stdio is allowed here.
154
155#if defined(USE_SYMBOLIZE)
156 for (size_t i = 0; i < size; ++i) {
157 OutputFrameId(i, handler);
158 handler->HandleOutput(" ");
159 OutputPointer(trace[i], handler);
160 handler->HandleOutput(" ");
161
162 char buf[1024] = { '\0' };
163
164 // Subtract by one as return address of function may be in the next
165 // function when a function is annotated as noreturn.
166 void* address = static_cast<char*>(trace[i]) - 1;
167 if (google::Symbolize(address, buf, sizeof(buf)))
168 handler->HandleOutput(buf);
169 else
170 handler->HandleOutput("<unknown>");
171
172 handler->HandleOutput("\n");
173 }
174#elif !defined(__UCLIBC__)
175 bool printed = false;
176
177 // Below part is async-signal unsafe (uses malloc), so execute it only
178 // when we are not executing the signal handler.
179 if (in_signal_handler == 0) {
180 scoped_ptr<char*, FreeDeleter>
181 trace_symbols(backtrace_symbols(trace, size));
182 if (trace_symbols.get()) {
183 for (size_t i = 0; i < size; ++i) {
184 std::string trace_symbol = trace_symbols.get()[i];
185 DemangleSymbols(&trace_symbol);
186 handler->HandleOutput(trace_symbol.c_str());
187 handler->HandleOutput("\n");
188 }
189
190 printed = true;
191 }
192 }
193
194 if (!printed) {
195 for (size_t i = 0; i < size; ++i) {
196 handler->HandleOutput(" [");
197 OutputPointer(trace[i], handler);
198 handler->HandleOutput("]\n");
199 }
200 }
201#endif // defined(USE_SYMBOLIZE)
202}
203
204void PrintToStderr(const char* output) {
205 // NOTE: This code MUST be async-signal safe (it's used by in-process

Callers 3

PrintMethod · 0.85
OutputToStreamMethod · 0.85
OutputToStringMethod · 0.85

Calls 6

OutputFrameIdFunction · 0.85
OutputPointerFunction · 0.85
DemangleSymbolsFunction · 0.85
HandleOutputMethod · 0.45
getMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected