aboutsummaryrefslogtreecommitdiff
path: root/lib/debugger.exp
blob: 08b10015ad6298f238c35c447c9a2fcb280673b3 (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
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
# 2001, 2002, 2003 Free Software Foundation, Inc.
#
# This file is part of DejaGnu.
#
# DejaGnu is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# DejaGnu 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.
#
# You should have received a copy of the GNU General Public License
# along with DejaGnu; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.

# This file was written by Rob Savoye. (rob@welcomehome.org)

#
# Dump the values of a shell expression representing variable
# names.
proc dumpvars { args } {
    uplevel 1 [list foreach i [uplevel 1 "info vars $args"] {
	if { [catch "array names $i" names ] } {
	    eval "puts \"${i} = \$${i}\""
	} else {
	    foreach k $names {
		eval "puts \"$i\($k\) = \$$i\($k\)\""
	    }
	}
    }
	      ]
}

#
# dump the values of a shell expression representing variable
# names.
proc dumplocals { args } {
    uplevel 1 [list foreach i [uplevel 1 "info locals $args"] {
	if { [catch "array names $i" names ] } {
	    eval "puts \"${i} = \$${i}\""
	} else {
	    foreach k $names {
		eval "puts \"$i\($k\) = \$$i\($k\)\""
	    }
	}
    }
	      ]
}
#
# Dump the body of procedures specified by a regexp.
#
proc dumprocs { args } {
    foreach i [info procs $args] {
	puts "\nproc $i \{ [info args $i] \} \{ [info body $i]\}"
    }
}

#
# Dump all the current watchpoints
#
proc dumpwatch { args } {
    foreach i [uplevel 1 "info vars $args"] {
	set tmp ""
	if { [catch "uplevel 1 array name $i" names] } {
	    set tmp [uplevel 1 trace vinfo $i]
	    if ![string match "" $tmp] {
		puts "$i $tmp"
	    }
	} else {
	    foreach k $names {
		set tmp [uplevel 1 trace vinfo [set i]($k)]
		if ![string match "" $tmp] {
		    puts "[set i]($k) = $tmp"
		}
	    }
	}
    }
}

#
# Trap a watchpoint for an array
#
proc watcharray { element type} {
    upvar [set array]($element) avar
    case $type {
	"w" { puts "New value of [set array]($element) is $avar" }
	"r" { puts "[set array]($element) (= $avar) was just read" }
	"u" { puts "[set array]($element) (= $avar) was just unset" }
    }
}

proc watchvar { v type } {
    upvar $v var
    case $type {
	"w" { puts "New value of $v is $var" }
	"r" { puts "$v (=$var) was just read" }
	"u" { puts "$v (=$var) was just unset" }
    }
}

#
# Watch when a variable is written
#
proc watchunset { arg } {
    if { [catch "uplevel 1 array name $arg" names ] } {
	if ![uplevel 1 info exists $arg] {
	    puts stderr "$arg does not exist"
	    return
	}
	uplevel 1 trace variable $arg u watchvar
    } else {
	foreach k $names {
	    if ![uplevel 1 info exists $arg] {
		puts stderr "$arg does not exist"
		return
	    }
	    uplevel 1 trace variable [set arg]($k) u watcharray
	}
    }
}

#
# Watch when a variable is written
#
proc watchwrite { arg } {
    if { [catch "uplevel 1 array name $arg" names ] } {
	if ![uplevel 1 info exists $arg] {
	    puts stderr "$arg does not exist"
	    return
	}
	uplevel 1 trace variable $arg w watchvar
    } else {
	foreach k $names {
	    if ![uplevel 1 info exists $arg] {
		puts stderr "$arg does not exist"
		return
	    }
	    uplevel 1 trace variable [set arg]($k) w watcharray
	}
    }
}

#
# Watch when a variable is read
#
proc watchread { arg } {
    if { [catch "uplevel 1 array name $arg" names ] } {
	if ![uplevel 1 info exists $arg] {
	    puts stderr "$arg does not exist"
	    return
	}
	uplevel 1 trace variable $arg r watchvar
    } else {
	foreach k $names {
	    if ![uplevel 1 info exists $arg] {
		puts stderr "$arg does not exist"
		return
	    }
	    uplevel 1 trace variable [set arg]($k) r watcharray
	}
    }
}

#
# Delete a watch point
#
proc watchdel { args } {
    foreach i [uplevel 1 "info vars $args"] {
	set tmp ""
	if { [catch "uplevel 1 array name $i" names] } {
	    catch "uplevel 1 trace vdelete $i w watchvar"
	    catch "uplevel 1 trace vdelete $i r watchvar"
	    catch "uplevel 1 trace vdelete $i u watchvar"
	} else {
	    foreach k $names {
		catch "uplevel 1 trace vdelete [set i]($k) w watcharray"
		catch "uplevel 1 trace vdelete [set i]($k) r watcharray"
		catch "uplevel 1 trace vdelete [set i]($k) u watcharray"
	    }
	}
    }
}

#
# This file creates GDB style commands for the Tcl debugger
#
proc print { var } {
    puts "$var"
}

proc quit { } {
    log_and_exit
}

proc bt { } {
    puts "[w]"
}

#
# create some stub procedures since we can't alias the command names
#
proc dp { args } {
    uplevel 1 dumprocs $args
}

proc dv { args } {
    uplevel 1 dumpvars $args
}

proc dl { args } {
    uplevel 1 dumplocals $args
}

proc dw { args } {
    uplevel 1 dumpwatch $args
}

proc q { } {
    quit
}

proc p { args } {
    uplevel 1 print $args
}

proc wu { args } {
    uplevel 1 watchunset $args
}

proc ww { args } {
    uplevel 1 watchwrite $args
}

proc wr { args } {
    uplevel 1 watchread $args
}

proc wd { args } {
    uplevel 1 watchdel $args
}