diff options
author | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-26 06:26:26 +0000 |
---|---|---|
committer | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-26 06:26:26 +0000 |
commit | 48c27f7fac6bb5cf9cc995df8a68d4f6d4c10600 (patch) | |
tree | b9ca64d89896a6fa93e86ec0287fb8f9229b977c /base/third_party/symbolize/symbolize.h | |
parent | 7c4ea146bc033d89c1a0d527ae3d43b587a23cab (diff) | |
download | chromium_src-48c27f7fac6bb5cf9cc995df8a68d4f6d4c10600.zip chromium_src-48c27f7fac6bb5cf9cc995df8a68d4f6d4c10600.tar.gz chromium_src-48c27f7fac6bb5cf9cc995df8a68d4f6d4c10600.tar.bz2 |
Import google-glog's Symbolize() and use it in debug_util_posix.cc.
Unlike glibc's backtrace_symbols(), google-glog's Symbolize() can
resolve symbols in binaries built with -fvisibility=hidden. This is
because Symbolize() uses both dynamic and regular symbols, while
backtrace_symbols() only uses dynamic symbols.
As shown below, the new backtrace is slightly less informative as it
does not have the binary name like out/Debug/base_unittests and the
distance information like +0x20, but it should be ok.
BUG=32762
TEST=out/Debug/base_unittests --gtest_filter='StackTrace*' --gtest_also_run_disabled_tests; and manually:
BEFORE
out/Debug/base_unittests(StackTrace::StackTrace()+0x20) [0x81d38f6]
out/Debug/base_unittests(StackTrace_DISABLED_DebugOutputToStream_Test::TestBody()+0x17) [0x806633d]
out/Debug/base_unittests(testing::Test::Run()+0x7a) [0x8242f96]
out/Debug/base_unittests(testing::internal::TestInfoImpl::Run()+0xb9) [0x824347b]
out/Debug/base_unittests(testing::TestCase::Run()+0xb7) [0x8243a7f]
out/Debug/base_unittests(testing::internal::UnitTestImpl::RunAllTests()+0x256) [0x824777e]
out/Debug/base_unittests(testing::UnitTest::Run()+0x14) [0x824680a]
out/Debug/base_unittests [0x8048cc5]
out/Debug/base_unittests(main+0x50) [0x80482a4]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe6) [0xb6b41b56]
out/Debug/base_unittests [0x80481c1]
AFTER
% out/Debug/base_unittests --gtest_filter='*DebugOutputToStream' --gtest_also_run_disabled_tests
StackTrace::StackTrace() [0x81d3910]
StackTrace_DISABLED_DebugOutputToStream_Test::TestBody() [0x806633d]
testing::Test::Run() [0x8242f66]
testing::internal::TestInfoImpl::Run() [0x824344b]
testing::TestCase::Run() [0x8243a4f]
testing::internal::UnitTestImpl::RunAllTests() [0x824774e]
testing::UnitTest::Run() [0x82467da]
TestSuite::Run() [0x8048cc5]
main [0x80482a4]
0xb6c0db56
0x80481c1
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=36997
Review URL: http://codereview.chromium.org/545148
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37090 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/third_party/symbolize/symbolize.h')
-rw-r--r-- | base/third_party/symbolize/symbolize.h | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/base/third_party/symbolize/symbolize.h b/base/third_party/symbolize/symbolize.h new file mode 100644 index 0000000..1ebe4dd --- /dev/null +++ b/base/third_party/symbolize/symbolize.h @@ -0,0 +1,116 @@ +// Copyright (c) 2006, 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. +// +// Author: Satoru Takabayashi +// +// This library provides Symbolize() function that symbolizes program +// counters to their corresponding symbol names on linux platforms. +// This library has a minimal implementation of an ELF symbol table +// reader (i.e. it doesn't depend on libelf, etc.). +// +// The algorithm used in Symbolize() is as follows. +// +// 1. Go through a list of maps in /proc/self/maps and find the map +// containing the program counter. +// +// 2. Open the mapped file and find a regular symbol table inside. +// Iterate over symbols in the symbol table and look for the symbol +// containing the program counter. If such a symbol is found, +// obtain the symbol name, and demangle the symbol if possible. +// If the symbol isn't found in the regular symbol table (binary is +// stripped), try the same thing with a dynamic symbol table. +// +// Note that Symbolize() is originally implemented to be used in +// FailureSignalHandler() in base/google.cc. Hence it doesn't use +// malloc() and other unsafe operations. It should be both +// thread-safe and async-signal-safe. + +#ifndef BASE_SYMBOLIZE_H_ +#define BASE_SYMBOLIZE_H_ + +#include "utilities.h" +#include "config.h" +#include "glog/logging.h" + +#ifdef HAVE_SYMBOLIZE + +#if defined(__ELF__) // defined by gcc on Linux +#include <elf.h> +#include <link.h> // For ElfW() macro. + +// If there is no ElfW macro, let's define it by ourself. +#ifndef ElfW +# if SIZEOF_VOID_P == 4 +# define ElfW(type) Elf32_##type +# elif SIZEOF_VOID_P == 8 +# define ElfW(type) Elf64_##type +# else +# error "Unknown sizeof(void *)" +# endif +#endif + +_START_GOOGLE_NAMESPACE_ + +// Gets the section header for the given name, if it exists. Returns true on +// success. Otherwise, returns false. +bool GetSectionHeaderByName(int fd, const char *name, size_t name_len, + ElfW(Shdr) *out); + +_END_GOOGLE_NAMESPACE_ + +#endif /* __ELF__ */ + +_START_GOOGLE_NAMESPACE_ + +// Installs a callback function, which will be called right before a symbol name +// is printed. The callback is intended to be used for showing a file name and a +// line number preceding a symbol name. +// "fd" is a file descriptor of the object file containing the program +// counter "pc". The callback function should write output to "out" +// and return the size of the output written. On error, the callback +// function should return -1. +typedef int (*SymbolizeCallback)(int fd, void *pc, char *out, size_t out_size, + uint64 relocation); +void InstallSymbolizeCallback(SymbolizeCallback callback); + +_END_GOOGLE_NAMESPACE_ + +#endif + +_START_GOOGLE_NAMESPACE_ + +// Symbolizes a program counter. On success, returns true and write the +// symbol name to "out". The symbol name is demangled if possible +// (supports symbols generated by GCC 3.x or newer). Otherwise, +// returns false. +bool Symbolize(void *pc, char *out, int out_size); + +_END_GOOGLE_NAMESPACE_ + +#endif // BASE_SYMBOLIZE_H_ |