summaryrefslogtreecommitdiffstats
path: root/compiler-rt
diff options
context:
space:
mode:
authorAlexey Samsonov <samsonov@google.com>2012-06-01 06:11:13 +0000
committerAlexey Samsonov <samsonov@google.com>2012-06-01 06:11:13 +0000
commit6f596767c39ce6ac5ce9baa79479b0e30e1729fc (patch)
tree2bf523a5abc9e8662336fe2cdd67ffaabf729e1e /compiler-rt
parent1d4d62d76c1d4d387434278e0642531ac93bab8f (diff)
downloadbcm5719-llvm-6f596767c39ce6ac5ce9baa79479b0e30e1729fc.tar.gz
bcm5719-llvm-6f596767c39ce6ac5ce9baa79479b0e30e1729fc.zip
Stub files for common symbolizer for AddressSanitizer and ThreadSanitizer tools.
It is an analogue of addr2line utility and should allow to map instruction address to a location in source code at run-time. It should use debug information (in DWARF) in a binary, and hopefully it would be possible to re-use code from llvm/DebugInfo/DIContext.h llvm-svn: 157806
Diffstat (limited to 'compiler-rt')
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_symbolizer.cc56
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_symbolizer.h60
2 files changed, 116 insertions, 0 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer.cc b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer.cc
new file mode 100644
index 00000000000..0b23418c1f1
--- /dev/null
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer.cc
@@ -0,0 +1,56 @@
+//===-- symbolizer.cc -------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This is a stub for LLVM-based symbolizer.
+// This file is shared between AddressSanitizer and ThreadSanitizer
+// run-time libraries. See sanitizer.h for details.
+//===----------------------------------------------------------------------===//
+
+// WARNING: Avoid using library functions - see comments in symbolizer.h.
+#include "sanitizer_symbolizer.h"
+// FIXME: replace library malloc/free with internal_malloc/internal_free
+// that would be provided by ASan/TSan run-time libraries.
+#if defined(__linux__)
+# include <malloc.h>
+#elif defined(__APPLE__)
+# include <malloc/malloc.h>
+#endif
+
+namespace __sanitizer {
+
+void AddressInfo::Clear() {
+ free(module);
+ free(function);
+ free(file);
+}
+
+void AddressInfoList::Clear() {
+ AddressInfoList *cur = this;
+ while (cur) {
+ cur->info.Clear();
+ AddressInfoList *nxt = cur->next;
+ free(cur);
+ cur = nxt;
+ }
+}
+
+AddressInfoList* SymbolizeCode(uptr address) {
+ AddressInfoList *list = (AddressInfoList*)malloc(sizeof(AddressInfoList));
+ list->next = 0;
+ list->info.address = address;
+ list->info.module = 0;
+ list->info.module_offset = 0;
+ list->info.function = 0;
+ list->info.file = 0;
+ list->info.line = 0;
+ list->info.column = 0;
+ return list;
+}
+
+} // namespace __sanitizer
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer.h b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer.h
new file mode 100644
index 00000000000..cce6fc93bb3
--- /dev/null
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer.h
@@ -0,0 +1,60 @@
+//===-- symbolizer.h --------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Symbolizer is intended to be used by both
+// AddressSanitizer and ThreadSanitizer to symbolize a given
+// address. It is an analogue of addr2line utility and allows to map
+// instruction address to a location in source code at run-time.
+//
+// Symbolizer is planned to use debug information (in DWARF format)
+// in a binary via interface defined in "llvm/DebugInfo/DIContext.h"
+//
+// Symbolizer code should be called from the run-time library of
+// dynamic tools, and generally should not call memory allocation
+// routines or other system library functions intercepted by those tools.
+// Instead, Symbolizer code should use their replacements, defined in
+// "compiler-rt/lib/sanitizer_common/sanitizer_libc.h".
+//===----------------------------------------------------------------------===//
+#ifndef SANITIZER_SYMBOLIZER_H
+#define SANITIZER_SYMBOLIZER_H
+
+#include "sanitizer_defs.h"
+#include "sanitizer_libc.h"
+// WARNING: Do not include system headers here. See details above.
+
+namespace __sanitizer {
+
+struct AddressInfo {
+ uptr address;
+ char *module;
+ uptr module_offset;
+ char *function;
+ char *file;
+ int line;
+ int column;
+
+ // Deletes all strings.
+ void Clear();
+};
+
+struct AddressInfoList {
+ AddressInfoList *next;
+ AddressInfo info;
+
+ // Deletes all nodes in a list.
+ void Clear();
+};
+
+// Returns a list of descriptions for a given address (in all inlined
+// functions). The ownership is transferred to the caller.
+AddressInfoList* SymbolizeCode(uptr address);
+
+} // namespace __sanitizer
+
+#endif // SANITIZER_SYMBOLIZER_H
OpenPOWER on IntegriCloud