WebKit Bugzilla
Attachment 358341 Details for
Bug 193024
: [lldb-webkit]: Add support for pretty-printing raw bitmask types
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
To Land
bug-193024-20190104112119.patch (text/plain), 9.42 KB, created by
Daniel Bates
on 2019-01-04 11:21:20 PST
(
hide
)
Description:
To Land
Filename:
MIME Type:
Creator:
Daniel Bates
Created:
2019-01-04 11:21:20 PST
Size:
9.42 KB
patch
obsolete
>Subversion Revision: 239624 >diff --git a/Tools/ChangeLog b/Tools/ChangeLog >index bfdc5f00d4a6babc76cb80e50894df0aa2d44691..25613b730eefbdca174fbf4e582c70ab9d493a2a 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,79 @@ >+2019-01-04 Daniel Bates <dabates@apple.com> >+ >+ [lldb-webkit]: Add support for pretty-printing raw bitmask types >+ https://bugs.webkit.org/show_bug.cgi?id=193024 >+ >+ Reviewed by Jer Noble. >+ >+ Add support infrastructure to pretty-print a raw bitmask type. Included is a pretty-printer >+ for the bitmask type WebEventFlags as an example. >+ >+ Exposed a new function lldb_webkit.addSummaryAndSyntheticFormattersForRawBitmaskType() >+ that can be used to register summary and synthetic child formatters for a bitmask type. >+ For example, consider the following enum and bitmask typedefs: >+ >+ typedef enum { >+ A = 1 << 0, >+ B = 1 << 1, >+ C = 1 << 2, >+ } SpecialFlagValues; >+ typedef unsigned SpecialFlags; >+ >+ To teach lldb-webkit how to pretty print SpecialFlags types, add the following code inside >+ __lldb_init_module(): >+ >+ addSummaryAndSyntheticFormattersForRawBitmaskType(debugger, "SpecialFlags", { >+ 1 << 0: "A", >+ 1 << 1: "B", >+ 1 << 2: "C", >+ }) >+ >+ * lldb/lldb_webkit.py: >+ (addSummaryAndSyntheticFormattersForRawBitmaskType): >+ (addSummaryAndSyntheticFormattersForRawBitmaskType.GeneratedRawBitmaskProvider): >+ (addSummaryAndSyntheticFormattersForRawBitmaskType.raw_bitmask_summary_provider): >+ (addSummaryAndSyntheticFormattersForRawBitmaskType.lldb_webkit): >+ A convenience function to dynamically creaste a synthetic formatter class and summary >+ string function for the specified bitmask type and enumerator value to name map. This >+ function register the dynamically created class and function with LLDB. >+ >+ (__lldb_init_module): >+ (FlagEnumerationProvider): >+ (FlagEnumerationProvider._enumerator_value_to_name_map): >+ (FlagEnumerationProvider._bitmask): >+ (FlagEnumerationProvider._update): >+ (FlagEnumerationProvider.has_children): >+ (FlagEnumerationProvider.num_children): >+ (FlagEnumerationProvider.get_child_index): >+ (FlagEnumerationProvider.get_child_at_index): >+ (FlagEnumerationProvider.update): >+ Extract out provider logic from WTFOptionSetProvider into a base class that can be shared. >+ >+ (WTFOptionSetProvider): >+ (WTFOptionSetProvider._enumerator_value_to_name_map): >+ (WTFOptionSetProvider._bitmask): >+ (WTFOptionSetProvider._update): >+ Write in terms of the base class. >+ >+ (RawBitmaskProviderBase): >+ (RawBitmaskProviderBase._enumerator_value_to_name_map): >+ (RawBitmaskProviderBase._bitmask): >+ Added. Base synthetic formatter class for a raw bitmask type. Derived classes are expected to >+ override the class variable ENUMERATOR_VALUE_TO_NAME_MAP with a dictionary of the form: >+ { >+ 1 << 0: "A", >+ 1 << 1: "B", >+ 1 << 2: "C", >+ } >+ It is not necessary to instantiate such a derived class directory. Instead use the convenience >+ function addSummaryAndSyntheticFormattersForRawBitmaskType. >+ >+ (WTFOptionSetProvider.has_children): Deleted. >+ (WTFOptionSetProvider.num_children): Deleted. >+ (WTFOptionSetProvider.get_child_index): Deleted. >+ (WTFOptionSetProvider.get_child_at_index): Deleted. >+ (WTFOptionSetProvider.update): Deleted. >+ > 2019-01-04 Chris Dumez <cdumez@apple.com> > > [PSON] Calling history.back() from inside the load event handler prevents process-swapping >diff --git a/Tools/lldb/lldb_webkit.py b/Tools/lldb/lldb_webkit.py >index 47e51f6a9a7d3d299ffa9aad6acb74d26d0b9d24..077a09425c541b22a1c61e373bd247d7c18b89f7 100644 >--- a/Tools/lldb/lldb_webkit.py >+++ b/Tools/lldb/lldb_webkit.py >@@ -33,6 +33,26 @@ import lldb > import string > import struct > >+ >+def addSummaryAndSyntheticFormattersForRawBitmaskType(debugger, type_name, enumerator_value_to_name_map): >+ class GeneratedRawBitmaskProvider(RawBitmaskProviderBase): >+ ENUMERATOR_VALUE_TO_NAME_MAP = enumerator_value_to_name_map.copy() >+ >+ def raw_bitmask_summary_provider(valobj, dict): >+ provider = GeneratedRawBitmaskProvider(valobj, dict) >+ return "{ size = %d }" % provider.size >+ >+ # Add the provider class and summary function to the global scope so that LLDB >+ # can find them. >+ synthetic_provider_class_name = type_name + 'Provider' >+ summary_provider_function_name = type_name + '_SummaryProvider' >+ globals()[synthetic_provider_class_name] = GeneratedRawBitmaskProvider >+ globals()[summary_provider_function_name] = raw_bitmask_summary_provider >+ >+ debugger.HandleCommand('type summary add --expand -F lldb_webkit.%s "%s"' % (summary_provider_function_name, type_name)) >+ debugger.HandleCommand('type synthetic add %s --python-class lldb_webkit.%s' % (type_name, synthetic_provider_class_name)) >+ >+ > def __lldb_init_module(debugger, dict): > debugger.HandleCommand('command script add -f lldb_webkit.btjs btjs') > debugger.HandleCommand('type summary add --expand -F lldb_webkit.WTFString_SummaryProvider WTF::String') >@@ -71,6 +91,18 @@ def __lldb_init_module(debugger, dict): > debugger.HandleCommand('type synthetic add -x "^WTF::HashTable<.+>$" --python-class lldb_webkit.WTFHashTableProvider') > debugger.HandleCommand('type synthetic add -x "^WTF::OptionSet<.+>$" --python-class lldb_webkit.WTFOptionSetProvider') > >+ addSummaryAndSyntheticFormattersForRawBitmaskType(debugger, "WebEventFlags", { >+ 0x00010000: "WebEventFlagMaskLeftCommandKey", >+ 0x00020000: "WebEventFlagMaskLeftShiftKey", >+ 0x00040000: "WebEventFlagMaskLeftCapsLockKey", >+ 0x00080000: "WebEventFlagMaskLeftOptionKey", >+ 0x00100000: "WebEventFlagMaskLeftControlKey", >+ 0x00800000: "WebEventFlagMaskRightControlKey", >+ 0x00200000: "WebEventFlagMaskRightShiftKey", >+ 0x00400000: "WebEventFlagMaskRightOptionKey", >+ 0x01000000: "WebEventFlagMaskRightCommandKey", >+ }) >+ > > def WTFString_SummaryProvider(valobj, dict): > provider = WTFStringProvider(valobj, dict) >@@ -697,11 +729,24 @@ class WebCoreDocumentProvider: > return WebCoreFrameProvider(frame_ptr, dict()) > > >-class WTFOptionSetProvider: >+class FlagEnumerationProvider(object): > def __init__(self, valobj, internal_dict): > self.valobj = valobj > self.update() > >+ # Subclasses must override this to return a dictionary that maps emumerator values to names. >+ def _enumerator_value_to_name_map(self): >+ pass >+ >+ # Subclasses must override this to return the bitmask. >+ def _bitmask(self): >+ pass >+ >+ # Subclasses can override this to perform any computations when LLDB needs to refresh >+ # this provider. >+ def _update(self): >+ pass >+ > def has_children(self): > return bool(self._elements) > >@@ -723,21 +768,17 @@ class WTFOptionSetProvider: > return None > > def update(self): >- self.storage = self.valobj.GetChildMemberWithName('m_storage') # May be an invalid value. >+ self._update() >+ > self._elements = [] > self.size = 0 > >- template_argument_sbType = self.valobj.GetType().GetTemplateArgumentType(0) >- enumerator_value_to_name_map = {} >- for sbTypeEnumMember in template_argument_sbType.get_enum_members_array(): >- enumerator_value = sbTypeEnumMember.GetValueAsUnsigned() >- if enumerator_value not in enumerator_value_to_name_map: >- enumerator_value_to_name_map[enumerator_value] = sbTypeEnumMember.GetName() >+ enumerator_value_to_name_map = self._enumerator_value_to_name_map() > if not enumerator_value_to_name_map: > return > > bitmask_with_all_options_set = sum(enumerator_value_to_name_map) >- bitmask = self.storage.GetValueAsUnsigned(0) >+ bitmask = self._bitmask() > if bitmask > bitmask_with_all_options_set: > return # Since this is an invalid value, return so the raw hex form is written out. > >@@ -752,6 +793,33 @@ class WTFOptionSetProvider: > self.size = len(elements) > > >+class WTFOptionSetProvider(FlagEnumerationProvider): >+ def _enumerator_value_to_name_map(self): >+ template_argument_sbType = self.valobj.GetType().GetTemplateArgumentType(0) >+ enumerator_value_to_name_map = {} >+ for sbTypeEnumMember in template_argument_sbType.get_enum_members_array(): >+ enumerator_value = sbTypeEnumMember.GetValueAsUnsigned() >+ if enumerator_value not in enumerator_value_to_name_map: >+ enumerator_value_to_name_map[enumerator_value] = sbTypeEnumMember.GetName() >+ return enumerator_value_to_name_map >+ >+ def _bitmask(self): >+ return self.storage.GetValueAsUnsigned(0) >+ >+ def _update(self): >+ self.storage = self.valobj.GetChildMemberWithName('m_storage') # May be an invalid value. >+ >+ >+class RawBitmaskProviderBase(FlagEnumerationProvider): >+ ENUMERATOR_VALUE_TO_NAME_MAP = {} >+ >+ def _enumerator_value_to_name_map(self): >+ return self.ENUMERATOR_VALUE_TO_NAME_MAP >+ >+ def _bitmask(self): >+ return self.valobj.GetValueAsUnsigned(0) >+ >+ > class WTFVectorProvider: > def __init__(self, valobj, internal_dict): > self.valobj = valobj
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 193024
:
358050
| 358341