Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dependencies of process_info(..., message*) #283

Merged
merged 6 commits into from
Aug 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Changed
- handling of demonitors (#281)
- handling of process_info(..., messages) (#283)

### Fixed
- fixed stacktrace information (#276)
Expand Down
7 changes: 4 additions & 3 deletions src/concuerror.erl
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,9 @@ start(Options, LogMsgs) ->

maybe_cover_compile() ->
Cover = os:getenv("CONCUERROR_COVER"),
case Cover =/= false of
case get(concuerror_cover) =:= undefined andalso Cover =/= false of
true ->
put(concuerror_cover, Cover),
case cover:is_compiled(?MODULE) of
false ->
{ok, Modules} = application:get_key(concuerror, modules),
Expand All @@ -191,8 +192,8 @@ maybe_cover_compile() ->
%%------------------------------------------------------------------------------

maybe_cover_export(Args) ->
Cover = os:getenv("CONCUERROR_COVER"),
case Cover =/= false of
Cover = erase(concuerror_cover),
case Cover =/= undefined of
true ->
Hash = binary:decode_unsigned(erlang:md5(term_to_binary(Args))),
Out = filename:join([Cover, io_lib:format("~.16b", [Hash])]),
Expand Down
34 changes: 16 additions & 18 deletions src/concuerror_callback.erl
Original file line number Diff line number Diff line change
Expand Up @@ -311,15 +311,11 @@ built_in(erlang, Display, 1, [Term], _Location, Info)
end,
concuerror_logger:print(Info#concuerror_info.logger, standard_io, Chars),
{{didit, true}, Info};
%% Process dictionary has been restored here. No need to report such ops.
%% Inner process dictionary has been restored here. No need to report such ops.
%% Also can't fail, as only true builtins reach this code.
built_in(erlang, Name, _Arity, Args, _Location, Info)
when Name =:= get; Name =:= get_keys; Name =:= put; Name =:= erase ->
try
{{didit, erlang:apply(erlang, Name, Args)}, Info}
catch
error:Reason -> {{error, Reason}, Info}
end;
%% XXX: Temporary
{{didit, erlang:apply(erlang, Name, Args)}, Info};
built_in(erlang, hibernate, 3, Args, _Location, Info) ->
[Module, Name, HibArgs] = Args,
self() ! {start, Module, Name, HibArgs},
Expand Down Expand Up @@ -682,8 +678,13 @@ run_built_in(erlang, process_info, 2, [Pid, Item], Info) when is_atom(Item) ->
catch error:badarg -> []
end;
messages ->
#concuerror_info{message_queue = Queue} = TheirInfo,
[M || #message{data = M} <- queue:to_list(Queue)];
#concuerror_info{logger = Logger} = TheirInfo,
Msg =
"Concuerror does not properly support"
" erlang:process_info(Other, messages),"
" returning an empty list instead.~n",
?unique(Logger, ?lwarning, Msg, []),
[];
message_queue_len ->
#concuerror_info{message_queue = Queue} = TheirInfo,
queue:len(Queue);
Expand Down Expand Up @@ -1852,8 +1853,8 @@ exiting(Reason, Stacktrace, InfoIn) ->
FunFold = fun(Fun, Acc) -> Fun(Acc) end,
FunList =
[fun ets_ownership_exiting_events/1,
link_monitor_handlers(links, fun handle_link/4, Links),
link_monitor_handlers(monitors, fun handle_monitor/4, Monitors)],
link_monitor_handlers(fun handle_link/4, Links),
link_monitor_handlers(fun handle_monitor/4, Monitors)],
NewInfo = ExitInfo#concuerror_info{exit_reason = Reason},
FinalInfo = lists:foldl(FunFold, NewInfo, FunList),
?debug_flag(?loop, exited),
Expand Down Expand Up @@ -1911,17 +1912,14 @@ handle_monitor({Ref, P, As}, S, Reason, InfoIn) ->
instrumented(call, MFArgs, exit, InfoIn),
NewInfo.

link_monitor_handlers(Type, Handler, LinksOrMonitors) ->
link_monitor_handlers(Handler, LinksOrMonitors) ->
fun(Info) ->
#concuerror_info{exit_reason = Reason} = Info,
HandleActive =
Fold =
fun({LinkOrMonitor, S}, InfoIn) ->
case S =:= active orelse Type =:= monitors of
true -> Handler(LinkOrMonitor, S, Reason, InfoIn);
false -> InfoIn
end
Handler(LinkOrMonitor, S, Reason, InfoIn)
end,
lists:foldl(HandleActive, Info, LinksOrMonitors)
lists:foldl(Fold, Info, LinksOrMonitors)
end.

%%------------------------------------------------------------------------------
Expand Down
10 changes: 7 additions & 3 deletions src/concuerror_dependencies.erl
Original file line number Diff line number Diff line change
Expand Up @@ -393,14 +393,17 @@ dependent_process_info(#builtin_event{mfargs = {_,_,[Pid, links]}},
when UnLink =:= link; UnLink =:= unlink -> true;
_ -> false
end;
dependent_process_info(#builtin_event{mfargs = {_,_,[Pid, Msg]}},
Other)
when Msg =:= messages; Msg =:= message_queue_len ->
dependent_process_info(#builtin_event{mfargs = {_,_,[Pid, message_queue_len]}},
Other) ->
case Other of
#message_event{recipient = Recipient} ->
Recipient =:= Pid;
#receive_event{recipient = Recipient, message = M} ->
Recipient =:= Pid andalso M =/= 'after';
#builtin_event{actor = Recipient, mfargs = {M, F, [_, Args]}} ->
Recipient =:= Pid andalso
{M, F} =:= {erlang, demonitor} andalso
try lists:member(flush, Args) catch _:_ -> false end;
_ -> false
end;
dependent_process_info(#builtin_event{mfargs = {_, _, [Pid, registered_name]}},
Expand Down Expand Up @@ -431,6 +434,7 @@ dependent_process_info(#builtin_event{mfargs = {_,_,[_, Safe]}},
Safe =:= current_stacktrace;
Safe =:= dictionary;
Safe =:= heap_size;
Safe =:= messages; %% If fixed, it should be an observer of message races
Safe =:= reductions;
Safe =:= stack_size;
Safe =:= status
Expand Down
3 changes: 2 additions & 1 deletion src/concuerror_instrumenter.erl
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ is_unsafe({erlang, F, A}) ->
StringF = atom_to_list(F),
not erl_safe(StringF)
end;
is_unsafe({erts_internal, garbage_collect, _}) ->
false;
is_unsafe({Safe, _, _})
when
Safe =:= binary
Expand Down Expand Up @@ -230,7 +232,6 @@ erl_safe("fun_info" ++ _) -> true;
erl_safe("function_exported" ) -> true;
erl_safe("garbage_collect" ) -> true;
erl_safe("get_module_info" ) -> true;
erl_safe("hash" ) -> true;
erl_safe("hibernate" ) -> false; %% Must be instrumented.
erl_safe("insert_element" ) -> true;
erl_safe("iolist_size" ) -> true;
Expand Down
Loading