proc keep_raised {top} {
if {[winfo exists $top]} {
raise $top
wm deiconify $top
after 1000 [info level 0]
}
}
proc sleep {sec} {
global __sleep_timer
set __sleep_timer 0
after [expr {1000 * $sec}] set __sleep_timer 1
vwait __sleep_timer
}
proc auto_step {} {
global auto_step_id
set auto_step_id [after 2000 auto_step]
gdb_cmd next
}
proc auto_step_cancel {} {
global auto_step_id
if {[info exists auto_step_id]} {
after cancel $auto_step_id
unset auto_step_id
}
}
proc tfind_cmd {command} {
gdbtk_busy
set err [catch {gdb_cmd $command} msg]
if {$err || [regexp "Target failed to find requested trace frame" $msg]} {
tk_messageBox -icon error -title "GDB" -type ok \
-modal task -message $msg
gdbtk_idle
return
} else {
gdbtk_update
gdbtk_idle
}
}
proc save_trace_commands {} {
set out_file [tk_getSaveFile -title "Enter output file for trace commands"]
debug "Got outfile: $out_file"
if {$out_file != ""} {
gdb_cmd "save-tracepoints $out_file"
}
}
proc do_test {{file {}} {verbose {}} {tests {}}} {
global _test
if {$file == {}} {
error "wrong \# args: should be: do_test file ?verbose? ?tests ...?"
}
if {$verbose != {}} {
set _test(verbose) $verbose
} elseif {![info exists _test(verbose)]} {
set _test(verbose) 0
}
if {$tests != {}} {
set _test(tests) $tests
}
set _test(interactive) 1
after 500 [list source $file]
}
proc gdbtk_read_defs {} {
global _test env
if {[info exists env(DEFS)]} {
set err [catch {source $env(DEFS)} errTxt]
} else {
set err [catch {source defs} errTxt]
}
if {$err} {
if {$_test(interactive)} {
tk_messageBox -icon error -message "Cannot load defs file:\n$errTxt" -type ok
return 0
} else {
puts stdout "cannot load defs files: $errTxt\ntry setting DEFS"
exit 1
}
}
return 1
}
proc bp_exists {linespec} {
lassign $linespec foo function filename line_number addr pc_addr
set bps [gdb_get_breakpoint_list]
foreach bpnum $bps {
set bpinfo [gdb_get_breakpoint_info $bpnum]
lassign $bpinfo file func line pc type enabled disposition \
ignore_count commands cond thread hit_count
if {$filename == $file && $function == $func && $addr == $pc} {
return $bpnum
}
}
return -1
}
proc CygScrolledListbox { win args } {
frame $win
eval {listbox $win.list -yscrollcommand [list $win.sy set]} $args
scrollbar $win.sy -orient vertical -command [list $win.list yview]
set pad [expr [$win.sy cget -width] + 2* \
([$win.sy cget -bd] + \
[$win.sy cget -highlightthickness])]
frame $win.pad -width $pad -height $pad
pack $win.sy -side right -fill y
pack $win.list -side left -fill both -expand true
return $win.list
}
proc gridCGet {slave option} {
set config_list [grid info $slave]
return [lindex $config_list [expr [lsearch $config_list $option] + 1]]
}
proc find_iwidgets_library {} {
global errMsg
set IwidgetsOK 1
if {[catch {package require Iwidgets 3.0} errMsg]} {
set IwidgetsOK 0
set iwidgetsSrcDir [glob -nocomplain [file join \
[file dirname [file dirname $::tcl_library]] \
itcl iwidgets*]]
set exec_name [info nameofexecutable]
set curdir [pwd]
if {[string compare [file type $exec_name] "link"] == 0} {
set exec_name [file readlink $exec_name]
if {[string compare [file pathtype $exec_name] "relative"] == 0} {
set exec_name [file join [pwd] $exec_name]
}
}
cd [file dirname $exec_name]
set exec_name [pwd]
cd $curdir
set iwidgetsBuildDir [glob -nocomplain [file join \
[file dirname $exec_name] \
itcl iwidgets*]]
if {[llength $iwidgetsSrcDir] == 1 && [llength $iwidgetsBuildDir] == 1} {
set initFile [file join [lindex $iwidgetsBuildDir 0] \
$::tcl_platform(platform) iwidgets.tcl]
set libDir [file join [lindex $iwidgetsSrcDir 0] generic]
if {[file exists $initFile] && [file isdirectory $libDir]} {
if {![catch {source $initFile} err]} {
set libPos [lsearch $::auto_path [file join $::iwidgets::library scripts]]
if {$libPos >= 0} {
set auto_path [lreplace $::auto_path $libPos $libPos $libDir]
} else {
lappend ::auto_path $libDir
}
set ::iwidgets::library $libDir
set IwidgetsOK 1
} else {
append errMsg "\nError in iwidgets.tcl file: $err"
}
}
} else {
append errMsg "\nCould not find in-place versions of the Iwidgets files\n"
append errMsg "Looked at: $iwidgetsSrcDir\n"
append errMsg "and: $iwidgetsBuildDir\n"
}
}
return $IwidgetsOK
}
proc get_disassembly_flavor {} {
if {[catch {gdb_cmd "show disassembly-flavor"} ret]} {
return ""
} else {
regexp {\"([^\"]*)\"\.} $ret dummy gdb_val
return $gdb_val
}
}
# ------------------------------------------------------------------
# PROC: list_disassembly_flavors - Lists the current disassembly flavors.
# Returns an empty list if the set disassembly-flavor is not supported.
# ------------------------------------------------------------------
proc list_disassembly_flavors {} {
catch {gdb_cmd "set disassembly-flavor"} ret_val
if {[regexp {Requires an argument\. Valid arguments are (.*)\.} \
$ret_val dummy list]} {
foreach elem [split $list ","] {
lappend vals [string trim $elem]
}
return [lsort $vals]
} else {
return {}
}
}
# ------------------------------------------------------------------
# PROC: init_disassembly_flavor - Synchs up gdb's internal disassembly
# flavor with the value in the preferences file.
# ------------------------------------------------------------------
proc init_disassembly_flavor {} {
set gdb_val [get_disassembly_flavor]
if {$gdb_val != ""} {
set def_val [pref get gdb/src/disassembly-flavor]
if {[string compare $def_val ""] != 0} {
if {[catch "gdb_cmd \"set disassembly-flavor $def_val\""]} {
pref set gdb/src/disassembly-flavor $gdb_val
}
} else {
pref set gdb/src/disassembly-flavor $gdb_val
}
}
}
proc list_element_strcmp {index first second} {
set theFirst [lindex $first $index]
set theSecond [lindex $second $index]
return [string compare $theFirst $theSecond]
}