xref: /freebsd/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_printer.h (revision 069ac18495ad8fde2748bc94b0f80a50250bb01d)
1 //===-- sanitizer_stacktrace_printer.h --------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file is shared between sanitizers' run-time libraries.
10 //
11 //===----------------------------------------------------------------------===//
12 #ifndef SANITIZER_STACKTRACE_PRINTER_H
13 #define SANITIZER_STACKTRACE_PRINTER_H
14 
15 #include "sanitizer_common.h"
16 #include "sanitizer_symbolizer.h"
17 
18 namespace __sanitizer {
19 
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 = "");
71 
72 }  // namespace __sanitizer
73 
74 #endif  // SANITIZER_STACKTRACE_PRINTER_H
75