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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [gdb/] [gdbtcl/] [util.tcl] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# Utilities for GDBtk.
2
# Copyright 1997, 1998, 1999 Cygnus Solutions
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
# Misc routines
17
#
18
#   PROCS:
19
#
20
#     keep_raised - keep a window raised
21
#     sleep - wait a certain number of seconds and return
22
#     toggle_debug_mode - turn debugging on and off
23
#     freeze - make a window modal
24
#     bp_exists - does a breakpoint exist on linespec?
25
#
26
# ----------------------------------------------------------------------
27
#
28
 
29
 
30
# A helper procedure to keep a window on top.
31
proc keep_raised {top} {
32
  if {[winfo exists $top]} {
33
    raise $top
34
    wm deiconify $top
35
    after 1000 [info level 0]
36
  }
37
}
38
 
39
# sleep - wait a certain number of seconds then return
40
proc sleep {sec} {
41
  global __sleep_timer
42
  set __sleep_timer 0
43
  after [expr {1000 * $sec}] set __sleep_timer 1
44
  vwait __sleep_timer
45
}
46
 
47
 
48
# ------------------------------------------------------------------
49
#  PROC:  auto_step - automatically step through a program
50
# ------------------------------------------------------------------
51
 
52
# FIXME FIXME
53
proc auto_step {} {
54
  global auto_step_id
55
 
56
  set auto_step_id [after 2000 auto_step]
57
  gdb_cmd next
58
}
59
 
60
# ------------------------------------------------------------------
61
#  PROC:  auto_step_cancel - cancel auto-stepping
62
# ------------------------------------------------------------------
63
 
64
proc auto_step_cancel {} {
65
  global auto_step_id
66
 
67
  if {[info exists auto_step_id]} {
68
    after cancel $auto_step_id
69
    unset auto_step_id
70
  }
71
}
72
 
73
# ------------------------------------------------------------------
74
#  PROC:  tfind_cmd -- to execute a tfind command on the target
75
# ------------------------------------------------------------------
76
proc tfind_cmd {command} {
77
  gdbtk_busy
78
  # need to call gdb_cmd because we want to ignore the output
79
  set err [catch {gdb_cmd $command} msg]
80
  if {$err || [regexp "Target failed to find requested trace frame" $msg]} {
81
    tk_messageBox -icon error -title "GDB" -type ok \
82
      -modal task -message $msg
83
    gdbtk_idle
84
    return
85
  } else {
86
    gdbtk_update
87
    gdbtk_idle
88
  }
89
}
90
 
91
# ------------------------------------------------------------------
92
#  PROC:  save_trace_command -- Saves the current trace settings to a file
93
# ------------------------------------------------------------------
94
proc save_trace_commands {} {
95
 
96
  set out_file [tk_getSaveFile -title "Enter output file for trace commands"]
97
  debug "Got outfile: $out_file"
98
  if {$out_file != ""} {
99
    gdb_cmd "save-tracepoints $out_file"
100
  }
101
}
102
 
103
# ------------------------------------------------------------------
104
#  PROC:  do_test - invoke the test passed in
105
#           This proc is provided for convenience. For any test
106
#           that uses the console window (like the console window
107
#           tests), the file cannot be sourced directly using the
108
#           'tk' command because it will block the console window
109
#           until the file is done executing. This proc assures
110
#           that the console window is free for input by wrapping
111
#           the source call in an after callback.
112
#           Users may also pass in the verbose and tests globals
113
#           used by the testsuite.
114
# ------------------------------------------------------------------
115
proc do_test {{file {}} {verbose {}} {tests {}}} {
116
  global _test
117
 
118
  if {$file == {}} {
119
    error "wrong \# args: should be: do_test file ?verbose? ?tests ...?"
120
  }
121
 
122
  if {$verbose != {}} {
123
    set _test(verbose) $verbose
124
  } elseif {![info exists _test(verbose)]} {
125
    set _test(verbose) 0
126
  }
127
 
128
  if {$tests != {}} {
129
    set _test(tests) $tests
130
  }
131
 
132
  set _test(interactive) 1
133
  after 500 [list source $file]
134
}
135
 
