aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/src/beam_listing.erl
diff options
context:
space:
mode:
authorLukas Larsson <[email protected]>2017-10-19 14:50:50 +0200
committerLukas Larsson <[email protected]>2017-11-20 10:31:17 +0100
commitd8d07a7593d811a6adad060951bc425ee0d81446 (patch)
tree2c5f861c105089e47ecc28ac70bfc85c5a6365b1 /lib/compiler/src/beam_listing.erl
parent202d62c473e00fd066a70c85ba1d5c26ef2607a1 (diff)
downloadotp-d8d07a7593d811a6adad060951bc425ee0d81446.tar.gz
otp-d8d07a7593d811a6adad060951bc425ee0d81446.tar.bz2
otp-d8d07a7593d811a6adad060951bc425ee0d81446.zip
compiler: Add +to_dis option that dumps loaded asm
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 94b47cf568..836378727b 100644
--- a/lib/compiler/src/beam_listing.erl
+++ b/lib/compiler/src/beam_listing.erl
@@ -24,6 +24,7 @@
-include("core_parse.hrl").
-include("v3_kernel.hrl").
-include("v3_life.hrl").
+-include("beam_disasm.hrl").
-import(lists, [foreach/2]).
@@ -59,6 +60,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).