Bug 1496870 - Add a GDB pretty printer for mozilla::EnumSet. r=tromey
authorBotond Ballo <botond@mozilla.com>
Wed, 10 Oct 2018 16:33:56 +0000
changeset 496289 56b783db0fd3052b6344d55962e46bc692bc5383
parent 496288 6eb2ec7487c13cbfc024ed3ee2ba857ac87e1e89
child 496290 8db96096643ba13f2c5e5db526de96f1cf55dddc
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstromey
bugs1496870
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1496870 - Add a GDB pretty printer for mozilla::EnumSet. r=tromey Differential Revision: https://phabricator.services.mozilla.com/D7954
third_party/python/gdbpp/gdbpp/__init__.py
third_party/python/gdbpp/gdbpp/enumset.py
--- a/third_party/python/gdbpp/gdbpp/__init__.py
+++ b/third_party/python/gdbpp/gdbpp/__init__.py
@@ -13,16 +13,17 @@ class GeckoPrettyPrinter(object):
     def __init__(self, name, regexp):
         self.name = name
         self.regexp = regexp
 
     def __call__(self, wrapped):
         GeckoPrettyPrinter.pp.add_printer(self.name, self.regexp, wrapped)
         return wrapped
 
+import gdbpp.enumset
 import gdbpp.linkedlist
 import gdbpp.owningthread
 import gdbpp.smartptr
 import gdbpp.string
 import gdbpp.tarray
 import gdbpp.thashtable
 
 gdb.printing.register_pretty_printer(None, GeckoPrettyPrinter.pp)
new file mode 100644
--- /dev/null
+++ b/third_party/python/gdbpp/gdbpp/enumset.py
@@ -0,0 +1,28 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import gdb
+import itertools
+from gdbpp import GeckoPrettyPrinter
+
+@GeckoPrettyPrinter('mozilla::EnumSet', '^mozilla::EnumSet<.*>$')
+class enumset_printer(object):
+    def __init__(self, value):
+        self.value = value
+        self.enum_type = value.type.template_argument(0)
+
+    def children(self):
+        bitfield = self.value['mBitField']
+        max_bit = (self.enum_type.sizeof * 8) - 1
+        return (("flag", gdb.Value(i).cast(self.enum_type))
+                for i in range(0, max_bit)
+                if ((bitfield & (2**i)) != 0))
+
+    def to_string(self):
+        return str(self.value.type)
+
+    def display_hint(self):
+        return 'array'