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. 12 // 13 // Symbolizer is planned to use debug information (in DWARF format) 14 // in a binary via interface defined in "llvm/DebugInfo/DIContext.h" 15 // 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 24 25 #include "sanitizer_internal_defs.h" 26 #include "sanitizer_libc.h" 27 // WARNING: Do not include system headers here. See details above. 28 29 namespace __sanitizer { 30 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; 39 40 AddressInfo() { 41 internal_memset(this, 0, sizeof(AddressInfo)); 42 } 43 // Deletes all strings and sets all fields to zero. 44 void Clear(); 45 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; 51 } 52 }; 53 54 struct DataInfo { 55 uptr address; 56 char *module; 57 uptr module_offset; 58 char *name; 59 uptr start; 60 uptr size; 61 }; 62 63 // Fills at most "max_frames" elements of "frames" with descriptions 64 // for a given address (in all inlined functions). Returns the number 65 // of descriptions actually filled. 66 // This function should NOT be called from two threads simultaneously. 67 uptr SymbolizeCode(uptr address, AddressInfo *frames, uptr max_frames); 68 bool SymbolizeData(uptr address, DataInfo *info); 69 70 bool IsSymbolizerAvailable(); 71 72 // Attempts to demangle the provided C++ mangled name. 73 const char *Demangle(const char *Name); 74 75 // Starts external symbolizer program in a subprocess. Sanitizer communicates 76 // with external symbolizer via pipes. 77 bool InitializeExternalSymbolizer(const char *path_to_symbolizer); 78 79 class LoadedModule { 80 public: 81 LoadedModule(const char *module_name, uptr base_address); 82 void addAddressRange(uptr beg, uptr end); 83 bool containsAddress(uptr address) const; 84 85 const char *full_name() const { return full_name_; } 86 uptr base_address() const { return base_address_; } 87 88 private: 89 struct AddressRange { 90 uptr beg; 91 uptr end; 92 }; 93 char *full_name_; 94 uptr base_address_; 95 static const uptr kMaxNumberOfAddressRanges = 6; 96 AddressRange ranges_[kMaxNumberOfAddressRanges]; 97 uptr n_ranges_; 98 }; 99 100 // Creates external symbolizer connected via pipe, user should write 101 // to output_fd and read from input_fd. 102 bool StartSymbolizerSubprocess(const char *path_to_symbolizer, 103 int *input_fd, int *output_fd); 104 105 // OS-dependent function that fills array with descriptions of at most 106 // "max_modules" currently loaded modules. Returns the number of 107 // initialized modules. 108 uptr GetListOfModules(LoadedModule *modules, uptr max_modules); 109 110 } // namespace __sanitizer 111 112 #endif // SANITIZER_SYMBOLIZER_H 113