Skip to content

Commit

Permalink
fixup! compiler: Add support for debug information in BEAM files
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorng committed Nov 12, 2024
1 parent 6c47bf2 commit 025d308
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
8 changes: 6 additions & 2 deletions lib/compiler/src/beam_ssa_codegen.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2052,8 +2052,12 @@ cg_instr(executable_line, [{integer,Index}], _Dst, #cg_set{anno=Anno}) ->
[{executable_line,Location,Index}];
cg_instr(debug_line, [{integer,Index},{integer,Live},{literal,Info}],
_Dst, #cg_set{anno=Anno}) ->
{line,Location} = line(Anno),
[{debug_line,Location,Index,Live,Info}];
case line(Anno) of
{line,[]} ->
[];
{line,Location} ->
[{debug_line,Location,Index,Live,Info}]
end;
cg_instr(put_map, [{atom,assoc},SrcMap|Ss], Dst, Set) ->
Live = get_live(Set),
[{put_map_assoc,{f,0},SrcMap,Dst,Live,{list,Ss}}];
Expand Down
4 changes: 2 additions & 2 deletions lib/compiler/src/compile.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1676,8 +1676,8 @@ abstr_passes(AbstrStatus) ->
%% The `beam_debug_info` and `line_coverage` options are
%% mutually exclusive. If both are given, ignore the
%% `line_coverage` option.
{delay,[{iff,beam_debug_info,?pass(beam_debug_info)},
{iff,line_coverage,{pass,sys_coverage}}]},
{delay,[{iff,line_coverage,{pass,sys_coverage}},
{iff,beam_debug_info,?pass(beam_debug_info)}]},

?pass(expand_records),
{iff,'dexp',{listing,"expand"}},
Expand Down
26 changes: 24 additions & 2 deletions lib/compiler/src/sys_coverage.erl
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,11 @@ munge_expr({'catch',Anno,Expr}, Vars0) ->
munge_expr({call,Anno1,{remote,Anno2,ExprM,ExprF},Exprs}, Vars0) ->
{MungedExprM, Vars1} = munge_expr(ExprM, Vars0),
{MungedExprF, Vars2} = munge_expr(ExprF, Vars1),
{MungedExprs, Vars3} = munge_exprs(Exprs, Vars2),
{MungedExprs, Vars3} = munge_args(Exprs, Vars2),
{{call,Anno1,{remote,Anno2,MungedExprM,MungedExprF},MungedExprs}, Vars3};
munge_expr({call,Anno,Expr,Exprs}, Vars0) ->
{MungedExpr, Vars1} = munge_expr(Expr, Vars0),
{MungedExprs, Vars2} = munge_exprs(Exprs, Vars1),
{MungedExprs, Vars2} = munge_args(Exprs, Vars1),
{{call,Anno,MungedExpr,MungedExprs}, Vars2};
munge_expr({lc,Anno,Expr,Qs}, Vars0) ->
{MungedExpr, Vars1} = munge_expr(?BLOCK1(Expr), Vars0),
Expand Down Expand Up @@ -550,6 +550,28 @@ munge_expr({bin_element,Anno,Value,Size,TypeSpecifierList}, Vars0) ->
munge_expr(Form, Vars0) ->
{Form, Vars0}.

munge_args(Args0, #vars{in_guard=false,bump_instr=debug_line}=Vars) ->
%% We want to have `debug_line` instructions inserted before each line in
%% this example:
%%
%% bar:f(
%% bar:g(X),
%% bar:h(X)).
Args = [case is_atomic(Arg) of
true -> Arg;
false -> ?BLOCK(Arg)
end || Arg <- Args0],
munge_exprs(Args, Vars);
munge_args(Args, Vars) ->
munge_exprs(Args, Vars).

is_atomic({atom,_,_}) -> true;
is_atomic({float,_,_}) -> true;
is_atomic({integer,_,_}) -> true;
is_atomic({nil,_}) -> true;
is_atomic({var,_,_}) -> true;
is_atomic(_) -> false.

munge_exprs(Exprs, Vars) ->
munge_exprs(Exprs, Vars, []).

Expand Down

0 comments on commit 025d308

Please sign in to comment.