From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11253 invoked by alias); 6 Oct 2014 07:34:04 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 11242 invoked by uid 89); 6 Oct 2014 07:34:02 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL,BAYES_00,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mga01.intel.com Received: from mga01.intel.com (HELO mga01.intel.com) (192.55.52.88) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 06 Oct 2014 07:34:00 +0000 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 06 Oct 2014 00:33:21 -0700 X-ExtLoop1: 1 Received: from irsmsx103.ger.corp.intel.com ([163.33.3.157]) by fmsmga002.fm.intel.com with ESMTP; 06 Oct 2014 00:33:19 -0700 Received: from irsmsx151.ger.corp.intel.com (163.33.192.59) by IRSMSX103.ger.corp.intel.com (163.33.3.157) with Microsoft SMTP Server (TLS) id 14.3.195.1; Mon, 6 Oct 2014 08:33:19 +0100 Received: from irsmsx104.ger.corp.intel.com ([169.254.5.248]) by IRSMSX151.ger.corp.intel.com ([169.254.4.146]) with mapi id 14.03.0195.001; Mon, 6 Oct 2014 08:33:19 +0100 From: "Tedeschi, Walfred" To: Doug Evans CC: "gdb-patches@sourceware.org" Subject: RE: [PATCH][PR python/17364] Cleanup registration of __gdb_builtin_type_bound128 pretty-printer Date: Mon, 06 Oct 2014 07:34:00 -0000 Message-ID: References: In-Reply-To: Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2014-10/txt/msg00092.txt.bz2 Hi Doug, I have also submitted a patch for this last week. Though I was not creating= a new directory for pretty printers. https://sourceware.org/ml/gdb-patches/2014-09/msg00867.html I would like though to understand a bit more your comment on having x86 on = the name of the register. What is the purpose of that? (I could change it in case) About registration of the pretty printer. We could do the following: 1. Register an event listener for new obj_files. 2. Query at every event the architecture of the inferior. (In case we had = an event new_inferior loaded it would be cheaper.) 3. In case of x86 or amd64 we can then register the pretty-printer for the = bound registers. Regards, -Fred -----Original Message----- From: gdb-patches-owner@sourceware.org [mailto:gdb-patches-owner@sourceware= .org] On Behalf Of Doug Evans Sent: Saturday, October 04, 2014 8:47 PM To: gdb-patches@sourceware.org Subject: [PATCH][PR python/17364] Cleanup registration of __gdb_builtin_typ= e_bound128 pretty-printer Hi. The registration of this pretty-printer is all wrong. This patch creates a new global "builtin" collection of pretty-printers, ad= ds the bound pretty-printer to it, and provides an API call to let one regi= ster more builtin pretty-printers. I'd really like to get this into 7.8.1, I don't want the way it is currently registered to get built on. One thing that still bothers me is that the bound128 type is x86-specific a= nd yet the printer is arch-independent. That should require changing the name __gdb_builtin_type_bound128 in i386-t= dep.c to include x86 in the name (or some such), but maybe that's too big a= change for now. But as gdb becomes more multi-arch, attention to collisions and confusion i= n global namespaces (e.g., the space of builtin pretty-printers) is going t= o be more important. [One way to solve this would be to record such printers with the arch, but = that feels like overkill.] 2014-10-03 Doug Evans 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 "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.i= n index 1e8cd4b..00c70bb 100644 --- a/gdb/data-directory/Makefile.in +++ b/gdb/data-directory/Makefile.in @@ -64,7 +64,6 @@ PYTHON_FILE_LIST =3D \ 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 =3D \ 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 =20 @HAVE_PYTHON_TRUE@PYTHON_FILES =3D $(PYTHON_FILE_LIST) @HAVE_PYTHON_FALSE= @PYTHON_FILES =3D 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 =3D os.path.dirname(os.path.dirname(__file__)) =20 packages =3D [ 'function', - 'command' + 'command', + 'printer' ] =20 # pkgutil.iter_modules is not available prior to Python 2.6. Instead, dif= f --git a/gdb/python/lib/gdb/command/bound_registers.py b/gdb/python/lib/gd= b/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 W= ITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILIT= Y or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public Licen= se for more details. -# -# You should have received a copy of the GNU General Public License -# alo= ng with this program. If not, see . - -import gdb.printing - -class BoundPrinter: - """Adds size field to a _rawbound128 type.""" - - def __init__ (self, val): - self.val =3D val - - def to_string (self): - upper =3D self.val["ubound"] - lower =3D self.val["lbound"] - size =3D (long) ((upper) - (lower)) - if size > -1: - size =3D size + 1 - result =3D '{lbound =3D %s, ubound =3D %s} : size %s' % (lower, up= per, 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 =3D 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/pr= inter/__init__.py new file mode 100644 index 0000000..ca768c89 --- /dev/null +++ b/gdb/python/lib/gdb/printer/__init__.py @@ -0,0 +1,16 @@ +# Copyright (C) 2010-2014 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify=20 +# it under the terms of the GNU General Public License as published by=20 +# the Free Software Foundation; either version 3 of the License, or #=20 +(at your option) any later version. +# +# This program is distributed in the hope that it will be useful, # but=20 +WITHOUT ANY WARRANTY; without even the implied warranty of #=20 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU=20 +General Public License for more details. +# +# You should have received a copy of the GNU General Public License #=20 +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..e585dcb --- /dev/null +++ b/gdb/python/lib/gdb/printer/bound_registers.py @@ -0,0 +1,36 @@ +# Pretty-printer utilities. +# Copyright (C) 2013-2014 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify=20 +# it under the terms of the GNU General Public License as published by=20 +# the Free Software Foundation; either version 3 of the License, or #=20 +(at your option) any later version. +# +# This program is distributed in the hope that it will be useful, # but=20 +WITHOUT ANY WARRANTY; without even the implied warranty of #=20 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU=20 +General Public License for more details. +# +# You should have received a copy of the GNU General Public License #=20 +along with this program. If not, see . + +import gdb.printing + +class Bound128Printer: + """Adds size field to a _rawbound128 type.""" + + def __init__ (self, val): + self.val =3D val + + def to_string (self): + upper =3D self.val["ubound"] + lower =3D self.val["lbound"] + size =3D (long) ((upper) - (lower)) + if size > -1: + size =3D size + 1 + result =3D '{lbound =3D %s, ubound =3D %s} : size %s' % (lower, up= per, size) + return result + +gdb.printing.add_builtin_pretty_printer ('bound128', + '^__gdb_builtin_type_bound128', + Bound128Printer) diff --git a/gdb/python/lib/gdb/printing.py b/gdb/python/lib/gdb/printing.p= y 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=20 +printers # to this with add_builtin_pretty_printer. + +_builtin_pretty_printers =3D 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) 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