Pristine Ack-5.5
[Ack-5.5.git] / util / grind / grind.1
1 .\" $Id: grind.1,v 1.8 1994/06/24 10:59:57 ceriel Exp $
2 .TH GRIND 1 "$Revision: 1.8 $"
3 .SH NAME
4 grind \- source-level debugger for ACK
5 .SH SYNOPSIS
6 .B grind
7 [ <ACK object file> ] [ <object file> ]
8 .SH DESCRIPTION
9 .B Grind
10 is a utility for source-level debugging and execution of
11 programs written in C, Modula-2, or Pascal.
12 Its operation resembles the operation of 
13 .IR dbx ,
14 a source-level debugger
15 available on many Unix systems. However, some
16 .B grind
17 commands are not available in
18 .IR dbx ,
19 some
20 .I dbx
21 commands are not available in
22 .BR grind ,
23 and some things are just different.
24 .LP
25 .I <object file>
26 is an object file, produced by
27 .IR ack (1)
28 with the
29 .B \-g
30 option to include a symbol table.
31 .LP
32 If no
33 .I <object file>
34 is specified, "a.out" is used.
35 .LP
36 For some machines, the debugger does not recognize the object file
37 format. For these machines, the result of the
38 .IR led (6)
39 program must be saved and offered to
40 .BR grind ,
41 for instance:
42 .DS
43 m68020 -c.out -g blabla.c
44 m68020 blabla.out
45 grind blabla.out a.out
46 .DE
47 .SH USAGE
48 Some
49 .B grind
50 commands take an expression argument.
51 .SS Expressions
52 .B Grind
53 expressions are combinations of variables, constants, and operators.
54 The syntax and the operators depend on the source language of the program
55 being debugged. However, the type rules are probably less strict than the
56 rules of this language. For instance, in Modula-2 one cannot combine
57 values of type INTEGER with values of type REAL in an expression without
58 using conversion routines. In
59 .BR grind ,
60 the conversions needed are performed automatically.
61 .LP
62 Expressions whose value is to be printed can be given a "format" by appending
63 a `\e', followed by a format. A format consists of a string of letters.
64 The following letters are available:
65 .LP
66 .nf
67 c       print all integer values as a char
68 d       print all integer values in signed decimal format
69 o       print all integer values in octal format
70 x       print all integer values in hexadecimal format
71 h       print all integer values in hexadecimal format
72 u       print all integer values in unsigned decimal format
73 s       for "pointer to char" types, make an attempt to print
74         the indicated string
75 .fi
76 .SS Operators
77 .LP
78 .B Grind
79 supports operators for addition, subtraction, multiplication, division,
80 remainder, bitwise or, bitwise xor, bitwise and, boolean or,
81 boolean and, left-shift, right-shift, address-of, dereference, less than,
82 less than or equal, equal, not equal, greater than, greater than or equal,
83 selection, array subscripting.
84 .LP
85 The syntax and priority of these operators depends on the source language.
86 Parentheses can be used for grouping.
87 .SS "Scope Rules"
88 .LP
89 .B Grind
90 uses the current file and function to resolve scope conflicts.
91 Their values are updated as files and functions are entered and exited
92 during execution.
93 Names can also be qualified with procedure- or module names, as in
94 \fImodule\fP`\fIprocedure\fP`\fIname\fP.
95 .B Grind
96 tries to be intelligent about names; qualification is only needed when
97 names are used for more than one object in a program and the current scope
98 does not help.
99 .SS "Positions"
100 In general, there are two ways to specify a position; the first way is
101 to specify file name and line number, in a so-called at-clause, like this:
102 .RS
103 \fBat\fP [ "\fIfilename\fP": ] \fIlinenumber\fP
104 .RE
105 The
106 .I filename
107 part is optional.
108 The second way is to specify a function name, like this:
109 .RS
110 \fBin \fIfunction\fP
111 .RE
112 This indicates the first statement within the named function (except for
113 the trace command discussed later).
114 The following way is also accepted:
115 .RS
116 \fBin\fP \fIfunction\fP \fBat\fP [ "\fIfilename\fP": ] \fIlinenumber\fP
117 .RE
118 In this case, consistency of the information given is checked. This last
119 form is useful for "stuffing" output from the status command described later.
120 .SS "Command numbers"
121 .LP
122 Some command numbers have a command number associated with them. Other commands
123 refer to these command numbers. These command numbers can either be given as
124 an absolute number, or as a negative number. In the last case, the number
125 is interpreted relative to the last number assigned. This feature is normally
126 only used for commands that are put in a log file, so that "sourceing" these
127 log files is safer (see also the description of the \fBsource\fP and \fBlog\fP
128 commands).
129
130 .SS "Commands"
131 .TP
132 .B ^C
133 Interrupt.  Stop the program being debugged and enter
134 .BR grind .
135 .TP
136 \fBrun\fP [ \fIargs\fP ] [ < \fIinfile\fP ] [ > \fIoutfile\fP ]
137 Start executing
138 .I <object file>
139 with command line arguments
140 .IR args ,
141 and possible redirection of standard input and/or standard output.
142 .TP
143 .B rerun
144 Repeats the last
145 .B run
146 command.
147 .TP
148 .B "rerun ?"
149 Prints the last 
150 .B run
151 command.
152 .TP
153 \fBcont\fP [ \fIcount\fP ] [ \fBat\fP \fIsourceline\fP ]
154 .ti -0.5i
155 \fBc\fP [ \fIcount\fP ] [ \fBat\fP \fIsourceline\fP ]
156 .br
157 Continue execution from where it stopped, or, if \fIsourceline\fP is
158 given, at that source line. If \fIcount\fP is given, pass \fIcount\fP-1
159 breakpoints. \fIsourceline\fP must be in the same function.
160 .TP
161 \fBtrace\fP [ \fBon\fP \fIexpression\fP ] [ \fIposition\fP ] [ \fBif\fP \fIcondition\fP ]
162 .ti -0.5i
163 \fBt\fP [ \fBon\fP \fIexpression\fP ] [ \fIposition\fP ] [ \fBif\fP \fIcondition\fP ]
164 .br
165 Display tracing information.
166 If no argument is specified, each source line is displayed before
167 execution.
168 In addition, if an \fBon\fP-clause is given, the value of the expression
169 is printed.
170 If a position is given there are two possibilities: if the position is
171 given as \fBin\fP \fIfunction\fP, then the tracing information is
172 displayed only while executing the function or
173 procedure
174 .IR function .
175 If the position is given as \fBat\fP \fIlinenumber\fP,
176 then the tracing information is displayed only whenever the source line
177 indicated is reached.
178 If the position is given as \fBat\fP \fIlinenumber\fP \fBin\fP \fIfunction\fP,
179 the behavior is as if it was given as \fBat\fP \fIlinenumber\fP.
180 If a condition is given, tracing information is only displayed when
181 .I condition
182 is true.
183 .TP
184 \fBstop\fP [ \fIposition\fP ] [ \fBif\fP \fIcondition\fP ]
185 Stop execution when the
186 .I position
187 is reached, and then when
188 .I condition
189 becomes true.
190 If no position is given, stop when
191 .I condition
192 becomes true.
193 If no condition is given, stop when
194 .I position
195 is reached.
196 Either a position or a condition (or both) must be given.
197 .TP
198 \fBwhen\fP [ \fIposition\fP ] [ \fBif\fP \fIcondition\fP ] { \fIcommand\fP [ ; \fIcommand\fP ] ... }
199 Execute the
200 .B grind
201 .IR command (s)
202 when the
203 .I position
204 is reached, and then when
205 .I condition
206 becomes true.
207 If no position is given, do this when
208 .I condition
209 becomes true.
210 If no condition is given, do this when
211 .I position
212 is reached.
213 Either a position or a condition (or both) must be given.
214 .TP
215 \fBprint\fP [ \fIexpression\fP [ , \fIexpression\fP ] ... ]
216 .ti -0.5i
217 \fBp\fP [ \fIexpression\fP [ , \fIexpression\fP ] ... ]
218 .br
219 Print the value of each expression. If no argument is given, repeat the
220 last
221 .B print
222 command.
223 .TP
224 \fBdisplay\fP \fIexpression\fP [ , \fIexpression\fP ] ...
225 Print the value of each expression whenever the program stops.
226 .TP
227 .B dump
228 Saves the data (global data + stack) of the program. These data can
229 be restore with the
230 .B restore
231 command discussed later.
232 .B Dump
233 and
234 .B restore
235 combinations can be used as a poor man's implementation of an "undo"
236 facility.
237 .TP
238 .B status
239 Display active
240 .BR trace ,
241 .BR stop ,
242 .BR when ,
243 and
244 .B display
245 commands, and associated command numbers.
246 Also display current
247 .B dump
248 records.
249 .TP
250 \fBdelete\fP [ \fIcommandnumber\fP [ , \fIcommandnumber\fP ... ] ]
251 .ti -0.5i
252 \fBd\fP [ \fIcommandnumber\fP [ , \fIcommandnumber\fP ... ] ]
253 .br
254 Remove the commands corresponding to the \fIcommandnumber\fP's given
255 (as displayed by
256 .BR status ).
257 If no argument is given and there is a "current" breakpoint, remove that
258 breakpoint.
259 .TP
260 \fBrestore\fP [ \fIcommandnumber\fP ]
261 .ti -0.5i
262 \fBr\fP [ \fIcommandnumber\fP ]
263 .br
264 Restore the data corresponding to the dump of \fIcommandnumber\fP
265 (as displayed by
266 .BR status ).
267 This restores the values of all variables of the program to the values
268 at the time the dump was made. The program counter is also restored.
269 This effectively puts the program back into the state it was when the
270 dump was made, except for file-handling: the state of the files that
271 the program handles is not changed.
272 Apart from this,
273 .B restore
274 even works when the program is finished.
275 If no \fIcommandnumber\fP is given, the last dump is restored.
276 .TP
277 \fBstep\fP [ \fIn\fP ]
278 .ti -0.5i
279 \fBs\fP [ \fIn\fP ]
280 .br
281 Execute the next
282 .I n
283 source lines.
284 If omitted,
285 .I n
286 is taken to be 1.
287 This command steps into functions.
288 .TP
289 \fBnext\fP [ \fIn\fP ]
290 .ti -0.5i
291 \fBn\fP [ \fIn\fP ]
292 .br
293 Execute the next
294 .I n
295 source lines.
296 If omitted,
297 .I n
298 is taken to be 1.
299 .B Next
300 steps past function-calls.
301 .TP
302 \fBwhich\fP \fIname\fP
303 Print the fully-qualified name of the given name.
304 .TP
305 \fBfind\fP \fIname\fP
306 Print the fully qualified name of all symbols matching
307 .IR name .
308 .TP
309 \fBset\fP \fIexpression\fP \fBto\fP \fIexpression\fP
310 Assign the value of the second
311 .I expression
312 to the designator indicated by the first
313 .IR expression .
314 Needless to say, the first
315 .I expression
316 must indicate a designator (something that can be assigned to).
317 If the types do not match,
318 .B grind
319 tries to apply conversions.
320 .TP
321 \fBwhere\fP [ \fIn\fP | -\fIn\fP ]
322 .ti -0.5i
323 \fBw\fP [ \fIn\fP | -\fIn\fP ]
324 .br
325 List all, or the top
326 .IR n ,
327 or the bottom
328 .IR n ,
329 active functions on the stack.
330 .TP
331 \fBfile\fP [ \fIfilename\fP ]
332 Print the name of the current source file, or
333 change the current source file to
334 .IR filename .
335 .TP
336 \fBlist\fP [ \fIstartline\fP | \fIfunction\fP ] [ , \fIcount\fP | - [ \fIendline\fP ] ]
337 .ti -0.5i
338 \fBl\fP [ \fIstartline\fP | \fIfunction\fP ] [ , \fIcount\fP | - [ \fIendline\fP ] ]
339 .br
340 If no arguments are given, list the next \fIws\fP (default 10) lines from current source file,
341 if a
342 .I startline
343 is given, list from
344 .IR startline ,
345 if a
346 .I function
347 is given, list from the first statement of
348 .IR function .
349 If a \fIcount\fP is given, list \fIcount\fP lines and set \fIws\fP to \fIcount\fP.
350 If an \fIendline\fP is given, list up until this line; if a - is given without
351 an \fIendline\fP, list up until the end of the file.
352 .TP
353 \fBhelp\fP [ \fIcommand\fP ]
354 .ti -0.5i
355 \fB?\fP [ \fIcommand\fP ]
356 .br
357 Print a summary of \fBgrind\fP commands, or print a message explaining
358 \fIcommand\fP.
359 .TP
360 \fBsource\fP \fIfilename\fP
361 .br
362 Read and execute \fBgrind\fP commands from \fIfilename\fP. This is useful for
363 executing \fBgrind\fP log files created with the \fBlog\fP command.
364 .TP
365 \fBlog\fP [ \fIfilename\fP | off ]
366 .br
367 Start logging the \fBgrind\fP commands given on file \fIfilename\fP, or
368 stop logging. If no argument is given, the current log file is printed.
369 In logged commands, an absolute command number is replaced by a relative one.
370 .TP
371 \fBdisable\fP [ \fIcommandnumber\fP [ , \fIcommandnumber\fP ... ] ]
372 .br
373 Disable the commands corresponding to the \fIcommandnumber\fP's given
374 (as displayed by
375 .BR status ).
376 If no argument is given and there is a "current" breakpoint, disable that
377 breakpoint.
378 Disabling commands keeps them in the status, but makes them inoperative.
379 Disabled commands can be enabled again with the \fBenable\fP command.
380 .TP
381 \fBenable\fP [ \fIcommandnumber\fP [ , \fIcommandnumber\fP ... ] ]
382 .br
383 Enable the commands corresponding to the \fIcommandnumber\fP's given
384 (as displayed by
385 .BR status ).
386 If no argument is given and there is a "current" breakpoint, enable that
387 breakpoint.
388 .TP
389 \fB!\fP \fIshellcommand\fP
390 .br
391 Invoke the shell with \fIshellcommand\fP. \fIshellcommand\fP extends to the
392 end of the line. In the command, the characters `%' and `!' are replaced
393 with the current file name and the previous shell command respectively.
394 The sequences `\e%' and `\e!' are replaced by `%' and `!' respectively.
395 .TP
396 \fBframe\fP [ \fIcount\fP | + \fIcount\fP | - \fIcount\fP ]
397 .br
398 The currently active procedure has frame number 0, the one that invoked this
399 one has frame number 1, etc. The \fBframe\fP command allows the user to
400 examine stack frames beyond the current one. For instance, after giving the
401 command `frame 1', variables of the frame invoking the currently active
402 procedure can be examined. There is a relative and an absolute version of this
403 command.
404 .TP
405 .B quit
406 .br
407 Exit
408 .BR grind .
409 .LP
410 Some commands can be repeated without arguments by entering an empty command line:
411 step, next, list, cont.
412 .SH SEE ALSO
413 .IR ack (1).
414 .IR led (6).
415 .SH REMARKS
416 .LP
417 .B Grind
418 does not understand the scope of WITH statements. The scope information needed
419 is not available in the symbol table.
420 .SH BUGS
421 .LP
422 .B Grind
423 does not correctly handle bit-fields.