1

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.

modeller
  • 3,770
  • 3
  • 25
  • 49
  • How hard is it to type `M-x gud-gdb backspace 6`. You are trying to save two keystrokes! It is likely that you can spend your efforts more productively. – Employed Russian Jun 03 '14 at 02:43
  • In real life I am dealing with names with various length up to 10+ chars to conform to naming standard, which is much tedious to type. So I still prefer a shortcut. Above is just a example with simplified name.... – modeller Jun 03 '14 at 04:24

2 Answers2

2

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.

juanleon
  • 9,220
  • 30
  • 41
0

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)
Andreas Röhler
  • 4,804
  • 14
  • 18
  • Thanks for the tip. This seems to need re-compilation of emacs. (or there is another way?) – modeller Jun 03 '14 at 11:59
  • There is no need to re-compile. However, when having difficulties with this, you should use solution delivered by juanleon. This leaves Emacs code untouched, thus no risk to mess up something. – Andreas Röhler Jun 03 '14 at 13:44
  • Understood. I will revisit this method later. – modeller Jun 03 '14 at 14:28