[Lldb-commits] [lldb] 26ff166 - [lldb][ClangExpressionParser] Emit more accurate language note for Objective-C++ fallback (#172047)
via lldb-commits
lldb-commits at lists.llvm.org
Fri Dec 12 09:43:01 PST 2025
Author: Michael Buch
Date: 2025-12-12T17:42:58Z
New Revision: 26ff16663777fc995e8c6b46fa2433610dab4f64
URL: https://github.com/llvm/llvm-project/commit/26ff16663777fc995e8c6b46fa2433610dab4f64
DIFF: https://github.com/llvm/llvm-project/commit/26ff16663777fc995e8c6b46fa2433610dab4f64.diff
LOG: [lldb][ClangExpressionParser] Emit more accurate language note for Objective-C++ fallback (#172047)
We fall back to `Objective-C++` when running C++ expressions in frames
that don't have debug-info. But we were missing a fallback note for this
situation. We would now print following note on expression error:
```
note: Possibly stopped inside system library, so speculatively enabled Objective-C. Ran expression as 'Objective C++'.
```
Added:
lldb/test/Shell/Expr/TestExprLanguageNote_NoDebug.cpp
Modified:
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
Removed:
################################################################################
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index bae3c44e333b6..eb47082a70552 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -607,15 +607,21 @@ static void SetupLangOpts(CompilerInstance &compiler,
lang_opts.CPlusPlus11 = true;
compiler.getHeaderSearchOpts().UseLibcxx = true;
[[fallthrough]];
- case lldb::eLanguageTypeC_plus_plus_03:
+ case lldb::eLanguageTypeC_plus_plus_03: {
lang_opts.CPlusPlus = true;
if (process_sp
// We're stopped in a frame without debug-info. The user probably
// intends to make global queries (which should include Objective-C).
- && !(frame_sp && frame_sp->HasDebugInformation()))
+ && !(frame_sp && frame_sp->HasDebugInformation())) {
lang_opts.ObjC =
process_sp->GetLanguageRuntime(lldb::eLanguageTypeObjC) != nullptr;
- break;
+ if (lang_opts.ObjC) {
+ language_for_note = lldb::eLanguageTypeObjC_plus_plus;
+ language_fallback_reason = "Possibly stopped inside system library, so "
+ "speculatively enabled Objective-C. ";
+ }
+ }
+ } break;
case lldb::eLanguageTypeObjC_plus_plus:
case lldb::eLanguageTypeUnknown:
default:
diff --git a/lldb/test/Shell/Expr/TestExprLanguageNote_NoDebug.cpp b/lldb/test/Shell/Expr/TestExprLanguageNote_NoDebug.cpp
new file mode 100644
index 0000000000000..61d36867d001c
--- /dev/null
+++ b/lldb/test/Shell/Expr/TestExprLanguageNote_NoDebug.cpp
@@ -0,0 +1,19 @@
+// REQUIRES: system-darwin
+//
+// Tests the language fall back diagnostic for when we fall back to
+// Objective-C++ when stopped in frames with no debug-info.
+//
+// RUN: %clangxx_host %s -o %t.out
+//
+// RUN: %lldb %t.out \
+// RUN: -o "b main" \
+// RUN: -o run \
+// RUN: -o "expr --language c++ -- blah" -o quit 2>&1 | FileCheck %s
+
+// CHECK: (lldb) expr
+// CHECK: note: Possibly stopped inside system library, so speculatively enabled Objective-C. Ran expression as 'Objective C++'.
+
+int main() {
+ int x = 10;
+ return x;
+}
More information about the lldb-commits
mailing list