OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [gdb/] [gdbtcl/] [srcwin.itb] - Blame information for rev 578

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# Source window for Insight.
2
# Copyright 1997, 1998, 1999, 2001 Red Hat
3
#
4
# This program is free software; you can redistribute it and/or modify it
5
# under the terms of the GNU General Public License (GPL) as published by
6
# the Free Software Foundation; either version 2 of the License, or (at
7
# your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
 
14
 
15
# ------------------------------------------------------------------
16
#  CONSTRUCTOR - create new source window
17
# ------------------------------------------------------------------
18
body SrcWin::constructor {args} {
19
  debug "$args"
20
  eval itk_initialize $args
21
  set top [winfo toplevel $itk_interior]
22
 
23
  _update_title ""
24
 
25
  # On Windows, create a sizebox.
26
  if {$::tcl_platform(platform) == "windows"} {
27
    ide_sizebox $itk_interior.sizebox
28
  }
29
 
30
  set Tracing [pref get gdb/mode]
31
  set current(filename) ""
32
 
33
  if {[catch {_build_win} mssg]} {
34
    dbug E "_build_win returned: $::errorInfo"
35
  }
36
 
37
  # add special delete handler
38
  wm protocol $top WM_DELETE_WINDOW "[code $this _exit]"
39
 
40
  # add hooks
41
  add_hook gdb_no_inferior_hook "$this no_inferior"
42
  add_hook download_progress_hook "$this download_progress"
43
  add_hook state_hook [code $this _set_state]
44
  add_hook gdb_clear_file_hook [code $this clear_file]
45
  after idle "
46
      update idletasks
47
      $this sizeWinByChild toolbar"
48
 
49
  lappend window_list $this
50
}
51
 
52
# ------------------------------------------------------------------
53
#  DESTRUCTOR - destroy window containing widget
54
# ------------------------------------------------------------------
55
body SrcWin::destructor {} {
56
  debug
57
  remove_hook gdb_no_inferior_hook "$this no_inferior"
58
  remove_hook download_progress_hook "$this download_progress"
59
  remove_hook state_hook [code $this _set_state]
60
  remove_hook gdb_clear_file_hook [code $this clear_file]
61
  set window_list [lremove $window_list $this]
62
  if {$pc_window == $this} then {
63
    set pc_window ""
64
  }
65
}
66
 
67
# ------------------------------------------------------------------
68
#  PRIVATE METHOD:  _build_win - build the main source window
69
# ------------------------------------------------------------------
70
body SrcWin::_build_win {} {
71
  global gdb_downloading gdb_running gdb_loaded
72
 
73
  # build source toolbar
74
  set _toolbar [conAdd toolbar -resizable 0]
75
  SrcBar $_toolbar $this \
76
    -updatecommand [list $this toggle_updates] \
77
    -updatevalue $do_updates
78
  pack $_toolbar -expand 1 -fill both
79
 
80
  # if user likes control on bottom...
81
  if {! [pref get gdb/src/top_control]} {
82
 
83
    # add a SrcTextWin container
84
    set srcwin [conAdd src]
85
    set twin [SrcTextWin $srcwin -Tracing $Tracing -parent $this]
86
    pack $srcwin -expand 1 -fill both
87
 
88
    # add status line
89
    set _status [conAdd status -resizable 0]
90
    label $_status -relief sunken -bd 3 -font global/status -height 1
91
    pack $_status -expand 1 -fill both
92
  }
93
 
94
  # add a status bar container
95
  set _statbar [conAdd stat -resizable 0]
96
  frame $_statbar
97
  pack $_statbar -expand 1 -fill both
98
 
99
  combobox::combobox $_statbar.name -maxheight 15 -font src-font\
100
    -command [code $this _name]
101
 
102
  set need_files 1
103
 
104
  combobox::combobox $_statbar.func -maxheight 15 -font src-font\
105
    -command [code $this goto_func]
106
  combobox::combobox $_statbar.mode -width 9 -editable false \
107
    -font src-font -command [code $this mode]
108
 
109
  $_statbar.mode list insert end SOURCE
110
  $_statbar.mode list insert end ASSEMBLY
111
  $_statbar.mode list insert end MIXED
112
  $_statbar.mode list insert end SRC+ASM
113
 
114
 
115
  # Search/download progress frame
116
  frame $_statbar.frame
117
  entry $_statbar.frame.search -bd 3 -font src-font -width 10
118
  bind_plain_key $_statbar.frame.search \
119
    Return [code $this _search forwards]
120
  bind_plain_key $_statbar.frame.search \
121
    Shift-Return [code $this _search backwards]
122
  canvas $_statbar.frame.progress -relief sunken -borderwidth 2 \
123
    -highlightthickness 0 -takefocus 0 -width 100 -height 0 -confine 1
124
  $_statbar.frame.progress create rectangle 0 0 0 \
125
    [winfo height $_statbar.frame.progress] -outline blue -fill blue -tags rect
126
 
127
  pack $_statbar.frame -side right -pady 4 -padx 10 -fill y -expand 1 -anchor e
128
  pack $_statbar.mode -side right -padx 10 -pady 4
129
  pack $_statbar.name $_statbar.func -side left -pady 4 -padx 10
130
 
131
  pack $_statbar.frame.search -fill x -expand yes
132
 
133
  # if user likes control on top...
134
  if {[pref get gdb/src/top_control]} {
135
 
136
    # add a SrcTextWin container
137
    set srcwin [conAdd src]
138
    set twin [SrcTextWin $srcwin -Tracing $Tracing -parent $this]
139
    pack $srcwin -expand 1 -fill both
140
 
141
    # add status line
142
    set _status [conAdd status -resizable 0]
143
    label $_status -relief sunken -bd 3 -font global/status -height 1
144
    pack $_status -expand 1 -fill both
145
  }
146
 
147
  set_execution_status
148
 
149
  # balloon help
150
  foreach i {entry button} {
151
    balloon register $_statbar.name.$i "Current file name"
152
    balloon register $_statbar.func.$i "Current function name"
153
    balloon register $_statbar.mode.$i "Source mode"
154
  }
155
  balloon register $_statbar.frame.search "Search for text"
156
  balloon variable $_status ${twin}_balloon
157
 
158
  $_statbar.mode entryset [$twin mode_get]
159
 
160
  # time to load the widget with a file.
161
  # If this is a new widget and the program is
162
  # not yet being debugged, load the file with "main" in it.
163
  if {$gdb_running} {
164
    if {[catch {gdb_loc} loc]} {
165
      # Nothing we can do but leave the window empty.
166
    } else {
167
      _update $loc
168
    }
169
  } else {
170
    if {[set linespec [gdbtk_locate_main]] != ""} {
171
      location BROWSE_TAG $linespec
172
    }
173
  }
174
}
175
 
