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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [gdb/] [gdbtcl/] [attachdlg.itb] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
#
2
# attachdlg.itb - itcl implementations for class AttachDlg
3
# ----------------------------------------------------------------------
4
# Implements Attach to process window...
5
#
6
# ----------------------------------------------------------------------
7
#   Copyright (C) 1999 Cygnus Solutions
8
#
9
 
10
body AttachDlg::constructor {args} {
11
 
12
  window_name "Attach To Process"
13
  build_win
14
  eval itk_initialize $args
15
 
16
}
17
 
18
body AttachDlg::build_win {} {
19
 
20
  # CHOOSE_PID: the list box with list or processes.  Also an entry
21
  # for typing in the PID by hand.
22
 
23
  itk_component add choose_pid {
24
    iwidgets::scrolledlistbox $itk_interior.cpid -visibleitems 30x15 \
25
      -labeltext "Choose process" -labelpos nw \
26
      -labelrelief groove -labelborderwidth 2 \
27
      -ipadx 8 -ipady 6 -childsitepos s -hscrollmode none \
28
      -textbackground white -exportselection 0 \
29
      -selectioncommand [code $this select_pid] \
30
      -dblclickcommand [code $this doit]
31
  }
32
 
33
  itk_component add pid_filter {
34
    iwidgets::entryfield [$itk_component(choose_pid) childsite].filt \
35
      -labeltext Filter: -textbackground white \
36
      -focuscommand [code $this clear_pid_selection] \
37
      -command [code $this filter_pid_selection]
38
  }
39
 
40
  $itk_component(pid_filter) insert 0 *
41
 
42
  itk_component add pid_sep {
43
    frame [$itk_component(choose_pid) childsite].sep \
44
      -height 2 -borderwidth 1 -relief sunken
45
  }
46
 
47
  # PID_ENTRY: this is the PID entry box.  You can enter the pid
48
  # by hand here, or click on the listbox to have it entered for you.
49
 
50
  itk_component add pid_entry {
51
    iwidgets::entryfield [$itk_component(choose_pid) childsite].lab \
52
      -labeltext PID: -validate numeric -textbackground white \
53
      -focuscommand [code $this clear_pid_selection]
54
  }
55
  pack $itk_component(pid_filter) -fill x -side top -pady 4
56
  pack $itk_component(pid_sep) -fill x -side top -pady 8
57
  pack $itk_component(pid_entry) -fill x -side bottom -pady 4
58
 
59
 
60
  itk_component add symbol_label {
61
    iwidgets::labeledframe $itk_interior.sym -labeltext "Choose Exec file" \
62
      -labelpos nw -labelrelief groove -labelborderwidth 2 \
63
      -ipadx 8 -ipady 6
64
  }
65
 
66
  itk_component add symbol_file {
67
    iwidgets::entryfield [$itk_interior.sym childsite].f -labeltext File: \
68
      -textbackground white
69
  }
70
  pack $itk_component(symbol_file) -pady 4 -padx 4 -fill x
71
  # can't use the -state in the entryfield, 'cause that affects the
72
  # label as well...
73
  $itk_component(symbol_file) component entry configure -state disabled
74
 
75
  $itk_component(symbol_file) configure -state normal
76
  $itk_component(symbol_file) insert 0 $::gdb_exe_name
77
  $itk_component(symbol_file) configure -state disabled
78
 
79
  itk_component add symbol_browse {
80
    button [$itk_component(symbol_file) childsite].br -text Choose... \
81
      -command [code $this choose_symbol_file]
82
  }
83
  pack $itk_component(symbol_browse) -pady 4 -padx 4 -ipadx 4
84
 
85
  itk_component add button_box {
86
    frame $itk_interior.b
87
  }
88
 
89
  itk_component add cancel {
90
    button $itk_component(button_box).cancel -text Cancel \
91
      -command [code $this cancel]
92
  }
93
 
94
  itk_component add ok {
95
    button $itk_component(button_box).ok -text OK -command [code $this doit]
96
  }
97
 
98
  if {$::gdb_exe_name == ""} {
99
    $itk_component(ok) configure -state disabled
100
  }
101
 
102
  ::standard_button_box $itk_component(button_box)
103
 
104
  pack $itk_component(button_box) -side bottom -fill x \
105
    -pady 4 -padx 4
106
  pack $itk_component(symbol_label) -side bottom -fill x -pady 4 -padx 4
107
  pack $itk_component(choose_pid) -fill both -expand 1 -pady 4 -padx 4
108
 
109
  after idle [list update idletasks;  $this list_pids]
110
 
111
}
112
 
