简体   繁体   English

运行gud-gdb时如何自定义可执行文件名称

[英]How to customize the executable name when running gud-gdb

I am using emacs 24.3.1 to write programs (in C and C++ mode). 我正在使用emacs 24.3.1编写程序(在C和C ++模式下)。

After compiling the current buffer, I run below command: Mx gud-gdb. 编译当前缓冲区后,我运行以下命令:Mx gud-gdb。 Emacs gives a prompt like below: gdb --fullname prog Emacs给出如下提示:gdb --fullname prog

However, sometimes the "prog" name is not the same as the executable name compiled from current buffer. 但是,有时“ prog”名称与从当前缓冲区编译的可执行文件名称不同。 eg I completed five programs prog1, prog2,... prog5, and is currently working on prog6. 例如,我完成了五个程序prog1,prog2,... prog5,目前正在研究prog6。 But Mx gud-gdb gives me gdb --fullname prog5. 但是Mx gud-gdb给了我gdb --fullname prog5。 (I want prog6 instead.) (我想改用prog6。)

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. 具体来说,“正确”表示强制gud-gdb使用当前缓冲区的名称(不带后缀)作为编名称。

Thanks in advance. 提前致谢。

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. 我认为emacs使用启发式方法(基于最新的可执行文件或类似的文件)来找出要提供的默认程序。

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. 此功能将在名为您正在编辑的文件(没有扩展名)的文件上执行gdb。

gud-query-cmdline accepts filename as an optional argument, which isn't served yet. gud-query-cmdline接受filename作为可选参数,目前尚未提供。

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM