Commit 07e1852c authored by Yuan Fu's avatar Yuan Fu Committed by Eli Zaretskii

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)
parent 30abcda5
Pipeline #4764 passed with stage
in 73 minutes and 58 seconds
......@@ -105,13 +105,24 @@
(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.
......@@ -3450,7 +3461,7 @@ line."
(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
......@@ -3490,6 +3501,9 @@ in `gdb-memory-format'."
(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))
......@@ -3503,10 +3517,15 @@ in `gdb-memory-format'."
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)))
......@@ -3540,7 +3559,7 @@ in `gdb-memory-format'."
"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)
......@@ -3723,7 +3742,19 @@ DOC is an optional documentation string."
(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"
......@@ -3740,13 +3771,9 @@ DOC is an optional documentation string."
'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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment