您的位置:首页 > 其它

一次emacs调试经历

2008-10-13 16:41 435 查看
上午都在看emacs中关于版本控制的文档。下午写程序的时候,又遇到了别的问题。

还是在前两天从网上找到自定义emacs的编译命令的方法,代码如下:

1. (defun sucha-smart-compile ()
2. "Simply compile your file according to the file type."
3. (interactive)
4. (save-some-buffers t)
5. (let
6. ((compile-command nil)
7. (alist
8. (list '("//.c$" . "c:/mingw/bin/gcc")
9. '("//.cc$" . "c:/mingw/bin/g++")
10. '("//.cpp$" . "c:/mingw/bin/g++"))))
11. (while (not (null alist))
12. (if (string-match (caar alist) (buffer-file-name))
13. (setq compile-command
14. (concat (cdar alist) " " "/"" (buffer-file-name) "/"")))
15. (setq alist (cdr alist)))
16.
17. (if (null compile-command)
18. (setq compile-command
19. (read-from-minibuffer "Compile command: ")))
20. (compile compile-command)))
21. (global-set-key [C-f5] 'compile)
22. (global-set-key [f5] 'sucha-smart-compile)
其中,c:/mingw/bin是我的电脑上的编译器所在目录,这样写完程序一按f5键就会自动编译连接,但令人不爽的是它总是生成一个默认的a.exe,而不是我所希望的名字。生成一个a.exe的话,再使用gdb调试这个a.exe,就会得到一个:error process filter,:wrong argument type:stringp nil的错误信息。郁闷至极。当时猜想可以是gdb在emacs下有特殊的规定,而且猜想可能就是因为可执行文件与源代码文件的文件名不一样。于是今天把上述代码修改成下面的样子:
(defun sucha-smart-compile ()
"Simply compile your file according to the file type."
(interactive)
(save-some-buffers t)
(let
((compile-command nil)
(alist
(list '("//.c$" . "c:/mingw/bin/gcc -g ")
'("//.cc$" . "c:/mingw/bin/g++ -g ")
'("//.cpp$" . "c:/mingw/bin/g++ -g "))))
(while (not (null alist))
(if (string-match (caar alist) (buffer-file-name))
(setq compile-command[/b]
(concat (cdar alist) (file-name-nondirectory buffer-file-name)[/b]
" -o " [/b]
(file-name-sans-extension (file-name-nondirectory buffer-file-name)) ".exe")))[/b]
(setq alist (cdr alist)))

(if (null compile-command)
(setq compile-command
(read-from-minibuffer "Compile command: ")))
(compile compile-command)))
(global-set-key [C-f5] 'compile)
(global-set-key [f5] 'sucha-smart-compile)
主要是修改了上面高亮显示的那部分代码,其中file-name-nondirectory函数用来取得路径名抛掉目录后的纯文件名,file-name-sans-extension用来取得文件名去掉扩展名后的名字。这样终于达成所愿。
但是,使用gdb调试仍然是那个错误信息,google了一下,没有任何关于这个错误信息的消息。
突然间注意到,使用自动编译时和手动输入编译命令进行编译时-o参数后面的生成文件的名字在emacs下的显示是不一样的。自动编译时没有什么特别,而手动输入时生成文件的名字是被高亮显示的,很有可能就是使用自动编译命令生成的可执行文件在emacs中调试时不被看做具有可执行文件属性,因此导致了错误。如果真是这样的话,应该有两个方法可以改正,一个是使用emacs中的命令在编译后将生成的文件加上可执行文件属性,另一个是看看gdb是否提供了相应的选项在调试前不检查文件的属性。
另外,自己曾经费了好大功夫去猜一个可能的功能的命令,然后去emacs中使用C-h f或者C-h v去验证并从中得到一些emacs命名的规则的一点规律。但其实这些都在elisp的文档中,讲解的相当明白。
在emacs中,函数以-p结尾的通常是一个返回bool值的函数。这是一点猜测。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: