public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH, PR 17364] Need better printer names in bound_register.py
@ 2014-09-30  7:29 Walfred Tedeschi
  2014-10-09 17:34 ` Doug Evans
  0 siblings, 1 reply; 4+ messages in thread
From: Walfred Tedeschi @ 2014-09-30  7:29 UTC (permalink / raw)
  To: palves, mark.kettenis; +Cc: gdb-patches, Walfred Tedeschi

Moved the printer to the global scope and changed the name of the
printer to a more specific name.

2014.09.11  Walfred Tedeschi  <walfred.tedeschi@intel.com>

python/lib/gdb/command:

	* bound_registers.py (mpx_bound_reg_printer) Added function to
	register pretty-printing for bound registers, and fixed comments.
	(build_pretty_printer) Removed.

---
 gdb/python/lib/gdb/command/bound_registers.py | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/gdb/python/lib/gdb/command/bound_registers.py b/gdb/python/lib/gdb/command/bound_registers.py
index 24d4c45..6f2dbc6 100644
--- a/gdb/python/lib/gdb/command/bound_registers.py
+++ b/gdb/python/lib/gdb/command/bound_registers.py
@@ -16,8 +16,8 @@
 
 import gdb.printing
 
-class BoundPrinter:
-    """Adds size field to a _rawbound128 type."""
+class BoundPrinter (object):
+    """Adds size field to a  __gdb_builtin_type_bound128 type."""
 
     def __init__ (self, val):
         self.val = val
@@ -31,15 +31,14 @@ class BoundPrinter:
         result = '{lbound = %s, ubound = %s} : size %s' % (lower, upper, size)
         return result
 
-# There are two pattern matching used: first one is related to a library
-# second is related to the type. Since we are displaying a register all
-# libraries are accepted. Type to be processed is the same present
-# in the xml file.
+# Register a global pretty-printer for the bnd[0..3] pseudo
+# register.
 
-def build_pretty_printer ():
-    pp = gdb.printing.RegexpCollectionPrettyPrinter (".*")
-    pp.add_printer ('bound', '^__gdb_builtin_type_bound128', BoundPrinter)
-    return pp
+def mpx_bound_reg_printer (val):
+    lookup_tag = val.type.tag
+    if lookup_tag == None:
+        return None
+    if lookup_tag == "__gdb_builtin_type_bound128":
+        return BoundPrinter (val)
 
-gdb.printing.register_pretty_printer (gdb.current_objfile (),
-                                      build_pretty_printer ())
+gdb.pretty_printers.append (mpx_bound_reg_printer)
-- 
1.9.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH, PR 17364] Need better printer names in bound_register.py
  2014-09-30  7:29 [PATCH, PR 17364] Need better printer names in bound_register.py Walfred Tedeschi
@ 2014-10-09 17:34 ` Doug Evans
  2014-10-10  6:58   ` Tedeschi, Walfred
  0 siblings, 1 reply; 4+ messages in thread
From: Doug Evans @ 2014-10-09 17:34 UTC (permalink / raw)
  To: Walfred Tedeschi; +Cc: palves, mark.kettenis, gdb-patches

Walfred Tedeschi writes:
 > Moved the printer to the global scope and changed the name of the
 > printer to a more specific name.
 > 
 > 2014.09.11  Walfred Tedeschi  <walfred.tedeschi@intel.com>
 > 
 > python/lib/gdb/command:
 > 
 > 	* bound_registers.py (mpx_bound_reg_printer) Added function to
 > 	register pretty-printing for bound registers, and fixed comments.
 > 	(build_pretty_printer) Removed.

Hi.

fwiw, I kinda like grouping together all the pretty-printers provided by gdb.
See https://sourceware.org/ml/gdb-patches/2014-10/msg00081.html

Using RegexpCollectionPrettyPrinter is a bit of overkill since there are no
templates, at least not yet.  We could certainly add
SimpleCollectionPrettyPrinter or some such that just did string comparisons
on tag names instead of regexps, but since this is all implementation detail
we could defer this.

 > +def mpx_bound_reg_printer (val):
 > +    lookup_tag = val.type.tag
 > +    if lookup_tag == None:
 > +        return None
 > +    if lookup_tag == "__gdb_builtin_type_bound128":
 > +        return BoundPrinter (val)

Random comments:

1) "lookup_tag" is a bit confusing as there is no lookup done here.
I'd rename it to just val_type_tag or some such.
[Assuming we keep this version.]

2) "mpx" is presumably enough to distinguish this pretty-printer from other
arch's bounds reg pretty-printers (probably a better choice than "x86" too).

3) If I do "info pretty" I see this:

global pretty-printers:
  mpx_bound_reg_printer

Having "printer" in the name is superfluous, thus if one was to do
things this way I'd rename mpx_bound_reg_printer to mpx_bound_reg.
That way the user can do "disable pretty-printer global mpx_bound_reg".

4) It might be preferable to pick a name closer to the actual type's name:
"mpx_bound128" ?

[digression:
Registering printers as functions was how pretty-printers were originally
added, but it turned out to be insufficient: printers need to be disableable
and thus need names.  OTOH one tends to think of the name of the function
here as an implementation detail, except that it isn't.]

---

Going forward,
I like the idea of providing basic infrastructure for grouping builtin
pretty-printers together and using that for 17364.
Plus this file really doesn't belong in python/lib/gdb/command.

I propose sticking with this patch
https://sourceware.org/ml/gdb-patches/2014-10/msg00081.html
but I'm happy to tweak it as desired (e.g. use "mpx_bound128" as the name).

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH, PR 17364] Need better printer names in bound_register.py
  2014-10-09 17:34 ` Doug Evans
