danilashtefan created this revision.
danilashtefan requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114008

Files:
  lldb/examples/synthetic/gnu_libstdcpp.py
  lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp

Index: lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
===================================================================
--- lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -918,6 +918,11 @@
       SyntheticChildrenSP(new ScriptedSyntheticChildren(
           stl_deref_flags,
           "lldb.formatters.cpp.gnu_libstdcpp.StdMapLikeSynthProvider")));
+  cpp_category_sp->GetRegexTypeSyntheticsContainer()->Add(
+      RegularExpression("^std::deque<.+>(( )?&)?$"),
+      SyntheticChildrenSP(new ScriptedSyntheticChildren(
+          stl_deref_flags,
+          "lldb.formatters.cpp.gnu_libstdcpp.StdDequeSynthProvider")));
   cpp_category_sp->GetRegexTypeSyntheticsContainer()->Add(
       RegularExpression("^std::(__cxx11::)?list<.+>(( )?&)?$"),
       SyntheticChildrenSP(new ScriptedSyntheticChildren(
@@ -946,6 +951,10 @@
       RegularExpression("^std::set<.+> >(( )?&)?$"),
       TypeSummaryImplSP(
           new StringSummaryFormat(stl_summary_flags, "size=${svar%#}")));
+  cpp_category_sp->GetRegexTypeSummariesContainer()->Add(
+      RegularExpression("^std::deque<.+>(( )?&)?$"),
+      TypeSummaryImplSP(
+          new StringSummaryFormat(stl_summary_flags, "size=${svar%#}")));
   cpp_category_sp->GetRegexTypeSummariesContainer()->Add(
       RegularExpression("^std::multimap<.+> >(( )?&)?$"),
       TypeSummaryImplSP(
Index: lldb/examples/synthetic/gnu_libstdcpp.py
===================================================================
--- lldb/examples/synthetic/gnu_libstdcpp.py
+++ lldb/examples/synthetic/gnu_libstdcpp.py
@@ -8,6 +8,80 @@
 # You are encouraged to look at the STL implementation for your platform
 # before relying on these formatters to do the right thing for your setup
 
+class StdDequeSynthProvider:
+    def __init__(self, valobj, dict):
+        print("Init called")
+        self.valobj = valobj
+        self.count = None
+
+    def update(self):
+        # preemptively setting this to None - we might end up changing our mind
+        # later
+        self.count = None
+        try:
+            print("Update called")
+            self.impl = self.valobj.GetChildMemberWithName('_M_impl')
+            self.start  = self.impl.GetChildMemberWithName("_M_start")
+            self.start_cur = self.start.GetChildMemberWithName('_M_cur')
+            self.finish = self.impl.GetChildMemberWithName("_M_finish")
+            self.finish_cur = self.finish.GetChildMemberWithName('_M_cur')
+            self.data_type = self.valobj.GetType().GetUnqualifiedType().GetTemplateArgumentType(0)
+            self.data_size = self.data_type.GetByteSize()
+        except:
+            pass
+
+    def get_child_index(self, name):
+        try:
+            return int(name.lstrip('[').rstrip(']'))
+        except:
+            return -1
+
+    def get_child_at_index(self, index):
+        print("Get child at index called")
+        logger = lldb.formatters.Logger.Logger()
+        logger >> "Being asked to fetch child[" + str(index) + "]"
+        if index < 0:
+            return None
+        if index >= self.num_children():
+            return None
+        try:
+            offset = index * self.data_size
+            return self.start_cur.CreateChildAtOffset( '[' + str(index) + ']', offset, self.data_type)
+        except:
+            logger >> "Cannot get child"
+            return None
+    
+    def num_children(self):
+        print("Number of children called")
+        if self.count is None:
+            self.count = self.num_children_impl()
+        return self.count
+    
+    def num_children_impl(self):
+        # logger = lldb.formatters.Logger.Logger()
+        # try:
+        #     start_val = self.start_cur.GetValueAsUnsigned(0)
+        #     print("Start value is: " + str(start_val))
+        #     finish_val = self.finish_cur.GetValueAsUnsigned(0)
+        #     print("Finish value is: " + str(finish_val))
+        #     if start_val == 0 or finish_val == 0:
+        #         print("Start of Finish val's are 0")
+        #         return 0
+        #     if start_val >= finish_val:
+        #         print("Start is greater than finish")
+        #         return 0
+
+        #     num_children = (finish_val - start_val)
+        #     if (num_children % self.data_size) != 0:
+        #             return 0
+        #     else:
+        #         num_children = num_children // self.data_size
+        #     return num_children
+        # except:
+        #     print("Cannot determine the size")
+        #     logger >> "Could not determine the size"
+        #     return 0
+        return 4
 
 class AbstractListSynthProvider:
     def __init__(self, valobj, dict, has_prev):
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to