1 # GDB GUI setup for GDB, the GNU debugger.
2 # Copyright 1994, 1995, 1996
3 # Free Software Foundation, Inc.
5 # Written by Stu Grossman <grossman@cygnus.com> of Cygnus Support.
7 # This file is part of GDB.
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.
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.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 set wins
($cfile) .src.
text
28 set breakpoint_file
(-1) {[garbage
]}
29 set disassemble_with_source nosource
30 set expr_update_list
(0) 0
34 #option add *Foreground Black
35 #option add *Background White
36 #option add *Font -*-*-medium-r-normal--18-*-*-*-m-*-*-1
38 proc echo
string {puts stdout
$string}
40 # Assign elements from LIST to variables named in ARGS. FIXME replace
41 # with TclX version someday.
42 proc lassign
{list args
} {
43 set len
[expr {[llength $args] - 1}]
45 upvar [lindex $args $len] local
46 set local
[lindex $list $len]
54 # decr (var val) - compliment to incr
59 proc decr
{var
{val
1}} {
61 set num
[expr {$num - $val}]
66 # Center a window on the screen.
68 proc center_window
toplevel {
69 # Withdraw and update, to ensure geometry computations are finished.
73 set x
[expr {[winfo screenwidth
$toplevel] / 2
74 - [winfo reqwidth
$toplevel] / 2
75 - [winfo vrootx
$toplevel]}]
76 set y
[expr {[winfo screenheight
$toplevel] / 2
77 - [winfo reqheight
$toplevel] / 2
78 - [winfo vrooty
$toplevel]}]
79 wm geometry
$toplevel +${x
}+${y
}
80 wm deiconify
$toplevel
84 # Rearrange the bindtags so the widget comes after the class. I was
85 # always for Ousterhout putting the class bindings first, but no...
87 proc bind_widget_after_class
{widget
} {
88 set class
[winfo class
$widget]
90 foreach tag
[bindtags $widget] {
91 if {$tag == $widget} {
96 lappend newList
$widget
100 bindtags $widget $newList
104 # Make sure line number $LINE is visible in the text widget. But be
105 # more clever than the "see" command: if LINE is not currently
106 # displayed, arrange for LINE to be centered. There are cases in
107 # which this does not work, so as a last resort we revert to "see".
109 # This is inefficient, but probably not slow enough to actually
112 proc ensure_line_visible
{text line
} {
113 set pixHeight
[winfo height
$text]
114 # Compute height of widget in lines. This fails if a line is wider
115 # than the screen. FIXME.
116 set topLine
[lindex [split [$text index
@0,0] .
] 0]
117 set botLine
[lindex [split [$text index
@0,${pixHeight
}] .
] 0]
119 if {$line > $topLine && $line < $botLine} then
{
120 # Onscreen, and not on the very edge.
124 set newTop
[expr {$line - ($botLine - $topLine)}]
125 if {$newTop < 0} then
{
128 $text yview moveto
$newTop
130 # In case the above failed.
134 if {[info exists env
(EDITOR
)]} then
{
135 set editor
$env(EDITOR
)
142 # These functions are called by GDB (from C code) to do various things in
143 # TK-land. All start with the prefix `gdbtk_tcl_' to make them easy to find.
149 # gdbtk_tcl_fputs (text) - Output text to the command window
153 # GDB calls this to output TEXT to the GDB command window. The text is
154 # placed at the end of the text widget. Note that output may not occur,
155 # due to buffering. Use gdbtk_tcl_flush to cause an immediate update.
158 proc gdbtk_tcl_fputs
{arg
} {
159 .cmd.
text insert end
"$arg"
163 proc gdbtk_tcl_fputs_error
{arg
} {
164 .cmd.
text insert end
"$arg"
171 # gdbtk_tcl_flush () - Flush output to the command window
175 # GDB calls this to force all buffered text to the GDB command window.
178 proc gdbtk_tcl_flush
{} {
186 # gdbtk_tcl_query (message) - Create a yes/no query dialog box
190 # GDB calls this to create a yes/no dialog box containing MESSAGE. GDB
191 # is hung while the dialog box is active (ie: no commands will work),
192 # however windows can still be refreshed in case of damage or exposure.
195 proc gdbtk_tcl_query
{message} {
196 # FIXME We really want a Help button here. But Tk's brain-damaged
197 # modal dialogs won't really allow it. Should have async dialog
199 set result
[tk_dialog .query
"gdb : query" "$message" questhead
0 Yes No
]
200 return [expr {!$result}]
206 # gdbtk_start_variable_annotation (args ...) -
210 # Not yet implemented.
213 proc gdbtk_tcl_start_variable_annotation
{valaddr ref_type stor_cl
214 cum_expr field type_cast
} {
215 echo
"gdbtk_tcl_start_variable_annotation $valaddr $ref_type $stor_cl $cum_expr $field $type_cast"
221 # gdbtk_end_variable_annotation (args ...) -
225 # Not yet implemented.
228 proc gdbtk_tcl_end_variable_annotation
{} {
229 echo gdbtk_tcl_end_variable_annotation
235 # gdbtk_tcl_breakpoint (action bpnum file line) - Notify the TK
236 # interface of changes to breakpoints.
240 # GDB calls this to notify TK of changes to breakpoints. ACTION is one
242 # create - Notify of breakpoint creation
243 # delete - Notify of breakpoint deletion
244 # modify - Notify of breakpoint modification
247 # file line pc type enabled disposition silent ignore_count commands cond_string thread hit_count
249 proc gdbtk_tcl_breakpoint
{action bpnum
} {
250 set bpinfo
[gdb_get_breakpoint_info
$bpnum]
251 set file [lindex $bpinfo 0]
252 set line
[lindex $bpinfo 1]
253 set pc
[lindex $bpinfo 2]
254 set enable
[lindex $bpinfo 4]
256 if {$action == "modify"} {
257 if {$enable == "1"} {
264 ${action
}_breakpoint
$bpnum $file $line $pc
267 proc create_breakpoints_window
{} {
270 if {[winfo exists .breakpoints
]} {raise .breakpoints
; return}
272 build_framework .breakpoints
"Breakpoints" ""
274 # First, delete all the old view menu entries
276 .breakpoints.menubar.view.
menu delete
0 last
280 destroy .breakpoints.
label
282 # Replace text with a canvas and fix the scrollbars
284 destroy .breakpoints.
text
285 scrollbar .breakpoints.scrollx
-orient horizontal
\
286 -command {.breakpoints.c xview
} -relief sunken
287 canvas .breakpoints.c
-relief sunken
-bd 2 \
289 -yscrollcommand {.breakpoints.scroll
set} \
290 -xscrollcommand {.breakpoints.scrollx
set}
291 .breakpoints.scroll configure
-command {.breakpoints.c yview
}
293 pack .breakpoints.scrollx
-side bottom
-fill x
-in .breakpoints.
info
294 pack .breakpoints.c
-side left
-expand yes
-fill both
\
295 -in .breakpoints.
info
299 # Create a frame for each breakpoint
301 foreach bpnum
[gdb_get_breakpoint_list
] {
302 add_breakpoint_frame
$bpnum
306 # Create a frame for bpnum in the .breakpoints canvas
308 proc add_breakpoint_frame bpnum
{
313 if {![winfo exists .breakpoints
]} return
315 set bpinfo
[gdb_get_breakpoint_info
$bpnum]
317 lassign
$bpinfo file line pc type enabled
($bpnum) disposition
($bpnum) \
318 silent ignore_count commands cond thread hit_count
320 set f .breakpoints.c.
$bpnum
322 if {![winfo exists
$f]} {
323 frame $f -relief sunken
-bd 2
325 label $f.id
-text "#$bpnum $file:$line ($pc)" \
326 -relief flat
-bd 2 -anchor w
328 label $f.hit_count.
label -text "Hit count:" -relief flat
\
329 -bd 2 -anchor w
-width 11
330 label $f.hit_count.val
-text $hit_count -relief flat
\
332 checkbutton $f.hit_count.enabled
-text Enabled
\
333 -variable enabled
($bpnum) -anchor w
-relief flat
335 pack $f.hit_count.
label $f.hit_count.val
-side left
336 pack $f.hit_count.enabled
-side right
339 label $f.thread.
label -text "Thread: " -relief flat
-bd 2 \
341 entry $f.thread.
entry -bd 2 -relief sunken
-width 10
342 $f.thread.
entry insert end
$thread
343 pack $f.thread.
label -side left
344 pack $f.thread.
entry -side left
-fill x
347 label $f.cond.
label -text "Condition: " -relief flat
-bd 2 \
349 entry $f.cond.
entry -bd 2 -relief sunken
350 $f.cond.
entry insert end
$cond
351 pack $f.cond.
label -side left
352 pack $f.cond.
entry -side left
-fill x
-expand yes
354 frame $f.ignore_count
355 label $f.ignore_count.
label -text "Ignore count: " \
356 -relief flat
-bd 2 -width 11 -anchor w
357 entry $f.ignore_count.
entry -bd 2 -relief sunken
-width 10
358 $f.ignore_count.
entry insert end
$ignore_count
359 pack $f.ignore_count.
label -side left
360 pack $f.ignore_count.
entry -side left
-fill x
364 label $f.disps.
label -text "Disposition: " -relief flat
-bd 2 \
367 radiobutton $f.disps.delete
-text Delete
\
368 -variable disposition
($bpnum) -anchor w
-relief flat
\
369 -command "gdb_cmd \"delete break $bpnum\"" \
372 radiobutton $f.disps.disable
-text Disable
\
373 -variable disposition
($bpnum) -anchor w
-relief flat
\
374 -command "gdb_cmd \"disable break $bpnum\"" \
377 radiobutton $f.disps.donttouch
-text "Leave alone" \
378 -variable disposition
($bpnum) -anchor w
-relief flat
\
379 -command "gdb_cmd \"enable break $bpnum\"" \
382 pack $f.disps.
label $f.disps.delete
$f.disps.disable
\
383 $f.disps.donttouch
-side left
-anchor w
384 text $f.commands
-relief sunken
-bd 2 -setgrid true
\
385 -cursor hand2
-height 3 -width 30
387 foreach line
$commands {
388 $f.commands insert end
"${line}\n"
391 pack $f.id
-side top
-anchor nw
-fill x
392 pack $f.hit_count
$f.cond
$f.thread
$f.ignore_count
$f.disps
\
393 $f.commands
-side top
-fill x
-anchor nw
396 set tag
[.breakpoints.c create window
0 $bpframe_lasty -window $f -anchor nw
]
398 set bbox
[.breakpoints.c bbox
$tag]
400 set bpframe_lasty
[lindex $bbox 3]
402 .breakpoints.c configure
-width [lindex $bbox 2]
405 # Delete a breakpoint frame
407 proc delete_breakpoint_frame bpnum
{
410 if {![winfo exists .breakpoints
]} return
412 # First, clear the canvas
414 .breakpoints.c delete all
416 # Now, repopulate it with all but the doomed breakpoint
419 foreach bp
[gdb_get_breakpoint_list
] {
421 add_breakpoint_frame
$bp
426 proc asm_win_name
{funcname
} {
427 if {$funcname == "*None*"} {return .asm.
text}
429 regsub -all {\.
} $funcname _ temp
431 return .asm.func_
${temp
}
437 # create_breakpoint (bpnum file line pc) - Record breakpoint info in TK land
441 # GDB calls this indirectly (through gdbtk_tcl_breakpoint) to notify TK
442 # land of breakpoint creation. This consists of recording the file and
443 # line number in the breakpoint_file and breakpoint_line arrays. Also,
444 # if there is already a window associated with FILE, it is updated with
448 proc create_breakpoint
{bpnum
file line pc
} {
450 global breakpoint_file
451 global breakpoint_line
452 global pos_to_breakpoint
453 global pos_to_bpcount
457 # Record breakpoint locations
459 set breakpoint_file
($bpnum) $file
460 set breakpoint_line
($bpnum) $line
461 set pos_to_breakpoint
($file:$line) $bpnum
462 if {![info exists pos_to_bpcount
($file:$line)]} {
463 set pos_to_bpcount
($file:$line) 0
465 incr pos_to_bpcount
($file:$line)
466 set pos_to_breakpoint
($pc) $bpnum
467 if {![info exists pos_to_bpcount
($pc)]} {
468 set pos_to_bpcount
($pc) 0
470 incr pos_to_bpcount
($pc)
472 # If there's a window for this file, update it
474 if {[info exists wins
($file)]} {
475 insert_breakpoint_tag
$wins($file) $line
478 # If there's an assembly window, update that too
480 set win
[asm_win_name
$cfunc]
481 if {[winfo exists
$win]} {
482 insert_breakpoint_tag
$win [pc_to_line
$pclist($cfunc) $pc]
485 # Update the breakpoints window
487 add_breakpoint_frame
$bpnum
493 # delete_breakpoint (bpnum file line pc) - Delete breakpoint info from TK land
497 # GDB calls this indirectly (through gdbtk_tcl_breakpoint) to notify TK
498 # land of breakpoint destruction. This consists of removing the file and
499 # line number from the breakpoint_file and breakpoint_line arrays. Also,
500 # if there is already a window associated with FILE, the tags are removed
504 proc delete_breakpoint
{bpnum
file line pc
} {
506 global breakpoint_file
507 global breakpoint_line
508 global pos_to_breakpoint
509 global pos_to_bpcount
512 # Save line number and file for later
514 set line
$breakpoint_line($bpnum)
516 set file $breakpoint_file($bpnum)
518 # Reset breakpoint annotation info
520 if {$pos_to_bpcount($file:$line) > 0} {
521 decr pos_to_bpcount
($file:$line)
523 if {$pos_to_bpcount($file:$line) == 0} {
524 catch "unset pos_to_breakpoint($file:$line)"
526 unset breakpoint_file
($bpnum)
527 unset breakpoint_line
($bpnum)
529 # If there's a window for this file, update it
531 if {[info exists wins
($file)]} {
532 delete_breakpoint_tag
$wins($file) $line
537 # If there's an assembly window, update that too
539 if {$pos_to_bpcount($pc) > 0} {
540 decr pos_to_bpcount
($pc)
542 if {$pos_to_bpcount($pc) == 0} {
543 catch "unset pos_to_breakpoint($pc)"
545 set win
[asm_win_name
$cfunc]
546 if {[winfo exists
$win]} {
547 delete_breakpoint_tag
$win [pc_to_line
$pclist($cfunc) $pc]
552 delete_breakpoint_frame
$bpnum
558 # enable_breakpoint (bpnum file line pc) - Record breakpoint info in TK land
562 # GDB calls this indirectly (through gdbtk_tcl_breakpoint) to notify TK
563 # land of a breakpoint being enabled. This consists of unstippling the
564 # specified breakpoint indicator.
567 proc enable_breakpoint
{bpnum
file line pc
} {
572 if {[info exists wins
($file)]} {
573 $wins($file) tag configure
$line -fgstipple {}
576 # If there's an assembly window, update that too
578 set win
[asm_win_name
$cfunc]
579 if {[winfo exists
$win]} {
580 $win tag configure
[pc_to_line
$pclist($cfunc) $pc] -fgstipple {}
583 # If there's a breakpoint window, update that too
585 if {[winfo exists .breakpoints
]} {
586 set enabled
($bpnum) 1
593 # disable_breakpoint (bpnum file line pc) - Record breakpoint info in TK land
597 # GDB calls this indirectly (through gdbtk_tcl_breakpoint) to notify TK
598 # land of a breakpoint being disabled. This consists of stippling the
599 # specified breakpoint indicator.
602 proc disable_breakpoint
{bpnum
file line pc
} {
607 if {[info exists wins
($file)]} {
608 $wins($file) tag configure
$line -fgstipple gray50
611 # If there's an assembly window, update that too
613 set win
[asm_win_name
$cfunc]
614 if {[winfo exists
$win]} {
615 $win tag configure
[pc_to_line
$pclist($cfunc) $pc] -fgstipple gray50
618 # If there's a breakpoint window, update that too
620 if {[winfo exists .breakpoints
]} {
621 set enabled
($bpnum) 0
628 # insert_breakpoint_tag (win line) - Insert a breakpoint tag in WIN.
632 # GDB calls this indirectly (through gdbtk_tcl_breakpoint) to insert a
633 # breakpoint tag into window WIN at line LINE.
636 proc insert_breakpoint_tag
{win line
} {
637 $win configure
-state normal
639 $win insert
$line.0 "B"
640 $win tag add margin
$line.0 $line.8
642 $win configure
-state disabled
648 # delete_breakpoint_tag (win line) - Remove a breakpoint tag from WIN.
652 # GDB calls this indirectly (through gdbtk_tcl_breakpoint) to remove a
653 # breakpoint tag from window WIN at line LINE.
656 proc delete_breakpoint_tag
{win line
} {
657 $win configure
-state normal
659 if {[string range
$win 0 3] == ".src"} then
{
660 $win insert
$line.0 "\xa4"
662 $win insert
$line.0 " "
664 $win tag add margin
$line.0 $line.8
665 $win configure
-state disabled
668 proc gdbtk_tcl_busy
{} {
669 if {[winfo exists .cmd
]} {
670 .cmd.
text configure
-state disabled
672 if {[winfo exists .src
]} {
673 .src.start configure
-state disabled
674 .src.stop configure
-state normal
675 .src.step configure
-state disabled
676 .src.next configure
-state disabled
677 .src.
continue configure
-state disabled
678 .src.finish configure
-state disabled
679 .src.up configure
-state disabled
680 .src.down configure
-state disabled
681 .src.bottom configure
-state disabled
683 if {[winfo exists .asm
]} {
684 .asm.stepi configure
-state disabled
685 .asm.nexti configure
-state disabled
686 .asm.
continue configure
-state disabled
687 .asm.finish configure
-state disabled
688 .asm.up configure
-state disabled
689 .asm.down configure
-state disabled
690 .asm.bottom configure
-state disabled
695 proc gdbtk_tcl_idle
{} {
696 if {[winfo exists .cmd
]} {
697 .cmd.
text configure
-state normal
699 if {[winfo exists .src
]} {
700 .src.start configure
-state normal
701 .src.stop configure
-state disabled
702 .src.step configure
-state normal
703 .src.next configure
-state normal
704 .src.
continue configure
-state normal
705 .src.finish configure
-state normal
706 .src.up configure
-state normal
707 .src.down configure
-state normal
708 .src.bottom configure
-state normal
710 if {[winfo exists .asm
]} {
711 .asm.stepi configure
-state normal
712 .asm.nexti configure
-state normal
713 .asm.
continue configure
-state normal
714 .asm.finish configure
-state normal
715 .asm.up configure
-state normal
716 .asm.down configure
-state normal
717 .asm.bottom configure
-state normal
725 # pc_to_line (pclist pc) - convert PC to a line number.
729 # Convert PC to a line number from PCLIST. If exact line isn't found,
730 # we return the first line that starts before PC.
732 proc pc_to_line
{pclist pc
} {
733 set line
[lsearch -exact $pclist $pc]
735 if {$line >= 1} { return $line }
738 foreach linepc
[lrange $pclist 1 end
] {
739 if {$pc < $linepc} { decr line
; return $line }
742 return [expr {$line - 1}]
748 # file popup menu - Define the file popup menu.
752 # This menu just contains a bunch of buttons that do various things to
753 # the line under the cursor.
757 # Edit - Run the editor (specified by the environment variable EDITOR) on
758 # this file, at the current line.
759 # Breakpoint - Set a breakpoint at the current line. This just shoves
760 # a `break' command at GDB with the appropriate file and line
761 # number. Eventually, GDB calls us back (at gdbtk_tcl_breakpoint)
762 # to notify us of where the breakpoint needs to show up.
765 menu .file_popup
-cursor hand2
-tearoff 0
766 .file_popup add command
-label "Not yet set" -state disabled
767 .file_popup add separator
768 .file_popup add command
-label "Edit" \
769 -command {exec $editor +$selected_line $selected_file &}
770 .file_popup add command
-label "Set breakpoint" \
771 -command {gdb_cmd
"break $selected_file:$selected_line"}
773 # Use this procedure to get the GDB core to execute the string `cmd'. This is
774 # a wrapper around gdb_cmd, which will catch errors, and send output to the
775 # command window. It will also cause all of the other windows to be updated.
777 proc interactive_cmd
{cmd
} {
778 catch {gdb_cmd
"$cmd"} result
779 .cmd.
text insert end
$result
787 # file popup menu - Define the file popup menu bindings.
791 # This defines the binding for the file popup menu. It simply
792 # unhighlights the line under the cursor.
795 bind .file_popup
<Any-ButtonRelease-1
> {
797 # Unhighlight the selected line
798 $selected_win tag delete breaktag
804 # listing_window_popup (win x y xrel yrel) - Handle popups for listing window
808 # This procedure is invoked by holding down button 2 (usually) in the
809 # listing window. The action taken depends upon where the button was
810 # pressed. If it was in the left margin (the breakpoint column), it
811 # sets or clears a breakpoint. In the main text area, it will pop up a
815 proc listing_window_popup
{win x y xrel yrel
} {
818 global file_to_debug_file
823 global pos_to_breakpoint
825 # Map TK window name back to file name.
827 set file $win_to_file($win)
829 set pos
[split [$win index
@$xrel,$yrel] .
]
831 # Record selected file and line for menu button actions
833 set selected_file
$file_to_debug_file($file)
834 set selected_line
[lindex $pos 0]
835 set selected_col
[lindex $pos 1]
836 set selected_win
$win
838 # Post the menu near the pointer, (and grab it)
840 .file_popup entryconfigure
0 -label "$selected_file:$selected_line"
842 tk_popup .file_popup
$x $y
848 # toggle_breakpoint (win x y xrel yrel) - Handle clicks on breakdots
852 # This procedure sets or clears breakpoints where the button clicked.
855 proc toggle_breakpoint
{win x y xrel yrel
} {
858 global file_to_debug_file
863 global pos_to_breakpoint
865 # Map TK window name back to file name.
867 set file $win_to_file($win)
869 set pos
[split [$win index
@$xrel,$yrel] .
]
871 # Record selected file and line
873 set selected_file
$file_to_debug_file($file)
874 set selected_line
[lindex $pos 0]
875 set selected_col
[lindex $pos 1]
876 set selected_win
$win
878 # If we're in the margin, then toggle the breakpoint
880 if {$selected_col < 8} { # this is alway true actually
881 set pos_break
$selected_file:$selected_line
882 set pos
$file:$selected_line
883 set tmp pos_to_breakpoint
($pos)
884 if {[info exists
$tmp]} {
886 gdb_cmd
"delete $bpnum"
888 gdb_cmd
"break $pos_break"
897 # asm_window_button_1 (win x y xrel yrel) - Handle button 1 in asm window
901 # This procedure is invoked as a result of holding down button 1 in the
902 # assembly window. The action taken depends upon where the button was
903 # pressed. If it was in the left margin (the breakpoint column), it
904 # sets or clears a breakpoint. In the main text area, it will pop up a
908 proc asm_window_button_1
{win x y xrel yrel
} {
911 global file_to_debug_file
916 global pos_to_breakpoint
920 set pos
[split [$win index
@$xrel,$yrel] .
]
922 # Record selected file and line for menu button actions
924 set selected_line
[lindex $pos 0]
925 set selected_col
[lindex $pos 1]
926 set selected_win
$win
930 set pc
[lindex $pclist($cfunc) $selected_line]
932 # If we're in the margin, then toggle the breakpoint
934 if {$selected_col < 11} {
935 set tmp pos_to_breakpoint
($pc)
936 if {[info exists
$tmp]} {
938 gdb_cmd
"delete $bpnum"
945 # Post the menu near the pointer, (and grab it)
947 # .file_popup entryconfigure 0 -label "$selected_file:$selected_line"
948 # .file_popup post [expr $x-[winfo width .file_popup]/2] [expr $y-10]
955 # do_nothing - Does absolutely nothing.
959 # This procedure does nothing. It is used as a placeholder to allow
960 # the disabling of bindings that would normally be inherited from the
961 # parent widget. I can't think of any other way to do this.
964 proc do_nothing
{} {}
969 # not_implemented_yet - warn that a feature is unavailable
973 # This procedure warns that something doesn't actually work yet.
976 proc not_implemented_yet
{message} {
977 tk_dialog .unimpl
"gdb : unimpl" \
978 "$message: not implemented in the interface yet" \
985 # create_expr_window - Create expression display window
989 # Create the expression display window.
993 set delete_expr_num
0
995 # Set delete_expr_num, and set -state of Delete button.
996 proc expr_update_button
{num
} {
997 global delete_expr_num
998 set delete_expr_num
$num
1004 .
expr.buts.delete configure
-state $state
1007 proc add_expr
{expr} {
1008 global expr_update_list
1016 checkbutton $e.updates.
$f -text "" -relief flat
\
1017 -variable expr_update_list
($expr_num)
1018 text $e.expressions.
$f -width 20 -height 1
1019 $e.expressions.
$f insert
0.0 $expr
1020 bind $e.expressions.
$f <1> "update_expr $expr_num"
1021 text $e.values.
$f -width 20 -height 1
1023 # Set up some bindings.
1024 foreach frame {updates expressions values
} {
1025 bind $e.
$frame.
$f <FocusIn
> "expr_update_button $expr_num"
1026 bind $e.
$frame.
$f <FocusOut
> "expr_update_button 0"
1029 update_expr
$expr_num
1031 pack $e.updates.
$f -side top
1032 pack $e.expressions.
$f -side top
-expand yes
-fill x
1033 pack $e.values.
$f -side top
-expand yes
-fill x
1036 proc delete_expr
{} {
1037 global delete_expr_num
1038 if {$delete_expr_num > 0} then
{
1040 set f e
${delete_expr_num
}
1042 destroy $e.updates.
$f $e.expressions.
$f $e.values.
$f
1044 # FIXME should we unset an element of expr_update_list here?
1048 proc update_expr
{expr_num
} {
1049 global expr_update_list
1054 set expr [$e.expressions.
$f get
0.0 end
]
1055 $e.values.
$f delete
0.0 end
1056 if {! [catch {gdb_eval
$expr} val
]} {
1057 $e.values.
$f insert
0.0 $val
1059 # FIXME consider flashing widget here.
1063 proc update_exprs
{} {
1064 global expr_update_list
1066 foreach expr_num
[array names expr_update_list
] {
1067 if {$expr_update_list($expr_num)} {
1068 update_expr
$expr_num
1073 proc create_expr_window
{} {
1075 if {[winfo exists .
expr]} {raise .
expr ; return}
1078 wm title .
expr "GDB Expressions"
1079 wm iconname .
expr "Expressions"
1081 frame .
expr.entryframe
-borderwidth 2 -relief raised
1082 label .
expr.entryframe.entrylab
-text "Expression: "
1083 entry .
expr.entryframe.
entry -borderwidth 2 -relief sunken
1084 bind .
expr.entryframe.
entry <Return
> {
1085 add_expr
[.
expr.entryframe.
entry get
]
1086 .
expr.entryframe.
entry delete
0 end
1089 pack .
expr.entryframe.entrylab
-side left
1090 pack .
expr.entryframe.
entry -side left
-fill x
-expand yes
1092 frame .
expr.buts
-borderwidth 2 -relief raised
1094 button .
expr.buts.delete
-text Delete
-command delete_expr
\
1097 button .
expr.buts.
close -text Close
-command {destroy .
expr}
1098 button .
expr.buts.help
-text Help
-state disabled
1100 pack .
expr.buts.delete
-side left
1101 pack .
expr.buts.help .
expr.buts.
close -side right
1103 pack .
expr.buts
-side bottom
-fill x
1104 pack .
expr.entryframe
-side bottom
-fill x
1106 frame .
expr.exprs
-borderwidth 2 -relief raised
1108 # Use three subframes so columns will line up. Easier than
1109 # dealing with BLT for a table geometry manager. Someday Tk
1110 # will have one, use it then. FIXME this messes up keyboard
1112 frame .
expr.exprs.updates
-borderwidth 0 -relief flat
1113 frame .
expr.exprs.expressions
-borderwidth 0 -relief flat
1114 frame .
expr.exprs.values
-borderwidth 0 -relief flat
1116 label .
expr.exprs.updates.
label -text Update
1117 pack .
expr.exprs.updates.
label -side top
-anchor w
1118 label .
expr.exprs.expressions.
label -text Expression
1119 pack .
expr.exprs.expressions.
label -side top
-anchor w
1120 label .
expr.exprs.values.
label -text Value
1121 pack .
expr.exprs.values.
label -side top
-anchor w
1123 pack .
expr.exprs.updates
-side left
1124 pack .
expr.exprs.values .
expr.exprs.expressions
\
1125 -side right
-expand 1 -fill x
1127 pack .
expr.exprs
-side top
-fill both
-expand 1 -anchor w
1133 # display_expression (expression) - Display EXPRESSION in display window
1137 # Display EXPRESSION and its value in the expression display window.
1140 proc display_expression
{expression
} {
1143 add_expr
$expression
1149 # create_file_win (filename) - Create a win for FILENAME.
1153 # The new text widget.
1157 # This procedure creates a text widget for FILENAME. It returns the
1158 # newly created widget. First, a text widget is created, and given basic
1159 # configuration info. Second, all the bindings are setup. Third, the
1160 # file FILENAME is read into the text widget. Fourth, margins and line
1161 # numbers are added.
1164 proc create_file_win
{filename debug_file
} {
1165 global breakpoint_file
1166 global breakpoint_line
1168 global debug_interface
1170 # Replace all the dirty characters in $filename with clean ones, and generate
1171 # a unique name for the text widget.
1173 regsub -all {\.
} $filename {} temp
1174 set win .src.
text$temp
1176 # Open the file, and read it into the text widget
1178 if {[catch "open $filename" fh
]} {
1179 # File can't be read. Put error message into .src.nofile window and return.
1181 catch {destroy .src.nofile
}
1182 text .src.nofile
-height 25 -width 88 -relief sunken
\
1183 -borderwidth 2 -yscrollcommand ".src.scroll set" \
1184 -setgrid true
-cursor hand2
1185 .src.nofile insert
0.0 $fh
1186 .src.nofile configure
-state disabled
1187 bind .src.nofile
<1> do_nothing
1188 bind .src.nofile
<B1-Motion
> do_nothing
1192 # Actually create and do basic configuration on the text widget.
1194 text $win -height 25 -width 88 -relief sunken
-borderwidth 2 \
1195 -yscrollcommand ".src.scroll set" -setgrid true
-cursor hand2
1197 # Setup all the bindings
1199 bind $win <Enter
> {focus %W
}
1200 bind $win <1> do_nothing
1201 bind $win <B1-Motion
> do_nothing
1203 bind $win <Key-Alt_R
> do_nothing
1204 bind $win <Key-Alt_L
> do_nothing
1205 bind $win <Key-Prior
> "$win yview {@0,0 - 10 lines}"
1206 bind $win <Key-Next
> "$win yview {@0,0 + 10 lines}"
1207 bind $win <Key-Up
> "$win yview {@0,0 - 1 lines}"
1208 bind $win <Key-Down
> "$win yview {@0,0 + 1 lines}"
1209 bind $win <Key-Home
> {update_listing
[gdb_loc
]}
1210 bind $win <Key-End
> "$win see end"
1212 bind $win n
{interactive_cmd next
}
1213 bind $win s
{interactive_cmd step
}
1214 bind $win c
{interactive_cmd
continue}
1215 bind $win f
{interactive_cmd finish
}
1216 bind $win u
{interactive_cmd up
}
1217 bind $win d
{interactive_cmd down
}
1219 if $debug_interface {
1220 bind $win <Control-C
> {
1226 $win insert
0.0 [read $fh]
1229 # Add margins (for annotations) and a line number to each line (if requested)
1231 set numlines
[$win index end
]
1232 set numlines
[lindex [split $numlines .
] 0]
1233 if {$line_numbers} {
1234 for {set i
1} {$i <= $numlines} {incr i
} {
1235 $win insert
$i.0 [format " %4d " $i]
1236 $win tag add
source $i.8 "$i.0 lineend"
1239 for {set i
1} {$i <= $numlines} {incr i
} {
1240 $win insert
$i.0 " "
1241 $win tag add
source $i.8 "$i.0 lineend"
1247 foreach i
[gdb_sourcelines
$debug_file] {
1249 $win insert
$i.0 "\xa4"
1250 $win tag add margin
$i.0 $i.8
1253 # A debugging trick to highlight sensitive regions.
1254 if $debug_interface {
1255 $win tag
bind source <Enter
> {
1256 %W tag configure
source -background yellow
1258 $win tag
bind source <Leave
> {
1259 %W tag configure
source -background green
1261 $win tag
bind margin
<Enter
> {
1262 %W tag configure margin
-background red
1264 $win tag
bind margin
<Leave
> {
1265 %W tag configure margin
-background skyblue
1269 $win tag
bind margin
<1> {
1270 toggle_breakpoint
%W
%X
%Y
%x
%y
1273 $win tag
bind source <1> {
1274 %W mark
set anchor
"@%x,%y wordstart"
1275 set last
[%W index
"@%x,%y wordend"]
1276 %W tag remove sel
0.0 anchor
1277 %W tag remove sel
$last end
1278 %W tag add sel anchor
$last
1280 # $win tag bind source <Double-Button-1> {
1281 # %W mark set anchor "@%x,%y wordstart"
1282 # set last [%W index "@%x,%y wordend"]
1283 # %W tag remove sel 0.0 anchor
1284 # %W tag remove sel $last end
1285 # %W tag add sel anchor $last
1286 # echo "Selected [selection get]"
1288 $win tag
bind source <B1-Motion
> {
1289 %W tag remove sel
0.0 anchor
1290 %W tag remove sel
$last end
1291 %W tag add sel anchor
@%x
,%y
1293 $win tag
bind sel
<1> break
1294 $win tag
bind sel
<Double-Button-1
> {
1295 display_expression
[selection get
]
1298 $win tag
bind sel
<B1-Motion
> break
1301 $win tag
bind source <2> {
1302 listing_window_popup
%W
%X
%Y
%x
%y
1305 # Make these bindings do nothing on the text window -- they
1306 # are completely handled by the tag bindings above.
1308 bind $win <B1-Motion
> break
1309 bind $win <Double-Button-1
> break
1311 # Scan though the breakpoint data base and install any destined for this file
1313 foreach bpnum
[array names breakpoint_file
] {
1314 if {$breakpoint_file($bpnum) == $filename} {
1315 insert_breakpoint_tag
$win $breakpoint_line($bpnum)
1319 # Disable the text widget to prevent user modifications
1321 $win configure
-state disabled
1328 # create_asm_win (funcname pc) - Create an assembly win for FUNCNAME.
1332 # The new text widget.
1336 # This procedure creates a text widget for FUNCNAME. It returns the
1337 # newly created widget. First, a text widget is created, and given basic
1338 # configuration info. Second, all the bindings are setup. Third, the
1339 # function FUNCNAME is read into the text widget.
1342 proc create_asm_win
{funcname pc
} {
1343 global breakpoint_file
1344 global breakpoint_line
1346 global disassemble_with_source
1348 # Replace all the dirty characters in $filename with clean ones, and generate
1349 # a unique name for the text widget.
1351 set win
[asm_win_name
$funcname]
1353 # Actually create and do basic configuration on the text widget.
1355 text $win -height 25 -width 80 -relief sunken
-borderwidth 2 \
1356 -setgrid true
-cursor hand2
-yscrollcommand ".asm.scroll set"
1358 # Setup all the bindings
1360 bind $win <Enter
> {focus %W
}
1361 bind $win <1> {asm_window_button_1
%W
%X
%Y
%x
%y
; break}
1362 bind $win <B1-Motion
> break
1363 bind $win <Double-Button-1
> break
1365 bind $win <Key-Alt_R
> do_nothing
1366 bind $win <Key-Alt_L
> do_nothing
1368 bind $win n
{interactive_cmd nexti
}
1369 bind $win s
{interactive_cmd stepi
}
1370 bind $win c
{interactive_cmd
continue}
1371 bind $win f
{interactive_cmd finish
}
1372 bind $win u
{interactive_cmd up
}
1373 bind $win d
{interactive_cmd down
}
1375 # Disassemble the code, and read it into the new text widget
1377 $win insert end
[gdb_disassemble
$disassemble_with_source $pc]
1379 set numlines
[$win index end
]
1380 set numlines
[lindex [split $numlines .
] 0]
1383 # Delete the first and last lines, cuz these contain useless info
1385 # $win delete 1.0 2.0
1386 # $win delete {end - 1 lines} end
1389 # Add margins (for annotations) and note the PC for each line
1391 catch "unset pclist($funcname)"
1392 lappend pclist
($funcname) Unused
1393 for {set i
1} {$i <= $numlines} {incr i
} {
1394 scan [$win get
$i.0 "$i.0 lineend"] "%s " pc
1395 lappend pclist
($funcname) $pc
1396 $win insert
$i.0 " "
1399 # Scan though the breakpoint data base and install any destined for this file
1401 # foreach bpnum [array names breakpoint_file] {
1402 # if {$breakpoint_file($bpnum) == $filename} {
1403 # insert_breakpoint_tag $win $breakpoint_line($bpnum)
1407 # Disable the text widget to prevent user modifications
1409 $win configure
-state disabled
1416 # update_listing (linespec) - Update the listing window according to
1421 # This procedure is called from various places to update the listing
1422 # window based on LINESPEC. It is usually invoked with the result of
1425 # It will move the cursor, and scroll the text widget if necessary.
1426 # Also, it will switch to another text widget if necessary, and update
1427 # the label widget too.
1429 # LINESPEC is a list of the form:
1431 # { DEBUG_FILE FUNCNAME FILENAME LINE }, where:
1433 # DEBUG_FILE - is the abbreviated form of the file name. This is usually
1434 # the file name string given to the cc command. This is
1435 # primarily needed for breakpoint commands, and when an
1436 # abbreviated for of the filename is desired.
1437 # FUNCNAME - is the name of the function.
1438 # FILENAME - is the fully qualified (absolute) file name. It is usually
1439 # the same as $PWD/$DEBUG_FILE, where PWD is the working dir
1440 # at the time the cc command was given. This is used to
1441 # actually locate the file to be displayed.
1442 # LINE - The line number to be displayed.
1444 # Usually, this procedure will just move the cursor one line down to the
1445 # next line to be executed. However, if the cursor moves out of range
1446 # or into another file, it will scroll the text widget so that the line
1447 # of interest is in the middle of the viewable portion of the widget.
1450 proc update_listing
{linespec
} {
1453 global current_label
1455 global file_to_debug_file
1458 # Rip the linespec apart
1460 lassign
$linespec debug_file funcname
filename line
1462 # Sometimes there's no source file for this location
1464 if {$filename == ""} {set filename Blank
}
1466 # If we want to switch files, we need to unpack the current text widget, and
1467 # stick in the new one.
1469 if {$filename != $cfile} then
{
1470 pack forget
$wins($cfile)
1473 # Create a text widget for this file if necessary
1475 if {![info exists wins
($cfile)]} then
{
1476 set wins
($cfile) [create_file_win
$cfile $debug_file]
1477 if {$wins($cfile) != ".src.nofile"} {
1478 set win_to_file
($wins($cfile)) $cfile
1479 set file_to_debug_file
($cfile) $debug_file
1480 set pointers
($cfile) 1.1
1484 # Pack the text widget into the listing widget, and scroll to the right place
1486 pack $wins($cfile) -side left
-expand yes
-in .src.
info \
1487 -fill both
-after .src.scroll
1489 # Make the scrollbar point at the new text widget
1491 .src.scroll configure
-command "$wins($cfile) yview"
1493 # $wins($cfile) see "${line}.0 linestart"
1494 ensure_line_visible
$wins($cfile) $line
1497 # Update the label widget in case the filename or function name has changed
1499 if {$current_label != "$filename.$funcname"} then
{
1500 set tail
[expr [string last
/ $filename] + 1]
1501 set .src.
label "[string range $filename $tail end] : ${funcname}()"
1502 # .src.label configure -text "[string range $filename $tail end] : ${funcname}()"
1503 set current_label
$filename.
$funcname
1506 # Update the pointer, scrolling the text widget if necessary to keep the
1507 # pointer in an acceptable part of the screen.
1509 if {[info exists pointers
($cfile)]} then
{
1510 $wins($cfile) configure
-state normal
1511 set pointer_pos
$pointers($cfile)
1512 $wins($cfile) configure
-state normal
1513 $wins($cfile) delete
$pointer_pos "$pointer_pos + 2 char"
1514 $wins($cfile) insert
$pointer_pos " "
1516 set pointer_pos
[$wins($cfile) index
$line.1]
1517 set pointers
($cfile) $pointer_pos
1519 $wins($cfile) delete
$pointer_pos "$pointer_pos + 2 char"
1520 $wins($cfile) insert
$pointer_pos "->"
1521 ensure_line_visible
$wins($cfile) $line
1522 $wins($cfile) configure
-state disabled
1529 # create_asm_window - Open up the assembly window.
1533 # Create an assembly window if it doesn't exist.
1536 proc create_asm_window
{} {
1539 if {[winfo exists .asm
]} {raise .asm
; return}
1542 set win
[asm_win_name
$cfunc]
1544 build_framework .asm Assembly
"*NIL*"
1546 # First, delete all the old menu entries
1548 .asm.menubar.view.
menu delete
0 last
1550 .asm.
text configure
-yscrollcommand ".asm.scroll set"
1555 button .asm.stepi
-width 6 -text Stepi
\
1556 -command {interactive_cmd stepi
}
1557 button .asm.nexti
-width 6 -text Nexti
\
1558 -command {interactive_cmd nexti
}
1559 button .asm.
continue -width 6 -text Cont
\
1560 -command {interactive_cmd
continue}
1561 button .asm.finish
-width 6 -text Finish
\
1562 -command {interactive_cmd finish
}
1563 button .asm.up
-width 6 -text Up
-command {interactive_cmd up
}
1564 button .asm.down
-width 6 -text Down
\
1565 -command {interactive_cmd down
}
1566 button .asm.bottom
-width 6 -text Bottom
\
1567 -command {interactive_cmd
{frame 0}}
1569 pack .asm.stepi .asm.
continue .asm.up .asm.bottom
-side left
-padx 3 -pady 5 -in .asm.row1
1570 pack .asm.nexti .asm.finish .asm.down
-side left
-padx 3 -pady 5 -in .asm.row2
1572 pack .asm.row2 .asm.row1
-side bottom
-anchor w
-before .asm.
info
1576 update_assembly
[gdb_loc
]
1578 # We do this update_assembly to get the proper value of disassemble-from-exec.
1580 # exec file menu item
1581 .asm.menubar.view.
menu add
radiobutton -label "Exec file" \
1582 -variable disassemble-from-exec
-value 1
1583 # target memory menu item
1584 .asm.menubar.view.
menu add
radiobutton -label "Target memory" \
1585 -variable disassemble-from-exec
-value 0
1587 # Disassemble with source
1588 .asm.menubar.view.
menu add
checkbutton -label "Source" \
1589 -variable disassemble_with_source
-onvalue source \
1590 -offvalue nosource
-command {
1591 foreach asm
[info command .asm.func_
*] {
1595 update_assembly
[gdb_loc
]
1599 proc reg_config_menu
{} {
1600 catch {destroy .reg.config
}
1601 toplevel .reg.config
1602 wm geometry .reg.config
+300+300
1603 wm title .reg.config
"Register configuration"
1604 wm iconname .reg.config
"Reg config"
1605 set regnames
[gdb_regnames
]
1606 set num_regs
[llength $regnames]
1608 frame .reg.config.buts
1610 button .reg.config.done
-text " Done " -command "
1611 recompute_reg_display_list $num_regs
1613 update_registers all
1614 destroy .reg.config "
1616 button .reg.config.
update -text Update
-command "
1617 recompute_reg_display_list $num_regs
1619 update_registers all "
1621 pack .reg.config.buts
-side bottom
-fill x
1623 pack .reg.config.done
-side left
-fill x
-expand yes
-in .reg.config.buts
1624 pack .reg.config.
update -side right
-fill x
-expand yes
-in .reg.config.buts
1626 # Since there can be lots of registers, we build the window with no more than
1627 # 32 rows, and as many columns as needed.
1629 # First, figure out how many columns we need and create that many column frame
1632 set ncols
[expr ($num_regs + 31) / 32]
1634 for {set col
0} {$col < $ncols} {incr col
} {
1635 frame .reg.config.col
$col
1636 pack .reg.config.col
$col -side left
-anchor n
1639 # Now, create the checkbutton widgets and pack them in the appropriate columns
1643 for {set regnum
0} {$regnum < $num_regs} {incr regnum
} {
1644 set regname
[lindex $regnames $regnum]
1645 checkbutton .reg.config.col
$col.
$row -text $regname -pady 0 \
1646 -variable regena
($regnum) -relief flat
-anchor w
-bd 1
1648 pack .reg.config.col
$col.
$row -side top
-fill both
1661 # create_registers_window - Open up the register display window.
1665 # Create the register display window, with automatic updates.
1668 proc create_registers_window
{} {
1671 if {[winfo exists .reg
]} {raise .reg
; return}
1673 # Create an initial register display list consisting of all registers
1675 if {![info exists reg_format
]} {
1676 global reg_display_list
1677 global changed_reg_list
1681 set num_regs
[llength [gdb_regnames
]]
1682 for {set regnum
0} {$regnum < $num_regs} {incr regnum
} {
1683 set regena
($regnum) 1
1685 recompute_reg_display_list
$num_regs
1686 set changed_reg_list
$reg_display_list
1689 build_framework .reg Registers
1691 # First, delete all the old menu entries
1693 .reg.menubar.view.
menu delete
0 last
1696 .reg.menubar.view.
menu add
radiobutton -label Hex
\
1697 -command {set reg_format x
; update_registers all
}
1700 .reg.menubar.view.
menu add
radiobutton -label Decimal
\
1701 -command {set reg_format d
; update_registers all
}
1704 .reg.menubar.view.
menu add
radiobutton -label Octal
\
1705 -command {set reg_format o
; update_registers all
}
1708 .reg.menubar.view.
menu add
radiobutton -label Natural
\
1709 -command {set reg_format
{} ; update_registers all
}
1712 .reg.menubar.view.
menu add separator
1714 .reg.menubar.view.
menu add command
-label Config
-command {
1719 # Install the reg names
1722 update_registers all
1725 # Convert regena into a list of the enabled $regnums
1727 proc recompute_reg_display_list
{num_regs
} {
1728 global reg_display_list
1732 catch {unset reg_display_list
}
1735 for {set regnum
0} {$regnum < $num_regs} {incr regnum
} {
1737 if {[set regena
($regnum)] != 0} {
1738 lappend reg_display_list
$regnum
1739 set regmap
($regnum) $line
1745 # Fill out the register window with the names of the regs specified in
1748 proc populate_reg_window
{} {
1749 global max_regname_width
1750 global reg_display_list
1752 .reg.
text configure
-state normal
1754 .reg.
text delete
0.0 end
1756 set regnames
[eval gdb_regnames
$reg_display_list]
1758 # Figure out the longest register name
1760 set max_regname_width
0
1762 foreach reg
$regnames {
1763 set len
[string length
$reg]
1764 if {$len > $max_regname_width} {set max_regname_width
$len}
1767 set width
[expr $max_regname_width + 15]
1769 set height
[llength $regnames]
1771 if {$height > 60} {set height
60}
1773 .reg.
text configure
-height $height -width $width
1775 foreach reg
$regnames {
1776 .reg.
text insert end
[format "%-*s \n" $max_regname_width ${reg
}]
1780 .reg.
text configure
-state disabled
1786 # update_registers - Update the registers window.
1790 # This procedure updates the registers window.
1793 proc update_registers
{which
} {
1794 global max_regname_width
1796 global reg_display_list
1797 global changed_reg_list
1801 set margin
[expr $max_regname_width + 1]
1803 set winwidth
[lindex [$win configure
-width] 4]
1804 set valwidth
[expr $winwidth - $margin]
1806 $win configure
-state normal
1808 if {$which == "all"} {
1810 foreach regnum
$reg_display_list {
1811 set regval
[gdb_fetch_registers
$reg_format $regnum]
1812 set regval
[format "%-*s" $valwidth $regval]
1813 $win delete
$lineindex.
$margin "$lineindex.0 lineend"
1814 $win insert
$lineindex.
$margin $regval
1817 $win configure
-state disabled
1821 # Unhighlight the old values
1823 foreach regnum
$changed_reg_list {
1824 $win tag delete
$win.
$regnum
1827 # Now, highlight the changed values of the interesting registers
1829 set changed_reg_list
[eval gdb_changed_register_list
$reg_display_list]
1832 foreach regnum
$changed_reg_list {
1833 set regval
[gdb_fetch_registers
$reg_format $regnum]
1834 set regval
[format "%-*s" $valwidth $regval]
1836 set lineindex
$regmap($regnum)
1837 $win delete
$lineindex.
$margin "$lineindex.0 lineend"
1838 $win insert
$lineindex.
$margin $regval
1839 $win tag add
$win.
$regnum $lineindex.0 "$lineindex.0 lineend"
1840 eval $win tag configure
$win.
$regnum $highlight
1843 $win configure
-state disabled
1849 # update_assembly - Update the assembly window.
1853 # This procedure updates the assembly window.
1856 proc update_assembly
{linespec
} {
1859 global current_label
1861 global file_to_debug_file
1862 global current_asm_label
1866 # Rip the linespec apart
1868 lassign
$linespec debug_file funcname
filename line pc
1870 set win
[asm_win_name
$cfunc]
1872 # Sometimes there's no source file for this location
1874 if {$filename == ""} {set filename Blank
}
1876 # If we want to switch funcs, we need to unpack the current text widget, and
1877 # stick in the new one.
1879 if {$funcname != $cfunc } {
1883 set win
[asm_win_name
$cfunc]
1885 # Create a text widget for this func if necessary
1887 if {![winfo exists
$win]} {
1888 create_asm_win
$cfunc $pc
1889 set asm_pointers
($cfunc) 1.1
1890 set current_asm_label NIL
1893 # Pack the text widget, and scroll to the right place
1896 pack $win -side left
-expand yes
-fill both
\
1898 .asm.scroll configure
-command "$win yview"
1899 set line
[pc_to_line
$pclist($cfunc) $pc]
1900 ensure_line_visible
$win $line
1904 # Update the label widget in case the filename or function name has changed
1906 if {$current_asm_label != "$pc $funcname"} then
{
1907 set .asm.
label "$pc $funcname"
1908 set current_asm_label
"$pc $funcname"
1911 # Update the pointer, scrolling the text widget if necessary to keep the
1912 # pointer in an acceptable part of the screen.
1914 if {[info exists asm_pointers
($cfunc)]} then
{
1915 $win configure
-state normal
1916 set pointer_pos
$asm_pointers($cfunc)
1917 $win configure
-state normal
1918 $win delete
$pointer_pos "$pointer_pos + 2 char"
1919 $win insert
$pointer_pos " "
1921 # Map the PC back to a line in the window
1923 set line
[pc_to_line
$pclist($cfunc) $pc]
1926 echo
"Can't find PC $pc"
1930 set pointer_pos
[$win index
$line.1]
1931 set asm_pointers
($cfunc) $pointer_pos
1933 $win delete
$pointer_pos "$pointer_pos + 2 char"
1934 $win insert
$pointer_pos "->"
1935 ensure_line_visible
$win $line
1936 $win configure
-state disabled
1943 # update_ptr - Update the listing window.
1947 # This routine will update the listing window using the result of
1951 proc update_ptr
{} {
1952 update_listing
[gdb_loc
]
1953 if {[winfo exists .asm
]} {
1954 update_assembly
[gdb_loc
]
1956 if {[winfo exists .reg
]} {
1957 update_registers changed
1959 if {[winfo exists .
expr]} {
1962 if {[winfo exists .autocmd
]} {
1967 # Make toplevel window disappear
1971 proc files_command
{} {
1972 toplevel .files_window
1974 wm minsize .files_window
1 1
1975 # wm overrideredirect .files_window true
1976 listbox .files_window.
list -geometry 30x20
-setgrid true
\
1977 -yscrollcommand {.files_window.scroll
set} -relief sunken
\
1979 scrollbar .files_window.scroll
-orient vertical
\
1980 -command {.files_window.
list yview
} -relief sunken
1981 button .files_window.
close -text Close
-command {destroy .files_window
}
1982 .files_window.
list configure
-selectmode single
1984 # Get the file list from GDB, sort it, and format it as one entry per line.
1985 set lastSeen
{}; # Value that won't appear in
1988 foreach file [lsort [gdb_listfiles
]] {
1989 if {$file != $lastSeen} then
{
1990 lappend fileList
$file
1994 set filelist
[join [lsort [gdb_listfiles
]] "\n"]
1996 # Insert the file list into the widget
1998 eval .files_window.
list insert
0 $filelist
2000 pack .files_window.
close -side bottom
-fill x
-expand no
-anchor s
2001 pack .files_window.scroll
-side right
-fill both
2002 pack .files_window.
list -side left
-fill both
-expand yes
2003 bind .files_window.
list <Any-ButtonRelease-1
> {
2004 set file [%W get
[%W curselection
]]
2005 gdb_cmd
"list $file:1,0"
2006 update_listing
[gdb_loc
$file:1]
2007 destroy .files_window
2011 button .files
-text Files
-command files_command
2013 proc apply_filespec
{label default command
} {
2014 set filename [FSBox
$label $default]
2015 if {$filename != ""} {
2016 if {[catch {gdb_cmd
"$command $filename"} retval
]} {
2017 tk_dialog .filespec_error
"gdb : $label error" \
2018 "Error in command \"$command $filename\"" error \
2027 proc run_editor
{editor
file} {
2028 # FIXME should use index of line in middle of window, not line at
2031 set lineNo
[lindex [split [$wins($file) index
@0,0] .
] 0]
2032 exec $editor +$lineNo $file
2035 # Setup command window
2036 proc build_framework
{win
{title GDBtk
} {label {}}} {
2040 wm title
${win
} $title
2041 wm minsize
${win
} 1 1
2043 frame ${win
}.menubar
2045 menubutton ${win
}.menubar.
file -padx 12 -text File
\
2046 -menu ${win
}.menubar.
file.
menu -underline 0
2048 menu ${win
}.menubar.
file.
menu
2049 ${win
}.menubar.
file.
menu add command
-label File...
\
2050 -command {apply_filespec File a.out
file}
2051 ${win
}.menubar.
file.
menu add command
-label Target...
\
2052 -command { not_implemented_yet
"target" }
2053 ${win
}.menubar.
file.
menu add command
-label Edit
\
2054 -command {run_editor
$editor $cfile}
2055 ${win
}.menubar.
file.
menu add separator
2056 ${win
}.menubar.
file.
menu add command
-label "Exec File..." \
2057 -command {apply_filespec
{Exec File
} a.out exec-file
}
2058 ${win
}.menubar.
file.
menu add command
-label "Symbol File..." \
2059 -command {apply_filespec
{Symbol File
} a.out symbol-file
}
2060 ${win
}.menubar.
file.
menu add command
-label "Add Symbol File..." \
2061 -command { not_implemented_yet
"menu item, add symbol file" }
2062 ${win
}.menubar.
file.
menu add command
-label "Core File..." \
2063 -command {apply_filespec
{Core File
} core core-file
}
2065 ${win
}.menubar.
file.
menu add separator
2066 ${win
}.menubar.
file.
menu add command
-label Close
\
2067 -command "destroy ${win}"
2068 ${win
}.menubar.
file.
menu add separator
2069 ${win
}.menubar.
file.
menu add command
-label Quit
\
2070 -command {interactive_cmd quit
}
2072 menubutton ${win
}.menubar.commands
-padx 12 -text Commands
\
2073 -menu ${win
}.menubar.commands.
menu -underline 0
2075 menu ${win
}.menubar.commands.
menu
2076 ${win
}.menubar.commands.
menu add command
-label Run
\
2077 -command {interactive_cmd run
}
2078 ${win
}.menubar.commands.
menu add command
-label Step
\
2079 -command {interactive_cmd step
}
2080 ${win
}.menubar.commands.
menu add command
-label Next
\
2081 -command {interactive_cmd next
}
2082 ${win
}.menubar.commands.
menu add command
-label Continue
\
2083 -command {interactive_cmd
continue}
2084 ${win
}.menubar.commands.
menu add separator
2085 ${win
}.menubar.commands.
menu add command
-label Stepi
\
2086 -command {interactive_cmd stepi
}
2087 ${win
}.menubar.commands.
menu add command
-label Nexti
\
2088 -command {interactive_cmd nexti
}
2090 menubutton ${win
}.menubar.view
-padx 12 -text Options
\
2091 -menu ${win
}.menubar.view.
menu -underline 0
2093 menu ${win
}.menubar.view.
menu
2094 ${win
}.menubar.view.
menu add command
-label Hex
\
2096 ${win
}.menubar.view.
menu add command
-label Decimal
\
2097 -command {echo Decimal
}
2098 ${win
}.menubar.view.
menu add command
-label Octal
\
2099 -command {echo Octal
}
2101 menubutton ${win
}.menubar.window
-padx 12 -text Window
\
2102 -menu ${win
}.menubar.window.
menu -underline 0
2104 menu ${win
}.menubar.window.
menu
2105 ${win
}.menubar.window.
menu add command
-label Command
\
2106 -command create_command_window
2107 ${win
}.menubar.window.
menu add separator
2108 ${win
}.menubar.window.
menu add command
-label Source
\
2109 -command create_source_window
2110 ${win
}.menubar.window.
menu add command
-label Assembly
\
2111 -command create_asm_window
2112 ${win
}.menubar.window.
menu add separator
2113 ${win
}.menubar.window.
menu add command
-label Registers
\
2114 -command create_registers_window
2115 ${win
}.menubar.window.
menu add command
-label Expressions
\
2116 -command create_expr_window
2117 ${win
}.menubar.window.
menu add command
-label "Auto Command" \
2118 -command create_autocmd_window
2119 ${win
}.menubar.window.
menu add command
-label Breakpoints
\
2120 -command create_breakpoints_window
2122 # ${win}.menubar.window.menu add separator
2123 # ${win}.menubar.window.menu add command -label Files \
2124 # -command { not_implemented_yet "files window" }
2126 menubutton ${win
}.menubar.help
-padx 12 -text Help
\
2127 -menu ${win
}.menubar.help.
menu -underline 0
2129 menu ${win
}.menubar.help.
menu
2130 ${win
}.menubar.help.
menu add command
-label "with GDBtk" \
2131 -command {echo
"with GDBtk"}
2132 ${win
}.menubar.help.
menu add command
-label "with this window" \
2133 -command {echo
"with this window"}
2134 ${win
}.menubar.help.
menu add command
-label "Report bug" \
2135 -command {exec send-pr
}
2137 pack ${win
}.menubar.
file \
2138 ${win
}.menubar.view
\
2139 ${win
}.menubar.window
-side left
2140 pack ${win
}.menubar.help
-side right
2143 text ${win
}.
text -height 25 -width 80 -relief sunken
-borderwidth 2 \
2144 -setgrid true
-cursor hand2
-yscrollcommand "${win}.scroll set"
2146 set ${win
}.
label $label
2147 label ${win
}.
label -textvariable ${win
}.
label -borderwidth 2 -relief sunken
2149 scrollbar ${win
}.scroll
-orient vertical
-command "${win}.text yview" \
2152 bind $win <Key-Alt_R
> do_nothing
2153 bind $win <Key-Alt_L
> do_nothing
2155 pack ${win
}.
label -side bottom
-fill x
-in ${win
}.
info
2156 pack ${win
}.scroll
-side right
-fill y
-in ${win
}.
info
2157 pack ${win
}.
text -side left
-expand yes
-fill both
-in ${win
}.
info
2159 pack ${win
}.menubar
-side top
-fill x
2160 pack ${win
}.
info -side top
-fill both
-expand yes
2163 proc create_source_window
{} {
2167 if {[winfo exists .src
]} {raise .src
; return}
2169 build_framework .src Source
"*No file*"
2171 # First, delete all the old view menu entries
2173 .src.menubar.view.
menu delete
0 last
2175 # Source file selection
2176 .src.menubar.view.
menu add command
-label "Select source file" \
2177 -command files_command
2179 # Line numbers enable/disable menu item
2180 .src.menubar.view.
menu add
checkbutton -variable line_numbers
\
2181 -label "Line numbers" -onvalue 1 -offvalue 0 -command {
2182 foreach source [array names wins
] {
2183 if {$source == "Blank"} continue
2184 destroy $wins($source)
2188 update_listing
[gdb_loc
]
2194 button .src.start
-width 6 -text Start
-command \
2195 {interactive_cmd
{break main
}
2196 interactive_cmd
{enable delete
$bpnum}
2197 interactive_cmd run
}
2198 button .src.stop
-width 6 -text Stop
-fg red
-activeforeground red
\
2199 -state disabled
-command gdb_stop
2200 button .src.step
-width 6 -text Step
\
2201 -command {interactive_cmd step
}
2202 button .src.next
-width 6 -text Next
\
2203 -command {interactive_cmd next
}
2204 button .src.
continue -width 6 -text Cont
\
2205 -command {interactive_cmd
continue}
2206 button .src.finish
-width 6 -text Finish
\
2207 -command {interactive_cmd finish
}
2208 button .src.up
-width 6 -text Up
\
2209 -command {interactive_cmd up
}
2210 button .src.down
-width 6 -text Down
\
2211 -command {interactive_cmd down
}
2212 button .src.bottom
-width 6 -text Bottom
\
2213 -command {interactive_cmd
{frame 0}}
2215 pack .src.start .src.step .src.
continue .src.up .src.bottom
\
2216 -side left
-padx 3 -pady 5 -in .src.row1
2217 pack .src.stop .src.next .src.finish .src.down
-side left
-padx 3 \
2218 -pady 5 -in .src.row2
2220 pack .src.row2 .src.row1
-side bottom
-anchor w
-before .src.
info
2222 $wins($cfile) insert
0.0 " This page intentionally left blank."
2223 $wins($cfile) configure
-width 88 -state disabled
\
2224 -yscrollcommand ".src.scroll set"
2227 proc update_autocmd
{} {
2228 global .autocmd.
label
2229 global accumulate_output
2231 catch {gdb_cmd
"${.autocmd.label}"} result
2232 if {!$accumulate_output} { .autocmd.
text delete
0.0 end
}
2233 .autocmd.
text insert end
$result
2234 .autocmd.
text see end
2237 proc create_autocmd_window
{} {
2238 global .autocmd.
label
2240 if {[winfo exists .autocmd
]} {raise .autocmd
; return}
2242 build_framework .autocmd
"Auto Command" ""
2244 # First, delete all the old view menu entries
2246 .autocmd.menubar.view.
menu delete
0 last
2248 # Accumulate output option
2250 .autocmd.menubar.view.
menu add
checkbutton \
2251 -variable accumulate_output
\
2252 -label "Accumulate output" -onvalue 1 -offvalue 0
2254 # Now, create entry widget with label
2256 frame .autocmd.entryframe
2258 entry .autocmd.
entry -borderwidth 2 -relief sunken
2259 bind .autocmd.
entry <Key-Return
> {
2260 set .autocmd.
label [.autocmd.
entry get
]
2261 .autocmd.
entry delete
0 end
2264 label .autocmd.entrylab
-text "Command: "
2266 pack .autocmd.entrylab
-in .autocmd.entryframe
-side left
2267 pack .autocmd.
entry -in .autocmd.entryframe
-side left
-fill x
-expand yes
2269 pack .autocmd.entryframe
-side bottom
-fill x
-before .autocmd.
info
2272 # Return the longest common prefix in SLIST. Can be empty string.
2274 proc find_lcp slist
{
2275 # Handle trivial cases where list is empty or length 1
2276 if {[llength $slist] <= 1} {return [lindex $slist 0]}
2278 set prefix
[lindex $slist 0]
2279 set prefixlast
[expr [string length
$prefix] - 1]
2281 foreach str
[lrange $slist 1 end
] {
2282 set test_str
[string range
$str 0 $prefixlast]
2283 while {[string compare
$test_str $prefix] != 0} {
2285 set prefix
[string range
$prefix 0 $prefixlast]
2286 set test_str
[string range
$str 0 $prefixlast]
2288 if {$prefixlast < 0} break
2293 # Look through COMPLETIONS to generate the suffix needed to do command
2294 # completion on CMD.
2296 proc find_completion
{cmd completions
} {
2297 # Get longest common prefix
2298 set lcp
[find_lcp
$completions]
2299 set cmd_len
[string length
$cmd]
2300 # Return suffix beyond end of cmd
2301 return [string range
$lcp $cmd_len end
]
2304 proc create_command_window
{} {
2309 if {[winfo exists .cmd
]} {raise .cmd
; return}
2311 build_framework .cmd Command
"* Command Buffer *"
2313 # Put focus on command area.
2318 gdb_cmd
{set language c
}
2319 gdb_cmd
{set height
0}
2320 gdb_cmd
{set width
0}
2322 # Tk uses the Motifism that Delete means delete forward. I
2323 # hate this, and I'm not gonna take it any more.
2324 set bsBinding
[bind Text
<BackSpace
>]
2325 bind .cmd.
text <Delete
> "delete_char %W ; $bsBinding; break"
2326 bind .cmd.
text <BackSpace
> {delete_char
%W
}
2327 bind .cmd.
text <Control-c
> gdb_stop
2328 bind .cmd.
text <Control-u
> {delete_line
%W
; break}
2329 bind .cmd.
text <Any-Key
> {
2333 append command_line
%A
2336 bind .cmd.
text <Key-Return
> {
2339 interactive_cmd
$command_line
2342 # catch "gdb_cmd [list $command_line]" result
2343 # %W insert end $result
2346 %W insert end
"(gdb) "
2350 bind .cmd.
text <Button-2
> {
2351 %W insert end
[selection get
]
2353 append command_line
[selection get
]
2356 bind .cmd.
text <B2-Motion
> break
2357 bind .cmd.
text <ButtonRelease-2
> break
2358 bind .cmd.
text <Key-Tab
> {
2359 set choices
[gdb_cmd
"complete $command_line"]
2360 set choices
[string trimright
$choices \n]
2361 set choices
[split $choices \n]
2363 # Just do completion if this is the first tab
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] {
2375 %W insert end
"$completion "
2376 append command_line
" "
2381 %W insert end
$completion
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
2396 %W insert end
"\n[join $choices { }]\n(gdb) $command_line"
2403 proc delete_char
{win
} {
2405 set tmp
[expr [string length
$command_line] - 2]
2406 set command_line
[string range
$command_line 0 $tmp]
2409 proc delete_line
{win
} {
2412 $win delete
{end linestart
+ 6 chars
} end
2419 # simple file selector.
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
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.
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
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.
2451 proc FSBox
{{purpose
"Select file:"} {defaultName
""} {cmd
""} {errorHandler
2455 if {[Exwin_Toplevel
$w "Select File" FileSelect
]} {
2456 # path independent names for the widgets
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
2466 set fileselect
(result
) "" ;# value to return if no callback procedures
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
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
2476 Widget_Frame
$w.
file sframe
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
}
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
}
2491 $w.but.quit configure
-text Cancel
\
2492 -command [list fileselect.cancel.cmd
$w]
2494 Widget_AddBut
$w.but ok OK
\
2495 [list fileselect.ok.cmd
$w $cmd $errorHandler] {left padx
1}
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
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
]
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
]
2513 $fileselect(list) configure
-selectmode single
2515 bind $fileselect(list) <Button-1
> {
2516 # puts stderr "button 1 release"
2517 $fileselect(entry) delete
0 end
2518 $fileselect(entry) insert
0 [%W get
[%W nearest
%y
]]
2521 bind $fileselect(list) <Key
> {
2522 $fileselect(entry) delete
0 end
2523 $fileselect(entry) insert
0 [%W get
[%W nearest
%y
]]
2526 bind $fileselect(list) <Double-ButtonPress-1
> {
2527 # puts stderr "double button 1"
2528 $fileselect(entry) delete
0 end
2529 $fileselect(entry) insert
0 [%W get
[%W nearest
%y
]]
2530 $fileselect(ok
) invoke
2533 bind $fileselect(list) <Return
> {
2534 $fileselect(entry) delete
0 end
2535 $fileselect(entry) insert
0 [%W get
[%W nearest
%y
]]
2536 $fileselect(ok
) invoke
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]
2544 if {[info exists fileselect
(lastDir
)] && ![string length
$defaultName]} {
2545 set dir
$fileselect(lastDir
)
2547 set dir
[file dirname
$defaultName]
2549 set fileselect
(pwd) [pwd]
2551 $fileselect(direntry
) delete
0 end
2552 $fileselect(direntry
) insert
0 [pwd]/
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"
2559 fileselect.
list.cmd
$fileselect(direntry
) startup
2561 # set kbd focus to entry widget
2563 # Exwin_ToplevelFocus $w $fileselect(entry)
2565 # Wait for button hits if no callbacks are defined
2567 if {"$cmd" == "" && "$errorHandler" == ""} {
2568 # wait for the box to be destroyed
2571 tkwait variable fileselect
(result
)
2574 set path
$fileselect(result
)
2575 set fileselect
(lastDir
) [pwd]
2576 fileselect.
cd $fileselect(pwd)
2577 return [string trimright
[string trim
$path] /]
2579 fileselect.
cd $fileselect(pwd)
2583 proc fileselect.
cd { dir
} {
2585 if {[catch {cd $dir} err
]} {
2590 # auxiliary button procedures
2592 proc fileselect.yck
{ {tag
{}} } {
2594 $fileselect(msg
) configure
-text "Yck! $tag"
2597 proc fileselect.ok
{} {
2599 $fileselect(msg
) configure
-text $fileselect(text)
2602 proc fileselect.cancel.cmd
{w
} {
2604 set fileselect
(result
) {}
2608 proc fileselect.
list.cmd
{w
{state normal
}} {
2610 set seldir
[$fileselect(direntry
) get
]
2611 if {[catch {glob $seldir} dir
]} {
2612 fileselect.yck
"glob failed"
2615 if {[llength $dir] > 1} {
2616 set dir
[file dirname
$seldir]
2617 set pat
[file tail
$seldir]
2619 set pat
$fileselect(pattern
)
2623 if {[file isdirectory
$dir]} {
2624 fileselect.getfiles
$dir $pat $state
2625 focus $fileselect(entry)
2627 fileselect.yck
"not a dir"
2631 proc fileselect.ok.cmd
{w cmd errorHandler
} {
2633 set selname
[$fileselect(entry) get
]
2634 set seldir
[$fileselect(direntry
) get
]
2636 if {[string match
/* $selname]} {
2637 set selected
$selname
2639 if {[string match ~
* $selname]} {
2640 set selected
$selname
2642 set selected
$seldir/$selname
2646 # some nasty file names may cause "file isdirectory" to return an error
2647 if {[catch {file isdirectory
$selected} isdir
]} {
2648 fileselect.yck
"isdirectory failed"
2651 if {[catch {glob $selected} globlist
]} {
2652 if {![file isdirectory
[file dirname
$selected]]} {
2653 fileselect.yck
"bad pathname"
2656 set globlist
$selected
2661 if {[llength $globlist] > 1} {
2662 set dir
[file dirname
$selected]
2663 set pat
[file tail
$selected]
2664 fileselect.getfiles
$dir $pat
2667 set selected
$globlist
2669 if {[file isdirectory
$selected]} {
2670 fileselect.getfiles
$selected $fileselect(pattern
)
2671 $fileselect(entry) delete
0 end
2678 set fileselect
(result
) $selected
2683 proc fileselect.getfiles
{ dir
{pat
*} {state normal
} } {
2685 $fileselect(msg
) configure
-text Listing...
2688 set currentDir
[pwd]
2690 if {[catch {set files
[lsort [glob -nocomplain $pat]]} err
]} {
2691 $fileselect(msg
) configure
-text $err
2692 $fileselect(list) delete
0 end
2698 # Normal case - show current directory
2699 $fileselect(direntry
) delete
0 end
2700 $fileselect(direntry
) insert
0 [pwd]/
2703 # Directory already OK (tab related)
2706 # Changing directory (tab related)
2707 fileselect.
cd $currentDir
2710 # Avoid listing huge directories upon startup.
2711 $fileselect(direntry
) delete
0 end
2712 $fileselect(direntry
) insert
0 [pwd]/
2713 if {[llength $files] > 32} {
2720 # build a reordered list of the files: directories are displayed first
2721 # and marked with a trailing "/"
2722 if {[string compare
$dir /]} {
2723 fileselect.putfiles
$files [expr {($pat == "*") ?
1 : 0}]
2725 fileselect.putfiles
$files
2730 proc fileselect.putfiles
{files
{dotdot
0} } {
2733 $fileselect(list) delete
0 end
2735 $fileselect(list) insert end
"../"
2738 if {[file isdirectory
$i]} {
2739 $fileselect(list) insert end
$i/
2741 $fileselect(list) insert end
$i
2746 proc FileExistsDialog
{ name
} {
2749 set fileExists
(ok
) 0
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
}
2758 $w.msg config
-text "Warning: file exists
2760 OK to overwrite it?"
2762 set fileExists
(focus) [focus]
2765 tkwait variable fileExists
(ok
)
2768 return $fileExists(ok
)
2771 proc FileExistsCancel
{} {
2773 set fileExists
(ok
) 0
2776 proc FileExistsOK
{} {
2778 set fileExists
(ok
) 1
2781 proc fileselect.getfiledir
{ dir
{basedir
[pwd]} } {
2784 set path
[$fileselect(direntry
) get
]
2788 if {[string index
$path 0] == "~"} {
2792 set path
[$fileselect(entry) get
]
2794 if {[catch {set listFile
[glob -nocomplain $path*]}]} {
2797 foreach el
$listFile {
2799 if {[file isdirectory
$el]} {
2800 lappend returnList
[file tail
$el]
2802 } elseif
{![file isdirectory
$el]} {
2803 lappend returnList
[file tail
$el]
2810 proc fileselect.gethead
{ list } {
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]
2817 if {[string length
$el] < $i} {
2820 if {$thisChar != [string index
$el $i]} {
2828 # FIXME this function is a crock. Can write tilde expanding function
2829 # in terms of glob and quote_glob; do so.
2830 proc fileselect.expand.tilde
{ } {
2833 set entry [$fileselect(direntry
) get
]
2834 set dir
[string range
$entry 1 [string length
$entry]]
2842 ## look in /etc/passwd
2843 if {[file exists
/etc
/passwd
]} {
2844 if {[catch {set users
[exec cat
/etc
/passwd | sed s
/:.
*//]} err
]} {
2845 puts "Error\#1 $err"
2848 set list [split $users "\n"]
2850 if {[lsearch -exact $list "+"] != -1} {
2851 if {[catch {set users
[exec ypcat passwd | sed s
/:.
*//]} err
]} {
2852 puts "Error\#2 $err"
2855 set list [concat $list [split $users "\n"]]
2857 $fileselect(list) delete
0 end
2859 if {[string match
$dir* $el]} {
2860 lappend listmatch
$el
2861 $fileselect(list) insert end
$el
2864 set addings
[fileselect.gethead
$listmatch]
2865 if {$addings == ""} {
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
]
2873 $fileselect(direntry
) insert
0 ~
$addings
2877 proc fileselect.tab.dircmd
{ } {
2880 set dir
[$fileselect(direntry
) get
]
2882 $fileselect(direntry
) delete
0 end
2883 $fileselect(direntry
) insert
0 [pwd]
2884 if {[string compare
[pwd] "/"]} {
2885 $fileselect(direntry
) insert end
/
2889 if {[catch {set tmp
[file isdirectory
[file dirname
$dir]]}]} {
2890 if {[string index
$dir 0] == "~"} {
2891 fileselect.expand.tilde
2898 set dirFile
[fileselect.getfiledir
1 $dir]
2899 if {![llength $dirFile]} {
2902 if {[llength $dirFile] == 1} {
2903 $fileselect(direntry
) delete
0 end
2904 $fileselect(direntry
) insert
0 [file dirname
$dir]
2905 if {[string compare
[file dirname
$dir] /]} {
2906 $fileselect(direntry
) insert end
/[lindex $dirFile 0]/
2908 $fileselect(direntry
) insert end
[lindex $dirFile 0]/
2910 fileselect.getfiles
[$fileselect(direntry
) get
] \
2911 "[file tail [$fileselect(direntry) get]]$fileselect(pattern)" opt
2914 set headFile
[fileselect.gethead
$dirFile]
2915 $fileselect(direntry
) delete
0 end
2916 $fileselect(direntry
) insert
0 [file dirname
$dir]
2917 if {[string compare
[file dirname
$dir] /]} {
2918 $fileselect(direntry
) insert end
/$headFile
2920 $fileselect(direntry
) insert end
$headFile
2922 if {$headFile == "" && [file isdirectory
$dir]} {
2923 fileselect.getfiles
$dir\
2924 "[file tail [$fileselect(direntry) get]]$fileselect(pattern)" opt
2926 fileselect.getfiles
[file dirname
$dir]\
2927 "[file tail [$fileselect(direntry) get]]*" newdir
2931 proc fileselect.tab.filecmd
{ } {
2934 set dir
[$fileselect(direntry
) get
]
2938 if {![file isdirectory
$dir]} {
2939 error "dir $dir doesn't exist"
2941 set listFile
[fileselect.getfiledir
0 $dir]
2943 if {![llength $listFile]} {
2946 if {[llength $listFile] == 1} {
2947 $fileselect(entry) delete
0 end
2948 $fileselect(entry) insert
0 [lindex $listFile 0]
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
2957 proc Exwin_Toplevel
{ path name
{class Dialog
} {dismiss yes
}} {
2959 if {[catch {wm state
$path} state
]} {
2960 set t
[Widget_Toplevel
$path $name $class]
2961 if {![info exists exwin
(toplevels
)]} {
2962 set exwin
(toplevels
) [option get . exwinPaths
{}]
2964 set ix
[lsearch $exwin(toplevels
) $t]
2966 lappend exwin
(toplevels
) $t
2968 if {$dismiss == "yes"} {
2969 set f
[Widget_Frame
$t but Menubar
{top fill
}]
2970 Widget_AddBut
$f quit
"Dismiss" [list Exwin_Dismiss
$path]
2974 if {$state != "normal"} {
2976 wm geometry
$path $exwin(geometry
,$path)
2977 # Exmh_Debug Exwin_Toplevel $path $exwin(geometry,$path)
2987 proc Exwin_Dismiss
{ path
{geo ok
} } {
2991 set exwin
(geometry
,$path) [wm geometry
$path]
2994 set exwin
(geometry
,$path) [string trimleft
[wm geometry
$path] 0123456789x
]
2997 catch {unset exwin
(geometry
,$path)}
3003 proc 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 != {}} {
3007 if {[catch {wm geometry
$self $usergeo} err
]} {
3008 # Exmh_Debug Widget_Toplevel $self $usergeo => $err
3011 if {($x != {}) && ($y != {})} {
3012 # Exmh_Debug Event position $self +$x+$y
3013 wm geometry
$self +$x+$y
3016 wm title
$self $name
3021 proc Widget_Frame
{par child
{class GDB
} {where
{top expand fill
}} args
} {
3025 set self
$par.
$child
3027 eval {frame $self -class $class} $args
3028 pack append $par $self $where
3032 proc 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]
3035 if {[catch $cmd2 t
]} {
3036 puts stderr
"Widget_AddBut (warning) $t"
3037 eval $cmd2 {-font fixed
}
3039 pack append $par $par.
$but $where
3043 proc 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]
3046 if {[catch $cmd t
]} {
3047 puts stderr
"Widget_CheckBut (warning) $t"
3048 eval $cmd {-font fixed
}
3050 pack append $par $par.
$but $where
3054 proc Widget_Label
{ frame {name
label} {where
{left fill
}} args
} {
3055 set cmd
[list label $frame.
$name ]
3056 if {[catch [concat $cmd $args] t
]} {
3057 puts stderr
"Widget_Label (warning) $t"
3058 eval $cmd $args {-font fixed
}
3060 pack append $frame $frame.
$name $where
3064 proc Widget_Entry
{ frame {name
entry} {where
{left fill
}} args
} {
3065 set cmd
[list entry $frame.
$name ]
3066 if {[catch [concat $cmd $args] t
]} {
3067 puts stderr
"Widget_Entry (warning) $t"
3068 eval $cmd $args {-font fixed
}
3070 pack append $frame $frame.
$name $where
3074 # End of fileselect.tcl.
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
3081 proc create_copyright_window
{} {
3083 message .c.m
-text [gdb_cmd
{show version
}] -aspect 500 -relief raised
3086 bind .c.m
<1> {destroy .c
}
3087 bind .c
<Leave
> {destroy .c
}
3088 # "suitable period" currently means "15 seconds".
3090 if {[winfo exists .c
]} then
{
3099 # FIXME need to handle mono here. In Tk4 that is more complicated.
3100 set highlight
"-background red2 -borderwidth 2 -relief sunken"
3102 # Setup the initial windows
3103 create_source_window
3104 create_command_window
3106 # Make this last so user actually sees it.
3107 create_copyright_window
3111 if {[file exists ~
/.gdbtkinit
]} {