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

Subversion Repositories openfire2

[/] [openfire2/] [web_uploads/] [targetselection.itb] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 root
# Target selection dialog for Insight.
2
# Copyright 1997, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
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
# Implements GDB TargetSelection dialog
16
# ----------------------------------------------------------------------
17
 
18
# ------------------------------------------------------------------
19
#  CONSTRUCTOR - create new target selection window
20
# ------------------------------------------------------------------
21
body TargetSelection::constructor {args} {
22
  eval itk_initialize $args
23
  set top [winfo toplevel $itk_interior]
24
  _init
25
  build_win
26
}
27
 
28
body TargetSelection::getname {target name} {
29
 
30
  # Init target database if we haven't already done so
31
  init_target_db
32
 
33
  if {[info exists gdb_target($target,$name)]} {
34
    return $gdb_target($target,$name)
35
  } else {
36
    return ""
37
  }
38
}
39
 
40
body TargetSelection::init_target_db {} {
41
  # check to see if we already initialized this database
42
  if {$db_inited} {
43
    return
44
  }
45
  set db_inited 1
46
 
47
  # Target Database
48
  # Set the following members:
49
  # TARGET,pretty-name: Name to display to user
50
  # TARGET,debaud: Default baudrate
51
  # TARGET,baud-rates: Permissible baudrates
52
  # TARGET,cmd: Abstracted command to run for this target (tcpX and com1 are
53
  #          replaced with the real port and host/port in set_target)
54
  # TARGET,runlist: List of preferences for the target: {attach download run cont}
55
  # TARGET,after_attaching: a command to run after attaching to the target
56
 
57
  # Simulator
58
  set gdb_target(sim,pretty-name) "Simulator"
59
  set gdb_target(sim,defbaud) ""
60
  set gdb_target(sim,baud-rates) {}
61
  set gdb_target(sim,cmd) "sim"
62
  set gdb_target(sim,runlist) {1 1 1 0}
63
  set gdb_target(sim,options) ""
64
  set gdb_target(sim,after_attaching) {}
65
 
66
  # Remote serial port
67
  set gdb_target(serial,pretty-name) "Remote/Serial"
68
  set gdb_target(serial,defbaud) "115200"
69
  set gdb_target(serial,baud-rates) {9600 19200 38400 57600 115200}
70
  set gdb_target(serial,cmd) "remote com1"
71
  set gdb_target(serial,runlist) {1 1 0 1}
72
  set gdb_target(serial,after_attaching) {}
73
 
74
 # Remote TCP
75
 set gdb_target(remote,pretty-name) "Remote/TCP"
76
 set gdb_target(remote,defbaud) "TCP"
77
 set gdb_target(remote,baud-rates) {}
78
 set gdb_target(remote,cmd) "remote tcpX"
79
 set gdb_target(remote,runlist) {1 1 0 1}
80
 set gdb_target(remote,after_attaching) {}
81
 
82
}
83
 
84
body TargetSelection::default_port {} {
85
  global tcl_platform
86
  switch -regexp $tcl_platform(os) {
87
    Windows { set port /dev/com1 }
88
    Linux   { set port /dev/ttyS0 }
89
    SunOS   { set port /dev/ttya }
90
    AIX     { set port /dev/foo1 }
91
    ULTRIX  { set port /dev/foo1 }
92
    IRIX    { set port /dev/foo1 }
93
    OSF1    { set port /dev/foo1 }
94
    NetBSD  { set port /dev/foo1 }
95
    HP-UX   {
96
      # Special case...
97
      switch -regexp $tcl_platform(osVersion) {
98
        A.09 { set port /dev/tty00 }
99
        B.10 -
100
        B.11 { set port /dev/tty0p0 }
101
      }
102
    }
103
    default { set port /dev/ttya }
104
  }
105
 
106
  return $port
107
}
108
 
109
 
110
body TargetSelection::_init_prefs {} {
111
 
112
  if {$prefs_inited} {
113
    return
114
  }
115
  set prefs_inited 1
116
 
117
  # these are not target-specific
118
 
119
  pref define gdb/load/main 1
120
  pref define gdb/load/exit 1
121
  pref define gdb/load/check 0
122
 
123
  # these are target-specific
124
  # set up the defaults
125
  pref define gdb/load/default-verbose 0
126
  pref define gdb/load/default-port [default_port]
127
  pref define gdb/load/default-hostname "localhost"
128
  pref define gdb/load/default-after_attaching {}
129
}
130
 
