Skip to content

[sanitizer_symbolizer] Add MarkupStackTracePrinter #73040

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

avillega
Copy link

This PR is part of a stack, #73029 should be merged
and reviewed first. Please only review the last commit
of this PR.

Adds a new Implementation of StackTracePrinter that only
emits symbolizer markup. Currently this change only
affects Fuchsia OS. Should be NFC.

Created using spr 1.3.4
@llvmbot
Copy link
Member

llvmbot commented Nov 21, 2023

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Andres Villegas (avillega)

Changes

This PR is part of a stack, #73029 should be merged
and reviewed first. Please only review the last commit
of this PR.

Adds a new Implementation of StackTracePrinter that only
emits symbolizer markup. Currently this change only
affects Fuchsia OS. Should be NFC.


Full diff: https://github.com/llvm/llvm-project/pull/73040.diff

3 Files Affected:

  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_printer.cpp (+6-2)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_printer.h (+4)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.cpp (+23-21)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_printer.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_printer.cpp
index 69047c2e31eca2a..e0c3943e4a9743e 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_printer.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_printer.cpp
@@ -12,6 +12,7 @@
 
 #include "sanitizer_stacktrace_printer.h"
 
+#include "sanitizer_common.h"
 #include "sanitizer_file.h"
 #include "sanitizer_flags.h"
 #include "sanitizer_fuchsia.h"
@@ -25,8 +26,7 @@ StackTracePrinter *StackTracePrinter::GetOrInit() {
   if (stacktrace_printer)
     return stacktrace_printer;
 
-  stacktrace_printer =
-      new (GetGlobalLowLevelAllocator()) FormattedStackTracePrinter();
+  stacktrace_printer = StackTracePrinter::PlatformInit();
 
   CHECK(stacktrace_printer);
   return stacktrace_printer;
@@ -61,6 +61,10 @@ const char *StackTracePrinter::StripFunctionName(const char *function) {
 // sanitizer_symbolizer_markup.cpp implements these differently.
 #if !SANITIZER_SYMBOLIZER_MARKUP
 
+StackTracePrinter *StackTracePrinter::PlatformInit() {
+  return new (GetGlobalLowLevelAllocator()) FormattedStackTracePrinter();
+}
+
 static const char *DemangleFunctionName(const char *function) {
   if (!common_flags()->demangle)
     return function;
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_printer.h b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_printer.h
index 9cf39013e78bc17..9de09bda0062d45 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_printer.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_printer.h
@@ -46,6 +46,10 @@ class StackTracePrinter {
                           const DataInfo *DI,
                           const char *strip_path_prefix = "") = 0;
 
+ private:
+  // To be called from StackTracePrinter::GetOrInit
+  static StackTracePrinter *PlatformInit();
+
  protected:
   ~StackTracePrinter() {}
 };
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.cpp
index 6402cfd7c36e443..ef3866a4bd32ac8 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.cpp
@@ -76,27 +76,29 @@ bool Symbolizer::SymbolizeData(uptr addr, DataInfo *info) {
   return true;
 }
 
-// We ignore the format argument to __sanitizer_symbolize_global.
-void FormattedStackTracePrinter::RenderData(InternalScopedString *buffer,
-                                            const char *format,
-                                            const DataInfo *DI,
-                                            const char *strip_path_prefix) {
-  buffer->AppendF(kFormatData, DI->start);
-}
-
-bool FormattedStackTracePrinter::RenderNeedsSymbolization(const char *format) {
-  return false;
-}
-
-// We don't support the stack_trace_format flag at all.
-void FormattedStackTracePrinter::RenderFrame(InternalScopedString *buffer,
-                                             const char *format, int frame_no,
-                                             uptr address,
-                                             const AddressInfo *info,
-                                             bool vs_style,
-                                             const char *strip_path_prefix) {
-  CHECK(!RenderNeedsSymbolization(format));
-  buffer->AppendF(kFormatFrame, frame_no, address);
+class MarkupStackTracePrinter : public StackTracePrinter {
+  // We ignore the format argument to __sanitizer_symbolize_global.
+  void RenderData(InternalScopedString *buffer, const char *format,
+                  const DataInfo *DI, const char *strip_path_prefix) override {
+    buffer->AppendF(kFormatData, DI->start);
+  }
+
+  bool RenderNeedsSymbolization(const char *format) override { return false; }
+
+  // We don't support the stack_trace_format flag at all.
+  void RenderFrame(InternalScopedString *buffer, const char *format,
+                   int frame_no, uptr address, const AddressInfo *info,
+                   bool vs_style, const char *strip_path_prefix) override {
+    CHECK(!RenderNeedsSymbolization(format));
+    buffer->AppendF(kFormatFrame, frame_no, address);
+  }
+
+ protected:
+  ~MarkupStackTracePrinter();
+};
+
+StackTracePrinter *StackTracePrinter::PlatformInit() {
+  return new (GetGlobalLowLevelAllocator()) MarkupStackTracePrinter();
 }
 
 Symbolizer *Symbolizer::PlatformInit() {

@avillega
Copy link
Author

Was trying out spr

@avillega avillega closed this Nov 21, 2023
@avillega avillega deleted the users/avillega/sanitizer_symbolizer-add-markupstacktraceprinter branch November 21, 2023 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants