[Lldb-commits] [PATCH] D90318: Return actual type from SBType::GetArrayElementType

Andy Yankovsky via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Oct 28 10:11:28 PDT 2020


werat created this revision.
werat added reviewers: teemperor, jarin.
Herald added a reviewer: JDevlieghere.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.
werat requested review of this revision.

`SBType::GetArrayElementType` should return the actual type, not the canonical type (e.g. `int32_t`, not the underlying `int`).

Added a test case to validate the new behavior. I also ran all other tests on Linux (`ninja check-lldb`), they all pass.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90318

Files:
  lldb/source/API/SBType.cpp
  lldb/test/API/python_api/type/TestTypeList.py
  lldb/test/API/python_api/type/main.cpp


Index: lldb/test/API/python_api/type/main.cpp
===================================================================
--- lldb/test/API/python_api/type/main.cpp
+++ lldb/test/API/python_api/type/main.cpp
@@ -56,5 +56,8 @@
     // This corresponds to an empty task list.
     Task *empty_task_head = new Task(-1, NULL);
 
+    typedef int myint;
+    myint myint_arr[] = {1, 2, 3};
+
     return 0; // Break at this line
 }
Index: lldb/test/API/python_api/type/TestTypeList.py
===================================================================
--- lldb/test/API/python_api/type/TestTypeList.py
+++ lldb/test/API/python_api/type/TestTypeList.py
@@ -131,3 +131,16 @@
         # (lldb-enumerations.h).
         int_type = id_type.GetBasicType(lldb.eBasicTypeInt)
         self.assertTrue(id_type == int_type)
+
+        # Find 'myint_arr' and check the array element type.
+        myint_arr = frame0.FindVariable('myint_arr')
+        self.assertTrue(myint_arr, VALID_VARIABLE)
+        self.DebugSBValue(myint_arr)
+        myint_arr_type = myint_arr.GetType()
+        self.DebugSBType(myint_arr_type)
+        self.assertTrue(myint_arr_type.IsArrayType())
+        myint_arr_element_type = myint_arr_type.GetArrayElementType()
+        self.DebugSBType(myint_arr_element_type)
+        myint_type = target.FindFirstType('myint')
+        self.DebugSBType(myint_type)
+        self.assertTrue(myint_arr_element_type == myint_type)
Index: lldb/source/API/SBType.cpp
===================================================================
--- lldb/source/API/SBType.cpp
+++ lldb/source/API/SBType.cpp
@@ -212,10 +212,8 @@
 
   if (!IsValid())
     return LLDB_RECORD_RESULT(SBType());
-  CompilerType canonical_type =
-      m_opaque_sp->GetCompilerType(true).GetCanonicalType();
-  return LLDB_RECORD_RESULT(SBType(
-      TypeImplSP(new TypeImpl(canonical_type.GetArrayElementType(nullptr)))));
+  return LLDB_RECORD_RESULT(SBType(TypeImplSP(new TypeImpl(
+      m_opaque_sp->GetCompilerType(true).GetArrayElementType(nullptr)))));
 }
 
 SBType SBType::GetArrayType(uint64_t size) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90318.301321.patch
Type: text/x-patch
Size: 2075 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20201028/8931b0db/attachment.bin>


More information about the lldb-commits mailing list