35
36:- module(gui_tracer,
37 [ guitracer/0,
38 noguitracer/0, 39 gtrace/0, 40 gtrace/1, 41 gspy/1, 42 gdebug/0 43 ]). 44:- use_module(library(pce)). 45:- set_prolog_flag(generate_debug_info, false). 46:- meta_predicate
47 gtrace(0),
48 gspy(:).
66guitracer :-
67 current_prolog_flag(gui_tracer, true),
68 !.
69guitracer :-
70 current_prolog_flag(gui_tracer, _),
71 !,
72 set_prolog_flag(gui_tracer, true),
73 visible(+cut_call),
74 print_message(informational, gui_tracer(true)).
75guitracer :-
76 in_pce_thread_sync(
77 load_files([library('trace/trace')],
78 [ silent(true),
79 if(not_loaded)
80 ])),
81 set_prolog_flag(gui_tracer, true),
82 visible(+cut_call),
83 print_message(informational, gui_tracer(true)).
91noguitracer :-
92 current_prolog_flag(gui_tracer, true),
93 !,
94 set_prolog_flag(gui_tracer, false),
95 visible(-cut_call),
96 print_message(informational, gui_tracer(false)).
97noguitracer.
103:- '$hide'(gtrace/0). 104
105gtrace :-
106 guitracer,
107 trace.
114gtrace(Goal) :-
115 guitracer,
116 thread_create(trace_goal(Goal), Id, [detached(true)]),
117 print_message(informational, gui_tracer(in_thread(Id, Goal))).
118
119:- meta_predicate trace_goal(0). 120
121trace_goal(Goal) :-
122 catch(trace_goal_2(Goal), _, true),
123 !.
124trace_goal(_).
125
126trace_goal_2(Goal) :-
127 setup_call_catcher_cleanup(
128 trace,
129 Goal,
130 Catcher,
131 finished(Catcher, Det)),
132 notrace,
133 ( Det == true
134 -> true
135 ; in_pce_thread_sync(send(@(display), confirm, 'Retry goal?'))
136 -> trace, fail
137 ; !
138 ).
139
140:- '$hide'(finished/2). 141
142finished(Reason, Det) :-
143 notrace,
144 print_message(informational, gui_tracer(completed(Reason))),
145 ( Reason == exit
146 -> Det = true
147 ; Det = false
148 ).
154gspy(Predicate) :-
155 guitracer,
156 spy(Predicate).
162gdebug :-
163 guitracer,
164 debug.
165
166
167 170
171:- multifile
172 prolog:message/3. 173
174prolog:message(gui_tracer(true)) -->
175 [ 'The graphical front-end will be used for subsequent tracing' ].
176prolog:message(gui_tracer(false)) -->
177 [ 'Subsequent tracing uses the commandline tracer' ].
178prolog:message(gui_tracer(in_thread(Id, _Goal))) -->
179 [ 'Debugging goal in new thread ~q'-[Id] ].
180prolog:message(gui_tracer(completed(Reason))) -->
181 [ 'Goal completed: ~q~n'-[Reason] ]
Graphical debugger utilities
This module provides utilities that use the graphical debugger rather than the conventional 4-port commandline debugger. This library is part of XPCE.