131
body TargetSelection::_init_target {} {
132
  global gdb_target_name
133
 
134
# Xilinx changes - Force this to a remote target
135
  set gdb_target_name sim
136
# end Xilinx changes
137
 
138
  #set target_list [get_target_list]
139
  set target_list { sim serial remote }
140
  set target $gdb_target_name
141
 
142
  # target = CANCEL should never come into here.  If the target was
143
  # returned as CANCEL, it should be fixed by the caller...  But it
144
  # should not be harmful if it gets in here.
145
 
146
  if {$target == "" || [string compare $target CANCEL] == 0} {
147
    set target default
148
  }
149
 
150
  set defbaud $gdb_target($target,defbaud)
151
  pref define gdb/load/$target-baud $defbaud
152
  pref define gdb/load/$target-port [pref get gdb/load/default-port]
153
  pref define gdb/load/$target-verbose [pref get gdb/load/default-verbose]
154
  pref define gdb/load/$target-portname 1234
155
  pref define gdb/load/$target-hostname [pref get gdb/load/default-hostname]
156
 
157
  set err [catch {pref get gdb/load/$target-runlist} run_list]
158
  if {$err} {
159
    set run_list $gdb_target($target,runlist)
160
    pref setd gdb/load/$target-runlist $run_list
161
  }
162
  pref set gdb/src/run_attach [lindex $run_list 0]
163
  pref set gdb/src/run_load   [lindex $run_list 1]
164
  pref set gdb/src/run_run    [lindex $run_list 2]
165
  pref set gdb/src/run_cont   [lindex $run_list 3]
166
 
167
  set err [catch {pref get gdb/load/$target-after_attaching} aa]
168
  if {$err} {
169
    set aa $gdb_target($target,after_attaching)
170
    pref setd gdb/load/$target-after_attaching $aa
171
  }
172
}
173
 
174
body TargetSelection::_init {} {
175
 
176
  if {!$trace_inited} {
177
    # Trace all gdb_loaded changes based on target
178
    trace variable gdb_loaded w [code TargetSelection::target_trace]
179
  }
180
  set trace_inited 1
181
 
182
  init_target_db        ;# initialize database
183
  _init_prefs   ;# initialize load prefs
184
  _init_target  ;# initialize target prefs
185
  set_saved
186
 
187
  # This tells us that the target system is inited.  Some of these
188
  # init functions need to be called every time the target dialog is
189
  # posted, some only once.  The latter functions can check inited to
190
  # see what they should do.
191
 
192
}
193
 
