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/D114266

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
@@ -913,6 +913,11 @@
       SyntheticChildrenSP(new ScriptedSyntheticChildren(
           stl_deref_flags,
           "lldb.formatters.cpp.gnu_libstdcpp.StdMapLikeSynthProvider")));
+  cpp_category_sp->GetRegexTypeSyntheticsContainer()->Add(
+      RegularExpression("^std::optional<.+>(( )?&)?$"),
+      SyntheticChildrenSP(new ScriptedSyntheticChildren(
+          stl_synth_flags,
+          "lldb.formatters.cpp.gnu_libstdcpp.StdOptionalSynthProvider")));
   cpp_category_sp->GetRegexTypeSyntheticsContainer()->Add(
       RegularExpression("^std::multiset<.+> >(( )?&)?$"),
       SyntheticChildrenSP(new ScriptedSyntheticChildren(
Index: lldb/examples/synthetic/gnu_libstdcpp.py
===================================================================
--- lldb/examples/synthetic/gnu_libstdcpp.py
+++ lldb/examples/synthetic/gnu_libstdcpp.py
@@ -8,6 +8,46 @@
 # 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 StdOptionalSynthProvider:
+    def __init__(self, valobj, dict):
+        self.valobj = valobj
+
+    def update(self):
+        try:
+            self.payload = self.valobj.GetChildMemberWithName('_M_payload')
+            self.engaged = self.payload.GetChildMemberWithName('_M_engaged')
+            self.payload_payload= 
self.payload.GetChildMemberWithName('_M_payload')
+        except:
+            pass
+        return False
+
+    def has_value(self):
+        logger = lldb.formatters.Logger.Logger()
+        try:
+            return self.engaged.GetValueAsUnsigned(0) == 1
+        except:
+            logger >> "Error determining engaged value"
+            return False
+
+    def num_children(self):
+        logger = lldb.formatters.Logger.Logger()
+        try:
+            num_children = 1 if self.has_value() else 0
+            return num_children
+        except:
+            logger >> "Error determining number of children"
+
+    def get_child_index(self, name):
+        try:
+            return int(name.lstrip('[').rstrip(']'))
+        except:
+            return -1
+
+    def get_child_at_index(self, index):
+        self.payload_value = 
self.payload_payload.GetChildMemberWithName("_M_value").GetValue()
+        if (self.has_value() == False):
+            pass
+        return self.payload_value
 
 class AbstractListSynthProvider:
     def __init__(self, valobj, dict, has_prev):


Index: lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
===================================================================
--- lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -913,6 +913,11 @@
       SyntheticChildrenSP(new ScriptedSyntheticChildren(
           stl_deref_flags,
           "lldb.formatters.cpp.gnu_libstdcpp.StdMapLikeSynthProvider")));
+  cpp_category_sp->GetRegexTypeSyntheticsContainer()->Add(
+      RegularExpression("^std::optional<.+>(( )?&)?$"),
+      SyntheticChildrenSP(new ScriptedSyntheticChildren(
+          stl_synth_flags,
+          "lldb.formatters.cpp.gnu_libstdcpp.StdOptionalSynthProvider")));
   cpp_category_sp->GetRegexTypeSyntheticsContainer()->Add(
       RegularExpression("^std::multiset<.+> >(( )?&)?$"),
       SyntheticChildrenSP(new ScriptedSyntheticChildren(
Index: lldb/examples/synthetic/gnu_libstdcpp.py
===================================================================
--- lldb/examples/synthetic/gnu_libstdcpp.py
+++ lldb/examples/synthetic/gnu_libstdcpp.py
@@ -8,6 +8,46 @@
 # 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 StdOptionalSynthProvider:
+    def __init__(self, valobj, dict):
+        self.valobj = valobj
+
+    def update(self):
+        try:
+            self.payload = self.valobj.GetChildMemberWithName('_M_payload')
+            self.engaged = self.payload.GetChildMemberWithName('_M_engaged')
+            self.payload_payload= self.payload.GetChildMemberWithName('_M_payload')
+        except:
+            pass
+        return False
+
+    def has_value(self):
+        logger = lldb.formatters.Logger.Logger()
+        try:
+            return self.engaged.GetValueAsUnsigned(0) == 1
+        except:
+            logger >> "Error determining engaged value"
+            return False
+
+    def num_children(self):
+        logger = lldb.formatters.Logger.Logger()
+        try:
+            num_children = 1 if self.has_value() else 0
+            return num_children
+        except:
+            logger >> "Error determining number of children"
+
+    def get_child_index(self, name):
+        try:
+            return int(name.lstrip('[').rstrip(']'))
+        except:
+            return -1
+
+    def get_child_at_index(self, index):
+        self.payload_value = self.payload_payload.GetChildMemberWithName("_M_value").GetValue()
+        if (self.has_value() == False):
+            pass
+        return self.payload_value
 
 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