comparison lisp/gud.el @ 48293:3a409a9620a7

(gud-find-file): Set up GDB tool bar. (gud-menu-map): New commands: run, goto. Enable some commands for gdba. (gud-query-cmdline): Pass default directory to gdba. (gdb): Defune gud-goto and gud-run. (gud-gdb-complete-command): Maybe use gdba-complete-filter. (gud-mode): Set up local tool bar. (gud-display-line): For gdba, call gdb-display-source-buffer. (gud-basic-call): For gdba, maybe delete the current prompt. (gud-tool-bar-map): New variable. (gud-read-address): Correction.
author Nick Roberts <nickrob@snap.net.nz>
date Thu, 14 Nov 2002 01:56:58 +0000
parents b82c4ff4d201
children 21b6ba166466
comparison
equal deleted inserted replaced
48292:27d9e4538750 48293:3a409a9620a7
92 (let ((minor-mode gud-minor-mode) 92 (let ((minor-mode gud-minor-mode)
93 (buf (funcall gud-find-file file))) 93 (buf (funcall gud-find-file file)))
94 (when buf 94 (when buf
95 ;; Copy `gud-minor-mode' to the found buffer to turn on the menu. 95 ;; Copy `gud-minor-mode' to the found buffer to turn on the menu.
96 (with-current-buffer buf 96 (with-current-buffer buf
97 (set (make-local-variable 'gud-minor-mode) minor-mode)) 97 (set (make-local-variable 'gud-minor-mode) minor-mode)
98 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map))
98 buf))) 99 buf)))
99 100
100 (easy-mmode-defmap gud-menu-map 101 (easy-mmode-defmap gud-menu-map
101 '(([refresh] "Refresh" . gud-refresh) 102 '(([refresh] "Refresh" . gud-refresh)
103 ([run] menu-item "Run" gud-run
104 :enable (memq gud-minor-mode '(gdba gdb)))
105 ([goto] menu-item "Continue to selection" gud-goto
106 :enable (memq gud-minor-mode '(gdba gdb)))
102 ([remove] "Remove Breakpoint" . gud-remove) 107 ([remove] "Remove Breakpoint" . gud-remove)
103 ([tbreak] menu-item "Temporary Breakpoint" gud-tbreak 108 ([tbreak] menu-item "Temporary Breakpoint" gud-tbreak
104 :enable (memq gud-minor-mode '(gdb sdb xdb))) 109 :enable (memq gud-minor-mode '(gdba gdb sdb xdb)))
105 ([break] "Set Breakpoint" . gud-break) 110 ([break] "Set Breakpoint" . gud-break)
106 ([up] menu-item "Up Stack" gud-up 111 ([up] menu-item "Up Stack" gud-up
107 :enable (memq gud-minor-mode '(gdb dbx xdb jdb))) 112 :enable (memq gud-minor-mode '(gdba gdb dbx xdb jdb)))
108 ([down] menu-item "Down Stack" gud-down 113 ([down] menu-item "Down Stack" gud-down
109 :enable (memq gud-minor-mode '(gdb dbx xdb jdb))) 114 :enable (memq gud-minor-mode '(gdba gdb dbx xdb jdb)))
110 ([print] "Print Expression" . gud-print) 115 ([print] "Print Expression" . gud-print)
116 ([display] menu-item "Display Expression" gud-display
117 :enable (eq gud-minor-mode 'gdba))
111 ([finish] menu-item "Finish Function" gud-finish 118 ([finish] menu-item "Finish Function" gud-finish
112 :enable (memq gud-minor-mode '(gdb xdb jdb))) 119 :enable (memq gud-minor-mode '(gdba gdb xdb jdb)))
113 ([stepi] "Step Instruction" . gud-stepi) 120 ([stepi] "Step Instruction" . gud-stepi)
114 ([step] "Step Line" . gud-step) 121 ([step] "Step Line" . gud-step)
115 ([next] "Next Line" . gud-next) 122 ([next] "Next Line" . gud-next)
116 ([cont] "Continue" . gud-cont)) 123 ([cont] "Continue" . gud-cont))
117 "Menu for `gud-mode'." 124 "Menu for `gud-mode'."
384 (unless (boundp hist-sym) (set hist-sym nil)) 391 (unless (boundp hist-sym) (set hist-sym nil))
385 (read-from-minibuffer 392 (read-from-minibuffer
386 (format "Run %s (like this): " minor-mode) 393 (format "Run %s (like this): " minor-mode)
387 (or (car-safe (symbol-value hist-sym)) 394 (or (car-safe (symbol-value hist-sym))
388 (concat (or cmd-name (symbol-name minor-mode)) 395 (concat (or cmd-name (symbol-name minor-mode))
389 " " 396 " " default-directory
390 (or init 397 (or init
391 (let ((file nil)) 398 (let ((file nil))
392 (dolist (f (directory-files default-directory) file) 399 (dolist (f (directory-files default-directory) file)
393 (if (and (file-executable-p f) 400 (if (and (file-executable-p f)
394 (not (file-directory-p f)) 401 (not (file-directory-p f))
420 (gud-def gud-jump "tbreak %f:%l\njump %f:%l" "\C-j" "Relocate execution address to line at point in source buffer.") 427 (gud-def gud-jump "tbreak %f:%l\njump %f:%l" "\C-j" "Relocate execution address to line at point in source buffer.")
421 428
422 (gud-def gud-up "up %p" "<" "Up N stack frames (numeric arg).") 429 (gud-def gud-up "up %p" "<" "Up N stack frames (numeric arg).")
423 (gud-def gud-down "down %p" ">" "Down N stack frames (numeric arg).") 430 (gud-def gud-down "down %p" ">" "Down N stack frames (numeric arg).")
424 (gud-def gud-print "print %e" "\C-p" "Evaluate C expression at point.") 431 (gud-def gud-print "print %e" "\C-p" "Evaluate C expression at point.")
432 (gud-def gud-goto "until %l" "\C-u" "Continue up to current line.")
433 (gud-def gud-run "run" nil "Run the program.")
425 434
426 (local-set-key "\C-i" 'gud-gdb-complete-command) 435 (local-set-key "\C-i" 'gud-gdb-complete-command)
427 (local-set-key [menu-bar debug tbreak] '("Temporary Breakpoint" . gud-tbreak)) 436 (local-set-key [menu-bar debug tbreak] '("Temporary Breakpoint" . gud-tbreak))
428 (local-set-key [menu-bar debug finish] '("Finish Function" . gud-finish)) 437 (local-set-key [menu-bar debug finish] '("Finish Function" . gud-finish))
429 (local-set-key [menu-bar debug up] '("Up Stack" . gud-up)) 438 (local-set-key [menu-bar debug up] '("Up Stack" . gud-up))
462 ;; Find the word break. This match will always succeed. 471 ;; Find the word break. This match will always succeed.
463 (string-match "\\(\\`\\| \\)\\([^ ]*\\)\\'" command) 472 (string-match "\\(\\`\\| \\)\\([^ ]*\\)\\'" command)
464 (setq gud-gdb-complete-break (match-beginning 2) 473 (setq gud-gdb-complete-break (match-beginning 2)
465 command-word (substring command gud-gdb-complete-break)) 474 command-word (substring command gud-gdb-complete-break))
466 ;; Temporarily install our filter function. 475 ;; Temporarily install our filter function.
467 (let ((gud-marker-filter 'gud-gdb-complete-filter)) 476 (let ((gud-marker-filter (if (eq gud-minor-mode 'gdba)
477 'gdba-complete-filter
478 'gud-gdb-complete-filter)))
468 ;; Issue the command to GDB. 479 ;; Issue the command to GDB.
469 (gud-basic-call (concat "complete " command)) 480 (gud-basic-call (concat "complete " command))
470 (setq gud-gdb-complete-in-progress t 481 (setq gud-gdb-complete-in-progress t
471 gud-gdb-complete-string nil 482 gud-gdb-complete-string nil
472 gud-gdb-complete-list nil) 483 gud-gdb-complete-list nil)
2206 Other commands for interacting with the debugger process are inherited from 2217 Other commands for interacting with the debugger process are inherited from
2207 comint mode, which see." 2218 comint mode, which see."
2208 (setq mode-line-process '(":%s")) 2219 (setq mode-line-process '(":%s"))
2209 (define-key (current-local-map) "\C-c\C-l" 'gud-refresh) 2220 (define-key (current-local-map) "\C-c\C-l" 'gud-refresh)
2210 (set (make-local-variable 'gud-last-frame) nil) 2221 (set (make-local-variable 'gud-last-frame) nil)
2222 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
2211 (make-local-variable 'comint-prompt-regexp) 2223 (make-local-variable 'comint-prompt-regexp)
2212 ;; Don't put repeated commands in command history many times. 2224 ;; Don't put repeated commands in command history many times.
2213 (set (make-local-variable 'comint-input-ignoredups) t) 2225 (set (make-local-variable 'comint-input-ignoredups) t)
2214 (make-local-variable 'paragraph-start) 2226 (make-local-variable 'paragraph-start)
2215 (set (make-local-variable 'gud-delete-prompt-marker) (make-marker))) 2227 (set (make-local-variable 'gud-delete-prompt-marker) (make-marker)))
2229 ;; The other three args specify the values to use 2241 ;; The other three args specify the values to use
2230 ;; for local variables in the debugger buffer. 2242 ;; for local variables in the debugger buffer.
2231 (defun gud-common-init (command-line massage-args marker-filter &optional find-file) 2243 (defun gud-common-init (command-line massage-args marker-filter &optional find-file)
2232 (let* ((words (split-string command-line)) 2244 (let* ((words (split-string command-line))
2233 (program (car words)) 2245 (program (car words))
2234 (dir default-directory)
2235 ;; Extract the file name from WORDS 2246 ;; Extract the file name from WORDS
2236 ;; and put t in its place. 2247 ;; and put t in its place.
2237 ;; Later on we will put the modified file name arg back there. 2248 ;; Later on we will put the modified file name arg back there.
2238 (file-word (let ((w (cdr words))) 2249 (file-word (let ((w (cdr words)))
2239 (while (and w (= ?- (aref (car w) 0))) 2250 (while (and w (= ?- (aref (car w) 0)))
2253 (if (file-name-directory file-subst) 2264 (if (file-name-directory file-subst)
2254 (expand-file-name file-subst) 2265 (expand-file-name file-subst)
2255 file-subst))) 2266 file-subst)))
2256 (filepart (and file-word (concat "-" (file-name-nondirectory file))))) 2267 (filepart (and file-word (concat "-" (file-name-nondirectory file)))))
2257 (pop-to-buffer (concat "*gud" filepart "*")) 2268 (pop-to-buffer (concat "*gud" filepart "*"))
2258 (setq default-directory dir)
2259 ;; Set default-directory to the file's directory. 2269 ;; Set default-directory to the file's directory.
2260 (and file-word 2270 (and file-word
2261 gud-chdir-before-run 2271 gud-chdir-before-run
2262 ;; Don't set default-directory if no directory was specified. 2272 ;; Don't set default-directory if no directory was specified.
2263 ;; In that case, either the file is found in the current directory, 2273 ;; In that case, either the file is found in the current directory,
2422 (save-excursion 2432 (save-excursion
2423 (or (eq (current-buffer) gud-comint-buffer) 2433 (or (eq (current-buffer) gud-comint-buffer)
2424 (set-buffer gud-comint-buffer)) 2434 (set-buffer gud-comint-buffer))
2425 (gud-find-file true-file))) 2435 (gud-find-file true-file)))
2426 (window (and buffer (or (get-buffer-window buffer) 2436 (window (and buffer (or (get-buffer-window buffer)
2427 (display-buffer buffer)))) 2437 (if (eq gud-minor-mode 'gdba)
2438 (gdb-display-source-buffer buffer)
2439 (display-buffer buffer)))))
2428 (pos)) 2440 (pos))
2429 (if buffer 2441 (if buffer
2430 (progn 2442 (progn
2431 (save-excursion 2443 (save-excursion
2432 (set-buffer buffer) 2444 (set-buffer buffer)
2492 ;; There might be text left in STR when the loop ends. 2504 ;; There might be text left in STR when the loop ends.
2493 (concat result str))) 2505 (concat result str)))
2494 2506
2495 (defun gud-read-address () 2507 (defun gud-read-address ()
2496 "Return a string containing the core-address found in the buffer at point." 2508 "Return a string containing the core-address found in the buffer at point."
2497 (save-excursion 2509 (save-match-data
2498 (let ((pt (point)) found begin) 2510 (save-excursion
2499 (setq found (if (search-backward "0x" (- pt 7) t) (point))) 2511 (let ((pt (point)) found begin)
2500 (cond 2512 (setq found (if (search-backward "0x" (- pt 7) t) (point)))
2501 (found (forward-char 2) 2513 (cond
2502 (buffer-substring found 2514 (found (forward-char 2)
2503 (progn (re-search-forward "[^0-9a-f]") 2515 (buffer-substring found
2504 (forward-char -1) 2516 (progn (re-search-forward "[^0-9a-f]")
2505 (point)))) 2517 (forward-char -1)
2506 (t (setq begin (progn (re-search-backward "[^0-9]") 2518 (point))))
2507 (forward-char 1) 2519 (t (setq begin (progn (re-search-backward "[^0-9]")
2508 (point))) 2520 (forward-char 1)
2509 (forward-char 1) 2521 (point)))
2510 (re-search-forward "[^0-9]") 2522 (forward-char 1)
2511 (forward-char -1) 2523 (re-search-forward "[^0-9]")
2512 (buffer-substring begin (point))))))) 2524 (forward-char -1)
2525 (buffer-substring begin (point))))))))
2513 2526
2514 (defun gud-call (fmt &optional arg) 2527 (defun gud-call (fmt &optional arg)
2515 (let ((msg (gud-format-command fmt arg))) 2528 (let ((msg (gud-format-command fmt arg)))
2516 (message "Command: %s" msg) 2529 (message "Command: %s" msg)
2517 (sit-for 0) 2530 (sit-for 0)
2519 2532
2520 (defun gud-basic-call (command) 2533 (defun gud-basic-call (command)
2521 "Invoke the debugger COMMAND displaying source in other window." 2534 "Invoke the debugger COMMAND displaying source in other window."
2522 (interactive) 2535 (interactive)
2523 (gud-set-buffer) 2536 (gud-set-buffer)
2524 (let ((command (concat command "\n")) 2537 (let ((proc (get-buffer-process gud-comint-buffer)))
2525 (proc (get-buffer-process gud-comint-buffer)))
2526 (or proc (error "Current buffer has no process")) 2538 (or proc (error "Current buffer has no process"))
2527 ;; Arrange for the current prompt to get deleted. 2539 ;; Arrange for the current prompt to get deleted.
2528 (save-excursion 2540 (save-excursion
2529 (set-buffer gud-comint-buffer) 2541 (set-buffer gud-comint-buffer)
2530 (save-restriction 2542 (save-restriction
2531 (widen) 2543 (widen)
2532 (goto-char (process-mark proc)) 2544 (goto-char (process-mark proc))
2533 (forward-line 0) 2545 (forward-line 0)
2534 (if (looking-at comint-prompt-regexp) 2546 (if (looking-at comint-prompt-regexp)
2535 (set-marker gud-delete-prompt-marker (point))))) 2547 (set-marker gud-delete-prompt-marker (point)))
2536 (process-send-string proc command))) 2548 (if (eq gud-minor-mode 'gdba)
2549 (apply comint-input-sender (list proc command))
2550 (process-send-string proc (concat command "\n")))))))
2537 2551
2538 (defun gud-refresh (&optional arg) 2552 (defun gud-refresh (&optional arg)
2539 "Fix up a possibly garbled display, and redraw the arrow." 2553 "Fix up a possibly garbled display, and redraw the arrow."
2540 (interactive "P") 2554 (interactive "P")
2541 (or gud-last-frame (setq gud-last-frame gud-last-last-frame)) 2555 (or gud-last-frame (setq gud-last-frame gud-last-last-frame))
2717 (if class-found 2731 (if class-found
2718 (car class-found) 2732 (car class-found)
2719 (message "gud-find-class: class for file %s not found in gud-jdb-class-source-alist!" f) 2733 (message "gud-find-class: class for file %s not found in gud-jdb-class-source-alist!" f)
2720 nil)))) 2734 nil))))
2721 2735
2722 (provide 'gud) 2736 (defvar gud-tool-bar-map
2737 (if (display-graphic-p)
2738 (let ((tool-bar-map (make-sparse-keymap)))
2739 (tool-bar-add-item-from-menu 'gud-break "gud-break" gud-minor-mode-map)
2740 (tool-bar-add-item-from-menu 'gud-remove "gud-remove" gud-minor-mode-map)
2741 (tool-bar-add-item-from-menu 'gud-print "gud-print" gud-minor-mode-map)
2742 (tool-bar-add-item-from-menu 'gud-display "gud-display" gud-minor-mode-map)
2743 (tool-bar-add-item-from-menu 'gud-run "gud-run" gud-minor-mode-map)
2744 (tool-bar-add-item-from-menu 'gud-goto "gud-goto" gud-minor-mode-map)
2745 (tool-bar-add-item-from-menu 'gud-cont "gud-cont" gud-minor-mode-map)
2746 (tool-bar-add-item-from-menu 'gud-step "gud-step" gud-minor-mode-map)
2747 (tool-bar-add-item-from-menu 'gud-next "gud-next" gud-minor-mode-map)
2748 (tool-bar-add-item-from-menu 'gud-finish "gud-finish" gud-minor-mode-map)
2749 (tool-bar-add-item-from-menu 'gud-up "gud-up" gud-minor-mode-map)
2750 (tool-bar-add-item-from-menu 'gud-down "gud-down" gud-minor-mode-map)
2751 tool-bar-map)))
2752
2753 (provide 'mygud)
2723 2754
2724 ;;; gud.el ends here 2755 ;;; gud.el ends here