Skip to content

Commit cc21287

Browse files
author
Andres Villegas
authored
[sanitizer_symbolizer] Add MarkupStackTracePrinter (#73032)
Adds a new Implementation of StackTracePrinter that only emits symbolizer markup. Currently this change only affects Fuchsia OS. Should be NFC.
1 parent 23c84fb commit cc21287

File tree

3 files changed

+33
-23
lines changed

3 files changed

+33
-23
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_printer.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "sanitizer_stacktrace_printer.h"
1414

15+
#include "sanitizer_common.h"
1516
#include "sanitizer_file.h"
1617
#include "sanitizer_flags.h"
1718
#include "sanitizer_fuchsia.h"
@@ -25,8 +26,7 @@ StackTracePrinter *StackTracePrinter::GetOrInit() {
2526
if (stacktrace_printer)
2627
return stacktrace_printer;
2728

28-
stacktrace_printer =
29-
new (GetGlobalLowLevelAllocator()) FormattedStackTracePrinter();
29+
stacktrace_printer = StackTracePrinter::NewStackTracePrinter();
3030

3131
CHECK(stacktrace_printer);
3232
return stacktrace_printer;
@@ -61,6 +61,10 @@ const char *StackTracePrinter::StripFunctionName(const char *function) {
6161
// sanitizer_symbolizer_markup.cpp implements these differently.
6262
#if !SANITIZER_SYMBOLIZER_MARKUP
6363

64+
StackTracePrinter *StackTracePrinter::NewStackTracePrinter() {
65+
return new (GetGlobalLowLevelAllocator()) FormattedStackTracePrinter();
66+
}
67+
6468
static const char *DemangleFunctionName(const char *function) {
6569
if (!common_flags()->demangle)
6670
return function;

compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_printer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ class StackTracePrinter {
4646
const DataInfo *DI,
4747
const char *strip_path_prefix = "") = 0;
4848

49+
private:
50+
// To be called from StackTracePrinter::GetOrInit
51+
static StackTracePrinter *NewStackTracePrinter();
52+
4953
protected:
5054
~StackTracePrinter() {}
5155
};

compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.cpp

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,27 +76,29 @@ bool Symbolizer::SymbolizeData(uptr addr, DataInfo *info) {
7676
return true;
7777
}
7878

79-
// We ignore the format argument to __sanitizer_symbolize_global.
80-
void FormattedStackTracePrinter::RenderData(InternalScopedString *buffer,
81-
const char *format,
82-
const DataInfo *DI,
83-
const char *strip_path_prefix) {
84-
buffer->AppendF(kFormatData, DI->start);
85-
}
86-
87-
bool FormattedStackTracePrinter::RenderNeedsSymbolization(const char *format) {
88-
return false;
89-
}
90-
91-
// We don't support the stack_trace_format flag at all.
92-
void FormattedStackTracePrinter::RenderFrame(InternalScopedString *buffer,
93-
const char *format, int frame_no,
94-
uptr address,
95-
const AddressInfo *info,
96-
bool vs_style,
97-
const char *strip_path_prefix) {
98-
CHECK(!RenderNeedsSymbolization(format));
99-
buffer->AppendF(kFormatFrame, frame_no, address);
79+
class MarkupStackTracePrinter : public StackTracePrinter {
80+
// We ignore the format argument to __sanitizer_symbolize_global.
81+
void RenderData(InternalScopedString *buffer, const char *format,
82+
const DataInfo *DI, const char *strip_path_prefix) override {
83+
buffer->AppendF(kFormatData, DI->start);
84+
}
85+
86+
bool RenderNeedsSymbolization(const char *format) override { return false; }
87+
88+
// We don't support the stack_trace_format flag at all.
89+
void RenderFrame(InternalScopedString *buffer, const char *format,
90+
int frame_no, uptr address, const AddressInfo *info,
91+
bool vs_style, const char *strip_path_prefix) override {
92+
CHECK(!RenderNeedsSymbolization(format));
93+
buffer->AppendF(kFormatFrame, frame_no, address);
94+
}
95+
96+
protected:
97+
~MarkupStackTracePrinter();
98+
};
99+
100+
StackTracePrinter *StackTracePrinter::NewStackTracePrinter() {
101+
return new (GetGlobalLowLevelAllocator()) MarkupStackTracePrinter();
100102
}
101103

102104
Symbolizer *Symbolizer::PlatformInit() {

0 commit comments

Comments
 (0)