Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Erlang 如何知道.beam文件是否使用调试信息编译?_Erlang - Fatal编程技术网

Erlang 如何知道.beam文件是否使用调试信息编译?

Erlang 如何知道.beam文件是否使用调试信息编译?,erlang,Erlang,我发现我需要使用debug\u info参数编译一个.erl文件,以便在调试器中调试它 当我尝试在调试器中调试.beam文件时,我总是看到该文件没有调试信息,无法打开 **无效的beam文件或没有抽象代码:“%erlang debug/myapp.beam” 我怀疑可能是我以错误的方式编译了这些文件。 我尝试了所有可能的方法,但仍然没有运气,我觉得文件编译没有调试信息 我使用的一个最简单的例子是: 有没有办法知道某个特定的.beam文件是否使用debug_info编译?一种方法是使用检查beam

我发现我需要使用
debug\u info
参数编译一个
.erl
文件,以便在调试器中调试它

当我尝试在调试器中调试
.beam
文件时,我总是看到该文件没有调试信息,无法打开

**无效的beam文件或没有抽象代码:“%erlang debug/myapp.beam”

我怀疑可能是我以错误的方式编译了这些文件。 我尝试了所有可能的方法,但仍然没有运气,我觉得文件编译没有调试信息

我使用的一个最简单的例子是:

有没有办法知道某个特定的
.beam
文件是否使用debug_info编译?

一种方法是使用检查beam文件是否有大小非零的抽象代码块。例如,给定一个名为
x.beam
的beam文件,您可以从Linux/UNIX/OS x shell执行此检查,如下所示(请注意,
$
是我的shell提示符,我将其分为多行,以便于阅读,但您也可以将其全部放在一行中,无论哪种方式都可以):

这将检查beam文件中id为“abs”的块,并检查其关联的二进制数据大小是否为非零。如果是,则打印
,否则打印

下面是一个使用它的示例,我们首先使用调试信息编译,检查beam文件,然后在不使用调试信息的情况下编译,然后再次检查:

$ erlc +debug_info x.erl
$ erl -noinput -eval 'io:format("~s\n",
[case beam_lib:chunks(hd(init:get_plain_arguments()), ["Abst"]) of
    {ok,{_,[{"Abst",A}]}} when byte_size(A) /= 0 -> "yes";
    _ -> "no" end])' -s init stop -- x.beam
yes
$ erlc +no_debug_info x.erl
$ erl -noinput -eval 'io:format("~s\n",
[case beam_lib:chunks(hd(init:get_plain_arguments()), ["Abst"]) of
    {ok,{_,[{"Abst",A}]}} when byte_size(A) /= 0 -> "yes";
    _ -> "no" end])' -s init stop -- x.beam
no

您可以使用module_info函数访问所有编译选项。要对调试信息标志进行测试,可以使用PropList函数提取信息:

1> O = fun(M) ->               
1> Comp = M:module_info(compile),      
1> Options = proplists:get_value(options,Comp),
1> proplists:get_value(debug_info,Options)     
1> end.                                        
#Fun<erl_eval.6.50752066>
2> c(p564).
{ok,p564}
3> O(p564).
undefined
4> c(p564,[debug_info]). 
{ok,p564}
5> O(p564).             
true
6>
1>O=fun(M)->
1> Comp=M:模块信息(编译),
1> 选项=项目列表:获取_值(选项,组件),
1> PropList:get_值(调试信息、选项)
1> 结束。
#乐趣
2> c(p564)。
{好的,p564}
3> O(p564)。
未定义
4> c(p564[debug_info])。
{好的,p564}
5> O(p564)。
真的
6>
$ erlc +debug_info x.erl
$ erl -noinput -eval 'io:format("~s\n",
[case beam_lib:chunks(hd(init:get_plain_arguments()), ["Abst"]) of
    {ok,{_,[{"Abst",A}]}} when byte_size(A) /= 0 -> "yes";
    _ -> "no" end])' -s init stop -- x.beam
yes
$ erlc +no_debug_info x.erl
$ erl -noinput -eval 'io:format("~s\n",
[case beam_lib:chunks(hd(init:get_plain_arguments()), ["Abst"]) of
    {ok,{_,[{"Abst",A}]}} when byte_size(A) /= 0 -> "yes";
    _ -> "no" end])' -s init stop -- x.beam
no
1> O = fun(M) ->               
1> Comp = M:module_info(compile),      
1> Options = proplists:get_value(options,Comp),
1> proplists:get_value(debug_info,Options)     
1> end.                                        
#Fun<erl_eval.6.50752066>
2> c(p564).
{ok,p564}
3> O(p564).
undefined
4> c(p564,[debug_info]). 
{ok,p564}
5> O(p564).             
true
6>