From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nick Roberts Newsgroups: gmane.emacs.devel Subject: Extending GUD tooltips Date: Wed, 27 Apr 2005 15:47:37 +1200 Message-ID: <17007.2905.593257.125998@farnswood.snap.net.nz> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1114573978 29200 80.91.229.2 (27 Apr 2005 03:52:58 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 27 Apr 2005 03:52:58 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Apr 27 05:52:53 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DQdbW-0006h7-Dj for ged-emacs-devel@m.gmane.org; Wed, 27 Apr 2005 05:52:50 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DQdhM-0005nG-Ot for ged-emacs-devel@m.gmane.org; Tue, 26 Apr 2005 23:58:52 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DQdh7-0005iq-EI for emacs-devel@gnu.org; Tue, 26 Apr 2005 23:58:37 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DQdh4-0005gO-JM for emacs-devel@gnu.org; Tue, 26 Apr 2005 23:58:37 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DQdh4-0004sk-F6 for emacs-devel@gnu.org; Tue, 26 Apr 2005 23:58:34 -0400 Original-Received: from [202.37.101.8] (helo=viper.snap.net.nz) by monty-python.gnu.org with esmtp (Exim 4.34) id 1DQdZT-0007Rg-Dh for emacs-devel@gnu.org; Tue, 26 Apr 2005 23:50:44 -0400 Original-Received: from farnswood.snap.net.nz (p173-tnt1.snap.net.nz [202.124.110.173]) by viper.snap.net.nz (Postfix) with ESMTP id 4CF774AF960 for ; Wed, 27 Apr 2005 15:46:50 +1200 (NZST) Original-Received: by farnswood.snap.net.nz (Postfix, from userid 501) id B9F3F62A99; Wed, 27 Apr 2005 04:47:40 +0100 (BST) Original-To: emacs-devel@gnu.org X-Mailer: VM 7.19 under Emacs 22.0.50.25 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:36433 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:36433 This patch extends GUD tooltips to display #define directives over relevant identifiers when a C program is under the control of GDB but has no child process i.e the program has either not started, been signalled or exited. Such tooltips could be displayed even if GDB has not been invoked but it was easier to integrate them with the existing GUD tooltips and such information is a natural part of the debugging process. I seem to recall that Visual Studio has something similar. The patch is for three files: gdb-ui.el, tooltip.el and cc-mode.el. Clearly the changes for cc-mode.el need to be ratified by the maintainers of that file (I use /lib/cpp but this should be more general). I have sent an e-mail to the appropriate list (bug-cc-mode@gnu.org) over a week ago but not had a reply yet. Nick *** /home/nick/emacs/lisp/tooltip.el.~1.52.~ 2005-04-20 21:46:08.000000000 +1200 --- /home/nick/emacs/lisp/tooltip.el 2005-04-27 14:55:17.000000000 +1200 *************** *** 453,481 **** "Show tip for identifier or selection under the mouse. The mouse must either point at an identifier or inside a selected region for the tip window to be shown. If tooltip-gud-dereference is t, ! add a `*' in front of the printed expression. This function must return nil if it doesn't handle EVENT." (let (process) (when (and (eventp event) tooltip-gud-tips-p (boundp 'gud-comint-buffer) (setq process (get-buffer-process gud-comint-buffer)) (posn-point (event-end event)) ! (progn (setq tooltip-gud-event event) ! (eval (cons 'and tooltip-gud-display)))) (let ((expr (tooltip-expr-to-print event))) (when expr ! (let ((cmd (tooltip-gud-print-command expr))) ! (unless (null cmd) ; CMD can be nil if unknown debugger ! (case gud-minor-mode ! (gdba (gdb-enqueue-input ! (list (concat cmd "\n") 'gdb-tooltip-print))) ! (t ! (setq tooltip-gud-original-filter (process-filter process)) ! (set-process-filter process 'tooltip-gud-process-output) ! (gud-basic-call cmd))) ! expr))))))) (defun gdb-tooltip-print () (tooltip-show --- 453,498 ---- "Show tip for identifier or selection under the mouse. The mouse must either point at an identifier or inside a selected region for the tip window to be shown. If tooltip-gud-dereference is t, ! add a `*' in front of the printed expression. In the case of a C program ! controlled by GDB, show the associated #define directives when program is ! not executing. This function must return nil if it doesn't handle EVENT." (let (process) (when (and (eventp event) tooltip-gud-tips-p (boundp 'gud-comint-buffer) + gud-comint-buffer + (buffer-name gud-comint-buffer); gud-comint-buffer might be killed (setq process (get-buffer-process gud-comint-buffer)) (posn-point (event-end event)) ! (or (eq gud-minor-mode 'gdba) ! (progn (setq tooltip-gud-event event) ! (eval (cons 'and tooltip-gud-display))))) (let ((expr (tooltip-expr-to-print event))) (when expr ! (if (and (eq gud-minor-mode 'gdba) ! (not gdb-active-process)) ! (progn ! (with-current-buffer ! (window-buffer (let ((mouse (mouse-position))) ! (window-at (cadr mouse) ! (cddr mouse)))) ! (when (boundp 'cc-define-alist) ; might be a Fortran program ! (let ((define-elt (assoc expr cc-define-alist))) ! (unless (null define-elt) ! (tooltip-show (cdr define-elt)) ! expr))))) ! (let ((cmd (tooltip-gud-print-command expr))) ! (unless (null cmd) ; CMD can be nil if unknown debugger ! (case gud-minor-mode ! (gdba (gdb-enqueue-input ! (list (concat cmd "\n") 'gdb-tooltip-print))) ! (t ! (setq tooltip-gud-original-filter (process-filter process)) ! (set-process-filter process 'tooltip-gud-process-output) ! (gud-basic-call cmd))) ! expr)))))))) (defun gdb-tooltip-print () (tooltip-show *** /home/nick/emacs/lisp/progmodes/gdb-ui.el.~1.61.~ 2005-04-21 23:52:47.000000000 +1200 --- /home/nick/emacs/lisp/progmodes/gdb-ui.el 2005-04-27 15:10:24.000000000 +1200 *************** *** 82,87 **** --- 82,89 ---- (defvar gdb-location-alist nil "Alist of breakpoint numbers and full filenames.") (defvar gdb-find-file-unhook nil) + (defvar gdb-active-process nil "GUD tooltips display variable values when t, \ + and #define directives otherwise.") (defvar gdb-buffer-type nil "One of the symbols bound in `gdb-buffer-rules'.") *************** *** 776,783 **** ("post-prompt" gdb-post-prompt) ("source" gdb-source) ("starting" gdb-starting) ! ("exited" gdb-stopping) ! ("signalled" gdb-stopping) ("signal" gdb-stopping) ("breakpoint" gdb-stopping) ("watchpoint" gdb-stopping) --- 778,785 ---- ("post-prompt" gdb-post-prompt) ("source" gdb-source) ("starting" gdb-starting) ! ("exited" gdb-exited) ! ("signalled" gdb-exited) ("signal" gdb-stopping) ("breakpoint" gdb-stopping) ("watchpoint" gdb-stopping) *************** *** 853,858 **** --- 855,861 ---- "An annotation handler for `starting'. This says that I/O for the subprocess is now the program being debugged, not GDB." + (setq gdb-active-process t) (let ((sink gdb-output-sink)) (cond ((eq sink 'user) *************** *** 865,871 **** (error "Unexpected `starting' annotation"))))) (defun gdb-stopping (ignored) ! "An annotation handler for `exited' and other annotations. They say that I/O for the subprocess is now GDB, not the program being debugged." (if gdb-use-inferior-io-buffer --- 868,874 ---- (error "Unexpected `starting' annotation"))))) (defun gdb-stopping (ignored) ! "An annotation handler for `breakpoint' and other annotations. They say that I/O for the subprocess is now GDB, not the program being debugged." (if gdb-use-inferior-io-buffer *************** *** 877,882 **** --- 880,895 ---- (gdb-resync) (error "Unexpected stopping annotation")))))) + (defun gdb-exited (ignored) + "An annotation handler for `exited' and `signalled'. + They say that I/O for the subprocess is now GDB, not the program + being debugged and that the program is no longer running. This + function is used to change the focus of GUD tooltips to #define + directives." + (setq gdb-active-process nil) + (gdb-stopping ignored)) + + (defun gdb-frame-begin (ignored) (let ((sink gdb-output-sink)) (cond *************** *** 2140,2146 **** (gdb-remove-breakpoint-icons (point-min) (point-max) t) (setq gud-minor-mode nil) (kill-local-variable 'tool-bar-map) ! (setq gud-running nil)))))) (when (markerp gdb-overlay-arrow-position) (move-marker gdb-overlay-arrow-position nil) (setq gdb-overlay-arrow-position nil)) --- 2153,2160 ---- (gdb-remove-breakpoint-icons (point-min) (point-max) t) (setq gud-minor-mode nil) (kill-local-variable 'tool-bar-map) ! (setq gud-running nil) ! (setq gdb-active-process nil)))))) (when (markerp gdb-overlay-arrow-position) (move-marker gdb-overlay-arrow-position nil) (setq gdb-overlay-arrow-position nil)) *** /home/nick/emacs/lisp/progmodes/cc-mode.el.~1.33.~ 2005-01-01 19:31:19.000000000 +1300 --- /home/nick/emacs/lisp/progmodes/cc-mode.el 2005-04-27 14:15:54.000000000 +1200 *************** *** 639,644 **** --- 639,659 ---- ;;;###autoload (add-to-list 'auto-mode-alist '("\\.y\\(acc\\)?\\'" . c-mode)) ;;;###autoload (add-to-list 'auto-mode-alist '("\\.lex\\'" . c-mode)) + (defvar cc-define-alist nil "Alist of #define directives for GUD tooltips.") + + (defun cc-create-define-alist () + (let* ((file (buffer-file-name)) + (output + (with-output-to-string + (with-current-buffer standard-output + (call-process "/lib/cpp" + file t nil "-dM")))) + (define-list (split-string output "\n" t)) + (name)) + (dolist (define define-list) + (setq name (nth 1 (split-string define "[( ]"))) + (push (cons name define) cc-define-alist)))) + ;;;###autoload (defun c-mode () "Major mode for editing K&R and ANSI C code. *************** *** 662,672 **** --- 677,689 ---- mode-name "C" local-abbrev-table c-mode-abbrev-table abbrev-mode t) + (make-local-variable 'cc-define-alist) (use-local-map c-mode-map) (c-init-language-vars-for 'c-mode) (c-common-init 'c-mode) (easy-menu-add c-c-menu) (cc-imenu-init cc-imenu-c-generic-expression) + (cc-create-define-alist) (run-mode-hooks 'c-mode-common-hook 'c-mode-hook) (c-update-modeline))