[Lldb-commits] [PATCH] D62015: Make sure GetObjectDescription falls back to the Objective-C runtime.

2019-05-16 Thread Phabricator via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rLLDB360929: Make sure GetObjectDescription falls back to the 
Objective-C runtime. (authored by adrian, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D62015?vs=199862&id=199883#toc

Repository:
  rLLDB LLDB

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62015/new/

https://reviews.llvm.org/D62015

Files:
  packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/Makefile
  
packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/TestObjCXXBridgedPO.py
  packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/main.mm
  source/Core/ValueObject.cpp

Index: source/Core/ValueObject.cpp
===
--- source/Core/ValueObject.cpp
+++ source/Core/ValueObject.cpp
@@ -1086,44 +1086,46 @@
 }
 
 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,
Index: packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/Makefile
===
--- packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/Makefile
+++ packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/Makefile
@@ -0,0 +1,6 @@
+LEVEL = ../../../make
+
+OBJCXX_SOURCES := main.mm
+LDFLAGS = $(CFLAGS) -lobjc -framework CoreFoundation
+
+include $(LEVEL)/Makefile.rules
Index: packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/main.mm
===
--- packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/main.mm
+++ packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/main.mm
@@ -0,0 +1,12 @@
+#include 
+
+void stop() {}
+
+int main(int argc, char **argv)
+{
+  int value = 42;
+  CFNumberRef num;
+  num = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &value);
+  stop(); // break here
+  return 0;
+}
Index: packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/TestObjCXXBridgedPO.py
===
--- packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/TestObjCXXBridgedPO.py
+++ packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/TestObjCXXBridgedPO.py
@@ -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 

[Lldb-commits] [PATCH] D62015: Make sure GetObjectDescription falls back to the Objective-C runtime.

2019-05-16 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl updated this revision to Diff 199862.
aprantl added a comment.

Added test for raw pointer values.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62015/new/

https://reviews.llvm.org/D62015

Files:
  lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/Makefile
  
lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/TestObjCXXBridgedPO.py
  lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/main.mm
  lldb/source/Core/ValueObject.cpp

Index: lldb/source/Core/ValueObject.cpp
===
--- lldb/source/Core/ValueObject.cpp
+++ lldb/source/Core/ValueObject.cpp
@@ -1086,44 +1086,46 @@
 }
 
 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;
+  };
+
+  // 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 (runtime && runtime->GetObjectDescription(s, *this)) {
-m_object_desc_str.append(s.GetString());
-  }
-
-  if (m_object_desc_str.empty())
-return NULL;
-  else
-return m_object_desc_str.c_str();
 }
 
 bool ValueObject::GetValueAsCString(const lldb_private::TypeFormatImpl &format,
Index: lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/main.mm
===
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/main.mm
@@ -0,0 +1,12 @@
+#include 
+
+void stop() {}
+
+int main(int argc, char **argv)
+{
+  int value = 42;
+  CFNumberRef num;
+  num = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &value);
+  stop(); // break here
+  return 0;
+}
Index: lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/TestObjCXXBridgedPO.py
===
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/TestObjCXXBridgedPO.py
@@ -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'])
Index: lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/Makefile
===
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/Makefile
@@ -0,0 +1,6 @@
+LEVEL = ../../../make
+
+OBJCXX_SOURCES := main.mm
+LDFLAGS = $(CFLAGS) -lobjc -framework CoreFoundation
+
+include $(LEVEL)/Makefile.rules

[Lldb-commits] [PATCH] D62015: Make sure GetObjectDescription falls back to the Objective-C runtime.

2019-05-16 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl updated this revision to Diff 199860.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62015/new/

https://reviews.llvm.org/D62015

Files:
  lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/Makefile
  
lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/TestObjCXXBridgedPO.py
  lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/main.mm
  lldb/source/Core/ValueObject.cpp

Index: lldb/source/Core/ValueObject.cpp
===
--- lldb/source/Core/ValueObject.cpp
+++ lldb/source/Core/ValueObject.cpp
@@ -1086,44 +1086,46 @@
 }
 
 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;
+  };
+
+  // Try the native language runtime first.
+  LanguageType native_language = GetObjectRuntimeLanguage();
+  if (const char *desc = get_object_description(native_language))
+return desc;
+
+  switch (native_language) {
+  eLanguageTypeC:
+  eLanguageTypeC_plus_plus:
+  eLanguageTypeObjC:
+  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 (runtime && runtime->GetObjectDescription(s, *this)) {
-m_object_desc_str.append(s.GetString());
-  }
-
-  if (m_object_desc_str.empty())
-return NULL;
-  else
-return m_object_desc_str.c_str();
 }
 
 bool ValueObject::GetValueAsCString(const lldb_private::TypeFormatImpl &format,
Index: lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/main.mm
===
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/main.mm
@@ -0,0 +1,12 @@
+#include 
+
+void stop() {}
+
+int main(int argc, char **argv)
+{
+  int value = 42;
+  CFNumberRef num;
+  num = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &value);
+  stop(); // break here
+  return 0;
+}
Index: lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/TestObjCXXBridgedPO.py
===
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/TestObjCXXBridgedPO.py
@@ -0,0 +1,20 @@
+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', "got an Objective-C object description",
+substrs=['CFNumber', '0x', '42'])
+
Index: lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/Makefile
===
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/Makefile
@@ -0,0 +1,6 @@
+LEVEL = ../../../make
+
+OBJCXX_SOURCES := main.mm
+LDFLAGS = $(CFLAGS) -lobjc -framework CoreFoundation
+
+include $(LEVEL)/Makefile.rules
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D62015: Make sure GetObjectDescription falls back to the Objective-C runtime.

2019-05-16 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl updated this revision to Diff 199859.
aprantl added a comment.

Address review feedback.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62015/new/

https://reviews.llvm.org/D62015

Files:
  lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/Makefile
  
lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/TestObjCXXBridgedPO.py
  lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/main.mm
  lldb/source/Core/ValueObject.cpp

Index: lldb/source/Core/ValueObject.cpp
===
--- lldb/source/Core/ValueObject.cpp
+++ lldb/source/Core/ValueObject.cpp
@@ -1086,44 +1086,45 @@
 }
 
 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;
+  };
+
+  // Try the native language runtime first.
+  if (const char *desc = get_object_description(GetObjectRuntimeLanguage()))
+return desc;
+
+  switch (language) {
+  eLanguageTypeC:
+  eLanguageTypeC_plus_plus:
+  eLanguageTypeObjC:
+  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 (runtime && runtime->GetObjectDescription(s, *this)) {
-m_object_desc_str.append(s.GetString());
-  }
-
-  if (m_object_desc_str.empty())
-return NULL;
-  else
-return m_object_desc_str.c_str();
 }
 
 bool ValueObject::GetValueAsCString(const lldb_private::TypeFormatImpl &format,
Index: lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/main.mm
===
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/main.mm
@@ -0,0 +1,12 @@
+#include 
+
+void stop() {}
+
+int main(int argc, char **argv)
+{
+  int value = 42;
+  CFNumberRef num;
+  num = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &value);
+  stop(); // break here
+  return 0;
+}
Index: lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/TestObjCXXBridgedPO.py
===
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/TestObjCXXBridgedPO.py
@@ -0,0 +1,20 @@
+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', "got an Objective-C object description",
+substrs=['CFNumber', '0x', '42'])
+
Index: lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/Makefile
===
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/Makefile
@@ -0,0 +1,6 @@
+LEVEL = ../../../make
+
+OBJCXX_SOURCES := main.mm
+LDFLAGS = $(CFLAGS) -lobjc -framework CoreFoundation
+
+include $(LEVEL)/Makefile.rules
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D62015: Make sure GetObjectDescription falls back to the Objective-C runtime.

2019-05-16 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda added a comment.

My one concern is how this will work in a swift-lldb where we have a swift 
ValueObject, the print description fails, and we fall back to the ObjC print 
description.  That's a change in behavior, right?  I imagine worst case is that 
the objc print description will fail to produce anything and we'll have the 
same behavior as we do today.




Comment at: 
lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/TestObjCXXBridgedPO.py:16
+@skipIfWindows
+@skipIfNetBSD
+def test_bridged_type_po(self):

@skipUnlessDarwin


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62015/new/

https://reviews.llvm.org/D62015



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D62015: Make sure GetObjectDescription falls back to the Objective-C runtime.

2019-05-16 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl marked an inline comment as done.
aprantl added inline comments.



Comment at: lldb/source/Core/ValueObject.cpp:1112
-  bool is_signed;
-  if (compiler_type.IsIntegerType(is_signed) ||
-  compiler_type.IsPointerType()) {

This check was redundant, it is also performed by the ObjC runtime.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62015/new/

https://reviews.llvm.org/D62015



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D62015: Make sure GetObjectDescription falls back to the Objective-C runtime.

2019-05-16 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl created this revision.
aprantl added reviewers: jingham, jasonmolenda.
Herald added a project: LLDB.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D62015

Files:
  lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/Makefile
  
lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/TestObjCXXBridgedPO.py
  lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/main.mm
  lldb/source/Core/ValueObject.cpp

Index: lldb/source/Core/ValueObject.cpp
===
--- lldb/source/Core/ValueObject.cpp
+++ lldb/source/Core/ValueObject.cpp
@@ -1086,44 +1086,37 @@
 }
 
 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.
+  if (const char *desc = get_object_description(GetObjectRuntimeLanguage()))
+return desc;
 
-  if (m_object_desc_str.empty())
-return NULL;
-  else
-return m_object_desc_str.c_str();
+  // Try the Objective-C language runtime. This fallback is necessary
+  // for Objective-C++ and mixed Objective-C / C++ programs.
+  return get_object_description(eLanguageTypeObjC);
 }
 
 bool ValueObject::GetValueAsCString(const lldb_private::TypeFormatImpl &format,
Index: lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/main.mm
===
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/main.mm
@@ -0,0 +1,12 @@
+#include 
+
+void stop() {}
+
+int main(int argc, char **argv)
+{
+  int value = 42;
+  CFNumberRef num;
+  num = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &value);
+  stop(); // break here
+  return 0;
+}
Index: lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/TestObjCXXBridgedPO.py
===
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/TestObjCXXBridgedPO.py
@@ -0,0 +1,23 @@
+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)
+
+@skipIfFreeBSD
+@skipIfLinux
+@skipIfWindows
+@skipIfNetBSD
+def test_bridged_type_po(self):
+self.build()
+lldbutil.run_to_source_breakpoint(
+self, 'break here', lldb.SBFileSpec('main.mm'))
+self.expect('po num', "got an Objective-C object description",
+substrs=['CFNumber', '0x', '42'])
+
Index: lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/Makefile
===
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/lang/objcxx/cxx-bridged-po/Makefile
@@ -0,0 +1,6 @@
+LEVEL = ../../../make
+
+OBJCXX_SOURCES := main.mm
+LDFLAGS = $(CFLAGS) -lobjc -framework CoreFoundation
+
+include $(LEVEL)/Makefile.rules
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits