path: root/src/symbolize.h
diff options
author <>2014-03-01 00:33:41 (GMT)
committer <>2014-03-01 00:33:41 (GMT)
commit8367470aa572fa858cce67d6939b337d3909aa07 (patch)
tree703cd357d95b8d3e755cbbe6422e2927fa5e41dd /src/symbolize.h
parenta0073e504be20faa7e9c3b31ba795bdcfb99c967 (diff)
Adding a callback mechanism to allow users of google.glog to provide
their own implementation of OpenObjectFileContainingPcAndGetStartAddress. GTTF: Make stack trace symbolization code recognize more symbols. One example is __libc_start_main (easy to check), there may be more. Include the correct elf header on OpenBSD and Android. Fix Coverity NO_EFFECT defect. Comparing unsigned greater than or equal zero is always true. git-svn-id: eb4d4688-79bd-11dd-afb4-1d65580434c0
Diffstat (limited to 'src/symbolize.h')
1 files changed, 40 insertions, 1 deletions
diff --git a/src/symbolize.h b/src/symbolize.h
index 1ebe4dd..f617184 100644
--- a/src/symbolize.h
+++ b/src/symbolize.h
@@ -60,9 +60,26 @@
-#if defined(__ELF__) // defined by gcc on Linux
+#if defined(__ELF__) // defined by gcc
+#if defined(__OpenBSD__)
+#include <sys/exec_elf.h>
#include <elf.h>
+#if !defined(ANDROID)
#include <link.h> // For ElfW() macro.
+// For systems where SIZEOF_VOID_P is not defined, determine it
+// based on __LP64__ (defined by gcc on 64-bit systems)
+#if !defined(SIZEOF_VOID_P)
+# if defined(__LP64__)
+# define SIZEOF_VOID_P 8
+# else
+# define SIZEOF_VOID_P 4
+# endif
// If there is no ElfW macro, let's define it by ourself.
#ifndef ElfW
@@ -88,6 +105,10 @@ _END_GOOGLE_NAMESPACE_
+// Restrictions on the callbacks that follow:
+// - The callbacks must not use heaps but only use stacks.
+// - The callbacks must be async-signal-safe.
// 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.
@@ -99,6 +120,24 @@ typedef int (*SymbolizeCallback)(int fd, void *pc, char *out, size_t out_size,
uint64 relocation);
void InstallSymbolizeCallback(SymbolizeCallback callback);
+// Installs a callback function, which will be called instead of
+// OpenObjectFileContainingPcAndGetStartAddress. The callback is expected
+// to searches for the object file (from /proc/self/maps) that contains
+// the specified pc. If found, sets |start_address| to the start address
+// of where this object file is mapped in memory, sets the module base
+// address into |base_address|, copies the object file name into
+// |out_file_name|, and attempts to open the object file. If the object
+// file is opened successfully, returns the file descriptor. Otherwise,
+// returns -1. |out_file_name_size| is the size of the file name buffer
+// (including the null-terminator).
+typedef int (*SymbolizeOpenObjectFileCallback)(uint64_t pc,
+ uint64_t &start_address,
+ uint64_t &base_address,
+ char *out_file_name,
+ int out_file_name_size);
+void InstallSymbolizeOpenObjectFileCallback(
+ SymbolizeOpenObjectFileCallback callback);