|
13 | 13 | #define SANITIZER_STACKTRACE_PRINTER_H
|
14 | 14 |
|
15 | 15 | #include "sanitizer_common.h"
|
| 16 | +#include "sanitizer_internal_defs.h" |
16 | 17 | #include "sanitizer_symbolizer.h"
|
17 | 18 |
|
18 | 19 | namespace __sanitizer {
|
19 | 20 |
|
20 |
| -// Strip interceptor prefixes from function name. |
21 |
| -const char *StripFunctionName(const char *function); |
22 |
| - |
23 |
| -// Render the contents of "info" structure, which represents the contents of |
24 |
| -// stack frame "frame_no" and appends it to the "buffer". "format" is a |
25 |
| -// string with placeholders, which is copied to the output with |
26 |
| -// placeholders substituted with the contents of "info". For example, |
27 |
| -// format string |
28 |
| -// " frame %n: function %F at %S" |
29 |
| -// will be turned into |
30 |
| -// " frame 10: function foo::bar() at my/file.cc:10" |
31 |
| -// You may additionally pass "strip_path_prefix" to strip prefixes of paths to |
32 |
| -// source files and modules. |
33 |
| -// Here's the full list of available placeholders: |
34 |
| -// %% - represents a '%' character; |
35 |
| -// %n - frame number (copy of frame_no); |
36 |
| -// %p - PC in hex format; |
37 |
| -// %m - path to module (binary or shared object); |
38 |
| -// %o - offset in the module in hex format; |
39 |
| -// %f - function name; |
40 |
| -// %q - offset in the function in hex format (*if available*); |
41 |
| -// %s - path to source file; |
42 |
| -// %l - line in the source file; |
43 |
| -// %c - column in the source file; |
44 |
| -// %F - if function is known to be <foo>, prints "in <foo>", possibly |
45 |
| -// followed by the offset in this function, but only if source file |
46 |
| -// is unknown; |
47 |
| -// %S - prints file/line/column information; |
48 |
| -// %L - prints location information: file/line/column, if it is known, or |
49 |
| -// module+offset if it is known, or (<unknown module>) string. |
50 |
| -// %M - prints module basename and offset, if it is known, or PC. |
51 |
| -void RenderFrame(InternalScopedString *buffer, const char *format, int frame_no, |
52 |
| - uptr address, const AddressInfo *info, bool vs_style, |
53 |
| - const char *strip_path_prefix = ""); |
54 |
| - |
55 |
| -bool RenderNeedsSymbolization(const char *format); |
56 |
| - |
57 |
| -void RenderSourceLocation(InternalScopedString *buffer, const char *file, |
58 |
| - int line, int column, bool vs_style, |
59 |
| - const char *strip_path_prefix); |
60 |
| - |
61 |
| -void RenderModuleLocation(InternalScopedString *buffer, const char *module, |
62 |
| - uptr offset, ModuleArch arch, |
63 |
| - const char *strip_path_prefix); |
64 |
| - |
65 |
| -// Same as RenderFrame, but for data section (global variables). |
66 |
| -// Accepts %s, %l from above. |
67 |
| -// Also accepts: |
68 |
| -// %g - name of the global variable. |
69 |
| -void RenderData(InternalScopedString *buffer, const char *format, |
70 |
| - const DataInfo *DI, const char *strip_path_prefix = ""); |
| 21 | +// StacktracePrinter is an interface that is implemented by |
| 22 | +// classes that can perform rendering of the different parts |
| 23 | +// of a stacktrace. |
| 24 | +class StackTracePrinter { |
| 25 | + public: |
| 26 | + static StackTracePrinter *GetOrInit(); |
| 27 | + |
| 28 | + virtual const char *StripFunctionName(const char *function) { |
| 29 | + UNIMPLEMENTED(); |
| 30 | + } |
| 31 | + |
| 32 | + virtual void RenderFrame(InternalScopedString *buffer, const char *format, |
| 33 | + int frame_no, uptr address, const AddressInfo *info, |
| 34 | + bool vs_style, const char *strip_path_prefix = "") { |
| 35 | + UNIMPLEMENTED(); |
| 36 | + } |
| 37 | + |
| 38 | + virtual bool RenderNeedsSymbolization(const char *format) { return false; } |
| 39 | + |
| 40 | + virtual void RenderSourceLocation(InternalScopedString *buffer, |
| 41 | + const char *file, int line, int column, |
| 42 | + bool vs_style, |
| 43 | + const char *strip_path_prefix) {} |
| 44 | + |
| 45 | + virtual void RenderModuleLocation(InternalScopedString *buffer, |
| 46 | + const char *module, uptr offset, |
| 47 | + ModuleArch arch, |
| 48 | + const char *strip_path_prefix) {} |
| 49 | + virtual void RenderData(InternalScopedString *buffer, const char *format, |
| 50 | + const DataInfo *DI, |
| 51 | + const char *strip_path_prefix = "") { |
| 52 | + UNIMPLEMENTED(); |
| 53 | + } |
| 54 | + |
| 55 | + protected: |
| 56 | + ~StackTracePrinter() {} |
| 57 | +}; |
| 58 | + |
| 59 | +class FormattedStackTracePrinter : public StackTracePrinter { |
| 60 | + public: |
| 61 | + // Strip interceptor prefixes from function name. |
| 62 | + const char *StripFunctionName(const char *function) override; |
| 63 | + |
| 64 | + // Render the contents of "info" structure, which represents the contents of |
| 65 | + // stack frame "frame_no" and appends it to the "buffer". "format" is a |
| 66 | + // string with placeholders, which is copied to the output with |
| 67 | + // placeholders substituted with the contents of "info". For example, |
| 68 | + // format string |
| 69 | + // " frame %n: function %F at %S" |
| 70 | + // will be turned into |
| 71 | + // " frame 10: function foo::bar() at my/file.cc:10" |
| 72 | + // You may additionally pass "strip_path_prefix" to strip prefixes of paths to |
| 73 | + // source files and modules. |
| 74 | + // Here's the full list of available placeholders: |
| 75 | + // %% - represents a '%' character; |
| 76 | + // %n - frame number (copy of frame_no); |
| 77 | + // %p - PC in hex format; |
| 78 | + // %m - path to module (binary or shared object); |
| 79 | + // %o - offset in the module in hex format; |
| 80 | + // %f - function name; |
| 81 | + // %q - offset in the function in hex format (*if available*); |
| 82 | + // %s - path to source file; |
| 83 | + // %l - line in the source file; |
| 84 | + // %c - column in the source file; |
| 85 | + // %F - if function is known to be <foo>, prints "in <foo>", possibly |
| 86 | + // followed by the offset in this function, but only if source file |
| 87 | + // is unknown; |
| 88 | + // %S - prints file/line/column information; |
| 89 | + // %L - prints location information: file/line/column, if it is known, or |
| 90 | + // module+offset if it is known, or (<unknown module>) string. |
| 91 | + // %M - prints module basename and offset, if it is known, or PC. |
| 92 | + void RenderFrame(InternalScopedString *buffer, const char *format, |
| 93 | + int frame_no, uptr address, const AddressInfo *info, |
| 94 | + bool vs_style, const char *strip_path_prefix = "") override; |
| 95 | + |
| 96 | + bool RenderNeedsSymbolization(const char *format) override; |
| 97 | + |
| 98 | + void RenderSourceLocation(InternalScopedString *buffer, const char *file, |
| 99 | + int line, int column, bool vs_style, |
| 100 | + const char *strip_path_prefix) override; |
| 101 | + |
| 102 | + void RenderModuleLocation(InternalScopedString *buffer, const char *module, |
| 103 | + uptr offset, ModuleArch arch, |
| 104 | + const char *strip_path_prefix) override; |
| 105 | + |
| 106 | + // Same as RenderFrame, but for data section (global variables). |
| 107 | + // Accepts %s, %l from above. |
| 108 | + // Also accepts: |
| 109 | + // %g - name of the global variable. |
| 110 | + void RenderData(InternalScopedString *buffer, const char *format, |
| 111 | + const DataInfo *DI, |
| 112 | + const char *strip_path_prefix = "") override; |
| 113 | + |
| 114 | + protected: |
| 115 | + ~FormattedStackTracePrinter() {} |
| 116 | +}; |
71 | 117 |
|
72 | 118 | } // namespace __sanitizer
|
73 | 119 |
|
|
0 commit comments