Skip to content

Commit f45da5d

Browse files
Michael137AlexisPerry
authored andcommitted
Reland "[lldb][ObjC] Don't query objective-c runtime for decls in C++ contexts"
This relands llvm#95963. It had to be reverted because the `TestEarlyProcessLaunch.py` test was failing on the incremental macOS bots. The test failed because it was relying on expression log output from the ObjC introspection routines (but was the expression was called from a C++ context). The relanded patch simply ensures that the test runs the expressions as `ObjC` expressions. When LLDB isn't able to find a `clang::Decl` in response to a `FindExternalVisibleDeclsByName`, it will fall-back to looking into the Objective-C runtime for that decl. This ends up doing a lot of work which isn't necessary when we're debugging a C++ program. This patch makes the ObjC lookup conditional on the language that the ExpressionParser deduced (which can be explicitly set using the `expr --language` option or is set implicitly if we're stopped in an ObjC frame or a C++ frame without debug-info). rdar://96236519
1 parent 6ada671 commit f45da5d

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ void ClangASTSource::FindExternalVisibleDecls(
637637
FindDeclInModules(context, name);
638638
}
639639

640-
if (!context.m_found_type) {
640+
if (!context.m_found_type && m_ast_context->getLangOpts().ObjC) {
641641
FindDeclInObjCRuntime(context, name);
642642
}
643643
}

lldb/test/API/lang/objcxx/objc-from-cpp-frames-without-debuginfo/TestObjCFromCppFramesWithoutDebugInfo.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,11 @@ def test(self):
1515
(_, process, _, _) = lldbutil.run_to_name_breakpoint(self, "main")
1616

1717
self.assertState(process.GetState(), lldb.eStateStopped)
18+
19+
# Tests that we can use builtin Objective-C identifiers.
1820
self.expect("expr id", error=False)
21+
22+
# Tests that we can lookup Objective-C decls in the ObjC runtime plugin.
23+
self.expect_expr(
24+
"NSString *c; c == nullptr", result_value="true", result_type="bool"
25+
)

lldb/test/API/macosx/early-process-launch/TestEarlyProcessLaunch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ def test_early_process_launch(self):
3838
logfile_early = os.path.join(self.getBuildDir(), "types-log-early.txt")
3939
self.addTearDownHook(lambda: self.runCmd("log disable lldb types"))
4040
self.runCmd("log enable -f %s lldb types" % logfile_early)
41-
self.runCmd("expression global = 15")
41+
self.runCmd("expression --language objc -- global = 15")
4242

4343
err = process.Continue()
4444
self.assertTrue(err.Success())
4545

4646
logfile_later = os.path.join(self.getBuildDir(), "types-log-later.txt")
4747
self.runCmd("log enable -f %s lldb types" % logfile_later)
48-
self.runCmd("expression global = 25")
48+
self.runCmd("expression --language objc -- global = 25")
4949

5050
self.assertTrue(os.path.exists(logfile_early))
5151
self.assertTrue(os.path.exists(logfile_later))
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// UNSUPPORTED: system-linux, system-windows
2+
3+
// Tests that we don't consult the the Objective-C runtime
4+
// plugin when in a purely C++ context.
5+
//
6+
// RUN: %clangxx_host %p/Inputs/objc-cast.cpp -g -o %t
7+
// RUN: %lldb %t \
8+
// RUN: -o "b main" -o run \
9+
// RUN: -o "expression --language objective-c -- NSString * a; a" \
10+
// RUN: -o "expression --language objective-c++ -- NSString * b; b" \
11+
// RUN: -o "expression NSString" \
12+
// RUN: 2>&1 | FileCheck %s
13+
14+
// CHECK: (lldb) expression --language objective-c -- NSString * a; a
15+
// CHECK-NEXT: (NSString *){{.*}}= nil
16+
17+
// CHECK: (lldb) expression --language objective-c++ -- NSString * b; b
18+
// CHECK-NEXT: (NSString *){{.*}}= nil
19+
20+
// CHECK: (lldb) expression NSString
21+
// CHECK-NEXT: error:{{.*}} use of undeclared identifier 'NSString'

0 commit comments

Comments
 (0)