1 //===-- sanitizer_symbolizer.h ----------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
15 // Symbolizer is planned to use debug information (in DWARF format)
16 // in a binary via interface defined in "llvm/DebugInfo/DIContext.h"
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
27 #include "sanitizer_internal_defs.h"
28 #include "sanitizer_libc.h"
29 // WARNING: Do not include system headers here. See details above.
31 namespace __sanitizer
{
43 internal_memset(this, 0, sizeof(AddressInfo
));
45 // Deletes all strings and sets all fields to zero.
48 void FillAddressAndModuleInfo(uptr addr
, const char *mod_name
,
51 module
= internal_strdup(mod_name
);
52 module_offset
= mod_offset
;
56 // Fills at most "max_frames" elements of "frames" with descriptions
57 // for a given address (in all inlined functions). Returns the number
58 // of descriptions actually filled.
59 // This function should NOT be called from two threads simultaneously.
60 uptr
SymbolizeCode(uptr address
, AddressInfo
*frames
, uptr max_frames
);
62 // Starts external symbolizer program in a subprocess. Sanitizer communicates
63 // with external symbolizer via pipes.
64 bool InitializeExternalSymbolizer(const char *path_to_symbolizer
);
68 LoadedModule(const char *module_name
, uptr base_address
);
69 void addAddressRange(uptr beg
, uptr end
);
70 bool containsAddress(uptr address
) const;
72 const char *full_name() const { return full_name_
; }
73 uptr
base_address() const { return base_address_
; }
82 static const uptr kMaxNumberOfAddressRanges
= 8;
83 AddressRange ranges_
[kMaxNumberOfAddressRanges
];
87 // Creates external symbolizer connected via pipe, user should write
88 // to output_fd and read from input_fd.
89 bool StartSymbolizerSubprocess(const char *path_to_symbolizer
,
90 int *input_fd
, int *output_fd
);
92 // OS-dependent function that fills array with descriptions of at most
93 // "max_modules" currently loaded modules. Returns the number of
94 // initialized modules.
95 uptr
GetListOfModules(LoadedModule
*modules
, uptr max_modules
);
97 } // namespace __sanitizer
99 #endif // SANITIZER_SYMBOLIZER_H