* configure.ac: Change target-libasan to target-libsanitizer.
[official-gcc.git] / libsanitizer / sanitizer_common / sanitizer_symbolizer.h
blob83adf02528262aedcb282aafefd6d2d2af5fb681
1 //===-- sanitizer_symbolizer.h ----------------------------------*- C++ -*-===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // Symbolizer is intended to be used by both
9 // AddressSanitizer and ThreadSanitizer to symbolize a given
10 // address. It is an analogue of addr2line utility and allows to map
11 // instruction address to a location in source code at run-time.
13 // Symbolizer is planned to use debug information (in DWARF format)
14 // in a binary via interface defined in "llvm/DebugInfo/DIContext.h"
16 // Symbolizer code should be called from the run-time library of
17 // dynamic tools, and generally should not call memory allocation
18 // routines or other system library functions intercepted by those tools.
19 // Instead, Symbolizer code should use their replacements, defined in
20 // "compiler-rt/lib/sanitizer_common/sanitizer_libc.h".
21 //===----------------------------------------------------------------------===//
22 #ifndef SANITIZER_SYMBOLIZER_H
23 #define SANITIZER_SYMBOLIZER_H
25 #include "sanitizer_internal_defs.h"
26 #include "sanitizer_libc.h"
27 // WARNING: Do not include system headers here. See details above.
29 namespace __sanitizer {
31 struct AddressInfo {
32 uptr address;
33 char *module;
34 uptr module_offset;
35 char *function;
36 char *file;
37 int line;
38 int column;
40 AddressInfo() {
41 internal_memset(this, 0, sizeof(AddressInfo));
43 // Deletes all strings and sets all fields to zero.
44 void Clear();
46 void FillAddressAndModuleInfo(uptr addr, const char *mod_name,
47 uptr mod_offset) {
48 address = addr;
49 module = internal_strdup(mod_name);
50 module_offset = mod_offset;
54 // Fills at most "max_frames" elements of "frames" with descriptions
55 // for a given address (in all inlined functions). Returns the number
56 // of descriptions actually filled.
57 // This function should NOT be called from two threads simultaneously.
58 uptr SymbolizeCode(uptr address, AddressInfo *frames, uptr max_frames);
60 // Starts external symbolizer program in a subprocess. Sanitizer communicates
61 // with external symbolizer via pipes.
62 bool InitializeExternalSymbolizer(const char *path_to_symbolizer);
64 class LoadedModule {
65 public:
66 LoadedModule(const char *module_name, uptr base_address);
67 void addAddressRange(uptr beg, uptr end);
68 bool containsAddress(uptr address) const;
70 const char *full_name() const { return full_name_; }
71 uptr base_address() const { return base_address_; }
73 private:
74 struct AddressRange {
75 uptr beg;
76 uptr end;
78 char *full_name_;
79 uptr base_address_;
80 static const uptr kMaxNumberOfAddressRanges = 8;
81 AddressRange ranges_[kMaxNumberOfAddressRanges];
82 uptr n_ranges_;
85 // Creates external symbolizer connected via pipe, user should write
86 // to output_fd and read from input_fd.
87 bool StartSymbolizerSubprocess(const char *path_to_symbolizer,
88 int *input_fd, int *output_fd);
90 // OS-dependent function that fills array with descriptions of at most
91 // "max_modules" currently loaded modules. Returns the number of
92 // initialized modules.
93 uptr GetListOfModules(LoadedModule *modules, uptr max_modules);
95 } // namespace __sanitizer
97 #endif // SANITIZER_SYMBOLIZER_H