[compiler-rt] [sanitizer_symbolizer] Symbolizer Markup for linux. (PR #65543)
Florian Mayer via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 7 11:28:28 PDT 2023
================
@@ -11,20 +11,140 @@
// Implementation of offline markup symbolizer.
//===----------------------------------------------------------------------===//
-#include "sanitizer_platform.h"
-#if SANITIZER_SYMBOLIZER_MARKUP
+#include "sanitizer_symbolizer_markup.h"
-#if SANITIZER_FUCHSIA
+#include "sanitizer_common.h"
+#include "sanitizer_libc.h"
+#include "sanitizer_platform.h"
+#include "sanitizer_stacktrace.h"
+#include "sanitizer_symbolizer.h"
#include "sanitizer_symbolizer_fuchsia.h"
-# endif
-# include <limits.h>
-# include <unwind.h>
+namespace __sanitizer {
-# include "sanitizer_stacktrace.h"
-# include "sanitizer_symbolizer.h"
+void RenderDataMarkup(InternalScopedString *buffer, const char *format,
+ const DataInfo *DI, const char *strip_path_prefix) {
+ buffer->append(kFormatData, DI->start);
+}
-namespace __sanitizer {
+bool RenderNeedsSymbolizationMarkup(const char *format) { return false; }
+
+void RenderFrameMarkup(InternalScopedString *buffer, const char *format,
+ int frame_no, uptr address, const AddressInfo *info,
+ bool vs_style, const char *strip_path_prefix) {
+ CHECK(!RenderNeedsSymbolizationMarkup(format));
+ buffer->append(kFormatFrame, frame_no, address);
+}
+
+// Simplier view of a LoadedModule. It only holds information necessary to
+// identify unique modules.
+struct RenderedModule {
+ char *full_name;
+ u8 uuid[kModuleUUIDSize]; // BuildId
+ uptr base_address;
+};
+
+bool ModulesEq(const LoadedModule *module,
+ const RenderedModule *renderedModule) {
+ return module->base_address() == renderedModule->base_address &&
+ internal_memcmp(module->uuid(), renderedModule->uuid,
+ module->uuid_size()) == 0 &&
+ internal_strcmp(module->full_name(), renderedModule->full_name) == 0;
+}
+
+bool ModuleHasBeenRendered(
+ const LoadedModule *module,
+ const InternalMmapVectorNoCtor<RenderedModule> *renderedModules) {
+ for (auto *it = renderedModules->begin(); it != renderedModules->end();
+ ++it) {
+ const auto &renderedModule = *it;
+ if (ModulesEq(module, &renderedModule)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+void RenderModulesMarkup(InternalScopedString *buffer,
+ const ListOfModules *modules) {
+ // Keeps track of the modules that have been rendered.
+ static bool initialized = false;
+ static InternalMmapVectorNoCtor<RenderedModule> renderedModules;
+ if (!initialized) {
+ renderedModules.Initialize(modules->size());
+ initialized = true;
+ }
+
+ if (!renderedModules.size()) {
+ buffer->append("{{{reset}}}\n");
+ }
+
+ for (auto *moduleIt = modules->begin(); moduleIt != modules->end();
+ ++moduleIt) {
+ const LoadedModule &module = *moduleIt;
+
+ if (ModuleHasBeenRendered(&module, &renderedModules)) {
+ continue;
+ }
+
+ buffer->append("{{{module:%d:%s:elf:", renderedModules.size(),
+ module.full_name());
+ for (uptr i = 0; i < module.uuid_size(); i++) {
+ buffer->append("%02x", module.uuid()[i]);
+ }
+ buffer->append("}}}\n");
+
+ const auto ranges = module.ranges();
+ for (const auto &range : ranges) {
+ buffer->append("{{{mmap:%p:%p:load:%d:r", range.beg,
+ range.end - range.beg, renderedModules.size());
+ if (range.writable)
+ buffer->append("w");
+ if (range.executable)
+ buffer->append("x");
+
+ // module.base_address = dlpi_addr
+ // range.beg = dlpi_addr + p_vaddr
+ // relative address = p_vaddr = range.beg - module.base_address
+ buffer->append(":%p}}}\n", range.beg - module.base_address());
+ }
+
+ renderedModules.push_back({});
+ RenderedModule &curModule = renderedModules.back();
+ curModule.full_name = internal_strdup(module.full_name());
+ internal_memcpy(curModule.uuid, module.uuid(), module.uuid_size());
----------------
fmayer wrote:
assert that `curModule.uuid` buffer can hold module.uuid_size?
https://github.com/llvm/llvm-project/pull/65543
More information about the llvm-commits
mailing list