Title: [237564] trunk/Tools
Revision
237564
Author
dba...@webkit.org
Date
2018-10-29 13:57:15 -0700 (Mon, 29 Oct 2018)

Log Message

[lldb-webkit] Last aliased enumerator in OptionSet is printed; should print first enumerator
https://bugs.webkit.org/show_bug.cgi?id=191036

Reviewed by Andy Estes.

Prefer the first enumerator (in parse order) when pretty-printing an OptionSet that is parameterized
by an enum that contains two or more enumerators with the same value. For example, suppose
you have the following enum:

enum Flag {
    A = 1 << 0,
    AAlias = A,
};

Then pretty-printing OptionSet<Flag>(Flag::A) should print A instead of AAlias. A side effect of
this change is that OptionSet<Flag>(Flag::AAlias) will also print A as its only member as we cannot
differentiate between A and Alias. This should be acceptable in practice as aliased enumerators
tend to be used in bounds checks as opposed to code that adds to a set.

* lldb/lldbWebKitTester/main.cpp:
(testSummaryProviders):
* lldb/lldb_webkit.py:
(WTFOptionSetProvider.update):
* lldb/lldb_webkit_unittest.py:
(TestSummaryProviders.serial_test_WTFOptionSetProvider_simple):
(TestSummaryProviders):
(TestSummaryProviders.serial_test_WTFOptionSetProvider_aliased_flag):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (237563 => 237564)


--- trunk/Tools/ChangeLog	2018-10-29 20:55:33 UTC (rev 237563)
+++ trunk/Tools/ChangeLog	2018-10-29 20:57:15 UTC (rev 237564)
@@ -1,5 +1,35 @@
 2018-10-29  Daniel Bates  <daba...@apple.com>
 
+        [lldb-webkit] Last aliased enumerator in OptionSet is printed; should print first enumerator
+        https://bugs.webkit.org/show_bug.cgi?id=191036
+
+        Reviewed by Andy Estes.
+
+        Prefer the first enumerator (in parse order) when pretty-printing an OptionSet that is parameterized
+        by an enum that contains two or more enumerators with the same value. For example, suppose
+        you have the following enum:
+
+        enum Flag {
+            A = 1 << 0,
+            AAlias = A,
+        };
+
+        Then pretty-printing OptionSet<Flag>(Flag::A) should print A instead of AAlias. A side effect of
+        this change is that OptionSet<Flag>(Flag::AAlias) will also print A as its only member as we cannot
+        differentiate between A and Alias. This should be acceptable in practice as aliased enumerators
+        tend to be used in bounds checks as opposed to code that adds to a set.
+
+        * lldb/lldbWebKitTester/main.cpp:
+        (testSummaryProviders):
+        * lldb/lldb_webkit.py:
+        (WTFOptionSetProvider.update):
+        * lldb/lldb_webkit_unittest.py:
+        (TestSummaryProviders.serial_test_WTFOptionSetProvider_simple):
+        (TestSummaryProviders):
+        (TestSummaryProviders.serial_test_WTFOptionSetProvider_aliased_flag):
+
+2018-10-29  Daniel Bates  <daba...@apple.com>
+
         [llbd-webkit] Add summaries for Document, Frame, and SecurityOrigin
         https://bugs.webkit.org/show_bug.cgi?id=191033
 

Modified: trunk/Tools/lldb/lldbWebKitTester/main.cpp (237563 => 237564)


--- trunk/Tools/lldb/lldbWebKitTester/main.cpp	2018-10-29 20:55:33 UTC (rev 237563)
+++ trunk/Tools/lldb/lldbWebKitTester/main.cpp	2018-10-29 20:57:15 UTC (rev 237564)
@@ -50,6 +50,7 @@
     B = 1 << 1,
     C = 1 << 2,
     D = 1 << 3,
+    AAlias = A,
 };
 
 static void testSummaryProviders()
@@ -83,6 +84,7 @@
 
     OptionSet<ExampleFlags> exampleFlagsEmpty;
     OptionSet<ExampleFlags> exampleFlagsSimple { ExampleFlags::A, ExampleFlags::D, ExampleFlags::C };
+    OptionSet<ExampleFlags> exampleFlagsAliasedFlag { ExampleFlags::AAlias, ExampleFlags::D };
 
     breakForTestingSummaryProviders();
 }

Modified: trunk/Tools/lldb/lldb_webkit.py (237563 => 237564)


--- trunk/Tools/lldb/lldb_webkit.py	2018-10-29 20:55:33 UTC (rev 237563)
+++ trunk/Tools/lldb/lldb_webkit.py	2018-10-29 20:57:15 UTC (rev 237564)
@@ -733,7 +733,11 @@
         self.size = 0
 
         template_argument_sbType = self.valobj.GetType().GetTemplateArgumentType(0)
-        enumerator_value_to_name_map = {sbTypeEnumMember.GetValueAsUnsigned(): sbTypeEnumMember.GetName() for sbTypeEnumMember in template_argument_sbType.get_enum_members_array()}
+        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()
         if not enumerator_value_to_name_map:
             return
 

Modified: trunk/Tools/lldb/lldb_webkit_unittest.py (237563 => 237564)


--- trunk/Tools/lldb/lldb_webkit_unittest.py	2018-10-29 20:55:33 UTC (rev 237563)
+++ trunk/Tools/lldb/lldb_webkit_unittest.py	2018-10-29 20:57:15 UTC (rev 237564)
@@ -196,3 +196,11 @@
         self.assertEqual(provider.get_child_at_index(1).GetValue(), '4')
         self.assertEqual(provider.get_child_at_index(2).GetName(), 'D')
         self.assertEqual(provider.get_child_at_index(2).GetValue(), '8')
+
+    def serial_test_WTFOptionSetProvider_aliased_flag(self):
+        variable = self._sbFrame.FindVariable('exampleFlagsAliasedFlag')
+        provider = lldb_webkit.WTFOptionSetProvider(variable, {})
+        self.assertEqual(provider.get_child_at_index(0).GetName(), 'A')
+        self.assertEqual(provider.get_child_at_index(0).GetValue(), '1')
+        self.assertEqual(provider.get_child_at_index(1).GetName(), 'D')
+        self.assertEqual(provider.get_child_at_index(1).GetValue(), '8')
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to