unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Gustaf Waldemarson <gustaf.waldemarson@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 34589@debbugs.gnu.org
Subject: bug#34589: 26.1.91; GDB-MI Display Complex Data Types
Date: Thu, 21 Feb 2019 14:42:54 +0100	[thread overview]
Message-ID: <CABehr5cEUkmz-QUu4Gkb4-OmaU4XLNuTgP8NOaXfJUnwuBV0Ng@mail.gmail.com> (raw)
In-Reply-To: <83wolugz2r.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 2362 bytes --]

I took a stab at it, but it turned out to be a bit more complicated
than I thought:

- The `-stack-list-locals` accepts one of three flags, 0, 1, or 2 (or
equivalently, --no-values, --all-values or --simple-values).
   - No-values only prints the variable name,
   - All values print the variable name and the associated value.
   - Simple-values print the name, type and value for simple types.
   - There is no option to print everything (name, type and value),
this feels like an oversight in the API, but can be worked around,
sort of.

What I ended up doing was to create a new "handler" that runs before
the original one that records the variable name/value pair in a
hash-table, that the original handler can refer to for the value of
complex data-types. This works. but feels like a significant
work-around.

Additionally, when I was going through the GDB-MI documentation, I
noticed that `-stack-list-locals` is deprecated and should be replaced
with `-stack-list-variables`, so the second patch fixes that.
Incidentally, this also allow function arguments (argv, argc, etc) to
show up in the variable buffer.

I've attached the patches that accomplishes the above, but you may
want to have someone review it that actually knows at bit more about
gdb-mi.el.

I haven't contributed anything before either, so there might very well
be some other details that I've missed.

Best regards,
Gustaf


Den ons 20 feb. 2019 kl 18:16 skrev Eli Zaretskii <eliz@gnu.org>:
>
> > From: Gustaf Waldemarson <gustaf.waldemarson@gmail.com>
> > Date: Wed, 20 Feb 2019 11:08:15 +0100
> >
> > Since as C++ (and other languages) is moving more and more towards these
> > kinds non-simple data types, I figured I should send out a feature
> > request for something like the following:
> >
> > - Remove "--simple-values" by default.
> >
> > - Add a customizable variable such as `gdb-simple-values-only`, which
> >   adds the above flag.
> >
> > - Add a customizable variable such as `gdb-locals-value-limit` to limit
> >   the length a value is allowed to be shown.
> >
> > - Add a simple filter of the retrieved value string to make it fit on a
> >   single line (e.g., a simple version could just remove all newlines).
>
> Thanks.  We don't have an active developer for gdb-mi.el for the
> moment, so please consider writing these changes and submitting the
> patches here.

[-- Attachment #2: 0002-gdb-mi.el-Use-stack-list-variables.patch --]
[-- Type: text/x-patch, Size: 2367 bytes --]

From 054ebfe4cd150cb6d74b26e3e87ea7a32c2b62fc Mon Sep 17 00:00:00 2001
From: Gustaf Waldemarson <gustaf.waldemarson@gmail.com>
Date: Thu, 21 Feb 2019 13:52:21 +0100
Subject: [PATCH 2/2] gdb-mi.el: Use `-stack-list-variables`.

use `-stack-list-variables` instead of the deprecated
`-stack-list-locals`. Additionally, this allow function arguments to
be displayed in the locals buffer.
---
 lisp/progmodes/gdb-mi.el | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el
index 6fb09d1..683bfdb 100644
--- a/lisp/progmodes/gdb-mi.el
+++ b/lisp/progmodes/gdb-mi.el
@@ -4108,7 +4108,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))
@@ -4123,7 +4123,7 @@ gdb-select-frame
 ;; Retrieve the values of all variables before invalidating locals.
 (def-gdb-trigger-and-handler
   gdb-locals-values
-  (concat (gdb-current-context-command "-stack-list-locals")
+  (concat (gdb-current-context-command "-stack-list-variables")
           " --all-values")
   gdb-locals-values-handler gdb-locals-values-handler-custom
   '(start update))
@@ -4157,7 +4157,7 @@ gdb-locals-values-table
 
 (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) 'locals)))
+  (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)))
@@ -4207,7 +4207,7 @@ gdb-edit-locals-value
 ;; Complex data types are looked up in `gdb-locals-values-table'.
 (defun gdb-locals-handler-custom ()
   "Handler to rebuild the local variables table buffer."
-  (let ((locals-list (bindat-get-field (gdb-json-partial-output) 'locals))
+  (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))
-- 
2.7.4


[-- Attachment #3: 0001-gdb-mi.el-Display-complex-data-types.patch --]
[-- Type: text/x-patch, Size: 4863 bytes --]

From ebed165be8af3d7e145e1defa97892fdf9ddf560 Mon Sep 17 00:00:00 2001
From: Gustaf Waldemarson <gustaf.waldemarson@gmail.com>
Date: Thu, 21 Feb 2019 13:37:14 +0100
Subject: [PATCH 1/2] gdb-mi.el: Display complex data-types.

Create a new gdb buffer for extracting local variable values. To
extract the values for 'complex' data-types, the command
`-stack-list-locals` is used with the `--all-values` flag.

The extracted values are then stored in a hash-table for later use in
the `gdb-locals-handler-custom` that performs the actual update of the
Local variable buffer.

All variable values are filtered to fit it into a single line, being
truncated as necessary by the user customizable option
`gdb-locals-value-limit`.

The old behavior of hiding complex values can be restored using the
customizable `gdb-locals-simple-values-only` option.
---
 lisp/progmodes/gdb-mi.el | 69 +++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 66 insertions(+), 3 deletions(-)

diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el
index b63f82b..6fb09d1 100644
--- a/lisp/progmodes/gdb-mi.el
+++ b/lisp/progmodes/gdb-mi.el
@@ -4119,6 +4119,51 @@ 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-locals")
+          " --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)
+
+
+(defcustom gdb-locals-value-limit 100
+  "Maximum length the value of a local variable is allowed to be."
+  :type 'integer
+  :group 'gud)
+
+
+(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) 'locals)))
+    (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)
@@ -4135,6 +4180,17 @@ 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))
@@ -4147,9 +4203,10 @@ 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 ()
+  "Handler to rebuild the local variables table buffer."
   (let ((locals-list (bindat-get-field (gdb-json-partial-output) 'locals))
         (table (make-gdb-table)))
     (dolist (local locals-list)
@@ -4157,7 +4214,11 @@ gdb-locals-handler-custom
             (value (bindat-get-field local 'value))
             (type (bindat-get-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)
@@ -4581,6 +4642,8 @@ gdb-set-window-buffer
 
 (defun gdb-setup-windows ()
   "Layout the window pattern for option `gdb-many-windows'."
+  ;; 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)
-- 
2.7.4


  reply	other threads:[~2019-02-21 13:42 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 [this message]
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
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=CABehr5cEUkmz-QUu4Gkb4-OmaU4XLNuTgP8NOaXfJUnwuBV0Ng@mail.gmail.com \
    --to=gustaf.waldemarson@gmail.com \
    --cc=34589@debbugs.gnu.org \
    --cc=eliz@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).