diff --git a/lldb/examples/synthetic/gnu_libstdcpp.py b/lldb/examples/synthetic/gnu_libstdcpp.py --- a/lldb/examples/synthetic/gnu_libstdcpp.py +++ b/lldb/examples/synthetic/gnu_libstdcpp.py @@ -8,6 +8,108 @@ # 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): + 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: + self.impl = self.valobj.GetChildMemberWithName('_M_impl') + self.start = self.impl.GetChildMemberWithName("_M_start") + self.start_cur = self.start.GetChildMemberWithName('_M_cur') + self.start_cur_val = self.start_cur.GetValueAsUnsigned(0) + self.start_first = self.start.GetChildMemberWithName('_M_first') + self.start_last = self.start.GetChildMemberWithName('_M_last') + self.start_node = self.start.GetChildMemberWithName("_M_node") + self.start_node_val = self.start_node.GetValueAsUnsigned(0) + self.finish = self.impl.GetChildMemberWithName("_M_finish") + self.finish_cur = self.finish.GetChildMemberWithName('_M_cur') + self.finish_last = self.finish.GetChildMemberWithName('_M_last') + self.finish_first = self.finish.GetChildMemberWithName('_M_first') + self.finish_node = self.finish.GetChildMemberWithName('_M_node') + self.data_type = self.valobj.GetType().GetUnqualifiedType().GetTemplateArgumentType(0) + self.data_size = self.data_type.GetByteSize() + except: + pass + return False + + def get_child_index(self, name): + try: + return int(name.lstrip('[').rstrip(']')) + except: + return -1 + + # def set_node(self): + # try: + # self.start_node = self.start.GetChildMemberWithName("_M_node") + # print("Self_node: " + str(self.start_node)) + # self.start_node_data = self.start_node.GetData() + # print("Self_node_data: " + str(self.start_node_data)) + # self.start_node_data = self.start_node_data + 8 + # print("Next self_node_data: " + str(self.start_node_data)) + # except: + # print("Cannot set node") + # return None + + + + def get_child_at_index(self, index): + 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 + # # while offset > 0: + # while self.start_cur_val != self.start_last.GetValueAsUnsigned(0): + # self.start_cur_val = self.start_cur_val + self.data_size + # print("Reached end") + return self.start_cur.CreateChildAtOffset( '[' + str(index) + ']', offset, self.data_type) + # self.set_node() + return 0 + + except: + print("Cannot get chid") + logger >> "Cannot get child" + return None + + + def num_children(self): + if self.count is None: + self.count = self.num_children_impl() + return self.count + + def num_children_impl(self): + logger = lldb.formatters.Logger.Logger() + start_node = self.start.GetChildMemberWithName('_M_node') + start_node_val = start_node.GetValueAsUnsigned(0) + start_last_val = self.start_last.GetValueAsUnsigned(0) + start_cur_val = self.start_cur.GetValueAsUnsigned(0) + finish_node = self.finish.GetChildMemberWithName('_M_node') + finish_node_val = finish_node.GetValueAsUnsigned(0) + finish_cur_val = self.finish_cur.GetValueAsUnsigned(0) + finish_first_val = self.finish_first.GetValueAsUnsigned(0) + + + node_size = start_node.GetType().GetByteSize() + print("Node size: " + str(node_size)) + + try: + size = (512 / self.data_size) * ((finish_node_val - start_node_val)//int(node_size) - int(finish_node_val != 0)) \ + + (finish_cur_val - finish_first_val)//self.data_size \ + + (start_last_val - start_cur_val)//self.data_size + return size + except: + logger >> "Could not determine the size" + return 0 + + class AbstractListSynthProvider: def __init__(self, valobj, dict, has_prev): diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp --- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp +++ b/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(