194
# ------------------------------------------------------------------
195
#  METHOD:  build_win - build the dialog
196
# ------------------------------------------------------------------
197
body TargetSelection::build_win {} {
198
  global tcl_platform PREFS_state gdb_ImageDir gdb_target_name
199
 
200
  set f [frame $itk_interior.f]
201
  set opts [frame $itk_interior.moreoptions]
202
  frame $itk_interior.moreoptionsframe
203
  set btns [frame $itk_interior.buttons]
204
 
205
  #labelled frame "Connection"
206
  iwidgets::Labeledframe $f.lab -labelpos nw -labeltext [gettext "Connection"]
207
  set fr [$f.lab childsite]
208
 
209
  # target name
210
  label $fr.tarl -text [gettext "Target:"]
211
  combobox::combobox $fr.tar -editable 0 -command [code $this change_target] \
212
    -width $Width -maxheight 10
213
 
214
  # baud rate combobox
215
  label $fr.cbl -text [gettext "Baud Rate:"]
216
  combobox::combobox $fr.cb -editable 0 -command [code $this change_baud] \
217
    -textvariable [pref varname gdb/load/$target-baud] -width $Width \
218
    -maxheight 10
219
 
220
  if {[catch {gdb_cmd "show remotebaud"} res]} {
221
    set baud [pref get gdb/load/$target-baud]
222
  } else {
223
    set baud [lindex $res end]
224
    set baud [string trimright $baud "."]
225
    # When uninitialized, GDB returns a baud rate of 2^32
226
    # Detect this and ignore it.
227
    if {$baud > 4000000000} {
228
      set baud [pref get gdb/load/$target-baud]
229
    } else {
230
      pref setd gdb/load/$target-baud $baud
231
    }
232
  }
233
 
234
  # host entry widget
235
  entry $fr.host -textvariable [pref varname gdb/load/$target-hostname] \
236
    -width $Width
237
 
238
  # port combobox
239
  if {$tcl_platform(platform) == "windows"} {
240
    set editable 0
241
  } else {
242
    set editable 1
243
  }
244
 
245
  label $fr.portl -text [gettext "Port:"]
246
  combobox::combobox $fr.port -editable $editable \
247
    -textvariable [pref varname gdb/load/$target-port] \
248
    -width $Width -maxheight 10
249
 
250
  # load baud rates into combobox
251
  fill_rates
252
 
253
  # load port combobox
254
  if {$tcl_platform(platform) == "windows"} {
255
    foreach val [port_list] {
256
      $fr.port list insert end $val
257
    }
258
  } else {
259
    # fixme:  how do I find valid values for these????
260
    switch $tcl_platform(os) {
261
      Linux { set ports [list /dev/cua0 /dev/ttyS0 /dev/ttyS1 /dev/ttyS2 /dev/ttyS3]}
262
      SunOS { set ports [list /dev/ttya /dev/ttyb] }
263
      AIX   { set ports [list /dev/foo1 /dev/foo2] }
264
      ULTRIX { set ports [list /dev/foo1 /dev/foo2] }
265
      IRIX   { set ports [list /dev/foo1 /dev/foo2] }
266
      OSF1   { set ports [list /dev/foo1 /dev/foo2] }
267
      NetBSD { set ports [list /dev/foo1 /dev/foo2] }
268
      HP-UX  {
269
        # Special case...
270
        switch -regexp $tcl_platform(osVersion) {
271
          A.09 { set ports [list /dev/tty00 /dev/tty01] }
272
          B.10 -
273
          B.11 { set ports [list /dev/tty0p0 /dev/tty1p0] }
274
        }
275
      }
276
      default { set ports [list UNKNOWN UNKNOWN] }
277
    }
278
    foreach val $ports {
279
      $fr.port list insert end $val
280
    }
281
  }
282
 
283
  # Port entry widget
284
  entry $fr.porte -textvariable [pref varname gdb/load/$target-port] -width $Width
285
 
286
  frame $f.fr
287
  checkbutton $f.fr.main -text [gettext "Set breakpoint at 'main'"] \
288
    -variable [pref varname gdb/load/main]
289
  checkbutton $f.fr.exit -text [gettext "Set breakpoint at 'exit'"] \
290
    -variable [pref varname gdb/load/exit]
291
  frame $f.fr.bp
292
  checkbutton $f.fr.bp.at_func -text [gettext "Set breakpoint at"] \
293
    -variable [pref varname gdb/load/bp_at_func]
294
  entry $f.fr.bp.func -textvariable [pref varname gdb/load/bp_func] -width 20
295
  checkbutton $f.fr.verb -text [gettext "Display Download Dialog"] \
296
    -variable [pref varname gdb/load/$target-verbose]
297
  checkbutton $f.fr.xterm -text [gettext "Use xterm as inferior's tty"] \
298
    -variable [pref varname gdb/process/xtermtty] \
299
    -onvalue yes -offvalue no
300
 
301
  if {![pref get gdb/control_target]} {
302
    $f.fr.main configure -state disabled
303
    $f.fr.exit configure -state disabled
304
    $f.fr.verb configure -state disabled
305
    $f.fr.bp.at_func configure -state disabled
306
    $f.fr.bp.func configure -state disabled
307
    checkbutton $f.fr.check -text [gettext "Compare to remote executable"] \
308
      -variable [pref varname gdb/load/check]
309
    if { $gdb_target_name == "exec" } {
310
      $f.fr.check configure -state disabled
311
    }
312
  }
313
 
314
  grid $fr.tarl $fr.tar -sticky w -padx 5 -pady 5
315
  grid $fr.cbl $fr.cb -sticky w -padx 5 -pady 5
316
  grid $fr.portl $fr.port -sticky w -padx 5 -pady 5
317
  set mapped1 $fr.cb
318
  set mapped2 $fr.port
319
 
320
  grid $f.fr.main -sticky w -padx 5 -pady 5
321
  grid $f.fr.exit -sticky w -padx 5 -pady 5
322
  pack $f.fr.bp.at_func $f.fr.bp.func -side left
323
  grid $f.fr.bp -sticky w -padx 5 -pady 5
324
  grid $f.fr.verb -sticky w -padx 5 -pady 5
325
  grid $f.fr.xterm -sticky w -padx 5 -pady 5
326
  if {![pref get gdb/control_target]} {
327
    grid $f.fr.check -sticky w -padx 5 -pady 5
328
  }
329
 
330
  grid $f.lab $f.fr -sticky w -padx 5 -pady 5
331
 
332
  # Create the "More Options" thingy
333
  if {[lsearch [image names] _MORE_] == -1} {
334
    image create photo _MORE_ -file [file join $gdb_ImageDir more.gif]
335
    image create photo _LESS_ -file [file join $gdb_ImageDir less.gif]
336
  }
337
 
338
  set MoreButton [button $opts.button -image _MORE_ \
339
                    -relief flat -command [code $this toggle_more_options]]
340
  set MoreLabel [label $opts.lbl -text {More Options}]
341
  frame $opts.frame -relief raised -bd 1
342
  pack $opts.button $opts.lbl -side left
343
  place $opts.frame -relx 1 -x -10 -rely 0.5 -relwidth 0.73 -height 2 -anchor e
344
 
345
  # Create the (hidden) more options frame
346
  set MoreFrame [iwidgets::Labeledframe $itk_interior.moreoptionsframe.frame \
347
                   -labelpos nw -labeltext {Run Options}]
348
  set frame [$MoreFrame childsite]
349
 
350
  set var [pref varname gdb/src/run_attach]
351
  checkbutton $frame.attach -text {Attach to Target} -variable $var
352
 
353
  set var [pref varname gdb/src/run_load]
354
  checkbutton $frame.load -text {Download Program} -variable $var
355
 
356
  set rm_frame [iwidgets::labeledframe $frame.run_method -labelpos nw -labeltext "Run Method" ]
357
  set RunMethod [ $rm_frame childsite ]
358
 
359
  set rm_label [label $frame.label -text "Run Method:"]
360
  set var [pref varname gdb/src/run_cont]
361
  radiobutton $RunMethod.cont -text {Continue from Last Stop} -value 1 -variable $var \
362
    -command [code $this set_run run]
363
 
364
  set var [pref varname gdb/src/run_run]
365
  radiobutton $RunMethod.run -text {Run Program} -value 1 -variable $var \
366
    -command [code $this set_run cont]
367
 
368
  # The after attaching command entry
369
  set _after_entry [entry $frame.aftere]
370
  label $frame.afterl -text {Command to issue after attaching:}
371
 
372
  grid $frame.label -column 1 -row 0 -sticky w
373
  grid $frame.attach -column 0 -row 1 -ipady 2
374
  grid $frame.load -column 0 -row 2 -ipady 2
375
 
376
  grid $RunMethod.run -column 0 -row 1 -sticky w -ipady 2
377
  grid $RunMethod.cont -column 0 -row 2 -sticky w -ipady 2
378
 
379
  grid $rm_frame -column 1 -row 1 -rowspan 2 -sticky nsew -ipady 2
380
 
381
  grid $frame.afterl -row 4 -sticky we -columnspan 2 -ipady 2
382
  grid $frame.aftere -sticky we -columnspan 2 -ipady 2
383
  grid columnconfigure $frame 0 -weight 1
384
  grid columnconfigure $frame 1 -weight 1
385
 
386
  # Map everything onto the screen
387
  # This looks like a possible packing bug -- our topmost frame
388
  # will not resize itself. So, instead, use the topmost frame.
389
  #pack $f $opts $itk_interior.moreoptionsframe -side top -fill x
390
  pack $MoreFrame -fill x -expand yes
391
  pack $f $opts -side top -fill x
392
 
393
  change_target $gdb_target($target,pretty-name)
394
 
395
  button $btns.ok -text [gettext OK] -width 7 -command [code $this save] \
396
    -default active
397
  button $btns.cancel -text [gettext Cancel] -width 7 \
398
    -command [code $this cancel]
399
  button $btns.help -text [gettext Help] -width 7 -command [code $this help] \
400
    -state disabled
401
  standard_button_box $btns
402
  bind $btns.ok  "$btns.ok flash; $btns.ok invoke"
403
  bind $btns.cancel  "$btns.cancel flash; $btns.cancel invoke"
404
  bind $btns.help  "$btns.help flash; $btns.help invoke"
405
 
406
  pack $btns -side bottom -anchor e
407
  focus $btns.ok
408
 
409
  # set up balloon help
410
  balloon register $f.fr.bp.at_func "Set User-Speficied Breakpoints at Run Time"
411
  balloon register $f.fr.bp.func "Enter a List of Functions for Breakpoints"
412
 
413
  window_name "Target Selection"
414
 
415
  if {[valid_target $target]} {
416
    $fr.tar configure -value $gdb_target($target,pretty-name)
417
  }
418
  fill_targets
419
 
420
 
421
}
422
 
