aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/src/beam_listing.erl
diff options
context:
space:
mode:
authorLukas Larsson <[email protected]>2017-11-20 10:33:30 +0100
committerLukas Larsson <[email protected]>2017-11-20 10:33:30 +0100
commita90b3712dcec20c96eeeecbabc2672ec67c7d89a (patch)
tree1f2e3f8d03324568d62412cbf1872d45b940b205 /lib/compiler/src/beam_listing.erl
parentc08edb85c05f77c0c8c3b99361dfd373d24fccb5 (diff)
parent3b5fced77873fa6ee87a81a6162acf9d9f43c6de (diff)
downloadotp-a90b3712dcec20c96eeeecbabc2672ec67c7d89a.tar.gz
otp-a90b3712dcec20c96eeeecbabc2672ec67c7d89a.tar.bz2
otp-a90b3712dcec20c96eeeecbabc2672ec67c7d89a.zip
Merge branch 'maint'
Conflicts: lib/compiler/src/beam_listing.erl
Diffstat (limited to 'lib/compiler/src/beam_listing.erl')
-rw-r--r--lib/compiler/src/beam_listing.erl14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/compiler/src/beam_listing.erl b/lib/compiler/src/beam_listing.erl
index 9422f9a78a..d1d00017e9 100644
--- a/lib/compiler/src/beam_listing.erl
+++ b/lib/compiler/src/beam_listing.erl
@@ -23,6 +23,7 @@
-include("core_parse.hrl").
-include("v3_kernel.hrl").
+-include("beam_disasm.hrl").
-import(lists, [foreach/2]).
@@ -53,6 +54,19 @@ module(Stream, {Mod,Exp,Attr,Code,NumLabels}) ->
[Name, Arity, Entry]),
io:put_chars(Stream, format_asm(Asm))
end, Code);
+module(Stream, Code) when is_binary(Code) ->
+ #beam_file{ module = Module, compile_info = CInfo } = beam_disasm:file(Code),
+ Loaded = code:is_loaded(Module),
+ Sticky = code:is_sticky(Module),
+ [code:unstick_mod(Module) || Sticky],
+
+ {module, Module} = code:load_binary(Module, proplists:get_value(source, CInfo), Code),
+ ok = erts_debug:df(Stream, Module),
+
+ %% Restore loaded module
+ _ = [{module, Module} = code:load_file(Module) || Loaded =/= false],
+ [code:stick_mod(Module) || Sticky],
+ ok;
module(Stream, [_|_]=Fs) ->
%% Form-based abstract format.
foreach(fun (F) -> io:format(Stream, "~p.\n", [F]) end, Fs).