[Lldb-commits] [lldb] [lldb][InstrumentationRuntime] Run sanitizer utility expressions as C (PR #172019)
Michael Buch via lldb-commits
lldb-commits at lists.llvm.org
Fri Dec 12 07:24:55 PST 2025
https://github.com/Michael137 created https://github.com/llvm/llvm-project/pull/172019
The utility expressions in the `InstrumentationRuntime` plugins are just plain C code, but we run them as `ObjC++`. That meant we were doing redundant work (like looking up decls in the Objective-C runtime). The sanitizer tests sporadically time out while looking up function symbols in the Objective-C runtime. This patch switches the expression language to `C`.
Didn't find a great way of testing this other than looking at the expression log.
rdar://165656320
>From 9e1ab2a4b96818953f2562c7e76dffdf2f58c5e2 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Fri, 12 Dec 2025 15:20:20 +0000
Subject: [PATCH] [lldb][InstrumentationRuntime] Run sanitizer utility
expressions as C
The utility expressions in the `InstrumentationRuntime` plugins are just plain C code, but we run them as `ObjC++`. That meant we were doing redundant work (like looking up decls in the Objective-C runtime). The sanitizer tests sporadically time out while looking up function symbols in the Objective-C runtime. This patch switches the expression language to `C`.
Didn't find a great way of testing this other than looking at the expression log.
rdar://165656320
---
.../TSan/InstrumentationRuntimeTSan.cpp | 2 +-
.../UBSan/InstrumentationRuntimeUBSan.cpp | 2 +-
.../Utility/ReportRetriever.cpp | 2 +-
.../Shell/Expr/TestASanReportExprNoObjC.test | 22 ++++++++++++
.../Shell/Expr/TestTSanReportExprNoObjC.test | 34 +++++++++++++++++++
.../Shell/Expr/TestUBSanReportExprNoObjC.test | 24 +++++++++++++
6 files changed, 83 insertions(+), 3 deletions(-)
create mode 100644 lldb/test/Shell/Expr/TestASanReportExprNoObjC.test
create mode 100644 lldb/test/Shell/Expr/TestTSanReportExprNoObjC.test
create mode 100644 lldb/test/Shell/Expr/TestUBSanReportExprNoObjC.test
diff --git a/lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp b/lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp
index 498da3ffe5a4a..7db971556a2f0 100644
--- a/lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp
+++ b/lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp
@@ -319,7 +319,7 @@ StructuredData::ObjectSP InstrumentationRuntimeTSan::RetrieveReportData(
options.SetTimeout(process_sp->GetUtilityExpressionTimeout());
options.SetPrefix(thread_sanitizer_retrieve_report_data_prefix);
options.SetAutoApplyFixIts(false);
- options.SetLanguage(eLanguageTypeObjC_plus_plus);
+ options.SetLanguage(eLanguageTypeC);
ValueObjectSP main_value;
ExecutionContext exe_ctx;
diff --git a/lldb/source/Plugins/InstrumentationRuntime/UBSan/InstrumentationRuntimeUBSan.cpp b/lldb/source/Plugins/InstrumentationRuntime/UBSan/InstrumentationRuntimeUBSan.cpp
index 565fd353a98e5..1db85e6815636 100644
--- a/lldb/source/Plugins/InstrumentationRuntime/UBSan/InstrumentationRuntimeUBSan.cpp
+++ b/lldb/source/Plugins/InstrumentationRuntime/UBSan/InstrumentationRuntimeUBSan.cpp
@@ -124,7 +124,7 @@ StructuredData::ObjectSP InstrumentationRuntimeUBSan::RetrieveReportData(
options.SetTimeout(process_sp->GetUtilityExpressionTimeout());
options.SetPrefix(ub_sanitizer_retrieve_report_data_prefix);
options.SetAutoApplyFixIts(false);
- options.SetLanguage(eLanguageTypeObjC_plus_plus);
+ options.SetLanguage(eLanguageTypeC);
ValueObjectSP main_value;
ExecutionContext exe_ctx;
diff --git a/lldb/source/Plugins/InstrumentationRuntime/Utility/ReportRetriever.cpp b/lldb/source/Plugins/InstrumentationRuntime/Utility/ReportRetriever.cpp
index 3642cb18c7a97..85852ba40c61c 100644
--- a/lldb/source/Plugins/InstrumentationRuntime/Utility/ReportRetriever.cpp
+++ b/lldb/source/Plugins/InstrumentationRuntime/Utility/ReportRetriever.cpp
@@ -81,7 +81,7 @@ ReportRetriever::RetrieveReportData(const ProcessSP process_sp) {
options.SetTimeout(process_sp->GetUtilityExpressionTimeout());
options.SetPrefix(address_sanitizer_retrieve_report_data_prefix);
options.SetAutoApplyFixIts(false);
- options.SetLanguage(eLanguageTypeObjC_plus_plus);
+ options.SetLanguage(eLanguageTypeC);
if (auto [m, _] = GetPreferredAsanModule(process_sp->GetTarget()); m) {
SymbolContextList sc_list;
diff --git a/lldb/test/Shell/Expr/TestASanReportExprNoObjC.test b/lldb/test/Shell/Expr/TestASanReportExprNoObjC.test
new file mode 100644
index 0000000000000..6d50ca264b107
--- /dev/null
+++ b/lldb/test/Shell/Expr/TestASanReportExprNoObjC.test
@@ -0,0 +1,22 @@
+# Tests that the ASan Instrumentation Runtime's utility expression
+# runs as C (and doesn't try to find decls in the ObjC runtime).
+#
+# RUN: split-file %s %t
+# RUN: %clangxx_host -g %t/main.cpp -fsanitize=address -o %t.out
+#
+# RUN: %lldb -s %t/commands.input %t.out -o exit \
+# RUN: | FileCheck %s --implicit-check-not="AppleObjCVendor"
+
+#--- main.cpp
+
+int main() {
+ int a[5] = {0};
+
+ return a[10];
+}
+
+#--- commands.input
+log enable lldb expr
+run
+
+# CHECK: Picked c for expression evaluation.
diff --git a/lldb/test/Shell/Expr/TestTSanReportExprNoObjC.test b/lldb/test/Shell/Expr/TestTSanReportExprNoObjC.test
new file mode 100644
index 0000000000000..fe1ea3f4f28f4
--- /dev/null
+++ b/lldb/test/Shell/Expr/TestTSanReportExprNoObjC.test
@@ -0,0 +1,34 @@
+# Tests that the TSan Instrumentation Runtime's utility expression
+# runs as C (and doesn't try to find decls in the ObjC runtime).
+#
+# RUN: split-file %s %t
+# RUN: %clangxx_host -std=c++11 -g %t/main.cpp -fsanitize=thread -o %t.out
+#
+# RUN: %lldb -s %t/commands.input %t.out -o exit \
+# RUN: | FileCheck %s --implicit-check-not="AppleObjCVendor"
+
+#--- main.cpp
+
+#include <thread>
+
+char c = '\0';
+
+void f() {
+ c = 'x';
+}
+
+int main() {
+ std::thread t1(f);
+ std::thread t2(f);
+
+ t1.join();
+ t2.join();
+}
+
+#--- commands.input
+log enable lldb expr
+run
+
+# CHECK: Picked c for expression evaluation.
+
+
diff --git a/lldb/test/Shell/Expr/TestUBSanReportExprNoObjC.test b/lldb/test/Shell/Expr/TestUBSanReportExprNoObjC.test
new file mode 100644
index 0000000000000..39fb9b41a5fed
--- /dev/null
+++ b/lldb/test/Shell/Expr/TestUBSanReportExprNoObjC.test
@@ -0,0 +1,24 @@
+# Tests that the UBSan Instrumentation Runtime's utility expression
+# runs as C (and doesn't try to find decls in the ObjC runtime).
+# Tests that the UBSan Instrumentation Runtime's utility expression
+# runs as C (and doesn't try to find decls in the ObjC runtime).
+#
+# RUN: split-file %s %t
+# RUN: %clangxx_host -g %t/main.cpp -fsanitize=undefined -o %t.out
+#
+# RUN: %lldb -s %t/commands.input %t.out -o exit \
+# RUN: | FileCheck %s --implicit-check-not="AppleObjCVendor"
+
+#--- main.cpp
+
+int main() {
+ int *p = nullptr;
+
+ return *p;
+}
+
+#--- commands.input
+log enable lldb expr
+run
+
+# CHECK: Picked c for expression evaluation.
More information about the lldb-commits
mailing list