home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / interfaces / gdbsrc.el < prev    next >
Encoding:
Text File  |  1991-05-03  |  22.7 KB  |  685 lines

  1. ; From: ayers@ASC.SLB.COM
  2. ; Subject: Gdbsrc - GNU gdb extension.
  3. ; Date: 13 Nov 90 05:30:34 GMT
  4. ; Organization: GNUs Not Usenet
  5. ; Until release 19.....
  6. ;  GDBSRC::
  7. ;  Gdbsrc extends the emacs GDB interface to accept gdb commands issued
  8. ;  from the source code buffer.  Gdbsrc behaves similar to gdb except
  9. ;  now most debugging may be done from the source code using the *gdb*
  10. ;  buffer to view output. Supports a point and click model under X to
  11. ;  evaluate source code expressions (no more typing long variable names).
  12. ;  And more.. makes debugging fun! :-)
  13. ; We have been using it here for about 5 months and really like it.
  14. ; Supports C source at the moment but C++ support will be added if there
  15. ; is sufficient interest.
  16. ;-----------------------------------------------------------
  17. ;; Run gdbsrc under GNU Emacs (Mouse supported under X11R4)
  18. ;; 1990 Debby Ayers ayers@asc.slb.com, Rich Schaefer schaefer@asc.slb.com
  19. ;; Schlumberger, Austin, Tx 
  20.  
  21. ;; This file is not part of the GNU Emacs distribution.
  22.  
  23. ;; This file is distributed in the hope that it will be useful,
  24. ;; but WITHOUT ANY WARRANTY.  No author or distributor
  25. ;; accepts responsibility to anyone for the consequences of using it
  26. ;; or for whether it serves any particular purpose or works at all,
  27. ;; unless he says so in writing.  Refer to the GNU Emacs General Public
  28. ;; License for full details.
  29.  
  30. ;; Everyone is granted permission to copy, modify and redistribute
  31. ;; this file, but only under the conditions described in the
  32. ;; GNU Emacs General Public License.   A copy of this license is
  33. ;; supposed to have been given to you along with GNU Emacs so you
  34. ;; can know your rights and responsibilities.  It should be in a
  35. ;; file named COPYING.  Among other things, the copyright notice
  36. ;; and this notice must be preserved on all copies.
  37.  
  38. ;; GDBSRC::Gdb Source Mode Interface description.
  39. ;; Gdbsrc extends the emacs GDB interface to accept gdb commands issued
  40. ;; from the source code buffer. Gdbsrc behaves similar to gdb except now all 
  41. ;; debugging may be done from the currently focused source buffer using 
  42. ;; the *gdb* buffer to view output.
  43.  
  44. ;; When source files are displayed through gdbsrc, buffers are put in 
  45. ;; gdb-src-mode minor mode. This mode puts the buffer in read-only state
  46. ;; and sets up a special key and mouse map to invoke communication with
  47. ;; the current gdb process. The minor mode may be toggled on/off as needed.
  48. ;; (ESC-T) 
  49.  
  50. ;; C-expressions may be evaluated by gdbsrc by simply pointing at text in the
  51. ;; current source buffer with the mouse or by centering the cursor over text
  52. ;; and typing a single key command. ('p' for print, '*' for print *).
  53.  
  54. ;; As code is debugged and new buffers are displayed, the focus of gdbsrc
  55. ;; follows to each new source buffer. Makes debugging fun. (sound like a
  56. ;; commercial or what!)
  57. ;; 
  58. ;; To start:
  59. ;; Copy this file into gdbsrc.el
  60. ;; Compile if desired and load from .emacs
  61. ;; Issue "gdbsrc" from M-x command line.
  62. ;; Proceed with debugging as usual until source code is displayed.
  63. ;; Once source is displayed , go to source buffer and start debugging.
  64. ;; At any time you may issue a "C-h C-b" to see the current key
  65. ;; bindings.(help-for-help at M-x)
  66. ;; Toggle mode on/off to edit text. (ESC-T)
  67.  
  68. ;; All key-bindings may be redefined. 
  69. ;; Local Bindings for Gdb-Src minor mode
  70. ;; Buffer is placed in READ-ONLY mode.
  71.  
  72. ;; Current Listing ::
  73. ;;key        binding                    Comment
  74. ;;---        -------                    -------
  75. ;;
  76. ;; r               gdb-return-from-src    GDB return command
  77. ;; n               gdb-next-from-src    GDB next command
  78. ;; b               gdb-back-from-src    GDB back command
  79. ;; w               gdb-where-from-src    GDB where command
  80. ;; f               gdb-finish-from-src    GDB finish command
  81. ;; u               gdb-up-from-src      GDB up command
  82. ;; d               gdb-down-from-src    GDB down command
  83. ;; c               gdb-cont-from-src    GDB continue command
  84. ;; i               gdb-stepi-from-src    GDB step instruction command
  85. ;; s               gdb-step-from-src    GDB step command
  86. ;; ?               gdb-whatis-c-sexp    GDB whatis command for data at
  87. ;;                         buffer point
  88. ;; x               gdb-src-delete        GDB Delete all breakpoints if no arg
  89. ;;                         given or delete arg (C-u arg x)
  90. ;; m               gdb-src-frame         GDB Display current frame if no arg,
  91. ;;                         given or display frame arg
  92. ;; *               gdb-*print-c-sexp    GDB print * command for data at
  93. ;;                           buffer point
  94. ;; !               goto-gdb        Goto the GDB output buffer
  95. ;; p               gdb-print-c-sexp    GDB print * command for data at
  96. ;;                         buffer point
  97. ;; g               goto-gdb        Goto the GDB output buffer
  98. ;; t               gdb-src-mode        Toggles Gdb-Src mode (turns it off)
  99. ;; 
  100. ;; C-c C-f         gdb-finish-from-src    GDB finish command
  101. ;; 
  102. ;; C-x SPC         gdb-break        Set break for line with point
  103. ;; ESC t           gdb-src-mode        Toggle Gdb-Src mode
  104. ;;
  105. ;; X11/R4 Mouse Support
  106. ;; Click: 
  107. ;;
  108. ;;  left will set point (as always)
  109. ;;  shift-left will grab c-sexp and send to gdb to print
  110. ;;  shift-control-left will grab c-sexp and send to gdb to print *
  111. ;; 
  112. ;;  middle will paste last cut at point
  113. ;;  shift-middle will send gdb the currently marked region to print...
  114. ;;  shift-control-middle will send gdb the currently marked region to print *
  115. ;;
  116. ;;  right button will copy from point to mouse into the cut buffer...
  117. ;;  shift-right button will send currently marked region to GDB as a break point
  118. ;;  shift-control-middle will issue a continue and break when point is reached
  119. ;;
  120. ;; Local Bindings for buffer when you exit Gdb-Src minor mode
  121. ;;
  122. ;; C-x SPC         gdb-break        Set break for line with point
  123. ;; ESC t           gdb-src-mode        Toggle Gdb-Src mode
  124. ;;
  125. ;; Please send bug reports, modifications, and or comments to:
  126. ;; ayers@asc.slb.com  or schaefer@asc.slb.com
  127.  
  128. (provide 'gdbsrc)
  129.  
  130. (defvar gdb-src-mode nil
  131. " Indicates whether buffer is in gdb-src-mode or not")
  132.  
  133. (defvar gdb-src-window nil
  134. " Contains the window name of the current gdb source file")
  135.  
  136. (defvar gdb-src-active-p t
  137. " Set to nil if you do not want source files put in gdb-src-mode")
  138.  
  139. (defun setup-gdb-src-window (window)
  140. " Called from gdb-display-line to put the next source file
  141.   in gdb-src-mode and save the window name"
  142.   (setq gdb-src-window window)
  143.   (and gdb-src-active-p (not gdb-src-mode )(gdb-src-mode 1))
  144. )
  145.  
  146. (defvar gdb-src-call-p nil
  147. " True if gdb command issued from a source buffer")
  148.  
  149. (defvar gdb-associated-buffer nil
  150.   "Buffer name of attached gdb process")
  151. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  152. ;; Gdbsrc command.
  153. ;;
  154. ;;
  155. (defun gdbsrc (path)
  156.   " Activates a gdb session with  gdb-src-mode turned on."
  157.   (interactive "FRun gdb on file: ")
  158.   (gdb path)
  159.   (setq gdb-src-window nil)
  160.   (setq gdb-src-active-p 1)
  161.   (setq gdb-src-call-p nil)
  162.   (setq gdb-src-mode nil)
  163.   (set-process-filter 
  164.    (get-buffer-process current-gdb-buffer) 'gdb-src-mode-filter)
  165.   (set-process-sentinel 
  166.    (get-buffer-process current-gdb-buffer) 'gdb-src-mode-sentinel)
  167.   (fset (intern "gdb-display-line") 'gdb-src-display-line)
  168.   (if (featurep 'x-mouse) (setup-gdb-mouse))
  169.   (message "Gbd source mode active"))
  170.  
  171. (defvar gdb-src-mode-map nil
  172.   "Keymap for gdb-src-mode")
  173.  
  174. (if gdb-src-mode-map 
  175.     nil
  176.   (setq gdb-src-mode-map (copy-keymap c-mode-map))
  177.   ;;Keys
  178.   (define-key gdb-src-mode-map "t" 'gdb-src-mode)
  179.   (define-key gdb-src-mode-map "g" 'goto-gdb)
  180.   (define-key gdb-src-mode-map "p" 'gdb-print-c-sexp)
  181.   (define-key gdb-src-mode-map "!" 'goto-gdb)
  182.   (define-key gdb-src-mode-map "*" 'gdb-*print-c-sexp)
  183.   (define-key gdb-src-mode-map "?" 'gdb-whatis-c-sexp)
  184.   (define-key ctl-x-map " " 'gdb-break)
  185.   (define-key esc-map "t" 'gdb-src-mode)
  186.  
  187.   )
  188. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  189. ;;
  190. ;; There are two ways to set up new keyboard commands for gdbsrc.
  191. ;;
  192. ;; Use the macro def-gdb-from-src (similiar to def-gdb of gdb.el).
  193. ;; This macro generates a function and a define key for you.
  194. ;;
  195. ;; Ex. (def-gdb-from-src "name-of-command" "key-to-bind-to" "Documentation")
  196. ;;
  197. ;; The limitation here is "name-of-command" has to be a command gdb knows
  198. ;; about like "break" etc
  199. ;;
  200. ;; For more sophisticated interaction, write your function and call
  201. ;; (gdb-call-from-src command-string) where command-string is some
  202. ;; command and its arguments that you have generated somehow. Look at
  203. ;; gdb-src-print-csexp for an example. Once you have written this function
  204. ;; use a (define-key gdb-src-mode-map "key" 'function) to put it in the 
  205. ;; gdbsrc keymap.
  206. ;;
  207. ; Use this macro to setup other gdb commands.
  208. (defmacro def-gdb-from-src (name key &optional doc)
  209.   (let* ((fun (intern (format "gdb-%s-from-src" name)))
  210.      (cstr (list 'if '(not (= 1 arg))
  211.              (list 'format "%s %s" name 'arg)
  212.              name)))
  213.     (list 'progn
  214.        (list 'defun fun '(arg)
  215.         (or doc "")
  216.         '(interactive "p")
  217.         (list 'gdb-call-from-src cstr))
  218.       (list 'define-key 'gdb-src-mode-map key  (list 'quote fun)))))
  219.  
  220. (def-gdb-from-src "finish" "\C-c\C-f" "Finish executing current function")
  221. (def-gdb-from-src "step"  "s" "Step one instruction in src")
  222. (def-gdb-from-src "stepi" "i" "Step one source line (skip functions)")
  223. (def-gdb-from-src "cont"  "c" "Continue with display")
  224. (def-gdb-from-src "down"  "d" "Go down N stack frames (numeric arg) ")
  225. (def-gdb-from-src "up"    "u" "Go up N stack frames (numeric arg) with display")
  226. (def-gdb-from-src "finish" "f" "Finish frame")
  227. (def-gdb-from-src "where" "w" "Finish frame")
  228. (def-gdb-from-src "back"  "b" "Display Backtrace")
  229. (def-gdb-from-src "next"  "n" "Step one line with display")
  230. (def-gdb-from-src "return" "r" "Return from selected stack frame")
  231. (def-gdb-from-src "delete" "x" "Delete all breakpoints")
  232. (def-gdb-from-src "frame" "m" "Show frame if noarg, with arg go to frame")
  233. ;;
  234. ;; Setup Mouse Bindings for Gdbsrc mode.
  235. ;;
  236. (defun setup-gdb-mouse ()
  237.   (interactive)
  238.  
  239.   ;; shift-left will grab c-sexp and send to gdb to print
  240.   (define-key mouse-map x-button-s-left 'x-gdb-print-csexp)
  241.  
  242.   ;; shift-control-left will grab c-sexp and send to gdb to print * 
  243.   (define-key mouse-map x-button-c-s-left 'x-gdb-*print-csexp)
  244.  
  245.   ;; shift-middle will send gdb the currently marked region to print...
  246.   (define-key mouse-map x-button-s-middle 'x-gdb-print-region)
  247.  
  248.   ;; shift-control-middle will send gdb the currently mark region to print *
  249.   (define-key mouse-map x-button-c-s-middle 'x-gdb-*print-region)
  250.  
  251.   ;; left button will set point
  252.   (define-key mouse-map x-button-left 'x-mouse-set-point)
  253.  
  254.   ;; middle button will paste last cut at point
  255.   (define-key mouse-map x-button-middle 'x-paste-text)
  256.  
  257.   ;; right button will copy from point to here into cut buffer...
  258.   (define-key mouse-map x-button-right 'x-cut-marked-region)
  259.  
  260.   ;; shift-right will send gdb a "break" at whatever is in the cut-buffer
  261.   (define-key mouse-map x-button-s-right 'x-gdb-break-region)
  262.  
  263.  ;; shift-right will send gdb a "break" at whatever is in the cut-buffer
  264.   (define-key mouse-map x-button-c-s-right ' x-gdb-continue-until-point))
  265.  
  266. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  267. ;;; Gdb Source minor mode.
  268. ;;;
  269. ;;; gdb-src-mode(arg)
  270. ;;;
  271. ;;; Gdb-src-mode defines the following buffer specific variables:
  272. ;;; 
  273. ;;; gdb-src-mode:            The current status of gdb-src-mode
  274. ;;; gdb-associated-buffer:   The gdb buffer to send commands to.
  275. ;;; gdb-src-mode-map-before: The Keymap before entering src mode
  276. ;;; gdb-initial-readonly:    Initial readonly status
  277. ;;;
  278. (defun gdb-src-mode (arg)
  279. "Minor mode for interacting with gdb from a c source file.
  280. With arg, turn gdb-src-mode on iff arg is positive.  In gdb-src-mode,
  281. you may send an associated gdb buffer commands from the current buffer
  282. containing c source code."
  283.   (interactive "P")
  284.   (make-local-variable 'gdb-src-mode)
  285.   (make-local-variable 'gdb-associated-buffer)
  286.   (make-local-variable 'gdb-src-mode-map-before)
  287.   (make-local-variable 'gdb-initial-readonly)
  288.   (setq gdb-src-mode
  289.     (if (null arg)
  290.         (not gdb-src-mode)
  291.       (> (prefix-numeric-value arg) 0)))
  292.  
  293.   (if gdb-src-mode
  294.       (progn
  295.     ; inherit global values
  296.     (or (assq 'gdb-src-mode minor-mode-alist)
  297.         (setq minor-mode-alist
  298.           (cons '(gdb-src-mode "-Gdb-Src")
  299.             minor-mode-alist)))
  300.     (if gdb-associated-buffer nil
  301.       (progn
  302.         (setq gdb-initial-readonly buffer-read-only)
  303.         (setq gdb-associated-buffer current-gdb-buffer))
  304.       )
  305.     (setq buffer-read-only t)
  306.     (setq gdb-src-mode-map-before (current-local-map))
  307.     (use-local-map gdb-src-mode-map)
  308.     (message "Enter gdb-src-mode.")
  309.     )
  310.     (progn
  311.       (use-local-map gdb-src-mode-map-before)
  312.       (setq buffer-read-only gdb-initial-readonly)
  313.       (message "Exit gdb-src-mode.")
  314.       )
  315.     )
  316.   
  317.   ;; Update mode-line by setting buffer-modified to itself.
  318.   (set-buffer-modified-p (buffer-modified-p))
  319.   )
  320.  
  321. ;;
  322. ;; Sends commands to gdb process.
  323.  
  324. (defun gdb-call-from-src (command)
  325.   "Send associated gdb process COMMAND displaying source in this window."
  326.   (setq gdb-src-call-p t)
  327.   (pop-to-buffer (or gdb-associated-buffer current-gdb-buffer))
  328.   (goto-char (dot-max))
  329.   (beginning-of-line)
  330. ; Go past gdb prompt 
  331.   (re-search-forward
  332.      shell-prompt-pattern (save-excursion (end-of-line) (point))  t)
  333. ; Delete any not-supposed-to-be-there text
  334.   (delete-region (point) (dot-max)) 
  335.   (insert-string command)
  336.   (shell-send-input))
  337.  
  338.  
  339.  
  340. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  341. ;;;
  342. ;;; Define Commands for GDB SRC Mode Buffer
  343. ;;;
  344. ;;;
  345. ;;;
  346.  
  347.  
  348. ;;; Set this variable to a valid format string
  349. ;;; to print c-sexps in a different way (hex,octal, etc)
  350.  
  351. (defvar gdb-print-format "")
  352.  
  353. (defun gdb-print-c-sexp ()
  354.   "Find the nearest c-mode sexp. Send it to gdb with print command."
  355.   (interactive)
  356.   (let* ((tag (find-c-sexp))
  357.     (command (concat "print " gdb-print-format tag)))
  358.     (gdb-call-from-src command))
  359. )
  360.     
  361.  
  362. (defun gdb-*print-c-sexp ()
  363.   "Find the nearest c-mode sexp. Send it to gdb with the print * command."
  364.   (interactive)
  365.   (let* ((tag (find-c-sexp))
  366.     (command (concat "print " gdb-print-format "*"  tag)))
  367.     (gdb-call-from-src  command))
  368. )
  369.  
  370. (defun gdb-whatis-c-sexp ()
  371.   "Find the nearest c-mode sexp. Send it to gdb with the whatis command. "
  372.   (interactive)
  373.   (let* ((tag (find-c-sexp))
  374.      (command (concat "whatis " tag)))
  375.     (gdb-call-from-src command))
  376.   )
  377.  
  378. (defun goto-gdb ()
  379.   (interactive)
  380.   (bury-buffer (current-buffer))
  381.   (switch-to-buffer (or gdb-associated-buffer current-gdb-buffer))
  382.   )
  383.  
  384. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  385. ;;;
  386. ;;;  The following functions are used to extract the closest surrounding
  387. ;;;  c expression from point
  388. ;;;
  389. ;;;
  390. (defun back-sexp ()
  391.   "Version of backward-sexp that catches errors"
  392.   (condition-case nil
  393.       (backward-sexp)
  394.     (error t)))
  395.  
  396. (defun forw-sexp ()
  397.   "Version of forward-sexp that catches errors"
  398.   (condition-case nil
  399.      (forward-sexp)
  400.     (error t)))
  401.  
  402. (defun sexp-compound-sep (span-start span-end)
  403.   " Returns '.' for '->' & '.', returns ' ' for white space,
  404.     returns '?' for other puctuation"  
  405.   (let ((result ? )
  406.     (syntax))
  407.     (while (< span-start span-end)
  408.       (setq syntax (char-syntax (char-after span-start)))
  409.       (cond
  410.        ((= syntax ? ) t)
  411.        ((= syntax ?.) (setq syntax (char-after span-start))
  412.     (cond 
  413.      ((= syntax ?.) (setq result ?.))
  414.      ((and (= syntax ?-) (= (char-after (+ span-start 1)) ?>))
  415.       (setq result ?.)
  416.       (setq span-start (+ span-start 1)))
  417.      (t (setq span-start span-end)
  418.         (setq result ??)))))
  419.       (setq span-start (+ span-start 1)))
  420.     result 
  421.     )
  422.   )
  423.  
  424. (defun sexp-compound (first second)
  425.   "Returns non-nil if the concatenation of two S-EXPs result in a Single C 
  426. token. The two S-EXPs are represented as a cons cells, where the car 
  427. specifies the point in the current buffer that marks the begging of the 
  428. S-EXP and the cdr specifies the character after the end of the S-EXP
  429. Link S-Exps of the form:
  430.       Sexp -> SexpC
  431.       Sexp . Sexp
  432.       Sexp (Sexp)        Maybe exclude if first Sexp is: if, while, do, for, switch
  433.       Sexp [Sexp]
  434.       (Sexp) Sexp
  435.       [Sexp] Sexp"
  436.   (let ((span-start (cdr first))
  437.     (span-end (car second))
  438.     (syntax))
  439.     (setq syntax (sexp-compound-sep span-start span-end))
  440.     (cond
  441.      ((= (car first) (car second)) nil)
  442.      ((= (cdr first) (cdr second)) nil)
  443.      ((= syntax ?.) t)
  444.      ((= syntax ? )
  445.      (setq span-start (char-after (- span-start 1)))
  446.      (setq span-end (char-after span-end))
  447.      (cond
  448.       ((= span-start ?) ) t )
  449.       ((= span-start ?] ) t )
  450.           ((= span-end ?( ) t )
  451.       ((= span-end ?[ ) t )
  452.       (t nil))
  453.      )
  454.      (t nil))
  455.     )
  456.   )
  457.  
  458. (defun sexp-cur ()
  459.   "Returns the  S-EXP that Point is a member, Point is set to begging of S-EXP.
  460. The S-EXPs is represented as a cons cell, where the car specifies the point in
  461. the current buffer that marks the begging of the S-EXP and the cdr specifies 
  462. the character after the end of the S-EXP"
  463.   (let ((p (point)) (begin) (end))
  464.     (back-sexp)
  465.     (setq begin (point))
  466.     (forw-sexp)
  467.     (setq end (point))
  468.     (if (>= p end) 
  469.     (progn
  470.      (setq begin p)
  471.      (goto-char p)
  472.      (forw-sexp)
  473.      (setq end (point))
  474.      )
  475.       )
  476.     (goto-char begin)
  477.     (cons begin end)
  478.     )
  479.   )
  480.  
  481. (defun sexp-prev ()
  482.   "Returns the previous S-EXP, Point is set to begging of that S-EXP.
  483. The S-EXPs is represented as a cons cell, where the car specifies the point in
  484. the current buffer that marks the begging of the S-EXP and the cdr specifies 
  485. the character after the end of the S-EXP"
  486.   (let ((begin) (end))
  487.     (back-sexp)
  488.     (setq begin (point))
  489.     (forw-sexp)
  490.     (setq end (point))
  491.     (goto-char begin)
  492.     (cons begin end))
  493. )
  494.  
  495. (defun sexp-next ()
  496.   "Returns the following S-EXP, Point is set to begging of that S-EXP.
  497. The S-EXPs is represented as a cons cell, where the car specifies the point in
  498. the current buffer that marks the begging of the S-EXP and the cdr specifies 
  499. the character after the end of the S-EXP"
  500.   (let ((begin) (end))
  501.     (forw-sexp)
  502.     (forw-sexp)
  503.     (setq end (point))
  504.     (back-sexp)
  505.     (setq begin (point))
  506.     (cons begin end)
  507.     )
  508.   )
  509.  
  510. (defun find-c-sexp ()
  511.   "Returns the Complex  S-EXP that surrounds Point"
  512.   (interactive)
  513.   (save-excursion
  514.     (let ((p) (sexp) (test-sexp))
  515.       (setq p (point))
  516.       (setq sexp (sexp-cur))
  517.       (setq test-sexp (sexp-prev))
  518.       (while (sexp-compound test-sexp sexp)
  519.     (setq sexp (cons (car test-sexp) (cdr sexp)))
  520.     (goto-char (car sexp))
  521.     (setq test-sexp (sexp-prev))
  522.     )
  523.       (goto-char p)
  524.       (setq test-sexp (sexp-next))
  525.       (while (sexp-compound sexp test-sexp)
  526.     (setq sexp (cons (car sexp) (cdr test-sexp)))
  527.     (setq test-sexp (sexp-next))
  528.     )
  529.       (buffer-substring (car sexp) (cdr sexp))
  530.       )
  531.     )
  532.   )
  533.  
  534. ;;;  Mouse support for gdbsrc mode modified from existing mouse code.
  535. ;;;
  536. ;;;
  537.  
  538. (defun x-gdb-steal-csexp (arg) 
  539.   "Copies the containing s-expression located at the mouse cursor to point."
  540.   (let (relative-coordinate rel-x rel-y the-sexp)
  541.     (save-window-excursion ; don't forget what window we're in
  542.       (save-excursion      ; or our position in the window
  543.           ;;
  544.           ;; get the position of the mouse click...
  545.      (setq relative-coordinate (x-mouse-select arg))
  546.      (setq rel-x (car relative-coordinate))
  547.      (setq rel-y (car (cdr relative-coordinate)))
  548.      ;;
  549.      (if relative-coordinate 
  550.          (progn
  551.              ;;
  552.              ;; move to the position of the mouse click
  553.              ;; and grab the sexpression...
  554.            (move-to-window-line rel-y)
  555.            (move-to-column (+ rel-x (current-column)))
  556.            (setq the-sexp (find-c-sexp))))))))
  557.   
  558. (defun x-gdb-print-csexp (arg)
  559.   (gdb-call-from-src
  560.      (concat "print "  gdb-print-format (x-gdb-steal-csexp arg))))
  561.  
  562. (defun x-gdb-*print-csexp (arg)
  563.   (gdb-call-from-src
  564.      (concat "print *"  gdb-print-format (x-gdb-steal-csexp arg))))
  565.  
  566. (defun x-gdb-print-region (arg)
  567.   (let (( command  (concat "print " gdb-print-format (x-get-cut-buffer))))
  568.     (gdb-call-from-src command)))
  569.  
  570. (defun x-gdb-*print-region (arg)
  571.   (let (( command  (concat "print *" gdb-print-format (x-get-cut-buffer))))
  572.     (gdb-call-from-src command)))
  573.  
  574. (defun x-gdb-break-region (arg)
  575.  (let (( command  (concat "break " (x-get-cut-buffer))))
  576.     (gdb-call-from-src command)))
  577.  
  578. (defun x-gdb-continue-until-point (arg)
  579.   (if (coordinates-in-window-p arg (selected-window))
  580.       (progn
  581.     (x-mouse-set-point arg)
  582.     (gdb-call-from-src (concat "break " (1+ (count-lines 1 (point)))))
  583.     (gdb-call-from-src "c"))))
  584.     
  585. (defun x-cut-marked-region (arg)
  586.   (if (coordinates-in-window-p arg (selected-window))
  587.       (progn
  588.     (save-excursion
  589.       (x-mouse-set-mark arg)
  590.       (let ((beg (point))
  591.         (end (mark)))
  592.         (x-store-cut-buffer (buffer-substring beg end))
  593.         (copy-region-as-kill beg end)))
  594.     )
  595.     (message "Mouse not in selected window"))
  596. )
  597.  
  598. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  599. ;; Functions extended from gdb.el for gdbsrc.
  600. ;;
  601. ;; gdb-src-set-buffer - added a check to set buffer to gdb-associated-buffer
  602. ;;                  to handle multiple gdb sessions being driven from src
  603. ;;                  files.
  604. ;; gdb-src-display-line - added call to setup-gdb-src-window to put
  605. ;;                  source buffer in gdb-src-mode and save away window name.
  606. ;;
  607. ;; gdb-src-filter - scans for gdb prompt to know when to change windows.
  608. ;;                  Calls gdb-filter.
  609. ;;
  610. ;; gdb-src-sentinel - resets the gdb-associated-buffer to nil when 
  611. ;;                  process exits. Calls gdb-sentinel.
  612. ;;
  613. (defun gdb-set-buffer ()
  614.   "New gdb-set-buffer to allow gdb commands to be
  615.    called from other buffers besides current-gdb-buffer"
  616.   (cond ((eq major-mode 'gdb-mode)
  617.     (setq current-gdb-buffer (current-buffer)))
  618.     (gdb-src-call-p (setq current-gdb-buffer gdb-associated-buffer))))
  619.  
  620. (defun gdb-src-display-line (true-file line)
  621.   (let* ((buffer (find-file-noselect true-file))
  622.      (window (display-buffer buffer t))
  623.      (pos))
  624.     (save-excursion
  625.       (set-buffer buffer)
  626.       (setup-gdb-src-window window)
  627. ;      (message (buffer-name buffer))
  628.       (save-restriction
  629.     (widen)
  630.     (goto-line line)
  631.     (setq pos (point))
  632.     (setq overlay-arrow-string "=>")
  633.     (or overlay-arrow-position
  634.         (setq overlay-arrow-position (make-marker)))
  635.     (set-marker overlay-arrow-position (point) (current-buffer)))
  636.       (cond ((or (< pos (point-min)) (> pos (point-max)))
  637.          (widen)
  638.          (goto-char pos))))
  639.     (set-window-point window overlay-arrow-position )))
  640.  
  641. (defun gdb-src-mode-filter (proc string)
  642.    (let ((prompt (string-match gdb-prompt-pattern string)))
  643.      (gdb-filter proc string)
  644.      (if prompt 
  645.      (and gdb-src-call-p gdb-src-window
  646.           (select-window gdb-src-window)
  647.           (setq gdb-src-call-p nil))))
  648. )
  649.  
  650. (defun gdb-src-mode-sentinel (proc msg)
  651.   (setq gdb-associated-buffer nil)
  652.   (let ((buffers (buffer-list)))
  653.     (mapcar (function (lambda (buffer) 
  654.             (set-buffer buffer)
  655.             (if (eql gdb-associated-buffer current-gdb-buffer)
  656.                 (kill-local-variable 'gdb-associated-buffer))))
  657.         buffers))
  658.   (gdb-sentinel proc msg)
  659.   (message "Gdbsrc finished"))
  660.  
  661.  
  662. (defun goto-gdb ()
  663.   (interactive)
  664.   (bury-buffer (current-buffer))
  665.   (and current-gdb-buffer (switch-to-buffer current-gdb-buffer))
  666. )
  667.  
  668. ;;                      ---Deb
  669. ;;
  670. ;;
  671. ;;
  672. ;;
  673. ;;
  674. ;; Debra L. Ayers              Internet: ayers@asc.slb.com    
  675. ;;                          UUCP    : cs.utexas.edu!asc.slb.com!ayers
  676. ;;                          Phone   : (512) 331-3274
  677.