How do you get the Erlang debugger to do a conditional break?

Given a positive number N, my print_even () function prints all the even numbers between 1 and N:

-module(my).
-compile(export_all).

print_even(N) when N>0 -> even_helper(1, N).

even_helper(Current, N) when Current =< N ->
    io:format("(Current = ~w)~n", [Current]),
    case Current rem 2 of
        0 -> io:format("Number: ~p~n", [Current]);
        _ -> do_nothing
    end,
    even_helper(Current+1, N);
even_helper(Current, N) when Current > N ->
    ok.

Here is an example output:

28> my:print_even(10).
(Current = 1)
(Current = 2)
Number: 2
(Current = 3)
(Current = 4)
Number: 4
(Current = 5)
(Current = 6)
Number: 6
(Current = 7)
(Current = 8)
Number: 8
(Current = 9)
(Current = 10)
Number: 10
ok

Below is the code I use for conditional break:

-module(c_test).
-compile(export_all).

c_break(Bindings) ->
    case int:get_bindings('Current', Bindings) of
        {value, 3}  -> true;
        _           -> false
    end.

I set a conditional break in the following line in print_even ():

    case Current rem 2 of

... which, according to Erlang's debugger docs , should be legal. But no matter what I do, I can not get my c_break () function to execute. I expected execution to stop at the breakpoint when the current is 3, but the code ends and the breakpoint is skipped. I even tried:

c_break(Bindings) ->
    case int:get_bindings('Current', Bindings) of
        _  -> true;
    end.

But stopping will not stop at the breakpoint.

: , :

c_break(_) ->
    true.

:

c_break(X) ->
    io:format("~w~n", [X]),
    true.

..., .

+4
1

! @# $@# $@!! :

int:get_binding()
              ^
              |

int:get_bindings() 
               ^
               |

. , : , :

82> debugger:stop().
ok 

( : stop(), , - .)

:

83> c(my, [debug_info]).
{ok,my}
84> c(c_test).
{ok,c_test}

:

85> debugger:start().
{ok,<0.305.0>}

: start() Monitor window, :

Module > Interpret 

... my.erl , my.erl - , , .

, Monitor , :

 Break>Conditional Break 

... . , "" , View Module window, . " " , "", . " " , .. : , .

:

86> my:print_even(10).  
(Current = 1)
(Current = 2)
Number: 2
(Current = 3)

!

, "" , " ". " " , , .

"" , On Break, Attach Process , . , Attach Process .

, c_test c_break() . , , conditional_breaks break1().

+3

Source: https://habr.com/ru/post/1608924/


All Articles