Debugging “如何追踪”;用“失败”;Emacs中的错误?

Debugging “如何追踪”;用“失败”;Emacs中的错误?,debugging,emacs,ocaml,Debugging,Emacs,Ocaml,我正在Emacs下编写OCaml。我已经配置了Emacs,以便Meta-x compile和make-k使用超链接发出警告。但是对于failwith引发的错误,它不能提供超链接,例如: analyzing (ZONE)... Fatal error: exception Failure("to do") Raised at file "pervasives.ml", line 22, characters 22-33 Called from file "list.ml", line 69, ch

我正在Emacs下编写OCaml。我已经配置了Emacs,以便
Meta-x compile
make-k
使用超链接发出警告。但是对于
failwith
引发的错误,它不能提供超链接,例如:

analyzing (ZONE)...
Fatal error: exception Failure("to do")
Raised at file "pervasives.ml", line 22, characters 22-33
Called from file "list.ml", line 69, characters 12-15
make: *** [all] Error 2

Compilation exited abnormally with code 2 at Fri Jan 27 18:44:10

在我的代码中,有许多
由于“to do”
而失败,我需要知道是哪一个引发了错误,有人知道如何让Emacs定位这种错误吗?

有时编译成字节码可以提供更精确的堆栈跟踪

  • 确保使用
    -g
    选项进行编译(或使用ocamlbuild的
    debug
    标记)
  • 编译为字节码,堆栈跟踪更精确
  • 确保
    $OCAMLRUNPARAM
    设置了
    b
    选项(请参阅)
  • M-x下一个错误
    将允许您跟踪堆栈跟踪(如果您使用发行版中的
    caml模式
    ,并且至少使用OCaml 3.11)

    请参阅以获取要添加到.emacs中的某些elisp,以便编译主模式知道如何解析OCaml回溯报告

    以下是建议的代码(加上tuareg模式挂钩):

    (反跟踪的解除caml更改错误列表()
    钩子将编译错误regexp-alist变量更改为
    搜索ocaml回溯以查找错误位置“
    (互动)
    (项目
    (setq编译错误regexp)
    (附加)
    “((caml回溯)
    “^*\\(?:在\\\\\;从\\调用)文件\\(\“?\)\\([^,\“\n\t]+\\)\\1处引发\
    行?\\([0-9]+\\)-?\\([0-9]+\\)?\\(?:$\\)\
    \\(?:字符?\([0-9]+\)-?\([0-9]+\)?:?\)?\)”
    2 (3 . 4) (5 . 6)))
    编译错误regexp
    (setq编译错误regexp)
    (追加编译错误regexp alist'(caml回溯(()())))
    (为回溯添加挂钩“caml模式挂钩”caml更改错误列表)
    (为回溯添加挂钩“图阿雷格模式挂钩”caml更改错误列表)
    (断言失败()的解除caml更改错误列表)
    钩子将编译错误regexp-alist变量更改为
    在断言失败消息中搜索错误位置“
    (互动)
    (项目
    (setq编译错误regexp)
    (附加)
    “((caml断言失败
    断言失败(\“\([^,\”\n\t]+\)\,\([0-9]+\),\([0-9]+\),\([0-9]+\)
    1 2 3))
    编译错误regexp
    (setq编译错误regexp)
    (附加编译错误regexp alist'(caml断言失败(()())))
    (为断言失败添加挂钩“caml模式挂钩”caml更改错误列表)
    (为断言失败添加挂钩“tuareg模式挂钩”caml更改错误列表)
    
    真的吗?
    M-x下一个错误
    对堆栈跟踪不起作用。是的,如果您使用发行版中的
    caml模式
    ,并且至少使用OCaml 3.11。请参阅。
    (defun caml-change-error-alist-for-backtraces ()
      "Hook to change the compilation-error-regexp-alist variable, to
       search the ocaml backtraces for error locations"
      (interactive)
      (progn
        (setq compilation-error-regexp-alist-alist
              (append
               '((caml-backtrace
    "^ *\\(?:Raised at\\|Called from\\) file \\(\"?\\)\\([^,\" \n\t<>]+\\)\\1,\
     lines? \\([0-9]+\\)-?\\([0-9]+\\)?\\(?:$\\|,\
    \\(?: characters? \\([0-9]+\\)-?\\([0-9]+\\)?:?\\)?\\)"
                  2 (3 . 4) (5 . 6)))
               compilation-error-regexp-alist-alist))
        (setq compilation-error-regexp-alist
              (append compilation-error-regexp-alist '(caml-backtrace)))))
    
    (add-hook 'caml-mode-hook 'caml-change-error-alist-for-backtraces)
    (add-hook 'tuareg-mode-hook 'caml-change-error-alist-for-backtraces)
    
    
    (defun caml-change-error-alist-for-assert-failure ()
      "Hook to change the compilation-error-regexp-alist variable, to
       search the assert failure messages for error locations"
      (interactive)
      (progn
        (setq compilation-error-regexp-alist-alist
              (append
               '((caml-assert-failure
                  "Assert_failure(\"\\([^,\" \n\t<>]+\\)\", \\([0-9]+\\), \\([0-9]+\\))"
                  1 2 3))
               compilation-error-regexp-alist-alist))
        (setq compilation-error-regexp-alist
              (append compilation-error-regexp-alist '(caml-assert-failure)))))
    
    (add-hook 'caml-mode-hook 'caml-change-error-alist-for-assert-failure)
    (add-hook 'tuareg-mode-hook 'caml-change-error-alist-for-assert-failure)