Commit ba025fbd authored by Eli Zaretskii's avatar Eli Zaretskii

Fix and improve GUD Tooltip mode.

 lisp/tooltip.el (tooltip-identifier-from-point): Don't treat tokens
 inside comments and strings as identifiers.
 lisp/progmodes/gud.el (gud-tooltip-print-command): Quote the
 expression to evaluate.  This allows to evaluate expressions with
 embedded whitespace.
 (gud-tooltip-tips): Add a blank before the newline in the
 message-box text, for the benefit of message-box emulation on
 MS-Windows.
 lisp/progmodes/gdb-mi.el (gdb-tooltip-print): Don't ignore error
 messages from GDB, pop them up in a tooltip to give feedback to
 user.
 (gdb-tooltip-print-1): Quote the expression to evaluate.  This
 allows to evaluate expressions with embedded whitespace.
 (gdb-inferior-io--init-proc): Don't send "-inferior-tty" command
 if the TTY name is nil or empty (which happens when communicating
 with the inferior via pipes, e.g. on MS-Windows).
 (gdb-internals): If GDB sends a "&\n" empty debugging message,
 don't send that to the GUD buffer.

 doc/emacs/building.texi (Debugger Operation): Correct and improve
 documentation of the GUD Tooltip mode.
parent 9b8d5165
2012-08-14 Eli Zaretskii <eliz@gnu.org>
* building.texi (Debugger Operation): Correct and improve
documentation of the GUD Tooltip mode.
2012-07-31 Chong Yidong <cyd@gnu.org>
* emacs.texi: Fix ISBN (Bug#12080).
......
......@@ -588,19 +588,25 @@ to recompile and restart the program.
GUD Tooltip mode is a global minor mode that adds tooltip support to
GUD. To toggle this mode, type @kbd{M-x gud-tooltip-mode}. It is
disabled by default. If enabled, you can move the mouse cursor over a
variable to show its value in a tooltip (@pxref{Tooltips}); this takes
effect in the GUD interaction buffer, and in all source buffers with
major modes listed in the variable @code{gud-tooltip-modes}. If the
variable @code{gud-tooltip-echo-area} is non-@code{nil}, values are
shown in the echo area instead of a tooltip.
When using GUD Tooltip mode with @kbd{M-x gud-gdb}, you should note
that displaying an expression's value in GDB can sometimes expand a
macro, potentially causing side effects in the debugged program. If
you use the @kbd{M-x gdb} interface, this problem does not occur, as
there is special code to avoid side-effects; furthermore, you can
display macro definitions associated with an identifier when the
program is not executing.
variable, a function, or a macro (collectively called
@dfn{identifiers}) to show their values in tooltips
(@pxref{Tooltips}). Alternatively, mark an identifier or an
expression by dragging the mouse over it, then leave the mouse in the
marked area to have the value of the expression displayed in a
tooltip. The GUD Tooltip mode takes effect in the GUD interaction
buffer, and in all source buffers with major modes listed in the
variable @code{gud-tooltip-modes}. If the variable
@code{gud-tooltip-echo-area} is non-@code{nil}, or if you turned off
the tooltip mode, values are shown in the echo area instead of a
tooltip.
When using GUD Tooltip mode with @kbd{M-x gud-gdb}, displaying an
expression's value in GDB can sometimes expand a macro, potentially
causing side effects in the debugged program. For that reason, using
tooltips in @code{gud-gdb} is disabled. If you use the @kbd{M-x gdb}
interface, this problem does not occur, as there is special code to
avoid side-effects; furthermore, you can display macro definitions
associated with an identifier when the program is not executing.
@node Commands of GUD
@subsection Commands of GUD
......
2012-08-14 Eli Zaretskii <eliz@gnu.org>
* tooltip.el (tooltip-identifier-from-point): Don't treat tokens
inside comments and strings as identifiers.
* progmodes/gud.el (gud-tooltip-print-command): Quote the
expression to evaluate. This allows to evaluate expressions with
embedded whitespace.
(gud-tooltip-tips): Add a blank before the newline in the
message-box text, for the benefit of message-box emulation on
MS-Windows.
* progmodes/gdb-mi.el (gdb-tooltip-print): Don't ignore error
messages from GDB, pop them up in a tooltip to give feedback to
user.
(gdb-tooltip-print-1): Quote the expression to evaluate. This
allows to evaluate expressions with embedded whitespace.
(gdb-inferior-io--init-proc): Don't send "-inferior-tty" command
if the TTY name is nil or empty (which happens when communicating
with the inferior via pipes, e.g. on MS-Windows).
(gdb-internals): If GDB sends a "&\n" empty debugging message,
don't send that to the GUD buffer.
2012-08-14 Glenn Morris <rgm@gnu.org>
* emacs-lisp/bytecomp.el (byte-compile-setq-default):
......
......@@ -944,11 +944,16 @@ no input, and GDB is waiting for input."
(defun gdb-tooltip-print (expr)
(with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
(goto-char (point-min))
(if (re-search-forward ".*value=\\(\".*\"\\)" nil t)
(tooltip-show
(concat expr " = " (read (match-string 1)))
(or gud-tooltip-echo-area
(not (display-graphic-p)))))))
(cond
((re-search-forward ".*value=\\(\".*\"\\)" nil t)
(tooltip-show
(concat expr " = " (read (match-string 1)))
(or gud-tooltip-echo-area
(not (display-graphic-p)))))
((re-search-forward "msg=\\(\".+\"\\)$" nil t)
(tooltip-show (read (match-string 1))
(or gud-tooltip-echo-area
(not (display-graphic-p))))))))
;; If expr is a macro for a function don't print because of possible dangerous
;; side-effects. Also printing a function within a tooltip generates an
......@@ -958,7 +963,7 @@ no input, and GDB is waiting for input."
(goto-char (point-min))
(if (search-forward "expands to: " nil t)
(unless (looking-at "\\S-+.*(.*).*")
(gdb-input (concat "-data-evaluate-expression " expr)
(gdb-input (concat "-data-evaluate-expression \"" expr "\"")
`(lambda () (gdb-tooltip-print ,expr)))))))
(defun gdb-init-buffer ()
......@@ -1513,12 +1518,13 @@ DOC is an optional documentation string."
;; Set up inferior I/O. Needs GDB 6.4 onwards.
(set-process-filter proc 'gdb-inferior-filter)
(set-process-sentinel proc 'gdb-inferior-io-sentinel)
(gdb-input
(concat "-inferior-tty-set "
;; The process can run on a remote host.
(or (process-get proc 'remote-tty)
(process-tty-name proc)))
'ignore))
;; The process can run on a remote host.
(let ((tty (or (process-get proc 'remote-tty)
(process-tty-name proc))))
(unless (or (null tty)
(string= tty ""))
(gdb-input
(concat "-inferior-tty-set " tty) 'ignore))))
(defun gdb-inferior-io-sentinel (proc str)
(when (eq (process-status proc) 'failed)
......@@ -2100,13 +2106,15 @@ current thread and update GDB buffers."
(setq gdb-filter-output
(gdb-concat-output
gdb-filter-output
(let ((error-message
(read output-field)))
(put-text-property
0 (length error-message)
'face font-lock-warning-face
error-message)
error-message))))
(if (string= output-field "\"\\n\"")
""
(let ((error-message
(read output-field)))
(put-text-property
0 (length error-message)
'face font-lock-warning-face
error-message)
error-message)))))
;; Remove the trimmings from the console stream and send to GUD buffer
;; (frontend MI commands should not print to this stream)
......
......@@ -3411,7 +3411,7 @@ With arg, dereference expr if ARG is positive, otherwise do not dereference."
(defun gud-tooltip-print-command (expr)
"Return a suitable command to print the expression EXPR."
(pcase gud-minor-mode
(`gdbmi (concat "-data-evaluate-expression " expr))
(`gdbmi (concat "-data-evaluate-expression \"" expr "\""))
(`dbx (concat "print " expr))
((or `xdb `pdb) (concat "p " expr))
(`sdb (concat expr "/"))))
......@@ -3456,7 +3456,10 @@ This function must return nil if it doesn't handle EVENT."
(let ((cmd (gud-tooltip-print-command expr)))
(when (and gud-tooltip-mode (eq gud-minor-mode 'gdb))
(gud-tooltip-mode -1)
(message-box "Using GUD tooltips in this mode is unsafe\n\
;; The blank before the newline is for MS-Windows,
;; whose emulation of message box removes newlines and
;; displays a single long line.
(message-box "Using GUD tooltips in this mode is unsafe \n\
so they have been disabled."))
(unless (null cmd) ; CMD can be nil if unknown debugger
(if (eq gud-minor-mode 'gdbmi)
......
......@@ -25,6 +25,8 @@
;;; Code:
(require 'syntax)
(defvar comint-prompt-regexp)
(defgroup tooltip nil
......@@ -277,8 +279,11 @@ Value is nil if no identifier exists at point. Identifier extraction
is based on the current syntax table."
(save-excursion
(goto-char point)
(let ((start (progn (skip-syntax-backward "w_") (point))))
(unless (looking-at "[0-9]")
(let* ((start (progn (skip-syntax-backward "w_") (point)))
(pstate (syntax-ppss)))
(unless (or (looking-at "[0-9]")
(nth 3 pstate)
(nth 4 pstate))
(skip-syntax-forward "w_")
(when (> (point) start)
(buffer-substring start (point)))))))
......
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