home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-bin / lib / dejagnu / debugger.exp < prev    next >
Encoding:
Text File  |  1996-10-12  |  5.0 KB  |  234 lines

  1. #   Copyright (C) 1988, 1990, 1991, 1992 Free Software Foundation, Inc.
  2.  
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 2 of the License, or
  6. # (at your option) any later version.
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10. # GNU General Public License for more details.
  11. # You should have received a copy of the GNU General Public License
  12. # along with this program; if not, write to the Free Software
  13. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  14.  
  15. # Please email any bugs, comments, and/or additions to this file to:
  16. # bug-dejagnu@prep.ai.mit.edu
  17.  
  18. # This file was written by Rob Savoye. (rob@cygnus.com)
  19.  
  20. #
  21. # dumpvars -- dump the values of a shell expression representing variable
  22. #             names.
  23. proc dumpvars { args } {
  24.     uplevel 1 [list foreach i [uplevel 1 "info vars $args"] {
  25.     if { [catch "array names $i" names ] } {
  26.         eval "puts \"${i} = \$${i}\""
  27.     } else {
  28.         foreach k $names {
  29.         eval "puts \"$i\($k\) = \$$i\($k\)\""
  30.         }
  31.     }
  32.     }
  33.        ]
  34. }
  35.  
  36. #
  37. # dumprocs -- dump the body of procedures specified by a regexp.
  38. #
  39. proc dumprocs { args } {
  40.     foreach i [info procs $args] {
  41.     puts "\nproc $i \{ [info args $i] \} \{ [info body $i]\}"
  42.     }
  43. }
  44.  
  45. #
  46. # dumpwatch -- dump all the current watchpoints
  47. #
  48. proc dumpwatch { args } {
  49.     foreach i [uplevel 1 "info vars $args"] {
  50.     set tmp ""
  51.     if { [catch "uplevel 1 array name $i" names] } {
  52.         set tmp [uplevel 1 trace vinfo $i]
  53.         if ![string match "" $tmp] {
  54.         puts "$i $tmp"
  55.         }
  56.     } else {
  57.         foreach k $names {
  58.         set tmp [uplevel 1 trace vinfo [set i]($k)]
  59.         if ![string match "" $tmp] {
  60.             puts "[set i]($k) = $tmp"
  61.         }
  62.         }
  63.     }
  64.     }
  65. }
  66.  
  67. #
  68. # watcharray -- trap a watchpoint for an array
  69. #
  70. proc watcharray { array element type} {
  71.     upvar [set array]($element) avar
  72.     case $type {
  73.     "w" { puts "New value of [set array]($element) is $avar" }
  74.     "r" { puts "[set array]($element) (= $avar) was just read" }
  75.     "u" { puts "[set array]($element) (= $avar) was just unset" }
  76.     }
  77. }
  78.  
  79. proc watchvar { v null type } {
  80.     upvar $v var
  81.     case $type {
  82.     "w" { puts "New value of $v is $var" }
  83.     "r" { puts "$v (=$var) was just read" }
  84.     "u" { puts "$v (=$var) was just unset" }
  85.     }
  86. }
  87.  
  88. #
  89. # watchunset -- watch when a variable is written
  90. #
  91. proc watchunset { arg } {
  92.     if { [catch "uplevel 1 array name $arg" names ] } {
  93.     if ![uplevel 1 info exists $arg] {
  94.         puts stderr "$arg does not exist"
  95.         return
  96.     }
  97.     uplevel 1 trace variable $arg u watchvar
  98.     } else {
  99.     foreach k $names {
  100.         if ![uplevel 1 info exists $arg] {
  101.         puts stderr "$arg does not exist"
  102.         return
  103.         }
  104.         uplevel 1 trace variable [set arg]($k) u watcharray
  105.     }
  106.     }
  107. }
  108.  
  109. #
  110. # watchwrite -- watch when a variable is written
  111. #
  112. proc watchwrite { arg } {
  113.     if { [catch "uplevel 1 array name $arg" names ] } {
  114.     if ![uplevel 1 info exists $arg] {
  115.         puts stderr "$arg does not exist"
  116.         return
  117.     }
  118.     uplevel 1 trace variable $arg w watchvar
  119.     } else {
  120.     foreach k $names {
  121.         if ![uplevel 1 info exists $arg] {
  122.         puts stderr "$arg does not exist"
  123.         return
  124.         }
  125.         uplevel 1 trace variable [set arg]($k) w watcharray
  126.     }
  127.     }
  128. }
  129.  
  130. #
  131. # watchread -- watch when a variable is read
  132. #
  133. proc watchread { arg } {
  134.     if { [catch "uplevel 1 array name $arg" names ] } {
  135.     if ![uplevel 1 info exists $arg] {
  136.         puts stderr "$arg does not exist"
  137.         return
  138.     }
  139.     uplevel 1 trace variable $arg r watchvar
  140.     } else {
  141.     foreach k $names {
  142.         if ![uplevel 1 info exists $arg] {
  143.         puts stderr "$arg does not exist"
  144.         return
  145.         }
  146.         uplevel 1 trace variable [set arg]($k) r watcharray
  147.     }
  148.     }
  149. }
  150.  
  151. #
  152. # watchdel -- delete a watch point
  153. #
  154. proc watchdel { args } {
  155.     foreach i [uplevel 1 "info vars $args"] {
  156.     set tmp ""
  157.     if { [catch "uplevel 1 array name $i" names] } {
  158.         catch "uplevel 1 trace vdelete $i w watchvar"
  159.         catch "uplevel 1 trace vdelete $i r watchvar"
  160.         catch "uplevel 1 trace vdelete $i u watchvar"
  161.     } else {
  162.         foreach k $names {
  163.         catch "uplevel 1 trace vdelete [set i]($k) w watcharray"
  164.         catch "uplevel 1 trace vdelete [set i]($k) r watcharray"
  165.         catch "uplevel 1 trace vdelete [set i]($k) u watcharray"
  166.         }
  167.     }
  168.     }
  169. }
  170.  
  171. #
  172. # this file creates GDB style commands for the Tcl debugger
  173. #
  174. proc print { var } {
  175.     puts "$var"
  176. }
  177.  
  178. proc quit { } {
  179.     log_summary
  180.     exit
  181. }
  182.  
  183. proc bt { } {
  184.     puts "[w]"
  185. }
  186.  
  187. #
  188. # create some stub procedures since we can't alias the command names
  189. #
  190. proc dp { args } {
  191.   uplevel 1 dumprocs $args
  192. }
  193.  
  194. proc dv { args } {
  195.   uplevel 1 dumpvars $args
  196. }
  197.  
  198. proc dw { args } {
  199.     uplevel 1 dumpwatch $args
  200. }
  201.  
  202. proc q { } {
  203.     quit
  204. }
  205.  
  206. proc p { args } {
  207.     uplevel 1 print $args
  208. }
  209.  
  210. proc wu { args } {
  211.     uplevel 1 watchunset $args
  212. }
  213.  
  214. proc ww { args } {
  215.     uplevel 1 watchwrite $args
  216. }
  217.  
  218. proc wr { args } {
  219.     uplevel 1 watchread $args
  220. }
  221.  
  222. proc wd { args } {
  223.     uplevel 1 watchdel $args
  224. }
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.