Skip to content

Decode "Line" chunk and expand line instructions#51

Merged
dumbbell merged 1 commit into
mainfrom
decode-line-chunk-for-meaningful-staktraces
Feb 15, 2022
Merged

Decode "Line" chunk and expand line instructions#51
dumbbell merged 1 commit into
mainfrom
decode-line-chunk-for-meaningful-staktraces

Conversation

@dumbbell

Copy link
Copy Markdown
Collaborator

Line information comes from the "Line" chunk in the beam module. This is not decoded by beam_disasm and the line instructions it produces only have the index inside that "Line" beam chunk.

So far, we needed to get rid of all those line instructions because they were invalid for the compiler. It meant that frames in stacktraces pointing to an extracted function had no location. This made any sort of debugging quite difficult.

Here is an example without this patch:

%% Based on the following function:
%%     crashing_fun() ->
%%         throw("Expected crash").

1> Fun = khepri_fun:to_standalone_fun(fun mod:crashing_fun/0, #{}).
2> khepri_fun:exec(Fun, []).
** exception throw: "Expected crash"
     in function  kfun__mod__crashing_fun__33048370:run/0

Now, we decode the "Line" beam chunk for each module we need to disassemble. We then use this decoded table to replace the incomplete line instructions by valid ones.

Thanks to that, we get stacktrace frames with correct locations, making debugging far easier. Here is the same example as above, but with this change in place:

1> Fun = khepri_fun:to_standalone_fun(fun mod:crashing_fun/0, #{}).
2> khepri_fun:exec(Fun, []).
** exception throw: "Expected crash"
     in function  kfun__mod__crashing_fun__33048370:run/0 (.../mod.erl, line 30)

Fixes #50.

@dumbbell dumbbell added the enhancement New feature or request label Feb 14, 2022
@dumbbell dumbbell self-assigned this Feb 14, 2022
@coveralls

coveralls commented Feb 14, 2022

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 359

  • 57 of 66 (86.36%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 85.46%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/khepri_fun.erl 57 66 86.36%
Totals Coverage Status
Change from base Build 357: 0.1%
Covered Lines: 1534
Relevant Lines: 1795

💛 - Coveralls

Line information comes from the "Line" chunk in the beam module. This
is not decoded by `beam_disasm` and the `line` instructions it produces
only have the index inside that "Line" beam chunk.

So far, we needed to get rid of all those `line` instructions because
they were invalid for the compiler. It meant that frames in stacktraces
pointing to an extracted function had no location. This made any sort of
debugging quite difficult.

Here is an example without this patch:

    %% Based on the following function:
    %%     crashing_fun() ->
    %%         throw("Expected crash").

    1> Fun = khepri_fun:to_standalone_fun(fun mod:crashing_fun/0, #{}).
    2> khepri_fun:exec(Fun, []).
    ** exception throw: "Expected crash"
         in function  kfun__mod__crashing_fun__33048370:run/0

Now, we decode the "Line" beam chunk for each module we need to
disassemble. We then use this decoded table to replace the incomplete
`line` instructions by valid ones.

Thanks to that, we get stacktrace frames with correct locations, making
debugging far easier. Here is the same example as above, but with this
change in place:

    1> Fun = khepri_fun:to_standalone_fun(fun mod:crashing_fun/0, #{}).
    2> khepri_fun:exec(Fun, []).
    ** exception throw: "Expected crash"
         in function  kfun__mod__crashing_fun__33048370:run/0 (.../mod.erl, line 30)

Fixes #50.
@dumbbell
dumbbell force-pushed the decode-line-chunk-for-meaningful-staktraces branch from a1d0527 to 4582437 Compare February 15, 2022 13:38
@dumbbell
dumbbell marked this pull request as ready for review February 15, 2022 13:43
@dumbbell
dumbbell merged commit ff54079 into main Feb 15, 2022
@dumbbell
dumbbell deleted the decode-line-chunk-for-meaningful-staktraces branch February 15, 2022 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exceptions in standalone functions have unhelpful stacktraces

2 participants