From: William Xu <william.xwl@gmail.com>
To: 34589@debbugs.gnu.org
Subject: bug#34589: 26.1.91; GDB-MI Display Complex Data Types
Date: Sun, 06 Mar 2022 21:44:13 +0100 [thread overview]
Message-ID: <87sfrubyle.fsf@gmail.com> (raw)
In-Reply-To: <CABehr5eM22py479W2mS0cpGrfy2TeHRyMkWNnzGc+kcNHWwaVw@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 308 bytes --]
This patch really makes gdb "Locals" buffer finally useful.
I did a simple test, you can compare the results as shown in attached
screenshots. I have to update the patch to apply to master.
How about merging it to master? From previous posts, it seems there is
no copyright issue any more?
--
William
[-- Attachment #2: after.png --]
[-- Type: image/png, Size: 105085 bytes --]
[-- Attachment #3: before.png --]
[-- Type: image/png, Size: 46868 bytes --]
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: gdb-mi.el.patch --]
[-- Type: text/x-diff, Size: 4449 bytes --]
diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el
index ddccbe80e7..5732501513 100644
--- a/lisp/progmodes/gdb-mi.el
+++ b/lisp/progmodes/gdb-mi.el
@@ -4288,7 +4288,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))
@@ -4299,6 +4299,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-mi--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)
@@ -4315,6 +4357,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))
@@ -4327,17 +4378,22 @@ 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 (gdb-mi--field (gdb-mi--partial-output) 'locals))
+ "Handler to rebuild the local variables table buffer."
+ (let ((locals-list (bindat-get-field (gdb-mi--partial-output) 'variables))
(table (make-gdb-table)))
(dolist (local locals-list)
(let ((name (gdb-mi--field local 'name))
(value (gdb-mi--field local 'value))
(type (gdb-mi--field local 'type)))
(when (not value)
- (setq value "<complex data type>"))
+ (setq value
+ (if gdb-locals-simple-values-only
+ "<complex data type>"
+ (gethash name gdb-locals-values-table "<unavailable>"))))
+ (setq value (gdb-locals-value-filter value))
+
(if (or (not value)
(string-match "0x" value))
(add-text-properties 0 (length name)
@@ -4860,6 +4916,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)
next prev parent reply other threads:[~2022-03-06 20:44 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-20 10:08 bug#34589: 26.1.91; GDB-MI Display Complex Data Types Gustaf Waldemarson
2019-02-20 17:16 ` Eli Zaretskii
2019-02-21 13:42 ` Gustaf Waldemarson
2019-02-23 9:40 ` Eli Zaretskii
2019-02-23 10:01 ` Gustaf Waldemarson
2019-02-23 10:36 ` Eli Zaretskii
2019-02-28 16:05 ` Gustaf Waldemarson
2019-02-28 17:24 ` Andrew W. Nosenko
2019-02-28 17:58 ` Eli Zaretskii
2019-03-01 3:57 ` Richard Stallman
2019-03-02 3:28 ` Richard Stallman
2019-03-03 20:32 ` Gustaf Waldemarson
2019-03-04 3:30 ` Eli Zaretskii
2019-03-04 8:05 ` Gustaf Waldemarson
2019-03-08 9:06 ` Eli Zaretskii
2019-11-05 10:05 ` Gustaf Waldemarson
2020-09-30 18:08 ` Lars Ingebrigtsen
2020-09-30 18:30 ` Eli Zaretskii
2020-04-15 14:54 ` Yuan Fu
2020-04-15 15:05 ` Eli Zaretskii
2022-03-06 20:39 ` William Xu
2022-03-06 20:44 ` William Xu [this message]
2022-03-06 20:46 ` Weilin Xu
2022-03-06 21:56 ` Lars Ingebrigtsen
2022-03-06 22:33 ` William Xu
2022-03-06 23:02 ` Lars Ingebrigtsen
2022-03-07 9:27 ` William Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87sfrubyle.fsf@gmail.com \
--to=william.xwl@gmail.com \
--cc=34589@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).