-# GDB GUI setup
+# GDB GUI setup for GDB, the GNU debugger.
+# Copyright 1994, 1995
+# Free Software Foundation, Inc.
+
+# Written by Stu Grossman <grossman@cygnus.com> of Cygnus Support.
+
+# This file is part of GDB.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
set cfile Blank
set wins($cfile) .src.text
set screen_height 0
set screen_top 0
set screen_bot 0
-set current_output_win .cmd.text
set cfunc NIL
set line_numbers 1
set breakpoint_file(-1) {[garbage]}
+set disassemble_with_source nosource
+set expr_update_list(0) 0
#option add *Foreground Black
#option add *Background White
#
proc gdbtk_tcl_fputs {arg} {
- global current_output_win
-
- $current_output_win insert end "$arg"
- $current_output_win yview -pickplace end
+ .cmd.text insert end "$arg"
+ .cmd.text yview -pickplace end
}
proc gdbtk_tcl_fputs_error {arg} {
#
proc gdbtk_tcl_flush {} {
- global current_output_win
-
- $current_output_win yview -pickplace end
+ .cmd.text yview -pickplace end
update idletasks
}
# of:
# create - Notify of breakpoint creation
# delete - Notify of breakpoint deletion
-# enable - Notify of breakpoint enabling
-# disable - Notify of breakpoint disabling
-#
-# All actions take the same set of arguments: BPNUM is the breakpoint
-# number, FILE is the source file and LINE is the line number, and PC is
-# the pc of the affected breakpoint.
+# modify - Notify of breakpoint modification
#
-proc gdbtk_tcl_breakpoint {action bpnum file line pc} {
+# file line pc type enabled disposition silent ignore_count commands cond_string thread hit_count
+
+proc gdbtk_tcl_breakpoint {action bpnum} {
+ set bpinfo [gdb_get_breakpoint_info $bpnum]
+ set file [lindex $bpinfo 0]
+ set line [lindex $bpinfo 1]
+ set pc [lindex $bpinfo 2]
+ set enable [lindex $bpinfo 4]
+
+ if {$action == "modify"} {
+ if {$enable == "enabled"} {
+ set action enable
+ } else {
+ set action disable
+ }
+ }
+
${action}_breakpoint $bpnum $file $line $pc
}
+proc create_breakpoints_window {} {
+ global bpframe_lasty
+
+ if [winfo exists .breakpoints] {raise .breakpoints ; return}
+
+ build_framework .breakpoints "Breakpoints" ""
+
+# First, delete all the old view menu entries
+
+ .breakpoints.menubar.view.menu delete 0 last
+
+# Get rid of label
+
+ destroy .breakpoints.label
+
+# Replace text with a canvas and fix the scrollbars
+
+ destroy .breakpoints.text
+ canvas .breakpoints.c -relief sunken -bd 2 \
+ -cursor hand2 -yscrollcommand {.breakpoints.scroll set}
+ .breakpoints.scroll configure -command {.breakpoints.c yview}
+ scrollbar .breakpoints.scrollx -orient horizontal \
+ -command {.breakpoints.c xview} -relief sunken
+
+ pack .breakpoints.scrollx -side bottom -fill x -in .breakpoints.info
+ pack .breakpoints.c -side left -expand yes -fill both \
+ -in .breakpoints.info
+
+ set bpframe_lasty 0
+
+# Create a frame for each breakpoint
+
+ foreach bpnum [gdb_get_breakpoint_list] {
+ add_breakpoint_frame $bpnum
+ }
+}
+
+# Create a frame for bpnum in the .breakpoints canvas
+
+proc add_breakpoint_frame bpnum {
+ global bpframe_lasty
+
+ if ![winfo exists .breakpoints] return
+
+ set bpinfo [gdb_get_breakpoint_info $bpnum]
+
+ set file [lindex $bpinfo 0]
+ set line [lindex $bpinfo 1]
+ set pc [lindex $bpinfo 2]
+ set type [lindex $bpinfo 3]
+ set enabled [lindex $bpinfo 4]
+ set disposition [lindex $bpinfo 5]
+ set silent [lindex $bpinfo 6]
+ set ignore_count [lindex $bpinfo 7]
+ set commands [lindex $bpinfo 8]
+ set cond [lindex $bpinfo 9]
+ set thread [lindex $bpinfo 10]
+ set hit_count [lindex $bpinfo 11]
+
+ set f .breakpoints.c.$bpnum
+
+ if ![winfo exists $f] {
+ frame $f -relief sunken -bd 2
+
+ label $f.id -text "#$bpnum $file:$line ($pc)" \
+ -relief flat -bd 2 -anchor w
+ frame $f.hit_count
+ label $f.hit_count.label -text "Hit count:" -relief flat \
+ -bd 2 -anchor w -width 11
+ label $f.hit_count.val -text $hit_count -relief flat \
+ -bd 2 -anchor w
+ checkbutton $f.hit_count.enabled -text Enabled \
+ -variable enabled -anchor w -relief flat
+ pack $f.hit_count.label $f.hit_count.val -side left
+ pack $f.hit_count.enabled -side right
+
+ frame $f.thread
+ label $f.thread.label -text "Thread: " -relief flat -bd 2 \
+ -width 11 -anchor w
+ entry $f.thread.entry -bd 2 -relief sunken -width 10
+ $f.thread.entry insert end $thread
+ pack $f.thread.label -side left
+ pack $f.thread.entry -side left -fill x
+
+ frame $f.cond
+ label $f.cond.label -text "Condition: " -relief flat -bd 2 \
+ -width 11 -anchor w
+ entry $f.cond.entry -bd 2 -relief sunken
+ $f.cond.entry insert end $cond
+ pack $f.cond.label -side left
+ pack $f.cond.entry -side left -fill x -expand yes
+
+ frame $f.ignore_count
+ label $f.ignore_count.label -text "Ignore count: " \
+ -relief flat -bd 2 -width 11 -anchor w
+ entry $f.ignore_count.entry -bd 2 -relief sunken -width 10
+ $f.ignore_count.entry insert end $ignore_count
+ pack $f.ignore_count.label -side left
+ pack $f.ignore_count.entry -side left -fill x
+
+ frame $f.disps
+
+ label $f.disps.label -text "Disposition: " -relief flat -bd 2 \
+ -anchor w -width 11
+
+ radiobutton $f.disps.delete -text Delete \
+ -variable disposition -anchor w -relief flat
+
+ radiobutton $f.disps.disable -text Disable \
+ -variable disposition -anchor w -relief flat
+
+ radiobutton $f.disps.donttouch -text "Leave alone" \
+ -variable disposition -anchor w -relief flat
+
+ pack $f.disps.label $f.disps.delete $f.disps.disable \
+ $f.disps.donttouch -side left -anchor w
+ text $f.commands -relief sunken -bd 2 -setgrid true \
+ -cursor hand2 -height 3 -width 30
+
+ foreach line $commands {
+ $f.commands insert end "${line}\n"
+ }
+
+ pack $f.id -side top -anchor nw -fill x
+ pack $f.hit_count $f.cond $f.thread $f.ignore_count $f.disps \
+ $f.commands -side top -fill x -anchor nw
+ }
+
+ set tag [.breakpoints.c create window 0 $bpframe_lasty -window $f -anchor nw]
+ update
+ set bbox [.breakpoints.c bbox $tag]
+
+ set bpframe_lasty [lindex $bbox 3]
+
+ .breakpoints.c configure -width [lindex $bbox 2]
+}
+
+# Delete a breakpoint frame
+
+proc delete_breakpoint_frame bpnum {
+ global bpframe_lasty
+
+ if ![winfo exists .breakpoints] return
+
+# First, clear the canvas
+
+ .breakpoints.c delete all
+
+# Now, repopulate it with all but the doomed breakpoint
+
+ set bpframe_lasty 0
+ foreach bp [gdb_get_breakpoint_list] {
+ if {$bp != $bpnum} {
+ add_breakpoint_frame $bp
+ }
+ }
+}
+
proc asm_win_name {funcname} {
if {$funcname == "*None*"} {return .asm.text}
if [winfo exists $win] {
insert_breakpoint_tag $win [pc_to_line $pclist($cfunc) $pc]
}
+
+# Update the breakpoints window
+
+ add_breakpoint_frame $bpnum
}
#
}
}
}
+
+ delete_breakpoint_frame $bpnum
}
#
proc gdbtk_tcl_busy {} {
if [winfo exists .src] {
- catch {.src.start configure -state disabled}
- catch {.src.stop configure -state normal}
- catch {.src.step configure -state disabled}
- catch {.src.next configure -state disabled}
- catch {.src.continue configure -state disabled}
- catch {.src.finish configure -state disabled}
- catch {.src.up configure -state disabled}
- catch {.src.down configure -state disabled}
- catch {.src.bottom configure -state disabled}
+ .src.start configure -state disabled
+ .src.stop configure -state normal
+ .src.step configure -state disabled
+ .src.next configure -state disabled
+ .src.continue configure -state disabled
+ .src.finish configure -state disabled
+ .src.up configure -state disabled
+ .src.down configure -state disabled
+ .src.bottom configure -state disabled
}
if [winfo exists .asm] {
- catch {.asm.stepi configure -state disabled}
- catch {.asm.nexti configure -state disabled}
- catch {.asm.continue configure -state disabled}
- catch {.asm.finish configure -state disabled}
- catch {.asm.up configure -state disabled}
- catch {.asm.down configure -state disabled}
- catch {.asm.bottom configure -state disabled}
- catch {.asm.close configure -state disabled}
+ .asm.stepi configure -state disabled
+ .asm.nexti configure -state disabled
+ .asm.continue configure -state disabled
+ .asm.finish configure -state disabled
+ .asm.up configure -state disabled
+ .asm.down configure -state disabled
+ .asm.bottom configure -state disabled
}
+ return
}
proc gdbtk_tcl_idle {} {
if [winfo exists .src] {
- catch {.src.start configure -state normal}
- catch {.src.stop configure -state disabled}
- catch {.src.step configure -state normal}
- catch {.src.next configure -state normal}
- catch {.src.continue configure -state normal}
- catch {.src.finish configure -state normal}
- catch {.src.up configure -state normal}
- catch {.src.down configure -state normal}
- catch {.src.bottom configure -state normal}
+ .src.start configure -state normal
+ .src.stop configure -state disabled
+ .src.step configure -state normal
+ .src.next configure -state normal
+ .src.continue configure -state normal
+ .src.finish configure -state normal
+ .src.up configure -state normal
+ .src.down configure -state normal
+ .src.bottom configure -state normal
}
if [winfo exists .asm] {
- catch {.asm.stepi configure -state normal}
- catch {.asm.nexti configure -state normal}
- catch {.asm.continue configure -state normal}
- catch {.asm.finish configure -state normal}
- catch {.asm.up configure -state normal}
- catch {.asm.down configure -state normal}
- catch {.asm.bottom configure -state normal}
- catch {.asm.close configure -state normal}
+ .asm.stepi configure -state normal
+ .asm.nexti configure -state normal
+ .asm.continue configure -state normal
+ .asm.finish configure -state normal
+ .asm.up configure -state normal
+ .asm.down configure -state normal
+ .asm.bottom configure -state normal
}
+ return
}
#
.file_popup add command -label "Edit" -command {exec $editor +$selected_line $selected_file &}
.file_popup add command -label "Set breakpoint" -command {gdb_cmd "break $selected_file:$selected_line"}
+# Use this procedure to get the GDB core to execute the string `cmd'. This is
+# a wrapper around gdb_cmd, which will catch errors, and send output to the
+# command window. It will also cause all of the other windows to be updated.
+
+proc interactive_cmd {cmd} {
+ catch {gdb_cmd "$cmd"} result
+ .cmd.text insert end $result
+ .cmd.text yview -pickplace end
+ update_ptr
+}
+
#
# Bindings:
#
#
# Local procedure:
#
-# do_nothing - Does absoultely nothing.
+# do_nothing - Does absolutely nothing.
#
# Description:
#
#
# Local procedure:
#
-# create_expr_win - Creat expression display window
+# not_implemented_yet - warn that a feature is unavailable
+#
+# Description:
+#
+# This procedure warns that something doesn't actually work yet.
+#
+
+proc not_implemented_yet {message} {
+ tk_dialog .unimpl "gdb : unimpl" \
+ "$message: not implemented in the interface yet" \
+ {} 1 "OK"
+}
+
+##
+# Local procedure:
+#
+# create_expr_window - Create expression display window
#
# Description:
#
# Create the expression display window.
#
-proc create_expr_win {} {
+set expr_num 0
+
+proc add_expr {expr} {
+ global expr_update_list
+ global expr_num
+
+ incr expr_num
+
+ set e .expr.e${expr_num}
+
+ frame $e
+
+ checkbutton $e.update -text " " -relief flat \
+ -variable expr_update_list($expr_num)
+ text $e.expr -width 20 -height 1
+ $e.expr insert 0.0 $expr
+ bind $e.expr <1> "update_expr $expr_num"
+ text $e.val -width 20 -height 1
+
+ update_expr $expr_num
+
+ pack $e.update -side left -anchor nw
+ pack $e.expr $e.val -side left -expand yes -fill x
+
+ pack $e -side top -fill x -anchor w
+}
+
+set delete_expr_flag 0
+
+# This is a krock!!!
+
+proc delete_expr {} {
+ global delete_expr_flag
+
+ if {$delete_expr_flag == 1} {
+ set delete_expr_flag 0
+ tk_butUp .expr.delete
+ bind .expr.delete <Any-Leave> {}
+ } else {
+ set delete_expr_flag 1
+ bind .expr.delete <Any-Leave> do_nothing
+ tk_butDown .expr.delete
+ }
+}
+
+proc update_expr {expr_num} {
+ global delete_expr_flag
+ global expr_update_list
+
+ set e .expr.e${expr_num}
+
+ if {$delete_expr_flag == 1} {
+ set delete_expr_flag 0
+ destroy $e
+ tk_butUp .expr.delete
+ tk_butLeave .expr.delete
+ bind .expr.delete <Any-Leave> {}
+ unset expr_update_list($expr_num)
+ return
+ }
+
+ set expr [$e.expr get 0.0 end]
+
+ $e.val delete 0.0 end
+ if [catch "gdb_eval $expr" val] {
+
+ } else {
+ $e.val insert 0.0 $val
+ }
+}
+
+proc update_exprs {} {
+ global expr_update_list
+
+ foreach expr_num [array names expr_update_list] {
+ if $expr_update_list($expr_num) {
+ update_expr $expr_num
+ }
+ }
+}
+
+proc create_expr_window {} {
+
+ if [winfo exists .expr] {raise .expr ; return}
+
toplevel .expr
wm minsize .expr 1 1
wm title .expr Expression
- canvas .expr.c -yscrollcommand {.expr.scroll set} -cursor hand2 \
- -borderwidth 2 -relief groove
- scrollbar .expr.scroll -orient vertical -command {.expr.c yview}
- entry .expr.entry -borderwidth 2 -relief groove
+ wm iconname .expr "Reg config"
+
+ frame .expr.entryframe
+
+ entry .expr.entry -borderwidth 2 -relief sunken
+ bind .expr <Enter> {focus .expr.entry}
+ bind .expr.entry <Key-Return> {add_expr [.expr.entry get]
+ .expr.entry delete 0 end }
+
+ label .expr.entrylab -text "Expression: "
+
+ pack .expr.entrylab -in .expr.entryframe -side left
+ pack .expr.entry -in .expr.entryframe -side left -fill x -expand yes
+
+ frame .expr.buts
+
+ button .expr.delete -text Delete
+ bind .expr.delete <1> delete_expr
- pack .expr.entry -side bottom -fill x
- pack .expr.c -side left -fill both -expand yes
- pack .expr.scroll -side right -fill y
+ button .expr.close -text Close -command {destroy .expr}
- .expr.c create text 100 0 -text "Text string"
- .expr.c create rectangle 245 195 255 205 -outline black -fill white
+ pack .expr.delete -side left -fill x -expand yes -in .expr.buts
+ pack .expr.close -side right -fill x -expand yes -in .expr.buts
+
+ pack .expr.buts -side bottom -fill x
+ pack .expr.entryframe -side bottom -fill x
+
+ frame .expr.labels
+
+ label .expr.updlab -text Update
+ label .expr.exprlab -text Expression
+ label .expr.vallab -text Value
+
+ pack .expr.updlab -side left -in .expr.labels
+ pack .expr.exprlab .expr.vallab -side left -in .expr.labels -expand yes -anchor w
+
+ pack .expr.labels -side top -fill x -anchor w
}
#
#
# Description:
#
-# Display EXPRESSION and it's value in the expression display window.
+# Display EXPRESSION and its value in the expression display window.
#
proc display_expression {expression} {
- if ![winfo exists .expr] {create_expr_win}
-
+ create_expr_window
+ add_expr $expression
}
#
# File can't be read. Put error message into .src.nofile window and return.
catch {destroy .src.nofile}
- text .src.nofile -height 25 -width 88 -relief raised \
+ text .src.nofile -height 25 -width 88 -relief sunken \
-borderwidth 2 -yscrollcommand textscrollproc \
-setgrid true -cursor hand2
.src.nofile insert 0.0 $fh
# Actually create and do basic configuration on the text widget.
- text $win -height 25 -width 88 -relief raised -borderwidth 2 \
+ text $win -height 25 -width 88 -relief sunken -borderwidth 2 \
-yscrollcommand textscrollproc -setgrid true -cursor hand2
# Setup all the bindings
bind $win <Enter> {focus %W}
-# bind $win <1> {listing_window_button_1 %W %X %Y %x %y}
bind $win <1> do_nothing
bind $win <B1-Motion> do_nothing
- bind $win n {catch {gdb_cmd next} ; update_ptr}
- bind $win s {catch {gdb_cmd step} ; update_ptr}
- bind $win c {catch {gdb_cmd continue} ; update_ptr}
- bind $win f {catch {gdb_cmd finish} ; update_ptr}
- bind $win u {catch {gdb_cmd up} ; update_ptr}
- bind $win d {catch {gdb_cmd down} ; update_ptr}
+ bind $win <Key-Alt_R> do_nothing
+ bind $win <Key-Alt_L> do_nothing
+ bind $win <Key-Prior> "$win yview {@0,0 - 10 lines}"
+ bind $win <Key-Next> "$win yview {@0,0 + 10 lines}"
+ bind $win <Key-Up> "$win yview {@0,0 - 1 lines}"
+ bind $win <Key-Down> "$win yview {@0,0 + 1 lines}"
+ bind $win <Key-Home> {update_listing [gdb_loc]}
+ bind $win <Key-End> "$win yview -pickplace end"
+
+ bind $win n {interactive_cmd next}
+ bind $win s {interactive_cmd step}
+ bind $win c {interactive_cmd continue}
+ bind $win f {interactive_cmd finish}
+ bind $win u {interactive_cmd up}
+ bind $win d {interactive_cmd down}
$win delete 0.0 end
$win insert 0.0 [read $fh]
proc create_asm_win {funcname pc} {
global breakpoint_file
global breakpoint_line
- global current_output_win
global pclist
+ global disassemble_with_source
# Replace all the dirty characters in $filename with clean ones, and generate
# a unique name for the text widget.
# Actually create and do basic configuration on the text widget.
- text $win -height 25 -width 88 -relief raised -borderwidth 2 \
+ text $win -height 25 -width 80 -relief sunken -borderwidth 2 \
-setgrid true -cursor hand2 -yscrollcommand asmscrollproc
# Setup all the bindings
bind $win <Enter> {focus %W}
bind $win <1> {asm_window_button_1 %W %X %Y %x %y}
bind $win <B1-Motion> do_nothing
- bind $win n {catch {gdb_cmd nexti} ; update_ptr}
- bind $win s {catch {gdb_cmd stepi} ; update_ptr}
- bind $win c {catch {gdb_cmd continue} ; update_ptr}
- bind $win f {catch {gdb_cmd finish} ; update_ptr}
- bind $win u {catch {gdb_cmd up} ; update_ptr}
- bind $win d {catch {gdb_cmd down} ; update_ptr}
+
+ bind $win <Key-Alt_R> do_nothing
+ bind $win <Key-Alt_L> do_nothing
+ bind $win <Key-Prior> "$win yview {@0,0 - 10 lines}"
+ bind $win <Key-Next> "$win yview {@0,0 + 10 lines}"
+ bind $win <Key-Up> "$win yview {@0,0 - 1 lines}"
+ bind $win <Key-Down> "$win yview {@0,0 + 1 lines}"
+ bind $win <Key-Home> {update_assembly [gdb_loc]}
+ bind $win <Key-End> "$win yview -pickplace end"
+
+ bind $win n {interactive_cmd nexti}
+ bind $win s {interactive_cmd stepi}
+ bind $win c {interactive_cmd continue}
+ bind $win f {interactive_cmd finish}
+ bind $win u {interactive_cmd up}
+ bind $win d {interactive_cmd down}
# Disassemble the code, and read it into the new text widget
- set temp $current_output_win
- set current_output_win $win
- gdb_cmd "disassemble $pc"
- set current_output_win $temp
+ $win insert end [gdb_disassemble $disassemble_with_source $pc]
set numlines [$win index end]
set numlines [lindex [split $numlines .] 0]
# Delete the first and last lines, cuz these contain useless info
- $win delete 1.0 2.0
- $win delete {end - 1 lines} end
- decr numlines 2
+# $win delete 1.0 2.0
+# $win delete {end - 1 lines} end
+# decr numlines 2
# Add margins (for annotations) and note the PC for each line
$win insert $i.0 " "
}
-
# Scan though the breakpoint data base and install any destined for this file
# foreach bpnum [array names breakpoint_file] {
proc create_asm_window {} {
global cfunc
- if ![winfo exists .asm] {
- set cfunc *None*
- set win [asm_win_name $cfunc]
+ if [winfo exists .asm] {raise .asm ; return}
- build_framework .asm Assembly "*NIL*"
+ set cfunc *None*
+ set win [asm_win_name $cfunc]
- .asm.text configure -yscrollcommand asmscrollproc
+ build_framework .asm Assembly "*NIL*"
- frame .asm.row1
- frame .asm.row2
+# First, delete all the old menu entries
- button .asm.stepi -width 6 -text Stepi \
- -command {catch {gdb_cmd stepi} ; update_ptr}
- button .asm.nexti -width 6 -text Nexti \
- -command {catch {gdb_cmd nexti} ; update_ptr}
- button .asm.continue -width 6 -text Cont \
- -command {catch {gdb_cmd continue} ; update_ptr}
- button .asm.finish -width 6 -text Finish \
- -command {catch {gdb_cmd finish} ; update_ptr}
- button .asm.up -width 6 -text Up -command {catch {gdb_cmd up} ; update_ptr}
- button .asm.down -width 6 -text Down \
- -command {catch {gdb_cmd down} ; update_ptr}
- button .asm.bottom -width 6 -text Bottom \
- -command {catch {gdb_cmd {frame 0}} ; update_ptr}
+ .asm.menubar.view.menu delete 0 last
- pack .asm.stepi .asm.continue .asm.up .asm.bottom -side left -padx 3 -pady 5 -in .asm.row1
- pack .asm.nexti .asm.finish .asm.down -side left -padx 3 -pady 5 -in .asm.row2
+ .asm.text configure -yscrollcommand asmscrollproc
- pack .asm.row2 .asm.row1 -side bottom -anchor w -before .asm.info
+ frame .asm.row1
+ frame .asm.row2
- update
+ button .asm.stepi -width 6 -text Stepi \
+ -command {interactive_cmd stepi}
+ button .asm.nexti -width 6 -text Nexti \
+ -command {interactive_cmd nexti}
+ button .asm.continue -width 6 -text Cont \
+ -command {interactive_cmd continue}
+ button .asm.finish -width 6 -text Finish \
+ -command {interactive_cmd finish}
+ button .asm.up -width 6 -text Up -command {interactive_cmd up}
+ button .asm.down -width 6 -text Down \
+ -command {interactive_cmd down}
+ button .asm.bottom -width 6 -text Bottom \
+ -command {interactive_cmd {frame 0}}
- update_assembly [gdb_loc]
- }
+ pack .asm.stepi .asm.continue .asm.up .asm.bottom -side left -padx 3 -pady 5 -in .asm.row1
+ pack .asm.nexti .asm.finish .asm.down -side left -padx 3 -pady 5 -in .asm.row2
+
+ pack .asm.row2 .asm.row1 -side bottom -anchor w -before .asm.info
+
+ update
+
+ update_assembly [gdb_loc]
+
+# We do this update_assembly to get the proper value of disassemble-from-exec.
+
+# exec file menu item
+ .asm.menubar.view.menu add radiobutton -label "Exec file" \
+ -variable disassemble-from-exec -value 1
+# target memory menu item
+ .asm.menubar.view.menu add radiobutton -label "Target memory" \
+ -variable disassemble-from-exec -value 0
+
+# Disassemble with source
+ .asm.menubar.view.menu add checkbutton -label "Source" \
+ -variable disassemble_with_source -onvalue source \
+ -offvalue nosource -command {
+ foreach asm [info command .asm.func_*] {
+ destroy $asm
+ }
+ set cfunc NIL
+ update_assembly [gdb_loc]
+ }
}
proc reg_config_menu {} {
proc create_registers_window {} {
global reg_format
- if [winfo exists .reg] return
+ if [winfo exists .reg] {raise .reg ; return}
# Create an initial register display list consisting of all registers
.reg.menubar.view.menu delete 0 last
# Hex menu item
- .reg.menubar.view.menu add radiobutton -variable reg_format \
- -label Hex -value x -command {update_registers all}
+ .reg.menubar.view.menu add radiobutton -label Hex \
+ -command {set reg_format x ; update_registers all}
# Decimal menu item
- .reg.menubar.view.menu add radiobutton -variable reg_format \
- -label Decimal -value d -command {update_registers all}
+ .reg.menubar.view.menu add radiobutton -label Decimal \
+ -command {set reg_format d ; update_registers all}
# Octal menu item
- .reg.menubar.view.menu add radiobutton -variable reg_format \
- -label Octal -value o -command {update_registers all}
+ .reg.menubar.view.menu add radiobutton -label Octal \
+ -command {set reg_format o ; update_registers all}
# Natural menu item
- .reg.menubar.view.menu add radiobutton -variable reg_format \
- -label Natural -value {} -command {update_registers all}
+ .reg.menubar.view.menu add radiobutton -label Natural \
+ -command {set reg_format {} ; update_registers all}
# Config menu item
.reg.menubar.view.menu add separator
-after .asm.scroll
.asm.scroll configure -command "$win yview"
set line [pc_to_line $pclist($cfunc) $pc]
+ update
$win yview [expr $line - $asm_screen_height / 2]
}
if [winfo exists .reg] {
update_registers changed
}
+ if [winfo exists .expr] {
+ update_exprs
+ }
+ if [winfo exists .autocmd] {
+ update_autocmd
+ }
}
# Make toplevel window disappear
wm minsize .files_window 1 1
# wm overrideredirect .files_window true
- listbox .files_window.list -geometry 30x20 -setgrid true
+ listbox .files_window.list -geometry 30x20 -setgrid true \
+ -yscrollcommand {.files_window.scroll set} -relief sunken \
+ -borderwidth 2
+ scrollbar .files_window.scroll -orient vertical \
+ -command {.files_window.list yview} -relief sunken
button .files_window.close -text Close -command {destroy .files_window}
tk_listboxSingleSelect .files_window.list
- eval .files_window.list insert 0 [lsort [gdb_listfiles]]
- pack .files_window.list -side top -fill both -expand yes
+
+# Get the file list from GDB, sort it, and format it as one entry per line.
+
+ set filelist [join [lsort [gdb_listfiles]] "\n"]
+
+# Now, remove duplicates (by using uniq)
+
+ set fh [open "| uniq > /tmp/gdbtk.[pid]" w]
+ puts $fh $filelist
+ close $fh
+ set fh [open /tmp/gdbtk.[pid]]
+ set filelist [split [read $fh] "\n"]
+ set filelist [lrange $filelist 0 [expr [llength $filelist] - 2]]
+ close $fh
+ exec rm /tmp/gdbtk.[pid]
+
+# Insert the file list into the widget
+
+ eval .files_window.list insert 0 $filelist
+
pack .files_window.close -side bottom -fill x -expand no -anchor s
+ pack .files_window.scroll -side right -fill both
+ pack .files_window.list -side left -fill both -expand yes
bind .files_window.list <Any-ButtonRelease-1> {
set file [%W get [%W curselection]]
gdb_cmd "list $file:1,0"
button .files -text Files -command files_command
+proc apply_filespec {label default command} {
+ set filename [FSBox $label $default]
+ if {$filename != ""} {
+ if [catch {gdb_cmd "$command $filename"} retval] {
+ tk_dialog .filespec_error "gdb : $label error" \
+ "Error in command \"$command $filename\"" {} 0 Dismiss
+ return
+ }
+ update_ptr
+ }
+}
+
# Setup command window
proc build_framework {win {title GDBtk} {label {}}} {
-menu ${win}.menubar.file.menu -underline 0
menu ${win}.menubar.file.menu
+ ${win}.menubar.file.menu add command -label File... \
+ -command {apply_filespec File a.out file}
+ ${win}.menubar.file.menu add command -label Target... \
+ -command { not_implemented_yet "target" }
${win}.menubar.file.menu add command -label Edit \
-command {exec $editor +[expr ($screen_top + $screen_bot)/2] $cfile &}
+ ${win}.menubar.file.menu add separator
+ ${win}.menubar.file.menu add command -label "Exec File..." \
+ -command {apply_filespec {Exec File} a.out exec-file}
+ ${win}.menubar.file.menu add command -label "Symbol File..." \
+ -command {apply_filespec {Symbol File} a.out symbol-file}
+ ${win}.menubar.file.menu add command -label "Add Symbol File..." \
+ -command { not_implemented_yet "menu item, add symbol file" }
+ ${win}.menubar.file.menu add command -label "Core File..." \
+ -command {apply_filespec {Core File} core core-file}
+
+ ${win}.menubar.file.menu add separator
${win}.menubar.file.menu add command -label Close \
-command "destroy ${win}"
+ ${win}.menubar.file.menu add separator
${win}.menubar.file.menu add command -label Quit \
- -command {catch {gdb_cmd quit}}
-
- menubutton ${win}.menubar.view -padx 12 -text View \
+ -command {interactive_cmd quit}
+
+ menubutton ${win}.menubar.commands -padx 12 -text Commands \
+ -menu ${win}.menubar.commands.menu -underline 0
+
+ menu ${win}.menubar.commands.menu
+ ${win}.menubar.commands.menu add command -label Run \
+ -command {interactive_cmd run}
+ ${win}.menubar.commands.menu add command -label Step \
+ -command {interactive_cmd step}
+ ${win}.menubar.commands.menu add command -label Next \
+ -command {interactive_cmd next}
+ ${win}.menubar.commands.menu add command -label Continue \
+ -command {interactive_cmd continue}
+ ${win}.menubar.commands.menu add separator
+ ${win}.menubar.commands.menu add command -label Stepi \
+ -command {interactive_cmd stepi}
+ ${win}.menubar.commands.menu add command -label Nexti \
+ -command {interactive_cmd nexti}
+
+ menubutton ${win}.menubar.view -padx 12 -text Options \
-menu ${win}.menubar.view.menu -underline 0
menu ${win}.menubar.view.menu
- ${win}.menubar.view.menu add command -label Hex -command {echo Hex}
+ ${win}.menubar.view.menu add command -label Hex \
+ -command {echo Hex}
${win}.menubar.view.menu add command -label Decimal \
-command {echo Decimal}
- ${win}.menubar.view.menu add command -label Octal -command {echo Octal}
+ ${win}.menubar.view.menu add command -label Octal \
+ -command {echo Octal}
menubutton ${win}.menubar.window -padx 12 -text Window \
-menu ${win}.menubar.window.menu -underline 0
menu ${win}.menubar.window.menu
- ${win}.menubar.window.menu add command -label Source \
- -command {echo Source}
${win}.menubar.window.menu add command -label Command \
- -command {echo Command}
+ -command create_command_window
+ ${win}.menubar.window.menu add separator
+ ${win}.menubar.window.menu add command -label Source \
+ -command create_source_window
${win}.menubar.window.menu add command -label Assembly \
- -command {create_asm_window ; update_ptr}
- ${win}.menubar.window.menu add command -label Register \
- -command {create_registers_window ; update_ptr}
+ -command create_asm_window
+ ${win}.menubar.window.menu add separator
+ ${win}.menubar.window.menu add command -label Registers \
+ -command create_registers_window
+ ${win}.menubar.window.menu add command -label Expressions \
+ -command create_expr_window
+ ${win}.menubar.window.menu add command -label "Auto Command" \
+ -command create_autocmd_window
+ ${win}.menubar.window.menu add command -label Breakpoints \
+ -command create_breakpoints_window
+
+# ${win}.menubar.window.menu add separator
+# ${win}.menubar.window.menu add command -label Files \
+# -command { not_implemented_yet "files window" }
menubutton ${win}.menubar.help -padx 12 -text Help \
-menu ${win}.menubar.help.menu -underline 0
${win}.menubar.help.menu add command -label "Report bug" \
-command {exec send-pr}
- tk_menuBar ${win}.menubar ${win}.menubar.file ${win}.menubar.view \
- ${win}.menubar.window ${win}.menubar.help
- pack ${win}.menubar.file ${win}.menubar.view ${win}.menubar.window \
- -side left
- pack ${win}.menubar.help -side right
+ tk_menuBar ${win}.menubar \
+ ${win}.menubar.file \
+ ${win}.menubar.view \
+ ${win}.menubar.window \
+ ${win}.menubar.help
+ pack ${win}.menubar.file \
+ ${win}.menubar.view \
+ ${win}.menubar.window -side left
+ pack ${win}.menubar.help -side right
frame ${win}.info
- text ${win}.text -height 25 -width 80 -relief raised -borderwidth 2 \
+ text ${win}.text -height 25 -width 80 -relief sunken -borderwidth 2 \
-setgrid true -cursor hand2 -yscrollcommand "${win}.scroll set"
set ${win}.label $label
- label ${win}.label -textvariable ${win}.label -borderwidth 2 -relief raised
+ label ${win}.label -textvariable ${win}.label -borderwidth 2 -relief sunken
+
+ scrollbar ${win}.scroll -orient vertical -command "${win}.text yview" \
+ -relief sunken
- scrollbar ${win}.scroll -orient vertical -command "${win}.text yview"
+ bind $win <Key-Alt_R> do_nothing
+ bind $win <Key-Alt_L> do_nothing
+ bind $win <Key-Prior> "$win yview {@0,0 - 10 lines}"
+ bind $win <Key-Next> "$win yview {@0,0 + 10 lines}"
+ bind $win <Key-Up> "$win yview {@0,0 - 1 lines}"
+ bind $win <Key-Down> "$win yview {@0,0 + 1 lines}"
+ bind $win <Key-Home> "$win yview -pickplace end"
+ bind $win <Key-End> "$win yview -pickplace end"
pack ${win}.label -side bottom -fill x -in ${win}.info
pack ${win}.scroll -side right -fill y -in ${win}.info
global wins
global cfile
+ if [winfo exists .src] {raise .src ; return}
+
build_framework .src Source "*No file*"
# First, delete all the old view menu entries
frame .src.row2
button .src.start -width 6 -text Start -command \
- {catch {gdb_cmd {break main}}
- catch {gdb_cmd {enable delete $bpnum}}
- catch {gdb_cmd run}
- update_ptr }
+ {interactive_cmd {break main}
+ interactive_cmd {enable delete $bpnum}
+ interactive_cmd run }
button .src.stop -width 6 -text Stop -fg red -activeforeground red \
-state disabled -command gdb_stop
button .src.step -width 6 -text Step \
- -command {catch {gdb_cmd step} ; update_ptr}
+ -command {interactive_cmd step}
button .src.next -width 6 -text Next \
- -command {catch {gdb_cmd next} ; update_ptr}
+ -command {interactive_cmd next}
button .src.continue -width 6 -text Cont \
- -command {catch {gdb_cmd continue} ; update_ptr}
+ -command {interactive_cmd continue}
button .src.finish -width 6 -text Finish \
- -command {catch {gdb_cmd finish} ; update_ptr}
+ -command {interactive_cmd finish}
button .src.up -width 6 -text Up \
- -command {catch {gdb_cmd up} ; update_ptr}
+ -command {interactive_cmd up}
button .src.down -width 6 -text Down \
- -command {catch {gdb_cmd down} ; update_ptr}
+ -command {interactive_cmd down}
button .src.bottom -width 6 -text Bottom \
- -command {catch {gdb_cmd {frame 0}} ; update_ptr}
+ -command {interactive_cmd {frame 0}}
pack .src.start .src.step .src.continue .src.up .src.bottom \
-side left -padx 3 -pady 5 -in .src.row1
set screen_bot [lindex $args 3]}
}
+proc update_autocmd {} {
+ global .autocmd.label
+ global accumulate_output
+
+ catch {gdb_cmd "${.autocmd.label}"} result
+ if !$accumulate_output { .autocmd.text delete 0.0 end }
+ .autocmd.text insert end $result
+ .autocmd.text yview -pickplace end
+}
+
+proc create_autocmd_window {} {
+ global .autocmd.label
+
+ if [winfo exists .autocmd] {raise .autocmd ; return}
+
+ build_framework .autocmd "Auto Command" ""
+
+# First, delete all the old view menu entries
+
+ .autocmd.menubar.view.menu delete 0 last
+
+# Accumulate output option
+
+ .autocmd.menubar.view.menu add checkbutton \
+ -variable accumulate_output \
+ -label "Accumulate output" -onvalue 1 -offvalue 0
+
+# Now, create entry widget with label
+
+ frame .autocmd.entryframe
+
+ entry .autocmd.entry -borderwidth 2 -relief sunken
+ bind .autocmd <Enter> {focus .autocmd.entry}
+ bind .autocmd.entry <Key-Return> {set .autocmd.label [.autocmd.entry get]
+ .autocmd.entry delete 0 end }
+
+ label .autocmd.entrylab -text "Command: "
+
+ pack .autocmd.entrylab -in .autocmd.entryframe -side left
+ pack .autocmd.entry -in .autocmd.entryframe -side left -fill x -expand yes
+
+ pack .autocmd.entryframe -side bottom -fill x -before .autocmd.info
+}
+
+# Return the longest common prefix in SLIST. Can be empty string.
+
+proc find_lcp slist {
+# Handle trivial cases where list is empty or length 1
+ if {[llength $slist] <= 1} {return [lindex $slist 0]}
+
+ set prefix [lindex $slist 0]
+ set prefixlast [expr [string length $prefix] - 1]
+
+ foreach str [lrange $slist 1 end] {
+ set test_str [string range $str 0 $prefixlast]
+ while {[string compare $test_str $prefix] != 0} {
+ decr prefixlast
+ set prefix [string range $prefix 0 $prefixlast]
+ set test_str [string range $str 0 $prefixlast]
+ }
+ if {$prefixlast < 0} break
+ }
+ return $prefix
+}
+
+# Look through COMPLETIONS to generate the suffix needed to do command
+# completion on CMD.
+
+proc find_completion {cmd completions} {
+# Get longest common prefix
+ set lcp [find_lcp $completions]
+ set cmd_len [string length $cmd]
+# Return suffix beyond end of cmd
+ return [string range $lcp $cmd_len end]
+}
+
proc create_command_window {} {
global command_line
+ global saw_tab
+
+ set saw_tab 0
+ if [winfo exists .cmd] {raise .cmd ; return}
build_framework .cmd Command "* Command Buffer *"
bind .cmd.text <Enter> {focus %W}
bind .cmd.text <Delete> {delete_char %W}
bind .cmd.text <BackSpace> {delete_char %W}
+ bind .cmd.text <Control-c> gdb_stop
bind .cmd.text <Control-u> {delete_line %W}
bind .cmd.text <Any-Key> {
global command_line
+ global saw_tab
+ set saw_tab 0
%W insert end %A
%W yview -pickplace end
append command_line %A
}
bind .cmd.text <Key-Return> {
global command_line
+ global saw_tab
+ set saw_tab 0
%W insert end \n
- %W yview -pickplace end
- catch "gdb_cmd [list $command_line]"
+ interactive_cmd $command_line
+
+# %W yview -pickplace end
+# catch "gdb_cmd [list $command_line]" result
+# %W insert end $result
set command_line {}
- update_ptr
+# update_ptr
%W insert end "(gdb) "
%W yview -pickplace end
}
+ bind .cmd.text <Button-2> {
+ global command_line
+ %W insert end [selection get]
+ %W yview -pickplace end
+ append command_line [selection get]
+ }
+ bind .cmd.text <Key-Tab> {
+ global command_line
+ global saw_tab
+ global choices
+
+ set choices [gdb_cmd "complete $command_line"]
+ set choices [string trimright $choices \n]
+ set choices [split $choices \n]
+
+# Just do completion if this is the first tab
+ if !$saw_tab {
+ set saw_tab 1
+ set completion [find_completion $command_line $choices]
+ append command_line $completion
+# Here is where the completion is actually done. If there is one match,
+# complete the command and print a space. If two or more matches, complete the
+# command and beep. If no match, just beep.
+ switch -exact [llength $choices] {
+ 0 {}
+ 1 {%W insert end "$completion "
+ append command_line " "
+ return }
+ default {%W insert end "$completion"}
+ }
+ puts -nonewline stdout \007
+ flush stdout
+ %W yview -pickplace end
+ } else {
+# User hit another consecutive tab. List the choices. Note that at this
+# point, choices may contain commands with spaces. We have to lop off
+# everything before (and including) the last space so that the completion
+# list only shows the possibilities for the last token.
+
+ set choices [lsort $choices]
+ if [regexp ".* " $command_line prefix] {
+ regsub -all $prefix $choices {} choices
+ }
+ %W insert end "\n[join $choices { }]\n(gdb) $command_line"
+ %W yview -pickplace end
+ }
+ }
proc delete_char {win} {
global command_line
set tmp [expr [string length $command_line] - 2]
set command_line [string range $command_line 0 $tmp]
}
-
proc delete_line {win} {
global command_line
}
}
+#
+# fileselect.tcl --
+# simple file selector.
+#
+# Mario Jorge Silva msilva@cs.Berkeley.EDU
+# University of California Berkeley Ph: +1(510)642-8248
+# Computer Science Division, 571 Evans Hall Fax: +1(510)642-5775
+# Berkeley CA 94720
+#
+#
+# Copyright 1993 Regents of the University of California
+# Permission to use, copy, modify, and distribute this
+# software and its documentation for any purpose and without
+# fee is hereby granted, provided that this copyright
+# notice appears in all copies. The University of California
+# makes no representations about the suitability of this
+# software for any purpose. It is provided "as is" without
+# express or implied warranty.
+#
+
+
+# names starting with "fileselect" are reserved by this module
+# no other names used.
+# Hack - FSBox is defined instead of fileselect for backwards compatibility
+
+
+# this is the proc that creates the file selector box
+# purpose - comment string
+# defaultName - initial value for name
+# cmd - command to eval upon OK
+# errorHandler - command to eval upon Cancel
+# If neither cmd or errorHandler are specified, the return value
+# of the FSBox procedure is the selected file name.
+
+proc FSBox {{purpose "Select file:"} {defaultName ""} {cmd ""} {errorHandler
+""}} {
+ global fileselect
+ set w .fileSelect
+ if [Exwin_Toplevel $w "Select File" FileSelect] {
+ # path independent names for the widgets
+
+ set fileselect(list) $w.file.sframe.list
+ set fileselect(scroll) $w.file.sframe.scroll
+ set fileselect(direntry) $w.file.f1.direntry
+ set fileselect(entry) $w.file.f2.entry
+ set fileselect(ok) $w.but.ok
+ set fileselect(cancel) $w.but.cancel
+ set fileselect(msg) $w.label
+
+ set fileselect(result) "" ;# value to return if no callback procedures
+
+ # widgets
+ Widget_Label $w label {top fillx pady 10 padx 20} -anchor w -width 24
+ Widget_Frame $w file Dialog {left expand fill} -bd 10
+
+ Widget_Frame $w.file f1 Exmh {top fillx}
+ Widget_Label $w.file.f1 label {left} -text "Dir"
+ Widget_Entry $w.file.f1 direntry {right fillx expand} -width 30
+
+ Widget_Frame $w.file sframe
+
+ scrollbar $w.file.sframe.yscroll -relief sunken \
+ -command [list $w.file.sframe.list yview]
+ listbox $w.file.sframe.list -relief sunken \
+ -yscroll [list $w.file.sframe.yscroll set] -setgrid 1
+ pack append $w.file.sframe \
+ $w.file.sframe.yscroll {right filly} \
+ $w.file.sframe.list {left expand fill}
+
+ Widget_Frame $w.file f2 Exmh {top fillx}
+ Widget_Label $w.file.f2 label {left} -text Name
+ Widget_Entry $w.file.f2 entry {right fillx expand}
+
+ # buttons
+ $w.but.quit configure -text Cancel \
+ -command [list fileselect.cancel.cmd $w]
+
+ Widget_AddBut $w.but ok OK \
+ [list fileselect.ok.cmd $w $cmd $errorHandler] {left padx 1}
+
+ Widget_AddBut $w.but list List \
+ [list fileselect.list.cmd $w] {left padx 1}
+ Widget_CheckBut $w.but listall "List all" fileselect(pattern)
+ $w.but.listall configure -onvalue "{*,.*}" -offvalue "*" \
+ -command {fileselect.list.cmd $fileselect(direntry)}
+ $w.but.listall deselect
+
+ # Set up bindings for the browser.
+ foreach ww [list $w $fileselect(entry)] {
+ bind $ww <Return> [list $fileselect(ok) invoke]
+ bind $ww <Control-c> [list $fileselect(cancel) invoke]
+ }
+ bind $fileselect(direntry) <Return> [list fileselect.list.cmd %W]
+ bind $fileselect(direntry) <Tab> [list fileselect.tab.dircmd]
+ bind $fileselect(entry) <Tab> [list fileselect.tab.filecmd]
+
+ tk_listboxSingleSelect $fileselect(list)
+
+
+ bind $fileselect(list) <Button-1> {
+ # puts stderr "button 1 release"
+ %W select from [%W nearest %y]
+ $fileselect(entry) delete 0 end
+ $fileselect(entry) insert 0 [%W get [%W nearest %y]]
+ }
+
+ bind $fileselect(list) <Key> {
+ %W select from [%W nearest %y]
+ $fileselect(entry) delete 0 end
+ $fileselect(entry) insert 0 [%W get [%W nearest %y]]
+ }
+
+ bind $fileselect(list) <Double-ButtonPress-1> {
+ # puts stderr "double button 1"
+ %W select from [%W nearest %y]
+ $fileselect(entry) delete 0 end
+ $fileselect(entry) insert 0 [%W get [%W nearest %y]]
+ $fileselect(ok) invoke
+ }
+
+ bind $fileselect(list) <Return> {
+ %W select from [%W nearest %y]
+ $fileselect(entry) delete 0 end
+ $fileselect(entry) insert 0 [%W get [%W nearest %y]]
+ $fileselect(ok) invoke
+ }
+ }
+ set fileselect(text) $purpose
+ $fileselect(msg) configure -text $purpose
+ $fileselect(entry) delete 0 end
+ $fileselect(entry) insert 0 [file tail $defaultName]
+
+ if {[info exists fileselect(lastDir)] && ![string length $defaultName]} {
+ set dir $fileselect(lastDir)
+ } else {
+ set dir [file dirname $defaultName]
+ }
+ set fileselect(pwd) [pwd]
+ fileselect.cd $dir
+ $fileselect(direntry) delete 0 end
+ $fileselect(direntry) insert 0 [pwd]/
+
+ $fileselect(list) delete 0 end
+ $fileselect(list) insert 0 "Big directory:"
+ $fileselect(list) insert 1 $dir
+ $fileselect(list) insert 2 "Press Return for Listing"
+
+ fileselect.list.cmd $fileselect(direntry) startup
+
+ # set kbd focus to entry widget
+
+# Exwin_ToplevelFocus $w $fileselect(entry)
+
+ # Wait for button hits if no callbacks are defined
+
+ if {"$cmd" == "" && "$errorHandler" == ""} {
+ # wait for the box to be destroyed
+ update idletask
+ grab $w
+ tkwait variable fileselect(result)
+ grab release $w
+
+ set path $fileselect(result)
+ set fileselect(lastDir) [pwd]
+ fileselect.cd $fileselect(pwd)
+ return [string trimright [string trim $path] /]
+ }
+ fileselect.cd $fileselect(pwd)
+ return ""
+}
+
+proc fileselect.cd { dir } {
+ global fileselect
+ if [catch {cd $dir} err] {
+ fileselect.yck $dir
+ cd
+ }
+}
+# auxiliary button procedures
+
+proc fileselect.yck { {tag {}} } {
+ global fileselect
+ $fileselect(msg) configure -text "Yck! $tag"
+}
+proc fileselect.ok {} {
+ global fileselect
+ $fileselect(msg) configure -text $fileselect(text)
+}
+
+proc fileselect.cancel.cmd {w} {
+ global fileselect
+ set fileselect(result) {}
+ destroy $w
+}
+
+proc fileselect.list.cmd {w {state normal}} {
+ global fileselect
+ set seldir [$fileselect(direntry) get]
+ if {[catch {glob $seldir} dir]} {
+ fileselect.yck "glob failed"
+ return
+ }
+ if {[llength $dir] > 1} {
+ set dir [file dirname $seldir]
+ set pat [file tail $seldir]
+ } else {
+ set pat $fileselect(pattern)
+ }
+ fileselect.ok
+ update idletasks
+ if [file isdirectory $dir] {
+ fileselect.getfiles $dir $pat $state
+ focus $fileselect(entry)
+ } else {
+ fileselect.yck "not a dir"
+ }
+}
+
+proc fileselect.ok.cmd {w cmd errorHandler} {
+ global fileselect
+ set selname [$fileselect(entry) get]
+ set seldir [$fileselect(direntry) get]
+
+ if [string match /* $selname] {
+ set selected $selname
+ } else {
+ if [string match ~* $selname] {
+ set selected $selname
+ } else {
+ set selected $seldir/$selname
+ }
+ }
+
+ # some nasty file names may cause "file isdirectory" to return an error
+ if [catch {file isdirectory $selected} isdir] {
+ fileselect.yck "isdirectory failed"
+ return
+ }
+ if [catch {glob $selected} globlist] {
+ if ![file isdirectory [file dirname $selected]] {
+ fileselect.yck "bad pathname"
+ return
+ }
+ set globlist $selected
+ }
+ fileselect.ok
+ update idletasks
+
+ if {[llength $globlist] > 1} {
+ set dir [file dirname $selected]
+ set pat [file tail $selected]
+ fileselect.getfiles $dir $pat
+ return
+ } else {
+ set selected $globlist
+ }
+ if [file isdirectory $selected] {
+ fileselect.getfiles $selected $fileselect(pattern)
+ $fileselect(entry) delete 0 end
+ return
+ }
+
+ if {$cmd != {}} {
+ $cmd $selected
+ } else {
+ set fileselect(result) $selected
+ }
+ destroy $w
+}
+
+proc fileselect.getfiles { dir {pat *} {state normal} } {
+ global fileselect
+ $fileselect(msg) configure -text Listing...
+ update idletasks
+
+ set currentDir [pwd]
+ fileselect.cd $dir
+ if [catch {set files [lsort [glob -nocomplain $pat]]} err] {
+ $fileselect(msg) configure -text $err
+ $fileselect(list) delete 0 end
+ update idletasks
+ return
+ }
+ switch -- $state {
+ normal {
+ # Normal case - show current directory
+ $fileselect(direntry) delete 0 end
+ $fileselect(direntry) insert 0 [pwd]/
+ }
+ opt {
+ # Directory already OK (tab related)
+ }
+ newdir {
+ # Changing directory (tab related)
+ fileselect.cd $currentDir
+ }
+ startup {
+ # Avoid listing huge directories upon startup.
+ $fileselect(direntry) delete 0 end
+ $fileselect(direntry) insert 0 [pwd]/
+ if {[llength $files] > 32} {
+ fileselect.ok
+ return
+ }
+ }
+ }
+
+ # build a reordered list of the files: directories are displayed first
+ # and marked with a trailing "/"
+ if [string compare $dir /] {
+ fileselect.putfiles $files [expr {($pat == "*") ? 1 : 0}]
+ } else {
+ fileselect.putfiles $files
+ }
+ fileselect.ok
+}
+
+proc fileselect.putfiles {files {dotdot 0} } {
+ global fileselect
+
+ $fileselect(list) delete 0 end
+ if {$dotdot} {
+ $fileselect(list) insert end "../"
+ }
+ foreach i $files {
+ if {[file isdirectory $i]} {
+ $fileselect(list) insert end $i/
+ } else {
+ $fileselect(list) insert end $i
+ }
+ }
+}
+
+proc FileExistsDialog { name } {
+ set w .fileExists
+ global fileExists
+ set fileExists(ok) 0
+ {
+ message $w.msg -aspect 1000
+ pack $w.msg -side top -fill both -padx 20 -pady 20
+ $w.but.quit config -text Cancel -command {FileExistsCancel}
+ button $w.but.ok -text OK -command {FileExistsOK}
+ pack $w.but.ok -side left
+ bind $w.msg <Return> {FileExistsOK}
+ }
+ $w.msg config -text "Warning: file exists
+$name
+OK to overwrite it?"
+
+ set fileExists(focus) [focus]
+ focus $w.msg
+ grab $w
+ tkwait variable fileExists(ok)
+ grab release $w
+ destroy $w
+ return $fileExists(ok)
+}
+proc FileExistsCancel {} {
+ global fileExists
+ set fileExists(ok) 0
+}
+proc FileExistsOK {} {
+ global fileExists
+ set fileExists(ok) 1
+}
+
+proc fileselect.getfiledir { dir {basedir [pwd]} } {
+ global fileselect
+
+ set path [$fileselect(direntry) get]
+ set returnList {}
+
+ if {$dir != 0} {
+ if {[string index $path 0] == "~"} {
+ set path $path/
+ }
+ } else {
+ set path [$fileselect(entry) get]
+ }
+ if [catch {set listFile [glob -nocomplain $path*]}] {
+ return $returnList
+ }
+ foreach el $listFile {
+ if {$dir != 0} {
+ if [file isdirectory $el] {
+ lappend returnList [file tail $el]
+ }
+ } elseif ![file isdirectory $el] {
+ lappend returnList [file tail $el]
+ }
+ }
+
+ return $returnList
+}
+
+proc fileselect.gethead { list } {
+ set returnHead ""
+
+ for {set i 0} {[string length [lindex $list 0]] > $i}\
+ {incr i; set returnHead $returnHead$thisChar} {
+ set thisChar [string index [lindex $list 0] $i]
+ foreach el $list {
+ if {[string length $el] < $i} {
+ return $returnHead
+ }
+ if {$thisChar != [string index $el $i]} {
+ return $returnHead
+ }
+ }
+ }
+ return $returnHead
+}
+
+proc fileselect.expand.tilde { } {
+ global fileselect
+
+ set entry [$fileselect(direntry) get]
+ set dir [string range $entry 1 [string length $entry]]
+
+ if {$dir == ""} {
+ return
+ }
+
+ set listmatch {}
+
+ ## look in /etc/passwd
+ if [file exists /etc/passwd] {
+ if [catch {set users [exec cat /etc/passwd | sed s/:.*//]} err] {
+ puts "Error\#1 $err"
+ return
+ }
+ set list [split $users "\n"]
+ }
+ if {[lsearch -exact $list "+"] != -1} {
+ if [catch {set users [exec ypcat passwd | sed s/:.*//]} err] {
+ puts "Error\#2 $err"
+ return
+ }
+ set list [concat $list [split $users "\n"]]
+ }
+ $fileselect(list) delete 0 end
+ foreach el $list {
+ if [string match $dir* $el] {
+ lappend listmatch $el
+ $fileselect(list) insert end $el
+ }
+ }
+ set addings [fileselect.gethead $listmatch]
+ if {$addings == ""} {
+ return
+ }
+ $fileselect(direntry) delete 0 end
+ if {[llength $listmatch] == 1} {
+ $fileselect(direntry) insert 0 [file dirname ~$addings/]
+ fileselect.getfiles [$fileselect(direntry) get]
+ } else {
+ $fileselect(direntry) insert 0 ~$addings
+ }
+}
+
+proc fileselect.tab.dircmd { } {
+ global fileselect
+
+ set dir [$fileselect(direntry) get]
+ if {$dir == ""} {
+ $fileselect(direntry) delete 0 end
+ $fileselect(direntry) insert 0 [pwd]
+ if [string compare [pwd] "/"] {
+ $fileselect(direntry) insert end /
+ }
+ return
+ }
+ if [catch {set tmp [file isdirectory [file dirname $dir]]}] {
+ if {[string index $dir 0] == "~"} {
+ fileselect.expand.tilde
+ }
+ return
+ }
+ if {!$tmp} {
+ return
+ }
+ set dirFile [fileselect.getfiledir 1 $dir]
+ if ![llength $dirFile] {
+ return
+ }
+ if {[llength $dirFile] == 1} {
+ $fileselect(direntry) delete 0 end
+ $fileselect(direntry) insert 0 [file dirname $dir]
+ if [string compare [file dirname $dir] /] {
+ $fileselect(direntry) insert end /[lindex $dirFile 0]/
+ } else {
+ $fileselect(direntry) insert end [lindex $dirFile 0]/
+ }
+ fileselect.getfiles [$fileselect(direntry) get] \
+ "[file tail [$fileselect(direntry) get]]$fileselect(pattern)" opt
+ return
+ }
+ set headFile [fileselect.gethead $dirFile]
+ $fileselect(direntry) delete 0 end
+ $fileselect(direntry) insert 0 [file dirname $dir]
+ if [string compare [file dirname $dir] /] {
+ $fileselect(direntry) insert end /$headFile
+ } else {
+ $fileselect(direntry) insert end $headFile
+ }
+ if {$headFile == "" && [file isdirectory $dir]} {
+ fileselect.getfiles $dir\
+ "[file tail [$fileselect(direntry) get]]$fileselect(pattern)" opt
+ } else {
+ fileselect.getfiles [file dirname $dir]\
+ "[file tail [$fileselect(direntry) get]]*" newdir
+ }
+}
+
+proc fileselect.tab.filecmd { } {
+ global fileselect
+
+ set dir [$fileselect(direntry) get]
+ if {$dir == ""} {
+ set dir [pwd]
+ }
+ if {![file isdirectory $dir]} {
+ error "dir $dir doesn't exist"
+ }
+ set listFile [fileselect.getfiledir 0 $dir]
+ puts $listFile
+ if ![llength $listFile] {
+ return
+ }
+ if {[llength $listFile] == 1} {
+ $fileselect(entry) delete 0 end
+ $fileselect(entry) insert 0 [lindex $listFile 0]
+ return
+ }
+ set headFile [fileselect.gethead $listFile]
+ $fileselect(entry) delete 0 end
+ $fileselect(entry) insert 0 $headFile
+ fileselect.getfiles $dir "[$fileselect(entry) get]$fileselect(pattern)" opt
+}
+
+proc Exwin_Toplevel { path name {class Dialog} {dismiss yes}} {
+ global exwin
+ if [catch {wm state $path} state] {
+ set t [Widget_Toplevel $path $name $class]
+ if ![info exists exwin(toplevels)] {
+ set exwin(toplevels) [option get . exwinPaths {}]
+ }
+ set ix [lsearch $exwin(toplevels) $t]
+ if {$ix < 0} {
+ lappend exwin(toplevels) $t
+ }
+ if {$dismiss == "yes"} {
+ set f [Widget_Frame $t but Menubar {top fill}]
+ Widget_AddBut $f quit "Dismiss" [list Exwin_Dismiss $path]
+ }
+ return 1
+ } else {
+ if {$state != "normal"} {
+ catch {
+ wm geometry $path $exwin(geometry,$path)
+# Exmh_Debug Exwin_Toplevel $path $exwin(geometry,$path)
+ }
+ wm deiconify $path
+ } else {
+ catch {raise $path}
+ }
+ return 0
+ }
+}
+
+proc Exwin_Dismiss { path {geo ok} } {
+ global exwin
+ case $geo {
+ "ok" {
+ set exwin(geometry,$path) [wm geometry $path]
+ }
+ "nosize" {
+ set exwin(geometry,$path) [string trimleft [wm geometry $path] 0123456789x]
+ }
+ default {
+ catch {unset exwin(geometry,$path)}
+ }
+ }
+ wm withdraw $path
+}
+
+proc Widget_Toplevel { path name {class Dialog} {x {}} {y {}} } {
+ set self [toplevel $path -class $class]
+ set usergeo [option get $path position Position]
+ if {$usergeo != {}} {
+ if [catch {wm geometry $self $usergeo} err] {
+# Exmh_Debug Widget_Toplevel $self $usergeo => $err
+ }
+ } else {
+ if {($x != {}) && ($y != {})} {
+# Exmh_Debug Event position $self +$x+$y
+ wm geometry $self +$x+$y
+ }
+ }
+ wm title $self $name
+ wm group $self .
+ return $self
+}
+
+proc Widget_Frame {par child {class GDB} {where {top expand fill}} args } {
+ if {$par == "."} {
+ set self .$child
+ } else {
+ set self $par.$child
+ }
+ eval {frame $self -class $class} $args
+ pack append $par $self $where
+ return $self
+}
+
+proc Widget_AddBut {par but txt cmd {where {right padx 1}} } {
+ # Create a Packed button. Return the button pathname
+ set cmd2 [list button $par.$but -text $txt -command $cmd]
+ if [catch $cmd2 t] {
+ puts stderr "Widget_AddBut (warning) $t"
+ eval $cmd2 {-font fixed}
+ }
+ pack append $par $par.$but $where
+ return $par.$but
+}
+proc Widget_CheckBut {par but txt var {where {right padx 1}} } {
+ # Create a check button. Return the button pathname
+ set cmd [list checkbutton $par.$but -text $txt -variable $var]
+ if [catch $cmd t] {
+ puts stderr "Widget_CheckBut (warning) $t"
+ eval $cmd {-font fixed}
+ }
+ pack append $par $par.$but $where
+ return $par.$but
+}
+
+proc Widget_Label { frame {name label} {where {left fill}} args} {
+ set cmd [list label $frame.$name ]
+ if [catch [concat $cmd $args] t] {
+ puts stderr "Widget_Label (warning) $t"
+ eval $cmd $args {-font fixed}
+ }
+ pack append $frame $frame.$name $where
+ return $frame.$name
+}
+proc Widget_Entry { frame {name entry} {where {left fill}} args} {
+ set cmd [list entry $frame.$name ]
+ if [catch [concat $cmd $args] t] {
+ puts stderr "Widget_Entry (warning) $t"
+ eval $cmd $args {-font fixed}
+ }
+ pack append $frame $frame.$name $where
+ return $frame.$name
+}
+
+# End of fileselect.tcl.
+
# Setup the initial windows
create_source_window
}
create_command_window
+
+# Create a copyright window
+
update
+toplevel .c
+wm geometry .c +300+300
+wm overrideredirect .c true
+
+message .c.m -text [gdb_cmd "show version"] -aspect 500 -relief raised
+pack .c.m
+bind .c.m <Leave> {destroy .c}
+update
+
+if [file exists ~/.gdbtkinit] {
+ source ~/.gdbtkinit
+}