Debug tooltips only intermittently work: global `mlgud-tooltip-mode` ends up off while `matlab-shell-gud-minor-mode` is on
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 59/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- emacs
- 領域
- devtools
調査の方向性
Read matlab-shell-gud.el and mlgud.el, starting with the minor mode bodies and the debug prompt transition described in the issue. Trace how enabling or disabling the buffer local modes changes the global tooltip mode, then check the transition behavior with the supplied run.sh reproduction. Done means tooltips stay enabled while debugging is active and are disabled when debugging ends.
索引モデルが issue の本文から書いたものです。
説明
Description
With matlab-shell-debug-tooltips-p set to t, hovering over a variable in a .m buffer while stopped at the K>> prompt only sometimes shows its value. Tooltips are supposed to turn on whenever debugging starts. In an affected buffer, the local matlab-shell-gud-minor-mode was t but the global mlgud-tooltip-mode was nil (and track-mouse was nil), i.e. tooltips were off even though debug mode was active. Tooltips are controlled by one global switch, but they are turned on and off by modes that are local to each buffer.
Cause
mlgud-tooltip-modeis:global t(mlgud.el).- In
matlab-shell-gud.el,matlab-shell-gud-minor-modecalls(mlgud-tooltip-mode 1)when it is enabled, ifmatlab-shell-debug-tooltips-pis set. - The body of
matlab-shell-inactive-gud-minor-modecalls(mlgud-tooltip-mode -1)unconditionally, so it runs both when the mode is enabled and when it is disabled. Likewisematlab-shell-gud-minor-mode's disable branch calls it. - On entering the
K>>prompt, the prompt-tracking code runs(global-matlab-shell-gud-minor-mode 1)and then(global-matlab-shell-inactive-gud-minor-mode -1). Disabling the inactive mode runs its body, which switches the global tooltip mode off right after the first call switched it on.
I confirmed this order with trace-function on mlgud-tooltip-mode, matlab-shell-gud-minor-mode and matlab-shell-inactive-gud-minor-mode while entering K>>, with two matlab buffers open and no workaround hook active (trace abridged):
1 -> (matlab-shell-gud-minor-mode 1)
| 2 -> (mlgud-tooltip-mode 1)
| 2 <- mlgud-tooltip-mode: t
1 <- matlab-shell-gud-minor-mode: t
(same again for the second buffer)
1 -> (matlab-shell-inactive-gud-minor-mode -1)
| 2 -> (mlgud-tooltip-mode -1)
| 2 <- mlgud-tooltip-mode: nil
1 <- matlab-shell-inactive-gud-minor-mode: nil
(same again for the second buffer)
The last call is (mlgud-tooltip-mode -1), so the global mode is nil once debug mode is active.
As far as I can tell from the repository history, matlab-shell-gud.el has not changed since 8.2.0, so this likely affects the latest release as well. I have not tested 8.2.2.
Workarounds
Killing the source buffer and running dbstep usually brings tooltips back. This fits the cause. Running dbstep reopens the file, and global-matlab-shell-gud-minor-mode enables matlab-shell-gud-minor-mode in the new buffer. That calls (mlgud-tooltip-mode 1), which turns the global switch back on and re-enables track-mouse in the buffers. No (global-matlab-shell-inactive-gud-minor-mode -1) call follows it, so nothing switches the global mode off again. That would also explain why it works "usually" and not always: it depends on whether something else toggles the inactive mode afterwards. I haven't traced this case.
A less intrusive workaround is to turn tooltips back on once the debug prompt is active:
(add-hook 'gud-matlab-debug-activate-hook
(lambda () (when matlab-shell-debug-tooltips-p (mlgud-tooltip-mode 1))))
With this hook, tooltips work reliably in my setup. gud-matlab-debug-activate-hook runs right after (global-matlab-shell-inactive-gud-minor-mode -1) in the prompt transition, so the hook re-enables the global switch after the call that turns it off.
The hook treats the symptom, not the root cause. The per-buffer minor modes still toggle the global mlgud-tooltip-mode, and the hook just puts it back afterwards. It runs only when K>> becomes active. If something else toggled the inactive mode later in the same debug session, tooltips could be switched off again until the next transition. I haven't observed that.
Suggested direction
Enable and disable the global tooltip mode in one place, when debugging starts and ends (for example from the gud-matlab-debug-active transition), not from the per-buffer minor modes.
Environment
- Emacs 29.4, Linux
- matlab-emacs 8.2.0
matlab-shell-debug-tooltips-p=t
Reproduction (bare Emacs, scripted)
Requires a MATLAB installation. Tested with Emacs 29.4, matlab-emacs 8.2.0 and MATLAB R2022b. Save the two files below in the same directory, then run:
M=/path/to/Emacs-MATLAB-Mode ./run.sh # without workaround
REPRO_HOOK=1 M=/path/to/Emacs-MATLAB-Mode ./run.sh # with the workaround hook
Optional: EMACS=/path/to/emacs and MATLAB_CMD=/path/to/matlab if they are not on your PATH.
The script starts matlab-shell in emacs -Q (with an empty startup.m and MATLABPATH unset), sets a breakpoint in a small test function, runs it to K>>, and prints the state of the tooltip modes plus a trace-function trace. A mouse hover can't be tested in batch mode, so it checks the state that tooltips depend on.
Results (single matlab buffer):
| Run | matlab-shell-gud-minor-mode (local) |
mlgud-tooltip-mode (global) |
track-mouse (local) |
Verdict |
|---|---|---|---|---|
./run.sh |
t |
nil |
nil |
BUG REPRODUCED |
REPRO_HOOK=1 ./run.sh |
t |
t |
t |
OK |
Trace without the hook (the same shape as in the trace above, one buffer):
1 -> (matlab-shell-gud-minor-mode 1)
| 2 -> (mlgud-tooltip-mode 1)
| 2 <- mlgud-tooltip-mode: t
1 <- matlab-shell-gud-minor-mode: t
1 -> (matlab-shell-inactive-gud-minor-mode -1)
| 2 -> (mlgud-tooltip-mode -1)
| 2 <- mlgud-tooltip-mode: nil
1 <- matlab-shell-inactive-gud-minor-mode: nil
run.sh
#!/bin/sh
# Batch repro of the matlab-shell debug tooltip issue, in a bare Emacs (emacs -Q).
# Usage: M=/path/to/Emacs-MATLAB-Mode ./run.sh -> without workaround (expect: BUG REPRODUCED)
# REPRO_HOOK=1 M=/path/to/Emacs-MATLAB-Mode ./run.sh -> with the workaround hook (expect: OK)
# Optional: EMACS=/path/to/emacs MATLAB_CMD=/path/to/matlab
here=$(cd "$(dirname "$0")" && pwd)
: "${M:?set M to the matlab-emacs directory, e.g. M=/path/to/Emacs-MATLAB-Mode}"
EMACS=${EMACS:-emacs}
MATLAB_CMD=${MATLAB_CMD:-matlab}
work=$(mktemp -d) || exit 1
echo '% empty' > "$work/startup.m" # unaltered startup, as recommended in DEBUGGING.org
cd "$work" || exit 1
env MATLABPATH= REPRO_DIR="$work" MATLAB_CMD="$MATLAB_CMD" \
"$EMACS" -Q --batch -L "$M" -l "$M/matlab-autoload.el" -l "$here/repro.el"
status=$?
echo "(exit status $status; work dir $work)"
exit $status
repro.el
;;; repro.el --- batch repro of the matlab-shell debug tooltip problem -*- lexical-binding: t; -*-
;;
;; Run through run.sh. Starts matlab-shell, stops at a breakpoint, then reports
;; whether the global `mlgud-tooltip-mode' is still on while
;; `matlab-shell-gud-minor-mode' is on in the source buffer.
;; A mouse hover can't be tested in batch mode; this checks the state that makes it work.
;;
;; Environment:
;; REPRO_DIR working dir (must be writable) - set by run.sh
;; MATLAB_CMD MATLAB executable - set by run.sh
;; REPRO_HOOK non-empty: install the workaround hook (expected result: tooltips stay on)
(require 'trace)
(require 'matlab-shell)
(require 'matlab-shell-gud)
(defvar repro-dir (file-name-as-directory (expand-file-name (getenv "REPRO_DIR"))))
(setq default-directory repro-dir)
(setq matlab-shell-command (or (getenv "MATLAB_CMD") "matlab"))
(setq matlab-shell-command-switches '("-nodesktop" "-nosplash" "-nodisplay"))
(setq matlab-shell-debug-tooltips-p t)
(when (not (string-empty-p (or (getenv "REPRO_HOOK") "")))
(add-hook 'gud-matlab-debug-activate-hook
(lambda () (when matlab-shell-debug-tooltips-p (mlgud-tooltip-mode 1)))))
(defun repro-say (fmt &rest args) (princ (apply #'format (concat fmt "\n") args)))
(defun repro-shell-buffer () (matlab-shell-active-p))
(defun repro-wait (pred timeout what)
"Wait until PRED returns non-nil, or fail after TIMEOUT seconds."
(let ((end (+ (float-time) timeout)))
(while (and (not (funcall pred)) (< (float-time) end))
(accept-process-output nil 0.2))
(unless (funcall pred)
(repro-say "TIMEOUT waiting for: %s" what)
(when (repro-shell-buffer)
(with-current-buffer (repro-shell-buffer)
(repro-say "--- tail of MATLAB buffer ---\n%s"
(buffer-substring (max (point-min) (- (point-max) 1500)) (point-max)))))
(kill-emacs 2))))
(defun repro-on-prompt ()
(and (repro-shell-buffer)
(with-current-buffer (repro-shell-buffer) (matlab-on-prompt-p))))
(defun repro-send (cmd)
(matlab-shell-send-command cmd)
(accept-process-output nil 0.3))
;; Test file: breakpoint goes on line 3.
(defvar repro-file (expand-file-name "tooltip_repro.m" repro-dir))
(with-temp-file repro-file
(insert "function tooltip_repro\nx = 1;\ny = x + 1;\ndisp(y)\nend\n"))
(defvar repro-src (find-file-noselect repro-file))
(repro-say "Starting matlab-shell (%s)..." matlab-shell-command)
(save-window-excursion (matlab-shell))
(repro-wait #'repro-on-prompt 180 "first MATLAB prompt")
;; Trace only after startup, so the output covers just the debug transition.
(dolist (f '(mlgud-tooltip-mode matlab-shell-gud-minor-mode matlab-shell-inactive-gud-minor-mode))
(trace-function-background f))
(repro-send (format "cd('%s')" repro-dir))
(repro-wait #'repro-on-prompt 60 "prompt after cd")
(repro-send "dbstop in tooltip_repro at 3")
(repro-wait #'repro-on-prompt 60 "prompt after dbstop")
(repro-send "tooltip_repro")
(repro-wait (lambda () gud-matlab-debug-active) 60 "K>> debug prompt (gud-matlab-debug-active)")
(let ((end (+ (float-time) 2.0))) (while (< (float-time) end) (accept-process-output nil 0.2)))
(let ((tip mlgud-tooltip-mode)
(gud (buffer-local-value 'matlab-shell-gud-minor-mode repro-src))
(trk (buffer-local-value 'track-mouse repro-src)))
(repro-say "\n===== STATE AT K>> (source buffer %s) =====" (buffer-name repro-src))
(repro-say "matlab-shell-gud-minor-mode (local) = %S" gud)
(repro-say "mlgud-tooltip-mode (global) = %S" tip)
(repro-say "track-mouse (local) = %S" trk)
(repro-say "REPRO_HOOK = %S" (getenv "REPRO_HOOK"))
(repro-say "\n===== TRACE =====")
(with-current-buffer (get-buffer-create "*trace-output*")
(repro-say "%s" (buffer-string)))
(repro-say "===== VERDICT =====")
(cond ((and gud (not tip)) (repro-say "BUG REPRODUCED: debug mode is on but tooltips are off."))
((and gud tip) (repro-say "OK: tooltips are on while debug mode is on."))
(t (repro-say "INCONCLUSIVE: gud minor mode is not on in the source buffer.")))
(ignore-errors (repro-send "dbquit"))
(ignore-errors (repro-send "exit"))
(kill-emacs (cond ((and gud (not tip)) 1) (gud 0) (t 3))))
- 主要言語
- Emacs Lisp
- スター
- 27
- フォーク
- 5
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
mathworks/Emacs-MATLAB-Mode のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 40/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 15/100
-
enhancement help wanted
難易度 4/5 3〜5日 初心者へのやさしさ 38/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 28/100
mathworks/Emacs-MATLAB-Mode#59 · コメント 3 件 · リアクション 1 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
mathworks/Emacs-MATLAB-Mode#50 · コメント 1 件 ·
mathworks/Emacs-MATLAB-Mode の issue をすべて見る
似ている issue
-
enhancement good first issue help wanted
難易度 1/5 1時間未満 初心者へのやさしさ 95/100
-
[Bug]: A Markdown link with both a :line suffix and a #L fragment opens a path containing ":line"オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
TanbirRamim/vibereel#39 ·
-
area:docs documentation Platform Ray vdr
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
NVIDIA-NeMo/Gym#7186 ·
メンテナーはふだん 2 日以内に返信
-
難易度 1/5 1〜3時間 初心者へのやさしさ 89/100
aaif-goose/goose#14001 ·
メンテナーはふだん 1 日以内に返信