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