微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在Emacs中实现错误回溯?

如何解决如何在Emacs中实现错误回溯?

| 我正在用Ocaml编写编译器。在终端中使用
make
进行编译和测试时,tracback效果很好,例如:
export OCAMLRUNParaM=b
./Simpler-Basic test.sib
Fatal error: exception Match_failure(\"interp.ml\",45,21)
Called from file \"interp.ml\",line 97,characters 72-86
Called from file \"list.ml\",line 74,characters 24-34
Called from file \"interp.ml\",line 108,characters 9-35
Called from file \"main.ml\",line 54,characters 4-17
make: *** [all] Error 2
但是,当我在Emacs中使用
Meta-x compile
和by0ѭ对其进行编译和测试时,它不会在缓冲区中显示回溯部分:
make
export OCAMLRUNParaM=b
./Simpler-Basic test.sib
Fatal error: exception Match_failure(\"interp.ml\",21)
make: *** [all] Error 2

Compilation exited abnormally with code 2 at Sat Jun 18 19:03:04
我的ѭ5中有一部分内容是我从朋友那里复制来进行追溯的:http://paste.ubuntu.com/628838/ 谁能告诉我如何修改我的
.emacs
,以使其在终端中显示回溯?非常感谢你     

解决方法

        你在哪里写
export OCAMLRUNPARAM=b
? 如果您在makefile中编写了此代码(↹代表制表符):
↹export OCAMLRUNPARAM=b
↹./Simpler-Basic test.sib
则它不起作用,因为每个makefile命令都在单独的shell中执行,因此第一行完成后环境变量分配消失了。您可以将这两行合并为一条逻辑行:
↹export OCAMLRUNPARAM=b; \\
↹./Simpler-Basic test.sib
如果在Emacs中运行Ocaml程序时总是想回溯,请在
.emacs
中设置环境变量:
(setenv \"OCAMLRUNPARAM\" \"b\")
为了使Emacs可以将回溯消息识别为带有位置的错误消息,您需要在
compilation-regexp-alist
中进行注册。在您的
.emacs
中放入以下内容(未经测试):
(eval-after-load \"caml\"
  (add-to-list \'compilation-regexp-alist
               \'(\"\\\\(^Raised at\\\\|Called from\\\\) file \\\"\\\\([^\"\\n]+\\\\)\\\",line \\\\([0-9]+\\\\)\"
                 2 3)))
    

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。