@ 2014-10-10  6:58   ` Tedeschi, Walfred
  2014-10-15 20:28     ` Doug Evans
  0 siblings, 1 reply; 4+ messages in thread
From: Tedeschi, Walfred @ 2014-10-10  6:58 UTC (permalink / raw)
  To: Doug Evans; +Cc: palves, mark.kettenis, gdb-patches

Hello Doug,

Thanks a lot for the nice and detailed explanation. I am fine to stick with the patch you mentioned.

Grouping the pretty-printers is indeed a nice idea!
Sorry for having taking some time to answer to the defect. I usually try to answer quick! :(

Do you think we should after that think about a mechanism to add this printer according to the architecture?

Thanks again and best regards,
-Fred


-----Original Message-----
From: Doug Evans [mailto:dje@google.com] 
Sent: Thursday, October 09, 2014 7:35 PM
To: Tedeschi, Walfred
Cc: palves@redhat.com; mark.kettenis@xs4all.nl; gdb-patches@sourceware.org
Subject: Re: [PATCH, PR 17364] Need better printer names in bound_register.py

Walfred Tedeschi writes:
 > Moved the printer to the global scope and changed the name of the  > printer to a more specific name.
 >
 > 2014.09.11  Walfred Tedeschi  <walfred.tedeschi@intel.com>  >  > python/lib/gdb/command:
 > 
 > 	* bound_registers.py (mpx_bound_reg_printer) Added function to
 > 	register pretty-printing for bound registers, and fixed comments.
 > 	(build_pretty_printer) Removed.

Hi.

fwiw, I kinda like grouping together all the pretty-printers provided by gdb.
See https://sourceware.org/ml/gdb-patches/2014-10/msg00081.html

Using RegexpCollectionPrettyPrinter is a bit of overkill since there are no templates, at least not yet.  We could certainly add SimpleCollectionPrettyPrinter or some such that just did string comparisons on tag names instead of regexps, but since this is all implementation detail we could defer this.

 > +def mpx_bound_reg_printer (val):
 > +    lookup_tag = val.type.tag
 > +    if lookup_tag == None:
 > +        return None
 > +    if lookup_tag == "__gdb_builtin_type_bound128":
 > +        return BoundPrinter (val)

Random comments:

1) "lookup_tag" is a bit confusing as there is no lookup done here.
I'd rename it to just val_type_tag or some such.
[Assuming we keep this version.]

2) "mpx" is presumably enough to distinguish this pretty-printer from other arch's bounds reg pretty-printers (probably a better choice than "x86" too).

3) If I do "info pretty" I see this:

global pretty-printers:
  mpx_bound_reg_printer

Having "printer" in the name is superfluous, thus if one was to do things this way I'd rename mpx_bound_reg_printer to mpx_bound_reg.
That way the user can do "disable pretty-printer global mpx_bound_reg".