423
# ------------------------------------------------------------------
424
#  METHOD:  set_saved - set saved values
425
# ------------------------------------------------------------------
426
body TargetSelection::set_saved {} {
427
  set saved_baud [pref get gdb/load/$target-baud]
428
  set saved_port [pref get gdb/load/$target-port]
429
  set saved_main [pref get gdb/load/main]
430
  set saved_exit [pref get gdb/load/exit]
431
  set saved_check [pref get gdb/load/check]
432
  set saved_verb [pref get gdb/load/$target-verbose]
433
  set saved_portname [pref get gdb/load/$target-portname]
434
  set saved_hostname [pref get gdb/load/$target-hostname]
435
  set saved_attach [pref get gdb/src/run_attach]
436
  set saved_load   [pref get gdb/src/run_load]
437
  set saved_run    [pref get gdb/src/run_run]
438
  set saved_cont   [pref get gdb/src/run_cont]
439
  if {[info exists gdb_target($target,options)]} {
440
    if {[catch {pref get gdb/load/$target-opts} saved_options]} {
441
      set saved_options ""
442
    }
443
  }
444
}
445
 
446
# ------------------------------------------------------------------
447
#  METHOD:  write_saved - write saved values to preferences
448
# ------------------------------------------------------------------
449
body TargetSelection::write_saved {} {
450
  pref setd gdb/load/$target-baud $saved_baud
451
  pref setd gdb/load/$target-port $saved_port
452
  pref setd gdb/load/main $saved_main
453
  pref setd gdb/load/exit $saved_exit
454
  pref setd gdb/load/check $saved_check
455
  pref setd gdb/load/$target-verbose $saved_verb
456
  pref setd gdb/load/$target-portname $saved_portname
457
  pref setd gdb/load/$target-hostname $saved_hostname
458
  pref setd gdb/load/$target-runlist [list $saved_attach $saved_load $saved_run $saved_cont]
459
  if {[info exists gdb_target($target,options)]} {
460
    pref setd gdb/load/$target-opts $saved_options
461
  }
462
  if {[catch {$_after_entry get} saved_after_attaching]} {
463
    set saved_after_attaching ""
464
  }
465
  pref setd gdb/load/$target-after_attaching $saved_after_attaching
466
}
467
 
