简体   繁体   English

如何使用Intellij想法调试Erlang项目?

[英]How to debug a Erlang project with Intellij idea?

I would like to learn an open source software used as a message broker(EMQTT https://github.com/emqtt/emqttd ), but when I am trying to change some code and trace how messages flow in it, there comes an problem that the Intellij Idea seems can only debug one Erlang function or one module at one time. 我想学习用作消息代理的开放源代码软件(EMQTT https://github.com/emqtt/emqttd ),但是当我尝试更改某些代码并跟踪消息在其中的流动方式时,出现了问题Intellij Idea似乎只能一次调试一个Erlang函数或一个模块。 Is there any way that I could debug the whole project and trace it with break point instead of debugging them in function one by one? 有什么方法可以调试整个项目并使用断点进行跟踪,而不是在功能中逐一调试? 在此处输入图片说明

Intellij Uses rebar as project manager. Intellij使用钢筋作为项目经理。 rebar was deprecated and rebar3 (new version of rebar) is available with advanced features. 不推荐使用rebar,并且rebar3(rebar的新版本)具有高级功能。

You can use rebar3 and its advanced features for running tests & dialyzer. 您可以使用rebar3及其高级功能来运行测试和透析仪。

EMQTT supports travis ! EMQTT支持travis!
You can fork it and enable travis in your project. 您可以将其派生并在项目中启用travis。 travis is a test platform and will test your project after every change. travis是一个测试平台,每次更改后都会测试您的项目。
for more info see travis docs 有关更多信息,请参阅travis文档

After some days of tries, I have found a method that could be used do debug with Intellij Idea, it is not as prefect as the method I would like to find, but it helps on some degree, just post it here for someone in need to reference. 经过几天的尝试,我发现可以用Intellij Idea进行调试的方法,它不如我想找到的方法完善,但在某种程度上有所帮助,只需将其发布在此处供有需要的人使用以供参考。

  1. cd in to the directory where your *.erl file is in. cd进入* .erl文件所在的目录。
  2. compile with c("your erl file", debug_info). 用c(“您的erl文件”,debug_info)进行编译。 There must be a debug_info when compile, otherwise, the debug will raise error: "no debug info in beam file". 编译时必须有一个debug_info,否则调试将引发错误:“ Beam文件中没有调试信息”。

  3. config parameters according to your module, below figure is for reference. 根据您的模块配置参数,下图仅供参考。 You may need provide function args if your function needs args 如果您的函数需要args,则可能需要提供函数args

ps: This is relative redundant to compile with shell, but it is the only method I found could works, if no beam file is supplied, it always raise error: "no beam file". ps:使用shell编译相对来说是多余的,但这是我发现的唯一可行的方法,如果没有提供任何梁文件,它总是会引发错误:“无梁文件”。

If anyone has a better method, please give me a help whether by answer this question or a comment, thanks a lot! 如果有人有更好的方法,请通过回答此问题或评论给我帮助,非常感谢!

在此处输入图片说明

Your solution of having the source files and artefacts in one directory seem to be the only way to use the Intellij debugger. 您将源文件和工件保存在一个目录中的解决方案似乎是使用Intellij调试器的唯一方法。 Since usually the source files and artefacts are not in the same directory, this behaviour seems odd. 由于通常源文件和工件不在同一目录中,因此这种行为似乎很奇怪。 I have opened an issue therefore ( https://github.com/ignatov/intellij-erlang/issues/811 ). 因此,我已经打开了一个问题( https://github.com/ignatov/intellij-erlang/issues/811 )。

A solution which works with rebar3 and eunit is described in How to debug erlang code during rebar3 eunit? 在rebar3 eunit期间如何调试erlang代码中介绍了适用于rebar3和eunit的解决方案 . You can start rebar3 as test shell in Intellij by using the support for running a rebar3 command provided with the erlang plugin. 通过使用对运行erlang插件随附的rebar3命令的支持,可以在Intellij中将rebar3作为测试外壳启动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM