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