468
# ------------------------------------------------------------------
469
#  METHOD:  fill_rates - fill baud rate combobox
470
# ------------------------------------------------------------------
471
body TargetSelection::fill_rates {} {
472
  $fr.cb list delete 0 end
473
 
474
  if {$gdb_target($target,baud-rates) != ""} {
475
    foreach val $gdb_target($target,baud-rates) {
476
      $fr.cb list insert end $val
477
    }
478
  }
479
}
480
 
481
# ------------------------------------------------------------------
482
#  METHOD:  fill_targets - fill target combobox
483
# ------------------------------------------------------------------
484
body TargetSelection::fill_targets {} {
485
  #[$fr.tar subwidget listbox] delete 0 end
486
  $fr.tar list delete 0 end
487
 
488
  foreach val $target_list {
489
    if {[info exists gdb_target($val,pretty-name)]} {
490
      $fr.tar list insert end $gdb_target($val,pretty-name)
491
 
492
      # Insert TCP target, if it exists
493
      if {[info exists gdb_target(${val}tcp,pretty-name)]} {
494
        $fr.tar list insert end $gdb_target(${val}tcp,pretty-name)
495
      }
496
    }
497
  }
498
}
499
 
500
# ------------------------------------------------------------------
501
#  METHOD:  config_dialog - Convenience method to map/unmap/rename
502
#            components onto the screen based on target T.
503
# ------------------------------------------------------------------
504
body TargetSelection::config_dialog {t} {
505
  pref define gdb/load/$t-verbose [pref get gdb/load/verbose]
506
  $f.fr.verb config -variable [pref varname gdb/load/$t-verbose]
507
  # Map the correct entries and comboboxes onto the screen
508
  if {$gdb_target($t,defbaud) == "TCP"} {
509
    # we have a tcp target
510
    # map host and porte
511
    if {$mapped1 != "$fr.host"} {
512
      grid forget $mapped1
513
      set mapped1 $fr.host
514
      grid $mapped1 -row 1 -column 1 -sticky w -padx 5 -pady 5
515
    }
516
    $fr.cbl configure -text "Hostname:"
517
    $fr.host config -textvariable [pref varname gdb/load/$t-hostname]
518
 
519
    if {$mapped2 != "$fr.porte"} {
520
      grid forget $mapped2
521
      set mapped2 $fr.porte
522
      grid $mapped2 -row 2 -column 1 -sticky w -padx 5 -pady 5
523
    }
524
    $fr.portl configure -text {Port:}
525
    $fr.porte config -textvariable [pref varname gdb/load/$t-portname] -fg black
526
 
527
    $mapped1 configure -state normal
528
    $mapped2 configure -state normal
529
  } elseif {$gdb_target($t,defbaud) == "ETH"} {
530
    # we have a udp target
531
    # map host and porte
532
    if {$mapped1 != "$fr.host"} {
533
      grid forget $mapped1
534
      set mapped1 $fr.host
535
      grid $mapped1 -row 1 -column 1 -sticky w -padx 5 -pady 5
536
    }
537
    $fr.cbl configure -text "Hostname:"
538
    $fr.host config -textvariable [pref varname gdb/load/$t-hostname]
539
 
540
    if {$mapped2 != "$fr.porte"} {
541
      grid forget $mapped2
542
    }
543
    $fr.portl configure -text {Port: N/A (fixed)}
544
 
545
    $mapped1 configure -state normal
546
    $mapped2 configure -state disabled
547
  } elseif {$gdb_target($t,defbaud) != ""} {
548
    # we have a serial target
549
    # map port and cb
550
    if {$mapped1 != "$fr.cb"} {
551
      grid forget $mapped1
552
      set mapped1 $fr.cb
553
      grid $mapped1 -row 1 -column 1 -sticky w -padx 5 -pady 5
554
    }
555
    $fr.cbl configure -text "Baud Rate:"
556
    $fr.cb configure -textvariable [pref varname gdb/load/$t-baud]
557
 
558
    if {$mapped2 != "$fr.port"} {
559
      grid forget $mapped2
560
      set mapped2 $fr.port
561
      grid $mapped2 -row 2 -column 1 -sticky w -padx 5 -pady 5
562
    }
563
    $fr.portl configure -text {Port:}
564
    $fr.port configure -textvariable [pref varname gdb/load/$t-port]
565
 
566
    $mapped1 configure -state normal
567
    $mapped2 configure -state normal
568
  } else {
569
    # we have a non-remote(-like) target
570
    # disable all (except tar) and check for
571
    # options
572
    $mapped1 configure -state disabled
573
    $mapped2 configure -state disabled
574
    $fr.porte configure -fg gray
575
 
576
    if {[info exists gdb_target($t,options)]} {
577
      if {$mapped1 != "$fr.host"} {
578
        grid forget $mapped1
579
        set mapped1 $fr.host
580
        grid $mapped1 -row 1 -column 1 -sticky w -padx 5 -pady 5
581
      }
582
      $mapped1 configure -state normal
583
      $fr.host config -textvariable [pref varname gdb/load/$t-opts]
584
 
585
      # We call options "arguments" for the exec target
586
      # FIXME: this is really overloaded!!
587
      if {$t == "exec"} {
588
        set text "Arguments:"
589
      } else {
590
        set text "Options:"
591
      }
592
      $fr.cbl configure -text $text
593
    }
594
  }
595
}
596
 