113
# ------------------------------------------------------------------
114
#  METHOD:  doit - This accepts the attach command.
115
# ------------------------------------------------------------------
116
 
117
body AttachDlg::doit {} {
118
  set AttachDlg::last_button 1
119
  set AttachDlg::last_pid [$itk_component(pid_entry) get]
120
  set AttachDlg::symbol_file [$itk_component(symbol_file) get]
121
  debug "About to unpost"
122
  unpost
123
}
124
 
125
# ------------------------------------------------------------------
126
#  METHOD:  cancel - unpost the dialog box without attaching.
127
# ------------------------------------------------------------------
128
 
129
body AttachDlg::cancel {} {
130
  set AttachDlg::last_button 0
131
  set AttachDlg::last_pid {}
132
  unpost
133
}
134
 
135
# ------------------------------------------------------------------
136
#  METHOD:  choose_symbol_file - Query for a new symbol file.
137
# ------------------------------------------------------------------
138
 
139
body AttachDlg::choose_symbol_file {} {
140
  set file [tk_getOpenFile -parent . -title "Load New Executable"]
141
  if {$file != ""} {
142
    $itk_component(symbol_file) configure -state normal
143
    $itk_component(symbol_file) clear
144
    $itk_component(symbol_file) insert 0 $file
145
    $itk_component(symbol_file) configure -state disabled
146
    $itk_component(ok) configure -state active
147
  }
148
}
149
 
150
 
151
# ------------------------------------------------------------------
152
#  METHOD:  list_pids - List the available processes.  Right now,
153
#           this just spawns ps, which means we have to deal with
154
#           all the different ps flags & output formats.  At some
155
#           point we should steal some C code to do it by hand.
156
# ------------------------------------------------------------------
157
 
158
body AttachDlg::list_pids {{pattern *}} {
159
  global tcl_platform
160
 
161
  switch $tcl_platform(os) {
162
    Linux {
163
      set ps_cmd "ps axw"
164
    }
165
    default {
166
      set ps_cmd "ps w"
167
    }
168
  }
169
  if {[catch {::open "|$ps_cmd" r} psH]} {
170
    set errTxt "Could not exec ps: $psH
171
You will have to enter the PID by hand."
172
    ManagedWin::open WarningDlg -message [list $errTxt]
173
    return
174
  }
175
  gets $psH header
176
 
177
  set nfields [llength $header]
178
  set nfields_m_1 [expr {$nfields - 1}]
179
  set regexp {^ *([^ ]*) +}
180
  for {set i 1} {$i < $nfields_m_1} {incr i} {
181
    append regexp {[^ ]* +}
182
  }
183
  append regexp {(.*)$}
184
 
185
  $itk_component(choose_pid) clear
186
  set pid_list {}
187
 
188
  while {[gets $psH line] >= 0} {
189
    regexp $regexp $line dummy PID COMMAND
190
    if {[string match $pattern $COMMAND]} {
191
      lappend pid_list [list $PID $COMMAND]
192
      $itk_component(choose_pid) insert end $COMMAND
193
    }
194
  }
195
 
196
  close $psH
197
  $itk_component(choose_pid) selection set 0
198
  select_pid
199
 
200
}
201
 
202
# ------------------------------------------------------------------
203
#  METHOD:  select_pid - Grab the selected element from the PID listbox
204
#           and insert the associated PID into the entry form.
205
# ------------------------------------------------------------------
206
 
207
body AttachDlg::select_pid {} {
208
  set hit [$itk_component(choose_pid) curselection]
209
  if {$hit != ""} {
210
    $itk_component(pid_entry) clear
211
    $itk_component(pid_entry) insert 0 [lindex [lindex $pid_list $hit] 0]
212
  }
213
}
214
 
215
# ------------------------------------------------------------------
216
#  METHOD:  clear_pid_selection - Clear the current PID selection.
217
# ------------------------------------------------------------------
218
 
219
body AttachDlg::clear_pid_selection {} {
220
  $itk_component(choose_pid) selection clear 0 end
221
  $itk_component(pid_entry) selection range 0 end
222
}
223
 
224
# ------------------------------------------------------------------
225
#  METHOD:  filter_pid_selection - Filters the pid box.
226
# ------------------------------------------------------------------
227
 
228
body AttachDlg::filter_pid_selection {} {
229
 
230
  list_pids [$itk_component(pid_filter) get]
231
}

powered by: WebSVN 2.1.0

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