176
 
177
# ------------------------------------------------------------------
178
#  PUBLIC METHOD:  _set_state - do things when program state changes
179
# ------------------------------------------------------------------
180
body SrcWin::_set_state {varname} {
181
  global gdb_running gdb_downloading gdb_loaded gdb_program_has_run
182
  debug "$varname l=$gdb_loaded d=$gdb_downloading r=$gdb_running"
183
 
184
  if {$varname == "gdb_loaded" && $gdb_loaded == 1} {
185
    set gdb_program_has_run 0
186
    #set current(filename) ""
187
    return
188
  }
189
 
190
  if {$gdb_running} {
191
    set state normal
192
    set gdb_program_has_run 1
193
  } else {
194
    set state disabled
195
  }
196
  if {!$Tracing} {
197
    $twin SetRunningState $state
198
  }
199
}
200
 
201
# ------------------------------------------------------------------
202
#  PUBLIC METHOD:  download_progress - update the progress meter when downloading
203
# ------------------------------------------------------------------
204
body SrcWin::download_progress { section num tot {msg ""} } {
205
  global download_start_time download_cancel_ok gdb_loaded
206
 
207
  #debug "$section $num $tot $msg"
208
  if {$last_section_start == 0} {
209
    pack forget $_statbar.frame.search
210
    pack $_statbar.frame.progress -fill both -expand yes
211
    ::update idletasks
212
  }
213
 
214
  if {$section == "DONE"} {
215
    set last_done $tot
216
    if {$gdb_loaded} {
217
      # loaded something
218
      set secs [expr {[clock seconds] - $download_start_time}]
219
      if {$secs} {
220
        set bps [expr {8 * $tot / $secs}]
221
        set_status "DOWNLOAD FINISHED: $tot bytes in $secs seconds ($bps bits per second)"
222
      } else {
223
        set_status "DOWNLOAD FINISHED"
224
      }
225
    }
226
  } elseif {$section != "CANCEL"} {
227
    if {$section != $last_section} {
228
      set last_section $section
229
      set last_section_start $last_done
230
    }
231
    set last_done [expr {$last_section_start + $num}]
232
    set_status "Downloading section $section - $num bytes"
233
  }
234
 
235
  set canvas $_statbar.frame.progress
236
  set height [winfo height $canvas]
237
  if {$last_done} {
238
    set width [winfo width $canvas]
239
    set rw [expr {double ($last_done) * $width / $tot}]
240
    $canvas coords rect 0 0 $rw $height
241
    ::update
242
  }
243
 
244
  if {$last_done == $tot || $section == "CANCEL"} {
245
    $_toolbar configure -runstop normal
246
    if {!$gdb_loaded} {
247
      ::update
248
      # errored or canceled
249
      if {$msg != ""} {
250
        set_status "DOWNLOAD FAILED: $msg"
251
      } else {
252
        set_status "DOWNLOAD CANCELLED"
253
      }
254
      $canvas coords rect 0 0 0 $height
255
      ::update idletasks
256
    }
257
 
258
    set last_section ""
259
    set last_done 0
260
    set last_section_start 0
261
 
262
    pack forget $_statbar.frame.progress
263
    pack $_statbar.frame.search -fill x -expand yes
264
    ::update idletasks
265
  }
266
}
267
 
268
# ------------------------------------------------------------------
269
#  PUBLIC METHOD:  reconfig - used when preferences change
270
# ------------------------------------------------------------------
271
body SrcWin::reconfig {} {
272
  debug
273
  $_toolbar reconfig
274
  $twin reconfig
275
}
276
 
277
 
278
# ------------------------------------------------------------------
279
#  PRIVATE METHOD:  _name - filename combobox callback
280
#  This is only called when the user edits the name combobox.
281
#  It is the only way that files can be inserted into the file list
282
#  once the debugger is started.
283
# ------------------------------------------------------------------
284
body SrcWin::_name {w {val ""}} {
285
  global _files
286
  debug "$w $val"
287
  if {$val != ""} {
288
    if {![info exists _files(short,$val)]} {
289
      if {![info exists _files(full,$val)]} {
290
        if [catch {gdb_find_file $val} full] {
291
          set_status "Cannot find source file \"$val\": $full"
292
          $_statbar.name entryset [lindex [file split $current(filename)] end]
293
          return
294
        }
295
        if {$full == ""} {
296
          set_status "Cannot find source file \"$val\""
297
          $_statbar.name entryset [lindex [file split $current(filename)] end]
298
          return
299
        }
300
        set _files(short,$full) $val
301
        set _files(full,$val) $full
302
      }
303
      set full $_files(full,$val)
304
    } else {
305
      set full $val
306
      set val $_files(short,$full)
307
    }
308
    $_statbar.name entryset $val
309
    location BROWSE_TAG [list $val "" $full 0 0 0 {}]
310
  }
311
}
312
 
313
# ------------------------------------------------------------------
314
#  PRIVATE PUBLIC METHOD:  toggle_updates - update toggle callback
315
# ------------------------------------------------------------------
316
body SrcWin::toggle_updates {value} {
317
  # save state in do_updates so it will be preserved
318
  # in window reconfigs
319
  set do_updates $value
320
}
321
 
322
# ------------------------------------------------------------------
323
#  PRIVATE PUBLIC METHOD:  goto_func - function combobox callback
324
# ------------------------------------------------------------------
325
body SrcWin::goto_func {w {val ""}} {
326
  if {$val != ""} {
327
    set mang 0
328
    if {[info exists _mangled_func($val)]} {
329
      set mang $_mangled_func($val)
330
    }
331
    if {$mang} {
332
      set loc $val
333
    } else {
334
      set fn [lindex [::file split $current(filename)] end]
335
      if {$fn == ""} {
336
        set loc $val
337
      } else {
338
        set loc $fn:$val
339
      }
340
    }
341
    debug "GOTO $loc"
342
    if {![catch {gdb_loc $loc} result]} {
343
      location BROWSE_TAG $result
344
    } else {
345
      dbug W "gdb_loc returned \"$result\""
346
    }
347
  }
348
}
349
 
350
# ------------------------------------------------------------------
351
#  PUBLIC METHOD:  fillNameCB - fill the name combobox
352
#
353
#         This method needs to be public, since other parts of
354
#         the gui can cause new symbols to be read.
355
# ------------------------------------------------------------------
356
body SrcWin::fillNameCB {} {
357
  global _files
358
  set allfiles [gdb_listfiles]
359
  debug "gdb_listfiles returned $allfiles"
360
  foreach f $allfiles {
361
    # FIXME: If you reactivate this code add a catch as gdb_find_file can err
362
    # (P.S.: I don't know why this is commented out)
363
    #set fullname [gdb_find_file $f]
364
    #set _files(full,$f) $fullname
365
    #set _files(short,$fullname) $f
366
    $_statbar.name list insert end $f
367
  }
368
  set need_files 0
369
}
370
 
