File: event_dbg.lgt

package info (click to toggle)
yap 5.1.1-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 16,124 kB
  • ctags: 14,650
  • sloc: ansic: 122,796; perl: 22,545; sh: 3,768; java: 1,277; makefile: 1,191; xml: 739; tcl: 624; lisp: 142; awk: 9
file content (181 lines) | stat: -rw-r--r-- 3,804 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181

:- object(event_dbg,
	implements(event_dbgp, event_handlersp),
	imports(monitor)).


	:- info([
		version is 1.0,
		date is 2000/7/24,
		author is 'Paulo Moura',
		comment is 'Debugging facilities similar to those found in most Prolog compilers.']).


	:- initialization(::init).


	:- protected(port_output/4).

	:- mode(port_output(+atom, +object, @callable, +object), one).

	:- info(port_output/4, [
		comment is 'Outputs current port information.',
		argnames is ['Port', 'Object', 'Message', 'Sender']]).


	:- protected(execute_option/1).

	:- mode(execute_option(+atom), one).

	:- info(execute_option/1, [
		comment is 'Executes a user option at a debugger port.',
		argnames is ['Option']]).


	:- protected(query_user/1).

	:- mode(query_user(-atom), one).

	:- info(query_user/1, [
		comment is 'Query a user about an option at a debugger port.',
		argnames is ['Option']]).


	:- private(stream_/2).
	:- dynamic(stream_/2).

	:- mode(stream_(?atom, ?stream), zero_or_more).

	:- info(stream/2, [
		comment is 'Stores the current debugger input and ouput streams.',
		argnames is ['Kind', 'Stream']]).


	stream(Name, Stream) :-
		::stream_(Name, Stream).


	set_stream(Name, Stream) :-
		::retractall(stream_(Name, _)),
		::assertz(stream_(Name, Stream)).


	trace :-
		self(Self),
		abolish_events(before, _, _, _, Self),
		abolish_events(after, _, _, _, Self),
		define_events(before, _, _, _, Self),
		define_events(after, _, _, _, Self).


	notrace :-
		self(Self),
		abolish_events(before, _, _, _, Self),
		abolish_events(after, _, _, _, Self).


	debugging :-
		::monitor_activated.


	debug :-
		::activate_monitor.


	nodebug :-
		::suspend_monitor.


	port_output(Port, Object, Message, Sender) :-
		::stream(output, Output),
		write(Output, Port),
		write(Output, ':     '),
		writeq(Output, Object),
		write(Output, ' <- '),
		writeq(Output, Message),
		write(Output, ' from '),
		writeq(Output, Sender),
		nl(Output).


	query_user(Option) :-
		::stream(output, Output),
		::stream(input, Input),
		repeat,
			write(Output, '    >> '),
			read(Input, Option),
			nl(Output),
			(valid_option(Option) ->
				true
				;
				::execute_option(h), fail),
		!.


	execute_option(c).

	execute_option(f) :-
		!, fail.

	execute_option(n) :-
		::nodebug.

	execute_option(b) :-
		::stream(output,Output),
		::stream(input, Input),
		repeat,
			write(Output, '     :- '),
			read(Input, Goal),
			writeq(Output, Goal),
			nl(Output),
			(once(Goal) ->
				write(Output, '     answer: '),
				writeq(Output, Goal), nl(Output)
				;
				write(Output, '     no'), nl(Output)),
		Goal = true,
		!.

	execute_option(a) :-
		throw(error(logtalk_execution_aborted)).

	execute_option(h) :-
		::stream(output, Output),
		write(Output, '     Available options are:'), nl(Output),
		write(Output, '       c - creep (go on)'), nl(Output),
		write(Output, '       f - fail (force failure or backtracking)'), nl(Output),
		write(Output, '       n - nodebug (turn off debug)'), nl(Output),
		write(Output, '       b - break (submit queries to the interpreter, type true to terminate)'), nl(Output),
		write(Output, '       a - abort (return to top level interpreter)'), nl(Output),
		write(Output, '       h - help (prints this list of options)'), nl(Output),
		nl(Output).


	valid_option(c).
	valid_option(f).
	valid_option(n).
	valid_option(b).
	valid_option(a).


	before(Object, Message, Sender) :-
		::port_output(call, Object, Message, Sender),
		::query_user(Option),
		::execute_option(Option).


	after(Object, Message, Sender) :-
		::port_output(exit, Object, Message, Sender),
		::query_user(Option),
		::execute_option(Option).


	init :-
		::reset_monitor,
		current_input(Input),
		::set_stream(input, Input),
		current_output(Output),
		::set_stream(output, Output).


:- end_object.