Skip to content

Commit

Permalink
don't use glibc-specific execinfo.h on uclibc builds
Browse files Browse the repository at this point in the history
The execinfo.h header is glibc-specific, as is the backtrace function.
Let's skip them for uclibc builds.

BUG=361130

Review URL: https://codereview.chromium.org/228753003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@262841 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
mostynb@opera.com committed Apr 9, 2014
1 parent 582f60b commit 816e504
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 2 additions & 0 deletions base/debug/stack_trace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ const void *const *StackTrace::Addresses(size_t* count) const {

std::string StackTrace::ToString() const {
std::stringstream stream;
#if !defined(__UCLIBC__)
OutputToStream(&stream);
#endif
return stream.str();
}

Expand Down
2 changes: 2 additions & 0 deletions base/debug/stack_trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@ class BASE_EXPORT StackTrace {
// number of elements in the returned array.
const void* const* Addresses(size_t* count) const;

#if !defined(__UCLIBC__)
// Prints the stack trace to stderr.
void Print() const;

// Resolves backtrace to symbols and write to stream.
void OutputToStream(std::ostream* os) const;
#endif

// Resolves backtrace to symbols and returns as string.
std::string ToString() const;
Expand Down
18 changes: 14 additions & 4 deletions base/debug/stack_trace_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "base/debug/stack_trace.h"

#include <errno.h>
#include <execinfo.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
Expand All @@ -23,6 +22,9 @@
#if defined(__GLIBCXX__)
#include <cxxabi.h>
#endif
#if !defined(__UCLIBC__)
#include <execinfo.h>
#endif

#if defined(OS_MACOSX)
#include <AvailabilityMacros.h>
Expand Down Expand Up @@ -71,7 +73,7 @@ void DemangleSymbols(std::string* text) {
// Note: code in this function is NOT async-signal safe (std::string uses
// malloc internally).

#if defined(__GLIBCXX__)
#if defined(__GLIBCXX__) && !defined(__UCLIBC__)

std::string::size_type search_from = 0;
while (search_from < text->size()) {
Expand Down Expand Up @@ -108,7 +110,7 @@ void DemangleSymbols(std::string* text) {
}
}

#endif // defined(__GLIBCXX__)
#endif // defined(__GLIBCXX__) && !defined(__UCLIBC__)
}
#endif // !defined(USE_SYMBOLIZE)

Expand Down Expand Up @@ -167,7 +169,7 @@ void ProcessBacktrace(void *const *trace,

handler->HandleOutput("\n");
}
#else
#elif !defined(__UCLIBC__)
bool printed = false;

// Below part is async-signal unsafe (uses malloc), so execute it only
Expand Down Expand Up @@ -279,7 +281,9 @@ void StackDumpSignalHandler(int signal, siginfo_t* info, void* void_context) {
}
PrintToStderr("\n");

#if !defined(__UCLIBC__)
debug::StackTrace().Print();
#endif

#if defined(OS_LINUX)
#if ARCH_CPU_X86_FAMILY
Expand Down Expand Up @@ -738,11 +742,16 @@ StackTrace::StackTrace() {
// NOTE: This code MUST be async-signal safe (it's used by in-process
// stack dumping signal handler). NO malloc or stdio is allowed here.

#if !defined(__UCLIBC__)
// Though the backtrace API man page does not list any possible negative
// return values, we take no chance.
count_ = base::saturated_cast<size_t>(backtrace(trace_, arraysize(trace_)));
#else
count_ = 0;
#endif
}

#if !defined(__UCLIBC__)
void StackTrace::Print() const {
// NOTE: This code MUST be async-signal safe (it's used by in-process
// stack dumping signal handler). NO malloc or stdio is allowed here.
Expand All @@ -755,6 +764,7 @@ void StackTrace::OutputToStream(std::ostream* os) const {
StreamBacktraceOutputHandler handler(os);
ProcessBacktrace(trace_, count_, &handler);
}
#endif

namespace internal {

Expand Down

0 comments on commit 816e504

Please sign in to comment.