aboutsummaryrefslogtreecommitdiff
path: root/lldb
diff options
context:
space:
mode:
authorMichael Buch <michaelbuch12@gmail.com>2024-06-18 18:04:03 +0100
committerMichael Buch <michaelbuch12@gmail.com>2024-06-21 20:35:30 +0100
commit9e6ea387c877a50394aca4b02f18a05e88cf2690 (patch)
tree588f271eda215831f48b13b5ab95287162224632 /lldb
parentad393151d30d573b14c0d5d6009deb971c2f3f85 (diff)
downloadllvm-9e6ea387c877a50394aca4b02f18a05e88cf2690.zip
llvm-9e6ea387c877a50394aca4b02f18a05e88cf2690.tar.gz
llvm-9e6ea387c877a50394aca4b02f18a05e88cf2690.tar.bz2
Reland "[lldb][ObjC] Don't query objective-c runtime for decls in C++ contexts"
This relands https://github.com/llvm/llvm-project/pull/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
Diffstat (limited to 'lldb')
-rw-r--r--lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp2
-rw-r--r--lldb/test/API/lang/objcxx/objc-from-cpp-frames-without-debuginfo/TestObjCFromCppFramesWithoutDebugInfo.py7
-rw-r--r--lldb/test/API/macosx/early-process-launch/TestEarlyProcessLaunch.py4
-rw-r--r--lldb/test/Shell/Expr/TestObjCInCXXContext.test21
4 files changed, 31 insertions, 3 deletions
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
index 82a7a2c..1fdd272 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -637,7 +637,7 @@ void ClangASTSource::FindExternalVisibleDecls(
FindDeclInModules(context, name);
}
- if (!context.m_found_type) {
+ if (!context.m_found_type && m_ast_context->getLangOpts().ObjC) {
FindDeclInObjCRuntime(context, name);
}
}
diff --git a/lldb/test/API/lang/objcxx/objc-from-cpp-frames-without-debuginfo/TestObjCFromCppFramesWithoutDebugInfo.py b/lldb/test/API/lang/objcxx/objc-from-cpp-frames-without-debuginfo/TestObjCFromCppFramesWithoutDebugInfo.py
index ef8d554..497c0dd 100644
--- a/lldb/test/API/lang/objcxx/objc-from-cpp-frames-without-debuginfo/TestObjCFromCppFramesWithoutDebugInfo.py
+++ b/lldb/test/API/lang/objcxx/objc-from-cpp-frames-without-debuginfo/TestObjCFromCppFramesWithoutDebugInfo.py
@@ -15,4 +15,11 @@ class TestObjCFromCppFramesWithoutDebugInfo(TestBase):
(_, process, _, _) = lldbutil.run_to_name_breakpoint(self, "main")
self.assertState(process.GetState(), lldb.eStateStopped)
+
+ # Tests that we can use builtin Objective-C identifiers.
self.expect("expr id", error=False)
+
+ # Tests that we can lookup Objective-C decls in the ObjC runtime plugin.
+ self.expect_expr(
+ "NSString *c; c == nullptr", result_value="true", result_type="bool"
+ )
diff --git a/lldb/test/API/macosx/early-process-launch/TestEarlyProcessLaunch.py b/lldb/test/API/macosx/early-process-launch/TestEarlyProcessLaunch.py
index 32a7bc8..c15abba 100644
--- a/lldb/test/API/macosx/early-process-launch/TestEarlyProcessLaunch.py
+++ b/lldb/test/API/macosx/early-process-launch/TestEarlyProcessLaunch.py
@@ -38,14 +38,14 @@ class TestEarlyProcessLaunch(TestBase):
logfile_early = os.path.join(self.getBuildDir(), "types-log-early.txt")
self.addTearDownHook(lambda: self.runCmd("log disable lldb types"))
self.runCmd("log enable -f %s lldb types" % logfile_early)
- self.runCmd("expression global = 15")
+ self.runCmd("expression --language objc -- global = 15")
err = process.Continue()
self.assertTrue(err.Success())
logfile_later = os.path.join(self.getBuildDir(), "types-log-later.txt")
self.runCmd("log enable -f %s lldb types" % logfile_later)
- self.runCmd("expression global = 25")
+ self.runCmd("expression --language objc -- global = 25")
self.assertTrue(os.path.exists(logfile_early))
self.assertTrue(os.path.exists(logfile_later))
diff --git a/lldb/test/Shell/Expr/TestObjCInCXXContext.test b/lldb/test/Shell/Expr/TestObjCInCXXContext.test
new file mode 100644
index 0000000..8537799
--- /dev/null
+++ b/lldb/test/Shell/Expr/TestObjCInCXXContext.test
@@ -0,0 +1,21 @@
+// UNSUPPORTED: system-linux, system-windows
+
+// Tests that we don't consult the the Objective-C runtime
+// plugin when in a purely C++ context.
+//
+// RUN: %clangxx_host %p/Inputs/objc-cast.cpp -g -o %t
+// RUN: %lldb %t \
+// RUN: -o "b main" -o run \
+// RUN: -o "expression --language objective-c -- NSString * a; a" \
+// RUN: -o "expression --language objective-c++ -- NSString * b; b" \
+// RUN: -o "expression NSString" \
+// RUN: 2>&1 | FileCheck %s
+
+// CHECK: (lldb) expression --language objective-c -- NSString * a; a
+// CHECK-NEXT: (NSString *){{.*}}= nil
+
+// CHECK: (lldb) expression --language objective-c++ -- NSString * b; b
+// CHECK-NEXT: (NSString *){{.*}}= nil
+
+// CHECK: (lldb) expression NSString
+// CHECK-NEXT: error:{{.*}} use of undeclared identifier 'NSString'