emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Extending GUD tooltips


From: Nick Roberts
Subject: Extending GUD tooltips
Date: Wed, 27 Apr 2005 15:47:37 +1200

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 (address@hidden) 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))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]