371
 
372
# ------------------------------------------------------------------
373
#  PUBLIC METHOD:  fillFuncCB - fill the function combobox
374
#
375
#         This method needs to be public, since other parts of
376
#         the gui can cause new symbols to be read.
377
# ------------------------------------------------------------------
378
body SrcWin::fillFuncCB {name} {
379
  $_statbar.func list delete 0 end
380
  if {$name != ""} {
381
    set maxlen 10
382
    if {[catch {gdb_listfuncs $name} listfuncs]} {
383
      tk_messageBox -icon error -default ok \
384
        -title "GDB" -type ok -modal system \
385
        -message "This file can not be found or does not contain\ndebugging information."
386
      _set_name ""
387
      return
388
    }
389
    foreach f $listfuncs {
390
      lassign $f func mang
391
      set _mangled_func($func) $mang
392
      $_statbar.func list insert end $func
393
      if {[string length $func] > $maxlen} {
394
        set maxlen [string length $func]
395
      }
396
    }
397
    $_statbar.func configure -width [expr $maxlen + 1]
398
  }
399
}
400
 
401
# ------------------------------------------------------------------
402
#  PUBLIC METHOD:  location - update the location displayed
403
#
404
#  a linespec looks like this:
405
#  0: basename of the file
406
#  1: function name
407
#  2: full filename
408
#  3: source line number
409
#  4: address
410
#  5: current PC - which will often be the same as address, but not when
411
#  6: shared library name if the pc is in a shared lib
412
#  we are browsing, or walking the stack.
413
#
414
# linespec will be "{} {} {} 0 0x0 0x0" when GDB has not started debugging.
415
# ------------------------------------------------------------------
416
body SrcWin::location {tag linespec} {
417
  global gdb_running gdb_exe_name _files tcl_platform
418
 
419
  # We need to keep track of changes to the line, filename, function name
420
  # and address so we can keep the widgets up-to-date.  Otherwise we
421
  # basically pass things through to the SrcTextWin location public method.
422
 
423
  debug "running=$gdb_running tag=$tag linespec=$linespec"
424
  lassign $linespec foo funcname name line addr pc_addr lib
425
 
426
  # need to call this to update running state
427
  set_execution_status $line $addr
428
 
429
  # "update" doesn't set the tag so we do it here
430
  if {$tag == ""} {
431
    if {$addr == $pc_addr} {
432
      set tag PC_TAG
433
    } else {
434
      set tag STACK_TAG
435
    }
436
  }
437
 
438
  if {!$gdb_running} {
439
    # When we are not yet debugging, we need to force something
440
    # to be displayed, so we choose to find function "main" and
441
    # display the file with it.
442
    set tag BROWSE_TAG
443
    debug "not running: name=$name funcname=$funcname line=$line"
444
    if {$name == ""} {
445
      if {[set linespec [gdbtk_locate_main]] == ""} {
446
        # no "main" function found
447
        return
448
      }
449
      lassign $linespec foo funcname name line addr pc_addr lib
450
      debug "new linespec=$linespec"
451
    }
452
  }
453
 
454
  # update file and function combobox
455
  if {$name != $current(filename)} {
456
    _set_name $name
457
    fillFuncCB $name
458
  }
459
 
460
  # set address and line widgets
461
  $_toolbar configure -address $addr -line $line
462
 
463
  # set function combobox
464
  $_statbar.func entryset $funcname
465
 
466
  # call SrcTextWin::location
467
  $twin location $tag $name $funcname $line $addr $pc_addr $lib
468
 
469
  set current(filename) $name
470
}
471
 
472
# ------------------------------------------------------------------
473
#  PUBLIC METHOD:  stack - handle stack commands
474
# ------------------------------------------------------------------
475
body SrcWin::stack {cmd} {
476
  if {$cmd == "bottom"} {
477
    set cmd "frame 0"
478
  }
479
  gdbtk_busy
480
  if {[catch {gdb_cmd "$cmd"} message]} {
481
    dbug E "STACK ERROR: $message"
482
  }
483
  gdbtk_update
484
  gdbtk_idle
485
}
486
 
487
# ------------------------------------------------------------------
488
#  METHOD:  _update - update widget when PC changes
489
# ------------------------------------------------------------------
490
body SrcWin::_update {loc} {
491
  debug "loc=$loc"
492
  # See if name combobox needs filled.
493
  if {$need_files} {
494
    fillNameCB
495
  }
496
  location "" $loc
497
}
498
 
499
# ------------------------------------------------------------------
500
#  PUBLIC METHOD:  idle - callback for gdbtk_idle
501
#  Called when the target is idle, so enable all buttons.
502
# ------------------------------------------------------------------
503
body SrcWin::idle {event} {
504
  $_toolbar configure -runstop normal
505
  enable_ui 1
506
}
507
 
508
# ------------------------------------------------------------------
509
#  PUBLIC METHOD:  mode - set mode to SOURCE, ASSEMBLY, MIXED, SRC+ASM
510
# ------------------------------------------------------------------
511
body SrcWin::mode {w new_mode {go 1}} {
512
  gdbtk_busy
513
  $_statbar.mode entryset $new_mode
514
  catch {$twin mode_set $new_mode $go} errorVal
515
  $_toolbar configure -displaymode $new_mode
516
  gdbtk_idle
517
}
518
 
519
# ------------------------------------------------------------------
520
#  PRIVATE METHOD:  _update_title - update title bar
521
# ------------------------------------------------------------------
522
body SrcWin::_update_title {name} {
523
  set fn [lindex [::file split $name] end]
524
  if {$fn == ""} {
525
    set prefix ""
526
  } else {
527
    set prefix "$fn - "
528
  }
529
  window_name "${prefix}Source Window" $fn
530
}
531
 
532
# ------------------------------------------------------------------
533
#  PUBLIC METHOD:  busy - disable things when gdb is busy
534
# ------------------------------------------------------------------
535
body SrcWin::busy {event} {
536
  global gdb_loaded gdb_target_name
537
#  debug "gdb_loaded=$gdb_loaded, gdb_target_name=$gdb_target_name"
538
 
539
  if {$do_updates} {
540
    enable_ui 0
541
    if {$Running} {
542
      $_toolbar configure -runstop running
543
      if {$gdb_loaded || \
544
            ([TargetSelection::native_debugging] && $gdb_target_name != "remote")} {
545
        set_status "Program is running."
546
      }
547
    } else {
548
      $_toolbar configure -runstop busy
549
    }
550
  }
551
}
552
 
553
# ------------------------------------------------------------------
554
#   PUBLIC METHOD:  update - The inferior's state has changed.
555
# ------------------------------------------------------------------
556
body SrcWin::update {event} {
557
 
558
  # FIXME: This is kinda lame. We need to run this only once
559
  # as it is now written, so only the first window in the list
560
  # will actually call choose_and_update.
561
  # This is still better than before, since it will not
562
  # matter if this window is destroyed: as long as _a_
563
  # SrcWin exists, this will get called.
564
  if {[lindex $window_list 0] == $this} {
565
    choose_and_update
566
  }
567
}
568
 
569
# ------------------------------------------------------------------
570
#  PRIVATE METHOD:  _set_name - set the name in the name combobox and in the title
571
# ------------------------------------------------------------------
572
body SrcWin::_set_name { val {found 1} } {
573
  global _files
574
  _update_title $val
575
  if {![info exists _files(short,$val)]} {
576
    if {![info exists _files(full,$val)]} {
577
      # not in our list; just display basename
578
      $_statbar.name entryset [lindex [::file split $val] end]
579
      return
580
    }
581
  } else {
582
    set val $_files(short,$val)
583
  }
584
  if {$found} {
585
    $_statbar.name entryset $val
586
  } else {
587
    $_statbar.name entryset "$val (not found)"
588
  }
589
}
590
 
591
# ------------------------------------------------------------------
592
#  PUBLIC METHOD:  set_status - write a message to the status line.
593
#  If "tmp" is set, the status change will not be saved.
594
# ------------------------------------------------------------------
595
 
596
body SrcWin::set_status { {msg ""} {tmp 0} } {
597
  set msg [lindex [split $msg \n] 0]
598
  if {$tmp} {
599
    $_status configure -text $msg
600
    return
601
  }
602
  if {$msg != ""} {
603
    set saved_msg $msg
604
  }
605
  $_status configure -text $saved_msg
606
}
607
 
608
# ------------------------------------------------------------------
609
#  PUBLIC METHOD:  set_execution_status - write the current execution state
610
#  to the status line
611
# ------------------------------------------------------------------
612
body SrcWin::set_execution_status { {line ""} {pc ""}} {
613
  global gdb_running gdb_loaded gdb_program_has_run gdb_target_changed
614
  #debug "line=$line pc=$pc [gdb_target_has_execution] running=$gdb_running loaded=$gdb_loaded"
615
  set message ""
616
 
617
  if {![gdb_target_has_execution]} {
618
    if {$gdb_running} {
619
      set gdb_running 0
620
      # tell text window program is no longer running
621
      $twin ClearTags
622
    }
623
    if {$gdb_loaded} {
624
      if {$gdb_program_has_run} {
625
        set message "Program terminated. 'Run' will restart."
626
        # Need to set gdb_target_changed because most
627
        # remote targets detach when they are finished,
628
        # and this will force it to reattach.
629
        set gdb_target_changed 1
630
        set gdb_running 0
631
      } else {
632
        set message "Program is ready to run."
633
      }
634
    } else {
635
      set message "Program not running. Click on run icon to start."
636
    }
637
  } else {
638
 
639
    # gdb_target_has_execution has returned true, so we must be running.
640
    #
641
    # This can cause problems on targets which do not set inferior_pid.
642
    # Although this is bogus, much of gdb (and gdbtk) relies on
643
    # gdb_target_has_execution (and thus inferior_pid), so we should
644
    # not try to second guess it and fix those targets which do not set
645
    # inferior_pid when opened.
646
    set gdb_running 1
647
 
648
    # only do a gdb_loc if we have to
649
    if {$line == "" && $pc == ""} {
650
      if {[catch {gdb_loc} loc] == 0} {
651
        set line [lindex $loc 3]
652
        set pc [lindex $loc 4]
653
      }
654
    }
655
 
656
    if {$line == "" || $line == 0} {
657
      if {$pc == "" || $pc == 0} {
658
        if {$Tracing} {
659
          set message "Ready."
660
        } else {
661
          set message "Program stopped."
662
        }
663
      } else {
664
        set message [gdb_cmd "printf \"Program stopped at %lx\",$pc"]
665
      }
666
    } else {
667
      if {$Tracing} {
668
        set msg "Inspecting trace"
669
      } else {
670
        set msg "Program stopped"
671
      }
672
      switch [$twin mode_get] {
673
        ASSEMBLY {set message [gdb_cmd "printf \"$msg at 0x%lx\",$pc"] }
674
        MIXED {set message [gdb_cmd "printf \"$msg at line $line, 0x%lx\",$pc"] }
675
        SRC+ASM {set message [gdb_cmd "printf \"$msg at line $line, 0x%lx\",$pc"] }
676
        default {set message "$msg at line $line" }
677
      }
678
    }
679
  }
680
  set_status $message
681
}
682
 
