branch: master
commit 0a17ada92fdd695dc07155349b7a3947e39c6e2d
Author: Kilian Kilger <[email protected]>
Commit: Kilian Kilger <[email protected]>
Fix several issues when calling gdb, Fixes #59
---
realgud/common/core.el | 12 +++++++-----
realgud/debugger/gdb/gdb.el | 4 ++--
test/test-gdb-core.el | 34 ++++++++++++++++++++++++++++++++++
3 files changed, 43 insertions(+), 7 deletions(-)
diff --git a/realgud/common/core.el b/realgud/common/core.el
index fd2799c..cecd5ee 100644
--- a/realgud/common/core.el
+++ b/realgud/common/core.el
@@ -186,7 +186,7 @@ the buffer and data associated with it are already gone."
(message "That's all folks.... %s" string))
(defun realgud:binary (file-name)
-"Return a priority for wehther file-name is likely we can run gdb on"
+"Return a priority for whether file-name is likely we can run gdb on"
(let ((output (shell-command-to-string (format "file %s" file-name))))
(cond
((string-match "ELF" output) t)
@@ -214,9 +214,10 @@ marginal icons is reset."
(or (file-name-directory script-filename)
default-directory "./"))
(cmdproc-buffer-name
- (format "*%s %s shell*"
- (file-name-nondirectory debugger-name)
- (file-name-nondirectory script-filename)))
+ (replace-regexp-in-string "\s+" "\s"
+ (format "*%s %s shell*"
+ (file-name-nondirectory debugger-name)
+ (file-name-nondirectory script-filename))))
(cmdproc-buffer (get-buffer-create cmdproc-buffer-name))
(realgud-buf (current-buffer))
(cmd-args (cons program args))
@@ -240,7 +241,8 @@ marginal icons is reset."
(setq process nil)
))
- (unless (and process (eq 'run (process-status process)))
+ (if (and process (eq 'run (process-status process)))
+ cmdproc-buffer
(with-current-buffer cmdproc-buffer
(and (realgud-cmdbuf?) (not no-reset) (realgud:reset))
(setq default-directory default-directory)
diff --git a/realgud/debugger/gdb/gdb.el b/realgud/debugger/gdb/gdb.el
index e5d3432..892d8af 100644
--- a/realgud/debugger/gdb/gdb.el
+++ b/realgud/debugger/gdb/gdb.el
@@ -119,9 +119,9 @@ fringe and marginal icons.
(cmd-args (split-string-and-unquote cmd-str))
(parsed-args (realgud:gdb-parse-cmd-args cmd-args))
(script-args (caddr parsed-args))
- (script-name (car script-args))
+ (script-name (or (car script-args) ""))
(parsed-cmd-args
- (cl-remove-if 'nil (realgud:flatten parsed-args)))
+ (cl-remove-if-not 'stringp (realgud:flatten parsed-args)))
(cmd-buf (realgud:run-process realgud:gdb-command-name
script-name parsed-cmd-args
'realgud:gdb-minibuffer-history
diff --git a/test/test-gdb-core.el b/test/test-gdb-core.el
new file mode 100644
index 0000000..c3d2b87
--- /dev/null
+++ b/test/test-gdb-core.el
@@ -0,0 +1,34 @@
+;; Press C-x C-e at the end of the next line to run this file test
non-interactively
+;; (test-simple-run "emacs -batch -L %s -l %s" (file-name-directory
(locate-library "test-simple.elc")) buffer-file-name)
+
+(require 'test-simple)
+(load-file "../realgud/debugger/gdb/core.el")
+
+(test-simple-start)
+
+(note "invoke gdb without command line arguments")
+(assert-equal '(("gdb") nil nil nil)
+ (realgud:gdb-parse-cmd-args
+ '("gdb")))
+
+(note "invoke gdb with annotate command line parameter")
+(assert-equal '(("gdb" "--annotate" "1") nil nil t)
+ (realgud:gdb-parse-cmd-args
+ '("gdb" "--annotate" "1")))
+
+(note "invoke gdb with annotate command line parameter and file")
+(assert-equal '(("gdb" "--annotate" "1") nil ("file.c") t)
+ (realgud:gdb-parse-cmd-args
+ '("gdb" "--annotate" "1" "file.c")))
+
+(note "invoke gdb with annotate command line parameter and pid")
+(assert-equal '(("gdb" "--annotate" "1" "-p") nil ("4812") t)
+ (realgud:gdb-parse-cmd-args
+ '("gdb" "--annotate" "1" "-p" "4812")))
+
+(note "invoke gdb with pid")
+(assert-equal '(("gdb" "-p") nil ("4511") nil)
+ (realgud:gdb-parse-cmd-args
+ '("gdb" "-p" "4511")))
+
+(end-tests)