From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Lars Ingebrigtsen Newsgroups: gmane.emacs.bugs Subject: bug#34589: 26.1.91; GDB-MI Display Complex Data Types Date: Wed, 30 Sep 2020 20:08:24 +0200 Message-ID: <87v9fvyw6f.fsf@gnus.org> References: <83wolugz2r.fsf@gnu.org> <83va1aq1ui.fsf@gnu.org> <83o972pz92.fsf@gnu.org> <83zhqbe2og.fsf@gnu.org> <83va0tag67.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13242"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 34589@debbugs.gnu.org To: Gustaf Waldemarson Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Sep 30 20:09:31 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kNgXj-0003Ii-By for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 30 Sep 2020 20:09:31 +0200 Original-Received: from localhost ([::1]:53078 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kNgXi-0008BF-0K for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 30 Sep 2020 14:09:30 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60732) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNgXG-0008A1-PN for bug-gnu-emacs@gnu.org; Wed, 30 Sep 2020 14:09:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49753) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kNgXG-0006XI-9C for bug-gnu-emacs@gnu.org; Wed, 30 Sep 2020 14:09:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kNgXF-0005X2-UJ for bug-gnu-emacs@gnu.org; Wed, 30 Sep 2020 14:09:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Lars Ingebrigtsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 30 Sep 2020 18:09:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 34589 X-GNU-PR-Package: emacs Original-Received: via spool by 34589-submit@debbugs.gnu.org id=B34589.160148931721234 (code B ref 34589); Wed, 30 Sep 2020 18:09:01 +0000 Original-Received: (at 34589) by debbugs.gnu.org; 30 Sep 2020 18:08:37 +0000 Original-Received: from localhost ([127.0.0.1]:33066 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kNgWr-0005WQ-0w for submit@debbugs.gnu.org; Wed, 30 Sep 2020 14:08:37 -0400 Original-Received: from quimby.gnus.org ([95.216.78.240]:48288) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kNgWo-0005WC-SQ for 34589@debbugs.gnu.org; Wed, 30 Sep 2020 14:08:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=nrheQT/5puBFBaVQJL8O3XJ5i0HReakjlK5IeMYFIHY=; b=qx4AwHfXTbeooaGTos+Se/B0op kSqteV0fVkxB5cZ0bOP5QLOaxEHoykhv2RQ1rUJDXwoczTqdupRUr1NaEqcbOuz6BvwfzdjnM9crn QJ+y6DByjpfj3L2YEUPzJZ9lugMBcKu0jPYZDH2e87Iy9RZK3+ANfo03raNh21a3WPA4=; Original-Received: from cm-84.212.202.86.getinternet.no ([84.212.202.86] helo=xo) by quimby with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kNgWf-0004I5-Pp; Wed, 30 Sep 2020 20:08:28 +0200 X-Now-Playing: Laub's _Unter Anderen Bedingungen als Liebe_: "Losigkeit" In-Reply-To: (Gustaf Waldemarson's message of "Tue, 5 Nov 2019 11:05:48 +0100") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:189416 Archived-At: Gustaf Waldemarson writes: > After quite some time here, I have finally been able to get the proper > legal confirmation from Arm to submit patches. As far as I understand > things, any patch that I submit for Emacs will now have the copyright > correctly reassigned and should now be usable without any issues. Great! Your patch didn't apply cleanly to Emacs 28, so I've respun it (included below). There was unfortunately no followup on this at the time, and I'm not exactly a gdb expert (cough cough). Could somebody give this a look-over? It looks good to me, but I haven't tested it. > That said, during these months I've been rethinking the variable GDB > window somewhat, and would like to see what people thinks of a rework of > the following kind: > > - Instead of displaying variables as | 'type' | 'name' | 'value' |, > display them as | 'name' | 'short-type' | 'value' |, where > 'short-type' is the first `X' characters of the type name. > > I personally find this to be more useful, especially for C++ template > types which can easily occupy the whole window otherwise. > > - Possibly add a new tab 'behind' the variable window which contains the > /full/ type name. (This part may also have to interface with the new > tabbing interface, something I'll have to look into when I've got some > time.) > > (Also, if interesting, should this kind of rework be submitted as a > separate ticket?) Sure, a separate ticket would be nice. diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el index 086f0b6a08..49ec99fc32 100644 --- a/lisp/progmodes/gdb-mi.el +++ b/lisp/progmodes/gdb-mi.el @@ -4228,7 +4228,7 @@ gdb-select-frame ;; uses "-stack-list-locals --simple-values". Needs GDB 6.1 onwards. (def-gdb-trigger-and-handler gdb-invalidate-locals - (concat (gdb-current-context-command "-stack-list-locals") + (concat (gdb-current-context-command "-stack-list-variables") " --simple-values") gdb-locals-handler gdb-locals-handler-custom '(start update)) @@ -4239,6 +4239,48 @@ gdb-select-frame 'gdb-locals-mode 'gdb-invalidate-locals) + +;; Retrieve the values of all variables before invalidating locals. +(def-gdb-trigger-and-handler + gdb-locals-values + (concat (gdb-current-context-command "-stack-list-variables") + " --all-values") + gdb-locals-values-handler gdb-locals-values-handler-custom + '(start update)) + +(gdb-set-buffer-rules + 'gdb-locals-values-buffer + 'gdb-locals-values-buffer-name + 'gdb-locals-mode + 'gdb-locals-values) + +(defun gdb-locals-values-buffer-name () + (gdb-current-context-buffer-name + (concat "local values of " (gdb-get-target-string)))) + +(defcustom gdb-locals-simple-values-only nil + "Only display simple values in the Locals buffer." + :type 'boolean + :group 'gud + :version "28.1") + +(defcustom gdb-locals-value-limit 100 + "Maximum length the value of a local variable is allowed to be." + :type 'integer + :group 'gud + :version "28.1") + +(defvar gdb-locals-values-table (make-hash-table :test #'equal) + "Mapping of local variable names to a string with their value.") + +(defun gdb-locals-values-handler-custom () + "Store the values of local variables in `gdb-locals-value-map'." + (let ((locals-list (bindat-get-field (gdb-json-partial-output) 'variables))) + (dolist (local locals-list) + (let ((name (bindat-get-field local 'name)) + (value (bindat-get-field local 'value))) + (puthash name value gdb-locals-values-table))))) + (defvar gdb-locals-watch-map (let ((map (make-sparse-keymap))) (suppress-keymap map) @@ -4255,6 +4297,15 @@ gdb-edit-locals-map-1 map) "Keymap to edit value of a simple data type local variable.") +(defun gdb-locals-value-filter (value) + "Filter function for the local variable VALUE." + (let* ((no-nl (replace-regexp-in-string "\n" " " value)) + (str (replace-regexp-in-string "[[:space:]]+" " " no-nl)) + (limit gdb-locals-value-limit)) + (if (>= (length str) limit) + (concat (substring str 0 limit) "...") + str))) + (defun gdb-edit-locals-value (&optional event) "Assign a value to a variable displayed in the locals buffer." (interactive (list last-input-event)) @@ -4267,17 +4318,21 @@ gdb-edit-locals-value (gud-basic-call (concat "-gdb-set variable " var " = " value))))) -;; Don't display values of arrays or structures. -;; These can be expanded using gud-watch. +;; Complex data types are looked up in `gdb-locals-values-table'. (defun gdb-locals-handler-custom () - (let ((locals-list (bindat-get-field (gdb-json-partial-output) 'locals)) + "Handler to rebuild the local variables table buffer." + (let ((locals-list (bindat-get-field (gdb-json-partial-output) 'variables)) (table (make-gdb-table))) (dolist (local locals-list) (let ((name (bindat-get-field local 'name)) (value (bindat-get-field local 'value)) (type (bindat-get-field local 'type))) (when (not value) - (setq value "")) + (setq value + (if gdb-locals-simple-values-only + "" + (gethash name gdb-locals-values-table "")))) + (setq value (gdb-locals-value-filter value)) (if (or (not value) (string-match "0x" value)) (add-text-properties 0 (length name) @@ -4743,6 +4798,8 @@ gdb-setup-windows (expand-file-name gdb-default-window-configuration-file gdb-window-configuration-directory))) ;; Create default layout as before. + ;; Make sure that local values are updated before locals. + (gdb-get-buffer-create 'gdb-locals-values-buffer) (gdb-get-buffer-create 'gdb-locals-buffer) (gdb-get-buffer-create 'gdb-stack-buffer) (gdb-get-buffer-create 'gdb-breakpoints-buffer) -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no