-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeathers.tcl
1925 lines (1506 loc) · 48.8 KB
/
feathers.tcl
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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env wish
#
# a graphical debugger for compiled CHICKEN programs
#
# Copyright (c) 2015-2021, The CHICKEN Team
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
# conditions are met:
#
# Redistributions of source code must retain the above copyright notice, this list of conditions and the following
# disclaimer.
# 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.
# Neither the name of the author nor the names of its contributors may be used to endorse or promote
# products derived from this software without specific prior written permission.
#
# 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 HOLDERS 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.
set version 0
set protocol_version 1
set debugger_port 9999
set events(1) call
set events(2) assign
set events(3) gc
set events(4) entry
set events(5) signal
set events(6) connect
set events(7) listen
set events(8) interrupted
set reply(SETMASK) 1
set reply(TERMINATE) 2
set reply(CONTINUE) 3
set reply(SET_BREAKPOINT) 4
set reply(CLEAR_BREAKPOINT) 5
set reply(LIST_EVENTS) 6
set reply(GET_BYTES) 7
set reply(GET_AV) 8
set reply(GET_SLOTS) 9
set reply(GET_GLOBAL) 10
set reply(GET_STATS) 11
set reply(GET_TRACE) 12
set colors(header_foreground) white
set colors(header_background) black
set colors(text_foreground) black
set colors(text_background) gray90
set colors(event_foreground) black
set colors(event_background) white
set colors(breakpoint_foreground) white
set colors(breakpoint_background) DarkRed
set colors(highlight_foreground) white
set colors(highlight_background) CornflowerBlue
set colors(mark_foreground) black
set colors(mark_background) yellow
set colors(trace_background) gray90
set colors(trace_foreground) black
set typecode(0) VECTOR
set typecode(1) SYMBOL
set typecode(66) STRING
set typecode(3) PAIR
set typecode(36) CLOSURE
set typecode(85) FLONUM
set typecode(39) PORT
set typecode(8) STRUCTURE
set typecode(41) POINTER
set typecode(42) LOCATIVE
set typecode(43) TAGGED_POINTER
set typecode(77) LAMBDA_INFO
set typecode(15) BUCKET
set EXEC_EVENT_MASK 32; # signal
set STEP_EVENT_MASK 54; # call, entry, assign, signal
set membar_height 50
set value_cutoff_limit 200; # must be lower than limit in dbg-stub.c
set the_name "feathers"
set header_text "$the_name - (c)MMXV The CHICKEN Team - Version $version"
set startup_file ".$the_name"
set client_addr ""
set client_file ""
set current_filename ""
set current_c_filename ""
set file_list {}
set bp_queue {}
set watched_queue {}
set value_queue {}
set current_line ""
set current_c_line ""
set current_bp_lines {}
set current_bp_globals {}
set font_name "Courier"
set font_size 12
set program_name ""
set search_path {"."}
set data_view ""
set c_view ""
set data_queue {}
set reply_queue {}
set starting_up 1
set stepping 0
set terminated 0
set arguments_item_id ""
set watched_variables {}
set current_variable ""
set current_value ""
set listening 0
set process_id 0
set statistics_data ""
set mark_start_index(.t) ""
set mark_start_index(.code.t) ""
set current_c_location ""
set last_marked_widget .t
set selected_filename ""
set trace_data ""
set last_location ""
set logging 0
set env(CHICKEN_DEBUGGER) "localhost:9999"
proc Log {msg} {
global logging
if {$logging} {puts stderr $msg}
}
proc SetupGUI {} {
global font_name font_size colors the_name selected_filename
label .h -height 1 -textvariable header_text -anchor w
scrollbar .s -command {.t yview}
text .t -wrap char -yscrollcommand {.s set} -cursor arrow -state disabled \
-font [list $font_name $font_size]
frame .f
ttk::combobox .files -postcommand FilesList -textvariable selected_filename
pack .h -side top -fill x
pack .files -side top -fill x
pack .f -side bottom -fill x
pack .s -fill y -side right
pack .t -fill both -expand 1
for {set i 1} {$i <= 10} {incr i} {
button .f.b$i -text "F$i" -font {Helvetica 10} -borderwidth 0 -relief flat \
-pady 0
pack .f.b$i -side left -expand 1 -fill x
}
.f.b1 configure -text "F1 Run"
.f.b2 configure -text "F2 Where"
.f.b3 configure -text "F3 AddDir"
.f.b4 configure -text "F4 Data"
.f.b5 configure -text "F5 Continue"
.f.b6 configure -text "F6 Step"
.f.b7 configure -text "F7 Find Prev"
.f.b8 configure -text "F8 Find Next"
.f.b9 configure -text "F9 C"
.f.b10 configure -text "F10 Exit"
.h configure -background $colors(header_background) \
-foreground $colors(header_foreground) -font {Helvetica 12} \
-borderwidth 0
.t configure -background $colors(text_background) \
-foreground $colors(text_foreground) \
-insertbackground $colors(text_foreground) -borderwidth 0
.t tag configure ev -background $colors(event_background) \
-foreground $colors(event_foreground)
.t tag configure bp -background $colors(breakpoint_background) \
-foreground $colors(breakpoint_foreground)
.t tag configure hl -background $colors(highlight_background) \
-foreground $colors(highlight_foreground)
.t tag configure mk -background $colors(mark_background) \
-foreground $colors(mark_foreground)
.t tag lower mk sel
.t tag lower bp mk
.t tag lower hl bp
.t tag lower ev hl
focus .t
wm title . $the_name
}
proc SetupBindings {} {
for {set i 1} {$i <= 10} {incr i} {
bind . <F$i> [list .f.b$i invoke]
}
.f.b1 configure -command RunProcess
.f.b2 configure -command LocateFocus
.f.b3 configure -command AddDirectory
.f.b4 configure -command ShowData
.f.b5 configure -command ContinueExecution
.f.b6 configure -command StepExecution
.f.b7 configure -command FindPrevious
.f.b8 configure -command FindNext
.f.b9 configure -command OpenCView
.f.b10 configure -command Terminate
bind .t <ButtonPress-1> { focus .t; ToggleBreakpoint %y; break }
bind .t <ButtonRelease-1> break
bind .t <space> {StepExecution; break}
bind .t <Return> {ToggleBreakpoint; break}
bind .t <Up> {MoveFocus -1; break}
bind .t <Down> {MoveFocus 1; break}
bind .t <plus> {ResizeFont 1; break}
bind .t <minus> {ResizeFont -1; break}
bind .t <Escape> {Interrupt}
bind .t <ButtonPress-3> {StartMark %W %x %y; break}
bind .t <Motion> {MoveMark %W %x %y; break}
bind .t <ButtonRelease-3> {EndMark %W; break}
bind .files <<ComboboxSelected>> {SelectFile; focus .t}
wm protocol . WM_DELETE_WINDOW Terminate
}
proc SetupDataView {} {
global colors arguments_item_id stats membar_height the_name font_name font_size
toplevel .data
ttk::treeview .data.t -yscrollcommand {.data.s set} -columns {Values Addresses} \
-selectmode browse
.data.t heading 0 -text Value
.data.t heading 1 -text Address
scrollbar .data.s -command {.data.t yview}
entry .data.e
canvas .data.c -height $membar_height
frame .data.f
text .data.f.tr -state disabled -yscrollcommand {.data.f.trs set} -height 20 \
-font [list $font_name $font_size] -foreground $colors(trace_foreground) \
-background $colors(trace_background)
scrollbar .data.f.trs -command {.data.f.tr yview}
pack .data.f -side bottom -fill x
pack .data.c -side bottom -fill x
pack .data.e -side bottom -fill x
pack .data.s -fill y -side right
pack .data.t -fill both -expand 1
pack .data.f.trs -fill y -side right
pack .data.f.tr -side bottom -fill both -expand 1
.data.t tag configure watched -foreground $colors(breakpoint_foreground) \
-background $colors(breakpoint_background)
set arguments_item_id [.data.t insert {} end -text "<arguments>"]
set stats(fromspace_used) [.data.c create rectangle 0 0 0 0 -fill gray80]
set stats(fromspace_unused) [.data.c create rectangle 0 0 0 0 -fill gray40]
set stats(scratchspace_used) [.data.c create rectangle 0 0 0 0 -fill gray80]
set stats(scratchspace_unused) [.data.c create rectangle 0 0 0 0 -fill gray40]
set stats(nursery_used) [.data.c create rectangle 0 0 0 0 -fill gray80]
set stats(nursery_unused) [.data.c create rectangle 0 0 0 0 -fill gray40]
set mh [expr $membar_height / 3]
set stats(fromspace_name) [.data.c create text 10 0 -anchor nw -text "heap"]
set stats(scratchspace_name) [.data.c create text 10 $mh -anchor nw -text \
"scratch"]
set stats(nursery_name) [.data.c create text 10 [expr $mh * 2] -anchor nw \
-text "nursery"]
set stats(fromspace_percentage) [.data.c create text 0 0 -anchor center]
set stats(scratchspace_percentage) [.data.c create text 0 0 -anchor center]
set stats(nursery_percentage) [.data.c create text 0 0 -anchor center]
set stats(fromspace_size) [.data.c create text 0 0 -anchor ne]
set stats(scratchspace_size) [.data.c create text 0 0 -anchor ne]
set stats(nursery_size) [.data.c create text 0 0 -anchor ne]
wm title .data "$the_name - data view"
}
proc SetupDataViewBindings {} {
bind .data <F3> AddDirectory
bind .data <F4> ShowData
bind .data <F5> ContinueExecution
bind .data <F6> StepExecution
bind .data <F10> Terminate
bind .data.e <Return> {WatchGlobal; break}
bind .data.t <BackSpace> {RemoveGlobal; break}
bind .data.t <Delete> {RemoveGlobal; break}
bind .data.t <<TreeviewOpen>> OpenDataItem
bind .data.t <Return> {ToggleVariableWatch; break}
bind .data.t <Double-Button-1> {ToggleVariableWatch %x %y; break}
bind .data.t <<TreeviewSelect>> {Log [.data.t focus]; break}
bind .data.c <Configure> {RedrawStatistics}
wm protocol .data WM_DELETE_WINDOW CloseDataView
}
proc SetupCView {} {
global font_name font_size colors the_name
toplevel .code
label .code.h -height 1 -text "" -anchor w
scrollbar .code.s -command {.code.t yview}
text .code.t -wrap char -yscrollcommand {.code.s set} -cursor arrow -state \
disabled -font [list $font_name $font_size]
frame .code.f
pack .code.h -side top -fill x
pack .code.s -fill y -side right
pack .code.f -fill x -side bottom
pack .code.t -fill both -expand 1
.code.h configure -background $colors(header_background) \
-foreground $colors(header_foreground) -font {Helvetica 12} \
-borderwidth 0
.code.t configure -background $colors(text_background) \
-foreground $colors(text_foreground) \
-insertbackground $colors(text_foreground) -borderwidth 0
.code.t tag configure hl -background $colors(highlight_background) \
-foreground $colors(highlight_foreground)
.code.t tag configure mk -background $colors(mark_background) \
-foreground $colors(mark_foreground)
.code.t tag lower mk sel
.code.t tag lower hl mk
wm title .code "$the_name - code view"
focus .code.t
}
proc SetupCViewBindings {} {
bind .code <F3> AddDirectory
bind .code <F4> ShowData
bind .code <F5> ContinueExecution
bind .code <F6> StepExecution
bind .code <F7> {FindPrevious .code.t}
bind .code <F8> {FindNext .code.t}
bind .code <F10> Terminate
bind .code.t <ButtonPress-1> {focus .code.t}
bind .code.t <ButtonRelease-1> break
bind .code <plus> {ResizeFont 1; break}
bind .code <minus> {ResizeFont -1; break}
bind .code.t <ButtonPress-3> {StartMark %W %x %y; break}
bind .code.t <Motion> {MoveMark %W %x %y; break}
bind .code.t <ButtonRelease-3> {EndMark %W; break}
wm protocol .code WM_DELETE_WINDOW CloseCView
}
proc FilesList {} {
global file_list
.files configure -values $file_list
}
proc CloseDataView {} {
global data_view
if {$data_view != ""} {
set data_view ""
destroy .data
}
}
proc CloseCView {} {
global c_view
if {$c_view != ""} {
set c_view ""
destroy .code
}
}
proc ShowData {} {
global data_view starting_up client_file program_name the_name
if {$data_view == ""} {
SetupDataView
SetupDataViewBindings
set data_view .data
wm title .data "$the_name - $program_name - data view"
if {!$starting_up && $client_file != ""} UpdateData
}
}
proc OpenCView {} {
global c_view starting_up current_c_location the_name program_name
if {$c_view == ""} {
SetupCView
SetupCViewBindings
set c_view .code
wm title .code "$the_name - $program_name - code view"
Log "$current_c_location"
if {$current_c_location != ""} {
LocateCSource $current_c_location
}
}
}
proc AddDirectory {} {
global search_path current_filename
set dir "."
if {$current_filename != ""} {
set dir [file dirname $current_filename]
}
set dir [tk_chooseDirectory -title "Select directory to add to search path" \
-initialdir $dir]
if {$dir != ""} {
lappend search_path $dir
}
}
proc ResizeFont {n} {
global font_size font_name c_view
incr font_size $n
.t configure -font [list $font_name $font_size]
if {$c_view != ""} {
.code.t configure -font [list $font_name $font_size]
}
}
proc Flash {{color red}} {
global colors
.t configure -background $color
update
after 100 {.t configure -background $colors(text_background)}
}
proc CheckListening {} {
global listening
if {!$listening} {
Flash
return 0
}
return 1
}
proc MoveFocus {amount} {
global current_line
set ln [expr $current_line + $amount]
SetFocus $ln
}
proc LocateFocus {} {
global last_location
if {$last_location != ""} {
SetFocus $last_location
}
}
proc SetFocus {line} {
global current_line
if {$line > 0 && $line <= [.t count -lines 1.0 end]} {
set old [.t tag ranges hl]
if {$old != ""} {
eval .t tag remove hl $old
}
set current_line $line
.t tag add hl $line.0 "$line.0 lineend + 1 chars"
.t see $line.0
}
}
proc SetCFocus {line} {
global current_c_line
if {$line > 0 && $line <= [.code.t count -lines 1.0 end]} {
set old [.code.t tag ranges hl]
if {$old != ""} {
eval .code.t tag remove hl $old
}
set current_c_line $line
.code.t tag add hl $line.0 "$line.0 lineend + 1 chars"
.code.t see $line.0
}
}
proc Interrupt {} {
global process_id listening
if {$listening || $process_id == 0} return
catch {exec kill -USR2 $process_id}
}
proc ToggleBreakpoint {{y ""}} {
global current_filename bp_queue current_bp_lines
global current_line client_file reply_queue
if {$client_file == ""} return
if {$y != ""} {
if {[catch {set p [.t index @1,$y]}]} return
if {![regexp {^(\d+)\.} $p _ line]} return
} else {
set line $current_line
}
set aname "file:$current_filename"
global $aname
set aref "$aname\($line\)"
if {![CheckListening]} return
if {[info exists $aref]} {
set bps [set $aref]
if {$bps != ""} {
set bp1 [lindex $bps 0]
set bprest [lrange $bps 1 end]
set bp_queue [concat $bp_queue $bprest]
if {[lsearch -exact $current_bp_lines $line] != -1} {
UnmarkBP $line
SendReply CLEAR_BREAKPOINT $bp1
lappend reply_queue RemoveBPReply
} else {
MarkBP $line
SendReply SET_BREAKPOINT $bp1
lappend reply_queue AddBPReply
}
}
}
}
proc ToggleVariableWatch {{x ""} {y ""}} {
global globals current_bp_globals bp_queue
if {![CheckListening]} return
if {$x == ""} {
set item [.data.t focus]
} else {
if {[catch {.data.t identify item $x $y} item]} return
}
if {$item == ""} return
if {[.data.t parent $item] != ""} return
set name [.data.t item $item -text]
if {$name == "<arguments>"} return
if {![info exists globals($name)]} return
Log "globals: $name -> $globals($name)"
set bps $globals($name)
if {$bps != ""} {
set bp1 [lindex $bps 0]
set bprest [lrange $bps 1 end]
set bp_queue [concat $bp_queue $bprest]
if {[lsearch -exact $current_bp_globals $item] != -1} {
UnmarkWatchedVariable $item
SendReply CLEAR_BREAKPOINT $bp1
lappend reply_queue RemoveBPReply
} else {
MarkWatchedVariable $item
SendReply SET_BREAKPOINT $bp1
lappend reply_queue AddBPReply
}
}
}
proc AddBPReply {} {
global bp_queue reply_queue
if {$bp_queue != ""} {
set bp1 [lindex $bp_queue 0]
set bp_queue [lrange $bp_queue 1 end]
SendReply SET_BREAKPOINT $bp1
if {$bp_queue != ""} {
lappend reply_queue AddBPReply
}
}
}
proc RemoveBPReply {} {
global bp_queue reply_queue
if {$bp_queue != ""} {
set bp1 [lindex $bp_queue 0]
set bp_queue [lrange $bp_queue 1 end]
SendReply CLEAR_BREAKPOINT $bp1
if {$bp_queue != ""} {
lappend reply_queue RemoveBPReply
}
}
}
proc MarkBP {line} {
global current_bp_lines
if {[lsearch -exact $current_bp_lines $line] == -1} {
.t tag add bp $line.0 "$line.0 lineend"
lappend current_bp_lines $line
}
}
proc UnmarkBP {line} {
global current_bp_lines
set i [lsearch -exact $current_bp_lines $line]
if {$i != -1} {
set current_bp_lines [lreplace $current_bp_lines $i $i]
.t tag remove bp $line.0 "$line.0 lineend"
}
}
proc MarkWatchedVariable {item} {
global current_bp_globals
if {[lsearch -exact $current_bp_globals $item] == -1} {
.data.t tag add watched $item
lappend current_bp_globals $item
}
}
proc UnmarkWatchedVariable {item} {
global current_bp_globals
set i [lsearch -exact $current_bp_globals $item]
if {$i != -1} {
set current_bp_globals [lreplace $current_bp_globals $i $i]
.data.t tag remove watched $item
}
}
proc Terminate {} {
global client_file process_id
if {$client_file != ""} {
SendReply TERMINATE
set f $client_file
set client_file ""
close $f
catch {exec kill -9 $process_id}
}
exit
}
proc RunProcess {{prg ""}} {
global env client_file program_name search_path reply_queue current_filename
global data_queue bp_queue starting_up stepping terminated current_bp_lines
global terminated watched_variables watched_queue listening file_list
global value_queue process_id current_bp_globals data_view statistics_data
global arguments_item_id trace_data last_location
if {$client_file != ""} {
if {!$terminated} {SendReply TERMINATE}
set f $client_file
set client_file ""
close $f
}
set program_name $prg
if {$program_name == ""} {
set program_name [tk_getOpenFile -title "Select executable"]
}
if {$program_name == ""} return
set args [lassign $program_name prgfname]
set prgfname [file normalize $prgfname]
if {![file exists $prgfname]} {
.t configure -state normal
.t insert end "Could not start program:\n\nfile `$prgfname' does not exist"
.t see end
.t configure -state disabled
}
lappend search_path [file dirname $prgfname]
set reply_queue {}
set data_queue {}
set bp_queue {}
set watched_queue {}
set value_queue {}
set last_location ""
set starting_up 1
set stepping 0
set terminated 0
set current_bp_lines {}
set current_bp_globals {}
set current_filename ""
set watched_variables {}
set listening 0
set process_id 0
set statistics_data ""
set file_list {}
set trace_data ""
.t configure -state normal
.t delete 1.0 end
.t configure -state disabled
if {$data_view != ""} {
.data.t delete [lrange [.data.t children {}] 1 end]
.data.t delete [.data.t children $arguments_item_id]
}
if {[catch {eval exec $prgfname {*}$args <@ stdin >@ stdout 2>@ stderr &} result]} {
.t configure -state normal
.t insert end "Could not start program:\n\n$result"
.t see end
.t configure -state disabled
} else {
set process_id $result
}
}
proc UpdateHeader {{msg ""}} {
global header_text current_filename client_addr current_line
set header_text $client_addr
if {$current_filename != ""} {
set header_text $current_filename
if {$current_line != ""} {
append header_text ":$current_line"
}
}
if {$msg != ""} {
append header_text " - $msg"
}
}
proc ProcessInput {} {
global client_file terminated
gets $client_file line
if {[eof $client_file]} {
close $client_file
set client_file ""
set terminated 1
UpdateHeader "connection closed"
} elseif {![fblocked $client_file]} {
Log "Input: $line"
ProcessLine $line
}
}
proc ProcessLine {line} {
if {[regexp {^\((\d+)\s+([^\s]*)\s+([^\s]*)\s+([^)]*)\)$} $line _ evt loc val cloc]} {
set val [ProcessString $val]
set loc [ProcessString $loc]
set cloc [ProcessString $cloc]
ProcessEvent $evt $loc $val $cloc
} elseif {[regexp {^\(\*\s*(.*)\)$} $line _ data]} {
ProcessData $data
} else {
UpdateHeader "invalid input: [string range $line 0 40]..."
}
}
proc ProcessEvent {evt loc val cloc} {
global events reply_queue starting_up EXEC_EVENT_MASK data_queue c_view
global STEP_EVENT_MASK stepping data_view listening value_queue statistics_data
global current_c_location protocol_version the_name program_name trace_data
set listening 1
if {[info exists events($evt)]} {
set eventname $events($evt)
} else {
UpdateHeader "unrecognized event: $evt"
return
}
if {$data_queue != ""} {
set data_queue [lrange $data_queue 1 end]
}
Log "evt: $eventname, dq: $data_queue, rq: $reply_queue, vq: $value_queue"
if {$eventname != "listen"} {
set statistics_data ""
set trace_data ""
}
set current_c_location $cloc
if {$c_view != ""} {
LocateCSource $cloc
}
switch $eventname {
connect {
if {![regexp {^([^:]+):([^:]+):(\d+)$} $loc _ name pid pv]} {
UpdateHeader "invalid connection info: $loc"
return
}
if {$pv > $protocol_version} {
UpdateHeader "client protocol doesn't match: $pv"
return
}
wm title . "$the_name - $program_name"
Log "\n##################### CONNECT ##################"
SendReply SETMASK $STEP_EVENT_MASK
set stepping 1
lappend reply_queue FetchEventListReply FirstStepReply
}
listen {
if {$reply_queue != ""} {
set action [lindex $reply_queue 0]
set reply_queue [lrange $reply_queue 1 end]
Log "action: $action"
$action
} elseif {$val == 1} {
# new dbg-info was registered
lappend reply_queue ApplyTags
FetchEventListReply
}
}
default {
# call/entry/assign/signal/gc
LocateEvent $loc $val
UpdateHeader "\[$eventname\]"
if {$starting_up} {
SendReply SETMASK $EXEC_EVENT_MASK
set starting_up 0
} elseif {$data_view != ""} UpdateData
}
}
}
proc UpdateData {} {
global data_queue reply_queue watched_variables
global watched_queue
set watched_queue $watched_variables
lappend reply_queue GetGlobals
lappend data_queue GetAVData
SendReply GET_AV
}
proc GetAVData {data} {
global arguments_item_id value_queue
set vals [ParseValueList $data]
set cs [.data.t children $arguments_item_id]
set len [llength $vals]
set clen [llength $cs]
for {set i 0} {$i < $len} {incr i} {
lassign [ValueData [lindex $vals $i]] type text addr
if {$i >= $clen} {
set c [.data.t insert $arguments_item_id end -text $type -values \
[list $text $addr]]
} else {
set c [lindex $cs $i]
.data.t item $c -text $type -values [list $text $addr]
}
if {$addr != ""} {
lappend value_queue $c
}
incr i
}
if {$i < $clen} {
.data.t delete [lrange $cs $i end]
}
.data.t item $arguments_item_id -open 1
}
proc GetGlobals {} {
global data_queue reply_queue watched_queue current_variable
global data_view value_queue
if {$watched_queue != ""} {
set current_variable [lindex $watched_queue 0]
set watched_queue [lrange $watched_queue 1 end]
lappend data_queue GetGlobalData
set name [MangleSymbol [.data.t item $current_variable -text]]
SendReply GET_GLOBAL "\"$name\""
lappend reply_queue GetGlobals
} elseif {$data_view != ""} {
if {$value_queue != ""} {
GetValues
} else {
GetStatistics
}
}
}
proc GetValues {} {
global data_view value_queue current_value data_queue reply_queue
if {$data_view != ""} {
if {$value_queue != ""} {
set current_value [lindex $value_queue 0]
Log "get value: $current_value"
set value_queue [lrange $value_queue 1 end]
lappend data_queue GetValueData
scan [.data.t set $current_value 1] %x addr
SendReply GET_SLOTS $addr
lappend reply_queue GetValues
} else {
UpdateValueText {}
GetTrace
}
}
}
proc GetTrace {} {
global data_queue trace_data reply_queue
if {$trace_data == ""} {
lappend reply_queue GetStatistics
lappend data_queue GetTraceData
SendReply GET_TRACE
} else GetStatistics
}
proc GetTraceData {data} {
global trace_data
if {![regexp {^"([^"]*)"$} $data _ str]} {
append trace_data "<invalid trace data>\n"
} else {
append trace_data "$str\n"
}
}
proc RedrawTrace {} {
global trace_data
.data.f.tr configure -state normal
.data.f.tr delete 1.0 end
.data.f.tr insert 1.0 $trace_data
.data.f.tr configure -state disabled
}
proc GetStatistics {} {
global data_queue statistics_data reply_queue trace_data
if {$trace_data != ""} RedrawTrace
if {$statistics_data == ""} {
lappend data_queue GetStatisticsData
SendReply GET_STATS
}
}