sanitizer_symbolizer.h revision 238901
1//===-- sanitizer_symbolizer.h ----------------------------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// Symbolizer is intended to be used by both
11// AddressSanitizer and ThreadSanitizer to symbolize a given
12// address. It is an analogue of addr2line utility and allows to map
13// instruction address to a location in source code at run-time.
14//
15// Symbolizer is planned to use debug information (in DWARF format)
16// in a binary via interface defined in "llvm/DebugInfo/DIContext.h"
17//
18// Symbolizer code should be called from the run-time library of
19// dynamic tools, and generally should not call memory allocation
20// routines or other system library functions intercepted by those tools.
21// Instead, Symbolizer code should use their replacements, defined in
22// "compiler-rt/lib/sanitizer_common/sanitizer_libc.h".
23//===----------------------------------------------------------------------===//
24#ifndef SANITIZER_SYMBOLIZER_H
25#define SANITIZER_SYMBOLIZER_H
26
27#include "sanitizer_internal_defs.h"
28#include "sanitizer_libc.h"
29// WARNING: Do not include system headers here. See details above.
30
31namespace __sanitizer {
32
33struct AddressInfo {
34  uptr address;
35  char *module;
36  uptr module_offset;
37  char *function;
38  char *file;
39  int line;
40  int column;
41
42  AddressInfo() {
43    internal_memset(this, 0, sizeof(AddressInfo));
44  }
45  // Deletes all strings and sets all fields to zero.
46  void Clear();
47};
48
49// Fills at most "max_frames" elements of "frames" with descriptions
50// for a given address (in all inlined functions). Returns the number
51// of descriptions actually filled.
52// This function should NOT be called from two threads simultaneously.
53uptr SymbolizeCode(uptr address, AddressInfo *frames, uptr max_frames);
54
55// Debug info routines
56struct DWARFSection {
57  const char *data;
58  uptr size;
59  DWARFSection() {
60    data = 0;
61    size = 0;
62  }
63};
64// Returns true on success.
65bool FindDWARFSection(uptr object_file_addr, const char *section_name,
66                      DWARFSection *section);
67bool IsFullNameOfDWARFSection(const char *full_name, const char *short_name);
68
69class ModuleDIContext {
70 public:
71  ModuleDIContext(const char *module_name, uptr base_address);
72  void addAddressRange(uptr beg, uptr end);
73  bool containsAddress(uptr address) const;
74  void getAddressInfo(AddressInfo *info);
75
76  const char *full_name() const { return full_name_; }
77
78 private:
79  void CreateDIContext();
80
81  struct AddressRange {
82    uptr beg;
83    uptr end;
84  };
85  char *full_name_;
86  char *short_name_;
87  uptr base_address_;
88  static const uptr kMaxNumberOfAddressRanges = 8;
89  AddressRange ranges_[kMaxNumberOfAddressRanges];
90  uptr n_ranges_;
91  uptr mapped_addr_;
92  uptr mapped_size_;
93};
94
95// OS-dependent function that gets the linked list of all loaded modules.
96uptr GetListOfModules(ModuleDIContext *modules, uptr max_modules);
97
98}  // namespace __sanitizer
99
100#endif  // SANITIZER_SYMBOLIZER_H
101