/usr/share/amsn/debug.tcl is in amsn-data 0.98.9-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | ::Version::setSubversionId {$Id: debug.tcl 12293 2011-02-14 20:52:44Z vivia $}
global wchannel
if {![info exists wchannel]} {
set wchannel stdout
}
namespace eval ::debug {
proc help {} {
foreach proc [info commands ::debug::*] {
::debug::output $proc
}
}
proc printenvs {} {
global env
foreach env_var [array names env] { ::debug::output "$env_var = $env($env_var)"}
}
proc imgstats {} {
::debug::output "loaded pixmaps: [llength [array names ::skin::loaded_pixmaps]]"
::debug::output "pixmap names: [llength [array names ::skin::pixmaps_names]]"
::debug::output "image names: [llength [image names]]"
}
proc sysinfo {} {
global tcl_platform tk_patchLevel tcl_patchLevel
::debug::output "aMSN version: $::version from $::date"
::debug::output "TCL TK version: $tcl_patchLevel $tk_patchLevel"
::debug::output "Tcl platform: [array get tcl_platform]"
}
proc memuse { {about ""} } {
if {$about == ""} {
::debug::output "Nr of TCL commands: [llength [info commands]]"
::debug::output " -> nr invoked : [llength [info cmdcount]]"
# ::debug::output "Nr of variables : [llength [info vars]]"
::debug::output "Nr of global vars : [llength [info globals]]"
::debug::output "Packages loaded with"
::debug::output " 'load' : [llength [info loaded]]"
::debug::output " 'package require': [llength [package names]]"
::debug::output "Nr of images : [llength [image names]]"
}
#here we could have stats about 1 namespace for example
}
proc varsize { {namespace ""}} {
if {$namespace != ""} {
set namespaces [list $namespace]
} else {
set namespaces [namespace children ::]
}
foreach namespace $namespaces {
::debug::output "Namespace $namespace\n----------"
foreach var [info vars "${namespace}::*"] {
::debug::output "$var : "
catch { ::debug::output "\t[string length [set $var]]\n"}
catch { ::debug::output "\t[string length [array get $var]]"}
}
}
}
proc writeOn {} {
global HOME2
variable debugfile
global wchannel
set debugfile [file join $HOME2 debug.log]
#open the file for writing at the end of it
set wchannel [open $debugfile a+]
}
proc writeOff {} {
global wchannel
flush $wchannel
close $wchannel
set wchannel stdout
}
proc printStackTrace { } {
::debug::output "Stacktrace:"
for { set i [info level] } { $i > 0 } { incr i -1} {
::debug::output "Level $i : [info level $i]"
::debug::output "Called from within : "
}
::debug::output ""
}
proc printStackTrace2 { } {
for { set i [info level] } { $i > 0 } { incr i -1} {
puts "Level $i : [info level $i]"
puts "Called from within : "
}
puts ""
}
proc findSockets { {namespace "::" } } {
set result [list]
foreach v [info vars "${namespace}::*"] {
set content ""
if { [catch {set content [set $v]}] } {
foreach {key val} [array get $v] {
set content $val
if {[string first "sock" $content] == 0 &&
![catch {eof $content}]} {
lappend result $content
puts "Found socket $content in variable ${v} ($key)"
}
}
} else {
if {[string first "sock" $content] == 0 &&
![catch {eof $content}] } {
lappend result $content
puts "Found socket $content in variable ${v}"
}
}
}
foreach n [namespace children $namespace] {
set res [findSockets $n]
set result [concat $result $res]
}
return $result
}
#Aid procs
proc output {data} {
global wchannel
variable force
set force 1
#if we're writing to the file, also write to stdout
#.. better not :D
#if {$wchannel != "stdout"} {
# puts $data
#}
puts $wchannel $data
catch {if {$force == 1} {
catch {flush $wchannel}
} }
}
# adapted from: http://wiki.tcl.tk/15193
proc get_proc_full { name {level 2} } {
if {![string match ::* $name]} {
set ns [uplevel $level namespace current]
if { $ns != "::" } {
set name "${ns}::${name}"
}
}
return $name
}
proc stack_procs_enter { args } {
puts "Enter: [lindex $args 0]"
}
proc stack_procs_leave { args } {
set ret [lindex $args 2]
if { $ret == {} } {
set ret "{}"
}
puts "Leave: $ret <- [lindex $args 0]"
}
proc enable_hook {} {
rename proc ::tk::proc
uplevel #0 {
::tk::proc proc { name args body } {
set name [::debug::get_proc_full $name]
::tk::proc $name $args $body
trace add execution $name enter ::debug::stack_procs_enter
trace add execution $name leave ::debug::stack_procs_leave
}
}
}
proc disable_hook {} {
uplevel #0 {
catch {
rename proc {}
rename ::tk::proc proc
}
}
}
# This will not work with upvar or uplevel!
# We must hook them to and increment the level!
proc stack_procs { {filename {}} } {
::debug::enable_hook
if { [catch {
if { $filename == {} } {
reload_files
} else {
source $filename
}
} res ] } {
puts "Error when loading files: $res"
}
::debug::disable_hook
}
proc find_all_snits { {ns "::"} } {
foreach n [namespace children $ns] {
if {[string first "Snit_inst" $n] != -1} {
puts "[namespace parent $n] --- [set ${n}::Snit_instance]"
}
find_all_snits $n
}
}
}
|