forked from Ravenbrook/mlworks
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path_break_trace.sml
More file actions
executable file
·400 lines (346 loc) · 12.2 KB
/
_break_trace.sml
File metadata and controls
executable file
·400 lines (346 loc) · 12.2 KB
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
(* The Break and Trace Manager combined top level tool
*
* Copyright 2013 Ravenbrook Limited <http://www.ravenbrook.com/>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Log: _break_trace.sml,v $
* Revision 1.6 1998/03/31 15:14:36 johnh
* [Bug #30346]
* Call Capi.getNextWindowPos.
*
* Revision 1.5 1998/02/13 15:57:44 johnh
* [Bug #30344]
* Allow windows to retain size and position.
*
* Revision 1.4 1998/01/27 16:03:56 johnh
* [Bug #30071]
* Merge in Project Workspace changes.
*
* Revision 1.3.2.2 1997/11/20 17:02:16 johnh
* [Bug #30071]
* Remove Paths menu.
*
* Revision 1.3.2.1 1997/09/11 20:52:07 daveb
* branched from trunk for label MLWorks_workspace_97
*
* Revision 1.3 1997/06/12 15:02:24 johnh
* [Bug #30175]
* Combine tools and windows menu - goodbye windows menu.
*
* Revision 1.2 1997/06/09 14:35:56 johnh
* Automatic checkin:
* changed attribute _comment to ' * '
*
*
*)
require "../basis/__int";
require "capi";
require "menus";
require "tooldata";
require "gui_utils";
require "../main/user_options";
require "../debugger/newtrace";
require "../utils/lists";
require "break_trace";
functor BreakTrace (
structure Capi: CAPI
structure Menus: MENUS
structure Lists: LISTS
structure Trace: TRACE
structure GuiUtils: GUI_UTILS
structure ToolData: TOOL_DATA
structure UserOptions: USER_OPTIONS
sharing type Menus.Widget = Capi.Widget = ToolData.Widget = GuiUtils.Widget
sharing type Menus.ButtonSpec = ToolData.ButtonSpec
sharing type GuiUtils.MotifContext = ToolData.MotifContext
sharing type Menus.ButtonSpec = GuiUtils.ButtonSpec
sharing type GuiUtils.user_context = ToolData.ShellTypes.user_context
): BREAK_TRACE =
struct
type Widget = Capi.Widget
type ButtonSpec = Menus.ButtonSpec
type ToolData = ToolData.ToolData
structure Options = UserOptions.Options
local
val trace_list = ref []
val break_list = ref []
(* stringlist holds the strings, including formatting to show (B) and (T) prefixes,
* which are displayed in the list of break/trace point items.
*)
val stringlist = ref [] : string list ref
fun get_trans_breaks {name:string, hits:int, max:int} = "(B) " ^
name ^ " : (hits " ^ Int.toString hits ^ ", maximum " ^
(if max >= 0 then Int.toString max else "counting")
^ ")"
fun get_trans_traces name = "(T) " ^ name
fun set_stringlist () =
stringlist := (map get_trans_traces (!trace_list)) @
(map get_trans_breaks (!break_list))
fun initialize () =
let
fun initialize' (arg_list, get) =
(arg_list := get();
set_stringlist ())
in
initialize' (trace_list, Trace.traces);
initialize' (break_list, Trace.breakpoints)
end
fun find_space(arg as (s, i)) =
if i >= size s orelse MLWorks.String.ordof arg = ord #" " then
i
else
find_space(s, i+1)
fun ignore_spaces(arg as (s, i)) =
if i >= size s orelse MLWorks.String.ordof arg <> ord #" " then
i
else
ignore_spaces(s, i+1)
fun strip_trailing(s, i) =
if i <= 0 then s
else
if i >= size s orelse MLWorks.String.ordof(s, i) = ord #" " then
strip_trailing(s, i-1)
else
substring (* could raise Substring *)(s, 0, i+1)
(* parse_name removes leading and trailing spaces from the input name
*)
fun parse_name name =
let
val i = ignore_spaces(name, 0)
val size_name = size name
in
if i >= size_name then
"<null>"
else
let
val i' = find_space(name, i)
val n' = substring (name, i, i'-i)
val n = strip_trailing(n', size n')
in
n
end
end
fun parse_b max name =
let
val name = parse_name name
val max = if max < 0 then ~1 else max
in
{name=name, hits=0, max=max}
end
fun parse_t name = parse_name name
fun break_member_fn(_, []) = false
| break_member_fn(arg1 as {name, hits, max},
{name=name', hits=hits', max=max'} :: rest) =
name=name' orelse break_member_fn(arg1, rest)
(* filter functions duplicate break or trace points *)
fun break_filter_fn {name, hits, max} =
let
fun filter{name=name', hits, max} = name <> name'
in
filter
end
fun trace_filter_fn name = (fn s => s <> name)
fun ok_string s = s <> ""
(* Remove either a trace point or a break point from the reference list *)
fun remove_item name (arg_list, set_trans, member_fn, filter_fn) =
if (ok_string name) andalso member_fn(set_trans name, !arg_list) then
arg_list := Lists.filterp (filter_fn (set_trans name)) (!arg_list)
else ()
(* stores the Break/Trace window handle or widget *)
val bt_manager = ref NONE
val sizeRef = ref NONE
val posRef = ref NONE
in
fun create_bt_manager (tooldata as ToolData.TOOLDATA
{args, appdata, current_context, motif_context, tools}) =
let
val ToolData.APPLICATIONDATA {applicationShell,...} = appdata
val parent = applicationShell
val local_context = ref motif_context
(* stores the current selection in the list of break/trace items *)
val selection = ref NONE
fun get_current_user_context () =
GuiUtils.get_user_context (!local_context)
fun mk_tooldata _ = tooldata
val name = "Trace and Breakpoint Manager"
(* Make the widgets *)
val (shell,form,menubar,_) =
Capi.make_main_window {name = name,
title = name,
parent = parent,
contextLabel = false,
winMenu = false,
pos = getOpt (!posRef, Capi.getNextWindowPos())}
val buttonPane =
Capi.make_managed_widget ("listManagerButtonPane", Capi.RowColumn, form, []);
val label = Capi.make_managed_widget ("Trace and Break Points:", Capi.Label, form, []);
val {scroll,list,set_items,...} =
Capi.make_scrolllist
{parent = form,
name = "listManagerList", (* Note that this name is ignored *)
(* the selection is stored as a string excluding the (B) or (T) prefix. *)
select_fn = fn _ => fn s => (selection := SOME (substring (s, 4, size s - 4))),
action_fn = fn _ => fn s => (),
print_fn = fn _ => fn s => s}
fun set_list _ = set_items Options.default_print_options (!stringlist)
fun delete_all _ =
(stringlist := [];
break_list := [];
trace_list := [];
Trace.trace_list [];
Trace.break_list [];
selection := NONE;
set_list ())
(* adds either a trace or break point to the corresponding reference list. *)
fun add_item name (arg_list, set_trans, member_fn, filter_fn) =
if ok_string name then
let
val trans = set_trans name
in
if member_fn(trans, !arg_list) then
arg_list := trans :: Lists.filterp (filter_fn trans) (!arg_list)
else
arg_list := trans :: !arg_list;
set_stringlist ();
set_list ()
end
else ()
(* created and get_dialog_ref are used to show/hide the input dialog for the
* Break/Trace manager. The dialog is only created once.
*)
val created = ref false
val get_dialog_ref = ref (fn () => ())
fun get_dialog () =
let
val isBreakpoint = ref true
val itemName = ref ""
val maxCount = ref 1
(* add_bt_item is the action function for the input dialog *)
fun add_bt_item () =
if (!isBreakpoint) then
(add_item (!itemName) (break_list, parse_b (!maxCount), break_member_fn,break_filter_fn);
Trace.break_list (!break_list))
else
(add_item (!itemName) (trace_list, parse_t, Lists.member, trace_filter_fn);
Trace.trace_list (!trace_list))
fun add_item_dialog parent =
let
open Menus
val _ = created := true
in
create_dialog
(parent,
"Add Break and Trace Points",
"addBreakTraceItems",
add_bt_item,
[OPTRADIO
[OPTTOGGLE ("addBreak", fn _ => true, fn b => (isBreakpoint := b; true)),
OPTTOGGLE ("addTrace", fn _ => false, fn b => (isBreakpoint := (not b); true))],
OPTSEPARATOR,
OPTTEXT ("breakTraceItem", fn _ => (!itemName), fn s => (itemName := s; true)),
OPTINT ("maximumBreaks", fn _ => (!maxCount), fn i => (maxCount := i; true))])
end
in
if (!created) then
(!get_dialog_ref)()
else
(get_dialog_ref := #1 (add_item_dialog shell);
(!get_dialog_ref)())
end
fun reset _ = (initialize (); set_list ())
fun do_delete () =
let
val selected = if isSome (!selection) then valOf (!selection) else ""
fun remove_point point =
if Lists.member (point, !trace_list) then
remove_item point (trace_list, parse_t, Lists.member, trace_filter_fn)
else
remove_item point (break_list, parse_b 0, break_member_fn,break_filter_fn)
val new_stringlist = remove_point selected
in
Trace.break_list (!break_list);
Trace.trace_list (!trace_list);
set_stringlist();
selection := NONE;
set_list ()
end
val {update = other_buttons_update_fn, ...} =
Menus.make_buttons
(buttonPane,
[Menus.PUSH ("breakTraceButton",
get_dialog,
fn _ => true),
Menus.PUSH ("deleteSelectedButton",
do_delete,
fn _ => isSome(!selection)),
Menus.PUSH ("deleteAllButton",
delete_all,
fn _ => true)])
fun storeSizePos () =
(sizeRef := SOME (Capi.widget_size shell);
posRef := SOME (Capi.widget_pos shell))
fun close_window _ =
(Menus.quit ();
bt_manager := NONE;
storeSizePos();
Capi.destroy shell)
val menuspec =
[ToolData.file_menu [("close", close_window, fn _ => true)],
ToolData.edit_menu (shell,
{cut = NONE,
paste = NONE,
copy = NONE,
delete = SOME do_delete,
edit_possible = fn _ => true,
selection_made = fn _ => isSome(!selection),
delete_all = SOME ("deleteAll", delete_all, fn _ => true),
edit_source = []}),
ToolData.tools_menu (mk_tooldata, get_current_user_context),
ToolData.usage_menu
([("addBreakTrace", get_dialog, fn _ => true)],[]),
ToolData.debug_menu []]
in
Menus.make_submenus (menubar,menuspec);
Capi.set_close_callback(shell, close_window);
Capi.Layout.lay_out
(form, !sizeRef,
[Capi.Layout.MENUBAR menubar,
Capi.Layout.FIXED label,
Capi.Layout.FLEX scroll,
Capi.Layout.FIXED buttonPane,
Capi.Layout.SPACE]);
reset ();
shell
end
fun create tooldata =
if isSome(!bt_manager) then
(Capi.initialize_toplevel (valOf (!bt_manager));
Capi.to_front (valOf (!bt_manager)))
else
(bt_manager := SOME (create_bt_manager tooldata);
create tooldata)
end
end