[Lldb-commits] [lldb] r360929 - Make sure GetObjectDescription falls back to the Objective-C runtime.
Adrian Prantl via lldb-commits
lldb-commits at lists.llvm.org
Thu May 16 12:21:31 PDT 2019
Author: adrian
Date: Thu May 16 12:21:31 2019
New Revision: 360929
URL: http://llvm.org/viewvc/llvm-project?rev=360929&view=rev
Log:
Make sure GetObjectDescription falls back to the Objective-C runtime.
This fixes an unintended regression introduced by
https://reviews.llvm.org/D61451 by making sure the Objective-C runtime
is also tried when the "correct" language runtime failed to return an
object description.
rdar://problem/50791055
Differential Revision: https://reviews.llvm.org/D62015
Added:
lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/
lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/Makefile
lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/TestObjCXXBridgedPO.py
lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/main.mm
Modified:
lldb/trunk/source/Core/ValueObject.cpp
Added: lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/Makefile?rev=360929&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/Makefile (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/Makefile Thu May 16 12:21:31 2019
@@ -0,0 +1,6 @@
+LEVEL = ../../../make
+
+OBJCXX_SOURCES := main.mm
+LDFLAGS = $(CFLAGS) -lobjc -framework CoreFoundation
+
+include $(LEVEL)/Makefile.rules
Added: lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/TestObjCXXBridgedPO.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/TestObjCXXBridgedPO.py?rev=360929&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/TestObjCXXBridgedPO.py (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/TestObjCXXBridgedPO.py Thu May 16 12:21:31 2019
@@ -0,0 +1,24 @@
+import lldb
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.decorators import *
+import lldbsuite.test.lldbutil as lldbutil
+
+class TestObjCXXBridgedPO(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ def setUp(self):
+ TestBase.setUp(self)
+
+ @skipUnlessDarwin
+ def test_bridged_type_po(self):
+ self.build()
+ lldbutil.run_to_source_breakpoint(
+ self, 'break here', lldb.SBFileSpec('main.mm'))
+ self.expect('po num',
+ "did not get the Objective-C object description",
+ substrs=['CFNumber', '0x', '42'])
+ pointer_val = str(self.frame().FindVariable('num').GetValue())
+ self.expect('po '+pointer_val,
+ "did not get the Objective-C object description",
+ substrs=['CFNumber', '0x', '42'])
Added: lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/main.mm
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/main.mm?rev=360929&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/main.mm (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/main.mm Thu May 16 12:21:31 2019
@@ -0,0 +1,12 @@
+#include <CoreFoundation/CoreFoundation.h>
+
+void stop() {}
+
+int main(int argc, char **argv)
+{
+ int value = 42;
+ CFNumberRef num;
+ num = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &value);
+ stop(); // break here
+ return 0;
+}
Modified: lldb/trunk/source/Core/ValueObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=360929&r1=360928&r2=360929&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObject.cpp (original)
+++ lldb/trunk/source/Core/ValueObject.cpp Thu May 16 12:21:31 2019
@@ -1086,44 +1086,46 @@ std::pair<TypeValidatorResult, std::stri
}
const char *ValueObject::GetObjectDescription() {
-
if (!UpdateValueIfNeeded(true))
- return NULL;
+ return nullptr;
+ // Return cached value.
if (!m_object_desc_str.empty())
return m_object_desc_str.c_str();
ExecutionContext exe_ctx(GetExecutionContextRef());
Process *process = exe_ctx.GetProcessPtr();
- if (process == NULL)
- return NULL;
-
- StreamString s;
-
- LanguageType language = GetObjectRuntimeLanguage();
- LanguageRuntime *runtime = process->GetLanguageRuntime(language);
+ if (!process)
+ return nullptr;
- if (runtime == NULL) {
- // Aw, hell, if the things a pointer, or even just an integer, let's try
- // ObjC anyway...
- CompilerType compiler_type = GetCompilerType();
- if (compiler_type) {
- bool is_signed;
- if (compiler_type.IsIntegerType(is_signed) ||
- compiler_type.IsPointerType()) {
- runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
+ // Returns the object description produced by one language runtime.
+ auto get_object_description = [&](LanguageType language) -> const char * {
+ if (LanguageRuntime *runtime = process->GetLanguageRuntime(language)) {
+ StreamString s;
+ if (runtime->GetObjectDescription(s, *this)) {
+ m_object_desc_str.append(s.GetString());
+ return m_object_desc_str.c_str();
}
}
- }
+ return nullptr;
+ };
- if (runtime && runtime->GetObjectDescription(s, *this)) {
- m_object_desc_str.append(s.GetString());
+ // Try the native language runtime first.
+ LanguageType native_language = GetObjectRuntimeLanguage();
+ if (const char *desc = get_object_description(native_language))
+ return desc;
+
+ switch (native_language) {
+ case eLanguageTypeC:
+ case eLanguageTypeC_plus_plus:
+ case eLanguageTypeObjC:
+ case eLanguageTypeObjC_plus_plus:
+ // Try the Objective-C language runtime. This fallback is necessary
+ // for Objective-C++ and mixed Objective-C / C++ programs.
+ return get_object_description(eLanguageTypeObjC);
+ default:
+ return nullptr;
}
-
- if (m_object_desc_str.empty())
- return NULL;
- else
- return m_object_desc_str.c_str();
}
bool ValueObject::GetValueAsCString(const lldb_private::TypeFormatImpl &format,
More information about the lldb-commits
mailing list