]> code.delx.au - gnu-emacs-elpa/commitdiff
DRY/fix debugger invocation code. This time, mostly for remake and gdb
authorrocky <rocky@gnu.org>
Wed, 9 Jul 2014 10:29:41 +0000 (06:29 -0400)
committerrocky <rocky@gnu.org>
Wed, 9 Jul 2014 10:29:41 +0000 (06:29 -0400)
realgud/debugger/bashdb/core.el
realgud/debugger/gdb/core.el
realgud/debugger/gdb/gdb.el
realgud/debugger/kshdb/core.el
realgud/debugger/remake/core.el
realgud/debugger/remake/remake.el
realgud/debugger/trepan/core.el
test/gcd.sh [new file with mode: 0755]
test/test-bashdb.el
test/test-gub-core.el
test/test-remake-core.el

index 99ac3c71c6d3f91fb5cbc63defe9de957e21c1fb..46323837637b291f836a3ba1ca25124e0ba841d5 100644 (file)
@@ -7,6 +7,7 @@
                       "realgud-")
 (require-relative-list '("init") "realgud:bashdb-")
 
+(declare-function realgud:expand-file-name-if-exists 'realgud-core)
 (declare-function realgud-parse-command-arg  'realgud-core)
 (declare-function realgud-query-cmdline      'realgud-core)
 (declare-function realgud-suggest-invocation 'realgud-core)
@@ -133,7 +134,8 @@ Note that path elements have been expanded via `expand-file-name'.
           ((member arg '("--library" "-l"))
            (setq arg (pop args))
            (nconc debugger-args
-                  (list arg (expand-file-name (pop args)))))
+                  (list arg (realgud:expand-file-name-if-exists
+                             (pop args)))))
           ;; Other options with arguments.
           ((string-match "^-" arg)
            (setq pair (realgud-parse-command-arg
@@ -141,7 +143,7 @@ Note that path elements have been expanded via `expand-file-name'.
            (nconc debugger-args (car pair))
            (setq args (cadr pair)))
           ;; Anything else must be the script to debug.
-          (t (setq script-name (expand-file-name arg))
+          (t (setq script-name (realgud:expand-file-name-if-exists arg))
              (setq script-args (cons script-name (cdr args))))
           )))
       (list interpreter-args debugger-args script-args annotate-p))))
index 99aa8e8fdf5c1caa68efd6bdc20698ef813dd7fd..65ebd9a1c9bbc3135531c919ceeb855da4957663 100644 (file)
@@ -7,6 +7,7 @@
                         "../../common/lang")
                       "realgud-")
 
