Just use set_debug_mode(File) <before> loading the file (or other file which recursively loads it) -- of course using Ciao inside emacs simplify all this.
clip(20:55:04):/home/bardo/tmp
ciaosh
{Including /home/bardo/.ciaorc } Ciao-Prolog 1.7 #21: Tue Sep 26 14:25:48 CEST 2000 ?- set_debug_mode(sga).
yes ?- ensure_loaded(sga).
yes ?- debug_module(user). {Modules selected for debugging: [user]} {No module is selected for source debugging}
yes ?- trace. {The debugger will first creep -- showing everything (trace)}
yes {trace} ?- findterm([1,2,3,4,5,6,7,8,9],0,N). 1 1 Call: user:findterm([1,2,3,4,5,6,7,8,9],0,_340) ? 2 2 Call: _540 is 0+1 ? 2 2 Exit: 1 is 0+1 ? 3 2 Call: user:test(1) ? 3 2 Exit: user:test(1) ? 4 2 Call: user:findterm([2,3,4,5,6,7,8,9],1,_340) ? 5 3 Call: _986 is 1+2 ? 5 3 Exit: 3 is 1+2 ? 6 3 Call: user:test(3) ? 6 3 Exit: user:test(3) ? 7 3 Call: user:findterm([3,4,5,6,7,8,9],3,_340) ? 8 4 Call: _1431 is 3+3 ? 8 4 Exit: 6 is 3+3 ? 9 4 Call: user:test(6) ? 9 4 Exit: user:test(6) ? 10 4 Call: user:findterm([4,5,6,7,8,9],6,_340) ? 11 5 Call: _1875 is 6+4 ? 11 5 Exit: 10 is 6+4 ? 12 5 Call: user:test(10) ? n
N = 9 ?
yes {trace} ?-