From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Extend gdb to filter registers Date: Tue, 08 Oct 2019 13:26:41 -0400 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="98651"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: Emacs developers To: Yuan Fu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Oct 08 19:54:37 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iHtgy-000PVp-7J for ged-emacs-devel@m.gmane.org; Tue, 08 Oct 2019 19:54:36 +0200 Original-Received: from localhost ([::1]:59562 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHtgw-0004e6-BX for ged-emacs-devel@m.gmane.org; Tue, 08 Oct 2019 13:54:34 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50250) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHtG3-00072Y-GN for emacs-devel@gnu.org; Tue, 08 Oct 2019 13:26:48 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iHtG1-0007IQ-RQ for emacs-devel@gnu.org; Tue, 08 Oct 2019 13:26:47 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:17093) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iHtG1-0007Hz-K6 for emacs-devel@gnu.org; Tue, 08 Oct 2019 13:26:45 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 78D8385243; Tue, 8 Oct 2019 13:26:44 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id F29B3811E8; Tue, 8 Oct 2019 13:26:42 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1570555603; bh=SLOmF/u0Y/1Ac7rxaswqnOGC0k4qF5vcy0V4aLEyO3Q=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=jEM4tGugx00QhGiGTWsXkUX22acVaN1YDhYHY75RzTYR/EfZ9aScTChHbt16jryOO dMKBTLgYQd2GIHV12fottkEeTHr/OnFA5wBrr+fLDwyeHPWsbG7JMji6QMTfW1cN4g 9ORrmG7WAGplaSfbR3/TwDPplMRmjzgN99e7hr1iU6aR0z+yG5wQEFvz2E9uSWKtF7 B+G+lvJzzpefIEh63UH42/7Bb9sKJIAIIkegANfPnApK5b1wR+VSBaUkyWSxxCviWh FcugvylqTeIPxLFrhI9hQU7Ow5uTbtV6U/tJupEmc0qOybYi4NhnYRHh7lcRAYKbOk 1aFMJpxv2ISQA== Original-Received: from alfajor (modemcable157.163-203-24.mc.videotron.ca [24.203.163.157]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id B3974120699; Tue, 8 Oct 2019 13:26:42 -0400 (EDT) In-Reply-To: (Yuan Fu's message of "Fri, 4 Oct 2019 23:15:31 -0400") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 132.204.25.50 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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:240757 Archived-At: I just took a quick look at your code. Looks pretty good. See below the few nitpicks I found. Stefan > diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el > index 60852e4ad6..5b7e3321f3 100644 > --- a/lisp/progmodes/gdb-mi.el > +++ b/lisp/progmodes/gdb-mi.el > @@ -200,6 +200,13 @@ gdb-error > (defvar gdb-macro-info nil > "Non-nil if GDB knows that the inferior includes preprocessor macro in= fo.") > (defvar gdb-register-names nil "List of register names.") > +(defvar gdb-display-these-registers t > + "Registers that are displayed in register buffer. > +Can be a list, a function or t/nil. > +If a list, registers which names can be found in the list are displayed. > +If a function, it is passed with a register name and should > +return t to display and nil to not display. > +If t/nil, display all registers / none of the registers.") "which" =3D> "whose" Note: nil is a list, so the nil case is already covered by the list case. For the function case, please clarify what the argument will look like (a symbol or a string?). Is this expected to be set by the user via `setq`? If so, maybe it should be a `defcustom`? > +(defun gdb-registers-add-to-display (register) > + "Add REGISTER to display in register buffer. > +REGISTER is a string representing the name of the register. > +By default the register buffer displays all the registers. > +REGISTER can also be 'all, which configures gdb to display all registers. > +Also see `gdb-registers-remove-from-display'. " > + (interactive (list (completing-read "Register: " (append gdb-register-= names > + '("all"))))) > + (if (equal register "all") > + (setq gdb-display-these-registers t) > + (if (listp gdb-display-these-registers) > + (add-to-list 'gdb-display-these-registers register) > + (setq gdb-display-these-registers (list register))))) If gdb-display-these-registers is t this will not "add" but remove all but `register` from the display, which might surprise the user. Along the same lines, if gdb-display-these-registers is a function this will either silently throw away the function (if `listp` returns nil) or build a "broken" list (if `listp` return non-nil, which is very much possible). > +(defun gdb-registers-remove-from-display (register) > + "Remove REGISTER from display in register buffer. > +REGISTER is a string representing the name of the register. > +By default the register buffer displays all the registers. > +REGISTER can also be 'all, which configures gdb to hide all registers. > +Also see `gdb-registers-add-to-display'." > + (interactive (list (completing-read "Register: " (append gdb-register-= names > + '("all"))))) > + (if (equal register "all") > + (setq gdb-display-these-registers nil) > + (if (listp gdb-display-these-registers) > + (setq gdb-display-these-registers > + (remove register gdb-display-these-registers)) > + (user-error "gdb-display-these-registers is not a list, can=E2=80= =99t remove anything from it")))) This may similarly misbehave if gdb-display-these-registers is a function represented as a list (tho most likely in that case `register` won't be found in the list, so it will just silently do nothing). > + (when (cond ((and (listp gdb-display-these-registers) > + gdb-display-these-registers) ; not nil > + (member register-name gdb-display-these-registers= )) `consp` is a more efficient to test "list and non-nil". But here, we don't need to avoid the nil case, since (member X nil) will return nil anyway. Stefan