[Lldb-commits] [PATCH] D114450: Improve optional formatter

walter erquinigo via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Nov 23 09:19:09 PST 2021


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

As suggested by @labath in https://reviews.llvm.org/D114403, we should
make the formatter more resilient to corrupted data. The Libcxx version
explicitly checks for engaged = 1, so we can do that as well for safety.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114450

Files:
  lldb/examples/synthetic/gnu_libstdcpp.py


Index: lldb/examples/synthetic/gnu_libstdcpp.py
===================================================================
--- lldb/examples/synthetic/gnu_libstdcpp.py
+++ lldb/examples/synthetic/gnu_libstdcpp.py
@@ -1,5 +1,4 @@
 from __future__ import division
-import re
 import lldb.formatters.Logger
 
 # C++ STL formatters for LLDB
@@ -22,14 +21,14 @@
         try:
             self.payload = self.valobj.GetChildMemberWithName('_M_payload')
             self.value = self.payload.GetChildMemberWithName('_M_payload')
-            self.count = self.payload.GetChildMemberWithName('_M_engaged').GetValueAsUnsigned(0)
+            self.has_value = self.payload.GetChildMemberWithName('_M_engaged').GetValueAsUnsigned(0) == 1
         except:
-            self.count = 0
+            self.has_value = 0
         return False
 
 
     def num_children(self):
-        return self.count
+        return 1 if self.has_value else 0
 
     def get_child_index(self, name):
         return 0


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114450.389232.patch
Type: text/x-patch
Size: 982 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20211123/c9c09597/attachment.bin>


More information about the lldb-commits mailing list