aboutsummaryrefslogtreecommitdiffstats
path: root/lib/debugger/src
diff options
context:
space:
mode:
authorJosé Valim <[email protected]>2016-02-22 22:16:53 +0100
committerJosé Valim <[email protected]>2016-02-23 08:37:40 +0100
commitc7e82c6b406b632a191c791a1bd2162bde08f692 (patch)
tree699ff115ae3892e483d3a941edf17fe0b69616fa /lib/debugger/src
parente038cbe699acc19901e10b9569a3b783e900582d (diff)
downloadotp-c7e82c6b406b632a191c791a1bd2162bde08f692.tar.gz
otp-c7e82c6b406b632a191c791a1bd2162bde08f692.tar.bz2
otp-c7e82c6b406b632a191c791a1bd2162bde08f692.zip
Use compile source info in debugger
Prior to this commit, the debugger relied on a simple heuristic that traverses directory from the beam file to find a source file. The heuristic was maintained with this patch but, if it fails, it fallbacks to the source value in the module compile info. In order to illustrate how it works, one of the tests that could not find its source now passes successfully (showing the source lookup is more robust).
Diffstat (limited to 'lib/debugger/src')
-rw-r--r--lib/debugger/src/int.erl18
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/debugger/src/int.erl b/lib/debugger/src/int.erl
index 4f54beb45b..1e43d1858a 100644
--- a/lib/debugger/src/int.erl
+++ b/lib/debugger/src/int.erl
@@ -547,7 +547,7 @@ load({Mod, Src, Beam, BeamBin, Exp, Abst}, Dist) ->
check_module(Mod) ->
case code:which(Mod) of
Beam when is_list(Beam) ->
- case find_src(Beam) of
+ case find_src(Mod, Beam) of
Src when is_list(Src) ->
check_application(Src),
case check_beam(Beam) of
@@ -608,7 +608,7 @@ check_application2("gs-"++_) -> throw({error,{app,gs}});
check_application2("debugger-"++_) -> throw({error,{app,debugger}});
check_application2(_) -> ok.
-find_src(Beam) ->
+find_src(Mod, Beam) ->
Src0 = filename:rootname(Beam) ++ ".erl",
case is_file(Src0) of
true -> Src0;
@@ -618,10 +618,22 @@ find_src(Beam) ->
filename:basename(Src0)]),
case is_file(Src) of
true -> Src;
- false -> error
+ false -> find_src_from_module(Mod)
end
end.
+find_src_from_module(Mod) ->
+ Compile = Mod:module_info(compile),
+ case lists:keyfind(source, 1, Compile) of
+ {source, Src} ->
+ case is_file(Src) of
+ true -> Src;
+ false -> error
+ end;
+ false ->
+ error
+ end.
+
find_beam(Mod, Src) ->
SrcDir = filename:dirname(Src),
BeamFile = atom_to_list(Mod) ++ code:objfile_extension(),