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