[llvm-branch-commits] [compiler-rt] a03c81b - Fix review comments and squash tests
Andrés Villegas via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Nov 28 13:17:16 PST 2023
Author: Andrés Villegas
Date: 2023-11-28T21:17:10Z
New Revision: a03c81be070eccb0e064af314d02216e76bab854
URL: https://github.com/llvm/llvm-project/commit/a03c81be070eccb0e064af314d02216e76bab854
DIFF: https://github.com/llvm/llvm-project/commit/a03c81be070eccb0e064af314d02216e76bab854.diff
LOG: Fix review comments and squash tests
Created using spr 1.3.4
Added:
compiler-rt/test/sanitizer_common/TestCases/print-stack-trace-markup.cpp
Modified:
compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.cpp
compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.cpp
index fe9933e942eba55..cbd111e975781a3 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.cpp
@@ -19,7 +19,6 @@
#include "sanitizer_symbolizer_markup.h"
#include "sanitizer_common.h"
-#include "sanitizer_stacktrace_printer.h"
#include "sanitizer_symbolizer.h"
#include "sanitizer_symbolizer_markup_constants.h"
@@ -73,13 +72,6 @@ const char *MarkupSymbolizerTool::Demangle(const char *name) {
// symbolization and pretty-print the markup.
#if !SANITIZER_FUCHSIA
-// Simplier view of a LoadedModule. It only holds information necessary to
-// identify unique modules.
-struct RenderedModule {
- char *full_name;
- uptr base_address;
- u8 uuid[kModuleUUIDSize]; // BuildId
-};
static bool ModulesEq(const LoadedModule &module,
const RenderedModule &renderedModule) {
@@ -136,39 +128,31 @@ static void RenderMmaps(InternalScopedString *buffer,
}
void MarkupStackTracePrinter::RenderContext(InternalScopedString *buffer) {
- // Keeps track of the modules that have been rendered.
- static bool initialized = false;
- static InternalMmapVectorNoCtor<RenderedModule> renderedModules;
- if (!initialized) {
- // arbitrary initial size, counting the main module plus some important libs
- // like libc.
- renderedModules.Initialize(3);
- initialized = true;
- }
-
- if (renderedModules.size() == 0)
+ if (renderedModules_.size() == 0)
buffer->Append("{{{reset}}}\n");
const auto &modules = Symbolizer::GetOrInit()->GetRefreshedListOfModules();
for (const auto &module : modules) {
- if (ModuleHasBeenRendered(module, renderedModules))
+ if (ModuleHasBeenRendered(module, renderedModules_))
continue;
// symbolizer markup id, used to refer to this modules from other contextual
// elements
- uptr moduleId = renderedModules.size();
+ uptr moduleId = renderedModules_.size();
RenderModule(buffer, module, moduleId);
RenderMmaps(buffer, module, moduleId);
- RenderedModule renderedModule{
- internal_strdup(module.full_name()), module.base_address(), {}};
+ renderedModules_.push_back({
+ internal_strdup(module.full_name()),
+ module.base_address(),
+ {},
+ });
// kModuleUUIDSize is the size of curModule.uuid
CHECK_GE(kModuleUUIDSize, module.uuid_size());
- internal_memcpy(renderedModule.uuid, module.uuid(), module.uuid_size());
- renderedModules.push_back(renderedModule);
+ internal_memcpy(renderedModules_.back().uuid, module.uuid(), module.uuid_size());
}
}
#endif // !SANITIZER_FUCHSIA
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.h b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.h
index 07630d0b3bdf417..bc2ab24d625bb5a 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.h
@@ -20,6 +20,14 @@
namespace __sanitizer {
+// Simplier view of a LoadedModule. It only holds information necessary to
+// identify unique modules.
+struct RenderedModule {
+ char *full_name;
+ uptr base_address;
+ u8 uuid[kModuleUUIDSize]; // BuildId
+};
+
class MarkupStackTracePrinter : public StackTracePrinter {
public:
// We don't support the stack_trace_format flag at all.
@@ -35,6 +43,9 @@ class MarkupStackTracePrinter : public StackTracePrinter {
const char *strip_path_prefix = "") override;
private:
+ // Keeps track of the modules that have been rendered to avoid re-rendering
+ // them
+ InternalMmapVector<RenderedModule> renderedModules_;
void RenderContext(InternalScopedString *buffer);
protected:
diff --git a/compiler-rt/test/sanitizer_common/TestCases/print-stack-trace-markup.cpp b/compiler-rt/test/sanitizer_common/TestCases/print-stack-trace-markup.cpp
new file mode 100644
index 000000000000000..15d89d091a99e33
--- /dev/null
+++ b/compiler-rt/test/sanitizer_common/TestCases/print-stack-trace-markup.cpp
@@ -0,0 +1,38 @@
+// RUN: %clangxx %s -o %t
+// RUN: %env_tool_opts=enable_symbolizer_markup=1 %run %t 2>&1 | FileCheck %s
+
+// REQUIRES: linux
+#include <sanitizer/common_interface_defs.h>
+
+void Bar() { __sanitizer_print_stack_trace(); }
+
+void Foo() {
+ Bar();
+ return;
+}
+
+void Baz() { __sanitizer_print_stack_trace(); }
+
+int main() {
+ Foo();
+ Baz();
+ return 0;
+}
+
+// COM: For element syntax see: https://llvm.org/docs/SymbolizerMarkupFormat.html
+// COM: OPEN is {{{ and CLOSE is }}}
+
+// CHECK: [[OPEN:{{{]]reset[[CLOSE:}}}]]
+// CHECK: [[OPEN]]module:[[MOD_ID:[0-9]+]]:{{.+}}:elf:{{[0-9a-fA-F]+}}[[CLOSE]]
+// CHECK: [[OPEN]]mmap:{{0x[0-9a-fA-F]+:0x[0-9a-fA-F]+}}:load:[[MOD_ID]]:{{r[wx]{0,2}:0x[0-9a-fA-F]+}}[[CLOSE]]
+// CHECK: [[OPEN]]bt:0:0x{{[0-9a-fA-F]+}}[[CLOSE]]
+// CHECK-NEXT: [[OPEN]]bt:1:0x{{[0-9a-fA-F]+}}[[CLOSE]]
+// CHECK-NEXT: [[OPEN]]bt:2:0x{{[0-9a-fA-F]+}}[[CLOSE]]
+
+// COM: Emitting a second backtrace should not emit contextual elements in this case.
+// CHECK-NOT: [[OPEN:{{{]]reset[[CLOSE:}}}]]
+// CHECK-NOT: [[OPEN]]module:[[MOD_ID:[0-9]+]]:{{.+}}:elf:{{[0-9a-fA-F]+}}[[CLOSE]]
+// CHECK-NOT: [[OPEN]]mmap:{{0x[0-9a-fA-F]+:0x[0-9a-fA-F]+}}:load:[[MOD_ID]]:{{r[wx]{0,2}:0x[0-9a-fA-F]+}}[[CLOSE]]
+
+// CHECK: [[OPEN]]bt:0:0x{{[0-9a-fA-F]+}}[[CLOSE]]
+// CHECK-NEXT: [[OPEN]]bt:1:0x{{[0-9a-fA-F]+}}[[CLOSE]]
More information about the llvm-branch-commits
mailing list