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