Skip to content

Commit 26ff166

Browse files
authored
[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++'. ```
1 parent b8816a4 commit 26ff166

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
@@ -607,15 +607,21 @@ static void SetupLangOpts(CompilerInstance &compiler,
607607
lang_opts.CPlusPlus11 = true;
608608
compiler.getHeaderSearchOpts().UseLibcxx = true;
609609
[[fallthrough]];
610-
case lldb::eLanguageTypeC_plus_plus_03:
610+
case lldb::eLanguageTypeC_plus_plus_03: {
611611
lang_opts.CPlusPlus = true;
612612
if (process_sp
613613
// We're stopped in a frame without debug-info. The user probably
614614
// intends to make global queries (which should include Objective-C).
615-
&& !(frame_sp && frame_sp->HasDebugInformation()))
615+
&& !(frame_sp && frame_sp->HasDebugInformation())) {
616616
lang_opts.ObjC =
617617
process_sp->GetLanguageRuntime(lldb::eLanguageTypeObjC) != nullptr;
618-
break;
618+
if (lang_opts.ObjC) {
619+
language_for_note = lldb::eLanguageTypeObjC_plus_plus;
620+
language_fallback_reason = "Possibly stopped inside system library, so "
621+
"speculatively enabled Objective-C. ";
622+
}
623+
}
624+
} break;
619625
case lldb::eLanguageTypeObjC_plus_plus:
620626
case lldb::eLanguageTypeUnknown:
621627
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)