[Lldb-commits] [lldb] [lldb] Enable SanitizersAllocationTraces=tagged in darwin-mte-launcher (PR #186326)

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Thu Mar 12 23:48:07 PDT 2026


https://github.com/JDevlieghere created https://github.com/llvm/llvm-project/pull/186326

Collect allocation traces for tagged memory when using the `darwin-mte-launcher` to help debug MTE crashes.

>From 7cc9f777dbc4d99d18fe7f75b527bfaec571364e Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere <jonas at devlieghere.com>
Date: Thu, 12 Mar 2026 23:45:33 -0700
Subject: [PATCH] [lldb] Enable SanitizersAllocationTraces=tagged in
 darwin-mte-launcher

Collect allocation traces for tagged memory when using the
`darwin-mte-launcher` to help debug MTE crashes.
---
 .../darwin-mte-launcher.cpp                   | 27 +++++++++++++------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/lldb/tools/darwin-mte-launcher/darwin-mte-launcher.cpp b/lldb/tools/darwin-mte-launcher/darwin-mte-launcher.cpp
index 8f55e09f5c60b..ae11e4741e16a 100644
--- a/lldb/tools/darwin-mte-launcher/darwin-mte-launcher.cpp
+++ b/lldb/tools/darwin-mte-launcher/darwin-mte-launcher.cpp
@@ -14,6 +14,24 @@
 
 using namespace llvm;
 
+static std::vector<const char *> get_extended_env(const char *envp[]) {
+  // Copy over the current environment.
+  std::vector<const char *> new_envp;
+  for (const char **e = envp; *e; ++e)
+    new_envp.push_back(*e);
+
+  // Python's allocator (pymalloc) is not aware of Memory Tagging Extension
+  // (MTE) and crashes.
+  // https://bugs.python.org/issue43593
+  new_envp.push_back("PYTHONMALLOC=malloc");
+
+  // Collect allocation traces for tagged memory.
+  new_envp.push_back("SanitizersAllocationTraces=tagged");
+
+  new_envp.push_back(nullptr);
+  return new_envp;
+}
+
 int main(int argc, const char *argv[], const char *envp[]) {
   const char *program = argv[1];
   const char **new_args = &argv[1];
@@ -45,14 +63,7 @@ int main(int argc, const char *argv[], const char *envp[]) {
     return EXIT_FAILURE;
   }
 
-  // Python's allocator (pymalloc) is not aware of Memory Tagging Extension
-  // (MTE) and crashes.
-  // https://bugs.python.org/issue43593
-  std::vector<const char *> new_envp;
-  for (const char **e = envp; *e; ++e)
-    new_envp.push_back(*e);
-  new_envp.push_back("PYTHONMALLOC=malloc");
-  new_envp.push_back(nullptr);
+  std::vector<const char *> new_envp = get_extended_env(envp);
 
   pid_t pid;
   ret = posix_spawn(&pid, program, /*file_actions=*/nullptr, &attr,



More information about the lldb-commits mailing list