136
# ------------------------------------------------------------------
137
#  PROCEDURE:  gdbtk_read_defs
138
#        Reads in the defs file for the testsuite. This is usually
139
#        the first procedure called by a test file. It returns
140
#        1 if it was successful and 0 if not (if run interactively
141
#        from the console window) or exits (if running via dejagnu).
142
# ------------------------------------------------------------------
143
proc gdbtk_read_defs {} {
144
  global _test env
145
 
146
  if {[info exists env(DEFS)]} {
147
    set err [catch {source $env(DEFS)} errTxt]
148
  } else {
149
    set err [catch {source defs} errTxt]
150
  }
151
 
152
  if {$err} {
153
    if {$_test(interactive)} {
154
      tk_messageBox -icon error -message "Cannot load defs file:\n$errTxt" -type ok
155
      return 0
156
    } else {
157
      puts stderr "cannot load defs files: $errTxt\ntry setting DEFS"
158
      exit 1
159
    }
160
  }
161
 
162
  return 1
163
}
164
 
165
# ------------------------------------------------------------------
166
#  PROCEDURE:  bp_exists
167
#            Returns BPNUM if a breakpoint exists at LINESPEC or
168
#            -1 if no breakpoint exists there
169
# ------------------------------------------------------------------
170
proc bp_exists {linespec} {
171
 
172
  lassign $linespec foo function filename line_number addr pc_addr
173
 
174
  set bps [gdb_get_breakpoint_list]
175
  foreach bpnum $bps {
176
    set bpinfo [gdb_get_breakpoint_info $bpnum]
177
    lassign $bpinfo file func line pc type enabled disposition \
178
      ignore_count commands cond thread hit_count user_specification
179
    if {$filename == $file && $function == $func && $addr == $pc} {
180
      return $bpnum
181
    }
182
  }
183
 
184
  return -1
185
}
186
 
187
 
188
# Scrolled Listbox - this could be in libgui,
189
# but we'll probably just start using new iwidgets stuff 
190
# soon so keep it here temporarily.  This is based on
191
# code from Welch's book.
192
 
193
proc CygScrolledListbox { win args } {
194
  frame $win
195
  # Create listbox attached to scrollbars, pass thru $args
196
  eval {listbox $win.list -yscrollcommand [list $win.sy set]} $args
197
  scrollbar $win.sy -orient vertical -command [list $win.list yview]
198
 
199
  # Create padding based on the scrollbar width and border
200
  set pad [expr [$win.sy cget -width] + 2* \
201
             ([$win.sy cget -bd] + \
202
                [$win.sy cget -highlightthickness])]
203
 
204
  frame $win.pad -width $pad -height $pad
205
  pack $win.sy -side right -fill y
206
  pack $win.list -side left -fill both -expand true
207
  return $win.list
208
}
209
 
210
# gridCGet - This provides the missing grid cget
211
# command.
212
 
213
proc gridCGet {slave option} {
214
  set config_list [grid info $slave]
215
  return [lindex $config_list [expr [lsearch $config_list $option] + 1]]
216
}
217
 
