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