* gdbtk.c (gdbtk_init): Improve handling for errors in gdbtk.tcl
[deliverable/binutils-gdb.git] / gdb / gdbtk.tcl
CommitLineData
754e5da2
SG
1# GDB GUI setup
2
3set cfile Blank
006e71e9 4set wins($cfile) .src.text
754e5da2
SG
5set current_label {}
6set screen_height 0
7set screen_top 0
8set screen_bot 0
006e71e9 9set current_output_win .cmd.text
8532893d 10set cfunc NIL
86db943c 11set line_numbers 1
546b8ca7 12set breakpoint_file(-1) {[garbage]}
86db943c 13
006e71e9
SG
14#option add *Foreground Black
15#option add *Background White
16#option add *Font -*-*-medium-r-normal--18-*-*-*-m-*-*-1
746d1df4 17tk colormodel . monochrome
754e5da2
SG
18
19proc echo string {puts stdout $string}
20
8532893d
SG
21if [info exists env(EDITOR)] then {
22 set editor $env(EDITOR)
23 } else {
24 set editor emacs
25}
26
27# GDB callbacks
28#
29# These functions are called by GDB (from C code) to do various things in
30# TK-land. All start with the prefix `gdbtk_tcl_' to make them easy to find.
31#
32
33#
34# GDB Callback:
35#
36# gdbtk_tcl_fputs (text) - Output text to the command window
37#
38# Description:
39#
40# GDB calls this to output TEXT to the GDB command window. The text is
41# placed at the end of the text widget. Note that output may not occur,
42# due to buffering. Use gdbtk_tcl_flush to cause an immediate update.
43#
44
754e5da2 45proc gdbtk_tcl_fputs {arg} {
8532893d
SG
46 global current_output_win
47
48 $current_output_win insert end "$arg"
49 $current_output_win yview -pickplace end
50}
51
86db943c
SG
52proc gdbtk_tcl_fputs_error {arg} {
53 .cmd.text insert end "$arg"
54 .cmd.text yview -pickplace end
55}
56
8532893d
SG
57#
58# GDB Callback:
59#
60# gdbtk_tcl_flush () - Flush output to the command window
61#
62# Description:
63#
64# GDB calls this to force all buffered text to the GDB command window.
65#
66
67proc gdbtk_tcl_flush {} {
546b8ca7
SG
68 global current_output_win
69
8532893d
SG
70 $current_output_win yview -pickplace end
71 update idletasks
754e5da2
SG
72}
73
8532893d
SG
74#
75# GDB Callback:
76#
77# gdbtk_tcl_query (message) - Create a yes/no query dialog box
78#
79# Description:
80#
81# GDB calls this to create a yes/no dialog box containing MESSAGE. GDB
82# is hung while the dialog box is active (ie: no commands will work),
83# however windows can still be refreshed in case of damage or exposure.
84#
754e5da2
SG
85
86proc gdbtk_tcl_query {message} {
87 tk_dialog .query "gdb : query" "$message" {} 1 "No" "Yes"
88 }
89
8532893d
SG
90#
91# GDB Callback:
92#
93# gdbtk_start_variable_annotation (args ...) -
94#
95# Description:
96#
97# Not yet implemented.
98#
754e5da2
SG
99
100proc gdbtk_tcl_start_variable_annotation {valaddr ref_type stor_cl cum_expr field type_cast} {
101 echo "gdbtk_tcl_start_variable_annotation $valaddr $ref_type $stor_cl $cum_expr $field $type_cast"
102}
103
8532893d
SG
104#
105# GDB Callback:
106#
107# gdbtk_end_variable_annotation (args ...) -
108#
109# Description:
110#
111# Not yet implemented.
112#
113
754e5da2
SG
114proc gdbtk_tcl_end_variable_annotation {} {
115 echo gdbtk_tcl_end_variable_annotation
116}
117
8532893d
SG
118#
119# GDB Callback:
120#
121# gdbtk_tcl_breakpoint (action bpnum file line) - Notify the TK
122# interface of changes to breakpoints.
123#
124# Description:
125#
126# GDB calls this to notify TK of changes to breakpoints. ACTION is one
127# of:
128# create - Notify of breakpoint creation
129# delete - Notify of breakpoint deletion
130# enable - Notify of breakpoint enabling
131# disable - Notify of breakpoint disabling
132#
133# All actions take the same set of arguments: BPNUM is the breakpoint
134# number, FILE is the source file and LINE is the line number, and PC is
135# the pc of the affected breakpoint.
136#
137
138proc gdbtk_tcl_breakpoint {action bpnum file line pc} {
139 ${action}_breakpoint $bpnum $file $line $pc
754e5da2
SG
140}
141
335129a9 142proc asm_win_name {funcname} {
546b8ca7
SG
143 if {$funcname == "*None*"} {return .asm.text}
144
335129a9
SG
145 regsub -all {\.} $funcname _ temp
146
147 return .asm.func_${temp}
148}
149
8532893d
SG
150#
151# Local procedure:
152#
153# create_breakpoint (bpnum file line pc) - Record breakpoint info in TK land
154#
155# Description:
156#
157# GDB calls this indirectly (through gdbtk_tcl_breakpoint) to notify TK
158# land of breakpoint creation. This consists of recording the file and
159# line number in the breakpoint_file and breakpoint_line arrays. Also,
160# if there is already a window associated with FILE, it is updated with
161# a breakpoint tag.
162#
163
164proc create_breakpoint {bpnum file line pc} {
754e5da2
SG
165 global wins
166 global breakpoint_file
167 global breakpoint_line
8532893d 168 global pos_to_breakpoint
335129a9 169 global pos_to_bpcount
8532893d
SG
170 global cfunc
171 global pclist
754e5da2
SG
172
173# Record breakpoint locations
174
175 set breakpoint_file($bpnum) $file
176 set breakpoint_line($bpnum) $line
8532893d 177 set pos_to_breakpoint($file:$line) $bpnum
335129a9
SG
178 if ![info exists pos_to_bpcount($file:$line)] {
179 set pos_to_bpcount($file:$line) 0
180 }
181 incr pos_to_bpcount($file:$line)
182 set pos_to_breakpoint($pc) $bpnum
183 if ![info exists pos_to_bpcount($pc)] {
184 set pos_to_bpcount($pc) 0
185 }
186 incr pos_to_bpcount($pc)
754e5da2 187
8532893d 188# If there's a window for this file, update it
754e5da2
SG
189
190 if [info exists wins($file)] {
191 insert_breakpoint_tag $wins($file) $line
192 }
8532893d
SG
193
194# If there's an assembly window, update that too
195
335129a9 196 set win [asm_win_name $cfunc]
8532893d 197 if [winfo exists $win] {
637b1661 198 insert_breakpoint_tag $win [pc_to_line $pclist($cfunc) $pc]
8532893d 199 }
754e5da2
SG
200}
201
8532893d
SG
202#
203# Local procedure:
204#
205# delete_breakpoint (bpnum file line pc) - Delete breakpoint info from TK land
206#
207# Description:
208#
209# GDB calls this indirectly (through gdbtk_tcl_breakpoint) to notify TK
210# land of breakpoint destruction. This consists of removing the file and
211# line number from the breakpoint_file and breakpoint_line arrays. Also,
212# if there is already a window associated with FILE, the tags are removed
213# from it.
214#
215
216proc delete_breakpoint {bpnum file line pc} {
754e5da2
SG
217 global wins
218 global breakpoint_file
219 global breakpoint_line
8532893d 220 global pos_to_breakpoint
335129a9
SG
221 global pos_to_bpcount
222 global cfunc pclist
754e5da2 223
8532893d 224# Save line number and file for later
754e5da2
SG
225
226 set line $breakpoint_line($bpnum)
227
8532893d
SG
228 set file $breakpoint_file($bpnum)
229
754e5da2
SG
230# Reset breakpoint annotation info
231
335129a9 232 if {$pos_to_bpcount($file:$line) > 0} {
637b1661 233 decr pos_to_bpcount($file:$line)
335129a9
SG
234
235 if {$pos_to_bpcount($file:$line) == 0} {
637b1661
SG
236 catch "unset pos_to_breakpoint($file:$line)"
237
335129a9
SG
238 unset breakpoint_file($bpnum)
239 unset breakpoint_line($bpnum)
754e5da2 240
8532893d 241# If there's a window for this file, update it
754e5da2 242
335129a9
SG
243 if [info exists wins($file)] {
244 delete_breakpoint_tag $wins($file) $line
245 }
246 }
247 }
248
249# If there's an assembly window, update that too
250
251 if {$pos_to_bpcount($pc) > 0} {
637b1661 252 decr pos_to_bpcount($pc)
335129a9
SG
253
254 if {$pos_to_bpcount($pc) == 0} {
637b1661
SG
255 catch "unset pos_to_breakpoint($pc)"
256
335129a9
SG
257 set win [asm_win_name $cfunc]
258 if [winfo exists $win] {
637b1661 259 delete_breakpoint_tag $win [pc_to_line $pclist($cfunc) $pc]
335129a9
SG
260 }
261 }
754e5da2
SG
262 }
263}
264
8532893d
SG
265#
266# Local procedure:
267#
268# enable_breakpoint (bpnum file line pc) - Record breakpoint info in TK land
269#
270# Description:
271#
272# GDB calls this indirectly (through gdbtk_tcl_breakpoint) to notify TK
273# land of a breakpoint being enabled. This consists of unstippling the
274# specified breakpoint indicator.
275#
276
277proc enable_breakpoint {bpnum file line pc} {
278 global wins
335129a9
SG
279 global cfunc pclist
280
281 if [info exists wins($file)] {
282 $wins($file) tag configure $line -fgstipple {}
283 }
754e5da2 284
335129a9
SG
285# If there's an assembly window, update that too
286
287 set win [asm_win_name $cfunc]
288 if [winfo exists $win] {
637b1661 289 $win tag configure [pc_to_line $pclist($cfunc) $pc] -fgstipple {}
335129a9 290 }
754e5da2
SG
291}
292
8532893d
SG
293#
294# Local procedure:
295#
296# disable_breakpoint (bpnum file line pc) - Record breakpoint info in TK land
297#
298# Description:
299#
300# GDB calls this indirectly (through gdbtk_tcl_breakpoint) to notify TK
301# land of a breakpoint being disabled. This consists of stippling the
302# specified breakpoint indicator.
303#
304
305proc disable_breakpoint {bpnum file line pc} {
306 global wins
335129a9
SG
307 global cfunc pclist
308
309 if [info exists wins($file)] {
310 $wins($file) tag configure $line -fgstipple gray50
311 }
754e5da2 312
335129a9
SG
313# If there's an assembly window, update that too
314
315 set win [asm_win_name $cfunc]
316 if [winfo exists $win] {
637b1661 317 $win tag configure [pc_to_line $pclist($cfunc) $pc] -fgstipple gray50
335129a9 318 }
8532893d
SG
319}
320
321#
322# Local procedure:
323#
324# insert_breakpoint_tag (win line) - Insert a breakpoint tag in WIN.
325#
326# Description:
327#
328# GDB calls this indirectly (through gdbtk_tcl_breakpoint) to insert a
329# breakpoint tag into window WIN at line LINE.
330#
754e5da2 331
8532893d
SG
332proc insert_breakpoint_tag {win line} {
333 $win configure -state normal
334 $win delete $line.0
335 $win insert $line.0 "B"
336 $win tag add $line $line.0
479f0f18
SG
337 $win tag add delete $line.0 "$line.0 lineend"
338 $win tag add margin $line.0 "$line.0 lineend"
8532893d
SG
339
340 $win configure -state disabled
341}
342
343#
344# Local procedure:
345#
346# delete_breakpoint_tag (win line) - Remove a breakpoint tag from WIN.
347#
348# Description:
349#
350# GDB calls this indirectly (through gdbtk_tcl_breakpoint) to remove a
351# breakpoint tag from window WIN at line LINE.
352#
353
354proc delete_breakpoint_tag {win line} {
355 $win configure -state normal
356 $win delete $line.0
746d1df4
SG
357 if {[string range $win 0 3] == ".src"} then {
358 $win insert $line.0 "\xa4"
359 } else {
360 $win insert $line.0 " "
361 }
8532893d 362 $win tag delete $line
479f0f18
SG
363 $win tag add delete $line.0 "$line.0 lineend"
364 $win tag add margin $line.0 "$line.0 lineend"
8532893d
SG
365 $win configure -state disabled
366}
754e5da2 367
479f0f18 368proc gdbtk_tcl_busy {} {
86db943c 369 if [winfo exists .src] {
546b8ca7
SG
370 catch {.src.start configure -state disabled}
371 catch {.src.stop configure -state normal}
372 catch {.src.step configure -state disabled}
373 catch {.src.next configure -state disabled}
374 catch {.src.continue configure -state disabled}
375 catch {.src.finish configure -state disabled}
376 catch {.src.up configure -state disabled}
377 catch {.src.down configure -state disabled}
378 catch {.src.bottom configure -state disabled}
86db943c
SG
379 }
380 if [winfo exists .asm] {
546b8ca7
SG
381 catch {.asm.stepi configure -state disabled}
382 catch {.asm.nexti configure -state disabled}
383 catch {.asm.continue configure -state disabled}
384 catch {.asm.finish configure -state disabled}
385 catch {.asm.up configure -state disabled}
386 catch {.asm.down configure -state disabled}
387 catch {.asm.bottom configure -state disabled}
388 catch {.asm.close configure -state disabled}
86db943c 389 }
479f0f18
SG
390}
391
392proc gdbtk_tcl_idle {} {
86db943c 393 if [winfo exists .src] {
546b8ca7
SG
394 catch {.src.start configure -state normal}
395 catch {.src.stop configure -state disabled}
396 catch {.src.step configure -state normal}
397 catch {.src.next configure -state normal}
398 catch {.src.continue configure -state normal}
399 catch {.src.finish configure -state normal}
400 catch {.src.up configure -state normal}
401 catch {.src.down configure -state normal}
402 catch {.src.bottom configure -state normal}
86db943c
SG
403 }
404
405 if [winfo exists .asm] {
546b8ca7
SG
406 catch {.asm.stepi configure -state normal}
407 catch {.asm.nexti configure -state normal}
408 catch {.asm.continue configure -state normal}
409 catch {.asm.finish configure -state normal}
410 catch {.asm.up configure -state normal}
411 catch {.asm.down configure -state normal}
412 catch {.asm.bottom configure -state normal}
413 catch {.asm.close configure -state normal}
86db943c 414 }
479f0f18
SG
415}
416
637b1661
SG
417#
418# Local procedure:
419#
420# decr (var val) - compliment to incr
421#
422# Description:
423#
424#
425proc decr {var {val 1}} {
426 upvar $var num
427 set num [expr $num - $val]
428 return $num
429}
430
431#
432# Local procedure:
433#
434# pc_to_line (pclist pc) - convert PC to a line number.
435#
436# Description:
437#
438# Convert PC to a line number from PCLIST. If exact line isn't found,
439# we return the first line that starts before PC.
440#
441proc pc_to_line {pclist pc} {
442 set line [lsearch -exact $pclist $pc]
443
444 if {$line >= 1} { return $line }
445
446 set line 1
447 foreach linepc [lrange $pclist 1 end] {
448 if {$pc < $linepc} { decr line ; return $line }
449 incr line
450 }
451 return [expr $line - 1]
452}
453
8532893d
SG
454#
455# Menu:
456#
457# file popup menu - Define the file popup menu.
458#
459# Description:
460#
461# This menu just contains a bunch of buttons that do various things to
462# the line under the cursor.
463#
464# Items:
465#
466# Edit - Run the editor (specified by the environment variable EDITOR) on
467# this file, at the current line.
468# Breakpoint - Set a breakpoint at the current line. This just shoves
469# a `break' command at GDB with the appropriate file and line
470# number. Eventually, GDB calls us back (at gdbtk_tcl_breakpoint)
471# to notify us of where the breakpoint needs to show up.
472#
473
474menu .file_popup -cursor hand2
475.file_popup add command -label "Not yet set" -state disabled
476.file_popup add separator
477.file_popup add command -label "Edit" -command {exec $editor +$selected_line $selected_file &}
478.file_popup add command -label "Set breakpoint" -command {gdb_cmd "break $selected_file:$selected_line"}
479
480#
481# Bindings:
482#
483# file popup menu - Define the file popup menu bindings.
484#
485# Description:
486#
487# This defines the binding for the file popup menu. Currently, there is
488# only one, which is activated when Button-1 is released. This causes
489# the menu to be unposted, releases the grab for the menu, and then
490# unhighlights the line under the cursor. After that, the selected menu
491# item is invoked.
492#
493
494bind .file_popup <Any-ButtonRelease-1> {
754e5da2
SG
495 global selected_win
496
497# First, remove the menu, and release the pointer
498
8532893d
SG
499 .file_popup unpost
500 grab release .file_popup
754e5da2
SG
501
502# Unhighlight the selected line
503
504 $selected_win tag delete breaktag
754e5da2
SG
505
506# Actually invoke the menubutton here!
507
508 tk_invokeMenu %W
754e5da2
SG
509}
510
8532893d
SG
511#
512# Local procedure:
513#
514# file_popup_menu (win x y xrel yrel) - Popup the file popup menu.
515#
516# Description:
517#
518# This procedure is invoked as a result of a command binding in the
519# listing window. It does several things:
520# o - It highlights the line under the cursor.
521# o - It pops up the file popup menu which is intended to do
522# various things to the aforementioned line.
523# o - Grabs the mouse for the file popup menu.
524#
525
754e5da2
SG
526# Button 1 has been pressed in a listing window. Pop up a menu.
527
8532893d 528proc file_popup_menu {win x y xrel yrel} {
754e5da2
SG
529 global wins
530 global win_to_file
531 global file_to_debug_file
532 global highlight
533 global selected_line
534 global selected_file
535 global selected_win
536
754e5da2
SG
537# Map TK window name back to file name.
538
539 set file $win_to_file($win)
540
541 set pos [$win index @$xrel,$yrel]
542
543# Record selected file and line for menu button actions
544
545 set selected_file $file_to_debug_file($file)
546 set selected_line [lindex [split $pos .] 0]
547 set selected_win $win
548
549# Highlight the selected line
550
551 eval $win tag config breaktag $highlight
552 $win tag add breaktag "$pos linestart" "$pos linestart + 1l"
553
554# Post the menu near the pointer, (and grab it)
555
8532893d
SG
556 .file_popup entryconfigure 0 -label "$selected_file:$selected_line"
557 .file_popup post [expr $x-[winfo width .file_popup]/2] [expr $y-10]
558 grab .file_popup
754e5da2
SG
559}
560
8532893d
SG
561#
562# Local procedure:
563#
564# listing_window_button_1 (win x y xrel yrel) - Handle button 1 in listing window
565#
566# Description:
567#
568# This procedure is invoked as a result of holding down button 1 in the
569# listing window. The action taken depends upon where the button was
570# pressed. If it was in the left margin (the breakpoint column), it
571# sets or clears a breakpoint. In the main text area, it will pop up a
572# menu.
573#
574
575proc listing_window_button_1 {win x y xrel yrel} {
576 global wins
577 global win_to_file
578 global file_to_debug_file
579 global highlight
580 global selected_line
581 global selected_file
582 global selected_win
583 global pos_to_breakpoint
584
585# Map TK window name back to file name.
586
587 set file $win_to_file($win)
588
589 set pos [split [$win index @$xrel,$yrel] .]
590
591# Record selected file and line for menu button actions
592
593 set selected_file $file_to_debug_file($file)
594 set selected_line [lindex $pos 0]
595 set selected_col [lindex $pos 1]
596 set selected_win $win
597
598# If we're in the margin, then toggle the breakpoint
599
600 if {$selected_col < 8} {
601 set pos_break $selected_file:$selected_line
602 set pos $file:$selected_line
603 set tmp pos_to_breakpoint($pos)
604 if [info exists $tmp] {
605 set bpnum [set $tmp]
606 gdb_cmd "delete $bpnum"
607 } else {
608 gdb_cmd "break $pos_break"
609 }
610 return
611 }
612
613# Post the menu near the pointer, (and grab it)
614
615 .file_popup entryconfigure 0 -label "$selected_file:$selected_line"
616 .file_popup post [expr $x-[winfo width .file_popup]/2] [expr $y-10]
617 grab .file_popup
618}
619
620#
621# Local procedure:
622#
623# asm_window_button_1 (win x y xrel yrel) - Handle button 1 in asm window
624#
625# Description:
626#
627# This procedure is invoked as a result of holding down button 1 in the
628# assembly window. The action taken depends upon where the button was
629# pressed. If it was in the left margin (the breakpoint column), it
630# sets or clears a breakpoint. In the main text area, it will pop up a
631# menu.
632#
633
634proc asm_window_button_1 {win x y xrel yrel} {
635 global wins
636 global win_to_file
637 global file_to_debug_file
638 global highlight
639 global selected_line
640 global selected_file
641 global selected_win
642 global pos_to_breakpoint
643 global pclist
644 global cfunc
645
646 set pos [split [$win index @$xrel,$yrel] .]
647
648# Record selected file and line for menu button actions
649
650 set selected_line [lindex $pos 0]
651 set selected_col [lindex $pos 1]
652 set selected_win $win
653
654# Figure out the PC
655
656 set pc [lindex $pclist($cfunc) $selected_line]
657
658# If we're in the margin, then toggle the breakpoint
659
746d1df4 660 if {$selected_col < 11} {
8532893d
SG
661 set tmp pos_to_breakpoint($pc)
662 if [info exists $tmp] {
663 set bpnum [set $tmp]
664 gdb_cmd "delete $bpnum"
665 } else {
666 gdb_cmd "break *$pc"
667 }
668 return
669 }
670
671# Post the menu near the pointer, (and grab it)
672
673# .file_popup entryconfigure 0 -label "$selected_file:$selected_line"
674# .file_popup post [expr $x-[winfo width .file_popup]/2] [expr $y-10]
675# grab .file_popup
676}
677
678#
679# Local procedure:
680#
e12533e3 681# do_nothing - Does absolutely nothing.
8532893d
SG
682#
683# Description:
684#
685# This procedure does nothing. It is used as a placeholder to allow
686# the disabling of bindings that would normally be inherited from the
687# parent widget. I can't think of any other way to do this.
688#
689
754e5da2
SG
690proc do_nothing {} {}
691
479f0f18
SG
692#
693# Local procedure:
694#
e12533e3
SS
695# not_implemented_yet - warn that a feature is unavailable
696#
697# Description:
698#
699# This procedure warns that something doesn't actually work yet.
700#
701
702proc not_implemented_yet {message} {
c4a5c37c
SS
703 tk_dialog .unimpl "gdb : unimpl" \
704 "$message: not implemented in the interface yet" \
e12533e3
SS
705 {} 1 "OK"
706}
707
708##
709# Local procedure:
710#
c4a5c37c 711# create_expr_win - Create expression display window
479f0f18
SG
712#
713# Description:
714#
715# Create the expression display window.
716#
717
09722039
SG
718set expr_num 0
719
720proc add_expr {expr} {
721 global expr_update_list
722 global expr_num
723
724 incr expr_num
725
726 set e .expr.e${expr_num}
727
728 frame $e
729
730 checkbutton $e.update -text " " -relief flat \
731 -variable expr_update_list($expr_num)
732 message $e.expr -text $expr -aspect 200
733 bind $e.expr <1> "update_expr $expr_num"
734 message $e.val -aspect 200
735
736 update_expr $expr_num
737
738 pack $e.update -side left -anchor nw
739 pack $e.expr $e.val -side left -expand yes -anchor w
740
741 pack $e -side top -fill x -anchor w
742}
743
744set delete_expr_flag 0
745
746# This is a krock!!!
747
748proc delete_expr {} {
749 global delete_expr_flag
750
751 if {$delete_expr_flag == 1} {
752 set delete_expr_flag 0
753 tk_butUp .expr.delete
754 bind .expr.delete <Any-Leave> {}
755 } else {
756 set delete_expr_flag 1
757 bind .expr.delete <Any-Leave> do_nothing
758 tk_butDown .expr.delete
759 }
760}
761
762proc update_expr {expr_num} {
763 global delete_expr_flag
764
765 set e .expr.e${expr_num}
766
767 if {$delete_expr_flag == 1} {
768 set delete_expr_flag 0
769 destroy $e
770 tk_butUp .expr.delete
771 tk_butLeave .expr.delete
772 bind .expr.delete <Any-Leave> {}
773 return
774 }
775
776 set expr [lindex [$e.expr configure -text] 4]
777
778 $e.val config -text [gdb_eval $expr]
779}
780
479f0f18
SG
781proc create_expr_win {} {
782 toplevel .expr
783 wm minsize .expr 1 1
784 wm title .expr Expression
09722039 785 wm iconname .expr "Reg config"
479f0f18 786
09722039 787 frame .expr.entryframe
479f0f18 788
09722039
SG
789 entry .expr.entry -borderwidth 2 -relief sunken
790 bind .expr <Enter> {focus .expr.entry}
791 bind .expr.entry <Key-Return> {add_expr [.expr.entry get]
792 .expr.entry delete 0 end }
793
794 label .expr.entrylab -text "Expression: "
795
796 pack .expr.entrylab -in .expr.entryframe -side left
797 pack .expr.entry -in .expr.entryframe -side left -fill x -expand yes
798
799 frame .expr.buts
800
801 button .expr.delete -text Delete
802 bind .expr.delete <1> delete_expr
803
804 button .expr.close -text Close -command {destroy .expr}
805
806 pack .expr.delete -side left -fill x -expand yes -in .expr.buts
807 pack .expr.close -side right -fill x -expand yes -in .expr.buts
808
809 pack .expr.buts -side bottom -fill x
810 pack .expr.entryframe -side bottom -fill x
811
812 frame .expr.labels
813
814 label .expr.updlab -text Update
815 label .expr.exprlab -text Expression
816 label .expr.vallab -text Value
817
818 pack .expr.updlab -side left -in .expr.labels
819 pack .expr.exprlab .expr.vallab -side left -in .expr.labels -expand yes -anchor w
820
821 pack .expr.labels -side top -fill x -anchor w
479f0f18
SG
822}
823
824#
825# Local procedure:
826#
827# display_expression (expression) - Display EXPRESSION in display window
828#
829# Description:
830#
e12533e3 831# Display EXPRESSION and its value in the expression display window.
479f0f18
SG
832#
833
834proc display_expression {expression} {
835 if ![winfo exists .expr] {create_expr_win}
836
09722039 837 add_expr $expression
479f0f18
SG
838}
839
8532893d
SG
840#
841# Local procedure:
842#
843# create_file_win (filename) - Create a win for FILENAME.
844#
845# Return value:
846#
847# The new text widget.
848#
849# Description:
850#
851# This procedure creates a text widget for FILENAME. It returns the
852# newly created widget. First, a text widget is created, and given basic
853# configuration info. Second, all the bindings are setup. Third, the
854# file FILENAME is read into the text widget. Fourth, margins and line
855# numbers are added.
856#
857
746d1df4 858proc create_file_win {filename debug_file} {
754e5da2
SG
859 global breakpoint_file
860 global breakpoint_line
86db943c 861 global line_numbers
754e5da2 862
8532893d
SG
863# Replace all the dirty characters in $filename with clean ones, and generate
864# a unique name for the text widget.
865
746d1df4 866 regsub -all {\.} $filename {} temp
006e71e9 867 set win .src.text$temp
8532893d 868
637b1661
SG
869# Open the file, and read it into the text widget
870
871 if [catch "open $filename" fh] {
746d1df4
SG
872# File can't be read. Put error message into .src.nofile window and return.
873
874 catch {destroy .src.nofile}
875 text .src.nofile -height 25 -width 88 -relief raised \
876 -borderwidth 2 -yscrollcommand textscrollproc \
877 -setgrid true -cursor hand2
878 .src.nofile insert 0.0 $fh
879 .src.nofile configure -state disabled
880 bind .src.nofile <1> do_nothing
881 bind .src.nofile <B1-Motion> do_nothing
882 return .src.nofile
637b1661
SG
883 }
884
8532893d
SG
885# Actually create and do basic configuration on the text widget.
886
746d1df4
SG
887 text $win -height 25 -width 88 -relief raised -borderwidth 2 \
888 -yscrollcommand textscrollproc -setgrid true -cursor hand2
8532893d
SG
889
890# Setup all the bindings
891
754e5da2 892 bind $win <Enter> {focus %W}
479f0f18
SG
893# bind $win <1> {listing_window_button_1 %W %X %Y %x %y}
894 bind $win <1> do_nothing
754e5da2 895 bind $win <B1-Motion> do_nothing
479f0f18 896
86db943c
SG
897 bind $win n {catch {gdb_cmd next} ; update_ptr}
898 bind $win s {catch {gdb_cmd step} ; update_ptr}
899 bind $win c {catch {gdb_cmd continue} ; update_ptr}
900 bind $win f {catch {gdb_cmd finish} ; update_ptr}
901 bind $win u {catch {gdb_cmd up} ; update_ptr}
902 bind $win d {catch {gdb_cmd down} ; update_ptr}
8532893d 903
754e5da2
SG
904 $win delete 0.0 end
905 $win insert 0.0 [read $fh]
906 close $fh
8532893d 907
86db943c 908# Add margins (for annotations) and a line number to each line (if requested)
8532893d 909
754e5da2
SG
910 set numlines [$win index end]
911 set numlines [lindex [split $numlines .] 0]
86db943c
SG
912 if $line_numbers {
913 for {set i 1} {$i <= $numlines} {incr i} {
914 $win insert $i.0 [format " %4d " $i]
915 $win tag add source $i.8 "$i.0 lineend"
916 }
917 } else {
918 for {set i 1} {$i <= $numlines} {incr i} {
919 $win insert $i.0 " "
920 $win tag add source $i.8 "$i.0 lineend"
921 }
922 }
479f0f18 923
746d1df4
SG
924# Add the breakdots
925
926 foreach i [gdb_sourcelines $debug_file] {
927 $win delete $i.0
928 $win insert $i.0 "\xa4"
929 $win tag add margin $i.0 $i.8
930 }
931
479f0f18
SG
932 $win tag bind margin <1> {listing_window_button_1 %W %X %Y %x %y}
933 $win tag bind source <1> {
934 %W mark set anchor "@%x,%y wordstart"
935 set last [%W index "@%x,%y wordend"]
936 %W tag remove sel 0.0 anchor
937 %W tag remove sel $last end
938 %W tag add sel anchor $last
939 }
940# $win tag bind source <Double-Button-1> {
941# %W mark set anchor "@%x,%y wordstart"
942# set last [%W index "@%x,%y wordend"]
943# %W tag remove sel 0.0 anchor
944# %W tag remove sel $last end
945# %W tag add sel anchor $last
946# echo "Selected [selection get]"
947# }
948 $win tag bind source <B1-Motion> {
949 %W tag remove sel 0.0 anchor
950 %W tag remove sel $last end
951 %W tag add sel anchor @%x,%y
754e5da2 952 }
479f0f18
SG
953 $win tag bind sel <1> do_nothing
954 $win tag bind sel <Double-Button-1> {display_expression [selection get]}
955 $win tag raise sel
956
754e5da2 957
8532893d
SG
958# Scan though the breakpoint data base and install any destined for this file
959
754e5da2
SG
960 foreach bpnum [array names breakpoint_file] {
961 if {$breakpoint_file($bpnum) == $filename} {
962 insert_breakpoint_tag $win $breakpoint_line($bpnum)
963 }
964 }
965
8532893d
SG
966# Disable the text widget to prevent user modifications
967
754e5da2
SG
968 $win configure -state disabled
969 return $win
970}
971
8532893d
SG
972#
973# Local procedure:
974#
637b1661 975# create_asm_win (funcname pc) - Create an assembly win for FUNCNAME.
8532893d
SG
976#
977# Return value:
978#
979# The new text widget.
980#
981# Description:
982#
983# This procedure creates a text widget for FUNCNAME. It returns the
984# newly created widget. First, a text widget is created, and given basic
985# configuration info. Second, all the bindings are setup. Third, the
986# function FUNCNAME is read into the text widget.
987#
988
637b1661 989proc create_asm_win {funcname pc} {
8532893d
SG
990 global breakpoint_file
991 global breakpoint_line
992 global current_output_win
993 global pclist
994
995# Replace all the dirty characters in $filename with clean ones, and generate
996# a unique name for the text widget.
997
335129a9 998 set win [asm_win_name $funcname]
8532893d
SG
999
1000# Actually create and do basic configuration on the text widget.
1001
09722039 1002 text $win -height 25 -width 80 -relief raised -borderwidth 2 \
8532893d
SG
1003 -setgrid true -cursor hand2 -yscrollcommand asmscrollproc
1004
1005# Setup all the bindings
1006
1007 bind $win <Enter> {focus %W}
1008 bind $win <1> {asm_window_button_1 %W %X %Y %x %y}
1009 bind $win <B1-Motion> do_nothing
86db943c
SG
1010 bind $win n {catch {gdb_cmd nexti} ; update_ptr}
1011 bind $win s {catch {gdb_cmd stepi} ; update_ptr}
1012 bind $win c {catch {gdb_cmd continue} ; update_ptr}
1013 bind $win f {catch {gdb_cmd finish} ; update_ptr}
1014 bind $win u {catch {gdb_cmd up} ; update_ptr}
1015 bind $win d {catch {gdb_cmd down} ; update_ptr}
8532893d
SG
1016
1017# Disassemble the code, and read it into the new text widget
1018
006e71e9 1019 set temp $current_output_win
8532893d 1020 set current_output_win $win
09722039 1021 catch "gdb_disassemble source $pc"
006e71e9 1022 set current_output_win $temp
8532893d
SG
1023
1024 set numlines [$win index end]
1025 set numlines [lindex [split $numlines .] 0]
637b1661 1026 decr numlines
8532893d
SG
1027
1028# Delete the first and last lines, cuz these contain useless info
1029
09722039
SG
1030# $win delete 1.0 2.0
1031# $win delete {end - 1 lines} end
1032# decr numlines 2
8532893d
SG
1033
1034# Add margins (for annotations) and note the PC for each line
1035
637b1661 1036 catch "unset pclist($funcname)"
335129a9 1037 lappend pclist($funcname) Unused
8532893d
SG
1038 for {set i 1} {$i <= $numlines} {incr i} {
1039 scan [$win get $i.0 "$i.0 lineend"] "%s " pc
1040 lappend pclist($funcname) $pc
1041 $win insert $i.0 " "
1042 }
1043
1044
1045# Scan though the breakpoint data base and install any destined for this file
1046
1047# foreach bpnum [array names breakpoint_file] {
1048# if {$breakpoint_file($bpnum) == $filename} {
1049# insert_breakpoint_tag $win $breakpoint_line($bpnum)
1050# }
1051# }
1052
1053# Disable the text widget to prevent user modifications
1054
1055 $win configure -state disabled
1056 return $win
1057}
1058
1059#
1060# Local procedure:
1061#
1062# asmscrollproc (WINHEIGHT SCREENHEIGHT SCREENTOP SCREENBOT) - Update the
1063# asm window scrollbar.
1064#
1065# Description:
1066#
1067# This procedure is called to update the assembler window's scrollbar.
1068#
1069
1070proc asmscrollproc {args} {
1071 global asm_screen_height asm_screen_top asm_screen_bot
1072
1073 eval ".asm.scroll set $args"
1074 set asm_screen_height [lindex $args 1]
1075 set asm_screen_top [lindex $args 2]
1076 set asm_screen_bot [lindex $args 3]
1077}
1078
1079#
1080# Local procedure:
1081#
1082# update_listing (linespec) - Update the listing window according to
1083# LINESPEC.
1084#
1085# Description:
1086#
1087# This procedure is called from various places to update the listing
1088# window based on LINESPEC. It is usually invoked with the result of
1089# gdb_loc.
1090#
1091# It will move the cursor, and scroll the text widget if necessary.
1092# Also, it will switch to another text widget if necessary, and update
1093# the label widget too.
1094#
1095# LINESPEC is a list of the form:
1096#
1097# { DEBUG_FILE FUNCNAME FILENAME LINE }, where:
1098#
1099# DEBUG_FILE - is the abbreviated form of the file name. This is usually
1100# the file name string given to the cc command. This is
1101# primarily needed for breakpoint commands, and when an
1102# abbreviated for of the filename is desired.
1103# FUNCNAME - is the name of the function.
1104# FILENAME - is the fully qualified (absolute) file name. It is usually
1105# the same as $PWD/$DEBUG_FILE, where PWD is the working dir
1106# at the time the cc command was given. This is used to
1107# actually locate the file to be displayed.
1108# LINE - The line number to be displayed.
1109#
1110# Usually, this procedure will just move the cursor one line down to the
1111# next line to be executed. However, if the cursor moves out of range
1112# or into another file, it will scroll the text widget so that the line
1113# of interest is in the middle of the viewable portion of the widget.
1114#
1115
754e5da2
SG
1116proc update_listing {linespec} {
1117 global pointers
1118 global screen_height
1119 global screen_top
1120 global screen_bot
1121 global wins cfile
1122 global current_label
1123 global win_to_file
1124 global file_to_debug_file
746d1df4 1125 global .src.label
754e5da2 1126
8532893d
SG
1127# Rip the linespec apart
1128
754e5da2
SG
1129 set line [lindex $linespec 3]
1130 set filename [lindex $linespec 2]
1131 set funcname [lindex $linespec 1]
1132 set debug_file [lindex $linespec 0]
1133
8532893d
SG
1134# Sometimes there's no source file for this location
1135
754e5da2
SG
1136 if {$filename == ""} {set filename Blank}
1137
8532893d
SG
1138# If we want to switch files, we need to unpack the current text widget, and
1139# stick in the new one.
1140
754e5da2
SG
1141 if {$filename != $cfile} then {
1142 pack forget $wins($cfile)
1143 set cfile $filename
8532893d
SG
1144
1145# Create a text widget for this file if necessary
1146
754e5da2 1147 if ![info exists wins($cfile)] then {
746d1df4
SG
1148 set wins($cfile) [create_file_win $cfile $debug_file]
1149 if {$wins($cfile) != ".src.nofile"} {
637b1661
SG
1150 set win_to_file($wins($cfile)) $cfile
1151 set file_to_debug_file($cfile) $debug_file
1152 set pointers($cfile) 1.1
1153 }
754e5da2
SG
1154 }
1155
8532893d
SG
1156# Pack the text widget into the listing widget, and scroll to the right place
1157
746d1df4
SG
1158 pack $wins($cfile) -side left -expand yes -in .src.info \
1159 -fill both -after .src.scroll
1160
1161# Make the scrollbar point at the new text widget
1162
1163 .src.scroll configure -command "$wins($cfile) yview"
1164
754e5da2
SG
1165 $wins($cfile) yview [expr $line - $screen_height / 2]
1166 }
1167
8532893d
SG
1168# Update the label widget in case the filename or function name has changed
1169
754e5da2
SG
1170 if {$current_label != "$filename.$funcname"} then {
1171 set tail [expr [string last / $filename] + 1]
746d1df4
SG
1172 set .src.label "[string range $filename $tail end] : ${funcname}()"
1173# .src.label configure -text "[string range $filename $tail end] : ${funcname}()"
754e5da2
SG
1174 set current_label $filename.$funcname
1175 }
1176
8532893d
SG
1177# Update the pointer, scrolling the text widget if necessary to keep the
1178# pointer in an acceptable part of the screen.
1179
754e5da2
SG
1180 if [info exists pointers($cfile)] then {
1181 $wins($cfile) configure -state normal
1182 set pointer_pos $pointers($cfile)
1183 $wins($cfile) configure -state normal
746d1df4
SG
1184 $wins($cfile) delete $pointer_pos "$pointer_pos + 2 char"
1185 $wins($cfile) insert $pointer_pos " "
754e5da2
SG
1186
1187 set pointer_pos [$wins($cfile) index $line.1]
1188 set pointers($cfile) $pointer_pos
1189
746d1df4
SG
1190 $wins($cfile) delete $pointer_pos "$pointer_pos + 2 char"
1191 $wins($cfile) insert $pointer_pos "->"
754e5da2
SG
1192
1193 if {$line < $screen_top + 1
1194 || $line > $screen_bot} then {
1195 $wins($cfile) yview [expr $line - $screen_height / 2]
1196 }
1197
1198 $wins($cfile) configure -state disabled
1199 }
1200}
1201
8532893d
SG
1202#
1203# Local procedure:
1204#
746d1df4 1205# create_asm_window - Open up the assembly window.
8532893d
SG
1206#
1207# Description:
1208#
1209# Create an assembly window if it doesn't exist.
1210#
1211
746d1df4 1212proc create_asm_window {} {
8532893d
SG
1213 global cfunc
1214
1215 if ![winfo exists .asm] {
1216 set cfunc *None*
335129a9
SG
1217 set win [asm_win_name $cfunc]
1218
006e71e9
SG
1219 build_framework .asm Assembly "*NIL*"
1220
09722039
SG
1221# First, delete all the old menu entries
1222
1223 .asm.menubar.view.menu delete 0 last
1224
006e71e9 1225 .asm.text configure -yscrollcommand asmscrollproc
8532893d 1226
006e71e9
SG
1227 frame .asm.row1
1228 frame .asm.row2
8532893d 1229
006e71e9 1230 button .asm.stepi -width 6 -text Stepi \
86db943c 1231 -command {catch {gdb_cmd stepi} ; update_ptr}
006e71e9 1232 button .asm.nexti -width 6 -text Nexti \
86db943c 1233 -command {catch {gdb_cmd nexti} ; update_ptr}
006e71e9 1234 button .asm.continue -width 6 -text Cont \
86db943c 1235 -command {catch {gdb_cmd continue} ; update_ptr}
006e71e9 1236 button .asm.finish -width 6 -text Finish \
86db943c
SG
1237 -command {catch {gdb_cmd finish} ; update_ptr}
1238 button .asm.up -width 6 -text Up -command {catch {gdb_cmd up} ; update_ptr}
006e71e9 1239 button .asm.down -width 6 -text Down \
86db943c 1240 -command {catch {gdb_cmd down} ; update_ptr}
006e71e9 1241 button .asm.bottom -width 6 -text Bottom \
86db943c 1242 -command {catch {gdb_cmd {frame 0}} ; update_ptr}
8532893d 1243
006e71e9
SG
1244 pack .asm.stepi .asm.continue .asm.up .asm.bottom -side left -padx 3 -pady 5 -in .asm.row1
1245 pack .asm.nexti .asm.finish .asm.down -side left -padx 3 -pady 5 -in .asm.row2
1246
86db943c 1247 pack .asm.row2 .asm.row1 -side bottom -anchor w -before .asm.info
8532893d
SG
1248
1249 update
006e71e9 1250
006e71e9 1251 update_assembly [gdb_loc]
09722039
SG
1252
1253# We do this update_assembly to get the proper value of disassemble-from-exec.
1254
1255# exec file menu item
1256 .asm.menubar.view.menu add radiobutton -label "Exec file" \
1257 -variable disassemble-from-exec -value 1
1258# target memory menu item
1259 .asm.menubar.view.menu add radiobutton -label "Target memory" \
1260 -variable disassemble-from-exec -value 0
8532893d
SG
1261 }
1262}
1263
746d1df4 1264proc reg_config_menu {} {
746d1df4
SG
1265 catch {destroy .reg.config}
1266 toplevel .reg.config
1267 wm geometry .reg.config +300+300
1268 wm title .reg.config "Register configuration"
1269 wm iconname .reg.config "Reg config"
1270 set regnames [gdb_regnames]
1271 set num_regs [llength $regnames]
1272
86db943c
SG
1273 frame .reg.config.buts
1274
1275 button .reg.config.done -text " Done " -command "
1276 recompute_reg_display_list $num_regs
1277 populate_reg_window
1278 update_registers all
1279 destroy .reg.config "
1280
1281 button .reg.config.update -text Update -command "
1282 recompute_reg_display_list $num_regs
1283 populate_reg_window
1284 update_registers all "
1285
1286 pack .reg.config.buts -side bottom -fill x
746d1df4 1287
86db943c
SG
1288 pack .reg.config.done -side left -fill x -expand yes -in .reg.config.buts
1289 pack .reg.config.update -side right -fill x -expand yes -in .reg.config.buts
746d1df4
SG
1290
1291# Since there can be lots of registers, we build the window with no more than
1292# 32 rows, and as many columns as needed.
1293
1294# First, figure out how many columns we need and create that many column frame
1295# widgets
1296
1297 set ncols [expr ($num_regs + 31) / 32]
1298
1299 for {set col 0} {$col < $ncols} {incr col} {
1300 frame .reg.config.col$col
1301 pack .reg.config.col$col -side left -anchor n
1302 }
1303
1304# Now, create the checkbutton widgets and pack them in the appropriate columns
1305
1306 set col 0
1307 set row 0
1308 for {set regnum 0} {$regnum < $num_regs} {incr regnum} {
1309 set regname [lindex $regnames $regnum]
1310 checkbutton .reg.config.col$col.$row -text $regname -pady 0 \
86db943c 1311 -variable regena($regnum) -relief flat -anchor w -bd 1
746d1df4
SG
1312
1313 pack .reg.config.col$col.$row -side top -fill both
1314
1315 incr row
1316 if {$row >= 32} {
1317 incr col
1318 set row 0
1319 }
1320 }
1321}
1322
335129a9
SG
1323#
1324# Local procedure:
1325#
746d1df4 1326# create_registers_window - Open up the register display window.
335129a9
SG
1327#
1328# Description:
1329#
1330# Create the register display window, with automatic updates.
1331#
1332
746d1df4
SG
1333proc create_registers_window {} {
1334 global reg_format
1335
1336 if [winfo exists .reg] return
1337
1338# Create an initial register display list consisting of all registers
1339
1340 if ![info exists reg_format] {
1341 global reg_display_list
1342 global changed_reg_list
cb3313c1 1343 global regena
746d1df4
SG
1344
1345 set reg_format {}
1346 set num_regs [llength [gdb_regnames]]
1347 for {set regnum 0} {$regnum < $num_regs} {incr regnum} {
cb3313c1 1348 set regena($regnum) 1
746d1df4
SG
1349 }
1350 recompute_reg_display_list $num_regs
1351 set changed_reg_list $reg_display_list
1352 }
1353
1354 build_framework .reg Registers
1355
86db943c
SG
1356# First, delete all the old menu entries
1357
1358 .reg.menubar.view.menu delete 0 last
746d1df4
SG
1359
1360# Hex menu item
86db943c
SG
1361 .reg.menubar.view.menu add radiobutton -variable reg_format \
1362 -label Hex -value x -command {update_registers all}
746d1df4 1363
746d1df4 1364# Decimal menu item
86db943c
SG
1365 .reg.menubar.view.menu add radiobutton -variable reg_format \
1366 -label Decimal -value d -command {update_registers all}
746d1df4 1367
746d1df4 1368# Octal menu item
86db943c
SG
1369 .reg.menubar.view.menu add radiobutton -variable reg_format \
1370 -label Octal -value o -command {update_registers all}
746d1df4 1371
746d1df4 1372# Natural menu item
86db943c
SG
1373 .reg.menubar.view.menu add radiobutton -variable reg_format \
1374 -label Natural -value {} -command {update_registers all}
746d1df4 1375
86db943c
SG
1376# Config menu item
1377 .reg.menubar.view.menu add separator
1378
1379 .reg.menubar.view.menu add command -label Config -command {
1380 reg_config_menu }
746d1df4
SG
1381
1382 destroy .reg.label
1383
1384# Install the reg names
1385
1386 populate_reg_window
86db943c 1387 update_registers all
746d1df4
SG
1388}
1389
cb3313c1 1390# Convert regena into a list of the enabled $regnums
746d1df4
SG
1391
1392proc recompute_reg_display_list {num_regs} {
1393 global reg_display_list
cb3313c1
SG
1394 global regmap
1395 global regena
746d1df4
SG
1396
1397 catch {unset reg_display_list}
cb3313c1
SG
1398
1399 set line 1
746d1df4 1400 for {set regnum 0} {$regnum < $num_regs} {incr regnum} {
746d1df4 1401
cb3313c1 1402 if {[set regena($regnum)] != 0} {
746d1df4 1403 lappend reg_display_list $regnum
cb3313c1
SG
1404 set regmap($regnum) $line
1405 incr line
746d1df4
SG
1406 }
1407 }
1408}
1409
1410# Fill out the register window with the names of the regs specified in
1411# reg_display_list.
1412
1413proc populate_reg_window {} {
1414 global max_regname_width
1415 global reg_display_list
1416
1417 .reg.text configure -state normal
1418
1419 .reg.text delete 0.0 end
1420
1421 set regnames [eval gdb_regnames $reg_display_list]
1422
1423# Figure out the longest register name
335129a9 1424
746d1df4 1425 set max_regname_width 0
335129a9 1426
746d1df4
SG
1427 foreach reg $regnames {
1428 set len [string length $reg]
1429 if {$len > $max_regname_width} {set max_regname_width $len}
1430 }
1431
1432 set width [expr $max_regname_width + 15]
1433
1434 set height [llength $regnames]
1435
1436 if {$height > 60} {set height 60}
335129a9 1437
746d1df4
SG
1438 .reg.text configure -height $height -width $width
1439
1440 foreach reg $regnames {
1441 .reg.text insert end [format "%-*s \n" $max_regname_width ${reg}]
335129a9 1442 }
746d1df4
SG
1443
1444 .reg.text yview 0
1445 .reg.text configure -state disabled
335129a9
SG
1446}
1447
1448#
1449# Local procedure:
1450#
1451# update_registers - Update the registers window.
1452#
1453# Description:
1454#
1455# This procedure updates the registers window.
1456#
1457
746d1df4
SG
1458proc update_registers {which} {
1459 global max_regname_width
1460 global reg_format
1461 global reg_display_list
1462 global changed_reg_list
1463 global highlight
cb3313c1 1464 global regmap
335129a9 1465
746d1df4 1466 set margin [expr $max_regname_width + 1]
006e71e9 1467 set win .reg.text
746d1df4
SG
1468 set winwidth [lindex [$win configure -width] 4]
1469 set valwidth [expr $winwidth - $margin]
335129a9
SG
1470
1471 $win configure -state normal
1472
746d1df4 1473 if {$which == "all"} {
cb3313c1 1474 set lineindex 1
746d1df4
SG
1475 foreach regnum $reg_display_list {
1476 set regval [gdb_fetch_registers $reg_format $regnum]
1477 set regval [format "%-*s" $valwidth $regval]
cb3313c1
SG
1478 $win delete $lineindex.$margin "$lineindex.0 lineend"
1479 $win insert $lineindex.$margin $regval
1480 incr lineindex
746d1df4
SG
1481 }
1482 $win configure -state disabled
1483 return
1484 }
335129a9 1485
746d1df4
SG
1486# Unhighlight the old values
1487
1488 foreach regnum $changed_reg_list {
1489 $win tag delete $win.$regnum
1490 }
1491
1492# Now, highlight the changed values of the interesting registers
1493
1494 set changed_reg_list [eval gdb_changed_register_list $reg_display_list]
1495
cb3313c1 1496 set lineindex 1
746d1df4
SG
1497 foreach regnum $changed_reg_list {
1498 set regval [gdb_fetch_registers $reg_format $regnum]
1499 set regval [format "%-*s" $valwidth $regval]
cb3313c1
SG
1500
1501 set lineindex $regmap($regnum)
746d1df4
SG
1502 $win delete $lineindex.$margin "$lineindex.0 lineend"
1503 $win insert $lineindex.$margin $regval
1504 $win tag add $win.$regnum $lineindex.0 "$lineindex.0 lineend"
1505 eval $win tag configure $win.$regnum $highlight
1506 }
335129a9 1507
335129a9
SG
1508 $win configure -state disabled
1509}
1510
8532893d
SG
1511#
1512# Local procedure:
1513#
1514# update_assembly - Update the assembly window.
1515#
1516# Description:
1517#
1518# This procedure updates the assembly window.
1519#
1520
1521proc update_assembly {linespec} {
1522 global asm_pointers
1523 global screen_height
1524 global screen_top
1525 global screen_bot
1526 global wins cfunc
1527 global current_label
1528 global win_to_file
1529 global file_to_debug_file
1530 global current_asm_label
1531 global pclist
1532 global asm_screen_height asm_screen_top asm_screen_bot
746d1df4 1533 global .asm.label
8532893d
SG
1534
1535# Rip the linespec apart
1536
1537 set pc [lindex $linespec 4]
1538 set line [lindex $linespec 3]
1539 set filename [lindex $linespec 2]
1540 set funcname [lindex $linespec 1]
1541 set debug_file [lindex $linespec 0]
1542
335129a9 1543 set win [asm_win_name $cfunc]
8532893d
SG
1544
1545# Sometimes there's no source file for this location
1546
1547 if {$filename == ""} {set filename Blank}
1548
1549# If we want to switch funcs, we need to unpack the current text widget, and
1550# stick in the new one.
1551
637b1661 1552 if {$funcname != $cfunc } {
546b8ca7 1553 set oldwin $win
8532893d
SG
1554 set cfunc $funcname
1555
335129a9 1556 set win [asm_win_name $cfunc]
8532893d
SG
1557
1558# Create a text widget for this func if necessary
1559
637b1661
SG
1560 if {![winfo exists $win]} {
1561 create_asm_win $cfunc $pc
8532893d
SG
1562 set asm_pointers($cfunc) 1.1
1563 set current_asm_label NIL
1564 }
1565
1566# Pack the text widget, and scroll to the right place
1567
546b8ca7 1568 pack forget $oldwin
8532893d 1569 pack $win -side left -expand yes -fill both \
006e71e9 1570 -after .asm.scroll
746d1df4 1571 .asm.scroll configure -command "$win yview"
637b1661 1572 set line [pc_to_line $pclist($cfunc) $pc]
0af608b8 1573 update
8532893d
SG
1574 $win yview [expr $line - $asm_screen_height / 2]
1575 }
1576
1577# Update the label widget in case the filename or function name has changed
1578
335129a9 1579 if {$current_asm_label != "$pc $funcname"} then {
746d1df4 1580 set .asm.label "$pc $funcname"
335129a9 1581 set current_asm_label "$pc $funcname"
8532893d
SG
1582 }
1583
1584# Update the pointer, scrolling the text widget if necessary to keep the
1585# pointer in an acceptable part of the screen.
1586
1587 if [info exists asm_pointers($cfunc)] then {
1588 $win configure -state normal
1589 set pointer_pos $asm_pointers($cfunc)
1590 $win configure -state normal
746d1df4
SG
1591 $win delete $pointer_pos "$pointer_pos + 2 char"
1592 $win insert $pointer_pos " "
8532893d
SG
1593
1594# Map the PC back to a line in the window
1595
637b1661 1596 set line [pc_to_line $pclist($cfunc) $pc]
8532893d
SG
1597
1598 if {$line == -1} {
1599 echo "Can't find PC $pc"
1600 return
1601 }
1602
8532893d
SG
1603 set pointer_pos [$win index $line.1]
1604 set asm_pointers($cfunc) $pointer_pos
1605
746d1df4
SG
1606 $win delete $pointer_pos "$pointer_pos + 2 char"
1607 $win insert $pointer_pos "->"
8532893d
SG
1608
1609 if {$line < $asm_screen_top + 1
1610 || $line > $asm_screen_bot} then {
1611 $win yview [expr $line - $asm_screen_height / 2]
1612 }
1613
8532893d
SG
1614 $win configure -state disabled
1615 }
1616}
1617
006e71e9
SG
1618#
1619# Local procedure:
1620#
1621# update_ptr - Update the listing window.
1622#
1623# Description:
1624#
1625# This routine will update the listing window using the result of
1626# gdb_loc.
1627#
1628
8532893d
SG
1629proc update_ptr {} {
1630 update_listing [gdb_loc]
1631 if [winfo exists .asm] {
1632 update_assembly [gdb_loc]
1633 }
335129a9 1634 if [winfo exists .reg] {
746d1df4 1635 update_registers changed
335129a9 1636 }
8532893d
SG
1637}
1638
006e71e9 1639# Make toplevel window disappear
754e5da2 1640
006e71e9 1641wm withdraw .
754e5da2 1642
754e5da2
SG
1643proc files_command {} {
1644 toplevel .files_window
1645
1646 wm minsize .files_window 1 1
1647# wm overrideredirect .files_window true
1648 listbox .files_window.list -geometry 30x20 -setgrid true
1649 button .files_window.close -text Close -command {destroy .files_window}
1650 tk_listboxSingleSelect .files_window.list
1651 eval .files_window.list insert 0 [lsort [gdb_listfiles]]
1652 pack .files_window.list -side top -fill both -expand yes
1653 pack .files_window.close -side bottom -fill x -expand no -anchor s
1654 bind .files_window.list <Any-ButtonRelease-1> {
1655 set file [%W get [%W curselection]]
1656 gdb_cmd "list $file:1,0"
1657 update_listing [gdb_loc $file:1]
1658 destroy .files_window}
1659}
1660
1661button .files -text Files -command files_command
1662
754e5da2
SG
1663# Setup command window
1664
006e71e9 1665proc build_framework {win {title GDBtk} {label {}}} {
746d1df4 1666 global ${win}.label
006e71e9
SG
1667
1668 toplevel ${win}
04576ab6 1669 wm title ${win} $title
006e71e9
SG
1670 wm minsize ${win} 1 1
1671
1672 frame ${win}.menubar
1673
1674 menubutton ${win}.menubar.file -padx 12 -text File \
1675 -menu ${win}.menubar.file.menu -underline 0
1676
1677 menu ${win}.menubar.file.menu
e12533e3
SS
1678 ${win}.menubar.file.menu add command -label File... \
1679 -command {
1680 set filename [FSBox "File" "a.out"]
1681 gdb_cmd "file $filename"
1682 update_ptr
1683 }
1684 ${win}.menubar.file.menu add command -label Target... \
c4a5c37c 1685 -command { not_implemented_yet "target" }
006e71e9
SG
1686 ${win}.menubar.file.menu add command -label Edit \
1687 -command {exec $editor +[expr ($screen_top + $screen_bot)/2] $cfile &}
e12533e3
SS
1688 ${win}.menubar.file.menu add separator
1689 ${win}.menubar.file.menu add command -label "Exec File..." \
1690 -command {
1691 set filename [FSBox "Exec File" "a.out"]
1692 gdb_cmd "exec-file $filename"
1693 update_ptr
1694 }
1695 ${win}.menubar.file.menu add command -label "Symbol File..." \
1696 -command {
1697 set filename [FSBox "Symbol File" "a.out"]
1698 gdb_cmd "symbol-file $filename"
1699 update_ptr
1700 }
1701 ${win}.menubar.file.menu add command -label "Add Symbol File..." \
1702 -command { not_implemented_yet "menu item, add symbol file" }
1703 ${win}.menubar.file.menu add command -label "Core File..." \
1704 -command {
1705 set filename [FSBox "Core File" "core"]
1706 gdb_cmd "core-file $filename"
1707 update_ptr
1708 }
1709 ${win}.menubar.file.menu add separator
006e71e9
SG
1710 ${win}.menubar.file.menu add command -label Close \
1711 -command "destroy ${win}"
e12533e3 1712 ${win}.menubar.file.menu add separator
006e71e9 1713 ${win}.menubar.file.menu add command -label Quit \
e12533e3 1714 -command { catch { gdb_cmd quit } }
006e71e9 1715
c4a5c37c
SS
1716 menubutton ${win}.menubar.commands -padx 12 -text Commands \
1717 -menu ${win}.menubar.commands.menu -underline 0
1718
1719 menu ${win}.menubar.commands.menu
1720 ${win}.menubar.commands.menu add command -label Run \
1721 -command { catch {gdb_cmd run } ; update_ptr }
1722 ${win}.menubar.commands.menu add command -label Step \
1723 -command { catch { gdb_cmd step } ; update_ptr }
1724 ${win}.menubar.commands.menu add command -label Next \
1725 -command { catch { gdb_cmd next } ; update_ptr }
1726 ${win}.menubar.commands.menu add command -label Continue \
1727 -command { catch { gdb_cmd continue } ; update_ptr }
1728 ${win}.menubar.commands.menu add separator
1729 ${win}.menubar.commands.menu add command -label Stepi \
1730 -command { catch { gdb_cmd stepi } ; update_ptr }
1731 ${win}.menubar.commands.menu add command -label Nexti \
1732 -command { catch { gdb_cmd nexti } ; update_ptr }
1733
09722039 1734 menubutton ${win}.menubar.view -padx 12 -text Options \
006e71e9
SG
1735 -menu ${win}.menubar.view.menu -underline 0
1736
1737 menu ${win}.menubar.view.menu
c4a5c37c
SS
1738 ${win}.menubar.view.menu add command -label Hex \
1739 -command {echo Hex}
006e71e9
SG
1740 ${win}.menubar.view.menu add command -label Decimal \
1741 -command {echo Decimal}
c4a5c37c
SS
1742 ${win}.menubar.view.menu add command -label Octal \
1743 -command {echo Octal}
006e71e9
SG
1744
1745 menubutton ${win}.menubar.window -padx 12 -text Window \
1746 -menu ${win}.menubar.window.menu -underline 0
1747
1748 menu ${win}.menubar.window.menu
006e71e9
SG
1749 ${win}.menubar.window.menu add command -label Command \
1750 -command {echo Command}
c4a5c37c
SS
1751 ${win}.menubar.window.menu add separator
1752 ${win}.menubar.window.menu add command -label Source \
1753 -command {echo Source}
006e71e9 1754 ${win}.menubar.window.menu add command -label Assembly \
746d1df4 1755 -command {create_asm_window ; update_ptr}
c4a5c37c
SS
1756 ${win}.menubar.window.menu add separator
1757 ${win}.menubar.window.menu add command -label Registers \
746d1df4 1758 -command {create_registers_window ; update_ptr}
09722039
SG
1759 ${win}.menubar.window.menu add command -label Expressions \
1760 -command {create_expr_win ; update_ptr}
1761
c4a5c37c
SS
1762 ${win}.menubar.window.menu add separator
1763 ${win}.menubar.window.menu add command -label Files \
1764 -command { not_implemented_yet "files window" }
006e71e9
SG
1765
1766 menubutton ${win}.menubar.help -padx 12 -text Help \
1767 -menu ${win}.menubar.help.menu -underline 0
1768
1769 menu ${win}.menubar.help.menu
1770 ${win}.menubar.help.menu add command -label "with GDBtk" \
1771 -command {echo "with GDBtk"}
1772 ${win}.menubar.help.menu add command -label "with this window" \
1773 -command {echo "with this window"}
c981300c
SG
1774 ${win}.menubar.help.menu add command -label "Report bug" \
1775 -command {exec send-pr}
006e71e9 1776
c4a5c37c
SS
1777 tk_menuBar ${win}.menubar \
1778 ${win}.menubar.file \
c4a5c37c
SS
1779 ${win}.menubar.view \
1780 ${win}.menubar.window \
1781 ${win}.menubar.help
1782 pack ${win}.menubar.file \
c4a5c37c
SS
1783 ${win}.menubar.view \
1784 ${win}.menubar.window -side left
1785 pack ${win}.menubar.help -side right
006e71e9
SG
1786
1787 frame ${win}.info
1788 text ${win}.text -height 25 -width 80 -relief raised -borderwidth 2 \
1789 -setgrid true -cursor hand2 -yscrollcommand "${win}.scroll set"
1790
746d1df4
SG
1791 set ${win}.label $label
1792 label ${win}.label -textvariable ${win}.label -borderwidth 2 -relief raised
754e5da2 1793
006e71e9
SG
1794 scrollbar ${win}.scroll -orient vertical -command "${win}.text yview"
1795
1796 pack ${win}.label -side bottom -fill x -in ${win}.info
1797 pack ${win}.scroll -side right -fill y -in ${win}.info
1798 pack ${win}.text -side left -expand yes -fill both -in ${win}.info
1799
1800 pack ${win}.menubar -side top -fill x
1801 pack ${win}.info -side top -fill both -expand yes
1802}
1803
746d1df4
SG
1804proc create_source_window {} {
1805 global wins
1806 global cfile
1807
1808 build_framework .src Source "*No file*"
1809
86db943c
SG
1810# First, delete all the old view menu entries
1811
1812 .src.menubar.view.menu delete 0 last
1813
546b8ca7
SG
1814# Source file selection
1815 .src.menubar.view.menu add command -label "Select source file" \
1816 -command files_command
1817
86db943c
SG
1818# Line numbers enable/disable menu item
1819 .src.menubar.view.menu add checkbutton -variable line_numbers \
1820 -label "Line numbers" -onvalue 1 -offvalue 0 -command {
1821 foreach source [array names wins] {
1822 if {$source == "Blank"} continue
1823 destroy $wins($source)
1824 unset wins($source)
1825 }
1826 set cfile Blank
1827 update_listing [gdb_loc]
1828 }
1829
746d1df4
SG
1830 frame .src.row1
1831 frame .src.row2
1832
1833 button .src.start -width 6 -text Start -command \
86db943c
SG
1834 {catch {gdb_cmd {break main}}
1835 catch {gdb_cmd {enable delete $bpnum}}
1836 catch {gdb_cmd run}
746d1df4
SG
1837 update_ptr }
1838 button .src.stop -width 6 -text Stop -fg red -activeforeground red \
1839 -state disabled -command gdb_stop
1840 button .src.step -width 6 -text Step \
86db943c 1841 -command {catch {gdb_cmd step} ; update_ptr}
746d1df4 1842 button .src.next -width 6 -text Next \
86db943c 1843 -command {catch {gdb_cmd next} ; update_ptr}
746d1df4 1844 button .src.continue -width 6 -text Cont \
86db943c 1845 -command {catch {gdb_cmd continue} ; update_ptr}
746d1df4 1846 button .src.finish -width 6 -text Finish \
86db943c
SG
1847 -command {catch {gdb_cmd finish} ; update_ptr}
1848 button .src.up -width 6 -text Up \
1849 -command {catch {gdb_cmd up} ; update_ptr}
746d1df4 1850 button .src.down -width 6 -text Down \
86db943c 1851 -command {catch {gdb_cmd down} ; update_ptr}
746d1df4 1852 button .src.bottom -width 6 -text Bottom \
86db943c 1853 -command {catch {gdb_cmd {frame 0}} ; update_ptr}
746d1df4
SG
1854
1855 pack .src.start .src.step .src.continue .src.up .src.bottom \
1856 -side left -padx 3 -pady 5 -in .src.row1
1857 pack .src.stop .src.next .src.finish .src.down -side left -padx 3 \
1858 -pady 5 -in .src.row2
1859
86db943c 1860 pack .src.row2 .src.row1 -side bottom -anchor w -before .src.info
746d1df4
SG
1861
1862 $wins($cfile) insert 0.0 " This page intentionally left blank."
1863 $wins($cfile) configure -width 88 -state disabled \
1864 -yscrollcommand textscrollproc
1865
1866 proc textscrollproc {args} {global screen_height screen_top screen_bot
1867 eval ".src.scroll set $args"
1868 set screen_height [lindex $args 1]
1869 set screen_top [lindex $args 2]
1870 set screen_bot [lindex $args 3]}
1871}
754e5da2 1872
746d1df4 1873proc create_command_window {} {
754e5da2
SG
1874 global command_line
1875
746d1df4
SG
1876 build_framework .cmd Command "* Command Buffer *"
1877
754e5da2 1878 set command_line {}
746d1df4
SG
1879
1880 gdb_cmd {set language c}
1881 gdb_cmd {set height 0}
1882 gdb_cmd {set width 0}
1883
1884 bind .cmd.text <Enter> {focus %W}
1885 bind .cmd.text <Delete> {delete_char %W}
1886 bind .cmd.text <BackSpace> {delete_char %W}
1887 bind .cmd.text <Control-u> {delete_line %W}
1888 bind .cmd.text <Any-Key> {
1889 global command_line
1890
1891 %W insert end %A
1892 %W yview -pickplace end
1893 append command_line %A
1894 }
1895 bind .cmd.text <Key-Return> {
1896 global command_line
1897
1898 %W insert end \n
1899 %W yview -pickplace end
546b8ca7 1900 catch "gdb_cmd [list $command_line]"
746d1df4
SG
1901 set command_line {}
1902 update_ptr
1903 %W insert end "(gdb) "
1904 %W yview -pickplace end
1905 }
1906
1907 proc delete_char {win} {
1908 global command_line
1909
1910 tk_textBackspace $win
1911 $win yview -pickplace insert
1912 set tmp [expr [string length $command_line] - 2]
1913 set command_line [string range $command_line 0 $tmp]
754e5da2 1914 }
479f0f18 1915
746d1df4
SG
1916 proc delete_line {win} {
1917 global command_line
754e5da2 1918
746d1df4
SG
1919 $win delete {end linestart + 6 chars} end
1920 $win yview -pickplace insert
1921 set command_line {}
1922 }
754e5da2
SG
1923}
1924
e12533e3
SS
1925#
1926# fileselect.tcl --
1927# simple file selector.
1928#
1929# Mario Jorge Silva msilva@cs.Berkeley.EDU
1930# University of California Berkeley Ph: +1(510)642-8248
1931# Computer Science Division, 571 Evans Hall Fax: +1(510)642-5775
1932# Berkeley CA 94720
1933#
1934#
1935# Copyright 1993 Regents of the University of California
1936# Permission to use, copy, modify, and distribute this
1937# software and its documentation for any purpose and without
1938# fee is hereby granted, provided that this copyright
1939# notice appears in all copies. The University of California
1940# makes no representations about the suitability of this
1941# software for any purpose. It is provided "as is" without
1942# express or implied warranty.
1943#
1944
1945
1946# names starting with "fileselect" are reserved by this module
1947# no other names used.
1948# Hack - FSBox is defined instead of fileselect for backwards compatibility
1949
1950
1951# this is the proc that creates the file selector box
1952# purpose - comment string
1953# defaultName - initial value for name
1954# cmd - command to eval upon OK
1955# errorHandler - command to eval upon Cancel
1956# If neither cmd or errorHandler are specified, the return value
1957# of the FSBox procedure is the selected file name.
1958
1959proc FSBox {{purpose "Select file:"} {defaultName ""} {cmd ""} {errorHandler
1960""}} {
1961 global fileselect
1962 set w .fileSelect
1963 if [Exwin_Toplevel $w "Select File" FileSelect] {
1964 # path independent names for the widgets
1965
1966 set fileselect(list) $w.file.sframe.list
1967 set fileselect(scroll) $w.file.sframe.scroll
1968 set fileselect(direntry) $w.file.f1.direntry
1969 set fileselect(entry) $w.file.f2.entry
1970 set fileselect(ok) $w.but.ok
1971 set fileselect(cancel) $w.but.cancel
1972 set fileselect(msg) $w.label
1973
1974 set fileselect(result) "" ;# value to return if no callback procedures
1975
1976 # widgets
1977 Widget_Label $w label {top fillx pady 10 padx 20} -anchor w -width 24
1978 Widget_Frame $w file Dialog {left expand fill} -bd 10
1979
1980 Widget_Frame $w.file f1 Exmh {top fillx}
1981 Widget_Label $w.file.f1 label {left} -text "Dir"
1982 Widget_Entry $w.file.f1 direntry {right fillx expand} -width 30
1983
1984 Widget_Frame $w.file sframe
1985
1986 scrollbar $w.file.sframe.yscroll -relief sunken \
1987 -command [list $w.file.sframe.list yview]
1988 listbox $w.file.sframe.list -relief sunken \
1989 -yscroll [list $w.file.sframe.yscroll set] -setgrid 1
1990 pack append $w.file.sframe \
1991 $w.file.sframe.yscroll {right filly} \
1992 $w.file.sframe.list {left expand fill}
1993
1994 Widget_Frame $w.file f2 Exmh {top fillx}
1995 Widget_Label $w.file.f2 label {left} -text Name
1996 Widget_Entry $w.file.f2 entry {right fillx expand}
1997
1998 # buttons
1999 $w.but.quit configure -text Cancel \
2000 -command [list fileselect.cancel.cmd $w]
2001
2002 Widget_AddBut $w.but ok OK \
2003 [list fileselect.ok.cmd $w $cmd $errorHandler] {left padx 1}
2004
2005 Widget_AddBut $w.but list List \
2006 [list fileselect.list.cmd $w] {left padx 1}
2007 Widget_CheckBut $w.but listall "List all" fileselect(pattern)
2008 $w.but.listall configure -onvalue "{*,.*}" -offvalue "*" \
2009 -command {fileselect.list.cmd $fileselect(direntry)}
2010 $w.but.listall deselect
2011
2012 # Set up bindings for the browser.
2013 foreach ww [list $w $fileselect(entry)] {
2014 bind $ww <Return> [list $fileselect(ok) invoke]
2015 bind $ww <Control-c> [list $fileselect(cancel) invoke]
2016 }
2017 bind $fileselect(direntry) <Return> [list fileselect.list.cmd %W]
2018 bind $fileselect(direntry) <Tab> [list fileselect.tab.dircmd]
2019 bind $fileselect(entry) <Tab> [list fileselect.tab.filecmd]
2020
2021 tk_listboxSingleSelect $fileselect(list)
2022
2023
2024 bind $fileselect(list) <Button-1> {
2025 # puts stderr "button 1 release"
2026 %W select from [%W nearest %y]
2027 $fileselect(entry) delete 0 end
2028 $fileselect(entry) insert 0 [%W get [%W nearest %y]]
2029 }
2030
2031 bind $fileselect(list) <Key> {
2032 %W select from [%W nearest %y]
2033 $fileselect(entry) delete 0 end
2034 $fileselect(entry) insert 0 [%W get [%W nearest %y]]
2035 }
2036
2037 bind $fileselect(list) <Double-ButtonPress-1> {
2038 # puts stderr "double button 1"
2039 %W select from [%W nearest %y]
2040 $fileselect(entry) delete 0 end
2041 $fileselect(entry) insert 0 [%W get [%W nearest %y]]
2042 $fileselect(ok) invoke
2043 }
2044
2045 bind $fileselect(list) <Return> {
2046 %W select from [%W nearest %y]
2047 $fileselect(entry) delete 0 end
2048 $fileselect(entry) insert 0 [%W get [%W nearest %y]]
2049 $fileselect(ok) invoke
2050 }
2051 }
2052 set fileselect(text) $purpose
2053 $fileselect(msg) configure -text $purpose
2054 $fileselect(entry) delete 0 end
2055 $fileselect(entry) insert 0 [file tail $defaultName]
2056
2057 if {[info exists fileselect(lastDir)] && ![string length $defaultName]} {
2058 set dir $fileselect(lastDir)
2059 } else {
2060 set dir [file dirname $defaultName]
2061 }
2062 set fileselect(pwd) [pwd]
2063 fileselect.cd $dir
2064 $fileselect(direntry) delete 0 end
2065 $fileselect(direntry) insert 0 [pwd]/
2066
2067 $fileselect(list) delete 0 end
2068 $fileselect(list) insert 0 "Big directory:"
2069 $fileselect(list) insert 1 $dir
2070 $fileselect(list) insert 2 "Press Return for Listing"
2071
2072 fileselect.list.cmd $fileselect(direntry) startup
2073
2074 # set kbd focus to entry widget
2075
2076# Exwin_ToplevelFocus $w $fileselect(entry)
2077
2078 # Wait for button hits if no callbacks are defined
2079
2080 if {"$cmd" == "" && "$errorHandler" == ""} {
2081 # wait for the box to be destroyed
2082 update idletask
2083 grab $w
2084 tkwait variable fileselect(result)
2085 grab release $w
2086
2087 set path $fileselect(result)
2088 set fileselect(lastDir) [pwd]
2089 fileselect.cd $fileselect(pwd)
2090 return [string trimright [string trim $path] /]
2091 }
2092 fileselect.cd $fileselect(pwd)
2093 return ""
2094}
2095
2096proc fileselect.cd { dir } {
2097 global fileselect
2098 if [catch {cd $dir} err] {
2099 fileselect.yck $dir
2100 cd
2101 }
2102}
2103# auxiliary button procedures
2104
2105proc fileselect.yck { {tag {}} } {
2106 global fileselect
2107 $fileselect(msg) configure -text "Yck! $tag"
2108}
2109proc fileselect.ok {} {
2110 global fileselect
2111 $fileselect(msg) configure -text $fileselect(text)
2112}
2113
2114proc fileselect.cancel.cmd {w} {
2115 global fileselect
2116 set fileselect(result) {}
2117}
2118
2119proc fileselect.list.cmd {w {state normal}} {
2120 global fileselect
2121 set seldir [$fileselect(direntry) get]
2122 if {[catch {glob $seldir} dir]} {
2123 fileselect.yck "glob failed"
2124 return
2125 }
2126 if {[llength $dir] > 1} {
2127 set dir [file dirname $seldir]
2128 set pat [file tail $seldir]
2129 } else {
2130 set pat $fileselect(pattern)
2131 }
2132 fileselect.ok
2133 update idletasks
2134 if [file isdirectory $dir] {
2135 fileselect.getfiles $dir $pat $state
2136 focus $fileselect(entry)
2137 } else {
2138 fileselect.yck "not a dir"
2139 }
2140}
2141
2142proc fileselect.ok.cmd {w cmd errorHandler} {
2143 global fileselect
2144 set selname [$fileselect(entry) get]
2145 set seldir [$fileselect(direntry) get]
2146
2147 if [string match /* $selname] {
2148 set selected $selname
2149 } else {
2150 if [string match ~* $selname] {
2151 set selected $selname
2152 } else {
2153 set selected $seldir/$selname
2154 }
2155 }
2156
2157 # some nasty file names may cause "file isdirectory" to return an error
2158 if [catch {file isdirectory $selected} isdir] {
2159 fileselect.yck "isdirectory failed"
2160 return
2161 }
2162 if [catch {glob $selected} globlist] {
2163 if ![file isdirectory [file dirname $selected]] {
2164 fileselect.yck "bad pathname"
2165 return
2166 }
2167 set globlist $selected
2168 }
2169 fileselect.ok
2170 update idletasks
2171
2172 if {[llength $globlist] > 1} {
2173 set dir [file dirname $selected]
2174 set pat [file tail $selected]
2175 fileselect.getfiles $dir $pat
2176 return
2177 } else {
2178 set selected $globlist
2179 }
2180 if [file isdirectory $selected] {
2181 fileselect.getfiles $selected $fileselect(pattern)
2182 $fileselect(entry) delete 0 end
2183 return
2184 }
2185
2186 if {$cmd != {}} {
2187 $cmd $selected
2188 } else {
2189 set fileselect(result) $selected
2190 }
2191}
2192
2193proc fileselect.getfiles { dir {pat *} {state normal} } {
2194 global fileselect
2195 $fileselect(msg) configure -text Listing...
2196 update idletasks
2197
2198 set currentDir [pwd]
2199 fileselect.cd $dir
2200 if [catch {set files [lsort [glob -nocomplain $pat]]} err] {
2201 $fileselect(msg) configure -text $err
2202 $fileselect(list) delete 0 end
2203 update idletasks
2204 return
2205 }
2206 switch -- $state {
2207 normal {
2208 # Normal case - show current directory
2209 $fileselect(direntry) delete 0 end
2210 $fileselect(direntry) insert 0 [pwd]/
2211 }
2212 opt {
2213 # Directory already OK (tab related)
2214 }
2215 newdir {
2216 # Changing directory (tab related)
2217 fileselect.cd $currentDir
2218 }
2219 startup {
2220 # Avoid listing huge directories upon startup.
2221 $fileselect(direntry) delete 0 end
2222 $fileselect(direntry) insert 0 [pwd]/
2223 if {[llength $files] > 32} {
2224 fileselect.ok
2225 return
2226 }
2227 }
2228 }
2229
2230 # build a reordered list of the files: directories are displayed first
2231 # and marked with a trailing "/"
2232 if [string compare $dir /] {
2233 fileselect.putfiles $files [expr {($pat == "*") ? 1 : 0}]
2234 } else {
2235 fileselect.putfiles $files
2236 }
2237 fileselect.ok
2238}
2239
2240proc fileselect.putfiles {files {dotdot 0} } {
2241 global fileselect
2242
2243 $fileselect(list) delete 0 end
2244 if {$dotdot} {
2245 $fileselect(list) insert end "../"
2246 }
2247 foreach i $files {
2248 if {[file isdirectory $i]} {
2249 $fileselect(list) insert end $i/
2250 } else {
2251 $fileselect(list) insert end $i
2252 }
2253 }
2254}
2255
2256proc FileExistsDialog { name } {
2257 set w .fileExists
2258 global fileExists
2259 set fileExists(ok) 0
2260 {
2261 message $w.msg -aspect 1000
2262 pack $w.msg -side top -fill both -padx 20 -pady 20
2263 $w.but.quit config -text Cancel -command {FileExistsCancel}
2264 button $w.but.ok -text OK -command {FileExistsOK}
2265 pack $w.but.ok -side left
2266 bind $w.msg <Return> {FileExistsOK}
2267 }
2268 $w.msg config -text "Warning: file exists
2269$name
2270OK to overwrite it?"
2271
2272 set fileExists(focus) [focus]
2273 focus $w.msg
2274 grab $w
2275 tkwait variable fileExists(ok)
2276 grab release $w
2277 return $fileExists(ok)
2278}
2279proc FileExistsCancel {} {
2280 global fileExists
2281 set fileExists(ok) 0
2282}
2283proc FileExistsOK {} {
2284 global fileExists
2285 set fileExists(ok) 1
2286}
2287
2288proc fileselect.getfiledir { dir {basedir [pwd]} } {
2289 global fileselect
2290
2291 set path [$fileselect(direntry) get]
2292 set returnList {}
2293
2294 if {$dir != 0} {
2295 if {[string index $path 0] == "~"} {
2296 set path $path/
2297 }
2298 } else {
2299 set path [$fileselect(entry) get]
2300 }
2301 if [catch {set listFile [glob -nocomplain $path*]}] {
2302 return $returnList
2303 }
2304 foreach el $listFile {
2305 if {$dir != 0} {
2306 if [file isdirectory $el] {
2307 lappend returnList [file tail $el]
2308 }
2309 } elseif ![file isdirectory $el] {
2310 lappend returnList [file tail $el]
2311 }
2312 }
2313
2314 return $returnList
2315}
2316
2317proc fileselect.gethead { list } {
2318 set returnHead ""
2319
2320 for {set i 0} {[string length [lindex $list 0]] > $i}\
2321 {incr i; set returnHead $returnHead$thisChar} {
2322 set thisChar [string index [lindex $list 0] $i]
2323 foreach el $list {
2324 if {[string length $el] < $i} {
2325 return $returnHead
2326 }
2327 if {$thisChar != [string index $el $i]} {
2328 return $returnHead
2329 }
2330 }
2331 }
2332 return $returnHead
2333}
2334
2335proc fileselect.expand.tilde { } {
2336 global fileselect
2337
2338 set entry [$fileselect(direntry) get]
2339 set dir [string range $entry 1 [string length $entry]]
2340
2341 if {$dir == ""} {
2342 return
2343 }
2344
2345 set listmatch {}
2346
2347 ## look in /etc/passwd
2348 if [file exists /etc/passwd] {
2349 if [catch {set users [exec cat /etc/passwd | sed s/:.*//]} err] {
2350 puts "Error\#1 $err"
2351 return
2352 }
2353 set list [split $users "\n"]
2354 }
2355 if {[lsearch -exact $list "+"] != -1} {
2356 if [catch {set users [exec ypcat passwd | sed s/:.*//]} err] {
2357 puts "Error\#2 $err"
2358 return
2359 }
2360 set list [concat $list [split $users "\n"]]
2361 }
2362 $fileselect(list) delete 0 end
2363 foreach el $list {
2364 if [string match $dir* $el] {
2365 lappend listmatch $el
2366 $fileselect(list) insert end $el
2367 }
2368 }
2369 set addings [fileselect.gethead $listmatch]
2370 if {$addings == ""} {
2371 return
2372 }
2373 $fileselect(direntry) delete 0 end
2374 if {[llength $listmatch] == 1} {
2375 $fileselect(direntry) insert 0 [file dirname ~$addings/]
2376 fileselect.getfiles [$fileselect(direntry) get]
2377 } else {
2378 $fileselect(direntry) insert 0 ~$addings
2379 }
2380}
2381
2382proc fileselect.tab.dircmd { } {
2383 global fileselect
2384
2385 set dir [$fileselect(direntry) get]
2386 if {$dir == ""} {
2387 $fileselect(direntry) delete 0 end
2388 $fileselect(direntry) insert 0 [pwd]
2389 if [string compare [pwd] "/"] {
2390 $fileselect(direntry) insert end /
2391 }
2392 return
2393 }
2394 if [catch {set tmp [file isdirectory [file dirname $dir]]}] {
2395 if {[string index $dir 0] == "~"} {
2396 fileselect.expand.tilde
2397 }
2398 return
2399 }
2400 if {!$tmp} {
2401 return
2402 }
2403 set dirFile [fileselect.getfiledir 1 $dir]
2404 if ![llength $dirFile] {
2405 return
2406 }
2407 if {[llength $dirFile] == 1} {
2408 $fileselect(direntry) delete 0 end
2409 $fileselect(direntry) insert 0 [file dirname $dir]
2410 if [string compare [file dirname $dir] /] {
2411 $fileselect(direntry) insert end /[lindex $dirFile 0]/
2412 } else {
2413 $fileselect(direntry) insert end [lindex $dirFile 0]/
2414 }
2415 fileselect.getfiles [$fileselect(direntry) get] \
2416 "[file tail [$fileselect(direntry) get]]$fileselect(pattern)" opt
2417 return
2418 }
2419 set headFile [fileselect.gethead $dirFile]
2420 $fileselect(direntry) delete 0 end
2421 $fileselect(direntry) insert 0 [file dirname $dir]
2422 if [string compare [file dirname $dir] /] {
2423 $fileselect(direntry) insert end /$headFile
2424 } else {
2425 $fileselect(direntry) insert end $headFile
2426 }
2427 if {$headFile == "" && [file isdirectory $dir]} {
2428 fileselect.getfiles $dir\
2429 "[file tail [$fileselect(direntry) get]]$fileselect(pattern)" opt
2430 } else {
2431 fileselect.getfiles [file dirname $dir]\
2432 "[file tail [$fileselect(direntry) get]]*" newdir
2433 }
2434}
2435
2436proc fileselect.tab.filecmd { } {
2437 global fileselect
2438
2439 set dir [$fileselect(direntry) get]
2440 if {$dir == ""} {
2441 set dir [pwd]
2442 }
2443 if {![file isdirectory $dir]} {
2444 error "dir $dir doesn't exist"
2445 }
2446 set listFile [fileselect.getfiledir 0 $dir]
2447 puts $listFile
2448 if ![llength $listFile] {
2449 return
2450 }
2451 if {[llength $listFile] == 1} {
2452 $fileselect(entry) delete 0 end
2453 $fileselect(entry) insert 0 [lindex $listFile 0]
2454 return
2455 }
2456 set headFile [fileselect.gethead $listFile]
2457 $fileselect(entry) delete 0 end
2458 $fileselect(entry) insert 0 $headFile
2459 fileselect.getfiles $dir "[$fileselect(entry) get]$fileselect(pattern)" opt
2460}
2461
2462proc Exwin_Toplevel { path name {class Dialog} {dismiss yes}} {
2463 global exwin
2464 if [catch {wm state $path} state] {
2465 set t [Widget_Toplevel $path $name $class]
2466 if ![info exists exwin(toplevels)] {
2467 set exwin(toplevels) [option get . exwinPaths {}]
2468 }
2469 set ix [lsearch $exwin(toplevels) $t]
2470 if {$ix < 0} {
2471 lappend exwin(toplevels) $t
2472 }
2473 if {$dismiss == "yes"} {
2474 set f [Widget_Frame $t but Menubar {top fill}]
2475 Widget_AddBut $f quit "Dismiss" [list Exwin_Dismiss $path]
2476 }
2477 return 1
2478 } else {
2479 if {$state != "normal"} {
2480 catch {
2481 wm geometry $path $exwin(geometry,$path)
2482# Exmh_Debug Exwin_Toplevel $path $exwin(geometry,$path)
2483 }
2484 wm deiconify $path
2485 } else {
2486 catch {raise $path}
2487 }
2488 return 0
2489 }
2490}
2491
2492proc Exwin_Dismiss { path {geo ok} } {
2493 global exwin
2494 case $geo {
2495 "ok" {
2496 set exwin(geometry,$path) [wm geometry $path]
2497 }
2498 "nosize" {
2499 set exwin(geometry,$path) [string trimleft [wm geometry $path] 0123456789x]
2500 }
2501 default {
2502 catch {unset exwin(geometry,$path)}
2503 }
2504 }
2505 wm withdraw $path
2506}
2507
2508proc Widget_Toplevel { path name {class Dialog} {x {}} {y {}} } {
2509 set self [toplevel $path -class $class]
2510 set usergeo [option get $path position Position]
2511 if {$usergeo != {}} {
2512 if [catch {wm geometry $self $usergeo} err] {
2513# Exmh_Debug Widget_Toplevel $self $usergeo => $err
2514 }
2515 } else {
2516 if {($x != {}) && ($y != {})} {
2517# Exmh_Debug Event position $self +$x+$y
2518 wm geometry $self +$x+$y
2519 }
2520 }
2521 wm title $self $name
2522 wm group $self .
2523 return $self
2524}
2525
2526proc Widget_Frame {par child {class GDB} {where {top expand fill}} args } {
2527 if {$par == "."} {
2528 set self .$child
2529 } else {
2530 set self $par.$child
2531 }
2532 eval {frame $self -class $class} $args
2533 pack append $par $self $where
2534 return $self
2535}
2536
2537proc Widget_AddBut {par but txt cmd {where {right padx 1}} } {
2538 # Create a Packed button. Return the button pathname
2539 set cmd2 [list button $par.$but -text $txt -command $cmd]
2540 if [catch $cmd2 t] {
2541 puts stderr "Widget_AddBut (warning) $t"
2542 eval $cmd2 {-font fixed}
2543 }
2544 pack append $par $par.$but $where
2545 return $par.$but
2546}
2547proc Widget_CheckBut {par but txt var {where {right padx 1}} } {
2548 # Create a check button. Return the button pathname
2549 set cmd [list checkbutton $par.$but -text $txt -variable $var]
2550 if [catch $cmd t] {
2551 puts stderr "Widget_CheckBut (warning) $t"
2552 eval $cmd {-font fixed}
2553 }
2554 pack append $par $par.$but $where
2555 return $par.$but
2556}
2557
2558proc Widget_Label { frame {name label} {where {left fill}} args} {
2559 set cmd [list label $frame.$name ]
2560 if [catch [concat $cmd $args] t] {
2561 puts stderr "Widget_Label (warning) $t"
2562 eval $cmd $args {-font fixed}
2563 }
2564 pack append $frame $frame.$name $where
2565 return $frame.$name
2566}
2567proc Widget_Entry { frame {name entry} {where {left fill}} args} {
2568 set cmd [list entry $frame.$name ]
2569 if [catch [concat $cmd $args] t] {
2570 puts stderr "Widget_Entry (warning) $t"
2571 eval $cmd $args {-font fixed}
2572 }
2573 pack append $frame $frame.$name $where
2574 return $frame.$name
2575}
2576
2577# End of fileselect.tcl.
2578
746d1df4 2579# Setup the initial windows
a5cffdc4 2580
746d1df4
SG
2581create_source_window
2582
2583if {[tk colormodel .src.text] == "color"} {
2584 set highlight "-background red2 -borderwidth 2 -relief sunk"
2585} else {
2586 set fg [lindex [.src.text config -foreground] 4]
2587 set bg [lindex [.src.text config -background] 4]
2588 set highlight "-foreground $bg -background $fg -borderwidth 0"
a5cffdc4 2589}
746d1df4
SG
2590
2591create_command_window
09722039
SG
2592
2593# Create a copyright window
2594
2595toplevel .c
2596wm geometry .c +300+300
2597wm overrideredirect .c true
2598
2599text .t
2600set temp $current_output_win
2601set current_output_win .t
2602gdb_cmd "show version"
2603set current_output_win $temp
2604
2605message .c.m -text [.t get 0.0 end] -aspect 500
2606destroy .t
2607pack .c.m
2608bind .c.m <Leave> {destroy .c}
2609
746d1df4 2610update
This page took 0.147844 seconds and 4 git commands to generate.