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 used by sanitizers to map instruction address to a location in
9 // source code at run-time. Symbolizer either uses __sanitizer_symbolize_*
10 // defined in the program, or (if they are missing) tries to find and
11 // launch "llvm-symbolizer" commandline tool in a separate process and
12 // communicate with it.
14 // Generally we should try to avoid calling system library functions during
15 // symbolization (and use their replacements from sanitizer_libc.h instead).
16 //===----------------------------------------------------------------------===//
17 #ifndef SANITIZER_SYMBOLIZER_H
18 #define SANITIZER_SYMBOLIZER_H
20 #include "sanitizer_allocator_internal.h"
21 #include "sanitizer_internal_defs.h"
22 #include "sanitizer_libc.h"
24 namespace __sanitizer
{
32 static const uptr kUnknown
= ~(uptr
)0;
41 internal_memset(this, 0, sizeof(AddressInfo
));
42 function_offset
= kUnknown
;
45 // Deletes all strings and resets all fields.
48 InternalFree(function
);
50 internal_memset(this, 0, sizeof(AddressInfo
));
51 function_offset
= kUnknown
;
54 void FillAddressAndModuleInfo(uptr addr
, const char *mod_name
,
57 module
= internal_strdup(mod_name
);
58 module_offset
= mod_offset
;
73 /// Initialize and return platform-specific implementation of symbolizer
74 /// (if it wasn't already initialized).
75 static Symbolizer
*GetOrInit();
76 // Fills at most "max_frames" elements of "frames" with descriptions
77 // for a given address (in all inlined functions). Returns the number
78 // of descriptions actually filled.
79 virtual uptr
SymbolizePC(uptr address
, AddressInfo
*frames
, uptr max_frames
) {
82 virtual bool SymbolizeData(uptr address
, DataInfo
*info
) {
85 virtual bool GetModuleNameAndOffsetForPC(uptr pc
, const char **module_name
,
86 uptr
*module_address
) {
89 virtual bool CanReturnFileLineInfo() {
92 // Release internal caches (if any).
93 virtual void Flush() {}
94 // Attempts to demangle the provided C++ mangled name.
95 virtual const char *Demangle(const char *name
) {
98 virtual void PrepareForSandboxing() {}
100 // Allow user to install hooks that would be called before/after Symbolizer
101 // does the actual file/line info fetching. Specific sanitizers may need this
102 // to distinguish system library calls made in user code from calls made
103 // during in-process symbolization.
104 typedef void (*StartSymbolizationHook
)();
105 typedef void (*EndSymbolizationHook
)();
106 // May be called at most once.
107 void AddHooks(StartSymbolizationHook start_hook
,
108 EndSymbolizationHook end_hook
);
111 /// Platform-specific function for creating a Symbolizer object.
112 static Symbolizer
*PlatformInit();
113 /// Initialize the symbolizer in a disabled state. Not thread safe.
114 static Symbolizer
*Disable();
116 static Symbolizer
*symbolizer_
;
117 static StaticSpinMutex init_mu_
;
122 static LowLevelAllocator symbolizer_allocator_
;
124 StartSymbolizationHook start_hook_
;
125 EndSymbolizationHook end_hook_
;
126 class SymbolizerScope
{
128 explicit SymbolizerScope(const Symbolizer
*sym
);
131 const Symbolizer
*sym_
;
135 } // namespace __sanitizer
137 #endif // SANITIZER_SYMBOLIZER_H