=== modified file 'lisp/progmodes/gdb-mi.el' --- lisp/progmodes/gdb-mi.el 2011-10-06 16:11:38 +0000 +++ lisp/progmodes/gdb-mi.el 2011-10-23 19:30:03 +0000 @@ -599,6 +599,29 @@ (concat (gdb-gud-context-command ,cmd1 ,noall) " " ,cmd2) ,(when (not noarg) 'arg))) +(defun gdb--interpreter-ok () + "Whether the expected interpreter is being used. +-1: Not checked. + 0: Incorrect interpreter. + 1: Correct interpreter." + (let* ((buffer gud-comint-buffer) + (process (get-buffer-process buffer)) + (res (process-get process 'gdb--interpreter-ok))) + (if (equal res nil) -1 res))) + +(defun gdb--interpreter-check (string) + "Initial filter to check if a correct interpreter is being used." + (when (= (gdb--interpreter-ok) -1) + (let* ((target "=thread-group-added") ; first line in GDB/MI + (buffer gud-comint-buffer) + (process (get-buffer-process buffer))) + (if (or (> (length target) (length string)) + (string= (substring string 0 (length target)) target)) + (process-put process 'gdb--interpreter-ok 1) + (process-put process 'gdb--interpreter-ok 0)))) + (when (= (gdb--interpreter-ok) 1) + (gud-gdbmi-marker-filter string))) + ;;;###autoload (defun gdb (command-line) "Run gdb on program FILE in buffer *gud-FILE*. @@ -663,8 +686,18 @@ (gdb-restore-windows) (error "Multiple debugging requires restarting in text command mode")) - ;; - (gud-common-init command-line nil 'gud-gdbmi-marker-filter) + + ;; Start gdb and check for the interpreter being used + (gud-common-init command-line nil 'gdb--interpreter-check) + (while (= (gdb--interpreter-ok) -1) ; must wait until established + (sleep-for 1)) + (unless (= (gdb--interpreter-ok) 1) + (setq-default gud-marker-filter 'gud-gdbmi-marker-filter) + (insert "\nerror: You must start gdb with the GDB/MI interface (i.e., \"gdb -i=mi\")\n") + (error "You must start gdb with the GDB/MI interface (i.e., \"gdb -i=mi\")")) + ;; Change to "standard" filter + (setq gud-marker-filter 'gud-gdbmi-marker-filter) + (set (make-local-variable 'gud-minor-mode) 'gdbmi) (setq comint-input-sender 'gdb-send) (when (ring-empty-p comint-input-ring) ; cf shell-mode