Skip to content

Commit

Permalink
Test that we can see the stackframe (including top frame var) of a st…
Browse files Browse the repository at this point in the history
…epping process

Summary:
This checks in particular that we don't require to hit a user breakpoint in order to resolve variables (that used to be the case before the introduction of `edb_server_break:is_trapped`).

We add a dummy function that computes some arithmetic to avoid the current quirks of stepping in recursive functions.

Reviewed By: jcpetruzza

Differential Revision: D68508670

fbshipit-source-id: c3c51b3a918bb89f3741e79e96ea97e0cabd0f85
  • Loading branch information
Thibault Suzanne authored and facebook-github-bot committed Jan 23, 2025
1 parent c9f4460 commit 08aa332
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
60 changes: 60 additions & 0 deletions test/edb_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
%% Test cases for the test_stackframes group
-export([test_shows_stackframes_of_process_in_breakpoint/1]).
-export([test_shows_stackframes_of_paused_processes_not_in_breakpoint/1]).
-export([test_shows_stackframes_of_stepping_process/1]).
-export([test_can_control_max_size_of_terms_in_vars_for_process_in_bp/1]).
-export([test_can_control_max_size_of_terms_in_vars_for_process_not_in_bp/1]).
-export([test_doesnt_show_stackframes_for_running_processes/1]).
Expand Down Expand Up @@ -126,6 +127,7 @@ groups() ->
{test_stackframes, [], [
test_shows_stackframes_of_process_in_breakpoint,
test_shows_stackframes_of_paused_processes_not_in_breakpoint,
test_shows_stackframes_of_stepping_process,
test_can_control_max_size_of_terms_in_vars_for_process_in_bp,
test_can_control_max_size_of_terms_in_vars_for_process_not_in_bp,
test_doesnt_show_stackframes_for_running_processes,
Expand Down Expand Up @@ -2094,6 +2096,64 @@ test_shows_stackframes_of_paused_processes_not_in_breakpoint(Config) ->
),
ok.

test_shows_stackframes_of_stepping_process(Config) ->
TestModuleSource = proplists:get_value(erl_source, Config),

% Stop before computing 42
ok = edb:add_breakpoint(test_stackframes, 38),

% Spawn a process that will hit this breakpoint
Pid = erlang:spawn(test_stackframes, forty_two, []),
{ok, stopped} = edb:wait(),

% Step to the next line
ok = edb:step_over(Pid),
{ok, stopped} = edb:wait(),

% Check that we can see the stack frames
{ok, Frames} = edb:stack_frames(Pid),
?assertEqual(
[
% forty_two(1337)
#{id => 2, mfa => {test_stackframes, forty_two, 1}, source => TestModuleSource, line => 39},
% forty_two()
#{id => 1, mfa => {test_stackframes, forty_two, 0}, source => TestModuleSource, line => 34}
],
Frames
),

% Can't select the step frame
?assertEqual(
undefined,
edb:stack_frame_vars(Pid, 3)
),

% Can see variables in the top frame
?assertEqual(
{ok, #{
vars => #{
<<"X">> => {value, 1337},
<<"Six">> => {value, 6},
<<"FortyTwo">> => {value, 42}
},
xregs => [
{value, 1337}
],
yregs => []
}},
edb:stack_frame_vars(Pid, 2)
),

% Sanity check that we can select the bottom frame
?assertEqual(
{ok, #{
yregs => []
}},
edb:stack_frame_vars(Pid, 1)
),

ok.

test_can_control_max_size_of_terms_in_vars_for_process_in_bp(_Config) ->
% stop in hang() call
ok = edb:add_breakpoint(test_stackframes, 31),
Expand Down
11 changes: 10 additions & 1 deletion test/edb_SUITE_data/test_stackframes.erl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-module(test_stackframes). %01
-export([choose/2, ping/1, pong/0, hang/3]). %02
-export([choose/2, ping/1, pong/0, hang/3, forty_two/0]). %02

choose(N, K) when N =:= K -> %04
N div K; %05 (convoluted way to say 1, to have N and K "alive")
Expand Down Expand Up @@ -29,3 +29,12 @@ pong() -> %23

hang(X, Y, Z) -> %30
hang(X, Y, Z). %31

forty_two() -> %33
0 + forty_two(1337). %34 (force a non-tail call)

forty_two(X) -> %36
Six = 6, %37
FortyTwo = Six * 7, %38
_KeepXAlive = X + X, %39 (force X to be alive)
FortyTwo. %40

0 comments on commit 08aa332

Please sign in to comment.