Skip to content

Commit ae5e6a9

Browse files
committed
[lldb][ClangExpressionParser] Emit more accurate language note for Objective-C++ fallback (llvm#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++'. ``` (cherry picked from commit 26ff166)
1 parent 9f6bc46 commit ae5e6a9

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -650,15 +650,21 @@ static void SetupLangOpts(CompilerInstance &compiler,
650650
lang_opts.CPlusPlus11 = true;
651651
compiler.getHeaderSearchOpts().UseLibcxx = true;
652652
[[fallthrough]];
653-
case lldb::eLanguageTypeC_plus_plus_03:
653+
case lldb::eLanguageTypeC_plus_plus_03: {
654654
lang_opts.CPlusPlus = true;
655655
if (process_sp
656656
// We're stopped in a frame without debug-info. The user probably
657657
// intends to make global queries (which should include Objective-C).
658-
&& !(frame_sp && frame_sp->HasDebugInformation()))
658+
&& !(frame_sp && frame_sp->HasDebugInformation())) {
659659
lang_opts.ObjC =
660660
process_sp->GetLanguageRuntime(lldb::eLanguageTypeObjC) != nullptr;
661-
break;
661+
if (lang_opts.ObjC) {
662+
language_for_note = lldb::eLanguageTypeObjC_plus_plus;
663+
language_fallback_reason = "Possibly stopped inside system library, so "
664+
"speculatively enabled Objective-C. ";
665+
}
666+
}
667+
} break;
662668
case lldb::eLanguageTypeObjC_plus_plus:
663669
case lldb::eLanguageTypeUnknown:
664670
default:
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// REQUIRES: system-darwin
2+
//
3+
// Tests the language fall back diagnostic for when we fall back to
4+
// Objective-C++ when stopped in frames with no debug-info.
5+
//
6+
// RUN: %clangxx_host %s -o %t.out
7+
//
8+
// RUN: %lldb %t.out \
9+
// RUN: -o "b main" \
10+
// RUN: -o run \
11+
// RUN: -o "expr --language c++ -- blah" -o quit 2>&1 | FileCheck %s
12+
13+
// CHECK: (lldb) expr
14+
// CHECK: note: Possibly stopped inside system library, so speculatively enabled Objective-C. Ran expression as 'Objective C++'.
15+
16+
int main() {
17+
int x = 10;
18+
return x;
19+
}

0 commit comments

Comments
 (0)