From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.devel Subject: Re: Enabling --enable-check-lisp-object-type by default on x86 and AMD64 Date: Fri, 5 May 2017 16:23:52 -0700 Organization: UCLA Computer Science Department Message-ID: <764aeab0-964a-3225-d236-d44853f888a0@cs.ucla.edu> References: <83mvb8riq0.fsf@gnu.org> <83a878r2d0.fsf@gnu.org> <60379b71-bd6a-5f6f-dec1-523d6f4b2016@cs.ucla.edu> <83vapihdgs.fsf@gnu.org> <83shkmgfnh.fsf@gnu.org> <777fd9a2-232a-e52c-0a51-3d287567fb2e@cs.ucla.edu> <83efw5hkby.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------5981EE6223CA189F47C86679" X-Trace: blaine.gmane.org 1494026715 23753 195.159.176.226 (5 May 2017 23:25:15 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 5 May 2017 23:25:15 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.0 Cc: p.stephani2@gmail.com, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat May 06 01:25:11 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d6mb1-00065p-83 for ged-emacs-devel@m.gmane.org; Sat, 06 May 2017 01:25:11 +0200 Original-Received: from localhost ([::1]:49396 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6mb6-00060B-Ja for ged-emacs-devel@m.gmane.org; Fri, 05 May 2017 19:25:16 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39299) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6mZu-0005Ed-GW for emacs-devel@gnu.org; Fri, 05 May 2017 19:24:03 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d6mZt-0006ct-6z for emacs-devel@gnu.org; Fri, 05 May 2017 19:24:02 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:48692) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d6mZp-0006Vl-AZ; Fri, 05 May 2017 19:23:57 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id CE2D7160070; Fri, 5 May 2017 16:23:54 -0700 (PDT) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id PwYdynGSsXeu; Fri, 5 May 2017 16:23:53 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 25F761600B9; Fri, 5 May 2017 16:23:53 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 1EpBN95oQN-8; Fri, 5 May 2017 16:23:53 -0700 (PDT) Original-Received: from Penguin.CS.UCLA.EDU (Penguin.CS.UCLA.EDU [131.179.64.200]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id B219A160070; Fri, 5 May 2017 16:23:52 -0700 (PDT) In-Reply-To: <83efw5hkby.fsf@gnu.org> Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 131.179.128.68 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:214596 Archived-At: This is a multi-part message in MIME format. --------------5981EE6223CA189F47C86679 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 05/03/2017 11:22 AM, Eli Zaretskii wrote: > This is better, but how sure we are people's GDB is built with Python > support? We can ask developers to upgrade. GDB pretty-printing has worked with embedded Python for several years (since GDB 7.3 in 2011, I believe). We are not talking about general Emacs users here, only developers who are building bleeding-edge Emacs from Git. It's reasonable to expect these folks to have reasonably modern tools, especially since the only problem here is that the backtrace will be a bit harder to read if they use an old GDB. > Why not make this part of .gdbinit itself? Sure, we can do that. > Also, the Python script should be a bit smarter, to support also the > compilation without --enable-check-lisp-object-type. When I try this > script in such a build, GDB crashes when displaying a backtrace. Also doable. I installed the attached, which I hope addresses the above issues well enough. --------------5981EE6223CA189F47C86679 Content-Type: text/x-patch; name="0001-Pretty-print-Lisp_Object-values-in-GDB.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Pretty-print-Lisp_Object-values-in-GDB.patch" >From f46a91a7811c359fae9c1c2a7f9374f9c5303209 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 5 May 2017 15:59:24 -0700 Subject: [PATCH] Pretty-print Lisp_Object values in GDB * src/.gdbinit: Add a pretty-printer for Lisp_Object values. Now, GDB displays them as "XIL(0xXXX)" rather than displaying them as "..." when CHECK_LISP_OBJECT_TYPE is in effect and as "DDDDD" otherwise. --- src/.gdbinit | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/.gdbinit b/src/.gdbinit index 6d7476d..0596188 100644 --- a/src/.gdbinit +++ b/src/.gdbinit @@ -1264,3 +1264,60 @@ commands end continue end + + +# Put the Python code at the end of .gdbinit so that if GDB does not +# support Python, GDB will do all the above initializations before +# reporting an error. + +python + +# Omit pretty-printing in older (pre-7.3) GDBs that lack it. +if hasattr(gdb, 'printing'): + + class Emacs_Pretty_Printers (gdb.printing.RegexpCollectionPrettyPrinter): + """A collection of pretty-printers. This is like GDB's + RegexpCollectionPrettyPrinter except when printing Lisp_Object.""" + def __call__ (self, val): + """Look up the pretty-printer for the provided value.""" + type = val.type + typename = type.tag or type.name + basic_type = gdb.types.get_basic_type (type) + basic_typename = basic_type.tag or basic_type.name + for printer in self.subprinters: + if (printer.enabled + and ((printer.regexp == '^Lisp_Object$' + and typename == 'Lisp_Object') + or (basic_typename + and printer.compiled_re.search (basic_typename)))): + return printer.gen_printer (val) + return None + + class Lisp_Object_Printer: + "A printer for Lisp_Object values." + def __init__ (self, val): + self.val = val + + def to_string (self): + "Yield a string that can be fed back into GDB." + val = self.val + basic_type = gdb.types.get_basic_type (val.type) + if (basic_type.code == gdb.TYPE_CODE_STRUCT + and gdb.types.has_field (basic_type, "i")): + val = val["i"] + # Yield "XIL(N)", where N is a C integer. This helps humans + # distinguish Lisp_Object values from ordinary integers even + # when Lisp_Object is an integer. Perhaps some day the + # pretty-printing could be fancier. + if not val: + return "XIL(0)" # Easier to read than "XIL(0x0)". + return "XIL(0x%x)" % val + + def build_pretty_printer (): + pp = Emacs_Pretty_Printers ("Emacs") + pp.add_printer ('Lisp_Object', '^Lisp_Object$', Lisp_Object_Printer) + return pp + + gdb.printing.register_pretty_printer (gdb.current_objfile (), + build_pretty_printer (), True) +end -- 2.9.3 --------------5981EE6223CA189F47C86679--