]> git.lizzy.rs Git - plan9front.git/blob - sys/doc/acid.ms
added /sys/doc
[plan9front.git] / sys / doc / acid.ms
1 .HTML "Acid Manual
2 .am DS
3 .ft I
4 ..
5 .ta 1i 2.3i 4.5i  (optional to set tabs)
6 .TL
7 Acid Manual
8 .AU
9 Phil Winterbottom
10 philw@plan9.bell-labs.com
11 .SH
12 Introduction
13 .PP
14 Acid is a general purpose, source level symbolic debugger.
15 The debugger is built around a simple command language. 
16 The command language, distinct from the language of the program being debugged,
17 provides a flexible user interface that allows the debugger
18 interface to be customized for a specific application or architecture.
19 Moreover, it provides an opportunity to write test and
20 verification code independently of a program's source code.
21 Acid is able to debug multiple
22 processes provided they share a common set of symbols, such as the processes in
23 a threaded program.
24 .PP
25 Like other language-based solutions, Acid presents a poor user interface but
26 provides a powerful debugging tool.
27 Application of Acid to hard problems is best approached by writing functions off-line
28 (perhaps loading them with the
29 .CW include
30 function or using the support provided by
31 .I acme (1)),
32 rather than by trying to type intricate Acid operations
33 at the interactive prompt.
34 .PP
35 Acid allows the execution of a program to be controlled by operating on its
36 state while it is stopped and by monitoring and controlling its execution
37 when it is running. Each program action that causes a change 
38 of execution state is reflected by the execution
39 of an Acid function, which may be user defined.
40 A library of default functions provides the functionality of a normal debugger.
41 .PP
42 A Plan 9 process is controlled by writing messages to a control file in the
43 .I proc (3)
44 file system. Each control message has a corresponding Acid function, which
45 sends the message to the process. These functions take a process id
46 .I pid ) (
47 as an
48 argument. The memory and text file of the program may be manipulated using
49 the indirection operators. The symbol table, including source cross reference,
50 is available to an Acid program. The combination allows complex operations
51 to be performed both in terms of control flow and data manipulation.
52 .SH
53 Input format and \f(CWwhatis\fP
54 .PP
55 Comments start with
56 .CW //
57 and continue to the end of the line.
58 Input is a series of statements and expressions separated by semicolons.
59 At the top level of the interpreter, the builtin function
60 .CW print
61 is called automatically to display the result of all expressions except function calls.
62 A unary
63 .CW +
64 may be used as a shorthand to force the result of a function call to be printed.
65 .PP
66 Also at the top level, newlines are treated as semicolons
67 by the parser, so semicolons are unnecessary when evaluating expressions.
68 .PP
69 When Acid starts, it loads the default program modules,
70 enters interactive mode, and prints a prompt. In this state Acid accepts
71 either function definitions or statements to be evaluated.
72 In this interactive mode
73 statements are evaluated immediately, while function definitions are
74 stored for later invocation.
75 .PP
76 The
77 .CW whatis
78 operator can be used to report the state of identifiers known to the interpreter.
79 With no argument,
80 .CW whatis
81 reports the name of all defined Acid functions; when supplied with an identifier
82 as an argument it reports any variable, function, or type definition
83 associated with the identifier.
84 Because of the way the interpreter handles semicolons,
85 the result of a
86 .CW whatis
87 statement can be returned directly to Acid without adding semicolons.
88 A syntax error or interrupt returns Acid to the normal evaluation
89 mode; any partially evaluated definitions are lost.
90 .SH
91 Using the Library Functions
92 .PP
93 After loading the program binary, Acid loads the portable and architecture-specific
94 library functions  that form the standard debugging environment.
95 These files are Acid source code and are human-readable.
96 The following example uses the standard debugging library to show how
97 language and program interact:
98 .P1
99 % acid /bin/ls
100 /bin/ls:mips plan 9 executable
101
102 /sys/lib/acid/port
103 /sys/lib/acid/mips
104 acid: new()
105 75721: system call  _main ADD  $-0x14,R29
106 75721: breakpoint   main+0x4   MOVW  R31,0x0(R29)
107 acid: bpset(ls)
108 acid: cont()
109 75721: breakpoint   ls    ADD  $-0x16c8,R29
110 acid: stk()
111 At pc:0x0000141c:ls /sys/src/cmd/ls.c:87
112 ls(s=0x0000004d,multi=0x00000000) /sys/src/cmd/ls.c:87
113     called from main+0xf4 /sys/src/cmd/ls.c:79
114 main(argc=0x00000000,argv=0x7ffffff0) /sys/src/cmd/ls.c:48
115     called from _main+0x20 /sys/src/libc/mips/main9.s:10
116 acid: PC
117 0xc0000f60
118 acid: *PC
119 0x0000141c
120 acid: ls
121 0x0000141c
122 .P2
123 The function
124 .CW new()
125 creates a new process and stops it at the first instruction.
126 This change in state is reported by a call to the
127 Acid function
128 .CW stopped ,
129 which is called by the interpreter whenever the debugged program stops.
130 .CW Stopped
131 prints the status line giving the pid, the reason the program stopped
132 and the address and instruction at the current PC.
133 The function
134 .CW bpset
135 makes an entry in the breakpoint table and plants a breakpoint in memory.
136 The
137 .CW cont
138 function continues the process, allowing it to run until some condition
139 causes it to stop. In this case the program hits the breakpoint placed on
140 the function
141 .CW ls
142 in the C program. Once again the
143 .CW stopped
144 routine is called to print the status of the program. The function
145 .CW stk
146 prints a C stack trace of the current process. It is implemented using
147 a builtin Acid function that returns the stack trace as a list; the code
148 that formats the information is all written in Acid. 
149 The Acid variable
150 .CW PC
151 holds the address of the 
152 cell where the current value of the processor register
153 .CW PC
154 is stored. By indirecting through
155 the value of
156 .CW PC
157 the address where the program is stopped can be found.
158 All of the processor registers are available by the same mechanism.
159 .SH
160 Types
161 .PP
162 An Acid variable has one of four types:
163 .I integer ,
164 .I float ,
165 .I list ,
166 or
167 .I string .
168 The type of a variable is inferred from the type of the right-hand
169 side of the assignment expression which last set its value.
170 Referencing a variable that has not yet
171 been assigned draws a "used but not set" error. Many of the operators may
172 be applied to more than
173 one type; for these operators the action of the operator is determined by
174 the types of its operands. The action of each operator is defined in the
175 .I Expressions
176 section of this manual.
177 .SH
178 Variables
179 .PP
180 Acid has three kinds of variables: variables defined by the symbol table
181 of the debugged program, variables that are defined and maintained
182 by the interpreter as the debugged program changes state, and variables
183 defined and used by Acid programs.
184 .PP
185 Some examples of variables maintained by the interpreter are the register
186 pointers listed by name in the Acid list variable
187 .CW registers ,
188 and the symbol table listed by name and contents in the Acid variable
189 .CW symbols .
190 .PP
191 The variable
192 .CW pid
193 is updated by the interpreter to select the most recently created process
194 or the process selected by the
195 .CW setproc
196 builtin function.
197 .SH 1
198 Formats
199 .PP
200 In addition to a type, variables have formats. The format is a code
201 letter that determines the printing style and the effect of some of the
202 operators on that variable. The format codes are derived from the format
203 letters used by
204 .I db (1).
205 By default, symbol table variables and numeric constants
206 are assigned the format code
207 .CW X ,
208 which specifies 32-bit hexadecimal.
209 Printing a variable with this code yields the output
210 .CW 0x00123456 .
211 The format code of a variable may be changed from the default by using the 
212 builtin function
213 .CW fmt .
214 This function takes two arguments, an expression and a format code. After
215 the expression is evaluated the new format code is attached to the result
216 and forms the return value from
217 .CW fmt .
218 The backslash operator is a short form of
219 .CW fmt .
220 The format supplied by the backslash operator must be the format character
221 rather than an expression.
222 If the result is assigned to a variable the new format code is maintained
223 in the variable. For example:
224 .P1
225 acid: x=10
226 acid: print(x)
227 0x0000000a 
228 acid: x = fmt(x, 'D')
229 acid: print(x, fmt(x, 'X'))
230 10 0x0000000a
231 acid: x
232 10
233 acid: x\eo
234 12
235 .P2
236 The supported format characters are:
237 .RS
238 .IP \f(CWo\fP
239 Print two-byte integer in octal.
240 .IP \f(CWO\fP
241 Print four-byte integer in octal.
242 .IP \f(CWq\fP
243 Print two-byte integer in signed octal.
244 .IP \f(CWQ\fP
245 Print four-byte integer in signed octal.
246 .IP \f(CWB\fP
247 Print four-byte integer in binary.
248 .IP \f(CWd\fP
249 Print two-byte integer in signed decimal.
250 .IP \f(CWD\fP
251 Print four-byte integer in signed decimal.
252 .IP \f(CWV\fP
253 Print eight-byte integer in signed decimal.
254 .IP \f(CWZ\fP
255 Print eight-byte integer in unsigned decimal.
256 .IP \f(CWx\fP
257 Print two-byte integer in hexadecimal.
258 .IP \f(CWX\fP
259 Print four-byte integer in hexadecimal.
260 .IP \f(CWY\fP
261 Print eight-byte integer in hexadecimal.
262 .IP \f(CWu\fP
263 Print two-byte integer in unsigned decimal.
264 .IP \f(CWU\fP
265 Print four-byte integer in unsigned decimal.
266 .IP \f(CWf\fP
267 Print single-precision floating point number.
268 .IP \f(CWF\fP
269 Print double-precision floating point number.
270 .IP \f(CWg\fP
271 Print a single precision floating point number in string format.
272 .IP \f(CWG\fP
273 Print a double precision floating point number in string format.
274 .IP \f(CWb\fP
275 Print byte in hexadecimal.
276 .IP \f(CWc\fP
277 Print byte as an ASCII character.
278 .IP \f(CWC\fP
279 Like
280 .CW c ,
281 with
282 printable ASCII characters represented normally and
283 others printed in the form \f(CW\ex\fInn\fR.
284 .IP \f(CWs\fP
285 Interpret the addressed bytes as UTF characters
286 and print successive characters until a zero byte is reached.
287 .IP \f(CWr\fP
288 Print a two-byte integer as a rune.
289 .IP \f(CWR\fP
290 Print successive two-byte integers as runes
291 until a zero rune is reached.
292 .IP \f(CWi\fP
293 Print as machine instructions.
294 .IP \f(CWI\fP
295 As
296 .CW i
297 above, but print the machine instructions in
298 an alternate form if possible:
299 .CW sunsparc
300 and
301 .CW mipsco
302 reproduce the manufacturers' syntax.
303 .IP \f(CWa\fP
304 Print the value in symbolic form.
305 .RE
306 .SH
307 Complex types
308 .PP
309 Acid permits the definition of the layout of memory.
310 The usual method is to use the
311 .CW -a
312 flag of the compilers to produce Acid-language descriptions of data structures (see
313 .I 2c (1))
314 although such definitions can be typed interactively.
315 The keywords
316 .CW complex ,
317 .CW adt ,
318 .CW aggr ,
319 and
320 .CW union
321 are all equivalent; the compiler uses the synonyms to document the declarations.
322 A complex type is described as a set of members, each containing a format letter,
323 an offset in the structure, and a name.  For example, the C structure
324 .P1
325 struct List {
326         int         type;
327         struct List *next;
328 };
329 .P2
330 is described by the Acid statement
331 .P1
332 complex List {
333         'D'     0       type;
334         'X'     4       next;
335 };
336 .P2
337 .SH
338 Scope
339 .PP
340 Variables are global unless they are either parameters to functions
341 or are declared as
342 .CW local
343 in a function body. Parameters and local variables are available only in
344 the body of the function in which they are instantiated.
345 Variables are dynamically bound: if a function declares a local variable
346 with the same name as a global variable, the global variable will be hidden
347 whenever the function is executing.
348 For example, if a function
349 .CW f
350 has a local called
351 .CW main ,
352 any function called below
353 .CW f
354 will see the local version of
355 .CW main ,
356 not the external symbol.
357 .SH 1
358 Addressing
359 .PP
360 Since the symbol table specifies addresses,
361 to access the value of program variables
362 an extra level of indirection
363 is required relative to the source code.
364 For consistency, the registers are maintained as pointers as well; Acid variables with the names
365 of processor registers point to cells holding the saved registers.
366 .PP
367 The location in a file or memory image associated with
368 an address is calculated from a map
369 associated with the file.
370 Each map contains one or more quadruples (\c
371 .I t ,
372 .I b ,
373 .I e ,
374 .I f \|),
375 defining a segment named
376 .I t
377 (usually 
378 .CW text ,
379 .CW data ,
380 .CW regs ,
381 or
382 .CW fpregs )
383 mapping addresses in the range
384 .I b
385 through
386 .I e
387 to the part of the file
388 beginning at
389 offset
390 .I f .
391 The memory model of a Plan 9 process assumes
392 that segments are disjoint.  There
393 can be more than one segment of a given type (e.g., a process
394 may have more than one text segment) but segments
395 may not overlap.
396 An address
397 .I a
398 is translated
399 to a file address
400 by finding a segment
401 for which
402 .I b
403 +
404 .I a
405 <
406 .I e ;
407 the location in the file
408 is then
409 .I address
410 +
411 .I f
412 \-
413 .I b .
414 .PP
415 Usually,
416 the text and initialized data of a program
417 are mapped by segments called 
418 .CW text
419 and
420 .CW data .
421 Since a program file does not contain bss, stack, or register data,
422 these data are
423 not mapped by the data segment.
424 The text segment is mapped similarly in the memory image of
425 a normal (i.e., non-kernel) process.
426 However, the segment called 
427 .CW *data
428 maps memory from the beginning to the end of the program's data space.
429 This region contains the program's static data, the bss, the
430 heap and the stack.  A segment
431 called
432 .CW *regs
433 maps the registers;
434 .CW *fpregs
435 maps the floating point registers.
436 .PP
437 Sometimes it is useful to define a map with a single segment
438 mapping the region from 0 to 0xFFFFFFFF; such a map
439 allows the entire file to be examined
440 without address translation.  The builtin function
441 .CW map
442 examines and modifies Acid's map for a process.
443 .SH 1
444 Name Conflicts
445 .PP
446 Name conflicts between keywords in the Acid language, symbols in the program,
447 and previously defined functions are resolved when the interpreter starts up.
448 Each name is made unique by prefixing enough
449 .CW $
450 characters to the front of the name to make it unique. Acid reports
451 a list of each name change at startup. The report looks like this:
452 .P1
453 /bin/sam: mips plan 9 executable
454 /lib/acid/port
455 /lib/acid/mips
456 Symbol renames:
457         append=$append T/0xa4e40
458 acid:
459 .P2
460 The symbol
461 .CW append
462 is both a keyword and a text symbol in the program. The message reports
463 that the text symbol is now named
464 .CW $append .
465 .SH
466 Expressions
467 .PP
468 Operators have the same
469 binding and precedence as in C.
470 For operators of equal precedence, expressions are evaluated from left to right. 
471 .SH 1
472 Boolean expressions
473 .PP
474 If an expression is evaluated for a boolean condition the test
475 performed depends on the type of the result. If the result is of
476 .I integer
477 or
478 .I floating
479 type the result is true if the value is non-zero. If the expression is a
480 .I list
481 the result is true if there are any members in the list.
482 If the expression is a
483 .I string
484 the result is true if there are any characters in the string.
485 .DS
486         primary-expression:
487                 identifier
488                 identifier \f(CW:\fP identifier
489                 constant
490                 \f(CW(\fP expression \f(CW)\fP
491                 \f(CW{\fP elist \f(CW}\fP
492
493         elist:
494                 expression
495                 elist , expression
496 .DE
497 An identifier may be any legal Acid variable. The colon operator returns the
498 address of parameters or local variables in the current stack of a program.
499 For example:
500 .P1
501 *main:argc
502 .P2
503 prints the number of arguments passed into main. Local variables and parameters
504 can only be referenced after the frame has been established. It may be necessary to
505 step a program over the first few instructions of a breakpointed function to properly set
506 the frame.
507 .PP
508 Constants follow the same lexical rules as C.
509 A list of expressions delimited by braces forms a list constructor.
510 A new list is produced by evaluating each expression when the constructor is executed.
511 The empty list is formed from
512 .CW {} .
513 .P1
514 acid: x = 10
515 acid: l = { 1, x, 2\eD }
516 acid: x = 20
517 acid: l
518 {0x00000001 , 0x0000000a , 2 }
519 .P2
520 .SH 1
521 Lists
522 .PP
523 Several operators manipulate lists.
524 .DS
525         list-expression:
526                 primary-expression
527                 \f(CWhead\fP primary-expression
528                 \f(CWtail\fP primary-expression
529                 \f(CWappend\fP expression \f(CW,\fP primary-expression
530                 \f(CWdelete\fP expression \f(CW,\fP primary-expression
531 .DE
532 The
533 .I primary-expression
534 for
535 .CW head
536 and
537 .CW tail
538 must yield a value of type
539 .I list .
540 If there are no elements in the list the value of
541 .CW head
542 or
543 .CW tail
544 will be the empty list. Otherwise
545 .CW head
546 evaluates to the first element of the list and
547 .CW tail
548 evaluates to the rest.
549 .P1
550 acid: head {}
551 {}
552 acid: head {1, 2, 3, 4}
553 0x00000001 
554 acid: tail {1, 2, 3, 4}
555 {0x00000002 , 0x00000003 , 0x00000004 }
556 .P2
557 The first operand of
558 .CW append 
559 and
560 .CW delete
561 must be an expression that yields a
562 .I list .
563 .CW Append
564 places the result of evaluating
565 .I primary-expression
566 at the end of the list.
567 The
568 .I primary-expression
569 supplied to
570 .CW delete
571 must evaluate to an integer;
572 .CW delete
573 removes the 
574 .I n 'th
575 item from the list, where
576 .I n
577 is integral value of
578 .I primary-expression.
579 List indices are zero-based.
580 .P1
581         acid: append {1, 2}, 3
582         {0x00000001 , 0x00000002 , 0x00000003 }
583         acid: delete {1, 2, 3}, 1
584         {0x00000001 , 0x00000003 }
585 .P2
586 .PP
587 Assigning a list to a variable copies a reference to the list; if a list variable
588 is copied it still points at the same list.  To copy a list, the elements must
589 be copied piecewise using
590 .CW head
591 and
592 .CW append .
593 .SH 1
594 Operators
595 .PP
596 .DS
597         postfix-expression:
598                 list-expression
599                 postfix-expression \f(CW[\fP expression \f(CW]\fP
600                 postfix-expression \f(CW(\fP argument-list \f(CW)\fP
601                 postfix-expression \f(CW.\fP tag
602                 postfix-expression \f(CW->\fP tag 
603                 postfix-expression \f(CW++\fP
604                 postfix-expression \f(CW--\fP
605
606         argument-list:
607                 expression
608                 argument-list , expression
609 .DE
610 The
611 .CW [
612 .I expression
613 .CW ]
614 operator performs indexing.
615 The indexing expression must result in an expression of
616 .I integer
617 type, say
618 .I n .
619 The operation depends on the type of
620 .I postfix-expression .
621 If the
622 .I postfix-expression
623 yields an
624 .I integer
625 it is assumed to be the base address of an array in the memory image.
626 The index offsets into this array; the size of the array members is
627 determined by the format associated with the
628 .I postfix-expression .
629 If the 
630 .I postfix-expression
631 yields a
632 .I string
633 the index operator fetches the
634 .I n 'th
635 character
636 of the string. If the index points beyond the end
637 of the string, a zero is returned.
638 If the
639 .I postfix-expression
640 yields a
641 .I list
642 then the indexing operation returns the
643 .I n 'th
644 item of the list.
645 If the list contains less than
646 .I n
647 items the empty list
648 .CW {}
649 is returned.
650 .PP
651 The
652 .CW ++
653 and
654 .CW --
655 operators increment and decrement integer variables.
656 The amount of increment or decrement depends on the format code. These postfix
657 operators return the value of the variable before the increment or decrement
658 has taken place.
659 .DS
660         unary-expression:
661                 postfix-expression
662                 \f(CW++\fP unary-expression
663                 \f(CW--\fP unary-expression
664
665         unary-operator: one of
666                 \f(CW*\fP \f(CW@\fP \f(CW+\fP \f(CW-\fP ~ \f(CW!\fP
667 .DE
668 The operators
669 .CW *
670 and
671 .CW @
672 are the indirection operators.
673 .CW @
674 references a value from the text file of the program being debugged.
675 The size of the value depends on the format code. The
676 .CW *
677 operator fetches a value from the memory image of a process. If either
678 operator appears on the left-hand side of an assignment statement, either the file
679 or memory will be written. The file can only be modified when Acid is invoked
680 with the
681 .CW -w
682 option.
683 The prefix
684 .CW ++
685 and
686 .CW --
687 operators perform the same operation as their postfix counterparts but
688 return the value after the increment or decrement has been performed. Since the
689 .CW ++
690 and
691 .CW *
692 operators fetch and increment the correct amount for the specified format,
693 the following function prints correct machine instructions on a machine with
694 variable length instructions, such as the 68020 or 386:
695 .P1
696         defn asm(addr)
697         {
698                 addr = fmt(addr, 'i');
699                 loop 1, 10 do
700                         print(*addr++, "\en");
701         }
702 .P2
703 The operators
704 .CW ~
705 and
706 .CW !
707 perform bitwise and logical negation respectively. Their operands must be of
708 .I integer
709 type.
710 .DS
711         cast-expression:
712                 unary-expression
713                 unary-expression \f(CW\e\fP format-char
714                 \f(CW(\fP complex-name \f(CW)\fP unary-expression               
715 .DE
716 A unary expression may be preceded by a cast. The cast has the effect of
717 associating the value of 
718 .I unary-expression
719 with a complex type structure.
720 The result may then be dereferenced using the
721 .CW .
722 and
723 .CW ->
724 operators.
725 .PP
726 An Acid variable may be associated with a complex type
727 to enable accessing the type's members:
728 .P1
729 acid: complex List {
730         'D'     0       type;
731         'X'     4       next;
732 };
733 acid: complex List lhead
734 acid: lhead.type
735 10
736 acid: lhead = ((List)lhead).next
737 acid: lhead.type
738 -46
739 .P2
740 Note that the
741 .CW next
742 field cannot be given a complex type automatically.
743 .PP
744 When entered at the top level of the interpreter,
745 an expression of complex type
746 is treated specially.
747 If the type is called
748 .CW T
749 and an Acid function also called
750 .CW T
751 exists,
752 then that function will be called with the expression as its argument.
753 The compiler options
754 .CW -a
755 and
756 .CW -aa
757 will generate Acid source code defining such complex types and functions; see
758 .I 2c (1).
759 .PP
760 A
761 .I unary-expression
762 may be qualified with a format specifier using the
763 .CW \e
764 operator. This has the same effect as passing the expression to the
765 .CW fmt
766 builtin function.
767 .DS
768         multiplicative-expression:
769                 cast-expression
770                 multiplicative-expression \f(CW*\fP multiplicative-expression
771                 multiplicative-expression \f(CW/\fP multiplicative-expression
772                 multiplicative-expression \f(CW%\fP multiplicative-expression
773 .DE
774 These operate on
775 .I integer
776 and 
777 .I float
778 types and perform the expected operations:
779 .CW *
780 multiplication,
781 .CW /
782 division,
783 .CW %
784 modulus.
785 .DS
786         additive-expression:
787                 multiplicative-expression
788                 additive-expression \f(CW+\fP multiplicative-expression
789                 additive-expression \f(CW-\fP multiplicative-expression
790 .DE
791 These operators perform as expected for
792 .I integer
793 and 
794 .I float
795 operands.
796 Unlike in C,
797 .CW +
798 and
799 .CW -
800 do not scale the addition based on the format of the expression.
801 This means that
802 .CW i=i+1
803 will always add 1 but
804 .CW i++
805 will add the size corresponding to the format stored with
806 .CW i .
807 If both operands are of either
808 .I string
809 or
810 .I list
811 type then addition is defined as concatenation. 
812 Adding a string and an integer is treated as concatenation
813 with the Unicode character corresponding to the integer.
814 Subtraction is undefined for strings and lists.
815 .DS
816         shift-expression:
817                 additive-expression
818                 shift-expression \f(CW<<\fP additive-expression
819                 shift-expression \f(CW>>\fP additive-expression
820 .DE
821 The
822 .CW >>
823 and
824 .CW <<
825 operators perform bitwise right and left shifts respectively. Both
826 require operands of
827 .I integer
828 type.
829 .DS
830         relational-expression:
831                 relational-expression \f(CW<\fP shift-expression
832                 relational-expression \f(CW>\fP shift-expression
833                 relational-expression \f(CW<=\fP shift-expression
834                 relational-expression \f(CW>=\fP shift-expression
835
836         equality-expression:
837                 relational-expression
838                 relational-expression \f(CW==\fP equality-expression
839                 relational-expression \f(CW!=\fP equality-expression
840 .DE
841 The comparison operators are
842 .CW <
843 (less than),
844 .CW >
845 (greater than),
846 .CW <=
847 (less than or equal to),
848 .CW >=
849 (greater than or equal to),
850 .CW ==
851 (equal to) and
852 .CW !=
853 (not equal to). The result of a comparison is 0
854 if the condition is false, otherwise 1. The relational operators can only be
855 applied to operands of
856 .I integer
857 and
858 .I float
859 type. The equality operators apply to all types.  Comparing mixed types is legal.
860 Mixed integer and float compare on the integral value.  Other mixtures are always unequal.
861 Two lists are equal if they
862 have the same number of members and a pairwise comparison of the members results
863 in equality.
864 .DS
865         AND-expression:
866                 equality-expression
867                 AND-expression \f(CW&\fP equality-expression
868
869         XOR-expression:
870                 AND-expression
871                 XOR-expression \f(CW^\fP AND-expression
872
873         OR-expression:
874                 XOR-expression
875                 OR-expression \f(CW|\fP XOR-expression
876 .DE
877 These operators perform bitwise logical operations and apply only to the
878 .I integer
879 type.
880 The operators are
881 .CW &
882 (logical and),
883 .CW ^
884 (exclusive or) and
885 .CW |
886 (inclusive or).
887 .DS
888         logical-AND-expression:
889                 OR-expression
890                 logical-AND-expression \f(CW&&\fP OR-expression
891
892         logical-OR-expression:
893                 logical-AND-expression
894                 logical-OR-expression \f(CW||\fP logical-AND-expression
895 .DE
896 The
897 .CW &&
898 operator returns 1 if both of its operands evaluate to boolean true, otherwise 0.
899 The
900 .CW ||
901 operator returns 1 if either of its operands evaluates to boolean true,
902 otherwise 0.
903 .SH
904 Statements
905 .PP
906 .DS
907         \f(CWif\fP expression \f(CWthen\fP statement \f(CWelse\fP statement
908         \f(CWif\fP expression \f(CWthen\fP statement
909 .DE
910 The
911 .I expression
912 is evaluated as a boolean. If its value is true the statement after
913 the
914 .CW then
915 is executed, otherwise the statement after the
916 .CW else
917 is executed. The 
918 .CW else
919 portion may be omitted.
920 .DS
921         \f(CWwhile\fP expression \f(CWdo\fP statement
922 .DE
923 In a while loop, the
924 .I statement
925 is executed while the boolean
926 .I expression
927 evaluates
928 true.
929 .DS
930         \f(CWloop\fP startexpr, endexpr \f(CWdo\fP statement
931 .DE
932 The two expressions
933 .I startexpr
934 and
935 .I endexpr
936 are evaluated prior to loop entry.
937 .I Statement
938 is evaluated while the value of
939 .I startexpr
940 is less than or equal to
941 .I endexpr .
942 Both expressions must yield
943 .I integer
944 values. The value of
945 .I startexpr
946 is
947 incremented by one for each loop iteration.
948 Note that there is no explicit loop variable; the
949 .I expressions
950 are just values.
951 .DS
952         \f(CWreturn\fP expression
953 .DE
954 .CW return
955 terminates execution of the current function and returns to its caller.
956 The value of the function is given by expression. Since
957 .CW return
958 requires an argument, nil-valued functions should return the empty list
959 .CW {} .
960 .DS
961         \f(CWlocal\fP variable
962 .DE
963 The
964 .CW local
965 statement creates a local instance of
966 .I variable ,
967 which exists for the duration
968 of the instance of the function in which it is declared. Binding is dynamic: the local variable,
969 rather than the previous value of
970 .I variable ,
971 is visible to called functions.
972 After a return from the current function the previous value of
973 .I variable
974 is
975 restored.
976 .PP
977 If Acid is interrupted, the values of all local variables are lost,
978 as if the function returned.
979 .DS
980         \f(CWdefn\fP function-name \f(CW(\fP parameter-list \f(CW)\fP body
981
982         parameter-list:
983                 variable
984                 parameter-list , variable
985
986         body:
987                 \f(CW{\fP statement \f(CW}\fP
988 .DE
989 Functions are introduced by the
990 .CW defn
991 statement. The definition of parameter names suppresses any variables
992 of the same name until the function returns. The body of a function is a list
993 of statements enclosed by braces.
994 .SH
995 Code variables
996 .PP
997 Acid permits the delayed evaluation of a parameter to a function.  The parameter
998 may then be evaluated at any time with the
999 .CW eval
1000 operator.  Such parameters are called
1001 .I "code variables
1002 and are defined by prefixing their name with an asterisk in their declaration.
1003 .PP
1004 For example, this function wraps up an expression for later evaluation:
1005 .P1
1006 acid: defn code(*e) { return e; }
1007 acid: x = code(v+atoi("100")\eD)
1008 acid: print(x)
1009 (v+atoi("100"))\eD;
1010 acid: eval x
1011 <stdin>:5: (error) v used but not set
1012 acid: v=5
1013 acid: eval x
1014 105
1015 .P2
1016 .SH
1017 Source Code Management
1018 .PP
1019 Acid provides the means to examine source code. Source code is
1020 represented by lists of strings. Builtin functions provide mapping
1021 from address to lines and vice-versa. The default debugging environment
1022 has the means to load and display source files.
1023 .SH
1024 Builtin Functions
1025 .PP
1026 The Acid interpreter has a number of builtin functions, which cannot be redefined.
1027 These functions perform machine- or operating system-specific functions such as
1028 symbol table and process management.
1029 The following section presents a description of each builtin function.
1030 The notation
1031 .CW {}
1032 is used to denote the empty list, which is the default value of a function that
1033 does not execute a
1034 .CW return 
1035 statement.
1036 The type and number of parameters for each function are specified in the
1037 description; where a parameter can be of any type it is specified as type
1038 .I item .
1039 .de Ip
1040 .KS
1041 .in 0
1042 .LP
1043 .ie h \&\f2\\$1\fP\ \ \f(CW\\$2(\f2\\$3\f(CW)\f1\ \ \ \ \ \ \ \ \\$4
1044 .el .tl '\f2\\$1\fP\ \ \f(CW\\$2(\f2\\$3\f(CW)\f1''\\$4'
1045 .IP
1046 ..
1047 .de Ex
1048 .KE
1049 .KS
1050 .IP
1051 .ft CW
1052 .ta 4n +4n +4n +4n +4n +4n +4n +4n +4n +4n +4n +4n +4n +4n +4n +4n
1053 .nf
1054 .in +4n
1055 .br
1056 ..
1057 .de Ee
1058 .fi
1059 .ft 1
1060 .br
1061 .KE
1062 ..
1063 .\"
1064 .\"
1065 .\"
1066 .Ip integer access string "Check if a file can be read
1067 .CW Access
1068 returns the integer 1 if the file name in
1069 .I string
1070 can be read by the builtin functions
1071 .CW file ,
1072 .CW readfile ,
1073 or
1074 .CW include ,
1075 otherwise 0. A typical use of this function is to follow
1076 a search path looking for a source file; it is used by
1077 .CW findsrc .
1078 .Ex
1079 if access("main.c") then
1080         return file("main.c");
1081 .Ee
1082 .\"
1083 .\"
1084 .\"
1085 .Ip float atof string "Convert a string to float
1086 .CW atof
1087 converts the string supplied as its argument into a floating point
1088 number. The function accepts strings in the same format as the C
1089 function of the same name. The value returned has the format code
1090 .CW f .
1091 .CW atof
1092 returns the value 0.0 if it is unable to perform the conversion.
1093 .Ex
1094 acid: +atof("10.4e6")
1095 1.04e+07
1096 .Ee
1097 .\"
1098 .\"
1099 .\"
1100 .Ip integer atoi string "Convert a string to an integer
1101 .CW atoi
1102 converts the argument
1103 .i string
1104 to an integer value.
1105 The function accepts strings in the same format as the C function of the
1106 same name. The value returned has the format code
1107 .CW D .
1108 .CW atoi
1109 returns the integer 0 if it is unable to perform a conversion.
1110 .Ex
1111 acid: +atoi("-1255")
1112 -1255
1113 .Ee
1114 .\"
1115 .\"
1116 .\"
1117 .Ip \f(CW{}\fP error string "Generate an interpreter error
1118 .CW error
1119 generates an error message and returns the interpreter to interactive
1120 mode. If an Acid program is running, it is aborted.
1121 Processes being debugged are not affected. The values of all local variables are lost.
1122 .CW error
1123 is commonly used to stop the debugger when some interesting condition arises
1124 in the debugged program.
1125 .Ex
1126 while 1 do {
1127         step();
1128         if *main != @main then
1129                 error("memory corrupted");
1130 }
1131 .Ee
1132 .\"
1133 .\"
1134 .\"
1135 .Ip list file string "Read the contents of a file into a list
1136 .CW file
1137 reads the contents of the file specified by
1138 .I string
1139 into a list.
1140 Each element in the list is a string corresponding to a line in the file.
1141 .CW file
1142 breaks lines at the newline character, but the newline
1143 characters are not returned as part each string.
1144 .CW file
1145 returns the empty list if it encounters an error opening or reading the data.
1146 .Ex
1147 acid: print(file("main.c")[0])
1148 #include        <u.h>
1149 .Ee
1150 .\"
1151 .\"
1152 .\"
1153 .Ip integer filepc string "Convert source address to text address
1154 .CW filepc
1155 interprets its
1156 .I string
1157 argument as a source file address in the form of a file name and line offset.
1158 .CW filepc
1159 uses the symbol table to map the source address into a text address
1160 in the debugged program. The
1161 .I integer
1162 return value has the format
1163 .CW X .
1164 .CW filepc
1165 returns an address of -1 if the source address is invalid.
1166 The source file address uses the same format as
1167 .I acme (1).
1168 This function is commonly used to set breakpoints from the source text.
1169 .Ex
1170 acid: bpset(filepc("main:10"))
1171 acid: bptab()
1172         0x00001020 usage  ADD   $-0xc,R29
1173 .Ee
1174 .\"
1175 .\"
1176 .\"
1177 .Ip item fmt item,fmt "Set print, \f(CW@\fP and \f(CW*\fP formats
1178 .CW fmt
1179 evaluates the expression
1180 .I item
1181 and sets the format of the result to
1182 .I fmt .
1183 The format of a value determines how it will be printed and
1184 what kind of object will be fetched by the
1185 .CW *
1186 and
1187 .CW @
1188 operators. The
1189 .CW \e
1190 operator is a short-hand form of the
1191 .CW fmt
1192 builtin function. The
1193 .CW fmt
1194 function leaves the format of the
1195 .I item
1196 unchanged.
1197 .Ex
1198 acid: main=fmt(main, 'i') // as instructions
1199 acid: print(main\eX, "\et", *main)
1200 0x00001020 ADD  $-64,R29
1201 .Ee
1202 .\"
1203 .\"
1204 .\"
1205 .Ip fmt fmtof item "Get format
1206 .CW fmtof
1207 evaluates the expression
1208 .I item
1209 and returns the format of the result.
1210 .Ex
1211 acid: +fmtof(33)
1212 W
1213 acid: +fmtof("string")
1214 s
1215 .Ee
1216 .\"
1217 .\"
1218 .\"
1219 .Ip integer fmtsize item "Get format size
1220 .CW fmtsize
1221 evaluates the expression
1222 .I item
1223 and returns the size in bytes of a single element of result's format.
1224 .Ex
1225 acid: +fmtsize('c')
1226 8
1227 acid: +fmtsize('c'\ec)
1228 1
1229 acid: +fmtsize(0\eX)
1230 4
1231 acid: +fmtsize('c'\e3)
1232 10
1233 .Ee
1234 .\"
1235 .\"
1236 .\"
1237 .Ip list fnbound integer "Find start and end address of a function
1238 .CW fnbound
1239 interprets its
1240 .I integer
1241 argument as an address in the text of the debugged program.
1242 .CW fnbound
1243 returns a list containing two integers corresponding to
1244 the start and end addresses of the function containing the supplied address.
1245 If the
1246 .I integer
1247 address is not in the text segment of the program then the empty list is returned.
1248 .CW fnbound
1249 is used by
1250 .CW next
1251 to detect stepping into new functions.
1252 .Ex
1253 acid: print(fnbound(main))
1254 {0x00001050, 0x000014b8}
1255 .Ee
1256 .\"
1257 .\"
1258 .\"
1259 .Ip \f(CW{}\fP follow integer "Compute follow set
1260 The follow set is defined as the set of program counter values that could result
1261 from executing an instruction.
1262 .CW follow
1263 interprets its
1264 .I integer
1265 argument as a text address, decodes the instruction at
1266 that address and, with the current register set, builds a list of possible
1267 next program counter values. If the instruction at the specified address
1268 cannot be decoded
1269 .CW follow
1270 raises an error.
1271 .CW follow
1272 is used to plant breakpoints on
1273 all potential paths of execution. The following code fragment
1274 plants breakpoints on top of all potential following instructions.
1275 .Ex
1276 lst = follow(*PC);
1277 while lst do
1278 {
1279         *head lst = bpinst;
1280         lst = tail lst;
1281 }
1282 .Ee
1283 .\"
1284 .\"
1285 .\"
1286 .Ip \f(CW{}\fP include string "Take input from a new file
1287 .CW include
1288 opens the file specified by
1289 .I string
1290 and uses its contents as command input to the interpreter.
1291 The interpreter restores input to its previous source when it encounters
1292 either an end of file or an error.
1293 .CW include
1294 can be used to incrementally load symbol table information without
1295 leaving the interpreter.
1296 .Ex
1297 acid: include("/sys/src/cmd/acme/syms")
1298 .Ee
1299 .\"
1300 .\"
1301 .\"
1302 .Ip \f(CW{}\fP interpret string "Take input from a string
1303 .CW interpret
1304 evaluates the
1305 .I string
1306 expression and uses its result as command input for the interpreter.
1307 The interpreter restores input to its previous source when it encounters
1308 either the end of string or an error. The
1309 .CW interpret
1310 function allows Acid programs to write Acid code for later evaluation.
1311 .Ex
1312 acid: interpret("main+10;")
1313 0x0000102a
1314 .Ee
1315 .\"
1316 .\"
1317 .\"
1318 .Ip string itoa integer[,string] "Convert integer to string
1319 .CW itoa
1320 takes an integer argument and converts it into an ASCII string
1321 in the
1322 .CW D
1323 format.
1324 an alternate format string
1325 may be provided in the
1326 .CW %
1327 style of
1328 .I print (2).
1329 This function is commonly used to build
1330 .CW rc
1331 command lines.
1332 .Ex
1333 acid: rc("cat /proc/"+itoa(pid)+"/segment")
1334 Stack    7fc00000 80000000    1
1335 Data     00001000 00009000    1
1336 Data     00009000 0000a000    1
1337 Bss      0000a000 0000c000    1
1338 .Ee
1339 .\"
1340 .\"
1341 .\"
1342 .Ip \f(CW{}\fP kill integer "Kill a process
1343 .CW kill
1344 writes a kill control message into the control file of the process
1345 specified by the
1346 .I integer
1347 pid.
1348 If the process was previously installed by
1349 .CW setproc
1350 it will be removed from the list of active processes.
1351 If the
1352 .I integer
1353 has the same value as
1354 .CW pid ,
1355 then
1356 .CW pid
1357 will be set to 0.
1358 To continue debugging, a new process must be selected using
1359 .CW setproc .
1360 For example, to kill all the active processes:
1361 .Ex
1362 while proclist do {
1363         kill(head proclist);
1364         proclist = tail proclist;
1365 }
1366 .Ee
1367 .\"
1368 .\"
1369 .\"
1370 .Ip list map list "Set or retrieve process memory map
1371 .CW map
1372 either retrieves all the mappings associated with a process or sets a single
1373 map entry to a new value.
1374 If the
1375 .I list
1376 argument is omitted then
1377 .CW map
1378 returns a list of lists. Each sublist has four values and describes a
1379 single region of contiguous addresses in the
1380 memory or file image of the debugged program. The first entry is the name of the
1381 mapping. If the name begins with
1382 .CW *
1383 it denotes a map into the memory of an active process.
1384 The second and third values specify the base and end
1385 address of the region and the fourth number specifies the offset in the file
1386 corresponding to the first location of the region.
1387 A map entry may be set by supplying a list in the same format as the sublist
1388 described above. The name of the mapping must match a region already defined
1389 by the current map.
1390 Maps are set automatically for Plan 9 processes and some kernels; they may
1391 need to be set by hand for other kernels and programs that run on bare hardware.
1392 .Ex
1393 acid: map({"text", _start, end, 0x30})
1394 .Ee
1395 .\"
1396 .\"
1397 .\"
1398 .Ip integer match item,list "Search list for matching value
1399 .CW match
1400 compares each item in
1401 .I list
1402 using the equality operator
1403 .CW ==
1404 with
1405 .I item .
1406 The
1407 .I item
1408 can be of any type. If the match succeeds the result is the integer index
1409 of the matching value, otherwise -1.
1410 .Ex
1411 acid: list={8,9,10,11}
1412 acid: print(list[match(10, list)]\eD)
1413 10
1414 .Ee
1415 .\"
1416 .\"
1417 .\"
1418 .Ip \f(CW{}\fP newproc string "Create a new process
1419 .CW newproc
1420 starts a new process with an argument vector constructed from
1421 .I string .
1422 The argument vector excludes the name of the program to execute and
1423 each argument in
1424 .I string
1425 must be space separated. A new process can accept no more
1426 than 512 arguments. The internal variable
1427 .CW pid
1428 is set to the pid of the newly created process. The new pid
1429 is also appended to the list of active processes stored in the variable
1430 .CW proclist .
1431 The new process is created then halted at the first instruction, causing
1432 the debugger to call
1433 .CW stopped .
1434 The library functions
1435 .CW new
1436 and
1437 .CW win
1438 should be used to start processes when using the standard debugging
1439 environment.
1440 .Ex
1441 acid: newproc("-l .")
1442 56720: system call      _main   ADD     $-0x14,R29
1443 .Ee
1444 .\"
1445 .\"
1446 .\"
1447 .Ip string pcfile integer "Convert text address to source file name
1448 .CW pcfile
1449 interprets its
1450 .I integer
1451 argument as a text address in the debugged program. The address and symbol table
1452 are used to generate a string containing the name of the source file
1453 corresponding to the text address. If the address does not lie within the
1454 program the string
1455 .CW ?file?
1456 is returned.
1457 .Ex
1458 acid: print("Now at ", pcfile(*PC), ":", pcline(*PC))
1459 Now at ls.c:46 
1460 .Ee
1461 .\"
1462 .\"
1463 .\"
1464 .Ip integer pcline integer "Convert text address to source line number
1465 .CW pcline
1466 interprets its
1467 .I integer
1468 argument as a text address in the debugged program. The address and symbol table
1469 are used to generate an integer containing the line number in the source file
1470 corresponding to the text address. If the address does not lie within the
1471 program the integer 0 is returned.
1472 .Ex
1473 acid: +file("main.c")[pcline(main)]
1474 main(int argc, char *argv[])
1475 .Ee
1476 .\"
1477 .\"
1478 .\"
1479 .Ip \f(CW{}\fP print item,item,... "Print expressions
1480 .CW print
1481 evaluates each
1482 .I item
1483 supplied in its argument list and prints it to standard output. Each
1484 argument will be printed according to its associated format character.
1485 When the interpreter is executing, output is buffered and flushed every
1486 5000 statements or when the interpreter returns to interactive mode.
1487 .CW print
1488 accepts a maximum of 512 arguments.
1489 .Ex
1490 acid: print(10, "decimal ", 10\eD, "octal ", 10\eo)
1491 0x0000000a decimal 10 octal 000000000012 
1492 acid: print({1, 2, 3})
1493 {0x00000001 , 0x00000002 , 0x00000003 }
1494 acid: print(main, main\ea, "\et", @main\ei)
1495 0x00001020 main ADD     $-64,R29
1496 .Ee
1497 .\"
1498 .\"
1499 .\"
1500 .Ip \f(CW{}\fP printto string,item,item,... "Print expressions to file
1501 .CW printto
1502 offers a limited form of output redirection. The first
1503 .I string
1504 argument is used as the path name of a new file to create.
1505 Each
1506 .I item
1507 is then evaluated and printed to the newly created file. When all items
1508 have been printed the file is closed.
1509 .CW printto
1510 accepts a maximum of 512 arguments.
1511 .Ex
1512 acid: printto("/env/foo", "hello")
1513 acid: rc("echo -n $foo")
1514 hello
1515 .Ee
1516 .\"
1517 .\"
1518 .\"
1519 .Ip string rc string "Execute a shell command
1520 .CW rc
1521 evaluates
1522 .I string
1523 to form a shell command. A new command interpreter is started
1524 to execute the command. The Acid interpreter blocks until the command
1525 completes. The return value is the empty string
1526 if the command succeeds, otherwise the exit status of the failed command.
1527 .Ex
1528 acid: rc("B "+itoa(-pcline(addr))+" "+pcfile(addr));
1529 .Ee
1530 .\"
1531 .\"
1532 .\"
1533 .Ip string readfile string "Read file contents into a string
1534 .CW readfile
1535 takes the contents of the file specified by
1536 .I string
1537 and returns its contents as a new string.
1538 If
1539 .CW readfile
1540 encounters a zero byte in the file, it terminates.
1541 If
1542 .CW readfile
1543 encounters an error opening or reading the file then the empty list
1544 is returned.
1545 .CW readfile
1546 can be used to read the contents of device files whose lines are not
1547 terminated with newline characters.
1548 .Ex
1549 acid: ""+readfile("/dev/label")
1550 helix
1551 .Ee
1552 .\"
1553 .\"
1554 .\"
1555 .Ip string reason integer "Print cause of program stoppage
1556 .CW reason
1557 uses machine-dependent information to generate a string explaining
1558 why a process has stopped. The
1559 .I integer
1560 argument is the value of an architecture dependent status register,
1561 for example
1562 .CW CAUSE
1563 on the MIPS.
1564 .Ex
1565 acid: print(reason(*CAUSE))
1566 system call
1567 .Ee
1568 .\"
1569 .\"
1570 .\"
1571 .Ip integer regexp pattern,string "Regular expression match
1572 .CW regexp
1573 matches the
1574 .I pattern
1575 string supplied as its first argument with the 
1576 .I string
1577 supplied as its second.
1578 If the pattern matches the result is the value 1, otherwise 0.
1579 .Ex
1580 acid: print(regexp(".*bar", "foobar"))
1581 1
1582 .Ee
1583 .\"
1584 .\"
1585 .\"
1586 .Ip \f(CW{}\fP setproc integer "Set debugger focus
1587 .CW setproc
1588 selects the default process used for memory and control operations. It effectively
1589 shifts the focus of control between processes. The 
1590 .I integer
1591 argument specifies the pid of the process to look at.
1592 The variable
1593 .CW pid
1594 is set to the pid of the selected process. If the process is being
1595 selected for the first time its pid is added to the list of active
1596 processes
1597 .CW proclist .
1598 .Ex
1599 acid: setproc(68382)
1600 acid: procs()
1601 >68382: Stopped at main+0x4 setproc(68382)
1602 .Ee
1603 .\"
1604 .\"
1605 .\"
1606 .Ip \f(CW{}\fP start integer "Restart execution
1607 .CW start
1608 writes a
1609 .CW start
1610 message to the control file of the process specified by the pid
1611 supplied as its
1612 .I integer
1613 argument.
1614 .CW start
1615 draws an error if the process is not in the
1616 .CW Stopped
1617 state.
1618 .Ex
1619 acid: start(68382)
1620 acid: procs()
1621 >68382: Running at main+0x4 setproc(68382)
1622 .Ee
1623 .\"
1624 .\"
1625 .\"
1626 .Ip \f(CW{}\fP startstop integer "Restart execution, block until stopped
1627 .CW startstop
1628 performs the same actions as a call to
1629 .CW start
1630 followed by a call to
1631 .CW stop .
1632 The
1633 .I integer
1634 argument specifies the pid of the process to control. The process
1635 must be in the
1636 .CW Stopped
1637 state.
1638 Execution is restarted, the debugger then waits for the process to
1639 return to the
1640 .CW Stopped
1641 state. A process will stop if a startstop message has been written to its control
1642 file and any of the following conditions becomes true: the process executes or returns from
1643 a system call, the process generates a trap or the process receives a note.
1644 .CW startstop
1645 is used to implement single stepping.
1646 .Ex
1647 acid: startstop(pid)
1648 75374: breakpoint       ls      ADD     $-0x16c8,R29
1649 .Ee
1650 .\"
1651 .\"
1652 .\"
1653 .Ip string status integer "Return process state
1654 .CW status
1655 uses the pid supplied by its
1656 .I integer
1657 argument to generate a string describing the state of the process.
1658 The string corresponds to the state returned by the
1659 sixth column of the
1660 .I ps (1)
1661 command.
1662 A process must be in the
1663 .CW Stopped
1664 state to modify its memory or registers.
1665 .Ex
1666 acid: ""+status(pid)
1667 Stopped
1668 .Ee
1669 .\"
1670 .\"
1671 .\"
1672 .Ip \f(CW{}\fP stop integer "Wait for a process to stop
1673 .CW stop
1674 writes a
1675 .CW stop
1676 message to the control file of the process specified by the
1677 pid supplied as its
1678 .I integer
1679 argument.
1680 The interpreter blocks until the debugged process enters the
1681 .CW Stopped
1682 state.
1683 A process will stop if a stop message has been written to its control
1684 file and any of the following conditions becomes true: the process executes or returns from
1685 a system call, the process generates a trap, the process is scheduled or the
1686 process receives a note.
1687 .CW stop
1688 is used to wait for a process to halt before planting a breakpoint since Plan 9
1689 only allows a process's memory to be written while it is in the
1690 .CW Stopped
1691 state.
1692 .Ex
1693 defn bpset(addr) {
1694         if (status(pid)!="Stopped") then {
1695                 print("Waiting...\en");
1696                 stop(pid);
1697         }
1698         ...
1699 }
1700 .Ee
1701 .\"
1702 .\"
1703 .\"
1704 .Ip list strace pc,sp,linkreg "Stack trace
1705 .CW strace
1706 generates a list of lists corresponding to procedures called by the debugged
1707 program. Each sublist describes a single stack frame in the active process.
1708 The first element is an
1709 .I integer
1710 of format
1711 .CW X
1712 specifying the address of the called function. The second element is the value
1713 of the program counter when the function was called. The third and fourth elements
1714 contain lists of parameter and automatic variables respectively.
1715 Each element of these lists
1716 contains a string with the name of the variable and an
1717 .I integer
1718 value of format
1719 .CW X
1720 containing the current value of the variable.
1721 The arguments to
1722 .CW strace
1723 are the current value of the program counter, the current value of the
1724 stack pointer, and the address of the link register. All three parameters
1725 must be integers.
1726 The setting of 
1727 .I linkreg
1728 is architecture dependent. On the MIPS linkreg is set to the address of saved
1729 .CW R31 ,
1730 on the SPARC to the address of saved
1731 .CW R15 .
1732 For the other architectures
1733 .I linkreg
1734 is not used, but must point to valid memory.
1735 .Ex
1736 acid: print(strace(*PC, *SP, linkreg))
1737 {{0x0000141c, 0xc0000f74,
1738 {{"s", 0x0000004d}, {"multi", 0x00000000}}, 
1739 {{"db", 0x00000000}, {"fd", 0x000010a4},
1740 {"n", 0x00000001}, {"i", 0x00009824}}}}
1741 .Ee
1742 .\"
1743 .\"
1744 .\"
1745 .Ip \f(CW{}\fP waitstop integer "Wait for a process to stop
1746 .CW waitstop
1747 writes a waitstop message to the control file of the process specified by the
1748 pid supplied as its
1749 .I integer
1750 argument.
1751 The interpreter will remain blocked until the debugged process enters the
1752 .CW Stopped
1753 state.
1754 A process will stop if a waitstop message has been written to its control
1755 file and any of the following conditions becomes true: the process generates a trap
1756 or receives a note. Unlike
1757 .CW stop ,
1758 the
1759 .CW waitstop
1760 function is passive; it does not itself cause the program to stop.
1761 .Ex
1762 acid: waitstop(pid)
1763 75374: breakpoint       ls      ADD     $-0x16c8,R29
1764 .Ee
1765 .\"
1766 .\"
1767 .\"
1768 .SH
1769 Library Functions
1770 .PP
1771 A standard debugging environment is provided by modules automatically
1772 loaded when
1773 Acid is started.
1774 These modules are located in the directory
1775 .CW /sys/lib/acid .
1776 These functions may be overridden, personalized, or added to by code defined in
1777 .CW $home/lib/acid .
1778 The implementation of these functions can be examined using the
1779 .CW whatis
1780 operator and then modified during debugging sessions.
1781 .\"
1782 .\"
1783 .\"
1784 .Ip \f(CW{}\fP Bsrc integer "Load editor with source
1785 .CW Bsrc
1786 interprets the
1787 .I integer
1788 argument as a text address. The text address is used to produce a pathname
1789 and line number suitable for the
1790 .CW B
1791 command
1792 to send to the text editor
1793 .I sam (1)
1794 or
1795 .I acme (1).
1796 .CW Bsrc
1797 builds an
1798 .I rc (1)
1799 command to invoke
1800 .CW B ,
1801 which either selects an existing source file or loads a new source file into the editor.
1802 The line of source corresponding to the text address is then selected.
1803 In the following example
1804 .CW stopped
1805 is redefined so that the editor
1806 follows and displays the source line currently being executed.
1807 .Ex
1808 defn stopped(pid) {
1809         pstop(pid);
1810         Bsrc(*PC);
1811 }
1812 .Ee
1813 .\"
1814 .\"
1815 .\"
1816 .Ip \f(CW{}\fP Fpr "" "Display double precision floating registers
1817 For machines equipped with floating point,
1818 .CW Fpr
1819 displays the contents of the floating point registers as double precision
1820 values.
1821 .Ex
1822 acid: Fpr()
1823 F0   0. F2   0.
1824 F4   0. F6   0.
1825 F8   0. F10  0.
1826 \&...
1827 .Ee
1828 .\"
1829 .\"
1830 .\"
1831 .Ip \f(CW{}\fP Ureg integer "Display contents of Ureg structure
1832 .CW Ureg
1833 interprets the integer passed as its first argument as the address of a
1834 kernel
1835 .CW Ureg
1836 structure. Each element of the structure is retrieved and printed.
1837 The size and contents of the
1838 .CW Ureg
1839 structure are architecture dependent.
1840 This function can be used to decode the first argument passed to a
1841 .I notify (2)
1842 function after a process has received a note.
1843 .Ex
1844 acid: Ureg(*notehandler:ur)
1845         status  0x3000f000
1846         pc      0x1020
1847         sp      0x7ffffe00
1848         cause   0x00004002
1849 \&...
1850 .Ee
1851 .\"
1852 .\"
1853 .\"
1854 .Ip \f(CW{}\fP acidinit "" "Interpreter startup
1855 .CW acidinit
1856 is called by the interpreter after all
1857 modules have been loaded at initialization time.
1858 It is used to set up machine specific variables and the default source path.
1859 .CW acidinit
1860 should not be called by user code.
1861 .KE
1862 .\"
1863 .\"
1864 .\"
1865 .Ip \f(CW{}\fP addsrcdir string "Add element to source search path
1866 .CW addsrcdir
1867 interprets its string argument as a new directory
1868 .CW findsrc
1869 should search when looking for source code files.
1870 .CW addsrcdir
1871 draws an error if the directory is already in the source search path. The search
1872 path may be examined by looking at the variable
1873 .CW srcpath .
1874 .Ex
1875 acid: rc("9fs fornax")
1876 acid: addsrcpath("/n/fornax/sys/src/cmd")
1877 .Ee
1878 .\"
1879 .\"
1880 .\"
1881 .Ip \f(CW{}\fP asm integer "Disassemble machine instructions
1882 .CW asm
1883 interprets its integer argument as a text address from which to disassemble
1884 machine instructions.
1885 .CW asm
1886 prints the instruction address in symbolic and hexadecimal form, then prints
1887 the instructions with addressing modes. Up to twenty instructions will
1888 be disassembled.
1889 .CW asm
1890 stops disassembling when it reaches the end of the current function.
1891 Instructions are read from the file image using the
1892 .CW @
1893 operator.
1894 .Ex
1895 acid: asm(main)
1896 main     0x00001020 ADD    $-0x64,R29
1897 main+0x4 0x00001024 MOVW   R31,0x0(R29)
1898 main+0x8 0x00001028 MOVW   R1,argc+4(FP)
1899 main+0xc 0x0000102c MOVW   $bin(SB),R1
1900 .Ee
1901 .\"
1902 .\"
1903 .\"
1904 .Ip \f(CW{}\fP bpdel integer "Delete breakpoint
1905 .CW bpdel
1906 removes a previously set breakpoint from memory.
1907 The
1908 .I integer
1909 supplied as its argument must be the address of a previously set breakpoint.
1910 The breakpoint address is deleted from the active breakpoint list
1911 .CW bplist ,
1912 then the original instruction is copied from the file image to the memory
1913 image so that the breakpoint is removed.
1914 .Ex
1915 acid: bpdel(main+4)
1916 .Ee
1917 .\"
1918 .\"
1919 .\"
1920 .Ip \f(CW{}\fP bpset integer "Set a breakpoint
1921 .CW bpset
1922 places a breakpoint instruction at the address specified
1923 by its
1924 .I integer
1925 argument, which must be in the text segment.
1926 .CW bpset
1927 draws an error if a breakpoint has already been set at the specified address.
1928 A list of current breakpoints is maintained in the variable
1929 .CW bplist .
1930 Unlike in
1931 .I db (1),
1932 breakpoints are left in memory even when a process is stopped, and
1933 the process must exist, perhaps by being
1934 created by either
1935 .CW new
1936 or
1937 .CW win ,
1938 in order to place a breakpoint.
1939 .CW Db "" (
1940 accepts breakpoint commands before the process is started.)
1941 On the
1942 MIPS and SPARC architectures,
1943 breakpoints at function entry points should be set 4 bytes into the function
1944 because the
1945 instruction scheduler may fill
1946 .CW JAL
1947 branch delay slots with the first instruction of the function.
1948 .Ex
1949 acid: bpset(main+4)
1950 .Ee
1951 .\"
1952 .\"
1953 .\"
1954 .Ip \f(CW{}\fP bptab "" "List active breakpoints
1955 .CW bptab
1956 prints a list of currently installed breakpoints. The list contains the
1957 breakpoint address in symbolic and hexadecimal form as well as the instruction
1958 the breakpoint replaced. Breakpoints are not maintained across process creation
1959 using
1960 .CW new
1961 and
1962 .CW win .
1963 They are maintained across a fork, but care must be taken to keep control of
1964 the child process.
1965 .Ex
1966 acid: bpset(ls+4)
1967 acid: bptab()
1968         0x00001420 ls+0x4  MOVW R31,0x0(R29)
1969 .Ee
1970 .\"
1971 .\"
1972 .\"
1973 .Ip \f(CW{}\fP casm "" "Continue disassembly
1974 .CW casm
1975 continues to disassemble instructions from where the last
1976 .CW asm
1977 or
1978 .CW casm
1979 command stopped. Like
1980 .CW asm ,
1981 this command stops disassembling at function boundaries.
1982 .Ex
1983 acid: casm()
1984 main+0x10 0x00001030    MOVW    $0x1,R3
1985 main+0x14 0x00001034    MOVW    R3,0x8(R29)
1986 main+0x18 0x00001038    MOVW    $0x1,R5
1987 main+0x1c 0x0000103c    JAL     Binit(SB)
1988 .Ee
1989 .\"
1990 .\"
1991 .\"
1992 .Ip \f(CW{}\fP cont "" "Continue program execution
1993 .CW cont
1994 restarts execution of the currently active process.
1995 If the process is stopped on a breakpoint, the breakpoint is first removed,
1996 the program is single stepped, the breakpoint is replaced and the program
1997 is then set executing. This may cause
1998 .CW stopped()
1999 to be called twice.
2000 .CW cont
2001 causes the interpreter to block until the process enters the
2002 .CW Stopped
2003 state.
2004 .Ex
2005 acid: cont()
2006 95197: breakpoint       ls+0x4  MOVW    R31,0x0(R29)
2007 .Ee
2008 .\"
2009 .\"
2010 .\"
2011 .Ip \f(CW{}\fP dump integer,integer,string "Formatted memory dump
2012 .CW dump
2013 interprets its first argument as an address, its second argument as a
2014 count and its third as a format string.
2015 .CW dump
2016 fetches an object from memory at the current address and prints it according
2017 to the format. The address is incremented by the number of bytes specified by
2018 the format and the process is repeated count times. The format string is any
2019 combination of format characters, each preceded by an optional count.
2020 For each object,
2021 .CW dump
2022 prints the address in hexadecimal, a colon, the object and then a newline.
2023 .CW dump
2024 uses
2025 .CW mem
2026 to fetch each object.
2027 .Ex
2028 acid: dump(main+35, 4, "X2bi")
2029 0x00001043: 0x0c8fa700 108 143 lwc2 r0,0x528f(R4) 
2030 0x0000104d: 0xa9006811   0   0 swc3 r0,0x0(R24) 
2031 0x00001057: 0x2724e800   4  37 ADD  $-0x51,R23,R31 
2032 0x00001061: 0xa200688d   6   0 NOOP
2033 0x0000106b: 0x2710c000   7   0 BREAK
2034 .Ee
2035 .\"
2036 .\"
2037 .\"
2038 .Ip \f(CW{}\fP findsrc string "Use source path to load source file
2039 .CW findsrc
2040 interprets its
2041 .I string
2042 argument as a source file. Each directory in the source path is searched
2043 in turn for the file. If the file is found, the source text is loaded using
2044 .CW file
2045 and stored in the list of active source files called
2046 .CW srctext .
2047 The name of the file is added to the source file name list
2048 .CW srcfiles .
2049 Users are unlikely to call
2050 .CW findsrc
2051 from the command line, but may use it from scripts to preload source files
2052 for a debugging session. This function is used by
2053 .CW src
2054 and
2055 .CW line
2056 to locate and load source code. The default search path for the MIPS
2057 is
2058 .CW ./ ,
2059 .CW /sys/src/libc/port ,
2060 .CW /sys/src/libc/9sys ,
2061 .CW /sys/src/libc/mips .
2062 .Ex
2063 acid: findsrc(pcfile(main));
2064 .Ee
2065 .\"
2066 .\"
2067 .\"
2068 .Ip \f(CW{}\fP fpr "" "Display single precision floating registers
2069 For machines equipped with floating point,
2070 .CW fpr
2071 displays the contents of the floating point registers as single precision
2072 values. When the interpreter stores or manipulates floating point values
2073 it converts into double precision values.
2074 .Ex
2075 acid: fpr()
2076 F0   0. F1   0.
2077 F2   0. F3   0.
2078 F4   0. F5   0.
2079 \&...
2080 .Ee
2081 .\"
2082 .\"
2083 .\"
2084 .Ip \f(CW{}\fP func "" "Step while in function
2085 .CW func
2086 single steps the active process until it leaves the current function
2087 by either calling another function or returning to its caller.
2088 .CW func
2089 will execute a single instruction after leaving the current function.
2090 .Ex
2091 acid: func()
2092 95197: breakpoint       ls+0x8  MOVW    R1,R8
2093 95197: breakpoint       ls+0xc  MOVW    R8,R1
2094 95197: breakpoint       ls+0x10 MOVW    R8,s+4(FP)
2095 95197: breakpoint       ls+0x14 MOVW    $0x2f,R5
2096 95197: breakpoint       ls+0x18 JAL     utfrrune(SB)
2097 95197: breakpoint       utfrrune        ADD     $-0x18,R29
2098 .Ee
2099 .\"
2100 .\"
2101 .\"
2102 .Ip \f(CW{}\fP gpr "" "Display general purpose registers
2103 .CW gpr
2104 prints the values of the general purpose processor registers.
2105 .Ex
2106 acid: gpr()
2107 R1      0x00009562 R2   0x000010a4 R3   0x00005d08
2108 R4      0x0000000a R5   0x0000002f R6   0x00000008
2109 \&...
2110 .Ee
2111 .\"
2112 .\"
2113 .\"
2114 .Ip \f(CW{}\fP labstk integer "Print stack trace from label
2115 .CW labstk
2116 performs a stack trace from a Plan 9
2117 .I label.
2118 The kernel,
2119 C compilers store continuations in a common format. Since the
2120 compilers all use caller save conventions a continuation may be saved by
2121 storing a
2122 .CW PC
2123 and
2124 .CW SP
2125 pair. This data structure is called a label and is used by the
2126 the C function
2127 .CW longjmp
2128 and the kernel to schedule threads and processes.
2129 .CW labstk
2130 interprets its
2131 .I integer
2132 argument as the address of a label and produces a stack trace for
2133 the thread of execution. The value of the function
2134 .CW ALEF_tid
2135 is a suitable argument for
2136 .CW labstk .
2137 .Ex
2138 acid: labstk(*mousetid)
2139 At pc:0x00021a70:Rendez_Sleep+0x178 rendez.l:44
2140 Rendez_Sleep(r=0xcd7d8,bool=0xcd7e0,t=0x0) rendez.l:5
2141         called from ALEF_rcvmem+0x198 recvmem.l:45
2142 ALEF_rcvmem(c=0x000cd764,l=0x00000010) recvmem.l:6
2143 \&...
2144 .Ee
2145 .\"
2146 .\"
2147 .\"
2148 .Ip \f(CW{}\fP lstk "" "Stack trace with local variables
2149 .CW lstk
2150 produces a long format stack trace.
2151 The stack trace includes each function in the stack,
2152 where it was called from, and the value of the parameters and automatic
2153 variables for each function.
2154 .CW lstk
2155 displays the value rather than the address of each variable and all
2156 variables are assumed to be an integer in format
2157 .CW X .
2158 To print a variable in its correct format use the
2159 .CW :
2160 operator to find the address and apply the appropriate format before indirection
2161 with the
2162 .CW *
2163 operator. It may be necessary to single step a couple of instructions into
2164 a function to get a correct stack trace because the frame pointer adjustment
2165 instruction may get scheduled down into the body of the function.
2166 .Ex
2167 acid: lstk()
2168 At pc:0x00001024:main+0x4 ls.c:48
2169 main(argc=0x00000001,argv=0x7fffefec) ls.c:48
2170         called from _main+0x20 main9.s:10
2171         _argc=0x00000000
2172         _args=0x00000000
2173         fd=0x00000000
2174         buf=0x00000000
2175         i=0x00000000
2176 .Ee
2177 .\"
2178 .\"
2179 .\"
2180 .Ip \f(CW{}\fP mem integer,string "Print memory object
2181 .CW mem
2182 interprets its first
2183 .I integer
2184 argument as the address of an object to be printed according to the
2185 format supplied in its second
2186 .I string
2187 argument.
2188 The format string can be any combination of format characters, each preceded
2189 by an optional count.
2190 .Ex
2191 acid: mem(bdata+0x326, "2c2Xb")
2192 P = 0xa94bc464 0x3e5ae44d  19 
2193 .Ee
2194 .\"
2195 .\"
2196 .\"
2197 .Ip \f(CW{}\fP new "" "Create new process
2198 .CW new
2199 starts a new copy of the debugged program. The new program is started
2200 with the program arguments set by the variable
2201 .CW progargs .
2202 The new program is stopped in the second instruction of
2203 .CW main .
2204 The breakpoint list is reinitialized.
2205 .CW new
2206 may be used several times to instantiate several copies of a program
2207 simultaneously. The user can rotate between the copies using
2208 .CW setproc .
2209 .Ex
2210 acid: progargs="-l"
2211 acid: new()
2212 60: external interrupt  _main   ADD     $-0x14,R29
2213 60: breakpoint  main+0x4        MOVW    R31,0x0(R29)
2214 .Ee
2215 .\"
2216 .\"
2217 .\"
2218 .Ip \f(CW{}\fP next "" "Step through language statement
2219 .CW next
2220 steps through a single language level statement without tracing down
2221 through each statement in a called function. For each statement,
2222 .CW next
2223 prints the machine instructions executed as part of the statement. After
2224 the statement has executed, source lines around the current program
2225 counter are displayed.
2226 .Ex
2227 acid: next()
2228 60: breakpoint  Binit+0x4 MOVW  R31,0x0(R29)
2229 60: breakpoint  Binit+0x8 MOVW  f+8(FP),R4
2230 binit.c:93
2231  88     
2232  89     int
2233  90     Binit(Biobuf *bp, int f, int mode)
2234  91     {
2235 >92             return Binits(bp, f, mode, bp->b, BSIZE);
2236  93     }
2237 .Ee
2238 .\"
2239 .\"
2240 .\"
2241 .Ip \f(CW{}\fP notestk integer "Stack trace after receiving a note
2242 .CW notestk
2243 interprets its
2244 .I integer
2245 argument as the address of a
2246 .CW Ureg
2247 structure passed by the kernel to a
2248 .I notify (2)
2249 function during note processing.
2250 .CW notestk
2251 uses the
2252 .CW PC ,
2253 .CW SP ,
2254 and link register from the
2255 .CW Ureg
2256 to print a stack trace corresponding to the point in the program where the note
2257 was received.
2258 To get a valid stack trace on the MIPS and SPARC architectures from a notify
2259 routine, the program must stop in a new function called from the notify routine
2260 so that the link register is valid and the notify routine's parameters are
2261 addressable.
2262 .Ex
2263 acid: notestk(*notify:ur)
2264 Note pc:0x00001024:main+0x4 ls.c:48
2265 main(argc=0x00000001,argv=0x7fffefec) ls.c:48
2266         called from _main+0x20 main9.s:10
2267         _argc=0x00000000
2268         _args=0x00000000
2269 .Ee
2270 .\"
2271 .\"
2272 .\"
2273 .Ip \f(CW{}\fP pfl integer "Print source file and line
2274 .CW pfl
2275 interprets its argument as a text address and uses it to print
2276 the source file and line number corresponding to the address. The output
2277 has the same format as file addresses in
2278 .I acme (1).
2279 .Ex
2280 acid: pfl(main)
2281 ls.c:48
2282 .Ee
2283 .\"
2284 .\"
2285 .\"
2286 .Ip \f(CW{}\fP procs "" "Print active process list
2287 .CW procs
2288 prints a list of active process attached to the debugger. Each process
2289 produces a single line of output giving the pid, process state, the address
2290 the process is currently executing, and the
2291 .CW setproc
2292 command required to make that process current.
2293 The current process is marked in the first column with a
2294 .CW >
2295 character. The debugger maintains a list of processes in the variable
2296 .CW proclist .
2297 .Ex
2298 acid: procs()
2299 >62: Stopped at main+0x4 setproc(62)
2300  60: Stopped at Binit+0x8 setproc(60)
2301 .Ee
2302 .\"
2303 .\"
2304 .\"
2305 .Ip \f(CW{}\fP pstop integer "Print reason process stopped
2306 .CW pstop
2307 prints the status of the process specified by the
2308 .I integer
2309 pid supplied as its argument.
2310 .CW pstop
2311 is usually called from
2312 .CW stopped
2313 every time a process enters the
2314 .CW Stopped
2315 state.
2316 .Ex
2317 acid: pstop(62)
2318 0x0000003e: breakpoint  main+0x4        MOVW    R31,0x0(R29)
2319 .Ee
2320 .\"
2321 .\"
2322 .\"
2323 .Ip \f(CW{}\fP regs "" "Print registers
2324 .CW regs
2325 prints the contents of both the general and special purpose registers.
2326 .CW regs
2327 calls
2328 .CW spr
2329 then
2330 .CW gpr
2331 to display the contents of the registers.
2332 .KE
2333 .\"
2334 .\"
2335 .\"
2336 .Ip \f(CW{}\fP source "" "Summarize source data base
2337 .CW source
2338 prints the directory search path followed by a list of currently loaded
2339 source files. The source management functions
2340 .CW src
2341 and
2342 .CW findsrc
2343 use the search path to locate and load source files. Source files are
2344 loaded incrementally into a source data base during debugging. A list
2345 of loaded files is stored in the variable
2346 .CW srcfiles
2347 and the contents of each source file in the variable
2348 .CW srctext .
2349 .Ex
2350 acid: source()
2351 /n/bootes/sys/src/libbio/
2352 ./
2353 /sys/src/libc/port/
2354 /sys/src/libc/9sys/
2355 /sys/src/libc/mips/
2356         binit.c
2357 .Ee
2358 .\"
2359 .\"
2360 .\"
2361 .Ip \f(CW{}\fP spr "" "Print special purpose registers
2362 .CW spr
2363 prints the contents of the processor control and memory management
2364 registers. Where possible, the contents of the registers are decoded
2365 to provide extra information; for example the
2366 .CW CAUSE
2367 register on the MIPS is
2368 printed both in hexadecimal and using the
2369 .CW reason
2370 function.
2371 .Ex
2372 acid: spr()
2373 PC      0x00001024 main+0x4  ls.c:48
2374 SP      0x7fffef68 LINK 0x00006264 _main+0x28 main9.s:12
2375 STATUS  0x0000ff33 CAUSE        0x00000024 breakpoint
2376 TLBVIR  0x000000d3 BADVADR      0x00001020
2377 HI      0x00000004 LO           0x00001ff7
2378 .Ee
2379 .\"
2380 .\"
2381 .\"
2382 .Ip \f(CW{}\fP src integer "Print lines of source
2383 .CW src
2384 interprets its
2385 .I integer
2386 argument as a text address and uses this address to print 5 lines
2387 of source before and after the address. The current line is marked with a
2388 .CW >
2389 character.
2390 .CW src
2391 uses the source search path maintained by
2392 .CW source
2393 and
2394 .CW addsrcdir
2395 to locate the required source files.
2396 .Ex
2397 acid: src(*PC)
2398 ls.c:47
2399  42     Biobuf  bin;
2400  43     
2401  44     #define         HUNK    50
2402  45     
2403  46     void
2404 >47     main(int argc, char *argv[])
2405  48     {
2406  49             int i, fd;
2407  50             char buf[64];
2408  51     
2409  52             Binit(&bin, 1, OWRITE);
2410 .Ee
2411 .\"
2412 .\"
2413 .\"
2414 .Ip \f(CW{}\fP step "" "Single step process
2415 .CW step
2416 causes the debugged process to execute a single machine level instruction.
2417 If the program is stopped on a breakpoint set by
2418 .CW bpset
2419 it is first removed, the single step executed, and the breakpoint replaced.
2420 .CW step
2421 uses
2422 .CW follow
2423 to predict the address of the program counter after the current instruction
2424 has been executed. A breakpoint is placed at each of these predicted addresses
2425 and the process is started. When the process stops the breakpoints are removed.
2426 .Ex
2427 acid: step()
2428 62: breakpoint  main+0x8        MOVW    R1,argc+4(FP)
2429 .Ee
2430 .\"
2431 .\"
2432 .\"
2433 .Ip \f(CW{}\fP stk "" "Stack trace
2434 .CW stk
2435 produces a short format stack trace. The stack trace includes each function
2436 in the stack, where it was called from, and the value of the parameters.
2437 The short format omits the values of automatic variables.
2438 Parameters are assumed to be integer values in the format
2439 .CW X ;
2440 to print a parameter in the correct format use the
2441 .CW :
2442 to obtain its address, apply the correct format, and use the
2443 .CW *
2444 indirection operator to find its value.
2445 It may be necessary to single step a couple of instructions into
2446 a function to get a correct stack trace because the frame pointer adjustment
2447 instruction may get scheduled down into the body of the function.
2448 .Ex
2449 acid: stk()
2450 At pc:0x00001028:main+0x8 ls.c:48
2451 main(argc=0x00000002,argv=0x7fffefe4) ls.c:48
2452         called from _main+0x20 main9.s:10
2453 .Ee
2454 .\"
2455 .\"
2456 .\"
2457 .Ip \f(CW{}\fP stmnt "" "Execute a single statement
2458 .CW stmnt
2459 executes a single language level statement.
2460 .CW stmnt
2461 displays each machine level instruction as it is executed. When the executed
2462 statement is completed the source for the next statement is displayed.
2463 Unlike
2464 .CW next ,
2465 the
2466 .CW stmnt
2467 function will trace down through function calls.
2468 .Ex
2469 acid: stmnt()
2470 62: breakpoint  main+0x18 MOVW  R5,0xc(R29)
2471 62: breakpoint  main+0x1c JAL   Binit(SB)
2472 62: breakpoint  Binit     ADD   $-0x18,R29
2473 binit.c:91
2474  89     int
2475  90     Binit(Biobuf *bp, int f, int mode)
2476 >91     {
2477 .Ee
2478 .\"
2479 .\"
2480 .\"
2481 .Ip \f(CW{}\fP stopped integer "Report status of stopped process
2482 .CW stopped
2483 is called automatically by the interpreter
2484 every time a process enters the
2485 .CW Stopped
2486 state, such as when it hits a breakpoint.
2487 The pid is passed as the
2488 .I integer
2489 argument.  The default implementation just calls
2490 .CW pstop ,
2491 but the function may be changed to provide more information or perform fine control
2492 of execution.  Note that
2493 .CW stopped
2494 should return; for example, calling
2495 .CW step
2496 in
2497 .CW stopped
2498 will recur until the interpreter runs out of stack space.
2499 .Ex
2500 acid: defn stopped(pid) {
2501         if *lflag != 0 then error("lflag modified");
2502         }
2503 acid: progargs = "-l"
2504 acid: new();
2505 acid: while 1 do step();
2506 <stdin>:7: (error) lflag modified
2507 acid: stk()
2508 At pc:0x00001220:main+0x200 ls.c:54
2509 main(argc=0x00000001,argv=0x7fffffe8) ls.c:48
2510         called from _main+0x20 main9.s:10
2511 .Ee
2512 .\"
2513 .\"
2514 .\"
2515 .Ip \f(CW{}\fP symbols string "Search symbol table
2516 .CW symbols
2517 uses the regular expression supplied by
2518 .I string
2519 to search the symbol table for symbols whose name matches the
2520 regular expression.
2521 .Ex
2522 acid: symbols("main")
2523 main    T       0x00001020
2524 _main   T       0x0000623c
2525 .Ee
2526 .\"
2527 .\"
2528 .\"
2529 .Ip \f(CW{}\fP win "" "Start new process in a window
2530 .CW win
2531 performs exactly the same function as
2532 .CW new
2533 but uses the window system to create a new window for the debugged process.
2534 The variable
2535 .CW progargs
2536 supplies arguments to the new process.
2537 The environment variable
2538 .CW $8½srv
2539 must be set to allow the interpreter to locate the mount channel for the
2540 window system.
2541 The window is created in the top left corner of the screen and is
2542 400x600 pixels in size. The
2543 .CW win
2544 function may be modified to alter the geometry.
2545 The window system will not be able to deliver notes in the new window
2546 since the pid of the created process is not passed when the server is
2547 mounted to create a new window.
2548 .Ex
2549 acid: win()
2550 .Ee