Skip to content

Commit 07e1852

Browse files
casouriEli-Zaretskii
authored andcommitted
Enhance memory address evaluation in gdb-mi
Before, the memory buffer evaluated the expression as address and used the fixed result in each stop. This change store the expression itself and reevaluates it in each stop to yield 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 in evaluating the address, and we display the last successfully displayed memory 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. (Bug#39180)
1 parent 30abcda commit 07e1852

File tree

1 file changed

+42
-15
lines changed

1 file changed

+42
-15
lines changed

lisp/progmodes/gdb-mi.el

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,24 @@
105105
(defvar speedbar-initial-expansion-list-name)
106106
(defvar speedbar-frame)
107107

108-
(defvar gdb-memory-address "main")
109-
(defvar gdb-memory-last-address nil
108+
(defvar-local gdb-memory-address-expression "main"
109+
"This expression is passed to gdb.
110+
Possible value: main, $rsp, x+3.")
111+
(defvar-local gdb-memory-address nil
112+
"Address of memory display.")
113+
(defvar-local gdb-memory-last-address nil
110114
"Last successfully accessed memory address.")
111115
(defvar gdb-memory-next-page nil
112116
"Address of next memory page for program memory buffer.")
113117
(defvar gdb-memory-prev-page nil
114118
"Address of previous memory page for program memory buffer.")
119+
(defvar-local gdb--memory-display-warning nil
120+
"Display warning on memory header if t.
121+
122+
When error occurs when retrieving memory, gdb-mi displays the
123+
last successful page. In that case the expression might not
124+
match the memory displayed. We want to let the user be aware of
125+
that, so display a warning exclamation mark in the header line.")
115126

116127
(defvar gdb-thread-number nil
117128
"Main current thread.
@@ -3450,7 +3461,7 @@ line."
34503461
(def-gdb-trigger-and-handler
34513462
gdb-invalidate-memory
34523463
(format "-data-read-memory %s %s %d %d %d"
3453-
gdb-memory-address
3464+
(gdb-mi-quote gdb-memory-address-expression)
34543465
gdb-memory-format
34553466
gdb-memory-unit
34563467
gdb-memory-rows
@@ -3490,6 +3501,9 @@ in `gdb-memory-format'."
34903501
(err-msg (bindat-get-field res 'msg)))
34913502
(if (not err-msg)
34923503
(let ((memory (bindat-get-field res 'memory)))
3504+
(when gdb-memory-last-address
3505+
;; Nil means last retrieve emits error or just started the session.
3506+
(setq gdb--memory-display-warning nil))
34933507
(setq gdb-memory-address (bindat-get-field res 'addr))
34943508
(setq gdb-memory-next-page (bindat-get-field res 'next-page))
34953509
(setq gdb-memory-prev-page (bindat-get-field res 'prev-page))
@@ -3503,10 +3517,15 @@ in `gdb-memory-format'."
35033517
gdb-memory-format)))))
35043518
(newline)))
35053519
;; Show last page instead of empty buffer when out of bounds
3506-
(progn
3507-
(let ((gdb-memory-address gdb-memory-last-address))
3520+
(when gdb-memory-last-address
3521+
(let ((gdb-memory-address-expression gdb-memory-last-address))
3522+
;; If we don't set `gdb-memory-last-address' to nil,
3523+
;; `gdb-invalidate-memory' eventually calls
3524+
;; `gdb-read-memory-custom', making an infinite loop.
3525+
(setq gdb-memory-last-address nil
3526+
gdb--memory-display-warning t)
35083527
(gdb-invalidate-memory 'update)
3509-
(error err-msg))))))
3528+
(user-error "Error when retrieving memory: %s Displaying last successful page" err-msg))))))
35103529

35113530
(defvar gdb-memory-mode-map
35123531
(let ((map (make-sparse-keymap)))
@@ -3540,7 +3559,7 @@ in `gdb-memory-format'."
35403559
"Set the start memory address."
35413560
(interactive)
35423561
(let ((arg (read-from-minibuffer "Memory address: ")))
3543-
(setq gdb-memory-address arg))
3562+
(setq gdb-memory-address-expression arg))
35443563
(gdb-invalidate-memory 'update))
35453564

35463565
(defmacro def-gdb-set-positive-number (name variable echo-string &optional doc)
@@ -3723,7 +3742,19 @@ DOC is an optional documentation string."
37233742
(defvar gdb-memory-header
37243743
'(:eval
37253744
(concat
3726-
"Start address["
3745+
"Start address "
3746+
;; If `gdb-memory-address-expression' is nil, `propertize' would error.
3747+
(propertize (or gdb-memory-address-expression "N/A")
3748+
'face font-lock-warning-face
3749+
'help-echo "mouse-1: set start address"
3750+
'mouse-face 'mode-line-highlight
3751+
'local-map (gdb-make-header-line-mouse-map
3752+
'mouse-1
3753+
#'gdb-memory-set-address-event))
3754+
(if gdb--memory-display-warning
3755+
(propertize " !" 'face '(:inherit error :weight bold))
3756+
"")
3757+
" ["
37273758
(propertize "-"
37283759
'face font-lock-warning-face
37293760
'help-echo "mouse-1: decrement address"
@@ -3740,13 +3771,9 @@ DOC is an optional documentation string."
37403771
'mouse-1
37413772
#'gdb-memory-show-next-page))
37423773
"]: "
3743-
(propertize gdb-memory-address
3744-
'face font-lock-warning-face
3745-
'help-echo "mouse-1: set start address"
3746-
'mouse-face 'mode-line-highlight
3747-
'local-map (gdb-make-header-line-mouse-map
3748-
'mouse-1
3749-
#'gdb-memory-set-address-event))
3774+
;; If `gdb-memory-address' is nil, `propertize' would error.
3775+
(propertize (or gdb-memory-address "N/A")
3776+
'face font-lock-warning-face)
37503777
" Rows: "
37513778
(propertize (number-to-string gdb-memory-rows)
37523779
'face font-lock-warning-face

0 commit comments

Comments
 (0)