如何在Emacs中实现错误追溯? [英] How to realize error traceback in Emacs?
问题描述
make
进行编译和调试时,tracback会很好,例如:export OCAMLRUNPARAM = b
$但是当我通过
./Simpler-Basic test.sib
致命错误:异常Match_failure(interp.ml,45,21)
从文件第97行,字符72-86
从文件list.ml中调用,第74行,字符24-34
从文件interp.ml调用,第108行,字符9 -35
从文件main.ml中调用,第54行,字符4-17
make:*** [all]错误2
Meta-x编译
编译并在我的Emacs中测试它,然后是$ code > make ,它不会在缓冲区中显示回溯部分:make
导出OCAMLRUNPARAM = b
./Simpler-Basic test.sib
致命错误:异常Match_failure(interp.ml,45,21)
make:*** [all]错误2
编译在6月18日星期六异常退出代码2 19:03:04
Ther e是我的
.emacs
中的一部分,用于执行我从朋友复制的追溯: http://paste.ubuntu.com/628838/
有人可以告诉我如何修改我的
.emacs
,以便在终端中显示追溯?非常感谢你解决方案你在哪里写了
export OCAMLRUNPARAM = b
?
如果你在一个makefile中写这个(↹代表一个选项卡):
code>↹exportOCAMLRUNPARAM = b
↹。/ Simpleer-Basic test.sib
然后它不起作用,因为每个makefile命令在单独的shell中执行,所以环境变量赋值在第一行完成之后就会消失。您可以将两行合并在一条逻辑行中:
↹exportOCAMLRUNPARAM = b; \
↹。/ Simpleer-Basic test.sib
如果你总是想要回溯在Emacs内运行一个Ocaml程序,在
.emacs
中设置环境变量:(setenvOCAMLRUNPARAMb)
为了让Emacs识别回溯消息作为与位置的错误消息,您需要在
compilation-regexp-alist
。在你的.emacs
(未经测试)中放入这样的东西:eval-after-loadcaml
(add-to-list'compilation-regexp-alist
'(\\(^ Raised at\\\ | |来自于\\ )文件\\\([^\\\
] + \\)\,行\\([0-9] + \\)
2 3)))
I am writing a compiler in Ocaml. The tracback works well when I compile and test it with
make
in a terminal, for instance: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
But when I compile and test it in my Emacs by
Meta-x compile
followed bymake
, it does not show the traceback part in the buffer:make export OCAMLRUNPARAM=b ./Simpler-Basic test.sib Fatal error: exception Match_failure("interp.ml", 45, 21) make: *** [all] Error 2 Compilation exited abnormally with code 2 at Sat Jun 18 19:03:04
There is a part in my
.emacs
to do traceback that I copied from a friend: http://paste.ubuntu.com/628838/Could anyone tell me how to amend my
.emacs
so that it shows traceback as in a terminal? Thank you very much解决方案Where did you write
export OCAMLRUNPARAM=b
?If you wrote this in a makefile (↹ stands for a tab):
↹export OCAMLRUNPARAM=b ↹./Simpler-Basic test.sib
then it doesn't work because each makefile command is executed in a separate shell, so the environment variable assignment vanishes after the first line completes. You can combine the two lines in a single logical line instead:
↹export OCAMLRUNPARAM=b; \ ↹./Simpler-Basic test.sib
If you always want backtraces when running an Ocaml program from within Emacs, set the environment variable in your
.emacs
:(setenv "OCAMLRUNPARAM" "b")
In order for Emacs to recognize the backtrace messages as error messages with a location, you need to register them in
compilation-regexp-alist
. Put something like this in your.emacs
(untested):(eval-after-load "caml" (add-to-list 'compilation-regexp-alist '("\\(^Raised at\\|Called from\\) file \"\\([^"\n]+\\)\", line \\([0-9]+\\)" 2 3)))
这篇关于如何在Emacs中实现错误追溯?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!