https://github.com/Michael137 created 
https://github.com/llvm/llvm-project/pull/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++'.
```

>From f42a57267c3d55d5901114d797b7fa35bb1e98d1 Mon Sep 17 00:00:00 2001
From: Michael Buch <[email protected]>
Date: Fri, 12 Dec 2025 16:34:38 +0000
Subject: [PATCH] [lldb][ClangExpressionParser] Emit more accurate language
 note for Objective-C++ fallback

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++'.
```
---
 .../Clang/ClangExpressionParser.cpp           | 12 +++++++++---
 .../Expr/TestExprLanguageNote_NoDebug.cpp     | 19 +++++++++++++++++++
 2 files changed, 28 insertions(+), 3 deletions(-)
 create mode 100644 lldb/test/Shell/Expr/TestExprLanguageNote_NoDebug.cpp

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;
+}

_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to