unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Extending GUD tooltips
@ 2005-04-27  3:47 Nick Roberts
  2005-04-27  6:46 ` Jérôme Marant
  2005-04-27 18:36 ` Richard Stallman
  0 siblings, 2 replies; 14+ messages in thread
From: Nick Roberts @ 2005-04-27  3:47 UTC (permalink / raw)



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))

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2005-05-10 20:25 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-04-27  3:47 Extending GUD tooltips Nick Roberts
2005-04-27  6:46 ` Jérôme Marant
2005-04-27 23:00   ` Nick Roberts
2005-04-28  9:05     ` Jérôme Marant
2005-04-29  0:13     ` Richard Stallman
2005-05-03 10:45       ` Nick Roberts
     [not found]         ` <20050503233230.B47179F50F@mirror.positive-internet.com>
2005-05-04 16:57           ` Jérôme Marant
2005-05-05 19:45             ` Richard Stallman
2005-05-05 23:45           ` Nick Roberts
2005-05-06 18:51             ` Richard Stallman
2005-05-07  0:28               ` Nick Roberts
2005-05-07 18:35                 ` Richard Stallman
2005-05-10 20:25             ` Jérôme Marant
2005-04-27 18:36 ` Richard Stallman

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).