1 //===-- sanitizer_symbolizer_internal.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 // Header for internal classes and functions to be used by implementations of
13 //===----------------------------------------------------------------------===//
14 #ifndef SANITIZER_SYMBOLIZER_INTERNAL_H
15 #define SANITIZER_SYMBOLIZER_INTERNAL_H
17 #include "sanitizer_symbolizer.h"
19 namespace __sanitizer {
21 // Parsing helpers, 'str' is searched for delimiter(s) and a string or uptr
22 // is extracted. When extracting a string, a newly allocated (using
23 // InternalAlloc) and null-terminataed buffer is returned. They return a pointer
24 // to the next characted after the found delimiter.
25 const char *ExtractToken(const char *str, const char *delims, char **result);
26 const char *ExtractInt(const char *str, const char *delims, int *result);
27 const char *ExtractUptr(const char *str, const char *delims, uptr *result);
28 const char *ExtractTokenUpToDelimiter(const char *str, const char *delimiter,
31 const char *DemangleCXXABI(const char *name);
33 // SymbolizerTool is an interface that is implemented by individual "tools"
34 // that can perform symbolication (external llvm-symbolizer, libbacktrace,
35 // Windows DbgHelp symbolizer, etc.).
36 class SymbolizerTool {
38 // The main |Symbolizer| class implements a "fallback chain" of symbolizer
39 // tools. In a request to symbolize an address, if one tool returns false,
40 // the next tool in the chain will be tried.
43 SymbolizerTool() : next(nullptr) { }
45 // Can't declare pure virtual functions in sanitizer runtimes:
46 // __cxa_pure_virtual might be unavailable.
48 // The |stack| parameter is inout. It is pre-filled with the address,
49 // module base and module offset values and is to be used to construct
50 // other stack frames.
51 virtual bool SymbolizePC(uptr addr, SymbolizedStack *stack) {
55 // The |info| parameter is inout. It is pre-filled with the module base
56 // and module offset values.
57 virtual bool SymbolizeData(uptr addr, DataInfo *info) {
61 virtual void Flush() {}
63 // Return nullptr to fallback to the default platform-specific demangler.
64 virtual const char *Demangle(const char *name) {
69 // SymbolizerProcess encapsulates communication between the tool and
70 // external symbolizer program, running in a different subprocess.
71 // SymbolizerProcess may not be used from two threads simultaneously.
72 class SymbolizerProcess {
74 explicit SymbolizerProcess(const char *path, bool use_forkpty = false);
75 const char *SendCommand(const char *command);
79 const char *SendCommandImpl(const char *command);
80 bool ReadFromSymbolizer(char *buffer, uptr max_length);
81 bool WriteToSymbolizer(const char *buffer, uptr length);
82 bool StartSymbolizerSubprocess();
84 virtual bool ReachedEndOfOutput(const char *buffer, uptr length) const {
88 virtual void ExecuteWithDefaultArgs(const char *path_to_binary) const {
96 static const uptr kBufferSize = 16 * 1024;
97 char buffer_[kBufferSize];
99 static const uptr kMaxTimesRestarted = 5;
100 static const int kSymbolizerStartupTimeMillis = 10;
101 uptr times_restarted_;
102 bool failed_to_start_;
103 bool reported_invalid_path_;
107 } // namespace __sanitizer
109 #endif // SANITIZER_SYMBOLIZER_INTERNAL_H