簡體   English   中英

如何在Emacs中實現錯誤回溯?

[英]How to realize error traceback in 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然后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

我的.emacs有一部分是我從朋友那里復制的追溯: 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)))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM