9 set current_output_win .command.text
13 update_listing {termcap.c foo /etc/termcap 200}
16 proc echo string {puts stdout $string}
18 if [info exists env(EDITOR)] then {
19 set editor $env(EDITOR)
26 # These functions are called by GDB (from C code) to do various things in
27 # TK-land. All start with the prefix `gdbtk_tcl_' to make them easy to find.
33 # gdbtk_tcl_fputs (text) - Output text to the command window
37 # GDB calls this to output TEXT to the GDB command window. The text is
38 # placed at the end of the text widget. Note that output may not occur,
39 # due to buffering. Use gdbtk_tcl_flush to cause an immediate update.
42 proc gdbtk_tcl_fputs {arg} {
43 global current_output_win
45 $current_output_win insert end "$arg"
46 $current_output_win yview -pickplace end
52 # gdbtk_tcl_flush () - Flush output to the command window
56 # GDB calls this to force all buffered text to the GDB command window.
59 proc gdbtk_tcl_flush {} {
60 $current_output_win yview -pickplace end
67 # gdbtk_tcl_query (message) - Create a yes/no query dialog box
71 # GDB calls this to create a yes/no dialog box containing MESSAGE. GDB
72 # is hung while the dialog box is active (ie: no commands will work),
73 # however windows can still be refreshed in case of damage or exposure.
76 proc gdbtk_tcl_query {message} {
77 tk_dialog .query "gdb : query" "$message" {} 1 "No" "Yes"
83 # gdbtk_start_variable_annotation (args ...) -
87 # Not yet implemented.
90 proc gdbtk_tcl_start_variable_annotation {valaddr ref_type stor_cl cum_expr field type_cast} {
91 echo "gdbtk_tcl_start_variable_annotation $valaddr $ref_type $stor_cl $cum_expr $field $type_cast"
97 # gdbtk_end_variable_annotation (args ...) -
101 # Not yet implemented.
104 proc gdbtk_tcl_end_variable_annotation {} {
105 echo gdbtk_tcl_end_variable_annotation
111 # gdbtk_tcl_breakpoint (action bpnum file line) - Notify the TK
112 # interface of changes to breakpoints.
116 # GDB calls this to notify TK of changes to breakpoints. ACTION is one
118 # create - Notify of breakpoint creation
119 # delete - Notify of breakpoint deletion
120 # enable - Notify of breakpoint enabling
121 # disable - Notify of breakpoint disabling
123 # All actions take the same set of arguments: BPNUM is the breakpoint
124 # number, FILE is the source file and LINE is the line number, and PC is
125 # the pc of the affected breakpoint.
128 proc gdbtk_tcl_breakpoint {action bpnum file line pc} {
129 ${action}_breakpoint $bpnum $file $line $pc
132 proc asm_win_name {funcname} {
133 regsub -all {\.} $funcname _ temp
135 return .asm.func_${temp}
141 # create_breakpoint (bpnum file line pc) - Record breakpoint info in TK land
145 # GDB calls this indirectly (through gdbtk_tcl_breakpoint) to notify TK
146 # land of breakpoint creation. This consists of recording the file and
147 # line number in the breakpoint_file and breakpoint_line arrays. Also,
148 # if there is already a window associated with FILE, it is updated with
152 proc create_breakpoint {bpnum file line pc} {
154 global breakpoint_file
155 global breakpoint_line
156 global pos_to_breakpoint
157 global pos_to_bpcount
161 # Record breakpoint locations
163 set breakpoint_file($bpnum) $file
164 set breakpoint_line($bpnum) $line
165 set pos_to_breakpoint($file:$line) $bpnum
166 if ![info exists pos_to_bpcount($file:$line)] {
167 set pos_to_bpcount($file:$line) 0
169 incr pos_to_bpcount($file:$line)
170 set pos_to_breakpoint($pc) $bpnum
171 if ![info exists pos_to_bpcount($pc)] {
172 set pos_to_bpcount($pc) 0
174 incr pos_to_bpcount($pc)
176 # If there's a window for this file, update it
178 if [info exists wins($file)] {
179 insert_breakpoint_tag $wins($file) $line
182 # If there's an assembly window, update that too
184 set win [asm_win_name $cfunc]
185 if [winfo exists $win] {
186 insert_breakpoint_tag $win [pc_to_line $pclist($cfunc) $pc]
193 # delete_breakpoint (bpnum file line pc) - Delete breakpoint info from TK land
197 # GDB calls this indirectly (through gdbtk_tcl_breakpoint) to notify TK
198 # land of breakpoint destruction. This consists of removing the file and
199 # line number from the breakpoint_file and breakpoint_line arrays. Also,
200 # if there is already a window associated with FILE, the tags are removed
204 proc delete_breakpoint {bpnum file line pc} {
206 global breakpoint_file
207 global breakpoint_line
208 global pos_to_breakpoint
209 global pos_to_bpcount
212 # Save line number and file for later
214 set line $breakpoint_line($bpnum)
216 set file $breakpoint_file($bpnum)
218 # Reset breakpoint annotation info
220 if {$pos_to_bpcount($file:$line) > 0} {
221 decr pos_to_bpcount($file:$line)
223 if {$pos_to_bpcount($file:$line) == 0} {
224 catch "unset pos_to_breakpoint($file:$line)"
226 unset breakpoint_file($bpnum)
227 unset breakpoint_line($bpnum)
229 # If there's a window for this file, update it
231 if [info exists wins($file)] {
232 delete_breakpoint_tag $wins($file) $line
237 # If there's an assembly window, update that too
239 if {$pos_to_bpcount($pc) > 0} {
240 decr pos_to_bpcount($pc)
242 if {$pos_to_bpcount($pc) == 0} {
243 catch "unset pos_to_breakpoint($pc)"
245 set win [asm_win_name $cfunc]
246 if [winfo exists $win] {
247 delete_breakpoint_tag $win [pc_to_line $pclist($cfunc) $pc]
256 # enable_breakpoint (bpnum file line pc) - Record breakpoint info in TK land
260 # GDB calls this indirectly (through gdbtk_tcl_breakpoint) to notify TK
261 # land of a breakpoint being enabled. This consists of unstippling the
262 # specified breakpoint indicator.
265 proc enable_breakpoint {bpnum file line pc} {
269 if [info exists wins($file)] {
270 $wins($file) tag configure $line -fgstipple {}
273 # If there's an assembly window, update that too
275 set win [asm_win_name $cfunc]
276 if [winfo exists $win] {
277 $win tag configure [pc_to_line $pclist($cfunc) $pc] -fgstipple {}
284 # disable_breakpoint (bpnum file line pc) - Record breakpoint info in TK land
288 # GDB calls this indirectly (through gdbtk_tcl_breakpoint) to notify TK
289 # land of a breakpoint being disabled. This consists of stippling the
290 # specified breakpoint indicator.
293 proc disable_breakpoint {bpnum file line pc} {
297 if [info exists wins($file)] {
298 $wins($file) tag configure $line -fgstipple gray50
301 # If there's an assembly window, update that too
303 set win [asm_win_name $cfunc]
304 if [winfo exists $win] {
305 $win tag configure [pc_to_line $pclist($cfunc) $pc] -fgstipple gray50
312 # insert_breakpoint_tag (win line) - Insert a breakpoint tag in WIN.
316 # GDB calls this indirectly (through gdbtk_tcl_breakpoint) to insert a
317 # breakpoint tag into window WIN at line LINE.
320 proc insert_breakpoint_tag {win line} {
321 $win configure -state normal
323 $win insert $line.0 "B"
324 $win tag add $line $line.0
326 $win configure -state disabled
332 # delete_breakpoint_tag (win line) - Remove a breakpoint tag from WIN.
336 # GDB calls this indirectly (through gdbtk_tcl_breakpoint) to remove a
337 # breakpoint tag from window WIN at line LINE.
340 proc delete_breakpoint_tag {win line} {
341 $win configure -state normal
343 $win insert $line.0 " "
344 $win tag delete $line
345 $win configure -state disabled
351 # decr (var val) - compliment to incr
356 proc decr {var {val 1}} {
358 set num [expr $num - $val]
365 # pc_to_line (pclist pc) - convert PC to a line number.
369 # Convert PC to a line number from PCLIST. If exact line isn't found,
370 # we return the first line that starts before PC.
372 proc pc_to_line {pclist pc} {
373 set line [lsearch -exact $pclist $pc]
375 if {$line >= 1} { return $line }
378 foreach linepc [lrange $pclist 1 end] {
379 if {$pc < $linepc} { decr line ; return $line }
382 return [expr $line - 1]
388 # file popup menu - Define the file popup menu.
392 # This menu just contains a bunch of buttons that do various things to
393 # the line under the cursor.
397 # Edit - Run the editor (specified by the environment variable EDITOR) on
398 # this file, at the current line.
399 # Breakpoint - Set a breakpoint at the current line. This just shoves
400 # a `break' command at GDB with the appropriate file and line
401 # number. Eventually, GDB calls us back (at gdbtk_tcl_breakpoint)
402 # to notify us of where the breakpoint needs to show up.
405 menu .file_popup -cursor hand2
406 .file_popup add command -label "Not yet set" -state disabled
407 .file_popup add separator
408 .file_popup add command -label "Edit" -command {exec $editor +$selected_line $selected_file &}
409 .file_popup add command -label "Set breakpoint" -command {gdb_cmd "break $selected_file:$selected_line"}
414 # file popup menu - Define the file popup menu bindings.
418 # This defines the binding for the file popup menu. Currently, there is
419 # only one, which is activated when Button-1 is released. This causes
420 # the menu to be unposted, releases the grab for the menu, and then
421 # unhighlights the line under the cursor. After that, the selected menu
425 bind .file_popup <Any-ButtonRelease-1> {
428 # First, remove the menu, and release the pointer
431 grab release .file_popup
433 # Unhighlight the selected line
435 $selected_win tag delete breaktag
437 # Actually invoke the menubutton here!
445 # file_popup_menu (win x y xrel yrel) - Popup the file popup menu.
449 # This procedure is invoked as a result of a command binding in the
450 # listing window. It does several things:
451 # o - It highlights the line under the cursor.
452 # o - It pops up the file popup menu which is intended to do
453 # various things to the aforementioned line.
454 # o - Grabs the mouse for the file popup menu.
457 # Button 1 has been pressed in a listing window. Pop up a menu.
459 proc file_popup_menu {win x y xrel yrel} {
462 global file_to_debug_file
468 # Map TK window name back to file name.
470 set file $win_to_file($win)
472 set pos [$win index @$xrel,$yrel]
474 # Record selected file and line for menu button actions
476 set selected_file $file_to_debug_file($file)
477 set selected_line [lindex [split $pos .] 0]
478 set selected_win $win
480 # Highlight the selected line
482 eval $win tag config breaktag $highlight
483 $win tag add breaktag "$pos linestart" "$pos linestart + 1l"
485 # Post the menu near the pointer, (and grab it)
487 .file_popup entryconfigure 0 -label "$selected_file:$selected_line"
488 .file_popup post [expr $x-[winfo width .file_popup]/2] [expr $y-10]
495 # listing_window_button_1 (win x y xrel yrel) - Handle button 1 in listing window
499 # This procedure is invoked as a result of holding down button 1 in the
500 # listing window. The action taken depends upon where the button was
501 # pressed. If it was in the left margin (the breakpoint column), it
502 # sets or clears a breakpoint. In the main text area, it will pop up a
506 proc listing_window_button_1 {win x y xrel yrel} {
509 global file_to_debug_file
514 global pos_to_breakpoint
516 # Map TK window name back to file name.
518 set file $win_to_file($win)
520 set pos [split [$win index @$xrel,$yrel] .]
522 # Record selected file and line for menu button actions
524 set selected_file $file_to_debug_file($file)
525 set selected_line [lindex $pos 0]
526 set selected_col [lindex $pos 1]
527 set selected_win $win
529 # If we're in the margin, then toggle the breakpoint
531 if {$selected_col < 8} {
532 set pos_break $selected_file:$selected_line
533 set pos $file:$selected_line
534 set tmp pos_to_breakpoint($pos)
535 if [info exists $tmp] {
537 gdb_cmd "delete $bpnum"
539 gdb_cmd "break $pos_break"
544 # Post the menu near the pointer, (and grab it)
546 .file_popup entryconfigure 0 -label "$selected_file:$selected_line"
547 .file_popup post [expr $x-[winfo width .file_popup]/2] [expr $y-10]
554 # asm_window_button_1 (win x y xrel yrel) - Handle button 1 in asm window
558 # This procedure is invoked as a result of holding down button 1 in the
559 # assembly window. The action taken depends upon where the button was
560 # pressed. If it was in the left margin (the breakpoint column), it
561 # sets or clears a breakpoint. In the main text area, it will pop up a
565 proc asm_window_button_1 {win x y xrel yrel} {
568 global file_to_debug_file
573 global pos_to_breakpoint
577 set pos [split [$win index @$xrel,$yrel] .]
579 # Record selected file and line for menu button actions
581 set selected_line [lindex $pos 0]
582 set selected_col [lindex $pos 1]
583 set selected_win $win
587 set pc [lindex $pclist($cfunc) $selected_line]
589 # If we're in the margin, then toggle the breakpoint
591 if {$selected_col < 8} {
592 set tmp pos_to_breakpoint($pc)
593 if [info exists $tmp] {
595 gdb_cmd "delete $bpnum"
602 # Post the menu near the pointer, (and grab it)
604 # .file_popup entryconfigure 0 -label "$selected_file:$selected_line"
605 # .file_popup post [expr $x-[winfo width .file_popup]/2] [expr $y-10]
612 # do_nothing - Does absoultely nothing.
616 # This procedure does nothing. It is used as a placeholder to allow
617 # the disabling of bindings that would normally be inherited from the
618 # parent widget. I can't think of any other way to do this.
621 proc do_nothing {} {}
626 # create_file_win (filename) - Create a win for FILENAME.
630 # The new text widget.
634 # This procedure creates a text widget for FILENAME. It returns the
635 # newly created widget. First, a text widget is created, and given basic
636 # configuration info. Second, all the bindings are setup. Third, the
637 # file FILENAME is read into the text widget. Fourth, margins and line
641 proc create_file_win {filename} {
642 global breakpoint_file
643 global breakpoint_line
645 # Replace all the dirty characters in $filename with clean ones, and generate
646 # a unique name for the text widget.
648 regsub -all {\.|/} $filename {} temp
651 # Open the file, and read it into the text widget
653 if [catch "open $filename" fh] {
654 # File can't be read. Put error message into .nofile window and return.
656 catch {destroy .nofile}
657 text .nofile -height 25 -width 80 -relief raised -borderwidth 2 -yscrollcommand textscrollproc -setgrid true -cursor hand2
658 .nofile insert 0.0 $fh
659 .nofile configure -state disabled
660 bind .nofile <1> do_nothing
661 bind .nofile <B1-Motion> do_nothing
665 # Actually create and do basic configuration on the text widget.
667 text $win -height 25 -width 80 -relief raised -borderwidth 2 -yscrollcommand textscrollproc -setgrid true -cursor hand2
669 # Setup all the bindings
671 bind $win <Enter> {focus %W}
672 bind $win <1> {listing_window_button_1 %W %X %Y %x %y}
673 bind $win <B1-Motion> do_nothing
674 bind $win n {gdb_cmd next ; update_ptr}
675 bind $win s {gdb_cmd step ; update_ptr}
676 bind $win c {gdb_cmd continue ; update_ptr}
677 bind $win f {gdb_cmd finish ; update_ptr}
678 bind $win u {gdb_cmd up ; update_ptr}
679 bind $win d {gdb_cmd down ; update_ptr}
682 $win insert 0.0 [read $fh]
685 # Add margins (for annotations) and a line number to each line
687 set numlines [$win index end]
688 set numlines [lindex [split $numlines .] 0]
689 for {set i 1} {$i <= $numlines} {incr i} {
690 $win insert $i.0 [format " %4d " $i]
693 # Scan though the breakpoint data base and install any destined for this file
695 foreach bpnum [array names breakpoint_file] {
696 if {$breakpoint_file($bpnum) == $filename} {
697 insert_breakpoint_tag $win $breakpoint_line($bpnum)
701 # Disable the text widget to prevent user modifications
703 $win configure -state disabled
710 # create_asm_win (funcname pc) - Create an assembly win for FUNCNAME.
714 # The new text widget.
718 # This procedure creates a text widget for FUNCNAME. It returns the
719 # newly created widget. First, a text widget is created, and given basic
720 # configuration info. Second, all the bindings are setup. Third, the
721 # function FUNCNAME is read into the text widget.
724 proc create_asm_win {funcname pc} {
725 global breakpoint_file
726 global breakpoint_line
727 global current_output_win
730 # Replace all the dirty characters in $filename with clean ones, and generate
731 # a unique name for the text widget.
733 set win [asm_win_name $funcname]
735 # Actually create and do basic configuration on the text widget.
737 text $win -height 25 -width 80 -relief raised -borderwidth 2 \
738 -setgrid true -cursor hand2 -yscrollcommand asmscrollproc
740 # Setup all the bindings
742 bind $win <Enter> {focus %W}
743 bind $win <1> {asm_window_button_1 %W %X %Y %x %y}
744 bind $win <B1-Motion> do_nothing
745 bind $win n {gdb_cmd nexti ; update_ptr}
746 bind $win s {gdb_cmd stepi ; update_ptr}
747 bind $win c {gdb_cmd continue ; update_ptr}
748 bind $win f {gdb_cmd finish ; update_ptr}
749 bind $win u {gdb_cmd up ; update_ptr}
750 bind $win d {gdb_cmd down ; update_ptr}
752 # Disassemble the code, and read it into the new text widget
754 set current_output_win $win
755 gdb_cmd "disassemble $pc"
756 set current_output_win .command.text
758 set numlines [$win index end]
759 set numlines [lindex [split $numlines .] 0]
762 # Delete the first and last lines, cuz these contain useless info
765 $win delete {end - 1 lines} end
768 # Add margins (for annotations) and note the PC for each line
770 catch "unset pclist($funcname)"
771 lappend pclist($funcname) Unused
772 for {set i 1} {$i <= $numlines} {incr i} {
773 scan [$win get $i.0 "$i.0 lineend"] "%s " pc
774 lappend pclist($funcname) $pc
779 # Scan though the breakpoint data base and install any destined for this file
781 # foreach bpnum [array names breakpoint_file] {
782 # if {$breakpoint_file($bpnum) == $filename} {
783 # insert_breakpoint_tag $win $breakpoint_line($bpnum)
787 # Disable the text widget to prevent user modifications
789 $win configure -state disabled
796 # asmscrollproc (WINHEIGHT SCREENHEIGHT SCREENTOP SCREENBOT) - Update the
797 # asm window scrollbar.
801 # This procedure is called to update the assembler window's scrollbar.
804 proc asmscrollproc {args} {
805 global asm_screen_height asm_screen_top asm_screen_bot
807 eval ".asm.scroll set $args"
808 set asm_screen_height [lindex $args 1]
809 set asm_screen_top [lindex $args 2]
810 set asm_screen_bot [lindex $args 3]
816 # update_listing (linespec) - Update the listing window according to
821 # This procedure is called from various places to update the listing
822 # window based on LINESPEC. It is usually invoked with the result of
825 # It will move the cursor, and scroll the text widget if necessary.
826 # Also, it will switch to another text widget if necessary, and update
827 # the label widget too.
829 # LINESPEC is a list of the form:
831 # { DEBUG_FILE FUNCNAME FILENAME LINE }, where:
833 # DEBUG_FILE - is the abbreviated form of the file name. This is usually
834 # the file name string given to the cc command. This is
835 # primarily needed for breakpoint commands, and when an
836 # abbreviated for of the filename is desired.
837 # FUNCNAME - is the name of the function.
838 # FILENAME - is the fully qualified (absolute) file name. It is usually
839 # the same as $PWD/$DEBUG_FILE, where PWD is the working dir
840 # at the time the cc command was given. This is used to
841 # actually locate the file to be displayed.
842 # LINE - The line number to be displayed.
844 # Usually, this procedure will just move the cursor one line down to the
845 # next line to be executed. However, if the cursor moves out of range
846 # or into another file, it will scroll the text widget so that the line
847 # of interest is in the middle of the viewable portion of the widget.
850 proc update_listing {linespec} {
858 global file_to_debug_file
860 # Rip the linespec apart
862 set line [lindex $linespec 3]
863 set filename [lindex $linespec 2]
864 set funcname [lindex $linespec 1]
865 set debug_file [lindex $linespec 0]
867 # Sometimes there's no source file for this location
869 if {$filename == ""} {set filename Blank}
871 # If we want to switch files, we need to unpack the current text widget, and
872 # stick in the new one.
874 if {$filename != $cfile} then {
875 pack forget $wins($cfile)
878 # Create a text widget for this file if necessary
880 if ![info exists wins($cfile)] then {
881 set wins($cfile) [create_file_win $cfile]
882 if {$wins($cfile) != ".nofile"} {
883 set win_to_file($wins($cfile)) $cfile
884 set file_to_debug_file($cfile) $debug_file
885 set pointers($cfile) 1.1
889 # Pack the text widget into the listing widget, and scroll to the right place
891 pack $wins($cfile) -side left -expand yes -in .listing -fill both -after .label
892 $wins($cfile) yview [expr $line - $screen_height / 2]
895 # Update the label widget in case the filename or function name has changed
897 if {$current_label != "$filename.$funcname"} then {
898 set tail [expr [string last / $filename] + 1]
899 .label configure -text "[string range $filename $tail end] : ${funcname}()"
900 set current_label $filename.$funcname
903 # Update the pointer, scrolling the text widget if necessary to keep the
904 # pointer in an acceptable part of the screen.
906 if [info exists pointers($cfile)] then {
907 $wins($cfile) configure -state normal
908 set pointer_pos $pointers($cfile)
909 $wins($cfile) configure -state normal
910 $wins($cfile) delete $pointer_pos
911 $wins($cfile) insert $pointer_pos " "
913 set pointer_pos [$wins($cfile) index $line.1]
914 set pointers($cfile) $pointer_pos
916 $wins($cfile) delete $pointer_pos
917 $wins($cfile) insert $pointer_pos "\xbb"
919 if {$line < $screen_top + 1
920 || $line > $screen_bot} then {
921 $wins($cfile) yview [expr $line - $screen_height / 2]
924 $wins($cfile) configure -state disabled
931 # update_ptr - Update the listing window.
935 # This routine will update the listing window using the result of
939 proc update_ptr {} {update_listing [gdb_loc]}
944 # asm_command - Open up the assembly window.
948 # Create an assembly window if it doesn't exist.
951 proc asm_command {} {
954 if ![winfo exists .asm] {
956 set win [asm_win_name $cfunc]
960 wm title .asm Assembly
962 label .asm.label -text "*NIL*" -borderwidth 2 -relief raised
963 text $win -height 25 -width 80 -relief raised -borderwidth 2 \
964 -setgrid true -cursor hand2 \
965 -yscrollcommand asmscrollproc
966 scrollbar .asm.scroll -orient vertical -command {$win yview}
969 button .asm.stepi -text Stepi \
970 -command {gdb_cmd stepi ; update_ptr}
971 button .asm.nexti -text Nexti \
972 -command {gdb_cmd nexti ; update_ptr}
973 button .asm.continue -text Continue \
974 -command {gdb_cmd continue ; update_ptr}
975 button .asm.finish -text Finish \
976 -command {gdb_cmd finish ; update_ptr}
977 button .asm.up -text Up -command {gdb_cmd up ; update_ptr}
978 button .asm.down -text Down \
979 -command {gdb_cmd down ; update_ptr}
980 button .asm.bottom -text Bottom \
981 -command {gdb_cmd {frame 0} ; update_ptr}
982 button .asm.close -text Close -command {destroy .asm}
984 pack .asm.label -side top -fill x
985 pack .asm.stepi .asm.nexti .asm.continue .asm.finish .asm.up \
986 .asm.down .asm.bottom .asm.close -side left -in .asm.buts
987 pack .asm.buts -side top -fill x
988 pack $win -side left -expand yes -fill both
989 pack .asm.scroll -side left -fill y
998 # registers_command - Open up the register display window.
1002 # Create the register display window, with automatic updates.
1005 proc registers_command {} {
1008 if ![winfo exists .reg] {
1011 wm title .reg Registers
1014 text $win -height 25 -width 80 -relief raised \
1016 -setgrid true -cursor hand2
1018 pack $win -side left -expand yes -fill both
1027 # update_registers - Update the registers window.
1031 # This procedure updates the registers window.
1034 proc update_registers {} {
1035 global current_output_win
1039 $win configure -state normal
1043 set current_output_win $win
1044 gdb_cmd "info registers"
1045 set current_output_win .command.text
1048 $win configure -state disabled
1054 # update_assembly - Update the assembly window.
1058 # This procedure updates the assembly window.
1061 proc update_assembly {linespec} {
1063 global screen_height
1067 global current_label
1069 global file_to_debug_file
1070 global current_asm_label
1072 global asm_screen_height asm_screen_top asm_screen_bot
1074 # Rip the linespec apart
1076 set pc [lindex $linespec 4]
1077 set line [lindex $linespec 3]
1078 set filename [lindex $linespec 2]
1079 set funcname [lindex $linespec 1]
1080 set debug_file [lindex $linespec 0]
1082 set win [asm_win_name $cfunc]
1084 # Sometimes there's no source file for this location
1086 if {$filename == ""} {set filename Blank}
1088 # If we want to switch funcs, we need to unpack the current text widget, and
1089 # stick in the new one.
1091 if {$funcname != $cfunc } {
1095 set win [asm_win_name $cfunc]
1097 # Create a text widget for this func if necessary
1099 if {![winfo exists $win]} {
1100 create_asm_win $cfunc $pc
1101 set asm_pointers($cfunc) 1.1
1102 set current_asm_label NIL
1105 # Pack the text widget, and scroll to the right place
1107 pack $win -side left -expand yes -fill both \
1109 set line [pc_to_line $pclist($cfunc) $pc]
1110 $win yview [expr $line - $asm_screen_height / 2]
1113 # Update the label widget in case the filename or function name has changed
1115 if {$current_asm_label != "$pc $funcname"} then {
1116 .asm.label configure -text "$pc $funcname"
1117 set current_asm_label "$pc $funcname"
1120 # Update the pointer, scrolling the text widget if necessary to keep the
1121 # pointer in an acceptable part of the screen.
1123 if [info exists asm_pointers($cfunc)] then {
1124 $win configure -state normal
1125 set pointer_pos $asm_pointers($cfunc)
1126 $win configure -state normal
1127 $win delete $pointer_pos
1128 $win insert $pointer_pos " "
1130 # Map the PC back to a line in the window
1132 set line [pc_to_line $pclist($cfunc) $pc]
1135 echo "Can't find PC $pc"
1139 set pointer_pos [$win index $line.1]
1140 set asm_pointers($cfunc) $pointer_pos
1142 $win delete $pointer_pos
1143 $win insert $pointer_pos "\xbb"
1145 if {$line < $asm_screen_top + 1
1146 || $line > $asm_screen_bot} then {
1147 $win yview [expr $line - $asm_screen_height / 2]
1150 # echo "Picking line $line"
1151 # $win yview -pickplace $line
1153 $win configure -state disabled
1157 proc update_ptr {} {
1158 update_listing [gdb_loc]
1159 if [winfo exists .asm] {
1160 update_assembly [gdb_loc]
1162 if [winfo exists .reg] {
1170 # listing window - Define the listing window.
1176 # Setup listing window
1182 label .label -text "*No file*" -borderwidth 2 -relief raised
1183 text $wins($cfile) -height 25 -width 80 -relief raised -borderwidth 2 -yscrollcommand textscrollproc -setgrid true -cursor hand2
1184 scrollbar .scroll -orient vertical -command {$wins($cfile) yview}
1186 if {[tk colormodel .text] == "color"} {
1187 set highlight "-background red2 -borderwidth 2 -relief sunk"
1189 set fg [lindex [.text config -foreground] 4]
1190 set bg [lindex [.text config -background] 4]
1191 set highlight "-foreground $bg -background $fg -borderwidth 0"
1194 proc textscrollproc {args} {global screen_height screen_top screen_bot
1195 eval ".scroll set $args"
1196 set screen_height [lindex $args 1]
1197 set screen_top [lindex $args 2]
1198 set screen_bot [lindex $args 3]}
1200 $wins($cfile) insert 0.0 " This page intentionally left blank."
1201 $wins($cfile) configure -state disabled
1203 pack .label -side bottom -fill x -in .listing
1204 pack $wins($cfile) -side left -expand yes -in .listing -fill both
1205 pack .scroll -side left -fill y -in .listing
1207 button .start -text Start -command \
1208 {gdb_cmd {break main}
1209 gdb_cmd {enable delete $bpnum}
1212 button .step -text Step -command {gdb_cmd step ; update_ptr}
1213 button .next -text Next -command {gdb_cmd next ; update_ptr}
1214 button .continue -text Continue -command {gdb_cmd continue ; update_ptr}
1215 button .finish -text Finish -command {gdb_cmd finish ; update_ptr}
1216 #button .test -text Test -command {echo [info var]}
1217 button .exit -text Exit -command {gdb_cmd quit}
1218 button .up -text Up -command {gdb_cmd up ; update_ptr}
1219 button .down -text Down -command {gdb_cmd down ; update_ptr}
1220 button .bottom -text Bottom -command {gdb_cmd {frame 0} ; update_ptr}
1221 button .asm_but -text Asm -command {asm_command ; update_ptr}
1222 button .registers -text Regs -command {registers_command ; update_ptr}
1224 proc files_command {} {
1225 toplevel .files_window
1227 wm minsize .files_window 1 1
1228 # wm overrideredirect .files_window true
1229 listbox .files_window.list -geometry 30x20 -setgrid true
1230 button .files_window.close -text Close -command {destroy .files_window}
1231 tk_listboxSingleSelect .files_window.list
1232 eval .files_window.list insert 0 [lsort [gdb_listfiles]]
1233 pack .files_window.list -side top -fill both -expand yes
1234 pack .files_window.close -side bottom -fill x -expand no -anchor s
1235 bind .files_window.list <Any-ButtonRelease-1> {
1236 set file [%W get [%W curselection]]
1237 gdb_cmd "list $file:1,0"
1238 update_listing [gdb_loc $file:1]
1239 destroy .files_window}
1242 button .files -text Files -command files_command
1244 pack .listing -side bottom -fill both -expand yes
1245 #pack .test -side bottom -fill x
1246 pack .start .step .next .continue .finish .up .down .bottom .asm_but \
1247 .registers .files .exit -side left
1249 wm title .command Command
1251 # Setup command window
1253 label .command.label -text "* Command Buffer *" -borderwidth 2 -relief raised
1254 text .command.text -height 25 -width 80 -relief raised -borderwidth 2 -setgrid true -cursor hand2
1256 pack .command.label -side top -fill x
1257 pack .command.text -side top -expand yes -fill both
1261 gdb_cmd {set language c}
1262 gdb_cmd {set height 0}
1263 gdb_cmd {set width 0}
1265 bind .command.text <Any-Key> {
1269 %W yview -pickplace end
1270 append command_line %A
1272 bind .command.text <Key-Return> {
1276 %W yview -pickplace end
1277 gdb_cmd $command_line
1280 %W insert end "(gdb) "
1281 %W yview -pickplace end
1283 bind .command.text <Enter> {focus %W}
1284 bind .command.text <Delete> {delete_char %W}
1285 bind .command.text <BackSpace> {delete_char %W}
1286 bind .command.text <Control-u> {delete_line %W}
1287 proc delete_char {win} {
1290 tk_textBackspace $win
1291 $win yview -pickplace insert
1292 set tmp [expr [string length $command_line] - 2]
1293 set command_line [string range $command_line 0 $tmp]
1296 proc delete_line {win} {
1299 $win delete {end linestart + 6 chars} end
1300 $win yview -pickplace insert
1304 wm minsize .command 1 1