+(declare-function realgud:expand-file-name-if-exists 'realgud-core)
 (declare-function realgud-lang-mode? 'realgud-lang)
 (declare-function realgud-parse-command-arg 'realgud-core)
 (declare-function realgud-query-cmdline 'realgud-core)
 (defun realgud:gdb-parse-cmd-args (orig-args)
   "Parse command line ARGS for the annotate level and name of script to debug.
 
-ARGS should contain a tokenized list of the command line to run.
+ORIG_ARGS should contain a tokenized list of the command line to run.
 
 We return the a list containing
-- the name of the debugger given (e.g. gdb) and its arguments - a list of strings
-- the script name and its arguments - list of strings
-- whether the annotate or emacs option was given ('-A', '--annotate' or '--emacs) - a boolean
+* the name of the debugger given (e.g. gdb) and its arguments - a list of strings
+* nil (a placehoder in other routines of this ilk for a debugger
+* the script name and its arguments - list of strings
+* whether the annotate or emacs option was given ('-A', '--annotate' or '--emacs) - a boolean
 
 For example for the following input
   (map 'list 'symbol-name
-   '(gdb --tty /dev/pts/1 --emacs ./gcd.py a b))
+   '(gdb --tty /dev/pts/1 -cd ~ --emacs ./gcd.py a b))
 
 we might return:
-   ((gdb --tty /dev/pts/1 --emacs) (./gcd.py a b) 't)
+   ((\"gdb\" \"--tty\" \"/dev/pts/1\" \"-cd\" \"home/rocky\' \"--emacs\") nil \"(/tmp/gcd.py a b\") 't\")
 
-NOTE: the above should have each item listed in quotes.
+Note that path elements have been expanded via `expand-file-name'.
 "
 
   ;; Parse the following kind of pattern:
@@ -74,8 +76,8 @@ NOTE: the above should have each item listed in quotes.
        (annotate-p nil))
 
     (if (not (and args))
-       ;; Got nothing: return '(nil nil nil)
-       (list debugger-args script-args annotate-p)
+       ;; Got nothing: return '(nil nil nil nil)
+       (list debugger-args nil script-args annotate-p)
       ;; else
       (progn
 
@@ -102,6 +104,12 @@ NOTE: the above should have each item listed in quotes.
             ((string-match "^--annotate=[0-9]" arg)
              (nconc debugger-args (list (pop args) (pop args)) )
              (setq annotate-p t))
+            ;; path-argument ooptions
+            ((member arg '("-cd" ))
+             (setq arg (pop args))
+             (nconc debugger-args
+                    (list arg (realgud:expand-file-name-if-exists
+                               (pop args)))))
             ;; Options with arguments.
             ((string-match "^-" arg)
              (setq pair (realgud-parse-command-arg
@@ -112,7 +120,7 @@ NOTE: the above should have each item listed in quotes.
             (t (setq script-name arg)
                (setq script-args args))
             )))
-       (list debugger-args script-args annotate-p)))))
+       (list debugger-args nil script-args annotate-p)))))
 
 (defvar realgud:gdb-command-name)
 (defun realgud:gdb-suggest-invocation (debugger-name)
index e8868fe608a13fb0629d3c4ccc3789afb23e5545..2302706c506cf9a3c84cf967f7b0a2872a0a766b 100644 (file)
@@ -25,21 +25,22 @@ This should be an executable on your path, or an absolute file name."
   :type 'string
   :group 'realgud:gdb)
 
-(declare-function gdb-track-mode (bool))
+(declare-function realgud:gdb-track-mode     'realgud:gdb-track-mode)
 (declare-function realgud-command            'realgud:gdb-core)
 (declare-function realgud:gdb-parse-cmd-args 'realgud:gdb-core)
 (declare-function realgud:gdb-query-cmdline  'realgud:gdb-core)
-(declare-function realgud-run-process        'realgud-core)
+(declare-function realgud:run-process        'realgud-core)
 
 ;; -------------------------------------------------------------------
 ;; The end.
 ;;
 
+(require 'list-utils)
 ;;;###autoload
-(defun realgud:gdb (&optional opt-command-line no-reset)
+(defun realgud:gdb (&optional opt-cmd-line no-reset)
   "Invoke the gdb debugger and start the Emacs user interface.
 
-OPT-COMMAND-LINE is treated like a shell string; arguments are
+OPT-CMD-LINE is treated like a shell string; arguments are
 tokenized by `split-string-and-unquote'.
 
 Normally, command buffers are reused when the same debugger is
@@ -52,13 +53,16 @@ fringe and marginal icons.
 "
 
   (interactive)
-  (let* ((cmd-str (or opt-command-line (realgud:gdb-query-cmdline "gdb")))
+  (let* ((cmd-str (or opt-cmd-line (realgud:gdb-query-cmdline "gdb")))
         (cmd-args (split-string-and-unquote cmd-str))
         (parsed-args (realgud:gdb-parse-cmd-args cmd-args))
-        (script-args (cdr cmd-args))
-        (script-name (expand-file-name (car script-args)))
-        (cmd-buf (realgud-run-process realgud:gdb-command-name (car script-args) cmd-args
-                                    'realgud:gdb-track-mode nil))
+        (script-args (caddr parsed-args))
+        (script-name (car script-args))
+        (parsed-cmd-args
+         (remove-if 'nil (list-utils-flatten parsed-args)))
+        (cmd-buf (realgud:run-process realgud:gdb-command-name
+                                      script-name parsed-cmd-args
+                                      'realgud:gdb-track-mode-hook nil))
         )
     (if cmd-buf
        (with-current-buffer cmd-buf
@@ -66,27 +70,10 @@ fringe and marginal icons.
          )
       )
     )
-
-    ;; ;; Parse the command line and pick out the script name and whether
-    ;; ;; --annotate has been set.
-
-    ;; (condition-case nil
-    ;;         (setq cmd-buf
-    ;;               (apply 'realgud-exec-shell "gdb" (car script-args)
-    ;;                      (car cmd-args) nil
-    ;;                      (cons script-name (cddr cmd-args))))
-    ;; (error nil))
-    ;; ;; FIXME: Is there probably is a way to remove the
-    ;; ;; below test and combine in condition-case?
-    ;; (let ((process (get-buffer-process cmd-buf)))
-    ;;   (if (and process (eq 'run (process-status process)))
-    ;;           (progn
-    ;;             (switch-to-buffer cmd-buf)
-    ;;             (realgud:gdb-track-mode 't)
-    ;;             (realgud-cmdbuf-info-cmd-args= cmd-args)
-    ;;             )
-    ;;         (message "Error running gdb command"))
-    ;; )
-    )
+  )
 
 (provide-me "realgud-")
+
+;; Local Variables:
+;; byte-compile-warnings: (not cl-functions)
+;; End:
index bc73cc86d5faadbd3ed916de8992a49c18e745b4..853cf461ea2a70d70b4cc2a44561277325628c55 100644 (file)
@@ -5,6 +5,11 @@
 (require-relative-list '("../../common/track" "../../common/core") "realgud-")
 (require-relative-list '("init") "realgud:kshdb-")
 
+(declare-function realgud:expand-file-name-if-exists 'realgud-core)
+(declare-function realgud-parse-command-arg  'realgud-core)
+(declare-function realgud-query-cmdline      'realgud-core)
+(declare-function realgud-suggest-invocation 'realgud-core)
+
 ;; FIXME: I think the following could be generalized and moved to
 ;; realgud-... probably via a macro.
 (defvar kshdb-minibuffer-history nil
@@ -24,6 +29,7 @@
    'kshdb-minibuffer-history
    opt-debugger))
 
+;;; FIXME: DRY this with other *-parse-cmd-args routines
 (defun kshdb-parse-cmd-args (orig-args)
   "Parse command line ARGS for the annotate level and name of script to debug.
 
@@ -121,8 +127,8 @@ NOTE: the above should have each item listed in quotes.
            (nconc debugger-args (car pair))
            (setq args (cadr pair)))
           ;; Anything else must be the script to debug.
-          (t (setq script-name arg)
-             (setq script-args args))
+          (t (setq script-name (realgud:expand-file-name-if-exists arg))
+              (setq script-args (cons script-name (cdr args))))
           )))
       (list interpreter-args debugger-args script-args annotate-p))))
 
index 9eed834fdace7e168698e70da7619533e4868c78..1f51c164575c2af51542a34e5e8d6779029c9444 100644 (file)
@@ -2,9 +2,20 @@
 (eval-when-compile (require 'cl))
 
 (require 'load-relative)
-(require-relative-list '("../../common/track" "../../common/core") "realgud-")
+(require-relative-list '("../../common/track" "../../common/core")
+                      "realgud-")
+(require-relative-list '("../../common/buffer/command")
+                      "realgud-buffer-")
 (require-relative-list '("init") "realgud:remake-")
 
+(declare-function realgud:expand-file-name-if-exists 'realgud-core)
+(declare-function realgud-parse-command-arg  'realgud-core)
+(declare-function realgud-query-cmdline      'realgud-core)
+(declare-function realgud-suggest-invocation 'realgud-core)
+(declare-function realgud-cmdbuf-command-string
+                                            'realgud-buffer-command)
+(declare-function realgud-cmdbuf-debugger-name
+                                            'realgud-buffer-command)
 ;; FIXME: I think the following could be generalized and moved to
 ;; realgud-... probably via a macro.
 (defvar remake-minibuffer-history nil
@@ -83,7 +94,8 @@ we might return:
 
           ((member arg '("--file" "--makefile" "-f"))
            (setq remake-args (nconc remake-args (list arg)))
-           (setq makefile-name (pop args))
+           (setq makefile-name (realgud:expand-file-name-if-exists
+                                (pop args)))
            (setq remake-args (nconc remake-args
                                     (list (format "%s" makefile-name)))))
 
index 32fd8197658625cd40d2f625f8fc4cc68acb4ed8..7aad9d816af25885826759784512732452eff906 100644 (file)
@@ -16,7 +16,7 @@
 
 (declare-function remake-query-cmdline  'realgud:remake-core)
 (declare-function remake-parse-cmd-args 'realgud:remake-core)
-(declare-function realgud:run-process   'realgud:run)
+(declare-function realgud:run-debugger  'realgud:run)
 
 ;; -------------------------------------------------------------------
 ;; User definable variables
@@ -31,40 +31,14 @@ This should be an executable on your path, or an absolute file name."
   :group 'remake)
 
 ;;;###autoload
-(defun realgud:remake-fn (&optional opt-cmd-line no-reset)
+(defun realgud:remake (&optional opt-cmd-line no-reset)
   "See `realgud:remake' for details"
-
-  (let* ((cmd-str (or opt-cmd-line (remake-query-cmdline "remake")))
-        (cmd-args (split-string-and-unquote cmd-str))
-        (parsed-args (remake-parse-cmd-args cmd-args))
-        (remake-program (car parsed-args))
-        (makefile-name (or (cadr parsed-args) "Makefile"))
-        (makefile-args (caddr parsed-args))
-        (cmd-buf))
-    (realgud:run-process "remake" makefile-name
-                     (cons remake-program makefile-args)
-                     'remake-track-mode no-reset)
-
-    ;; ;; Parse the command line and pick out the script name and whether
-    ;; ;; --annotate has been set.
-
-    ;; (condition-case nil
-    ;;         (setq cmd-buf
-    ;;               (apply 'realgud-exec-shell "remake" makefile-name
-    ;;                      remake-program no-reset makefile-args))
-    ;;   (error nil))
-    ;; ;; FIXME: Is there probably is a way to remove the
-    ;; ;; below test and combine in condition-case?
-    ;; (let ((process (get-buffer-process cmd-buf)))
-    ;;   (if (and process (eq 'run (process-status process)))
-    ;;           (progn
-    ;;             (switch-to-buffer cmd-buf)
-    ;;             (remake-track-mode 't)
-    ;;             (realgud-cmdbuf-info-cmd-args= cmd-args)
-    ;;             )
-    ;;         (message "Error running remake command"))
-    ;;   )
-    )
+  (interactive)
+  (realgud:run-debugger "remake"
+                       'remake-query-cmdline
+                       'remake-parse-cmd-args
+                       'remake-track-mode-hook
+                       opt-cmd-line no-reset)
   )
 
 (defalias 'remake 'realgud:remake)
index 3d51ab538431dbf954b98426c623cb6a17fda1ad..b843cc0df67ce7c9edd8436990d03e107a2e4b12 100644 (file)
@@ -129,6 +129,12 @@ Note that the script name path has been expanded via `expand-file-name'.
            ((string-match "^--annotate=[0-9]" arg)
             (nconc debugger-args (list (pop args)) )
             (setq annotate-p t))
+          ;; path-argument options
+          ((member arg '("--include" "-I" "--require" "-I"))
+           (setq arg (pop args))
+           (nconc debugger-args
+                  (list arg (realgud:expand-file-name-if-exists
+                             (pop args)))))
            ;; Options with arguments.
            ((string-match "^-" arg)
             (setq pair (realgud-parse-command-arg
diff --git a/test/gcd.sh b/test/gcd.sh
new file mode 100755 (executable)
index 0000000..497f33b
--- /dev/null
@@ -0,0 +1,25 @@
+#!/usr/bin/env bash
+# Greatest Common Divisor in POSIX shell using Euclid's algorithm.  On
+# return, variable gcd_value is set and is the gcd of parameters $1
+# and $2. The GCD of a negative number is the same as the GCD of its
+# absolute value, since a negative number is -1 times its positive
+# value.  Negative numbers are set when there is an error; -1 is set
+# when the wrong number of parameters are given.
+gcd() {
+    typeset -i a=$1
+    typeset -i b=$2
+    if (( a > b )) ; then
+       a=$b
+       b=$1
+    fi
+   if (( a == 1 || (b-a) == 0)) ; then
+       gcd_value=$a
+       return 0
+   fi
+   typeset -i c
+   ((c=b-a))
+   gcd $c $a
+}
+
+gcd $1 $2
+echo $gcd_value
index 92b0c326104f40b92ec59409bcfa81fffa6b774c..5c33b63c9a64d7c2ab994fb0e765b19a0aef37d6 100644 (file)
@@ -1,5 +1,8 @@
 (require 'test-simple)
 (load-file "../realgud/debugger/bashdb/bashdb.el")
+(load-file "../realgud/common/core.el")
+
+(declare-function realgud:expand-file-name-if-exists 'realgud-core)
 
 (eval-when-compile (defvar test:run-process-save))
 
@@ -18,7 +21,8 @@
    (format "%s %s %s %S" debugger-name script-filename cmd-args
           track-mode-func))
   (assert-equal "bashdb" debugger-name "debugger name gets passed")
-  (let ((expanded-name (expand-file-name "./gcd.sh")))
+  (let ((expanded-name
+        (realgud:expand-file-name-if-exists "./gcd.sh")))
     (assert-equal  expanded-name script-filename "file name check")
     (assert-equal (list "-l" (expand-file-name ".") expanded-name "3" "5")
                  (cdr cmd-args) "command args listified")
     ))
 
 (note "bashdb-parse-cmd-args")
-(assert-equal (list nil '("bashdb") (list (expand-file-name "foo")) nil)
+(assert-equal (list nil '("bashdb")
+                   (list (realgud:expand-file-name-if-exists "foo")) nil)
              (bashdb-parse-cmd-args '("bashdb" "foo")))
-(assert-equal (list nil '("bashdb") (list (expand-file-name "program.sh") "foo") nil)
+(assert-equal (list nil '("bashdb")
+                   (list (realgud:expand-file-name-if-exists "program.sh")
+                         "foo") nil)
              (bashdb-parse-cmd-args
               '("bashdb" "program.sh" "foo")))
 
index b9d77236a18cb0e6390887625d4759dcae0e73d4..8560d4a940e904d6e1d6a36cf6af82d7091ac701 100644 (file)
@@ -1,6 +1,7 @@
 (require 'test-simple)
 (load-file "../realgud/debugger/gub/core.el")
 
+(declare-function __FILE__ 'require-relative)
 (declare-function gub-parse-cmd-args 'realgud-gub-core)
 
 (test-simple-start)
index 877ac645340e6ec10e2209e8a6ca4eed664b2de4..0a20227873631008d13313c1409555177afc0231 100644 (file)
@@ -1,11 +1,18 @@
 (require 'test-simple)
 (load-file "../realgud/debugger/remake/core.el")
 
+(declare-function __FILE__ 'require-relative)
+(declare-function remake-parse-cmd-args        'realgud-remake-core)
+(declare-function remake-suggest-Makefile      'realgud-remake-core)
+(declare-function remake-suggest-file-priority 'realgud-remake-core)
+
 (test-simple-start)
 
-(assert-equal '("remake" "Makefile" ("-X" "-f" "Makefile"))
+(assert-equal (list "remake" (expand-file-name "Makefile")
+                   (list "-X" "-f" (expand-file-name "Makefile")))
              (remake-parse-cmd-args
-              '("remake" "-X" "-f" "Makefile")) "remake-parse-cmd-args")
+              '("remake" "-X" "-f" "Makefile"))
+             "remake-parse-cmd-args")
 
 (assert-equal "Makefile" (remake-suggest-Makefile) "remake-suggest-Makefile")