218
# ------------------------------------------------------------------
219
# PROC: find_iwidgets_library - Find the IWidgets library.
220
#
221
# This is a little bit of bogosity which is necessary so we
222
# can find the iwidgets libraries if we are not installed:
223
# The problem is that the iwidgets are really weird.  The init file is 
224
# in the build tree, but all the library files are in the source tree...
225
#
226
# ------------------------------------------------------------------
227
proc find_iwidgets_library {} {
228
  global errMsg
229
 
230
  set IwidgetsOK 1
231
 
232
  if {[catch {package require Iwidgets 3.0} errMsg]} {
233
 
234
    # OK, we are not installed or this would have succeeded...
235
    # Lets try to do it by hand:
236
    set IwidgetsOK 0
237
 
238
    set iwidgetsSrcDir [glob -nocomplain [file join \
239
                                            [file dirname [file dirname $::tcl_library]] \
240
                                            itcl iwidgets*]]
241
 
242
    # Canonicalize the executable's directory name.  It turns out that on Solaris, 
243
    # info nameofexecutable returns /foo/bar/real_dir/./gdb when gdb is launched from
244
    # another gdb session, so we have to fix this up.
245
 
246
    set exec_name [info nameofexecutable]
247
    set curdir [pwd]
248
    if {[string compare [file type $exec_name] "link"] == 0} {
249
      set exec_name [file readlink $exec_name]
250
      if {[string compare [file pathtype $exec_name] "relative"] == 0} {
251
        set exec_name [file join [pwd] $exec_name]
252
      }
253
    }
254
 
255
    cd [file dirname $exec_name]
256
    set exec_name [pwd]
257
    cd $curdir
258
 
259
    set iwidgetsBuildDir [glob -nocomplain [file join \
260
                                              [file dirname $exec_name] \
261
                                              itcl iwidgets*]]
262
    set initFile [file join [lindex $iwidgetsBuildDir 0] \
263
                    unix iwidgets.tcl]
264
 
265
    if {[llength $iwidgetsBuildDir] == 0} {
266
      # We could be runnning on an installed toolchain.
267
      # Check in "normal" installed place: "../../share/iwidgets*"
268
      set iwidgetsBuildDir [glob -nocomplain [file join \
269
                                                [file dirname [file dirname $exec_name]] \
270
                                                share iwidgets*]]
271
      set initFile [file join [lindex $iwidgetsBuildDir 0] iwidgets.tcl]
272
    }
273
 
274
    if {[llength $iwidgetsSrcDir] == 1 && [llength $iwidgetsBuildDir] == 1} {
275
      # The lindex is necessary because the path may have spaces in it...
276
      set libDir [file join [lindex $iwidgetsSrcDir 0] generic]
277
      if {[file exists $initFile] && [file isdirectory $libDir]} {
278
        if {![catch {source $initFile} err]} {
279
          # Now fix up the stuff the Iwidgets init file got wrong...
280
          set libPos [lsearch $::auto_path [file join $::iwidgets::library scripts]]
281
          if {$libPos >= 0} {
282
            set auto_path [lreplace $::auto_path $libPos $libPos $libDir]
283
          } else {
284
            lappend ::auto_path $libDir
285
          }
286
          set ::iwidgets::library $libDir
287
          set IwidgetsOK 1
288
        } else {
289
          append errMsg "\nError in iwidgets.tcl file: $err"
290
        }
291
      }
292
    } else {
293
      append errMsg "\nCould not find in-place versions of the Iwidgets files\n"
294
      append errMsg "Looked at: $iwidgetsSrcDir\n"
295
      append errMsg "and: $iwidgetsBuildDir\n"
296
    }
297
 
298
  }
299
  return $IwidgetsOK
300
}
301
 
302
# ------------------------------------------------------------------
303
#  PROC:  get_disassembly_flavor - gets the current disassembly flavor.
304
#         The set disassembly-flavor command is assumed to exist.  This
305
#         will error out if it does not.
306
# ------------------------------------------------------------------
307
proc get_disassembly_flavor {} {
308
  if {[catch {gdb_cmd "show disassembly-flavor"} ret]} {
309
    return ""
310
  } else {
311
    regexp {\"([^\"]*)\"\.} $ret dummy gdb_val
312
    return $gdb_val
313
  }
314
}
315
 
316
# ------------------------------------------------------------------
317
#  PROC:  list_disassembly_flavors - Lists the current disassembly flavors.
318
#         Returns an empty list if the set disassembly-flavor is not supported.
319
# ------------------------------------------------------------------
320
proc list_disassembly_flavors {} {
321
  catch {gdb_cmd "set disassembly-flavor"} ret_val
322
  if {[regexp {Requires an argument\. Valid arguments are (.*)\.} \
323
         $ret_val dummy list]} {
324
    foreach elem  [split $list ","] {
325
      lappend vals [string trim $elem]
326
    }
327
    return [lsort $vals]
328
  } else {
329
    return {}
330
  }
331
}
332
 
333
# ------------------------------------------------------------------
334
#  PROC:  init_disassembly_flavor - Synchs up gdb's internal disassembly
335
#         flavor with the value in the preferences file.
336
# ------------------------------------------------------------------
337
proc init_disassembly_flavor {} {
338
  set gdb_val [get_disassembly_flavor]
339
  if {$gdb_val != ""} {
340
    set def_val [pref get gdb/src/disassembly-flavor]
341
    if {[string compare $def_val ""] != 0} {
342
      if {[catch "gdb_cmd \"set disassembly-flavor $def_val\""]} {
343
        pref set gdb/src/disassembly-flavor $gdb_val
344
      }
345
    } else {
346
      pref set gdb/src/disassembly-flavor $gdb_val
347
    }
348
  }
349
}
350
 
351
# ------------------------------------------------------------------
352
#  PROC:  list_element_strcmp - to be used in lsort -command when the
353
#         elements are themselves lists, and you always want to look at
354
#         a particular item.
355
# ------------------------------------------------------------------
356
proc list_element_strcmp {index first second} {
357
  set theFirst [lindex $first $index]
358
  set theSecond [lindex $second $index]
359
 
360
  return [string compare $theFirst $theSecond]
361
}

powered by: WebSVN 2.1.0

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