rdebug.tex 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. \begin{document}
  2. \begin{Introduction}{Debugging}
  3. The package \name{RDEBUG} helps you to find bugs in algebraic
  4. REDUCE programs by making the functions of the PSL package
  5. \name{DEBUG} available for algebraic mode.
  6. The following facilities are available:
  7. Entry-exit trace (\nameref{tr}, \nameref{untr}):
  8. visualize every call of
  9. explicitly declared functions, printing their arguments and
  10. results.
  11. Assignment trace (\nameref{trst}, \nameref{untrst}):
  12. report all assignments which
  13. are executed inside explicitly declared functions. This facility
  14. is not available for compiled functions.
  15. Breakpoint (\nameref{br}, \nameref{unbr}):
  16. interrupt the program execution at
  17. entry and exit of explicitly declared functions, invoking
  18. a \nameref{breakloop}.
  19. Conditional trace (\nameref{trwhen}, \nameref{untrwhen})
  20. or break (\nameref{brwhen},\nameref{unbrwhen}).
  21. Rule trace (\nameref{trrl}, \nameref{untrrl}):
  22. report the arguments and results of a rule whenever it fires.
  23. You can control the debug output using the operator \nameref{trout}
  24. and the variable \nameref{trlimit}.
  25. \end{Introduction}
  26. %=============================================================
  27. \begin{Concept}{breakloop}
  28. \index{debug}
  29. A \name{break loop} is an interrupt of the program execution
  30. where control is given temporarily to the terminal for
  31. entering commands in a standard command - evaluate - print loop.
  32. When a break occurs, you can inspect the current
  33. environment or even alter it, and the
  34. interrupted computation may be terminated or continued.
  35. A break can be caused
  36. - by an internal error when the switch \nameref{break} is on,
  37. - by an explicit call of \name{lisp break()},
  38. - at entry and exit time of a procedure which has been
  39. declared by \nameref{br}.
  40. In a break situation the evaluation is stopped temporarily
  41. and the control returns to the terminal with a special prompt:
  42. \name{break[1]1:}.
  43. The number in square brackets counts the break level - it is
  44. increased when a break occurs inside a break; the normal
  45. REDUCE statement counter follows. Each break loop supports its
  46. own statement numbers and input and output buffers.
  47. After terminating of a break loop the
  48. previous statement counters and buffers are restored.
  49. In a break loop all REDUCE commands can be
  50. entered. Additionally, there is a set of single character commands
  51. which allow you to control the break environment. All these
  52. begin with an underscore character:
  53. \name{\_a;} terminate break and return to the top REDUCE level
  54. \name{\_c;} continue execution of interrupted procedure
  55. \name{\_i;} print a backtrace (list of procedures in the
  56. call hierarchy)
  57. \name{\_l} \meta{var}; (local) read the content of the local variable
  58. \meta{var}
  59. \name{\_m;} print the last (LISP-) error message
  60. \name{\_q;} terminate the break loop and return to the next
  61. higher level.
  62. Global variables can be accessed as usual in the REDUCE language.
  63. They can also be set to different values in the break loop.
  64. The inspect values assigned to dummy arguments and scalar variables of
  65. procedures in the actual call hierarchy, you need a special command
  66. \name{\_l}. These values cannot be altered in the break loop.
  67. \begin{Examples}
  68. procedure p1(x); \\
  69. begin scalar y1; y1:=x^2; return p2(y1); end;\\
  70. procedure p2(q); q^2;\\
  71. br p2;\\
  72. x:=22;\\
  73. p1(alpha);\\
  74. p2 being entered\\
  75. q: alpha**2$\\
  76. Break before entering `p2'\\
  77. break[1]1: x; & 22\\
  78. break[1]2: _l x; & alpha\\
  79. break[1]3: _l y1; & alpha^2 \\
  80. break[1]4: _l q;& alpha^2 \\
  81. break[1]6: _c;\\
  82. Break after call `p2', value `(expt (expt alpha 2) 2)'\\
  83. break[1]1: _c;\\
  84. &alpha^4\\
  85. \end{Examples}
  86. In the corresponding break loop caused by calling \name{p2}
  87. indirectly via \name{p1}, you can access the global \name{x}, the
  88. locals \name{x} and \name{y1} of \name{p1} and the \name{q} of
  89. \name{p2}.
  90. \end{Concept}
  91. %=========================================================
  92. \begin{Operator}{tr}
  93. \index{trace}\index{debug}
  94. The command \name{tr} puts one or several procedures to
  95. under trace. Every time such a function is executed, a message
  96. is printed during the procedure entry and another one is generated
  97. at the return time. The entry message records the
  98. actual procedure arguments equated to the dummy parameter
  99. names, and at the exit time the procedure value is printed.
  100. Recursive calls are marked by an indentation and a level number.
  101. \begin{Syntax}
  102. \name{tr}\meta{proc1},\meta{proc2},...,\meta{procn};
  103. \end{Syntax}
  104. Here \meta{proc1},\meta{proc2},...,\meta{procn}
  105. are names of procedures
  106. to be added to the set of traced procedures. See also
  107. \nameref{trst},\nameref{trwhen}.
  108. \end{Operator}
  109. \begin{Operator}{untr}
  110. \index{trace}\index{debug}
  111. Tracing is stopped for one or several functions by the
  112. command \name{untr}:
  113. \begin{Syntax}
  114. \name{untr}\meta{proc1},\meta{proc2},...,\meta{procn};
  115. \end{Syntax}
  116. \end{Operator}
  117. %========================================================
  118. \begin{Operator}{trst}
  119. \index{trace}\index{assignment-trace}\index{debug}
  120. Sometimes one needs detailed information about the inner behavior of
  121. a procedure, especially if it is a longer piece of code.
  122. For a procedure declared in a \name{trst} command
  123. an extended trace is performed:
  124. all executed explicit assignments and all passed labels
  125. are reported at run time.
  126. \begin{Syntax}
  127. \name{trst}\meta{proc1},\meta{proc2},...,\meta{procn};
  128. \end{Syntax}
  129. Here \meta{proc1},\meta{proc2},...,\meta{procn}
  130. are names of procedures
  131. to be added to the set of traced procedures.
  132. When your program contains a \nameref{for} loop,
  133. REDUCE translates this to a sequential piece of
  134. LISP instructions. When using \name{trst}, the printout
  135. is driven by the unfolded code. When the code contains a
  136. \name{for-each-in} statement, the name of the control variable is
  137. internally used to keep the remainder of the list during the loop
  138. control, and you will see the corresponding assignments
  139. in the printout rather than the individual values in the
  140. loop steps.
  141. \end{Operator}
  142. \begin{Operator}{untrst}
  143. \index{trace}\index{assignment-trace}\index{debug}
  144. Extended tracing is stopped for one or several functions by the
  145. command \name{untrst}:
  146. \begin{Syntax}
  147. \name{untrst}\meta{proc1},\meta{proc2},...,\meta{procn};
  148. \end{Syntax}
  149. \end{Operator}
  150. %=========================================================
  151. \begin{Operator}{trwhen}
  152. \index{trace}\index{debug}
  153. The trace output can be tunrned on or off automatically by
  154. a boolean expression which is linked to a traced procedure
  155. by the command \name{trwhen}:
  156. \begin{Syntax}
  157. trwhen \meta{name},\meta{booleanexpr};
  158. \end{Syntax}
  159. The boolean expression must follow
  160. standard REDUCE syntax. It may contain references
  161. to global values and to
  162. the actual parameters of the procedure. As long as the
  163. procedure is not compiled, the original names of the dummy arguments
  164. are used. For a compiled procedure the original names
  165. are not available; instead the names \name{a1}, \name{a2}, ...
  166. must be used. Example: the following procedure produces trace
  167. output only if the main variable of its argument is \name{x}:
  168. \begin{Examples}
  169. procedure hugo(u); otto(u);\\
  170. tr hugo;\\
  171. trwhen hugo,mainvar(u)=x;\\
  172. \end{Examples}
  173. Note: for a symbolic procedure, the \name{trwhen} command
  174. must be given in symbolic mode or with prefix $symbolic$.
  175. \end{Operator}
  176. \begin{Operator}{untrwhen}
  177. \index{trace}\index{debug}
  178. Conditional trace is stopped for a procedure by calling
  179. \begin{Syntax}
  180. untrwhen \meta{name};
  181. \end{Syntax}
  182. \end{Operator}
  183. %========================================================
  184. \begin{Switch}{break}
  185. \index{debug}
  186. When the switch \name{break} is set on, every
  187. evaluation error causes a \nameref{breakloop}. Most of these
  188. breaks are non-continuable; however, you have the
  189. opportunity to read the actual values of local variables
  190. in the environment which caused the error.
  191. \end{Switch}
  192. %=========================================================
  193. \begin{Operator}{br}
  194. \index{break}\index{debug}
  195. The command \name{br} declares one or several procedures
  196. as breakpoints. When executing such a function, the
  197. computation is interrupted by a \nameref{breakloop}
  198. at function enter and return times.
  199. \begin{Syntax}
  200. \name{br}\meta{proc1},\meta{proc2},...,\meta{procn};
  201. \end{Syntax}
  202. Here \meta{proc1},\meta{proc2},...,\meta{procn}
  203. are names of procedures
  204. to be added to the set of break points.
  205. See also \nameref{brwhen}.
  206. \end{Operator}
  207. \begin{Operator}{unbr}
  208. \index{break}\index{debug}
  209. The break property
  210. can be removed by the command \name{unbr}:
  211. \begin{Syntax}
  212. \name{unbr}\meta{proc1},\meta{proc2},...,\meta{procn};
  213. \end{Syntax}
  214. \end{Operator}
  215. % =============================================================
  216. \begin{Operator}{brwhen}
  217. \index{break}\index{debug}
  218. The break point (see \nameref{br})
  219. can be tunrned on or off automatically by
  220. a boolean expression which is linked to a breakpoint procedure
  221. by the command \name{brwhen}:
  222. \begin{Syntax}
  223. brwhen \meta{name},\meta{booleanexpr};
  224. \end{Syntax}
  225. The boolean expression must follow
  226. standard REDUCE syntax. It may contain references
  227. to global values and to
  228. the actual parameters of the procedure. As long as the
  229. procedure is not compiled, the original names of the dummy arguments
  230. are used. For a compiled procedure the original names
  231. are not available; instead the names \name{a1}, \name{a2}, ...
  232. must be used. Example: the following procedure is broken
  233. only if the main variable of its argument is \name{x}:
  234. \begin{Examples}
  235. procedure hugo(u); otto(u);\\
  236. br hugo;\\
  237. brwhen hugo,mainvar(u)=x;\\
  238. \end{Examples}
  239. Note: for a symbolic procedure, the \name{brwhen} command
  240. must be given in symbolic mode or with prefix $symbolic$.
  241. \end{Operator}
  242. \begin{Operator}{unbrwhen}
  243. \index{break}\index{debug}
  244. Conditional break is removed for a procedure by calling
  245. \begin{Syntax}
  246. unbrwhen \meta{name};
  247. \end{Syntax}
  248. \end{Operator}
  249. % ==============================================================
  250. \begin{Operator}{trrl}
  251. \index{debug}\index{rule}\index{ruleset}
  252. The command \name{trrl} allows you to trace individual rules
  253. or rule sets when they fire.
  254. \begin{Syntax}
  255. trrl \meta{rs1},\meta{rs2},...,\meta{rsn};
  256. \end{Syntax}
  257. where each of the \meta{rsi} is
  258. - a rule or a rule set,
  259. - a name of a rule or rule set (that is a non--indexed variable which
  260. is bound to a rule or rule list),
  261. - an operator name, representing the rules assigned to this
  262. operator.
  263. The specified rules are (re-) activated in REDUCE in
  264. a style that each of them prints a report every time if fires.
  265. The report is composed of the name or the rule or the
  266. name of the rule set plus the number of the rule in the set,
  267. the form matching the left hand side and the
  268. resulting right hand side.
  269. For an explicitly given rule, \name{trrl} assigns a generated name.
  270. \end{Operator}
  271. \begin{Operator}{untrrl}
  272. \index{debug}\index{rule}\index{ruleset}
  273. With \name{untrrl} you can remove the tracing from rules
  274. \begin{Syntax}
  275. untrrl \meta{rs1},\meta{rs2},...,\meta{rsn};
  276. \end{Syntax}
  277. The rules are reactivated in their original form. Alternatively
  278. you can use the command \nameref{clearrules} to remove the
  279. rules totally from the system. Please do not modify the
  280. rules between \name{trrl} and \name{untrrl} -- the result
  281. may be unpredictable.
  282. \end{Operator}
  283. %==============================================================
  284. \begin{Operator}{trout}
  285. \index{debug}\index{io}
  286. The trace output can be redirected to a separate file
  287. by using the command \name{trout}, followed
  288. by a file name in string quotes. A second call of \name{trout}
  289. closes the actual output file and assigns a new one.
  290. The file name NIL (without string quotes) causes the trace output
  291. to be redirected to the standard output device.
  292. Remark: under Windows a file name starting with "win:" causes
  293. a new window to be opened which receives the complete
  294. output of the debugging services.
  295. \end{Operator}
  296. %==============================================================
  297. \begin{Variable}{trlimit}
  298. \index{debug}\index{io}
  299. The integer valued share variable \name{trlimit} defines
  300. an upper limit for the number of items printed in formula
  301. collections. The
  302. initial value is 5. A different value can be assigned to
  303. increase or lower the output size.
  304. \begin{Examples}
  305. trlimit:=7;\\
  306. \end{Examples}
  307. \end{Variable}
  308. %==============================================================
  309. \begin{Variable}{trprinter}
  310. \index{debug}\index{io}
  311. If you want to select LISP style printing instead of
  312. algebraic printing during trace, set \name{trprinter!*}
  313. to \name{printx}:
  314. \begin{Syntax}
  315. lisp(trprinter!* := 'printx);
  316. \end{syntax}
  317. \end{Variable}