How to customize the executable name when running gud-gdb

1k views Asked by At

I am using emacs 24.3.1 to write programs (in C and C++ mode).

After compiling the current buffer, I run below command: M-x gud-gdb. Emacs gives a prompt like below: gdb --fullname prog

However, sometimes the "prog" name is not the same as the executable name compiled from current buffer. e.g. I completed five programs prog1, prog2,... prog5, and is currently working on prog6. But M-x gud-gdb gives me gdb --fullname prog5. (I want prog6 instead.)

Is there a way to correct this? Specifically, "correct" means forcing gud-gdb to use current buffer's name (without suffix) as the prog name.

Thanks in advance.

2

There are 2 answers

0
juanleon On BEST ANSWER

I think emacs uses a heuristic (based on what executable file is more recent or something like that) to figure out the default program to offer.

If your preferences are very specific you could define and use this function:

(defun my-gud-gdb ()
 (interactive)
 (gud-gdb (concat "gdb --fullname "
                  (file-name-sans-extension (buffer-file-name (current-buffer))))))

This function will execute gdb on a file named like the file you are editing without extension.

3
Andreas Röhler On

gud-query-cmdline accepts filename as an optional argument, which isn't served yet.

Patch below should provide it.

Make sure, file-permissions are set to executable

--- gud.el  Sun Mar 17 12:52:42 2013
+++ gud.el  Tue Jun  3 10:06:11 2014
@@ -716,7 +716,7 @@

   "Run gdb on program FILE in buffer *gud-FILE*.
 The directory containing FILE becomes the initial working
 directory and source-file directory for your debugger."
-  (interactive (list (gud-query-cmdline 'gud-gdb)))
+  (interactive (list (gud-query-cmdline 'gud-gdb (and (file-executable-p (buffer-file-name))(buffer-file-name)))))

   (when (and gud-comint-buffer
       (buffer-name gud-comint-buffer)