[英]How to realize error traceback in Emacs?
I am writing a compiler in Ocaml. 我正在Ocaml中编写一个编译器。 The tracback works well when I compile and test it with make
in a terminal, for instance: 当我在终端中使用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
But when I compile and test it in my Emacs by Meta-x compile
followed by make
, it does not show the traceback part in the buffer: 但是当我在我的Emacs中通过Meta-x compile
然后make
编译并测试它时,它不会在缓冲区中显示回溯部分:
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/ 我的.emacs
有一部分是我从朋友那里复制的追溯: http : //paste.ubuntu.com/628838/
Could anyone tell me how to amend my .emacs
so that it shows traceback as in a terminal? 谁能告诉我如何修改我的.emacs
以便它显示在终端中的追溯? Thank you very much 非常感谢你
Where did you write export OCAMLRUNPARAM=b
? 你在哪里写export OCAMLRUNPARAM=b
?
If you wrote this in a makefile (↹ stands for a tab): 如果你在makefile中写了这个(↹代表一个标签):
↹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. 然后它不起作用,因为每个makefile命令都在一个单独的shell中执行,因此环境变量赋值在第一行完成后消失。 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
: 如果您在Emacs中运行Ocaml程序时总是想要回溯,请在.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
. 为了让Emacs将回溯消息识别为带有位置的错误消息,您需要在compilation-regexp-alist
注册它们。 Put something like this in your .emacs
(untested): 在你的.emacs
放置这样的东西(未经测试):
(eval-after-load "caml"
(add-to-list 'compilation-regexp-alist
'("\\(^Raised at\\|Called from\\) file \"\\([^"\n]+\\)\", line \\([0-9]+\\)"
2 3)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.