1276789Sdim//===-- sanitizer_stacktrace_printer.h --------------------------*- C++ -*-===//
2276789Sdim//
3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353358Sdim// See https://llvm.org/LICENSE.txt for license information.
5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6276789Sdim//
7276789Sdim//===----------------------------------------------------------------------===//
8276789Sdim//
9276789Sdim// This file is shared between sanitizers' run-time libraries.
10276789Sdim//
11276789Sdim//===----------------------------------------------------------------------===//
12276789Sdim#ifndef SANITIZER_STACKTRACE_PRINTER_H
13276789Sdim#define SANITIZER_STACKTRACE_PRINTER_H
14276789Sdim
15276789Sdim#include "sanitizer_common.h"
16276789Sdim#include "sanitizer_symbolizer.h"
17276789Sdim
18276789Sdimnamespace __sanitizer {
19276789Sdim
20276789Sdim// Render the contents of "info" structure, which represents the contents of
21276789Sdim// stack frame "frame_no" and appends it to the "buffer". "format" is a
22276789Sdim// string with placeholders, which is copied to the output with
23276789Sdim// placeholders substituted with the contents of "info". For example,
24276789Sdim// format string
25276789Sdim//   "  frame %n: function %F at %S"
26276789Sdim// will be turned into
27276789Sdim//   "  frame 10: function foo::bar() at my/file.cc:10"
28276789Sdim// You may additionally pass "strip_path_prefix" to strip prefixes of paths to
29276789Sdim// source files and modules, and "strip_func_prefix" to strip prefixes of
30276789Sdim// function names.
31276789Sdim// Here's the full list of available placeholders:
32276789Sdim//   %% - represents a '%' character;
33276789Sdim//   %n - frame number (copy of frame_no);
34276789Sdim//   %p - PC in hex format;
35276789Sdim//   %m - path to module (binary or shared object);
36276789Sdim//   %o - offset in the module in hex format;
37276789Sdim//   %f - function name;
38276789Sdim//   %q - offset in the function in hex format (*if available*);
39276789Sdim//   %s - path to source file;
40276789Sdim//   %l - line in the source file;
41276789Sdim//   %c - column in the source file;
42276789Sdim//   %F - if function is known to be <foo>, prints "in <foo>", possibly
43276789Sdim//        followed by the offset in this function, but only if source file
44276789Sdim//        is unknown;
45276789Sdim//   %S - prints file/line/column information;
46276789Sdim//   %L - prints location information: file/line/column, if it is known, or
47276789Sdim//        module+offset if it is known, or (<unknown module>) string.
48276789Sdim//   %M - prints module basename and offset, if it is known, or PC.
49276789Sdimvoid RenderFrame(InternalScopedString *buffer, const char *format, int frame_no,
50288943Sdim                 const AddressInfo &info, bool vs_style,
51288943Sdim                 const char *strip_path_prefix = "",
52276789Sdim                 const char *strip_func_prefix = "");
53276789Sdim
54276789Sdimvoid RenderSourceLocation(InternalScopedString *buffer, const char *file,
55288943Sdim                          int line, int column, bool vs_style,
56288943Sdim                          const char *strip_path_prefix);
57276789Sdim
58276789Sdimvoid RenderModuleLocation(InternalScopedString *buffer, const char *module,
59314564Sdim                          uptr offset, ModuleArch arch,
60314564Sdim                          const char *strip_path_prefix);
61276789Sdim
62314564Sdim// Same as RenderFrame, but for data section (global variables).
63314564Sdim// Accepts %s, %l from above.
64314564Sdim// Also accepts:
65314564Sdim//   %g - name of the global variable.
66314564Sdimvoid RenderData(InternalScopedString *buffer, const char *format,
67314564Sdim                const DataInfo *DI, const char *strip_path_prefix = "");
68314564Sdim
69276789Sdim}  // namespace __sanitizer
70276789Sdim
71276789Sdim#endif  // SANITIZER_STACKTRACE_PRINTER_H
72