1 //===-- sanitizer_symbolizer.h ----------------------------------*- C++ -*-===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
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
{
41 internal_memset(this, 0, sizeof(AddressInfo
));
43 // Deletes all strings and sets all fields to zero.
46 void FillAddressAndModuleInfo(uptr addr
, const char *mod_name
,
49 module
= internal_strdup(mod_name
);
50 module_offset
= mod_offset
;
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
);
70 bool IsSymbolizerAvailable();
72 // Attempts to demangle the provided C++ mangled name.
73 const char *Demangle(const char *Name
);
75 // Starts external symbolizer program in a subprocess. Sanitizer communicates
76 // with external symbolizer via pipes.
77 bool InitializeExternalSymbolizer(const char *path_to_symbolizer
);
81 LoadedModule(const char *module_name
, uptr base_address
);
82 void addAddressRange(uptr beg
, uptr end
);
83 bool containsAddress(uptr address
) const;
85 const char *full_name() const { return full_name_
; }
86 uptr
base_address() const { return base_address_
; }
95 static const uptr kMaxNumberOfAddressRanges
= 6;
96 AddressRange ranges_
[kMaxNumberOfAddressRanges
];
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
);
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
);
110 } // namespace __sanitizer
112 #endif // SANITIZER_SYMBOLIZER_H