683
# ------------------------------------------------------------------
684
#  PUBLIC METHOD:  edit - invoke external editor
685
# ------------------------------------------------------------------
686
body SrcWin::edit {} {
687
  global enable_external_editor external_editor_command
688
  # If external editor is enabled, pass the file to the specified command
689
 
690
  if {$current(filename) == ""} {
691
    tk_dialog .warn {Edit} {No file is loaded in the source window.} error 0 Ok
692
    return
693
  }
694
 
695
  if {[catch {$twin report_source_location} loc_info]} {
696
    tk_dialog .warn "Edit" "No source file selected" error 0 Ok
697
    return
698
  }
699
 
700
 
701
  if {[info exists enable_external_editor] && $enable_external_editor} {
702
    if {[catch {uplevel \#0 "$external_editor_command edit $loc_info"} ]} {
703
      tk_dialog .warn-sn "Edit" $err error 0 Ok
704
    }
705
    return
706
  }
707
}
708
 
709
# ------------------------------------------------------------------
710
#  PUBLIC METHOD:  print - print the contents of the text widget
711
# ------------------------------------------------------------------
712
body SrcWin::print {} {
713
  # Call the SrcTextWin's print public method
714
  $twin print $top
715
}
716
 
717
# ------------------------------------------------------------------
718
# PUBLIC METHOD:   enable_ui
719
#              Enable all UI elements for user interaction.
720
# ------------------------------------------------------------------
721
body SrcWin::enable_ui { on } {
722
  #debug "$on"
723
  if {$on} {
724
    set Running 0
725
    set state normal
726
    set glyph ""
727
  } else {
728
    if {!$NoRun} {set Running 1}
729
    set state disabled
730
    set glyph watch
731
  }
732
  # combo boxes
733
  $_statbar.mode configure -state $state
734
  $_statbar.name configure -state $state
735
  $_statbar.func configure -state $state
736
 
737
  $twin enable $on
738
  $top configure -cursor $glyph
739
}
740
 
741
# ------------------------------------------------------------------
742
# PUBLIC METHOD:   no_inferior
743
#              Put the UI elements of this object into a state
744
#              appropriate for an inferior which is not executing.
745
#              For this object, this means:
746
# Disable:
747
# - key binding for all inferior control (not needed -- gdb does this
748
#    for us)
749
#
750
# Enable:
751
# - file/func/mode selectors
752
# - right-click popups, since gdb DOES allow looking at exe fil
753
# - selections
754
#
755
# Change mouse pointer to normal
756
# ------------------------------------------------------------------
757
body SrcWin::no_inferior {} {
758
  #debug
759
  set_execution_status
760
  enable_ui 1
761
}
762
 
763
# ------------------------------------------------------------------
764
#   PUBLIC METHOD: reset - reset the source window
765
# ------------------------------------------------------------------
766
body SrcWin::reset {} {
767
  set current(filename) ""
768
  set need_files 1
769
  set do_updates 1
770
  set last_section ""
771
  set last_section_start 0
772
  set last_done 0
773
  set saved_msg ""
774
 
775
  # do we need to flush the cache or clear the source windows?
776
 
777
  # Empty combo boxes
778
  $_statbar.name list delete 0 end
779
  $_statbar.name configure -value {}
780
  $_statbar.func list delete 0 end
781
  $_statbar.func configure -value {}
782
}
783
 
784
# ------------------------------------------------------------------
785
#  PRIVATE METHOD:  _search - search for text or jump to a specific line
786
#           in source window, going in the specified DIRECTION.
787
# ------------------------------------------------------------------
788
body SrcWin::_search {direction} {
789
  set exp [$_statbar.frame.search get]
790
  #debug "searching $direction for \"$exp\""
791
  set_status
792
  set_status [$twin search $exp $direction] 1
793
}
794
 
795
# ------------------------------------------------------------------
796
#  PROCEDURE: point_to_main
797
#         Proc that may be called to point some source window to
798
#         main (or an entry point?). (see gdbtk_tcl_exec_file_changed)
799
# ------------------------------------------------------------------
800
body SrcWin::point_to_main {} {
801
  # We need to force this to some default location. Assume main and
802
  # if that fails, let the source window guess (via gdb_loc using stop_pc).
803
  set src [lindex [ManagedWin::find SrcWin] 0]
804
  if {[set linespec [gdbtk_locate_main]] == ""} {
805
    gdbtk_update
806
    debug "could not find main"
807
  } else {
808
    $src location BROWSE_TAG [list $linespec]
809
  }
810
}
811
 
812
body SrcWin::_exit {} {
813
  debug
814
  if {[llength [ManagedWin::find SrcWin]] == 1} {
815
    if {![gdbtk_quit_check]} {
816
      return
817
    }
818
  }
819
  after idle [delete object $this]
820
}
821
 
822
# public method for testing use only!
823
body SrcWin::test_get {var {private_func 0}} {
824
  debug $var
825
  if {$private_func} {
826
    return [code $this $var]
827
  }
828
  return [set $var]
829
}
830
 
831
# ------------------------------------------------------------------
832
#  PUBLIC METHOD: toolbar - configure the toolbar's "state"
833
# ------------------------------------------------------------------
834
#
835
#  This method is used to configure the toolbar's running state.
836
#  Valid states include anything that the "runtest" variable of
837
#  the GDBSrcBar may accept. Specifically,
838
#
839
#  busy        - Run button becomes disabled
840
#  running     - Stop button appears, allowing user to stop executing target
841
#  downloading - Stop button appears, allowing user to interrupt downloading
842
#  normal      - Run button appears, allowing user to run/re-run exe
843
body SrcWin::toolbar {state} {
844
  $_toolbar configure -runstop $state
845
}
846
 
847
# ------------------------------------------------------------------
848
#  METHOD:  inferior - change execution state of inferior
849
# ------------------------------------------------------------------
850
#
851
# ACTION may be:
852
#   step       -  step the inferior one source line (stepping into functions)
853
#   next       -  step the inferior one source line (stepping over functions)
854
#   finish     -  finish the current frame of execution
855
#   continue   -  continue executing the inferior
856
#   stepi      -  step one machine instruction (stepping into calls)
857
#   nexti      -  step one machine instruction (stepping over calls)
858
#   run        -  run/re-run the inferior
859
#   stop       -  stop or detach from target
860
#
861
# FIXME: This should really be in an object which describes gdb's state.
862
# Unfortunately, this doesn't exist, so it's here for now.
863
body SrcWin::inferior {action} {
864
 
865
  switch $action {
866
    step { gdbtk_step }
867
 
868
    next { gdbtk_next }
869
 
870
    finish { gdbtk_finish }
871
 
872
    continue { gdbtk_continue }
873
 
874
    stepi { gdbtk_stepi }
875
 
876
    nexti { gdbtk_nexti }
877
 
878
    run { gdbtk_run }
879
 
880
    stop { gdbtk_stop }
881
  }
882
}
883
 
884
# ------------------------------------------------------------------
885
#  METHOD:  clear_file
886
#  Tasks for SrcWin to clear file:
887
#
888
# - clear window
889
# - reset to src mode
890
# - clear func/file comboboxes
891
# - clear status (done by no_inferior)
892
# - allow SrcTextWin to clear_file
893
# ------------------------------------------------------------------
894
body SrcWin::clear_file {} {
895
 
896
  # Reset to Source mode
897
  if {[$twin mode_get] != "SOURCE"} {
898
    mode {} SOURCE 0
899
  }
900
 
901
  no_inferior
902
  reset
903
 
904
  # run srctextwin clear_file
905
  $twin clear_file
906
}
907
 
908
# ------------------------------------------------------------------
909
#  METHOD:  get_file
910
#  Return name of displayed file, or empty string if no file.
911
# ------------------------------------------------------------------
912
body SrcWin::get_file {} {
913
  if {$twin == ""} {
914
    return ""
915
  } else {
916
    return [$twin get_file]
917
  }
918
}
919
 
920
# ------------------------------------------------------------------
921
#  METHOD:  is_fixed
922
#  Return boolean indicating whether this window is fixed.
923
# ------------------------------------------------------------------
924
body SrcWin::is_fixed {} {
925
  return 0
926
}
927
 
928
# ------------------------------------------------------------------
929
#  METHOD:  get_top
930
#  Return toplevel
931
# ------------------------------------------------------------------
932
body SrcWin::get_top {} {
933
  return $top
934
}
935
 
936
# ------------------------------------------------------------------
937
#  METHOD:  _set_tag_to_stack
938
#  Set tag to `stack' and update the underlying window.
939
# ------------------------------------------------------------------
940
body SrcWin::_set_tag_to_stack {} {
941
  set tag STACK_TAG
942
  if {$twin != ""} then {
943
    $twin set_tag_to_stack
944
  }
945
}
946
 
947
# ------------------------------------------------------------------
948
#  METHOD:  _choose_window
949
#  Choose the right source window.
950
# ------------------------------------------------------------------
951
body SrcWin::_choose_window {file} {
952
  # Find the next available source window.  The rules are:
953
  # 1. LRU overall
954
  # 2. Skip iconified windows
955
  # 3. If a window already shows the file, use it.  Prefer the
956
  #    window currently showing the PC
957
  # 4. If the window is fixed, skip it
958
  if {$pc_window != ""} then {
959
    if {[$pc_window get_file] == $file} then {
960
      return $pc_window
961
    }
962
  }
963
 
964
  set choice ""
965
  foreach win $window_list {
966
    if {[wm state [$win get_top]] != "normal"} then {
967
      continue
968
    }
969
 
970
    if {[$win get_file] == ""
971
        || [$win get_file] == $file
972
        || ! [$win is_fixed]} then {
973
      set choice $win
974
      break
975
    }
976
  }
977
 
978
  # If we didn't find an available window, then pick the current PC
979
  # window.
980
  if {$choice == ""} then {
981
    set choice $pc_window
982
  }
983
 
984
  set window_list [lremove $window_list $choice]
985
  lappend window_list $choice
986
 
987
  return $choice
988
}
989
 
990
# ------------------------------------------------------------------
991
#  METHOD:  choose_and_update
992
#  Choose the right source window and then cause it to be updated
993
# ------------------------------------------------------------------
994
body SrcWin::choose_and_update {} {
995
  if {$pc_window == ""} then {
996
    set pc_window [lindex $window_list 0]
997
  }
998
 
999
  if {$pc_window == ""} then {
1000
    # Nothing.
1001
  } elseif {[catch {gdb_loc} loc]} {
1002
    $pc_window set_execution_status
1003
  } else {
1004
    set prev $pc_window
1005
    set file [lindex $loc 2]
1006
    set pc_window [_choose_window $file]
1007
    debug "chose window $pc_window"
1008
    $pc_window _update $loc
1009
    if {$pc_window != $prev} then {
1010
      $pc_window reveal
1011
      $prev _set_tag_to_stack
1012
    }
1013
  }
1014
}
1015
 
1016
# ------------------------------------------------------------------
1017
#  METHOD:  choose_and_display
1018
#  Choose the right source window for a given file
1019
# ------------------------------------------------------------------
1020
body SrcWin::choose_and_display {tag linespec} {
1021
  set file [lindex $linespec 2]
1022
  set window [_choose_window $file]
1023
  $window location $tag $linespec
1024
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.