comparison lisp/gud.el @ 48922:aa7d3d1a21a3

(gud-menu-map): Add jdb support for "run". (gud-jdb-find-source-using-classpath): Use 'identity. (gud-jdb-marker-filter): Marker regexp and filename filtering change to support a backwards-incompatible change in Sun's jdb line number display in SDK versions 1.4. (gud-format-command): gud-find-class now requires two parameters (file and linenumber). (gud-find-class): Bulk of the change related to using c-syntactic symbols to locate nested class declarations in java sources visited by java-mode (cc-mode).
author Pavel Janík <Pavel@Janik.cz>
date Sat, 21 Dec 2002 23:04:46 +0000
parents 480e8dc8fc37
children 8e748161e8cf
comparison
equal deleted inserted replaced
48921:3aa5ba679145 48922:aa7d3d1a21a3
91 91
92 (easy-mmode-defmap gud-menu-map 92 (easy-mmode-defmap gud-menu-map
93 '(([refresh] "Refresh" . gud-refresh) 93 '(([refresh] "Refresh" . gud-refresh)
94 ([run] menu-item "Run" gud-run 94 ([run] menu-item "Run" gud-run
95 :enable (and (not gud-running) 95 :enable (and (not gud-running)
96 (memq gud-minor-mode '(gdba gdb)))) 96 (memq gud-minor-mode '(gdba gdb jdb))))
97 ([goto] menu-item "Continue to selection" gud-goto 97 ([goto] menu-item "Continue to selection" gud-goto
98 :enable (and (not gud-running) 98 :enable (and (not gud-running)
99 (memq gud-minor-mode '(gdba gdb)))) 99 (memq gud-minor-mode '(gdba gdb))))
100 ([remove] menu-item "Remove Breakpoint" gud-remove 100 ([remove] menu-item "Remove Breakpoint" gud-remove
101 :enable (not gud-running)) 101 :enable (not gud-running))
1365 ;; AUTHOR: Derek Davies <ddavies@world.std.com> 1365 ;; AUTHOR: Derek Davies <ddavies@world.std.com>
1366 ;; Zoltan Kemenczy <zoltan@ieee.org;zkemenczy@rim.net> 1366 ;; Zoltan Kemenczy <zoltan@ieee.org;zkemenczy@rim.net>
1367 ;; 1367 ;;
1368 ;; CREATED: Sun Feb 22 10:46:38 1998 Derek Davies. 1368 ;; CREATED: Sun Feb 22 10:46:38 1998 Derek Davies.
1369 ;; UPDATED: Nov 11, 2001 Zoltan Kemenczy 1369 ;; UPDATED: Nov 11, 2001 Zoltan Kemenczy
1370 ;; Dec 10, 2002 Zoltan Kemenczy - added nested class support
1370 ;; 1371 ;;
1371 ;; INVOCATION NOTES: 1372 ;; INVOCATION NOTES:
1372 ;; 1373 ;;
1373 ;; You invoke jdb-mode with: 1374 ;; You invoke jdb-mode with:
1374 ;; 1375 ;;
1808 (let 1809 (let
1809 (;; Replace dots with slashes and append ".java" to generate file 1810 (;; Replace dots with slashes and append ".java" to generate file
1810 ;; name relative to classpath 1811 ;; name relative to classpath
1811 (filename 1812 (filename
1812 (concat 1813 (concat
1813 (mapconcat (lambda (x) x) 1814 (mapconcat 'identity
1814 (split-string 1815 (split-string
1815 ;; Eliminate any subclass references in the class 1816 ;; Eliminate any subclass references in the class
1816 ;; name string. These start with a "$" 1817 ;; name string. These start with a "$"
1817 ((lambda (x) 1818 ((lambda (x)
1818 (if (string-match "$.*" x) 1819 (if (string-match "$.*" x)
1895 ;; matches <line-number>. We don't care about using 1896 ;; matches <line-number>. We don't care about using
1896 ;; <method> so we don't "group" it. 1897 ;; <method> so we don't "group" it.
1897 ;; 1898 ;;
1898 ;; FIXME: Java ID's are UNICODE strings, this matches ASCII 1899 ;; FIXME: Java ID's are UNICODE strings, this matches ASCII
1899 ;; ID's only. 1900 ;; ID's only.
1900 "\\(?:\[\\([0-9]+\\)\] \\)*\\([a-zA-Z0-9.$_]+\\)\\.[a-zA-Z0-9$_<>(),]+ \ 1901 ;;
1901 \\(([a-zA-Z0-9.$_]+:\\|line=\\)\\([0-9]+\\)" 1902 ;; The "," in the last square-bracket is necessary because of
1903 ;; Sun's total disrespect for backwards compatibility in
1904 ;; reported line numbers from jdb - starting in 1.4.0 they
1905 ;; introduced a comma at the thousands position (how
1906 ;; ingenious!)
1907
1908 "\\(\[[0-9]+\] \\)*\\([a-zA-Z0-9.$_]+\\)\\.[a-zA-Z0-9$_<>(),]+ \
1909 \\(([a-zA-Z0-9.$_]+:\\|line=\\)\\([0-9,]+\\)"
1902 gud-marker-acc) 1910 gud-marker-acc)
1903 1911
1904 ;; A good marker is one that: 1912 ;; A good marker is one that:
1905 ;; 1) does not have a "[n] " prefix (not part of a stack backtrace) 1913 ;; 1) does not have a "[n] " prefix (not part of a stack backtrace)
1906 ;; 2) does have an "[n] " prefix and n is the lowest prefix seen 1914 ;; 2) does have an "[n] " prefix and n is the lowest prefix seen
1909 ;; Return the info as a cons of the form: 1917 ;; Return the info as a cons of the form:
1910 ;; 1918 ;;
1911 ;; (<file-name> . <line-number>) . 1919 ;; (<file-name> . <line-number>) .
1912 (if (if (match-beginning 1) 1920 (if (if (match-beginning 1)
1913 (let (n) 1921 (let (n)
1914 (setq n (string-to-int (match-string 1 gud-marker-acc))) 1922 (setq n (string-to-int (substring
1923 gud-marker-acc
1924 (1+ (match-beginning 1))
1925 (- (match-end 1) 2))))
1915 (if (< n gud-jdb-lowest-stack-level) 1926 (if (< n gud-jdb-lowest-stack-level)
1916 (progn (setq gud-jdb-lowest-stack-level n) t))) 1927 (progn (setq gud-jdb-lowest-stack-level n) t)))
1917 t) 1928 t)
1918 (if (setq file-found 1929 (if (setq file-found
1919 (gud-jdb-find-source (match-string 2 gud-marker-acc))) 1930 (gud-jdb-find-source (match-string 2 gud-marker-acc)))
1920 (setq gud-last-frame 1931 (setq gud-last-frame
1921 (cons file-found 1932 (cons file-found
1922 (string-to-int (match-string 4 gud-marker-acc)))) 1933 (string-to-int
1934 (let
1935 ((numstr (match-string 4 gud-marker-acc)))
1936 (if (string-match "," numstr)
1937 (replace-match "" nil nil numstr)
1938 numstr)))))
1923 (message "Could not find source file."))) 1939 (message "Could not find source file.")))
1924 1940
1925 ;; Set the accumulator to the remaining text. 1941 ;; Set the accumulator to the remaining text.
1926 (setq gud-marker-acc (substring gud-marker-acc (match-end 0)))) 1942 (setq gud-marker-acc (substring gud-marker-acc (match-end 0))))
1927 1943
1988 (gud-def gud-next "next" "\C-n" "Step one line (skip functions).") 2004 (gud-def gud-next "next" "\C-n" "Step one line (skip functions).")
1989 (gud-def gud-cont "cont" "\C-r" "Continue with display.") 2005 (gud-def gud-cont "cont" "\C-r" "Continue with display.")
1990 (gud-def gud-finish "step up" "\C-f" "Continue until current method returns.") 2006 (gud-def gud-finish "step up" "\C-f" "Continue until current method returns.")
1991 (gud-def gud-up "up\C-Mwhere" "<" "Up one stack frame.") 2007 (gud-def gud-up "up\C-Mwhere" "<" "Up one stack frame.")
1992 (gud-def gud-down "down\C-Mwhere" ">" "Up one stack frame.") 2008 (gud-def gud-down "down\C-Mwhere" ">" "Up one stack frame.")
2009 (gud-def gud-run "run" nil "Run the program.") ;if VM start using jdb
1993 2010
1994 (setq comint-prompt-regexp "^> \\|^[^ ]+\\[[0-9]+\\] ") 2011 (setq comint-prompt-regexp "^> \\|^[^ ]+\\[[0-9]+\\] ")
1995 (setq paragraph-start comint-prompt-regexp) 2012 (setq paragraph-start comint-prompt-regexp)
1996 (run-hooks 'jdb-mode-hook) 2013 (run-hooks 'jdb-mode-hook)
1997 2014
2522 ((eq key ?e) 2539 ((eq key ?e)
2523 (setq subst (gud-find-c-expr))) 2540 (setq subst (gud-find-c-expr)))
2524 ((eq key ?a) 2541 ((eq key ?a)
2525 (setq subst (gud-read-address))) 2542 (setq subst (gud-read-address)))
2526 ((eq key ?c) 2543 ((eq key ?c)
2527 (setq subst (gud-find-class (if insource 2544 (setq subst
2528 (buffer-file-name) 2545 (gud-find-class
2529 (car frame))))) 2546 (if insource
2547 (buffer-file-name)
2548 (car frame))
2549 (if insource
2550 (save-restriction
2551 (widen)
2552 (+ (count-lines (point-min) (point))
2553 (if (bolp) 1 0)))
2554 (cdr frame)))))
2530 ((eq key ?p) 2555 ((eq key ?p)
2531 (setq subst (if arg (int-to-string arg))))) 2556 (setq subst (if arg (int-to-string arg)))))
2532 (setq result (concat result (match-string 1 str) subst))) 2557 (setq result (concat result (match-string 1 str) subst)))
2533 (setq str (substring str (match-end 2)))) 2558 (setq str (substring str (match-end 2))))
2534 ;; There might be text left in STR when the loop ends. 2559 ;; There might be text left in STR when the loop ends.
2728 ((= span-end ?() t) 2753 ((= span-end ?() t)
2729 ((= span-end ?[) t) 2754 ((= span-end ?[) t)
2730 (t nil))) 2755 (t nil)))
2731 (t nil)))) 2756 (t nil))))
2732 2757
2733 (defun gud-find-class (f) 2758 (defun gud-find-class (f line)
2734 "Find fully qualified class corresponding to file F. 2759 "Find fully qualified class in file F at line LINE.
2735 This function uses the `gud-jdb-classpath' (and optional 2760 This function uses the `gud-jdb-classpath' (and optional
2736 `gud-jdb-sourcepath') list(s) to derive a file 2761 `gud-jdb-sourcepath') list(s) to derive a file
2737 pathname relative to its classpath directory. The values in 2762 pathname relative to its classpath directory. The values in
2738 `gud-jdb-classpath' are assumed to have been converted to absolute 2763 `gud-jdb-classpath' are assumed to have been converted to absolute
2739 pathname standards using file-truename." 2764 pathname standards using file-truename.
2765 If F is visited by a buffer and its mode is CC-mode(Java),
2766 syntactic information of LINE is used to find the enclosing (nested)
2767 class string which is appended to the top level
2768 class of the file (using s to separate nested class ids)."
2740 ;; Convert f to a standard representation and remove suffix 2769 ;; Convert f to a standard representation and remove suffix
2741 (if (and gud-jdb-use-classpath (or gud-jdb-classpath gud-jdb-sourcepath)) 2770 (if (and gud-jdb-use-classpath (or gud-jdb-classpath gud-jdb-sourcepath))
2742 (save-match-data 2771 (save-match-data
2743 (let ((cplist (append gud-jdb-sourcepath gud-jdb-classpath)) 2772 (let ((cplist (append gud-jdb-sourcepath gud-jdb-classpath))
2744 class-found) 2773 (fbuffer (get-file-buffer f))
2745 (setq f (file-name-sans-extension (file-truename f))) 2774 class-found)
2746 ;; Search through classpath list for an entry that is 2775 (setq f (file-name-sans-extension (file-truename f)))
2747 ;; contained in f 2776 ;; Search through classpath list for an entry that is
2748 (while (and cplist (not class-found)) 2777 ;; contained in f
2749 (if (string-match (car cplist) f) 2778 (while (and cplist (not class-found))
2750 (setq class-found 2779 (if (string-match (car cplist) f)
2780 (setq class-found
2751 (mapconcat 'identity 2781 (mapconcat 'identity
2752 (split-string 2782 (split-string
2753 (substring f (+ (match-end 0) 1)) 2783 (substring f (+ (match-end 0) 1))
2754 "/") "."))) 2784 "/") ".")))
2755 (setq cplist (cdr cplist))) 2785 (setq cplist (cdr cplist)))
2756 (if (not class-found) 2786 ;; if f is visited by a java(cc-mode) buffer, walk up the
2757 (message "gud-find-class: class for file %s not found!" f)) 2787 ;; syntactic information chain and collect any 'inclass
2758 class-found)) 2788 ;; symbols until 'topmost-intro is reached to find out if
2789 ;; point is within a nested class
2790 (if (and fbuffer (equal (symbol-file 'java-mode) "cc-mode"))
2791 (save-excursion
2792 (set-buffer fbuffer)
2793 (let ((nclass) (syntax)
2794 (pos (point)))
2795 ;; While the c-syntactic information does not start
2796 ;; with the 'topmost-intro symbol, there may be
2797 ;; nested classes...
2798 (while (not (eq 'topmost-intro
2799 (car (car (c-guess-basic-syntax)))))
2800 ;; Check if the current position c-syntactic
2801 ;; analysis has 'inclass
2802 (setq syntax (c-guess-basic-syntax))
2803 (while
2804 (and (not (eq 'inclass (car (car syntax))))
2805 (cdr syntax))
2806 (setq syntax (cdr syntax)))
2807 (if (eq 'inclass (car (car syntax)))
2808 (progn
2809 (goto-char (cdr (car syntax)))
2810 ;; Now we're at the beginning of a class
2811 ;; definition. Find class name
2812 (looking-at
2813 "[A-Za-z0-9 \t\n]*?class[ \t\n]+\\([^ \t\n]+\\)")
2814 (setq nclass
2815 (append (list (match-string-no-properties 1))
2816 nclass)))
2817 (setq syntax (c-guess-basic-syntax))
2818 (while (and (not (cdr (car syntax))) (cdr syntax))
2819 (setq syntax (cdr syntax)))
2820 (goto-char (cdr (car syntax)))
2821 ))
2822 (string-match (concat (car nclass) "$") class-found)
2823 (setq class-found
2824 (replace-match (mapconcat 'identity nclass "$")
2825 t t class-found)))))
2826 (if (not class-found)
2827 (message "gud-find-class: class for file %s not found!" f))
2828 class-found))
2759 ;; Not using classpath - try class/source association list 2829 ;; Not using classpath - try class/source association list
2760 (let ((class-found (rassoc f gud-jdb-class-source-alist))) 2830 (let ((class-found (rassoc f gud-jdb-class-source-alist)))
2761 (if class-found 2831 (if class-found
2762 (car class-found) 2832 (car class-found)
2763 (message "gud-find-class: class for file %s not found in gud-jdb-class-source-alist!" f) 2833 (message "gud-find-class: class for file %s not found in gud-jdb-class-source-alist!" f)