all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#39180: 27.0.50; [PATCH] Use expressions as memory location in gdb-mi memory buffer
@ 2020-01-18 20:54 Yuan Fu
  2020-01-31 10:05 ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Yuan Fu @ 2020-01-18 20:54 UTC (permalink / raw)
  To: 39180

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

Currently gdb-mi does allow expressions as memory address, but it translates it to a fixed address. This patch makes gdb to store the expression and re-evaluate on updates. So the address changes as expression’s value changes.


[-- Attachment #2: memory.patch --]
[-- Type: application/octet-stream, Size: 8762 bytes --]

From 932a0e0bbec7939a89431bdc31316afbf2d23cde Mon Sep 17 00:00:00 2001
From: Yuan Fu <casouri@gmail.com>
Date: Sat, 5 Oct 2019 22:42:07 -0400
Subject: [PATCH 1/4] Enhance support for expressions as memory address
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Before the memory buffer evaluates the expression as address
and use the fixed result in each stop. This change stores the
expression itself and reevaluates it in each stop for an address.
Then displays the value of the memory at that address.

lisp/progmodes/gdb-mi.el (gdb-memory-address-expression): new
  (gdb-memory-address): change default value, add docstring
  (def-gdb-trigger-and-handler gdb-invalidate-memory,
  gdb-memory-set-address): replace ’gdb-memory-address’ with
    ’gdb-memory-address-expression’
  (gdb-memory-header): Add display for ’gdb-memory-address-expression’,
    move the mouse event from address to expression
---
 lisp/progmodes/gdb-mi.el | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el
index b08d487af3..bd4d216860 100644
--- a/lisp/progmodes/gdb-mi.el
+++ b/lisp/progmodes/gdb-mi.el
@@ -3445,7 +3445,7 @@ gdb-memory-unit
 (def-gdb-trigger-and-handler
   gdb-invalidate-memory
   (format "-data-read-memory %s %s %d %d %d"
-          gdb-memory-address
+          (gdb-mi-quote gdb-memory-address-expression)
           gdb-memory-format
           gdb-memory-unit
           gdb-memory-rows
@@ -3535,7 +3535,7 @@ gdb-memory-set-address
   "Set the start memory address."
   (interactive)
   (let ((arg (read-from-minibuffer "Memory address: ")))
-    (setq gdb-memory-address arg))
+    (setq gdb-memory-address-expression arg))
   (gdb-invalidate-memory 'update))
 
 (defmacro def-gdb-set-positive-number (name variable echo-string &optional doc)
@@ -3718,7 +3718,15 @@ gdb-memory-font-lock-keywords
 (defvar gdb-memory-header
   '(:eval
     (concat
-     "Start address["
+     "Start address "
+     (propertize gdb-memory-address-expression
+                 'face font-lock-warning-face
+                 'help-echo "mouse-1: set start address"
+                 'mouse-face 'mode-line-highlight
+                 'local-map (gdb-make-header-line-mouse-map
+                             'mouse-1
+                             #'gdb-memory-set-address-event))
+     " ["
      (propertize "-"
                  'face font-lock-warning-face
                  'help-echo "mouse-1: decrement address"
@@ -3736,12 +3744,7 @@ gdb-memory-header
                              #'gdb-memory-show-next-page))
      "]: "
      (propertize gdb-memory-address
-                 'face font-lock-warning-face
-                 'help-echo "mouse-1: set start address"
-                 'mouse-face 'mode-line-highlight
-                 'local-map (gdb-make-header-line-mouse-map
-                             'mouse-1
-                             #'gdb-memory-set-address-event))
+                 'face font-lock-warning-face)
      "  Rows: "
      (propertize (number-to-string gdb-memory-rows)
                  'face font-lock-warning-face
-- 
2.24.1


From d4e98f53dcb228b58f6c72b41ce2150160e863d7 Mon Sep 17 00:00:00 2001
From: Yuan Fu <casouri@gmail.com>
Date: Mon, 7 Oct 2019 20:36:23 -0400
Subject: [PATCH 2/4] Fix memory buffer code in gdb-mi
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* lisp/progmodes/gdb-mi.el (gdb-read-memory-custom):
Break infinite loop. Change ’error’ to ’user-error’
---
 lisp/progmodes/gdb-mi.el | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el
index bd4d216860..662671885c 100644
--- a/lisp/progmodes/gdb-mi.el
+++ b/lisp/progmodes/gdb-mi.el
@@ -3498,10 +3498,12 @@ gdb-read-memory-custom
                                             gdb-memory-format)))))
             (newline)))
       ;; Show last page instead of empty buffer when out of bounds
-      (progn
-        (let ((gdb-memory-address gdb-memory-last-address))
+      (when gdb-memory-last-address
+        (let ((gdb-memory-address-expression gdb-memory-last-address))
+          ;; avoid infinite loop
+          (setq gdb-memory-last-address nil)
           (gdb-invalidate-memory 'update)
-          (error err-msg))))))
+          (user-error "Error when retrieving memory: %s Displaying last successful page" err-msg))))))
 
 (defvar gdb-memory-mode-map
   (let ((map (make-sparse-keymap)))
-- 
2.24.1


From dc5008ac30718fd1e1920bb07300a0a2e10835c4 Mon Sep 17 00:00:00 2001
From: Yuan Fu <casouri@gmail.com>
Date: Mon, 7 Oct 2019 20:52:15 -0400
Subject: [PATCH 3/4] Protect against nil memory address in gdb-mi

* lisp/progmodes/gdb-mi.el (gdb-memory-header):
Protect against nil value
---
 lisp/progmodes/gdb-mi.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el
index 662671885c..eec11ebf0c 100644
--- a/lisp/progmodes/gdb-mi.el
+++ b/lisp/progmodes/gdb-mi.el
@@ -3721,7 +3721,7 @@ gdb-memory-header
   '(:eval
     (concat
      "Start address "
-     (propertize gdb-memory-address-expression
+     (propertize (or gdb-memory-address-expression "N/A")
                  'face font-lock-warning-face
                  'help-echo "mouse-1: set start address"
                  'mouse-face 'mode-line-highlight
@@ -3745,7 +3745,7 @@ gdb-memory-header
                              'mouse-1
                              #'gdb-memory-show-next-page))
      "]: "
-     (propertize gdb-memory-address
+     (propertize (or gdb-memory-address "N/A")
                  'face font-lock-warning-face)
      "  Rows: "
      (propertize (number-to-string gdb-memory-rows)
-- 
2.24.1


From 5b784a7312623b83dbeecafcbe0421c1035f9483 Mon Sep 17 00:00:00 2001
From: Yuan Fu <casouri@gmail.com>
Date: Mon, 7 Oct 2019 21:17:01 -0400
Subject: [PATCH 4/4] =?UTF-8?q?Display=20warning=20when=20address=20expres?=
 =?UTF-8?q?sion=20and=20address=20doesn=E2=80=99t=20match?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* lisp/progmodes/gdb-mi.el (gdb--memory-display-warning): new
(gdb-read-memory-custom, gdb-memory-header): Add warning
---
 lisp/progmodes/gdb-mi.el | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el
index eec11ebf0c..bdd01e0747 100644
--- a/lisp/progmodes/gdb-mi.el
+++ b/lisp/progmodes/gdb-mi.el
@@ -112,6 +112,12 @@ gdb-memory-next-page
   "Address of next memory page for program memory buffer.")
 (defvar	gdb-memory-prev-page nil
   "Address of previous memory page for program memory buffer.")
+(defvar-local gdb--memory-display-warning nil
+  "Display warning on memory header if t.
+
+When error occurs when retrieving memory, gdb-mi displays the last
+successful page. In that case the expression might not match the
+memory displayed.")
 
 (defvar gdb-thread-number nil
   "Main current thread.
@@ -3485,6 +3491,9 @@ gdb-read-memory-custom
          (err-msg (bindat-get-field res 'msg)))
     (if (not err-msg)
         (let ((memory (bindat-get-field res 'memory)))
+          (when gdb-memory-last-address
+            ;; nil means last retrieve emits error or just started the session
+            (setq gdb--memory-display-warning nil))
           (setq gdb-memory-address (bindat-get-field res 'addr))
           (setq gdb-memory-next-page (bindat-get-field res 'next-page))
           (setq gdb-memory-prev-page (bindat-get-field res 'prev-page))
@@ -3501,7 +3510,8 @@ gdb-read-memory-custom
       (when gdb-memory-last-address
         (let ((gdb-memory-address-expression gdb-memory-last-address))
           ;; avoid infinite loop
-          (setq gdb-memory-last-address nil)
+          (setq gdb-memory-last-address nil
+                gdb--memory-display-warning t)
           (gdb-invalidate-memory 'update)
           (user-error "Error when retrieving memory: %s Displaying last successful page" err-msg))))))
 
@@ -3728,6 +3738,9 @@ gdb-memory-header
                  'local-map (gdb-make-header-line-mouse-map
                              'mouse-1
                              #'gdb-memory-set-address-event))
+     (if gdb--memory-display-warning
+         (propertize " !" 'face '(:inherit error :weight bold))
+       "")
      " ["
      (propertize "-"
                  'face font-lock-warning-face
-- 
2.24.1


[-- Attachment #3: Type: text/plain, Size: 9034 bytes --]



In GNU Emacs 27.0.50 (build 3, x86_64-apple-darwin19.0.0, NS appkit-1894.10 Version 10.15.1 (Build 19B88))
of 2019-11-30 built on missSilver
Repository revision: e2828795d73637577c7726965974a047fe2d7119
Repository branch: master
Windowing system distributor 'Apple', version 10.3.1894
System Description:  Mac OS X 10.15.2

Recent messages:
Checking 24 files in /Users/yuan/attic/emacs/lisp/cedet...
Checking 59 files in /Users/yuan/attic/emacs/lisp/calendar...
Checking 87 files in /Users/yuan/attic/emacs/lisp/calc...
Checking 113 files in /Users/yuan/attic/emacs/lisp/obsolete...
Checking for load-path shadows...done
Auto-saving...
Quit
C-x C-g is undefined
Quit
Buffer *unsent mail to bug-gnu-emacs@gnu.org*<2> modified; kill anyway? (y or n) y

Configured using:
'configure --with-modules --with-pdumper=yes
--oldincludedir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/libxml2/'

Configured features:
NOTIFY KQUEUE ACL GNUTLS LIBXML2 ZLIB TOOLKIT_SCROLL_BARS NS MODULES
THREADS PDUMPER LCMS2

Important settings:
  value of $LC_CTYPE: UTF-8
  value of $LANG: en_CN.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Emacs-Lisp

Minor modes in effect:
  magit-todos-mode: t
  bug-reference-prog-mode: t
  desktop-save-mode: t
  ghelp-global-minor-mode: t
  minibuffer-electric-default-mode: t
  flymake-mode: t
  global-magit-file-mode: t
  magit-file-mode: t
  global-git-commit-mode: t
  async-bytecomp-package-mode: t
  shell-dirtrack-mode: t
  flyspell-mode: t
  outshine-mode: t
  ws-butler-global-mode: t
  ws-butler-mode: t
  minions-mode: t
  eyebrowse-mode: t
  savehist-mode: t
  global-hl-todo-mode: t
  hl-todo-mode: t
  global-highlight-parentheses-mode: t
  highlight-parentheses-mode: t
  rainbow-delimiters-mode: t
  global-undo-tree-mode: t
  undo-tree-mode: t
  electric-pair-mode: t
  winner-mode: t
  aggressive-indent-mode: t
  ivy-prescient-mode: t
  prescient-persist-mode: t
  recentf-mode: t
  which-key-mode: t
  general-override-mode: t
  outline-minor-mode: t
  ivy-mode: t
  company-mode: t
  override-global-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  electric-quote-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  transient-mark-mode: t
  hs-minor-mode: t

Load-path shadows:
/Users/yuan/.emacs.d/ranch/winman/windman hides /Users/yuan/.emacs.d/ranch/windman/windman
/Users/yuan/.emacs.d/ranch/nerd-font/test/test-helper hides /Users/yuan/.emacs.d/ranch/doom-themes/test/test-helper
/Users/yuan/.emacs.d/ranch/julia-mode/julia-mode hides /Users/yuan/.emacs.d/package/julia-mode-20190813.1326/julia-mode
/Users/yuan/.emacs.d/ranch/julia-mode/julia-latexsubs hides /Users/yuan/.emacs.d/package/julia-mode-20190813.1326/julia-latexsubs
/Users/yuan/.emacs.d/ranch/matlab-emacs/mlint hides /Users/yuan/.emacs.d/package/matlab-mode-20180928.1526/mlint
/Users/yuan/.emacs.d/ranch/matlab-emacs/company-matlab-shell hides /Users/yuan/.emacs.d/package/matlab-mode-20180928.1526/company-matlab-shell
/Users/yuan/.emacs.d/ranch/matlab-emacs/linemark hides /Users/yuan/.emacs.d/package/matlab-mode-20180928.1526/linemark
/Users/yuan/.emacs.d/ranch/matlab-emacs/semanticdb-matlab hides /Users/yuan/.emacs.d/package/matlab-mode-20180928.1526/semanticdb-matlab
/Users/yuan/.emacs.d/ranch/matlab-emacs/semantic-matlab hides /Users/yuan/.emacs.d/package/matlab-mode-20180928.1526/semantic-matlab
/Users/yuan/.emacs.d/ranch/matlab-emacs/srecode-matlab hides /Users/yuan/.emacs.d/package/matlab-mode-20180928.1526/srecode-matlab
/Users/yuan/.emacs.d/ranch/matlab-emacs/matlab hides /Users/yuan/.emacs.d/package/matlab-mode-20180928.1526/matlab
/Users/yuan/.emacs.d/ranch/matlab-emacs/cedet-matlab hides /Users/yuan/.emacs.d/package/matlab-mode-20180928.1526/cedet-matlab
/Users/yuan/.emacs.d/ranch/matlab-emacs/tlc hides /Users/yuan/.emacs.d/package/matlab-mode-20180928.1526/tlc
/Users/yuan/.emacs.d/ranch/matlab-emacs/matlab-publish hides /Users/yuan/.emacs.d/package/matlab-mode-20180928.1526/matlab-publish
/Users/yuan/.emacs.d/ranch/matlab-emacs/matlab-mode-pkg hides /Users/yuan/.emacs.d/package/matlab-mode-20180928.1526/matlab-mode-pkg
/Users/yuan/.emacs.d/package/faceup-20170925.1946/faceup hides /Users/yuan/attic/emacs/lisp/emacs-lisp/faceup

Features:
(magit-todos pcre2el rxt re-builder grep checkdoc lisp-mnt bug-reference
vc-mtn vc-hg ffap tramp tramp-loaddefs trampver tramp-integration
files-x tramp-compat parse-time iso8601 ls-lisp shadow sort mail-extr
emacsbug sendmail vc-git vc-bzr vc-src vc-sccs vc-svn vc-cvs vc-rcs vc
vc-dispatcher magit-bookmark bookmark company-oddmuse company-keywords
company-etags etags fileloop company-gtags company-dabbrev-code
company-dabbrev company-files company-capf company-cmake company-xcode
company-clang company-semantic company-eclim company-template
company-bbdb hideshow desktop frameset trivial-copy ghelp-eglot
ghelp-helpful ghelp-builtin ghelp cus-edit cus-start cus-load
luna-publish utility pause luna-general-config minibuf-eldef eglot array
jsonrpc ert pp ewoc debug flymake-proc flymake warnings url-util
magit-submodule magit-obsolete magit-blame magit-stash magit-reflog
magit-bisect magit-push magit-pull magit-fetch magit-clone magit-remote
magit-commit magit-sequence magit-notes magit-worktree magit-tag
magit-merge magit-branch magit-reset magit-files magit-refs magit-status
magit magit-repos magit-apply magit-wip magit-log which-func magit-diff
smerge-mode diff-mode magit-core magit-autorevert autorevert filenotify
magit-margin magit-transient magit-process magit-mode transient
git-commit magit-git magit-section magit-utils crm log-edit message rmc
puny rfc822 mml mml-sec epa derived epg epg-config gnus-util rmail
rmail-loaddefs text-property-search mm-decode mm-bodies mm-encode
mail-parse rfc2231 rfc2047 rfc2045 mm-util ietf-drums mail-prsvr
mailabbrev mail-utils gmm-utils mailheader pcvs-util add-log with-editor
async-bytecomp async shell server flyspell ispell outshine
outshine-org-cmds outorg isolate inline expand-region
text-mode-expansions the-org-mode-expansions er-basic-expansions
thingatpt expand-region-core expand-region-custom ws-butler minions
eyebrowse savehist buffer-move windmove hl-todo highlight-parentheses
rainbow-delimiters doom-cyberpunk-theme undo-tree diff
doom-one-light-theme elec-pair winner doom-themes doom-themes-base
windman aggressive-indent find-char ivy-prescient prescient recentf-ext
recentf tree-widget wid-edit which-key general helpful imenu trace
edebug backtrace info-look f dash-functional help-fns radix-tree
elisp-refs s loop dash org-element avl-tree generator org advice
org-macro org-footnote org-pcomplete pcomplete org-list org-faces
org-entities time-date noutline outline org-version ob-emacs-lisp ob
ob-tangle org-src ob-ref ob-lob ob-table ob-keys ob-exp ob-comint
ob-core ob-eval org-compat org-macs org-loaddefs format-spec find-func
cal-menu calendar cal-loaddefs counsel xdg xref project dired
dired-loaddefs compile comint ansi-color swiper cl-extra help-mode ivy
delsel ring colir color ivy-overlay company edmacro kmacro pcase
use-package use-package-ensure use-package-delight use-package-diminish
use-package-bind-key bind-key easy-mmode use-package-core finder-inf
tex-site info cowboy package easymenu browse-url url-handlers url-parse
auth-source cl-seq eieio eieio-core cl-macs eieio-loaddefs
password-cache json subr-x map url-vars cl-loaddefs cl-lib lunary
lunary-ui luna-f rx seq byte-opt gv bytecomp byte-compile cconv tooltip
eldoc electric uniquify ediff-hook vc-hooks lisp-float-type mwheel
term/ns-win ns-win ucs-normalize mule-util term/common-win tool-bar dnd
fontset image regexp-opt fringe tabulated-list replace newcomment
text-mode elisp-mode lisp-mode prog-mode register page tab-bar menu-bar
rfn-eshadow isearch timer select scroll-bar mouse jit-lock font-lock
syntax facemenu font-core term/tty-colors frame minibuffer cl-generic
cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese composite charscript charprop
case-table epa-hook jka-cmpr-hook help simple abbrev obarray
cl-preloaded nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote threads kqueue cocoa ns
lcms2 multi-tty make-network-process emacs)

Memory information:
((conses 16 197959 23437)
(symbols 48 9374 49)
(strings 32 38335 2058)
(string-bytes 1 1116712)
(vectors 16 24652)
(vector-slots 8 289694 28446)
(floats 8 511 434)
(intervals 56 14675 1317)
(buffers 1000 27))

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* bug#39180: 27.0.50; [PATCH] Use expressions as memory location in gdb-mi memory buffer
  2020-01-18 20:54 bug#39180: 27.0.50; [PATCH] Use expressions as memory location in gdb-mi memory buffer Yuan Fu
@ 2020-01-31 10:05 ` Eli Zaretskii
  2020-02-01  2:25   ` Yuan Fu
  0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2020-01-31 10:05 UTC (permalink / raw)
  To: Yuan Fu; +Cc: 39180

> From: Yuan Fu <casouri@gmail.com>
> Date: Sat, 18 Jan 2020 15:54:35 -0500
> 
> Currently gdb-mi does allow expressions as memory address, but it translates it to a fixed address. This patch makes gdb to store the expression and re-evaluate on updates. So the address changes as expression’s value changes.

Thanks.

Are these 4 patches needed to add the above improvement, or is each
part of the series independent, and could be applied on its own right?

If the entire series should be applied in a single transaction, please
make then a single patch, as that makes it easier to review and
apply.  Otherwise, please explain what is the rationale for each part
separately, because I don't think I understand it.

> Before the memory buffer evaluates the expression as address
> and use the fixed result in each stop. This change stores the
> expression itself and reevaluates it in each stop for an address.
> Then displays the value of the memory at that address.

Two spaces between sentences (here and elsewhere in the patch),
please.

> lisp/progmodes/gdb-mi.el (gdb-memory-address-expression): new
>   (gdb-memory-address): change default value, add docstring
>   (def-gdb-trigger-and-handler gdb-invalidate-memory,
>   gdb-memory-set-address): replace ’gdb-memory-address’ with
>     ’gdb-memory-address-expression’
>   (gdb-memory-header): Add display for ’gdb-memory-address-expression’,
>     move the mouse event from address to expression

Please quote symbols 'like this'.

> * lisp/progmodes/gdb-mi.el (gdb-read-memory-custom):
> Break infinite loop. Change ’error’ to ’user-error’

I don't understand what infinite loop are you alluding to here, and
how did it come into existence.

> * lisp/progmodes/gdb-mi.el (gdb-memory-header):
> Protect against nil value

And what is the problem you are trying to solve here?

> * lisp/progmodes/gdb-mi.el (gdb--memory-display-warning): new
> (gdb-read-memory-custom, gdb-memory-header): Add warning

And what is this part about?





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#39180: 27.0.50; [PATCH] Use expressions as memory location in gdb-mi memory buffer
  2020-01-31 10:05 ` Eli Zaretskii
@ 2020-02-01  2:25   ` Yuan Fu
  2020-02-08  9:51     ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Yuan Fu @ 2020-02-01  2:25 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 39180

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



> On Jan 31, 2020, at 5:05 AM, Eli Zaretskii <eliz@gnu.org> wrote:
> 
>> From: Yuan Fu <casouri@gmail.com>
>> Date: Sat, 18 Jan 2020 15:54:35 -0500
>> 
>> Currently gdb-mi does allow expressions as memory address, but it translates it to a fixed address. This patch makes gdb to store the expression and re-evaluate on updates. So the address changes as expression’s value changes.
> 
> Thanks.
> 
> Are these 4 patches needed to add the above improvement, or is each
> part of the series independent, and could be applied on its own right?
> 

I merged them into one.

> If the entire series should be applied in a single transaction, please
> make then a single patch, as that makes it easier to review and
> apply.  Otherwise, please explain what is the rationale for each part
> separately, because I don't think I understand it.
> 
>> Before the memory buffer evaluates the expression as address
>> and use the fixed result in each stop. This change stores the
>> expression itself and reevaluates it in each stop for an address.
>> Then displays the value of the memory at that address.
> 
> Two spaces between sentences (here and elsewhere in the patch),
> please.
> 
>> lisp/progmodes/gdb-mi.el (gdb-memory-address-expression): new
>>  (gdb-memory-address): change default value, add docstring
>>  (def-gdb-trigger-and-handler gdb-invalidate-memory,
>>  gdb-memory-set-address): replace ’gdb-memory-address’ with
>>    ’gdb-memory-address-expression’
>>  (gdb-memory-header): Add display for ’gdb-memory-address-expression’,
>>    move the mouse event from address to expression
> 
> Please quote symbols 'like this'.

Both fixed.

> 
>> * lisp/progmodes/gdb-mi.el (gdb-read-memory-custom):
>> Break infinite loop. Change ’error’ to ’user-error’
> 
> I don't understand what infinite loop are you alluding to here, and
> how did it come into existence.

Added some comments to explain.

> 
>> * lisp/progmodes/gdb-mi.el (gdb-memory-header):
>> Protect against nil value
> 
> And what is the problem you are trying to solve here?

Added some comments.

> 
>> * lisp/progmodes/gdb-mi.el (gdb--memory-display-warning): new
>> (gdb-read-memory-custom, gdb-memory-header): Add warning
> 
> And what is this part about?

Added some explanation in commit message and docstring of gdb--memory-display-warning.

And here is the new patch.

Yuan


[-- Attachment #2: memory-fixed.patch --]
[-- Type: application/octet-stream, Size: 6702 bytes --]

From 6be6b8aa1215aeac0cbed7432b980408b1275b24 Mon Sep 17 00:00:00 2001
From: Yuan Fu <casouri@gmail.com>
Date: Sat, 5 Oct 2019 22:42:07 -0400
Subject: [PATCH] Enhance memory buffer in gdb-mi

1. Enhance support for expressions as memory address

Before, the memory buffer evaluates the expression as address and use
the fixed result in each stop.  This change makes gdb store the
expression itself and reevaluates it in each stop for an address.

We also add a warning (a red bold exclamation mark) on the header line
when the content of the page doesn't represent the memory location
user requested for.  That happends when some error occurs and we
display the last successful page.

lisp/progmodes/gdb-mi.el (gdb-memory-address-expression,
gdb--memory-display-warning): New variables.
(gdb-memory-address): Change default value to nil; add docstring.
(def-gdb-trigger-and-handler, gdb-invalidate-memory,
gdb-memory-set-address): Replace 'gdb-memory-address' with
'gdb-memory-address-expression'.
(gdb-memory-header): Add code to display
'gdb-memory-address-expression' on header line.  Move the mouse event
from address to expression.  Add code to display the warning.
(gdb-memory-header): Fix the error from
'propertize' when 'gdb-memory-address-expression' or
'gdb-memory-address' is nil.
(gdb-read-memory-custom): Change 'error' to 'user-error'.  Add code to
display the warning.
---
 lisp/progmodes/gdb-mi.el | 57 +++++++++++++++++++++++++++++-----------
 1 file changed, 42 insertions(+), 15 deletions(-)

diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el
index 60852e4ad6..1384837a04 100644
--- a/lisp/progmodes/gdb-mi.el
+++ b/lisp/progmodes/gdb-mi.el
@@ -105,13 +105,24 @@ tool-bar-map
 (defvar speedbar-initial-expansion-list-name)
 (defvar speedbar-frame)
 
-(defvar	gdb-memory-address "main")
-(defvar	gdb-memory-last-address nil
+(defvar-local gdb-memory-address-expression "main"
+  "This expression is passed to gdb.
+Possible value: main, $rsp, x+3.")
+(defvar-local gdb-memory-address nil
+  "Address of memory display.")
+(defvar-local gdb-memory-last-address nil
   "Last successfully accessed memory address.")
 (defvar	gdb-memory-next-page nil
   "Address of next memory page for program memory buffer.")
 (defvar	gdb-memory-prev-page nil
   "Address of previous memory page for program memory buffer.")
+(defvar-local gdb--memory-display-warning nil
+  "Display warning on memory header if t.
+
+When error occurs when retrieving memory, gdb-mi displays the
+last successful page.  In that case the expression might not
+match the memory displayed.  We want to let the user be aware of
+that, so display a warning exclamation mark in the header line.")
 
 (defvar gdb-thread-number nil
   "Main current thread.
@@ -3444,7 +3455,7 @@ gdb-memory-unit
 (def-gdb-trigger-and-handler
   gdb-invalidate-memory
   (format "-data-read-memory %s %s %d %d %d"
-          gdb-memory-address
+          (gdb-mi-quote gdb-memory-address-expression)
           gdb-memory-format
           gdb-memory-unit
           gdb-memory-rows
@@ -3484,6 +3495,9 @@ gdb-read-memory-custom
          (err-msg (bindat-get-field res 'msg)))
     (if (not err-msg)
         (let ((memory (bindat-get-field res 'memory)))
+          (when gdb-memory-last-address
+            ;; Nil means last retrieve emits error or just started the session.
+            (setq gdb--memory-display-warning nil))
           (setq gdb-memory-address (bindat-get-field res 'addr))
           (setq gdb-memory-next-page (bindat-get-field res 'next-page))
           (setq gdb-memory-prev-page (bindat-get-field res 'prev-page))
@@ -3497,10 +3511,15 @@ gdb-read-memory-custom
                                             gdb-memory-format)))))
             (newline)))
       ;; Show last page instead of empty buffer when out of bounds
-      (progn
-        (let ((gdb-memory-address gdb-memory-last-address))
+      (when gdb-memory-last-address
+        (let ((gdb-memory-address-expression gdb-memory-last-address))
+          ;; If we don't set `gdb-memory-last-address' to nil,
+          ;; `gdb-invalidate-memory' eventually calls
+          ;; `gdb-read-memory-custom', making an infinite loop.
+          (setq gdb-memory-last-address nil
+                gdb--memory-display-warning t)
           (gdb-invalidate-memory 'update)
-          (error err-msg))))))
+          (user-error "Error when retrieving memory: %s Displaying last successful page" err-msg))))))
 
 (defvar gdb-memory-mode-map
   (let ((map (make-sparse-keymap)))
@@ -3534,7 +3553,7 @@ gdb-memory-set-address
   "Set the start memory address."
   (interactive)
   (let ((arg (read-from-minibuffer "Memory address: ")))
-    (setq gdb-memory-address arg))
+    (setq gdb-memory-address-expression arg))
   (gdb-invalidate-memory 'update))
 
 (defmacro def-gdb-set-positive-number (name variable echo-string &optional doc)
@@ -3717,7 +3736,19 @@ gdb-memory-font-lock-keywords
 (defvar gdb-memory-header
   '(:eval
     (concat
-     "Start address["
+     "Start address "
+     ;; If `gdb-memory-address-expression' is nil, `propertize' would error.
+     (propertize (or gdb-memory-address-expression "N/A")
+                 'face font-lock-warning-face
+                 'help-echo "mouse-1: set start address"
+                 'mouse-face 'mode-line-highlight
+                 'local-map (gdb-make-header-line-mouse-map
+                             'mouse-1
+                             #'gdb-memory-set-address-event))
+     (if gdb--memory-display-warning
+         (propertize " !" 'face '(:inherit error :weight bold))
+       "")
+     " ["
      (propertize "-"
                  'face font-lock-warning-face
                  'help-echo "mouse-1: decrement address"
@@ -3734,13 +3765,9 @@ gdb-memory-header
                              'mouse-1
                              #'gdb-memory-show-next-page))
      "]: "
-     (propertize gdb-memory-address
-                 'face font-lock-warning-face
-                 'help-echo "mouse-1: set start address"
-                 'mouse-face 'mode-line-highlight
-                 'local-map (gdb-make-header-line-mouse-map
-                             'mouse-1
-                             #'gdb-memory-set-address-event))
+     ;; If `gdb-memory-address' is nil, `propertize' would error.
+     (propertize (or gdb-memory-address "N/A")
+                 'face font-lock-warning-face)
      "  Rows: "
      (propertize (number-to-string gdb-memory-rows)
                  'face font-lock-warning-face
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* bug#39180: 27.0.50; [PATCH] Use expressions as memory location in gdb-mi memory buffer
  2020-02-01  2:25   ` Yuan Fu
@ 2020-02-08  9:51     ` Eli Zaretskii
  2020-02-10  4:45       ` Yuan Fu
  0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2020-02-08  9:51 UTC (permalink / raw)
  To: Yuan Fu; +Cc: 39180-done

> From: Yuan Fu <casouri@gmail.com>
> Date: Fri, 31 Jan 2020 21:25:00 -0500
> Cc: 39180@debbugs.gnu.org
> 
> And here is the new patch.

Thanks, I pushed it to the master branch.  I had to make some minor
editing changes in the commit log message; please see what I changed
and try to follow this style in the future.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#39180: 27.0.50; [PATCH] Use expressions as memory location in gdb-mi memory buffer
  2020-02-08  9:51     ` Eli Zaretskii
@ 2020-02-10  4:45       ` Yuan Fu
  0 siblings, 0 replies; 5+ messages in thread
From: Yuan Fu @ 2020-02-10  4:45 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 39180-done



> On Feb 8, 2020, at 4:51 AM, Eli Zaretskii <eliz@gnu.org> wrote:
> 
>> From: Yuan Fu <casouri@gmail.com>
>> Date: Fri, 31 Jan 2020 21:25:00 -0500
>> Cc: 39180@debbugs.gnu.org
>> 
>> And here is the new patch.
> 
> Thanks, I pushed it to the master branch.  I had to make some minor
> editing changes in the commit log message; please see what I changed
> and try to follow this style in the future.

Got it. I will.

Yuan





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-02-10  4:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-01-18 20:54 bug#39180: 27.0.50; [PATCH] Use expressions as memory location in gdb-mi memory buffer Yuan Fu
2020-01-31 10:05 ` Eli Zaretskii
2020-02-01  2:25   ` Yuan Fu
2020-02-08  9:51     ` Eli Zaretskii
2020-02-10  4:45       ` Yuan Fu

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.