597
# ------------------------------------------------------------------
598
#  METHOD:  change_target - callback for target combobox
599
# ------------------------------------------------------------------
600
body TargetSelection::change_target {w {name ""}} {
601
  if {$name == ""} {return}
602
  set target [get_target $name]
603
 
604
  if { "$target" == "exec" } {
605
    $RunMethod.run configure -state disabled -value 1
606
    $RunMethod.cont configure -state disabled
607
  } else {
608
    $RunMethod.run configure -state normal
609
    $RunMethod.cont configure -state normal
610
  }
611
 
612
  debug "$target"
613
  set defbaud $gdb_target($target,defbaud)
614
  pref define gdb/load/$target-baud $defbaud
615
  pref define gdb/load/$target-portname 1234
616
 
617
  pref define gdb/load/$target-hostname [pref get gdb/load/default-hostname]
618
  if {$defbaud == ""} {
619
    pref define gdb/load/$target-port ""
620
  } else {
621
    pref define gdb/load/$target-port [pref get gdb/load/default-port]
622
  }
623
 
624
  config_dialog $target
625
  fill_rates
626
 
627
  # Configure the default run options for this target
628
  set err [catch {pref get gdb/load/$target-runlist} run_list]
629
  if {$err} {
630
    set run_list $gdb_target($target,runlist)
631
    pref setd gdb/load/$target-runlist $run_list
632
  }
633
 
634
  pref set gdb/src/run_attach [lindex $run_list 0]
635
  pref set gdb/src/run_load   [lindex $run_list 1]
636
  pref set gdb/src/run_run    [lindex $run_list 2]
637
  pref set gdb/src/run_cont   [lindex $run_list 3]
638
  set_check_button $name
639
 
640
  set err [catch {pref get gdb/load/$target-after_attaching} aa]
641
  if {$err} {
642
    set aa $gdb_target($target,after_attaching)
643
    pref setd gdb/load/$target-after_attaching $aa
644
  }
645
 
646
  $_after_entry delete 0 end
647
  $_after_entry insert 0 $aa
648
 
649
  set_saved
650
 
651
  set changes 0
652
}
653
 