4) It might be preferable to pick a name closer to the actual type's name:
"mpx_bound128" ?

[digression:
Registering printers as functions was how pretty-printers were originally added, but it turned out to be insufficient: printers need to be disableable and thus need names.  OTOH one tends to think of the name of the function here as an implementation detail, except that it isn't.]

---

Going forward,
I like the idea of providing basic infrastructure for grouping builtin pretty-printers together and using that for 17364.
Plus this file really doesn't belong in python/lib/gdb/command.

I propose sticking with this patch
https://sourceware.org/ml/gdb-patches/2014-10/msg00081.html
but I'm happy to tweak it as desired (e.g. use "mpx_bound128" as the name).

Intel GmbH
Dornacher Strasse 1
85622 Feldkirchen/Muenchen, Deutschland
Sitz der Gesellschaft: Feldkirchen bei Muenchen
Geschaeftsfuehrer: Christian Lamprechter, Hannes Schwaderer, Douglas Lusk
Registergericht: Muenchen HRB 47456
Ust.-IdNr./VAT Registration No.: DE129385895
Citibank Frankfurt a.M. (BLZ 502 109 00) 600119052

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH, PR 17364] Need better printer names in bound_register.py
  2014-10-10  6:58   ` Tedeschi, Walfred
@ 2014-10-15 20:28     ` Doug Evans
  0 siblings, 0 replies; 4+ messages in thread
From: Doug Evans @ 2014-10-15 20:28 UTC (permalink / raw)
  To: Tedeschi, Walfred; +Cc: gdb-patches

