1//===-- sanitizer_stacktrace_printer.h --------------------------*- C++ -*-===//
2//
3// This file is distributed under the University of Illinois Open Source
4// License. See LICENSE.TXT for details.
5//
6//===----------------------------------------------------------------------===//
7//
8// This file is shared between sanitizers' run-time libraries.
9//
10//===----------------------------------------------------------------------===//
11#ifndef SANITIZER_STACKTRACE_PRINTER_H
12#define SANITIZER_STACKTRACE_PRINTER_H
13
14#include "sanitizer_common.h"
15#include "sanitizer_symbolizer.h"
16
17namespace __sanitizer {
18
19// Render the contents of "info" structure, which represents the contents of
20// stack frame "frame_no" and appends it to the "buffer". "format" is a
21// string with placeholders, which is copied to the output with
22// placeholders substituted with the contents of "info". For example,
23// format string
24//   "  frame %n: function %F at %S"
25// will be turned into
26//   "  frame 10: function foo::bar() at my/file.cc:10"
27// You may additionally pass "strip_path_prefix" to strip prefixes of paths to
28// source files and modules, and "strip_func_prefix" to strip prefixes of
29// function names.
30// Here's the full list of available placeholders:
31//   %% - represents a '%' character;
32//   %n - frame number (copy of frame_no);
33//   %p - PC in hex format;
34//   %m - path to module (binary or shared object);
35//   %o - offset in the module in hex format;
36//   %f - function name;
37//   %q - offset in the function in hex format (*if available*);
38//   %s - path to source file;
39//   %l - line in the source file;
40//   %c - column in the source file;
41//   %F - if function is known to be <foo>, prints "in <foo>", possibly
42//        followed by the offset in this function, but only if source file
43//        is unknown;
44//   %S - prints file/line/column information;
45//   %L - prints location information: file/line/column, if it is known, or
46//        module+offset if it is known, or (<unknown module>) string.
47//   %M - prints module basename and offset, if it is known, or PC.
48void RenderFrame(InternalScopedString *buffer, const char *format, int frame_no,
49                 const AddressInfo &info, bool vs_style,
50                 const char *strip_path_prefix = "",
51                 const char *strip_func_prefix = "");
52
53void RenderSourceLocation(InternalScopedString *buffer, const char *file,
54                          int line, int column, bool vs_style,
55                          const char *strip_path_prefix);
56
57void RenderModuleLocation(InternalScopedString *buffer, const char *module,
58                          uptr offset, ModuleArch arch,
59                          const char *strip_path_prefix);
60
61// Same as RenderFrame, but for data section (global variables).
62// Accepts %s, %l from above.
63// Also accepts:
64//   %g - name of the global variable.
65void RenderData(InternalScopedString *buffer, const char *format,
66                const DataInfo *DI, const char *strip_path_prefix = "");
67
68}  // namespace __sanitizer
69
70#endif  // SANITIZER_STACKTRACE_PRINTER_H
71