654
# ------------------------------------------------------------------
655
#  PRIVATE METHOD:  change_baud - called when the baud rate is changed.
656
#  If GDB is running, set baud rate in GDB and read it back.
657
# ------------------------------------------------------------------
658
body TargetSelection::change_baud {w {baud ""}} {
659
  if {$baud != ""} {
660
    if {([string compare $baud "TCP"] != 0)
661
        && ([string compare $baud "ETH"] != 0)} {
662
      gdb_cmd "set remotebaud $baud"
663
      if {[catch {gdb_cmd "show remotebaud"} res]} {
664
        set newbaud 0
665
      } else {
666
        set newbaud [lindex $res end]
667
        set newbaud [string trimright $newbaud "."]
668
        if {$newbaud > 4000000} {
669
          set newbaud 0
670
        }
671
      }
672
      if {$newbaud != $baud} {
673
        pref set gdb/load/$target-baud $newbaud
674
      }
675
    }
676
  }
677
}
678
 
679
 
680
# ------------------------------------------------------------------
681
#  METHOD:  port_list - return a list of valid ports for Windows
682
# ------------------------------------------------------------------
683
body TargetSelection::port_list {} {
684
  set plist ""
685
  # Scan com1 - com8 trying to open each one.
686
  # If permission is denied that means it is in use,
687
  # which is OK because we may be using it or the user
688
  # may be setting up the remote target manually with
689
  # a terminal program.
690
  for {set i 1} {$i < 9} { incr i} {
691
    if {[catch { set fd [::open com$i: RDWR] } msg]} {
692
      # Failed.  Find out why.
693
      if {[string first "permission denied" $msg] != -1} {
694
        # Port is there, but busy right now. That's OK.
695
        lappend plist /dev/com$i
696
      }
697
    } else {
698
      # We got it.  Now close it and add to list.
699
      close $fd
700
      lappend plist /dev/com$i
701
    }
702
  }
703
 
704
  return $plist
705
}
706
 
707
# ------------------------------------------------------------------
708
#  METHOD:  get_target_list - return a list of targets supported
709
#  by this GDB.  Parses the output of "help target"
710
# ------------------------------------------------------------------
711
body TargetSelection::get_target_list {} {
712
  set native [native_debugging]
713
  set names ""
714
  set res [gdb_cmd "help target"]
715
  for  each line [split $res \n] {
716
    if {![string compare [lindex $line 0] "target"]} {
717
      set name [lindex $line 1]
718
 
719
      # For cross debuggers, do not allow the target "exec"
720
      if {$name == "exec" && !$native} {
721
        continue
722
      }
723
      lappend names $name
724
    }
725
  }
726
  return $names
727
}
728
 
729
# ------------------------------------------------------------------
730
#  METHOD:  save - save values
731
# ------------------------------------------------------------------
732
body TargetSelection::save {} {
733
  global gdb_target_name
734
  set err [catch {
735
    set_saved
736
    write_saved
737
    set gdb_target_name $target
738
    pref setd gdb/load/target $target
739
  } errtxt]
740
  if {$err} {debug "target: $errtxt"}
741
  if {[valid_target $gdb_target_name]} {
742
    # Dismiss the dialog box
743
    unpost
744
  } else {
745
    tk_messageBox -message "The current target is not valid."
746
  }
747
 
748
}
749
 
750
 
751
# ------------------------------------------------------------------
752
#  METHOD:  cancel - restore previous values
753
# ------------------------------------------------------------------
754
body TargetSelection::cancel {} {
755
  global gdb_target_name
756
  catch {gdb_cmd "set remotebaud $saved_baud"}
757
 
758
  $fr.cb configure -value $saved_baud
759
  write_saved
760
  if {$exportcancel} {
761
    set gdb_target_name CANCEL
762
  }
763
 
764
  # Now dismiss the dialog
765
  unpost
766
}
767
 
