Home | History | Annotate | Line # | Download | only in sanitizer_common
sanitizer_stacktrace_printer.h revision 1.1.1.7
      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 // Render the contents of "info" structure, which represents the contents of
     21 // stack frame "frame_no" and appends it to the "buffer". "format" is a
     22 // string with placeholders, which is copied to the output with
     23 // placeholders substituted with the contents of "info". For example,
     24 // format string
     25 //   "  frame %n: function %F at %S"
     26 // will be turned into
     27 //   "  frame 10: function foo::bar() at my/file.cc:10"
     28 // You may additionally pass "strip_path_prefix" to strip prefixes of paths to
     29 // source files and modules, and "strip_func_prefix" to strip prefixes of
     30 // function names.
     31 // Here's the full list of available placeholders:
     32 //   %% - represents a '%' character;
     33 //   %n - frame number (copy of frame_no);
     34 //   %p - PC in hex format;
     35 //   %m - path to module (binary or shared object);
     36 //   %o - offset in the module in hex format;
     37 //   %f - function name;
     38 //   %q - offset in the function in hex format (*if available*);
     39 //   %s - path to source file;
     40 //   %l - line in the source file;
     41 //   %c - column in the source file;
     42 //   %F - if function is known to be <foo>, prints "in <foo>", possibly
     43 //        followed by the offset in this function, but only if source file
     44 //        is unknown;
     45 //   %S - prints file/line/column information;
     46 //   %L - prints location information: file/line/column, if it is known, or
     47 //        module+offset if it is known, or (<unknown module>) string.
     48 //   %M - prints module basename and offset, if it is known, or PC.
     49 void RenderFrame(InternalScopedString *buffer, const char *format, int frame_no,
     50                  const AddressInfo &info, bool vs_style,
     51                  const char *strip_path_prefix = "",
     52                  const char *strip_func_prefix = "");
     53 
     54 void RenderSourceLocation(InternalScopedString *buffer, const char *file,
     55                           int line, int column, bool vs_style,
     56                           const char *strip_path_prefix);
     57 
     58 void RenderModuleLocation(InternalScopedString *buffer, const char *module,
     59                           uptr offset, ModuleArch arch,
     60                           const char *strip_path_prefix);
     61 
     62 // Same as RenderFrame, but for data section (global variables).
     63 // Accepts %s, %l from above.
     64 // Also accepts:
     65 //   %g - name of the global variable.
     66 void RenderData(InternalScopedString *buffer, const char *format,
     67                 const DataInfo *DI, const char *strip_path_prefix = "");
     68 
     69 }  // namespace __sanitizer
     70 
     71 #endif  // SANITIZER_STACKTRACE_PRINTER_H
     72