summaryrefslogtreecommitdiff
path: root/gdb/gdbtk/plugins/intel-pentium/msrselection.itb
blob: 365a3ef02e7a3b7b92873c6c0ef0d7ec8b276cef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# Implements MSR selection dialog class for Insight.
# Copyright 1999, 2000, 2001 Red Hat, Inc.
#
# Written by Fernando Nasser  <fnasser@redhat.com>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License (GPL) as published by
# the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# ------------------------------------------------------------------
#  NAME:         MsrSelDlg::constructor
#  DESCRIPTION:  Create a new MSR Selection dialog window.
#
#  ARGUMENTS:    None
#  RETURNS:      Nothing
# ------------------------------------------------------------------
body MsrSelDlg::constructor {args} {

  window_name "MSR Selection"
  build_win
  eval itk_initialize $args

}

# ------------------------------------------------------------------
#  NAME:         protected method MsrSelDlg::build_win
#  DESCRIPTION:  Builds the MSR dialog window from widgets.
#
#  ARGUMENTS:    None
#  RETURNS:      Nothing
#
#  NOTES:        This method should only be called once for
#                each MsrSelDlg.
# ------------------------------------------------------------------
body MsrSelDlg::build_win {} {
  
  # CHOOSE_MSR: the list box with list of MSRs.  Also an entry
  # for typing in the MSR by hand.

  itk_component add choose_msr {
    iwidgets::scrolledlistbox $itk_interior.cmsr -visibleitems 30x15 \
      -labeltext "Choose MSR" -labelpos nw \
      -labelrelief groove -labelborderwidth 2 \
      -ipadx 8 -ipady 6 -childsitepos s -hscrollmode none \
      -textbackground white -exportselection 0 \
      -selectioncommand [code $this select_msr] \
      -dblclickcommand [code $this doit]
  }

  # MSR_ENTRY: this is the MSR entry box.  You can enter the MSR register name
  # by hand here, or click on the listbox to have it entered for you.

  itk_component add msr_entry {
    iwidgets::entryfield [$itk_component(choose_msr) childsite].lab \
      -labeltext MSR: -textbackground white \
      -focuscommand [code $this clear_msr_selection] \
      -command [code $this doit]
  }
  pack $itk_component(msr_entry) -fill x -side bottom -pady 4
  
  itk_component add button_box {
    frame $itk_interior.b
  }
  
  itk_component add ok {
    button $itk_component(button_box).ok -text OK -command [code $this doit]
  }
  $itk_component(ok) configure -state disabled

  itk_component add cancel {
    button $itk_component(button_box).cancel -text Cancel \
      -command [code $this cancel]
  }

  ::standard_button_box $itk_component(button_box)

  pack $itk_component(button_box) -side bottom -fill x \
    -pady 4 -padx 4
  pack $itk_component(choose_msr) -fill both -expand 1 -pady 4 -padx 4

  after idle [list update idletasks;  $this list_msrs]

}

# ------------------------------------------------------------------
#  NAME:         protected method MsrSelDlg::doit
#  DESCRIPTION:  Selects the MSR to view and unposts window.
#
#  ARGUMENTS:    None
#  RETURNS:      Nothing
#
#  NOTES:        
# ------------------------------------------------------------------
body MsrSelDlg::doit {} {
  set MsrSelDlg::last_button 1
  set msr [$itk_component(msr_entry) get]
  set MsrSelDlg::last_msr $msr

  if {[catch {gdb_cmd "set msr-pointer $msr"} result]} {
    ManagedWin::open WarningDlg -transient \
		    -message [list "Could not select this $msr:\n$result"]
  }

  debug "About to unpost"
  unpost
}

# ------------------------------------------------------------------
#  NAME:         protected method MsrSelDlg::cancel
#  DESCRIPTION:  Unposts the window without selecting
#                the MSR to view.
#
#  ARGUMENTS:    None
#  RETURNS:      Nothing
#
#  NOTES:        
# ------------------------------------------------------------------
body MsrSelDlg::cancel {} {
  set MsrSelDlg::last_button 0
  set MsrSelDlg::last_msr {}
  unpost
}

# ------------------------------------------------------------------
#  NAME:         protected method MsrSelDlg::list_msrs
#  DESCRIPTION:  List the known MSR names.
#
#  ARGUMENTS:    None
#  RETURNS:      Nothing
#
#  NOTES:        
# ------------------------------------------------------------------
body MsrSelDlg::list_msrs {{expr {}}} {
  set err [catch {gdb_cmd "set msr-pointer" 1} msg ]
  set msg [string trimright $msg "."]
  set msrnames [split $msg ,]
  set msrnames [lrange $msrnames 1 end]

  $itk_component(choose_msr) clear
  set msr_list {}

  foreach name $msrnames {
    lappend msr_list [list $name {set msr $name}]
    $itk_component(choose_msr) insert end $name
  }

  $itk_component(choose_msr) selection set 0
  select_msr
}

# ------------------------------------------------------------------
#  NAME:         protected method MsrSelDlg::select_msrs
#  DESCRIPTION:  Grab the selected element from the MSR listbox
#                and insert the associated MSR into the entry form.
#
#  ARGUMENTS:    None
#  RETURNS:      Nothing
#
#  NOTES:        
# ------------------------------------------------------------------
body MsrSelDlg::select_msr {} {
  set hit [$itk_component(choose_msr) curselection]
  if {$hit != ""} {
    $itk_component(msr_entry) clear
    $itk_component(msr_entry) insert 0 [lindex [lindex $msr_list $hit] 0]
    $itk_component(ok) configure -state normal
  }
}

# ------------------------------------------------------------------
#  METHOD:  clear_msr_selection - Clear the current MSR selection.
# ------------------------------------------------------------------
# ------------------------------------------------------------------
#  NAME:         protected method MsrSelDlg::clear_msrs_selection
#  DESCRIPTION:  Clear the current MSR selection.
#
#  ARGUMENTS:    None
#  RETURNS:      Nothing
#
#  NOTES:        
# ------------------------------------------------------------------
body MsrSelDlg::clear_msr_selection {} {
  $itk_component(choose_msr) selection clear 0 end
  $itk_component(msr_entry) selection range 0 end
}