From 6979730b1b9378a143b1bea3d0ff7b96c7bf02c5 Mon Sep 17 00:00:00 2001 From: Doug Evans Date: Wed, 15 Oct 2014 11:43:49 -0700 Subject: PR python/17364 gdb/ChangeLog: * 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. --- gdb/python/lib/gdb/__init__.py | 3 +- gdb/python/lib/gdb/command/bound_registers.py | 45 --------------------------- gdb/python/lib/gdb/printer/__init__.py | 14 +++++++++ gdb/python/lib/gdb/printer/bound_registers.py | 36 +++++++++++++++++++++ gdb/python/lib/gdb/printing.py | 14 +++++++++ 5 files changed, 66 insertions(+), 46 deletions(-) delete mode 100644 gdb/python/lib/gdb/command/bound_registers.py create mode 100644 gdb/python/lib/gdb/printer/__init__.py create mode 100644 gdb/python/lib/gdb/printer/bound_registers.py (limited to 'gdb/python') 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 . - -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 . 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 . + +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) -- cgit v1.1