Tedeschi, Walfred writes:
 > Hello Doug,
 > 
 > Thanks a lot for the nice and detailed explanation. I am fine to stick with the patch you mentioned.
 > 
 > Grouping the pretty-printers is indeed a nice idea!
 > Sorry for having taking some time to answer to the defect. I usually try to answer quick! :(

Hi.  No worries.
I've committed the following to trunk and the 7.8 branch.
We can work on further additions as we're able.

2014-10-15  Doug Evans  <dje@google.com>
	    Walfred Tedeschi  <walfred.tedeschi@intel.com>

	PR python/17364
	* python/lib/gdb/__init__.py (packages): Add "printer".
	* python/lib/gdb/command/bound_registers.py: Moved to ...
	* python/lib/gdb/printer/bound_registers.py: ... here.
	Add printer to global set of builtin printers.  Rename printer from
	"bound" to "mpx_bound128".
	* python/lib/gdb/printing.py (_builtin_pretty_printers): New global,
	registered as global "builtin" printer.
	(add_builtin_pretty_printer): New function.
	* data-directory/Makefile.in (PYTHON_FILE_LIST): Update, and add
	gdb/printer/__init__.py.

diff --git a/gdb/data-directory/Makefile.in b/gdb/data-directory/Makefile.in
index 1e8cd4b..00c70bb 100644
--- a/gdb/data-directory/Makefile.in
+++ b/gdb/data-directory/Makefile.in
@@ -64,7 +64,6 @@ PYTHON_FILE_LIST = \
 	gdb/printing.py \
 	gdb/prompt.py \
 	gdb/xmethod.py \
-	gdb/command/bound_registers.py \
 	gdb/command/__init__.py \
 	gdb/command/xmethods.py \
 	gdb/command/frame_filters.py \
@@ -74,7 +73,9 @@ PYTHON_FILE_LIST = \
 	gdb/command/explore.py \
 	gdb/function/__init__.py \
 	gdb/function/caller_is.py \
-	gdb/function/strfns.py
+	gdb/function/strfns.py \
+	gdb/printer/__init__.py \
+	gdb/printer/bound_registers.py
 
 @HAVE_PYTHON_TRUE@PYTHON_FILES = $(PYTHON_FILE_LIST)
 @HAVE_PYTHON_FALSE@PYTHON_FILES =
diff --git a/gdb/python/lib/gdb/__init__.py b/gdb/python/lib/gdb/__init__.py
index 557e168..8c6eee2 100644
--- a/gdb/python/lib/gdb/__init__.py
+++ b/gdb/python/lib/gdb/__init__.py
@@ -81,7 +81,8 @@ PYTHONDIR = os.path.dirname(os.path.dirname(__file__))
 
 packages = [
     'function',
-    'command'
+    'command',
+    'printer'
 ]
 
 # pkgutil.iter_modules is not available prior to Python 2.6.  Instead,
diff --git a/gdb/python/lib/gdb/command/bound_registers.py b/gdb/python/lib/gdb/command/bound_registers.py
deleted file mode 100644
index 24d4c45..0000000
--- a/gdb/python/lib/gdb/command/bound_registers.py
+++ /dev/null
@@ -1,45 +0,0 @@
-# Pretty-printer utilities.
-# Copyright (C) 2013-2014 Free Software Foundation, Inc.
-
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-import gdb.printing
-
-class BoundPrinter:
-    """Adds size field to a _rawbound128 type."""
-
-    def __init__ (self, val):
-        self.val = val
-
-    def to_string (self):
-        upper = self.val["ubound"]
-        lower = self.val["lbound"]
-        size  = (long) ((upper) - (lower))
-        if size > -1:
-            size = size + 1
-        result = '{lbound = %s, ubound = %s} : size %s' % (lower, upper, size)
-        return result
-
-# There are two pattern matching used: first one is related to a library
-# second is related to the type. Since we are displaying a register all
-# libraries are accepted. Type to be processed is the same present
-# in the xml file.
-
-def build_pretty_printer ():
-    pp = gdb.printing.RegexpCollectionPrettyPrinter (".*")
-    pp.add_printer ('bound', '^__gdb_builtin_type_bound128', BoundPrinter)
-    return pp
-
-gdb.printing.register_pretty_printer (gdb.current_objfile (),
-                                      build_pretty_printer ())
diff --git a/gdb/python/lib/gdb/printer/__init__.py b/gdb/python/lib/gdb/printer/__init__.py
new file mode 100644
index 0000000..04c0c7d
--- /dev/null
+++ b/gdb/python/lib/gdb/printer/__init__.py
@@ -0,0 +1,14 @@
+# Copyright (C) 2014 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
diff --git a/gdb/python/lib/gdb/printer/bound_registers.py b/gdb/python/lib/gdb/printer/bound_registers.py
new file mode 100644
index 0000000..25e6e80
--- /dev/null
+++ b/gdb/python/lib/gdb/printer/bound_registers.py
@@ -0,0 +1,36 @@
+# Pretty-printers for bounds registers.
+# Copyright (C) 2013-2014 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+import gdb.printing
+
+class MpxBound128Printer:
+    """Adds size field to a mpx __gdb_builtin_type_bound128 type."""
+
+    def __init__ (self, val):
+        self.val = val
+
+    def to_string (self):
+        upper = self.val["ubound"]
+        lower = self.val["lbound"]
+        size  = (long) ((upper) - (lower))
+        if size > -1:
+            size = size + 1
+        result = '{lbound = %s, ubound = %s} : size %s' % (lower, upper, size)
+        return result
+
+gdb.printing.add_builtin_pretty_printer ('mpx_bound128',
+                                         '^__gdb_builtin_type_bound128',
+                                         MpxBound128Printer)
diff --git a/gdb/python/lib/gdb/printing.py b/gdb/python/lib/gdb/printing.py
index 2940b93..ff5250a 100644
--- a/gdb/python/lib/gdb/printing.py
+++ b/gdb/python/lib/gdb/printing.py
@@ -263,3 +263,17 @@ class FlagEnumerationPrinter(PrettyPrinter):
             return _EnumInstance(self.enumerators, val)
         else:
             return None
+
+
+# Builtin pretty-printers.
+# The set is defined as empty, and files in printing/*.py add their printers
+# to this with add_builtin_pretty_printer.
+
+_builtin_pretty_printers = RegexpCollectionPrettyPrinter("builtin")
+
+register_pretty_printer(None, _builtin_pretty_printers)
+
+# Add a builtin pretty-printer.
+
+def add_builtin_pretty_printer(name, regexp, printer):
+    _builtin_pretty_printers.add_printer(name, regexp, printer)

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-10-15 20:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-30  7:29 [PATCH, PR 17364] Need better printer names in bound_register.py Walfred Tedeschi
2014-10-09 17:34 ` Doug Evans
2014-10-10  6:58   ` Tedeschi, Walfred
2014-10-15 20:28     ` Doug Evans

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).