sanitizer_stacktrace_printer.h 3.1 KB

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