https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/172019
>From 764d04c0dca00c81e8f204073bce78befe2db45c Mon Sep 17 00:00:00 2001 From: Michael Buch <[email protected]> Date: Fri, 12 Dec 2025 15:20:20 +0000 Subject: [PATCH 1/2] [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..64d9be2f39979 --- /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="AppleObjCDeclVendor" + +#--- 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..725289d4d60b7 --- /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="AppleObjCDeclVendor" + +#--- 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..62650e329fc42 --- /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="AppleObjCDeclVendor" + +#--- main.cpp + +int main() { + int *p = nullptr; + + return *p; +} + +#--- commands.input +log enable lldb expr +run + +# CHECK: Picked c for expression evaluation. >From d91b9ef3fd24883bf6d3158df19103fe12a1f7c9 Mon Sep 17 00:00:00 2001 From: Michael Buch <[email protected]> Date: Fri, 12 Dec 2025 15:57:15 +0000 Subject: [PATCH 2/2] fixup! remove tests --- .../Shell/Expr/TestASanReportExprNoObjC.test | 22 ------------ .../Shell/Expr/TestTSanReportExprNoObjC.test | 34 ------------------- .../Shell/Expr/TestUBSanReportExprNoObjC.test | 24 ------------- 3 files changed, 80 deletions(-) delete mode 100644 lldb/test/Shell/Expr/TestASanReportExprNoObjC.test delete mode 100644 lldb/test/Shell/Expr/TestTSanReportExprNoObjC.test delete mode 100644 lldb/test/Shell/Expr/TestUBSanReportExprNoObjC.test diff --git a/lldb/test/Shell/Expr/TestASanReportExprNoObjC.test b/lldb/test/Shell/Expr/TestASanReportExprNoObjC.test deleted file mode 100644 index 64d9be2f39979..0000000000000 --- a/lldb/test/Shell/Expr/TestASanReportExprNoObjC.test +++ /dev/null @@ -1,22 +0,0 @@ -# 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="AppleObjCDeclVendor" - -#--- 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 deleted file mode 100644 index 725289d4d60b7..0000000000000 --- a/lldb/test/Shell/Expr/TestTSanReportExprNoObjC.test +++ /dev/null @@ -1,34 +0,0 @@ -# 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="AppleObjCDeclVendor" - -#--- 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 deleted file mode 100644 index 62650e329fc42..0000000000000 --- a/lldb/test/Shell/Expr/TestUBSanReportExprNoObjC.test +++ /dev/null @@ -1,24 +0,0 @@ -# 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="AppleObjCDeclVendor" - -#--- main.cpp - -int main() { - int *p = nullptr; - - return *p; -} - -#--- commands.input -log enable lldb expr -run - -# CHECK: Picked c for expression evaluation. _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