768
# ------------------------------------------------------------------
769
#  METHOD: set_check_button - enable/disable compare-section command
770
# ------------------------------------------------------------------
771
body TargetSelection::set_check_button {name} {
772
  if {[winfo exists  $itk_interior.f.fr.check]} {
773
    if { $name == "exec" } {
774
      $itk_interior.f.fr.check configure -state disabled
775
    } else {
776
      $itk_interior.f.fr.check configure -state normal
777
    }
778
  }
779
}
780
 
781
# ------------------------------------------------------------------
782
#  METHOD:  help - launches context sensitive help.
783
# ------------------------------------------------------------------
784
body TargetSelection::help {} {
785
}
786
 
787
# ------------------------------------------------------------------
788
#  METHOD:  reconfig - used when preferences change
789
# ------------------------------------------------------------------
790
body TargetSelection::reconfig {} {
791
  # for now, just delete and recreate
792
  destroy $itk_interior.f
793
  build_win
794
}
795
 
796
# ------------------------------------------------------------------
797
#  METHOD:  get_target - get the internal name of a target from the
798
#              pretty-name
799
# ------------------------------------------------------------------
800
body TargetSelection::get_target {name} {
801
  set t {}
802
  set list [array get gdb_target *,pretty-name]
803
  set i [lsearch -exact $list $name]
804
  if {$i != -1} {
805
    incr i -1
806
    set t [lindex [split [lindex $list $i] ,] 0]
807
  } else {
808
    debug "unknown pretty-name \"$name\""
809
  }
810
  return $t
811
}
812
 
813
# ------------------------------------------------------------------
814
#  METHOD: toggle_more_options -- toggle displaying the  More/Fewer
815
#                Options pane
816
# ------------------------------------------------------------------
817
body TargetSelection::toggle_more_options {} {
818
  if {[$MoreLabel cget -text] == "More Options"} {
819
    $MoreLabel configure -text "Fewer Options"
820
    $MoreButton configure -image _LESS_
821
    # Bug in Tk? The top-most frame does not shrink...
822
    #pack $MoreFrame
823
    pack $itk_interior.moreoptionsframe -after $itk_interior.moreoptions -fill both -padx 5 -pady 5
824
  } else {
825
    $MoreLabel configure -text "More Options"
826
    $MoreButton configure -image _MORE_
827
    #pack forget $MoreFrame
828
    pack forget $itk_interior.moreoptionsframe
829
  }
830
}
831
 
832
# ------------------------------------------------------------------
833
#  METHOD:  set_run - set the run button. Make sure not both run and
834
#                     continue are selected.
835
# ------------------------------------------------------------------
836
body TargetSelection::set_run {check_which} {
837
  global PREFS_state
838
  set var [pref varname gdb/src/run_$check_which]
839
  global $var
840
  if {[set $var]} {
841
    set $var 0
842
  }
843
}
844
 
845
# ------------------------------------------------------------------
846
#   PROCEDURE: target_trace
847
#          This procedure is used to configure gdb_loaded
848
#          and possible more) whenever the value of gdb_loaded
849
#          is changed based on the current target.
850
# ------------------------------------------------------------------
851
body TargetSelection::target_trace {variable index op} {
852
  global gdb_target_name gdb_loaded
853
 
854
  switch $gdb_target_name {
855
 
856
    exec {
857
      # The exec target is always loaded.
858
      set gdb_loaded 1
859
    }
860
  }
861
}
862
 
863
# Returns 1 if TARGET is a _runnable_ target for this gdb.
864
body TargetSelection::valid_target {target} {
865
  #set err [catch {gdb_cmd "help target $target"}]
866
  set err 0
867
  if {$target == "exec" && ![native_debugging]} {
868
    set err 1
869
  }
870
 
871
  if {[regexp "tcp$" $target]} {
872
    # Special case (of course)
873
    regsub tcp$ $target {} foo
874
    return [valid_target $foo]
875
  }
876
 
877
  return [expr {$err == 0}]
878
}
879
 
880
# Returns 1 if this is not a cross debugger.
881
body TargetSelection::native_debugging {} {
882
  global GDBStartup
883
 
884
  set r [string compare $GDBStartup(host_name) $GDBStartup(target_name)]
885
  return [expr {!$r}]
886
}

powered by: WebSVN 2.1.0

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