1426d2b71SDavid du Colombier.HTML "Acid Manual 2bd389b36SDavid du Colombier.am DS 3bd389b36SDavid du Colombier.ft I 4bd389b36SDavid du Colombier.. 5bd389b36SDavid du Colombier.ta 1i 2.3i 4.5i (optional to set tabs) 6bd389b36SDavid du Colombier.TL 7219b2ee8SDavid du ColombierAcid Manual 8bd389b36SDavid du Colombier.AU 9bd389b36SDavid du ColombierPhil Winterbottom 107dd7cddfSDavid du Colombierphilw@plan9.bell-labs.com 11bd389b36SDavid du Colombier.SH 12bd389b36SDavid du ColombierIntroduction 13bd389b36SDavid du Colombier.PP 14bd389b36SDavid du ColombierAcid is a general purpose, source level symbolic debugger. 15bd389b36SDavid du ColombierThe debugger is built around a simple command language. 16219b2ee8SDavid du ColombierThe command language, distinct from the language of the program being debugged, 17219b2ee8SDavid du Colombierprovides a flexible user interface that allows the debugger 18bd389b36SDavid du Colombierinterface to be customized for a specific application or architecture. 19bd389b36SDavid du ColombierMoreover, it provides an opportunity to write test and 20bd389b36SDavid du Colombierverification code independently of a program's source code. 21bd389b36SDavid du ColombierAcid is able to debug multiple 22219b2ee8SDavid du Colombierprocesses provided they share a common set of symbols, such as the processes in 237dd7cddfSDavid du Colombiera threaded program. 24bd389b36SDavid du Colombier.PP 25219b2ee8SDavid du ColombierLike other language-based solutions, Acid presents a poor user interface but 26219b2ee8SDavid du Colombierprovides a powerful debugging tool. 27219b2ee8SDavid du ColombierApplication of Acid to hard problems is best approached by writing functions off-line 28219b2ee8SDavid du Colombier(perhaps loading them with the 29219b2ee8SDavid du Colombier.CW include 30219b2ee8SDavid du Colombierfunction or using the support provided by 31219b2ee8SDavid du Colombier.I acme (1)), 32219b2ee8SDavid du Colombierrather than by trying to type intricate Acid operations 33219b2ee8SDavid du Colombierat the interactive prompt. 34bd389b36SDavid du Colombier.PP 35bd389b36SDavid du ColombierAcid allows the execution of a program to be controlled by operating on its 36bd389b36SDavid du Colombierstate while it is stopped and by monitoring and controlling its execution 37219b2ee8SDavid du Colombierwhen it is running. Each program action that causes a change 38219b2ee8SDavid du Colombierof execution state is reflected by the execution 39219b2ee8SDavid du Colombierof an Acid function, which may be user defined. 40bd389b36SDavid du ColombierA library of default functions provides the functionality of a normal debugger. 41bd389b36SDavid du Colombier.PP 42bd389b36SDavid du ColombierA Plan 9 process is controlled by writing messages to a control file in the 43219b2ee8SDavid du Colombier.I proc (3) 44219b2ee8SDavid du Colombierfile system. Each control message has a corresponding Acid function, which 45219b2ee8SDavid du Colombiersends the message to the process. These functions take a process id 46219b2ee8SDavid du Colombier.I pid ) ( 47219b2ee8SDavid du Colombieras an 48bd389b36SDavid du Colombierargument. The memory and text file of the program may be manipulated using 49219b2ee8SDavid du Colombierthe indirection operators. The symbol table, including source cross reference, 50219b2ee8SDavid du Colombieris available to an Acid program. The combination allows complex operations 51bd389b36SDavid du Colombierto be performed both in terms of control flow and data manipulation. 52219b2ee8SDavid du Colombier.SH 53219b2ee8SDavid du ColombierInput format and \f(CWwhatis\fP 54bd389b36SDavid du Colombier.PP 55219b2ee8SDavid du ColombierComments start with 56219b2ee8SDavid du Colombier.CW // 57219b2ee8SDavid du Colombierand continue to the end of the line. 58219b2ee8SDavid du ColombierInput is a series of statements and expressions separated by semicolons. 59219b2ee8SDavid du ColombierAt the top level of the interpreter, the builtin function 60219b2ee8SDavid du Colombier.CW print 61219b2ee8SDavid du Colombieris called automatically to display the result of all expressions except function calls. 62219b2ee8SDavid du ColombierA unary 63219b2ee8SDavid du Colombier.CW + 64219b2ee8SDavid du Colombiermay be used as a shorthand to force the result of a function call to be printed. 65219b2ee8SDavid du Colombier.PP 66219b2ee8SDavid du ColombierAlso at the top level, newlines are treated as semicolons 67219b2ee8SDavid du Colombierby the parser, so semicolons are unnecessary when evaluating expressions. 68219b2ee8SDavid du Colombier.PP 69219b2ee8SDavid du ColombierWhen Acid starts, it loads the default program modules, 70219b2ee8SDavid du Colombierenters interactive mode, and prints a prompt. In this state Acid accepts 71219b2ee8SDavid du Colombiereither function definitions or statements to be evaluated. 72219b2ee8SDavid du ColombierIn this interactive mode 73219b2ee8SDavid du Colombierstatements are evaluated immediately, while function definitions are 74219b2ee8SDavid du Colombierstored for later invocation. 75219b2ee8SDavid du Colombier.PP 76219b2ee8SDavid du ColombierThe 77219b2ee8SDavid du Colombier.CW whatis 78219b2ee8SDavid du Colombieroperator can be used to report the state of identifiers known to the interpreter. 79219b2ee8SDavid du ColombierWith no argument, 80219b2ee8SDavid du Colombier.CW whatis 81219b2ee8SDavid du Colombierreports the name of all defined Acid functions; when supplied with an identifier 82219b2ee8SDavid du Colombieras an argument it reports any variable, function, or type definition 83219b2ee8SDavid du Colombierassociated with the identifier. 84219b2ee8SDavid du ColombierBecause of the way the interpreter handles semicolons, 85219b2ee8SDavid du Colombierthe result of a 86219b2ee8SDavid du Colombier.CW whatis 87219b2ee8SDavid du Colombierstatement can be returned directly to Acid without adding semicolons. 88219b2ee8SDavid du ColombierA syntax error or interrupt returns Acid to the normal evaluation 89219b2ee8SDavid du Colombiermode; any partially evaluated definitions are lost. 90bd389b36SDavid du Colombier.SH 91bd389b36SDavid du ColombierUsing the Library Functions 92bd389b36SDavid du Colombier.PP 93219b2ee8SDavid du ColombierAfter loading the program binary, Acid loads the portable and architecture-specific 94219b2ee8SDavid du Colombierlibrary functions that form the standard debugging environment. 95219b2ee8SDavid du ColombierThese files are Acid source code and are human-readable. 96bd389b36SDavid du ColombierThe following example uses the standard debugging library to show how 97bd389b36SDavid du Colombierlanguage and program interact: 98bd389b36SDavid du Colombier.P1 99bd389b36SDavid du Colombier% acid /bin/ls 100bd389b36SDavid du Colombier/bin/ls:mips plan 9 executable 101219b2ee8SDavid du Colombier 102219b2ee8SDavid du Colombier/sys/lib/acid/port 103219b2ee8SDavid du Colombier/sys/lib/acid/mips 104bd389b36SDavid du Colombieracid: new() 105219b2ee8SDavid du Colombier75721: system call _main ADD $-0x14,R29 106219b2ee8SDavid du Colombier75721: breakpoint main+0x4 MOVW R31,0x0(R29) 107bd389b36SDavid du Colombieracid: bpset(ls) 108bd389b36SDavid du Colombieracid: cont() 109219b2ee8SDavid du Colombier75721: breakpoint ls ADD $-0x16c8,R29 110bd389b36SDavid du Colombieracid: stk() 111219b2ee8SDavid du ColombierAt pc:0x0000141c:ls /sys/src/cmd/ls.c:87 112219b2ee8SDavid du Colombierls(s=0x0000004d,multi=0x00000000) /sys/src/cmd/ls.c:87 113219b2ee8SDavid du Colombier called from main+0xf4 /sys/src/cmd/ls.c:79 114219b2ee8SDavid du Colombiermain(argc=0x00000000,argv=0x7ffffff0) /sys/src/cmd/ls.c:48 115219b2ee8SDavid du Colombier called from _main+0x20 /sys/src/libc/mips/main9.s:10 116219b2ee8SDavid du Colombieracid: PC 117bd389b36SDavid du Colombier0xc0000f60 118219b2ee8SDavid du Colombieracid: *PC 119219b2ee8SDavid du Colombier0x0000141c 120219b2ee8SDavid du Colombieracid: ls 121219b2ee8SDavid du Colombier0x0000141c 122bd389b36SDavid du Colombier.P2 123219b2ee8SDavid du ColombierThe function 124bd389b36SDavid du Colombier.CW new() 125bd389b36SDavid du Colombiercreates a new process and stops it at the first instruction. 126219b2ee8SDavid du ColombierThis change in state is reported by a call to the 127219b2ee8SDavid du ColombierAcid function 128219b2ee8SDavid du Colombier.CW stopped , 129219b2ee8SDavid du Colombierwhich is called by the interpreter whenever the debugged program stops. 130bd389b36SDavid du Colombier.CW Stopped 131bd389b36SDavid du Colombierprints the status line giving the pid, the reason the program stopped 132bd389b36SDavid du Colombierand the address and instruction at the current PC. 133bd389b36SDavid du ColombierThe function 134bd389b36SDavid du Colombier.CW bpset 135bd389b36SDavid du Colombiermakes an entry in the breakpoint table and plants a breakpoint in memory. 136bd389b36SDavid du ColombierThe 137bd389b36SDavid du Colombier.CW cont 138bd389b36SDavid du Colombierfunction continues the process, allowing it to run until some condition 139bd389b36SDavid du Colombiercauses it to stop. In this case the program hits the breakpoint placed on 140219b2ee8SDavid du Colombierthe function 141219b2ee8SDavid du Colombier.CW ls 142219b2ee8SDavid du Colombierin the C program. Once again the 143bd389b36SDavid du Colombier.CW stopped 144bd389b36SDavid du Colombierroutine is called to print the status of the program. The function 145bd389b36SDavid du Colombier.CW stk 146bd389b36SDavid du Colombierprints a C stack trace of the current process. It is implemented using 147219b2ee8SDavid du Colombiera builtin Acid function that returns the stack trace as a list; the code 148219b2ee8SDavid du Colombierthat formats the information is all written in Acid. 149219b2ee8SDavid du ColombierThe Acid variable 150219b2ee8SDavid du Colombier.CW PC 151219b2ee8SDavid du Colombierholds the address of the 152219b2ee8SDavid du Colombiercell where the current value of the processor register 153219b2ee8SDavid du Colombier.CW PC 154219b2ee8SDavid du Colombieris stored. By indirecting through 155219b2ee8SDavid du Colombierthe value of 156219b2ee8SDavid du Colombier.CW PC 157219b2ee8SDavid du Colombierthe address where the program is stopped can be found. 158bd389b36SDavid du ColombierAll of the processor registers are available by the same mechanism. 159bd389b36SDavid du Colombier.SH 160bd389b36SDavid du ColombierTypes 161bd389b36SDavid du Colombier.PP 162219b2ee8SDavid du ColombierAn Acid variable has one of four types: 163bd389b36SDavid du Colombier.I integer , 164bd389b36SDavid du Colombier.I float , 165219b2ee8SDavid du Colombier.I list , 166bd389b36SDavid du Colombieror 167bd389b36SDavid du Colombier.I string . 168bd389b36SDavid du ColombierThe type of a variable is inferred from the type of the right-hand 169219b2ee8SDavid du Colombierside of the assignment expression which last set its value. 170219b2ee8SDavid du ColombierReferencing a variable that has not yet 171219b2ee8SDavid du Colombierbeen assigned draws a "used but not set" error. Many of the operators may 172bd389b36SDavid du Colombierbe applied to more than 173bd389b36SDavid du Colombierone type; for these operators the action of the operator is determined by 174bd389b36SDavid du Colombierthe types of its operands. The action of each operator is defined in the 175219b2ee8SDavid du Colombier.I Expressions 176219b2ee8SDavid du Colombiersection of this manual. 177bd389b36SDavid du Colombier.SH 178bd389b36SDavid du ColombierVariables 179bd389b36SDavid du Colombier.PP 180bd389b36SDavid du ColombierAcid has three kinds of variables: variables defined by the symbol table 181219b2ee8SDavid du Colombierof the debugged program, variables that are defined and maintained 182219b2ee8SDavid du Colombierby the interpreter as the debugged program changes state, and variables 183219b2ee8SDavid du Colombierdefined and used by Acid programs. 184bd389b36SDavid du Colombier.PP 185219b2ee8SDavid du ColombierSome examples of variables maintained by the interpreter are the register 186219b2ee8SDavid du Colombierpointers listed by name in the Acid list variable 187bd389b36SDavid du Colombier.CW registers , 188219b2ee8SDavid du Colombierand the symbol table listed by name and contents in the Acid variable 189bd389b36SDavid du Colombier.CW symbols . 190bd389b36SDavid du Colombier.PP 191bd389b36SDavid du ColombierThe variable 192bd389b36SDavid du Colombier.CW pid 193219b2ee8SDavid du Colombieris updated by the interpreter to select the most recently created process 194219b2ee8SDavid du Colombieror the process selected by the 195bd389b36SDavid du Colombier.CW setproc 196bd389b36SDavid du Colombierbuiltin function. 197bd389b36SDavid du Colombier.SH 1 198bd389b36SDavid du ColombierFormats 199bd389b36SDavid du Colombier.PP 200bd389b36SDavid du ColombierIn addition to a type, variables have formats. The format is a code 201bd389b36SDavid du Colombierletter that determines the printing style and the effect of some of the 202bd389b36SDavid du Colombieroperators on that variable. The format codes are derived from the format 203219b2ee8SDavid du Colombierletters used by 204219b2ee8SDavid du Colombier.I db (1). 205219b2ee8SDavid du ColombierBy default, symbol table variables and numeric constants 206219b2ee8SDavid du Colombierare assigned the format code 207219b2ee8SDavid du Colombier.CW X , 208219b2ee8SDavid du Colombierwhich specifies 32-bit hexadecimal. 209bd389b36SDavid du ColombierPrinting a variable with this code yields the output 210bd389b36SDavid du Colombier.CW 0x00123456 . 211bd389b36SDavid du ColombierThe format code of a variable may be changed from the default by using the 212bd389b36SDavid du Colombierbuiltin function 213bd389b36SDavid du Colombier.CW fmt . 214bd389b36SDavid du ColombierThis function takes two arguments, an expression and a format code. After 215bd389b36SDavid du Colombierthe expression is evaluated the new format code is attached to the result 216bd389b36SDavid du Colombierand forms the return value from 217bd389b36SDavid du Colombier.CW fmt . 218219b2ee8SDavid du ColombierThe backslash operator is a short form of 219219b2ee8SDavid du Colombier.CW fmt . 220219b2ee8SDavid du ColombierThe format supplied by the backslash operator must be the format character 221219b2ee8SDavid du Colombierrather than an expression. 222bd389b36SDavid du ColombierIf the result is assigned to a variable the new format code is maintained 223bd389b36SDavid du Colombierin the variable. For example: 224bd389b36SDavid du Colombier.P1 225bd389b36SDavid du Colombieracid: x=10 226bd389b36SDavid du Colombieracid: print(x) 227bd389b36SDavid du Colombier0x0000000a 228bd389b36SDavid du Colombieracid: x = fmt(x, 'D') 229bd389b36SDavid du Colombieracid: print(x, fmt(x, 'X')) 230bd389b36SDavid du Colombier10 0x0000000a 231219b2ee8SDavid du Colombieracid: x 232bd389b36SDavid du Colombier10 233219b2ee8SDavid du Colombieracid: x\eo 234219b2ee8SDavid du Colombier12 235bd389b36SDavid du Colombier.P2 236bd389b36SDavid du ColombierThe supported format characters are: 237bd389b36SDavid du Colombier.RS 238bd389b36SDavid du Colombier.IP \f(CWo\fP 239bd389b36SDavid du ColombierPrint two-byte integer in octal. 240bd389b36SDavid du Colombier.IP \f(CWO\fP 241bd389b36SDavid du ColombierPrint four-byte integer in octal. 242bd389b36SDavid du Colombier.IP \f(CWq\fP 243219b2ee8SDavid du ColombierPrint two-byte integer in signed octal. 244bd389b36SDavid du Colombier.IP \f(CWQ\fP 245219b2ee8SDavid du ColombierPrint four-byte integer in signed octal. 246219b2ee8SDavid du Colombier.IP \f(CWB\fP 247219b2ee8SDavid du ColombierPrint four-byte integer in binary. 248bd389b36SDavid du Colombier.IP \f(CWd\fP 249219b2ee8SDavid du ColombierPrint two-byte integer in signed decimal. 250bd389b36SDavid du Colombier.IP \f(CWD\fP 251219b2ee8SDavid du ColombierPrint four-byte integer in signed decimal. 2525ede6b93SDavid du Colombier.IP \f(CWV\fP 2537dd7cddfSDavid du ColombierPrint eight-byte integer in signed decimal. 2547dd7cddfSDavid du Colombier.IP \f(CWZ\fP 2557dd7cddfSDavid du ColombierPrint eight-byte integer in unsigned decimal. 256bd389b36SDavid du Colombier.IP \f(CWx\fP 257219b2ee8SDavid du ColombierPrint two-byte integer in hexadecimal. 258bd389b36SDavid du Colombier.IP \f(CWX\fP 259219b2ee8SDavid du ColombierPrint four-byte integer in hexadecimal. 2607dd7cddfSDavid du Colombier.IP \f(CWY\fP 2617dd7cddfSDavid du ColombierPrint eight-byte integer in hexadecimal. 262bd389b36SDavid du Colombier.IP \f(CWu\fP 263219b2ee8SDavid du ColombierPrint two-byte integer in unsigned decimal. 264bd389b36SDavid du Colombier.IP \f(CWU\fP 265219b2ee8SDavid du ColombierPrint four-byte integer in unsigned decimal. 266bd389b36SDavid du Colombier.IP \f(CWf\fP 267bd389b36SDavid du ColombierPrint single-precision floating point number. 268bd389b36SDavid du Colombier.IP \f(CWF\fP 269219b2ee8SDavid du ColombierPrint double-precision floating point number. 270219b2ee8SDavid du Colombier.IP \f(CWg\fP 271219b2ee8SDavid du ColombierPrint a single precision floating point number in string format. 272219b2ee8SDavid du Colombier.IP \f(CWG\fP 273219b2ee8SDavid du ColombierPrint a double precision floating point number in string format. 274bd389b36SDavid du Colombier.IP \f(CWb\fP 275219b2ee8SDavid du ColombierPrint byte in hexadecimal. 276bd389b36SDavid du Colombier.IP \f(CWc\fP 277219b2ee8SDavid du ColombierPrint byte as an ASCII character. 278bd389b36SDavid du Colombier.IP \f(CWC\fP 279219b2ee8SDavid du ColombierLike 280219b2ee8SDavid du Colombier.CW c , 281219b2ee8SDavid du Colombierwith 282219b2ee8SDavid du Colombierprintable ASCII characters represented normally and 283219b2ee8SDavid du Colombierothers printed in the form \f(CW\ex\fInn\fR. 284bd389b36SDavid du Colombier.IP \f(CWs\fP 285219b2ee8SDavid du ColombierInterpret the addressed bytes as UTF characters 286219b2ee8SDavid du Colombierand print successive characters until a zero byte is reached. 287bd389b36SDavid du Colombier.IP \f(CWr\fP 288219b2ee8SDavid du ColombierPrint a two-byte integer as a rune. 289bd389b36SDavid du Colombier.IP \f(CWR\fP 290219b2ee8SDavid du ColombierPrint successive two-byte integers as runes 291bd389b36SDavid du Colombieruntil a zero rune is reached. 292bd389b36SDavid du Colombier.IP \f(CWi\fP 293bd389b36SDavid du ColombierPrint as machine instructions. 294bd389b36SDavid du Colombier.IP \f(CWI\fP 295219b2ee8SDavid du ColombierAs 296219b2ee8SDavid du Colombier.CW i 297219b2ee8SDavid du Colombierabove, but print the machine instructions in 298219b2ee8SDavid du Colombieran alternate form if possible: 299219b2ee8SDavid du Colombier.CW sunsparc 300219b2ee8SDavid du Colombierand 301219b2ee8SDavid du Colombier.CW mipsco 302bd389b36SDavid du Colombierreproduce the manufacturers' syntax. 303bd389b36SDavid du Colombier.IP \f(CWa\fP 304bd389b36SDavid du ColombierPrint the value in symbolic form. 305bd389b36SDavid du Colombier.RE 306219b2ee8SDavid du Colombier.SH 307219b2ee8SDavid du ColombierComplex types 308219b2ee8SDavid du Colombier.PP 309219b2ee8SDavid du ColombierAcid permits the definition of the layout of memory. 310219b2ee8SDavid du ColombierThe usual method is to use the 311219b2ee8SDavid du Colombier.CW -a 312219b2ee8SDavid du Colombierflag of the compilers to produce Acid-language descriptions of data structures (see 3137dd7cddfSDavid du Colombier.I 2c (1)) 314219b2ee8SDavid du Colombieralthough such definitions can be typed interactively. 315219b2ee8SDavid du ColombierThe keywords 316219b2ee8SDavid du Colombier.CW complex , 317219b2ee8SDavid du Colombier.CW adt , 318219b2ee8SDavid du Colombier.CW aggr , 319219b2ee8SDavid du Colombierand 320219b2ee8SDavid du Colombier.CW union 321219b2ee8SDavid du Colombierare all equivalent; the compiler uses the synonyms to document the declarations. 322219b2ee8SDavid du ColombierA complex type is described as a set of members, each containing a format letter, 323219b2ee8SDavid du Colombieran offset in the structure, and a name. For example, the C structure 324219b2ee8SDavid du Colombier.P1 325219b2ee8SDavid du Colombierstruct List { 326219b2ee8SDavid du Colombier int type; 327219b2ee8SDavid du Colombier struct List *next; 328219b2ee8SDavid du Colombier}; 329219b2ee8SDavid du Colombier.P2 330219b2ee8SDavid du Colombieris described by the Acid statement 331219b2ee8SDavid du Colombier.P1 332219b2ee8SDavid du Colombiercomplex List { 333219b2ee8SDavid du Colombier 'D' 0 type; 334219b2ee8SDavid du Colombier 'X' 4 next; 335219b2ee8SDavid du Colombier}; 336219b2ee8SDavid du Colombier.P2 337219b2ee8SDavid du Colombier.SH 338bd389b36SDavid du ColombierScope 339bd389b36SDavid du Colombier.PP 340bd389b36SDavid du ColombierVariables are global unless they are either parameters to functions 341bd389b36SDavid du Colombieror are declared as 342bd389b36SDavid du Colombier.CW local 343bd389b36SDavid du Colombierin a function body. Parameters and local variables are available only in 344219b2ee8SDavid du Colombierthe body of the function in which they are instantiated. 345219b2ee8SDavid du ColombierVariables are dynamically bound: if a function declares a local variable 346219b2ee8SDavid du Colombierwith the same name as a global variable, the global variable will be hidden 347219b2ee8SDavid du Colombierwhenever the function is executing. 348219b2ee8SDavid du ColombierFor example, if a function 349219b2ee8SDavid du Colombier.CW f 350219b2ee8SDavid du Colombierhas a local called 351219b2ee8SDavid du Colombier.CW main , 352219b2ee8SDavid du Colombierany function called below 353219b2ee8SDavid du Colombier.CW f 354219b2ee8SDavid du Colombierwill see the local version of 355219b2ee8SDavid du Colombier.CW main , 356219b2ee8SDavid du Colombiernot the external symbol. 357bd389b36SDavid du Colombier.SH 1 358bd389b36SDavid du ColombierAddressing 359bd389b36SDavid du Colombier.PP 360219b2ee8SDavid du ColombierSince the symbol table specifies addresses, 361219b2ee8SDavid du Colombierto access the value of program variables 362219b2ee8SDavid du Colombieran extra level of indirection 363219b2ee8SDavid du Colombieris required relative to the source code. 364219b2ee8SDavid du ColombierFor consistency, the registers are maintained as pointers as well; Acid variables with the names 365219b2ee8SDavid du Colombierof processor registers point to cells holding the saved registers. 366219b2ee8SDavid du Colombier.PP 367219b2ee8SDavid du ColombierThe location in a file or memory image associated with 368219b2ee8SDavid du Colombieran address is calculated from a map 369219b2ee8SDavid du Colombierassociated with the file. 370219b2ee8SDavid du ColombierEach map contains one or more quadruples (\c 371219b2ee8SDavid du Colombier.I t , 372219b2ee8SDavid du Colombier.I b , 373219b2ee8SDavid du Colombier.I e , 374219b2ee8SDavid du Colombier.I f \|), 375219b2ee8SDavid du Colombierdefining a segment named 376219b2ee8SDavid du Colombier.I t 377219b2ee8SDavid du Colombier(usually 378219b2ee8SDavid du Colombier.CW text , 379219b2ee8SDavid du Colombier.CW data , 3807dd7cddfSDavid du Colombier.CW regs , 381219b2ee8SDavid du Colombieror 3827dd7cddfSDavid du Colombier.CW fpregs ) 383219b2ee8SDavid du Colombiermapping addresses in the range 384219b2ee8SDavid du Colombier.I b 385219b2ee8SDavid du Colombierthrough 386219b2ee8SDavid du Colombier.I e 387219b2ee8SDavid du Colombierto the part of the file 388219b2ee8SDavid du Colombierbeginning at 389219b2ee8SDavid du Colombieroffset 390219b2ee8SDavid du Colombier.I f . 391219b2ee8SDavid du ColombierThe memory model of a Plan 9 process assumes 392219b2ee8SDavid du Colombierthat segments are disjoint. There 393219b2ee8SDavid du Colombiercan be more than one segment of a given type (e.g., a process 394219b2ee8SDavid du Colombiermay have more than one text segment) but segments 395219b2ee8SDavid du Colombiermay not overlap. 396219b2ee8SDavid du ColombierAn address 397219b2ee8SDavid du Colombier.I a 398219b2ee8SDavid du Colombieris translated 399219b2ee8SDavid du Colombierto a file address 400219b2ee8SDavid du Colombierby finding a segment 401219b2ee8SDavid du Colombierfor which 402219b2ee8SDavid du Colombier.I b 403219b2ee8SDavid du Colombier+ 404219b2ee8SDavid du Colombier.I a 405219b2ee8SDavid du Colombier< 406219b2ee8SDavid du Colombier.I e ; 407219b2ee8SDavid du Colombierthe location in the file 408219b2ee8SDavid du Colombieris then 409219b2ee8SDavid du Colombier.I address 410219b2ee8SDavid du Colombier+ 411219b2ee8SDavid du Colombier.I f 412219b2ee8SDavid du Colombier\- 413219b2ee8SDavid du Colombier.I b . 414219b2ee8SDavid du Colombier.PP 415219b2ee8SDavid du ColombierUsually, 416219b2ee8SDavid du Colombierthe text and initialized data of a program 417219b2ee8SDavid du Colombierare mapped by segments called 418219b2ee8SDavid du Colombier.CW text 419219b2ee8SDavid du Colombierand 420219b2ee8SDavid du Colombier.CW data . 4217dd7cddfSDavid du ColombierSince a program file does not contain bss, stack, or register data, 422219b2ee8SDavid du Colombierthese data are 423219b2ee8SDavid du Colombiernot mapped by the data segment. 424219b2ee8SDavid du ColombierThe text segment is mapped similarly in the memory image of 425219b2ee8SDavid du Colombiera normal (i.e., non-kernel) process. 426219b2ee8SDavid du ColombierHowever, the segment called 427219b2ee8SDavid du Colombier.CW *data 4287dd7cddfSDavid du Colombiermaps memory from the beginning to the end of the program's data space. 429219b2ee8SDavid du ColombierThis region contains the program's static data, the bss, the 430219b2ee8SDavid du Colombierheap and the stack. A segment 431219b2ee8SDavid du Colombiercalled 4327dd7cddfSDavid du Colombier.CW *regs 4337dd7cddfSDavid du Colombiermaps the registers; 4347dd7cddfSDavid du Colombier.CW *fpregs 4357dd7cddfSDavid du Colombiermaps the floating point registers. 436219b2ee8SDavid du Colombier.PP 437219b2ee8SDavid du ColombierSometimes it is useful to define a map with a single segment 438219b2ee8SDavid du Colombiermapping the region from 0 to 0xFFFFFFFF; such a map 439219b2ee8SDavid du Colombierallows the entire file to be examined 440219b2ee8SDavid du Colombierwithout address translation. The builtin function 441219b2ee8SDavid du Colombier.CW map 442219b2ee8SDavid du Colombierexamines and modifies Acid's map for a process. 443bd389b36SDavid du Colombier.SH 1 444bd389b36SDavid du ColombierName Conflicts 445bd389b36SDavid du Colombier.PP 446219b2ee8SDavid du ColombierName conflicts between keywords in the Acid language, symbols in the program, 447bd389b36SDavid du Colombierand previously defined functions are resolved when the interpreter starts up. 448219b2ee8SDavid du ColombierEach name is made unique by prefixing enough 449bd389b36SDavid du Colombier.CW $ 450bd389b36SDavid du Colombiercharacters to the front of the name to make it unique. Acid reports 451219b2ee8SDavid du Colombiera list of each name change at startup. The report looks like this: 452bd389b36SDavid du Colombier.P1 453bd389b36SDavid du Colombier/bin/sam: mips plan 9 executable 454bd389b36SDavid du Colombier/lib/acid/port 455bd389b36SDavid du Colombier/lib/acid/mips 456bd389b36SDavid du ColombierSymbol renames: 457bd389b36SDavid du Colombier append=$append T/0xa4e40 458bd389b36SDavid du Colombieracid: 459bd389b36SDavid du Colombier.P2 460219b2ee8SDavid du ColombierThe symbol 461219b2ee8SDavid du Colombier.CW append 462219b2ee8SDavid du Colombieris both a keyword and a text symbol in the program. The message reports 463bd389b36SDavid du Colombierthat the text symbol is now named 464bd389b36SDavid du Colombier.CW $append . 465bd389b36SDavid du Colombier.SH 466bd389b36SDavid du ColombierExpressions 467bd389b36SDavid du Colombier.PP 468219b2ee8SDavid du ColombierOperators have the same 4697dd7cddfSDavid du Colombierbinding and precedence as in C. 470219b2ee8SDavid du ColombierFor operators of equal precedence, expressions are evaluated from left to right. 471bd389b36SDavid du Colombier.SH 1 472bd389b36SDavid du ColombierBoolean expressions 473bd389b36SDavid du Colombier.PP 474bd389b36SDavid du ColombierIf an expression is evaluated for a boolean condition the test 475bd389b36SDavid du Colombierperformed depends on the type of the result. If the result is of 476bd389b36SDavid du Colombier.I integer 477bd389b36SDavid du Colombieror 478bd389b36SDavid du Colombier.I floating 479bd389b36SDavid du Colombiertype the result is true if the value is non-zero. If the expression is a 480219b2ee8SDavid du Colombier.I list 481bd389b36SDavid du Colombierthe result is true if there are any members in the list. 482bd389b36SDavid du ColombierIf the expression is a 483bd389b36SDavid du Colombier.I string 484bd389b36SDavid du Colombierthe result is true if there are any characters in the string. 485bd389b36SDavid du Colombier.DS 486bd389b36SDavid du Colombier primary-expression: 487bd389b36SDavid du Colombier identifier 488bd389b36SDavid du Colombier identifier \f(CW:\fP identifier 489bd389b36SDavid du Colombier constant 490bd389b36SDavid du Colombier \f(CW(\fP expression \f(CW)\fP 491bd389b36SDavid du Colombier \f(CW{\fP elist \f(CW}\fP 492bd389b36SDavid du Colombier 493bd389b36SDavid du Colombier elist: 494bd389b36SDavid du Colombier expression 495bd389b36SDavid du Colombier elist , expression 496bd389b36SDavid du Colombier.DE 497219b2ee8SDavid du ColombierAn identifier may be any legal Acid variable. The colon operator returns the 498219b2ee8SDavid du Colombieraddress of parameters or local variables in the current stack of a program. 499219b2ee8SDavid du ColombierFor example: 500bd389b36SDavid du Colombier.P1 501219b2ee8SDavid du Colombier*main:argc 502bd389b36SDavid du Colombier.P2 503219b2ee8SDavid du Colombierprints the number of arguments passed into main. Local variables and parameters 504219b2ee8SDavid du Colombiercan only be referenced after the frame has been established. It may be necessary to 505219b2ee8SDavid du Colombierstep a program over the first few instructions of a breakpointed function to properly set 506bd389b36SDavid du Colombierthe frame. 507bd389b36SDavid du Colombier.PP 508219b2ee8SDavid du ColombierConstants follow the same lexical rules as C. 509219b2ee8SDavid du ColombierA list of expressions delimited by braces forms a list constructor. 510219b2ee8SDavid du ColombierA new list is produced by evaluating each expression when the constructor is executed. 511bd389b36SDavid du ColombierThe empty list is formed from 512bd389b36SDavid du Colombier.CW {} . 513bd389b36SDavid du Colombier.P1 514bd389b36SDavid du Colombieracid: x = 10 515219b2ee8SDavid du Colombieracid: l = { 1, x, 2\eD } 516bd389b36SDavid du Colombieracid: x = 20 517219b2ee8SDavid du Colombieracid: l 518219b2ee8SDavid du Colombier{0x00000001 , 0x0000000a , 2 } 519bd389b36SDavid du Colombier.P2 520bd389b36SDavid du Colombier.SH 1 521bd389b36SDavid du ColombierLists 522bd389b36SDavid du Colombier.PP 523bd389b36SDavid du ColombierSeveral operators manipulate lists. 524bd389b36SDavid du Colombier.DS 525bd389b36SDavid du Colombier list-expression: 526bd389b36SDavid du Colombier primary-expression 527bd389b36SDavid du Colombier \f(CWhead\fP primary-expression 528bd389b36SDavid du Colombier \f(CWtail\fP primary-expression 529bd389b36SDavid du Colombier \f(CWappend\fP expression \f(CW,\fP primary-expression 530bd389b36SDavid du Colombier \f(CWdelete\fP expression \f(CW,\fP primary-expression 531bd389b36SDavid du Colombier.DE 532bd389b36SDavid du ColombierThe 533bd389b36SDavid du Colombier.I primary-expression 534219b2ee8SDavid du Colombierfor 535219b2ee8SDavid du Colombier.CW head 536219b2ee8SDavid du Colombierand 537219b2ee8SDavid du Colombier.CW tail 538219b2ee8SDavid du Colombiermust yield a value of type 539bd389b36SDavid du Colombier.I list . 540bd389b36SDavid du ColombierIf there are no elements in the list the value of 541219b2ee8SDavid du Colombier.CW head 542bd389b36SDavid du Colombieror 543219b2ee8SDavid du Colombier.CW tail 544bd389b36SDavid du Colombierwill be the empty list. Otherwise 545bd389b36SDavid du Colombier.CW head 546bd389b36SDavid du Colombierevaluates to the first element of the list and 547bd389b36SDavid du Colombier.CW tail 548bd389b36SDavid du Colombierevaluates to the rest. 549bd389b36SDavid du Colombier.P1 550219b2ee8SDavid du Colombieracid: head {} 551bd389b36SDavid du Colombier{} 552219b2ee8SDavid du Colombieracid: head {1, 2, 3, 4} 553bd389b36SDavid du Colombier0x00000001 554219b2ee8SDavid du Colombieracid: tail {1, 2, 3, 4} 555bd389b36SDavid du Colombier{0x00000002 , 0x00000003 , 0x00000004 } 556bd389b36SDavid du Colombier.P2 557bd389b36SDavid du ColombierThe first operand of 558bd389b36SDavid du Colombier.CW append 559bd389b36SDavid du Colombierand 560bd389b36SDavid du Colombier.CW delete 561219b2ee8SDavid du Colombiermust be an expression that yields a 562bd389b36SDavid du Colombier.I list . 563bd389b36SDavid du Colombier.CW Append 564bd389b36SDavid du Colombierplaces the result of evaluating 565bd389b36SDavid du Colombier.I primary-expression 566bd389b36SDavid du Colombierat the end of the list. 567bd389b36SDavid du ColombierThe 568bd389b36SDavid du Colombier.I primary-expression 569bd389b36SDavid du Colombiersupplied to 570bd389b36SDavid du Colombier.CW delete 571bd389b36SDavid du Colombiermust evaluate to an integer; 572bd389b36SDavid du Colombier.CW delete 573219b2ee8SDavid du Colombierremoves the 574219b2ee8SDavid du Colombier.I n 'th 575219b2ee8SDavid du Colombieritem from the list, where 576219b2ee8SDavid du Colombier.I n 577219b2ee8SDavid du Colombieris integral value of 578219b2ee8SDavid du Colombier.I primary-expression. 579219b2ee8SDavid du ColombierList indices are zero-based. 580bd389b36SDavid du Colombier.P1 581219b2ee8SDavid du Colombier acid: append {1, 2}, 3 582bd389b36SDavid du Colombier {0x00000001 , 0x00000002 , 0x00000003 } 583219b2ee8SDavid du Colombier acid: delete {1, 2, 3}, 1 584bd389b36SDavid du Colombier {0x00000001 , 0x00000003 } 585bd389b36SDavid du Colombier.P2 586bd389b36SDavid du Colombier.PP 587219b2ee8SDavid du ColombierAssigning a list to a variable copies a reference to the list; if a list variable 588219b2ee8SDavid du Colombieris copied it still points at the same list. To copy a list, the elements must 589219b2ee8SDavid du Colombierbe copied piecewise using 590219b2ee8SDavid du Colombier.CW head 591219b2ee8SDavid du Colombierand 592219b2ee8SDavid du Colombier.CW append . 593bd389b36SDavid du Colombier.SH 1 594bd389b36SDavid du ColombierOperators 595bd389b36SDavid du Colombier.PP 596bd389b36SDavid du Colombier.DS 597bd389b36SDavid du Colombier postfix-expression: 598bd389b36SDavid du Colombier list-expression 599bd389b36SDavid du Colombier postfix-expression \f(CW[\fP expression \f(CW]\fP 600bd389b36SDavid du Colombier postfix-expression \f(CW(\fP argument-list \f(CW)\fP 601bd389b36SDavid du Colombier postfix-expression \f(CW.\fP tag 602bd389b36SDavid du Colombier postfix-expression \f(CW->\fP tag 603bd389b36SDavid du Colombier postfix-expression \f(CW++\fP 604bd389b36SDavid du Colombier postfix-expression \f(CW--\fP 605bd389b36SDavid du Colombier 606bd389b36SDavid du Colombier argument-list: 607bd389b36SDavid du Colombier expression 608bd389b36SDavid du Colombier argument-list , expression 609bd389b36SDavid du Colombier.DE 610bd389b36SDavid du ColombierThe 611219b2ee8SDavid du Colombier.CW [ 612219b2ee8SDavid du Colombier.I expression 613219b2ee8SDavid du Colombier.CW ] 614bd389b36SDavid du Colombieroperator performs indexing. 615219b2ee8SDavid du ColombierThe indexing expression must result in an expression of 616219b2ee8SDavid du Colombier.I integer 617219b2ee8SDavid du Colombiertype, say 618219b2ee8SDavid du Colombier.I n . 619bd389b36SDavid du ColombierThe operation depends on the type of 620bd389b36SDavid du Colombier.I postfix-expression . 621bd389b36SDavid du ColombierIf the 622bd389b36SDavid du Colombier.I postfix-expression 623bd389b36SDavid du Colombieryields an 624bd389b36SDavid du Colombier.I integer 625219b2ee8SDavid du Colombierit is assumed to be the base address of an array in the memory image. 626bd389b36SDavid du ColombierThe index offsets into this array; the size of the array members is 627bd389b36SDavid du Colombierdetermined by the format associated with the 628bd389b36SDavid du Colombier.I postfix-expression . 629bd389b36SDavid du ColombierIf the 630bd389b36SDavid du Colombier.I postfix-expression 631bd389b36SDavid du Colombieryields a 632bd389b36SDavid du Colombier.I string 633219b2ee8SDavid du Colombierthe index operator fetches the 634219b2ee8SDavid du Colombier.I n 'th 635219b2ee8SDavid du Colombiercharacter 636bd389b36SDavid du Colombierof the string. If the index points beyond the end 637219b2ee8SDavid du Colombierof the string, a zero is returned. 638bd389b36SDavid du ColombierIf the 639bd389b36SDavid du Colombier.I postfix-expression 640bd389b36SDavid du Colombieryields a 641bd389b36SDavid du Colombier.I list 642219b2ee8SDavid du Colombierthen the indexing operation returns the 643219b2ee8SDavid du Colombier.I n 'th 644219b2ee8SDavid du Colombieritem of the list. 645219b2ee8SDavid du ColombierIf the list contains less than 646219b2ee8SDavid du Colombier.I n 647219b2ee8SDavid du Colombieritems the empty list 648bd389b36SDavid du Colombier.CW {} 649bd389b36SDavid du Colombieris returned. 650bd389b36SDavid du Colombier.PP 651bd389b36SDavid du ColombierThe 652bd389b36SDavid du Colombier.CW ++ 653bd389b36SDavid du Colombierand 654bd389b36SDavid du Colombier.CW -- 655bd389b36SDavid du Colombieroperators increment and decrement integer variables. 656219b2ee8SDavid du ColombierThe amount of increment or decrement depends on the format code. These postfix 657bd389b36SDavid du Colombieroperators return the value of the variable before the increment or decrement 658bd389b36SDavid du Colombierhas taken place. 659bd389b36SDavid du Colombier.DS 660bd389b36SDavid du Colombier unary-expression: 661bd389b36SDavid du Colombier postfix-expression 662bd389b36SDavid du Colombier \f(CW++\fP unary-expression 663bd389b36SDavid du Colombier \f(CW--\fP unary-expression 664bd389b36SDavid du Colombier 665bd389b36SDavid du Colombier unary-operator: one of 666bd389b36SDavid du Colombier \f(CW*\fP \f(CW@\fP \f(CW+\fP \f(CW-\fP ~ \f(CW!\fP 667bd389b36SDavid du Colombier.DE 668bd389b36SDavid du ColombierThe operators 669bd389b36SDavid du Colombier.CW * 670bd389b36SDavid du Colombierand 671bd389b36SDavid du Colombier.CW @ 672bd389b36SDavid du Colombierare the indirection operators. 673bd389b36SDavid du Colombier.CW @ 674bd389b36SDavid du Colombierreferences a value from the text file of the program being debugged. 675bd389b36SDavid du ColombierThe size of the value depends on the format code. The 676bd389b36SDavid du Colombier.CW * 677219b2ee8SDavid du Colombieroperator fetches a value from the memory image of a process. If either 678bd389b36SDavid du Colombieroperator appears on the left-hand side of an assignment statement, either the file 679219b2ee8SDavid du Colombieror memory will be written. The file can only be modified when Acid is invoked 680bd389b36SDavid du Colombierwith the 681219b2ee8SDavid du Colombier.CW -w 682bd389b36SDavid du Colombieroption. 683bd389b36SDavid du ColombierThe prefix 684bd389b36SDavid du Colombier.CW ++ 685bd389b36SDavid du Colombierand 686bd389b36SDavid du Colombier.CW -- 687bd389b36SDavid du Colombieroperators perform the same operation as their postfix counterparts but 688bd389b36SDavid du Colombierreturn the value after the increment or decrement has been performed. Since the 689bd389b36SDavid du Colombier.CW ++ 690bd389b36SDavid du Colombierand 691bd389b36SDavid du Colombier.CW * 692bd389b36SDavid du Colombieroperators fetch and increment the correct amount for the specified format, 693bd389b36SDavid du Colombierthe following function prints correct machine instructions on a machine with 694219b2ee8SDavid du Colombiervariable length instructions, such as the 68020 or 386: 695bd389b36SDavid du Colombier.P1 696bd389b36SDavid du Colombier defn asm(addr) 697bd389b36SDavid du Colombier { 698bd389b36SDavid du Colombier addr = fmt(addr, 'i'); 699bd389b36SDavid du Colombier loop 1, 10 do 700bd389b36SDavid du Colombier print(*addr++, "\en"); 701bd389b36SDavid du Colombier } 702bd389b36SDavid du Colombier.P2 703bd389b36SDavid du ColombierThe operators 704bd389b36SDavid du Colombier.CW ~ 705bd389b36SDavid du Colombierand 706bd389b36SDavid du Colombier.CW ! 707219b2ee8SDavid du Colombierperform bitwise and logical negation respectively. Their operands must be of 708bd389b36SDavid du Colombier.I integer 709bd389b36SDavid du Colombiertype. 710bd389b36SDavid du Colombier.DS 711219b2ee8SDavid du Colombier cast-expression: 712219b2ee8SDavid du Colombier unary-expression 713219b2ee8SDavid du Colombier unary-expression \f(CW\e\fP format-char 714219b2ee8SDavid du Colombier \f(CW(\fP complex-name \f(CW)\fP unary-expression 715219b2ee8SDavid du Colombier.DE 716219b2ee8SDavid du ColombierA unary expression may be preceded by a cast. The cast has the effect of 717219b2ee8SDavid du Colombierassociating the value of 718219b2ee8SDavid du Colombier.I unary-expression 719219b2ee8SDavid du Colombierwith a complex type structure. 720219b2ee8SDavid du ColombierThe result may then be dereferenced using the 721219b2ee8SDavid du Colombier.CW . 722219b2ee8SDavid du Colombierand 723219b2ee8SDavid du Colombier.CW -> 724219b2ee8SDavid du Colombieroperators. 725219b2ee8SDavid du Colombier.PP 726219b2ee8SDavid du ColombierAn Acid variable may be associated with a complex type 727219b2ee8SDavid du Colombierto enable accessing the type's members: 728219b2ee8SDavid du Colombier.P1 729219b2ee8SDavid du Colombieracid: complex List { 730219b2ee8SDavid du Colombier 'D' 0 type; 731219b2ee8SDavid du Colombier 'X' 4 next; 732219b2ee8SDavid du Colombier}; 733219b2ee8SDavid du Colombieracid: complex List lhead 734219b2ee8SDavid du Colombieracid: lhead.type 735219b2ee8SDavid du Colombier10 736219b2ee8SDavid du Colombieracid: lhead = ((List)lhead).next 737219b2ee8SDavid du Colombieracid: lhead.type 738219b2ee8SDavid du Colombier-46 739219b2ee8SDavid du Colombier.P2 740219b2ee8SDavid du ColombierNote that the 741219b2ee8SDavid du Colombier.CW next 742219b2ee8SDavid du Colombierfield cannot be given a complex type automatically. 743219b2ee8SDavid du Colombier.PP 744219b2ee8SDavid du ColombierWhen entered at the top level of the interpreter, 745219b2ee8SDavid du Colombieran expression of complex type 746219b2ee8SDavid du Colombieris treated specially. 747219b2ee8SDavid du ColombierIf the type is called 748219b2ee8SDavid du Colombier.CW T 749219b2ee8SDavid du Colombierand an Acid function also called 750219b2ee8SDavid du Colombier.CW T 751219b2ee8SDavid du Colombierexists, 752219b2ee8SDavid du Colombierthen that function will be called with the expression as its argument. 753219b2ee8SDavid du ColombierThe compiler options 754219b2ee8SDavid du Colombier.CW -a 755219b2ee8SDavid du Colombierand 756219b2ee8SDavid du Colombier.CW -aa 757219b2ee8SDavid du Colombierwill generate Acid source code defining such complex types and functions; see 7587dd7cddfSDavid du Colombier.I 2c (1). 759219b2ee8SDavid du Colombier.PP 760219b2ee8SDavid du ColombierA 761219b2ee8SDavid du Colombier.I unary-expression 762219b2ee8SDavid du Colombiermay be qualified with a format specifier using the 763219b2ee8SDavid du Colombier.CW \e 764219b2ee8SDavid du Colombieroperator. This has the same effect as passing the expression to the 765219b2ee8SDavid du Colombier.CW fmt 766219b2ee8SDavid du Colombierbuiltin function. 767219b2ee8SDavid du Colombier.DS 768bd389b36SDavid du Colombier multiplicative-expression: 769219b2ee8SDavid du Colombier cast-expression 770bd389b36SDavid du Colombier multiplicative-expression \f(CW*\fP multiplicative-expression 771bd389b36SDavid du Colombier multiplicative-expression \f(CW/\fP multiplicative-expression 772bd389b36SDavid du Colombier multiplicative-expression \f(CW%\fP multiplicative-expression 773bd389b36SDavid du Colombier.DE 774219b2ee8SDavid du ColombierThese operate on 775bd389b36SDavid du Colombier.I integer 776bd389b36SDavid du Colombierand 777bd389b36SDavid du Colombier.I float 778bd389b36SDavid du Colombiertypes and perform the expected operations: 779bd389b36SDavid du Colombier.CW * 780bd389b36SDavid du Colombiermultiplication, 781bd389b36SDavid du Colombier.CW / 782bd389b36SDavid du Colombierdivision, 783bd389b36SDavid du Colombier.CW % 784bd389b36SDavid du Colombiermodulus. 785bd389b36SDavid du Colombier.DS 786bd389b36SDavid du Colombier additive-expression: 787bd389b36SDavid du Colombier multiplicative-expression 788bd389b36SDavid du Colombier additive-expression \f(CW+\fP multiplicative-expression 789bd389b36SDavid du Colombier additive-expression \f(CW-\fP multiplicative-expression 790bd389b36SDavid du Colombier.DE 791bd389b36SDavid du ColombierThese operators perform as expected for 792bd389b36SDavid du Colombier.I integer 793bd389b36SDavid du Colombierand 794bd389b36SDavid du Colombier.I float 795bd389b36SDavid du Colombieroperands. 796219b2ee8SDavid du ColombierUnlike in C, 797219b2ee8SDavid du Colombier.CW + 798219b2ee8SDavid du Colombierand 799219b2ee8SDavid du Colombier.CW - 800219b2ee8SDavid du Colombierdo not scale the addition based on the format of the expression. 801219b2ee8SDavid du ColombierThis means that 802219b2ee8SDavid du Colombier.CW i=i+1 803219b2ee8SDavid du Colombierwill always add 1 but 804219b2ee8SDavid du Colombier.CW i++ 805219b2ee8SDavid du Colombierwill add the size corresponding to the format stored with 806219b2ee8SDavid du Colombier.CW i . 807bd389b36SDavid du ColombierIf both operands are of either 808bd389b36SDavid du Colombier.I string 809bd389b36SDavid du Colombieror 810bd389b36SDavid du Colombier.I list 811ab3dc52fSDavid du Colombiertype then addition is defined as concatenation. 812ab3dc52fSDavid du ColombierAdding a string and an integer is treated as concatenation 813ab3dc52fSDavid du Colombierwith the Unicode character corresponding to the integer. 814ab3dc52fSDavid du ColombierSubtraction is undefined for strings and lists. 815bd389b36SDavid du Colombier.DS 816bd389b36SDavid du Colombier shift-expression: 817bd389b36SDavid du Colombier additive-expression 818219b2ee8SDavid du Colombier shift-expression \f(CW<<\fP additive-expression 819219b2ee8SDavid du Colombier shift-expression \f(CW>>\fP additive-expression 820bd389b36SDavid du Colombier.DE 821bd389b36SDavid du ColombierThe 822bd389b36SDavid du Colombier.CW >> 823bd389b36SDavid du Colombierand 824bd389b36SDavid du Colombier.CW << 825219b2ee8SDavid du Colombieroperators perform bitwise right and left shifts respectively. Both 826219b2ee8SDavid du Colombierrequire operands of 827bd389b36SDavid du Colombier.I integer 828bd389b36SDavid du Colombiertype. 829bd389b36SDavid du Colombier.DS 830bd389b36SDavid du Colombier relational-expression: 831bd389b36SDavid du Colombier relational-expression \f(CW<\fP shift-expression 832bd389b36SDavid du Colombier relational-expression \f(CW>\fP shift-expression 833219b2ee8SDavid du Colombier relational-expression \f(CW<=\fP shift-expression 834219b2ee8SDavid du Colombier relational-expression \f(CW>=\fP shift-expression 835bd389b36SDavid du Colombier 836bd389b36SDavid du Colombier equality-expression: 837bd389b36SDavid du Colombier relational-expression 838bd389b36SDavid du Colombier relational-expression \f(CW==\fP equality-expression 839bd389b36SDavid du Colombier relational-expression \f(CW!=\fP equality-expression 840bd389b36SDavid du Colombier.DE 841bd389b36SDavid du ColombierThe comparison operators are 842bd389b36SDavid du Colombier.CW < 843bd389b36SDavid du Colombier(less than), 844bd389b36SDavid du Colombier.CW > 845bd389b36SDavid du Colombier(greater than), 846bd389b36SDavid du Colombier.CW <= 847bd389b36SDavid du Colombier(less than or equal to), 848bd389b36SDavid du Colombier.CW >= 849bd389b36SDavid du Colombier(greater than or equal to), 850bd389b36SDavid du Colombier.CW == 851bd389b36SDavid du Colombier(equal to) and 852bd389b36SDavid du Colombier.CW != 853bd389b36SDavid du Colombier(not equal to). The result of a comparison is 0 854bd389b36SDavid du Colombierif the condition is false, otherwise 1. The relational operators can only be 855bd389b36SDavid du Colombierapplied to operands of 856bd389b36SDavid du Colombier.I integer 857bd389b36SDavid du Colombierand 858bd389b36SDavid du Colombier.I float 859219b2ee8SDavid du Colombiertype. The equality operators apply to all types. Comparing mixed types is legal. 860219b2ee8SDavid du ColombierMixed integer and float compare on the integral value. Other mixtures are always unequal. 861219b2ee8SDavid du ColombierTwo lists are equal if they 862219b2ee8SDavid du Colombierhave the same number of members and a pairwise comparison of the members results 863bd389b36SDavid du Colombierin equality. 864bd389b36SDavid du Colombier.DS 865bd389b36SDavid du Colombier AND-expression: 866bd389b36SDavid du Colombier equality-expression 867bd389b36SDavid du Colombier AND-expression \f(CW&\fP equality-expression 868bd389b36SDavid du Colombier 869bd389b36SDavid du Colombier XOR-expression: 870bd389b36SDavid du Colombier AND-expression 871219b2ee8SDavid du Colombier XOR-expression \f(CW^\fP AND-expression 872bd389b36SDavid du Colombier 873bd389b36SDavid du Colombier OR-expression: 874bd389b36SDavid du Colombier XOR-expression 875bd389b36SDavid du Colombier OR-expression \f(CW|\fP XOR-expression 876bd389b36SDavid du Colombier.DE 877bd389b36SDavid du ColombierThese operators perform bitwise logical operations and apply only to the 878bd389b36SDavid du Colombier.I integer 879bd389b36SDavid du Colombiertype. 880bd389b36SDavid du ColombierThe operators are 881bd389b36SDavid du Colombier.CW & 882bd389b36SDavid du Colombier(logical and), 883bd389b36SDavid du Colombier.CW ^ 884bd389b36SDavid du Colombier(exclusive or) and 885bd389b36SDavid du Colombier.CW | 886bd389b36SDavid du Colombier(inclusive or). 887bd389b36SDavid du Colombier.DS 888bd389b36SDavid du Colombier logical-AND-expression: 889bd389b36SDavid du Colombier OR-expression 890219b2ee8SDavid du Colombier logical-AND-expression \f(CW&&\fP OR-expression 891bd389b36SDavid du Colombier 892bd389b36SDavid du Colombier logical-OR-expression: 893bd389b36SDavid du Colombier logical-AND-expression 894219b2ee8SDavid du Colombier logical-OR-expression \f(CW||\fP logical-AND-expression 895bd389b36SDavid du Colombier.DE 896bd389b36SDavid du ColombierThe 897bd389b36SDavid du Colombier.CW && 898bd389b36SDavid du Colombieroperator returns 1 if both of its operands evaluate to boolean true, otherwise 0. 899bd389b36SDavid du ColombierThe 900bd389b36SDavid du Colombier.CW || 901219b2ee8SDavid du Colombieroperator returns 1 if either of its operands evaluates to boolean true, 902219b2ee8SDavid du Colombierotherwise 0. 903bd389b36SDavid du Colombier.SH 904bd389b36SDavid du ColombierStatements 905bd389b36SDavid du Colombier.PP 906bd389b36SDavid du Colombier.DS 907bd389b36SDavid du Colombier \f(CWif\fP expression \f(CWthen\fP statement \f(CWelse\fP statement 908bd389b36SDavid du Colombier \f(CWif\fP expression \f(CWthen\fP statement 909bd389b36SDavid du Colombier.DE 910219b2ee8SDavid du ColombierThe 911219b2ee8SDavid du Colombier.I expression 912219b2ee8SDavid du Colombieris evaluated as a boolean. If its value is true the statement after 913bd389b36SDavid du Colombierthe 914bd389b36SDavid du Colombier.CW then 915bd389b36SDavid du Colombieris executed, otherwise the statement after the 916bd389b36SDavid du Colombier.CW else 917bd389b36SDavid du Colombieris executed. The 918bd389b36SDavid du Colombier.CW else 919bd389b36SDavid du Colombierportion may be omitted. 920bd389b36SDavid du Colombier.DS 921bd389b36SDavid du Colombier \f(CWwhile\fP expression \f(CWdo\fP statement 922bd389b36SDavid du Colombier.DE 923219b2ee8SDavid du ColombierIn a while loop, the 924219b2ee8SDavid du Colombier.I statement 925219b2ee8SDavid du Colombieris executed while the boolean 926219b2ee8SDavid du Colombier.I expression 927219b2ee8SDavid du Colombierevaluates 928bd389b36SDavid du Colombiertrue. 929bd389b36SDavid du Colombier.DS 930bd389b36SDavid du Colombier \f(CWloop\fP startexpr, endexpr \f(CWdo\fP statement 931bd389b36SDavid du Colombier.DE 932bd389b36SDavid du ColombierThe two expressions 933bd389b36SDavid du Colombier.I startexpr 934bd389b36SDavid du Colombierand 935bd389b36SDavid du Colombier.I endexpr 936bd389b36SDavid du Colombierare evaluated prior to loop entry. 937bd389b36SDavid du Colombier.I Statement 938219b2ee8SDavid du Colombieris evaluated while the value of 939bd389b36SDavid du Colombier.I startexpr 940219b2ee8SDavid du Colombieris less than or equal to 941bd389b36SDavid du Colombier.I endexpr . 942219b2ee8SDavid du ColombierBoth expressions must yield 943219b2ee8SDavid du Colombier.I integer 944219b2ee8SDavid du Colombiervalues. The value of 945219b2ee8SDavid du Colombier.I startexpr 946219b2ee8SDavid du Colombieris 947bd389b36SDavid du Colombierincremented by one for each loop iteration. 948219b2ee8SDavid du ColombierNote that there is no explicit loop variable; the 949219b2ee8SDavid du Colombier.I expressions 950219b2ee8SDavid du Colombierare just values. 951bd389b36SDavid du Colombier.DS 952bd389b36SDavid du Colombier \f(CWreturn\fP expression 953bd389b36SDavid du Colombier.DE 954bd389b36SDavid du Colombier.CW return 955bd389b36SDavid du Colombierterminates execution of the current function and returns to its caller. 956bd389b36SDavid du ColombierThe value of the function is given by expression. Since 957bd389b36SDavid du Colombier.CW return 958219b2ee8SDavid du Colombierrequires an argument, nil-valued functions should return the empty list 959bd389b36SDavid du Colombier.CW {} . 960bd389b36SDavid du Colombier.DS 961bd389b36SDavid du Colombier \f(CWlocal\fP variable 962bd389b36SDavid du Colombier.DE 963bd389b36SDavid du ColombierThe 964bd389b36SDavid du Colombier.CW local 965219b2ee8SDavid du Colombierstatement creates a local instance of 966219b2ee8SDavid du Colombier.I variable , 967219b2ee8SDavid du Colombierwhich exists for the duration 968219b2ee8SDavid du Colombierof the instance of the function in which it is declared. Binding is dynamic: the local variable, 969219b2ee8SDavid du Colombierrather than the previous value of 970219b2ee8SDavid du Colombier.I variable , 971219b2ee8SDavid du Colombieris visible to called functions. 972219b2ee8SDavid du ColombierAfter a return from the current function the previous value of 973219b2ee8SDavid du Colombier.I variable 974219b2ee8SDavid du Colombieris 975219b2ee8SDavid du Colombierrestored. 976bd389b36SDavid du Colombier.PP 977219b2ee8SDavid du ColombierIf Acid is interrupted, the values of all local variables are lost, 978bd389b36SDavid du Colombieras if the function returned. 979bd389b36SDavid du Colombier.DS 980bd389b36SDavid du Colombier \f(CWdefn\fP function-name \f(CW(\fP parameter-list \f(CW)\fP body 981bd389b36SDavid du Colombier 982bd389b36SDavid du Colombier parameter-list: 983bd389b36SDavid du Colombier variable 984bd389b36SDavid du Colombier parameter-list , variable 985bd389b36SDavid du Colombier 986bd389b36SDavid du Colombier body: 987bd389b36SDavid du Colombier \f(CW{\fP statement \f(CW}\fP 988bd389b36SDavid du Colombier.DE 989bd389b36SDavid du ColombierFunctions are introduced by the 990bd389b36SDavid du Colombier.CW defn 991bd389b36SDavid du Colombierstatement. The definition of parameter names suppresses any variables 992bd389b36SDavid du Colombierof the same name until the function returns. The body of a function is a list 993bd389b36SDavid du Colombierof statements enclosed by braces. 994bd389b36SDavid du Colombier.SH 995219b2ee8SDavid du ColombierCode variables 996219b2ee8SDavid du Colombier.PP 997219b2ee8SDavid du ColombierAcid permits the delayed evaluation of a parameter to a function. The parameter 998219b2ee8SDavid du Colombiermay then be evaluated at any time with the 999219b2ee8SDavid du Colombier.CW eval 1000219b2ee8SDavid du Colombieroperator. Such parameters are called 1001219b2ee8SDavid du Colombier.I "code variables 1002219b2ee8SDavid du Colombierand are defined by prefixing their name with an asterisk in their declaration. 1003219b2ee8SDavid du Colombier.PP 1004219b2ee8SDavid du ColombierFor example, this function wraps up an expression for later evaluation: 1005219b2ee8SDavid du Colombier.P1 1006219b2ee8SDavid du Colombieracid: defn code(*e) { return e; } 1007219b2ee8SDavid du Colombieracid: x = code(v+atoi("100")\eD) 1008219b2ee8SDavid du Colombieracid: print(x) 1009219b2ee8SDavid du Colombier(v+atoi("100"))\eD; 1010219b2ee8SDavid du Colombieracid: eval x 1011219b2ee8SDavid du Colombier<stdin>:5: (error) v used but not set 1012219b2ee8SDavid du Colombieracid: v=5 1013219b2ee8SDavid du Colombieracid: eval x 1014219b2ee8SDavid du Colombier105 1015219b2ee8SDavid du Colombier.P2 1016219b2ee8SDavid du Colombier.SH 1017bd389b36SDavid du ColombierSource Code Management 1018bd389b36SDavid du Colombier.PP 1019219b2ee8SDavid du ColombierAcid provides the means to examine source code. Source code is 1020bd389b36SDavid du Colombierrepresented by lists of strings. Builtin functions provide mapping 1021bd389b36SDavid du Colombierfrom address to lines and vice-versa. The default debugging environment 1022bd389b36SDavid du Colombierhas the means to load and display source files. 1023bd389b36SDavid du Colombier.SH 1024bd389b36SDavid du ColombierBuiltin Functions 1025bd389b36SDavid du Colombier.PP 1026219b2ee8SDavid du ColombierThe Acid interpreter has a number of builtin functions, which cannot be redefined. 1027219b2ee8SDavid du ColombierThese functions perform machine- or operating system-specific functions such as 1028219b2ee8SDavid du Colombiersymbol table and process management. 1029219b2ee8SDavid du ColombierThe following section presents a description of each builtin function. 1030219b2ee8SDavid du ColombierThe notation 1031bd389b36SDavid du Colombier.CW {} 1032219b2ee8SDavid du Colombieris used to denote the empty list, which is the default value of a function that 1033219b2ee8SDavid du Colombierdoes not execute a 1034219b2ee8SDavid du Colombier.CW return 1035219b2ee8SDavid du Colombierstatement. 1036219b2ee8SDavid du ColombierThe type and number of parameters for each function are specified in the 1037219b2ee8SDavid du Colombierdescription; where a parameter can be of any type it is specified as type 1038219b2ee8SDavid du Colombier.I item . 1039bd389b36SDavid du Colombier.de Ip 1040219b2ee8SDavid du Colombier.KS 1041426d2b71SDavid du Colombier.in 0 1042219b2ee8SDavid du Colombier.LP 1043426d2b71SDavid du Colombier.ie h \&\f2\\$1\fP\ \ \f(CW\\$2(\f2\\$3\f(CW)\f1\ \ \ \ \ \ \ \ \\$4 1044426d2b71SDavid du Colombier.el .tl '\f2\\$1\fP\ \ \f(CW\\$2(\f2\\$3\f(CW)\f1''\\$4' 1045219b2ee8SDavid du Colombier.IP 1046219b2ee8SDavid du Colombier.. 1047219b2ee8SDavid du Colombier.de Ex 1048219b2ee8SDavid du Colombier.KE 1049219b2ee8SDavid du Colombier.KS 1050219b2ee8SDavid du Colombier.IP 1051219b2ee8SDavid du Colombier.ft CW 1052219b2ee8SDavid du Colombier.ta 4n +4n +4n +4n +4n +4n +4n +4n +4n +4n +4n +4n +4n +4n +4n +4n 1053219b2ee8SDavid du Colombier.nf 1054219b2ee8SDavid du Colombier.in +4n 1055bd389b36SDavid du Colombier.br 1056bd389b36SDavid du Colombier.. 1057219b2ee8SDavid du Colombier.de Ee 1058219b2ee8SDavid du Colombier.fi 1059219b2ee8SDavid du Colombier.ft 1 1060219b2ee8SDavid du Colombier.br 1061219b2ee8SDavid du Colombier.KE 1062219b2ee8SDavid du Colombier.. 1063219b2ee8SDavid du Colombier.\" 1064219b2ee8SDavid du Colombier.\" 1065219b2ee8SDavid du Colombier.\" 1066219b2ee8SDavid du Colombier.Ip integer access string "Check if a file can be read 1067219b2ee8SDavid du Colombier.CW Access 1068219b2ee8SDavid du Colombierreturns the integer 1 if the file name in 1069219b2ee8SDavid du Colombier.I string 1070219b2ee8SDavid du Colombiercan be read by the builtin functions 1071bd389b36SDavid du Colombier.CW file , 1072219b2ee8SDavid du Colombier.CW readfile , 1073219b2ee8SDavid du Colombieror 1074219b2ee8SDavid du Colombier.CW include , 1075219b2ee8SDavid du Colombierotherwise 0. A typical use of this function is to follow 1076219b2ee8SDavid du Colombiera search path looking for a source file; it is used by 1077219b2ee8SDavid du Colombier.CW findsrc . 1078219b2ee8SDavid du Colombier.Ex 1079219b2ee8SDavid du Colombierif access("main.c") then 1080219b2ee8SDavid du Colombier return file("main.c"); 1081219b2ee8SDavid du Colombier.Ee 1082219b2ee8SDavid du Colombier.\" 1083219b2ee8SDavid du Colombier.\" 1084219b2ee8SDavid du Colombier.\" 1085219b2ee8SDavid du Colombier.Ip float atof string "Convert a string to float 1086219b2ee8SDavid du Colombier.CW atof 1087219b2ee8SDavid du Colombierconverts the string supplied as its argument into a floating point 1088219b2ee8SDavid du Colombiernumber. The function accepts strings in the same format as the C 1089219b2ee8SDavid du Colombierfunction of the same name. The value returned has the format code 1090219b2ee8SDavid du Colombier.CW f . 1091219b2ee8SDavid du Colombier.CW atof 1092219b2ee8SDavid du Colombierreturns the value 0.0 if it is unable to perform the conversion. 1093219b2ee8SDavid du Colombier.Ex 1094219b2ee8SDavid du Colombieracid: +atof("10.4e6") 1095219b2ee8SDavid du Colombier1.04e+07 1096219b2ee8SDavid du Colombier.Ee 1097219b2ee8SDavid du Colombier.\" 1098219b2ee8SDavid du Colombier.\" 1099219b2ee8SDavid du Colombier.\" 1100219b2ee8SDavid du Colombier.Ip integer atoi string "Convert a string to an integer 1101219b2ee8SDavid du Colombier.CW atoi 1102219b2ee8SDavid du Colombierconverts the argument 1103219b2ee8SDavid du Colombier.i string 1104219b2ee8SDavid du Colombierto an integer value. 1105219b2ee8SDavid du ColombierThe function accepts strings in the same format as the C function of the 1106219b2ee8SDavid du Colombiersame name. The value returned has the format code 1107219b2ee8SDavid du Colombier.CW D . 1108219b2ee8SDavid du Colombier.CW atoi 1109219b2ee8SDavid du Colombierreturns the integer 0 if it is unable to perform a conversion. 1110219b2ee8SDavid du Colombier.Ex 1111219b2ee8SDavid du Colombieracid: +atoi("-1255") 1112219b2ee8SDavid du Colombier-1255 1113219b2ee8SDavid du Colombier.Ee 1114219b2ee8SDavid du Colombier.\" 1115219b2ee8SDavid du Colombier.\" 1116219b2ee8SDavid du Colombier.\" 1117219b2ee8SDavid du Colombier.Ip \f(CW{}\fP error string "Generate an interpreter error 1118219b2ee8SDavid du Colombier.CW error 1119219b2ee8SDavid du Colombiergenerates an error message and returns the interpreter to interactive 1120219b2ee8SDavid du Colombiermode. If an Acid program is running, it is aborted. 1121219b2ee8SDavid du ColombierProcesses being debugged are not affected. The values of all local variables are lost. 1122219b2ee8SDavid du Colombier.CW error 1123219b2ee8SDavid du Colombieris commonly used to stop the debugger when some interesting condition arises 1124219b2ee8SDavid du Colombierin the debugged program. 1125219b2ee8SDavid du Colombier.Ex 1126219b2ee8SDavid du Colombierwhile 1 do { 1127219b2ee8SDavid du Colombier step(); 1128219b2ee8SDavid du Colombier if *main != @main then 1129219b2ee8SDavid du Colombier error("memory corrupted"); 1130219b2ee8SDavid du Colombier} 1131219b2ee8SDavid du Colombier.Ee 1132219b2ee8SDavid du Colombier.\" 1133219b2ee8SDavid du Colombier.\" 1134219b2ee8SDavid du Colombier.\" 1135219b2ee8SDavid du Colombier.Ip list file string "Read the contents of a file into a list 1136219b2ee8SDavid du Colombier.CW file 1137219b2ee8SDavid du Colombierreads the contents of the file specified by 1138219b2ee8SDavid du Colombier.I string 1139219b2ee8SDavid du Colombierinto a list. 1140219b2ee8SDavid du ColombierEach element in the list is a string corresponding to a line in the file. 1141219b2ee8SDavid du Colombier.CW file 1142219b2ee8SDavid du Colombierbreaks lines at the newline character, but the newline 1143219b2ee8SDavid du Colombiercharacters are not returned as part each string. 1144219b2ee8SDavid du Colombier.CW file 1145219b2ee8SDavid du Colombierreturns the empty list if it encounters an error opening or reading the data. 1146219b2ee8SDavid du Colombier.Ex 1147219b2ee8SDavid du Colombieracid: print(file("main.c")[0]) 1148219b2ee8SDavid du Colombier#include <u.h> 1149219b2ee8SDavid du Colombier.Ee 1150219b2ee8SDavid du Colombier.\" 1151219b2ee8SDavid du Colombier.\" 1152219b2ee8SDavid du Colombier.\" 1153219b2ee8SDavid du Colombier.Ip integer filepc string "Convert source address to text address 1154219b2ee8SDavid du Colombier.CW filepc 1155219b2ee8SDavid du Colombierinterprets its 1156219b2ee8SDavid du Colombier.I string 1157219b2ee8SDavid du Colombierargument as a source file address in the form of a file name and line offset. 1158219b2ee8SDavid du Colombier.CW filepc 1159219b2ee8SDavid du Colombieruses the symbol table to map the source address into a text address 1160219b2ee8SDavid du Colombierin the debugged program. The 1161219b2ee8SDavid du Colombier.I integer 1162219b2ee8SDavid du Colombierreturn value has the format 1163219b2ee8SDavid du Colombier.CW X . 1164219b2ee8SDavid du Colombier.CW filepc 1165219b2ee8SDavid du Colombierreturns an address of -1 if the source address is invalid. 1166219b2ee8SDavid du ColombierThe source file address uses the same format as 1167219b2ee8SDavid du Colombier.I acme (1). 1168219b2ee8SDavid du ColombierThis function is commonly used to set breakpoints from the source text. 1169219b2ee8SDavid du Colombier.Ex 1170219b2ee8SDavid du Colombieracid: bpset(filepc("main:10")) 1171219b2ee8SDavid du Colombieracid: bptab() 1172219b2ee8SDavid du Colombier 0x00001020 usage ADD $-0xc,R29 1173219b2ee8SDavid du Colombier.Ee 1174219b2ee8SDavid du Colombier.\" 1175219b2ee8SDavid du Colombier.\" 1176219b2ee8SDavid du Colombier.\" 1177219b2ee8SDavid du Colombier.Ip item fmt item,fmt "Set print, \f(CW@\fP and \f(CW*\fP formats 1178219b2ee8SDavid du Colombier.CW fmt 1179219b2ee8SDavid du Colombierevaluates the expression 1180219b2ee8SDavid du Colombier.I item 1181219b2ee8SDavid du Colombierand sets the format of the result to 1182219b2ee8SDavid du Colombier.I fmt . 1183219b2ee8SDavid du ColombierThe format of a value determines how it will be printed and 1184219b2ee8SDavid du Colombierwhat kind of object will be fetched by the 1185219b2ee8SDavid du Colombier.CW * 1186219b2ee8SDavid du Colombierand 1187219b2ee8SDavid du Colombier.CW @ 1188219b2ee8SDavid du Colombieroperators. The 1189219b2ee8SDavid du Colombier.CW \e 1190219b2ee8SDavid du Colombieroperator is a short-hand form of the 1191219b2ee8SDavid du Colombier.CW fmt 1192219b2ee8SDavid du Colombierbuiltin function. The 1193219b2ee8SDavid du Colombier.CW fmt 1194219b2ee8SDavid du Colombierfunction leaves the format of the 1195219b2ee8SDavid du Colombier.I item 1196219b2ee8SDavid du Colombierunchanged. 1197219b2ee8SDavid du Colombier.Ex 1198219b2ee8SDavid du Colombieracid: main=fmt(main, 'i') // as instructions 1199219b2ee8SDavid du Colombieracid: print(main\eX, "\et", *main) 1200219b2ee8SDavid du Colombier0x00001020 ADD $-64,R29 1201219b2ee8SDavid du Colombier.Ee 1202219b2ee8SDavid du Colombier.\" 1203219b2ee8SDavid du Colombier.\" 1204219b2ee8SDavid du Colombier.\" 1205*7c70c028SDavid du Colombier.Ip fmt fmtof item "Get format 1206*7c70c028SDavid du Colombier.CW fmtof 1207*7c70c028SDavid du Colombierevaluates the expression 1208*7c70c028SDavid du Colombier.I item 1209*7c70c028SDavid du Colombierand returns the format of the result. 1210*7c70c028SDavid du Colombier.Ex 1211*7c70c028SDavid du Colombieracid: +fmtof(33) 1212*7c70c028SDavid du ColombierW 1213*7c70c028SDavid du Colombieracid: +fmtof("string") 1214*7c70c028SDavid du Colombiers 1215*7c70c028SDavid du Colombier.Ee 1216*7c70c028SDavid du Colombier.\" 1217*7c70c028SDavid du Colombier.\" 1218*7c70c028SDavid du Colombier.\" 1219*7c70c028SDavid du Colombier.Ip integer fmtsize item "Get format size 1220*7c70c028SDavid du Colombier.CW fmtsize 1221*7c70c028SDavid du Colombierevaluates the expression 1222*7c70c028SDavid du Colombier.I item 1223*7c70c028SDavid du Colombierand returns the size in bytes of a single element of result's format. 1224*7c70c028SDavid du Colombier.Ex 1225*7c70c028SDavid du Colombieracid: +fmtsize('c') 1226*7c70c028SDavid du Colombier8 1227*7c70c028SDavid du Colombieracid: +fmtsize('c'\ec) 1228*7c70c028SDavid du Colombier1 1229*7c70c028SDavid du Colombieracid: +fmtsize(0\eX) 1230*7c70c028SDavid du Colombier4 1231*7c70c028SDavid du Colombieracid: +fmtsize('c'\e3) 1232*7c70c028SDavid du Colombier10 1233*7c70c028SDavid du Colombier.Ee 1234*7c70c028SDavid du Colombier.\" 1235*7c70c028SDavid du Colombier.\" 1236*7c70c028SDavid du Colombier.\" 1237219b2ee8SDavid du Colombier.Ip list fnbound integer "Find start and end address of a function 1238219b2ee8SDavid du Colombier.CW fnbound 1239219b2ee8SDavid du Colombierinterprets its 1240219b2ee8SDavid du Colombier.I integer 1241219b2ee8SDavid du Colombierargument as an address in the text of the debugged program. 1242219b2ee8SDavid du Colombier.CW fnbound 1243219b2ee8SDavid du Colombierreturns a list containing two integers corresponding to 1244219b2ee8SDavid du Colombierthe start and end addresses of the function containing the supplied address. 1245219b2ee8SDavid du ColombierIf the 1246219b2ee8SDavid du Colombier.I integer 1247219b2ee8SDavid du Colombieraddress is not in the text segment of the program then the empty list is returned. 1248219b2ee8SDavid du Colombier.CW fnbound 1249219b2ee8SDavid du Colombieris used by 1250219b2ee8SDavid du Colombier.CW next 1251219b2ee8SDavid du Colombierto detect stepping into new functions. 1252219b2ee8SDavid du Colombier.Ex 1253219b2ee8SDavid du Colombieracid: print(fnbound(main)) 1254219b2ee8SDavid du Colombier{0x00001050, 0x000014b8} 1255219b2ee8SDavid du Colombier.Ee 1256219b2ee8SDavid du Colombier.\" 1257219b2ee8SDavid du Colombier.\" 1258219b2ee8SDavid du Colombier.\" 1259219b2ee8SDavid du Colombier.Ip \f(CW{}\fP follow integer "Compute follow set 1260219b2ee8SDavid du ColombierThe follow set is defined as the set of program counter values that could result 1261219b2ee8SDavid du Colombierfrom executing an instruction. 1262219b2ee8SDavid du Colombier.CW follow 1263219b2ee8SDavid du Colombierinterprets its 1264219b2ee8SDavid du Colombier.I integer 1265219b2ee8SDavid du Colombierargument as a text address, decodes the instruction at 1266219b2ee8SDavid du Colombierthat address and, with the current register set, builds a list of possible 1267219b2ee8SDavid du Colombiernext program counter values. If the instruction at the specified address 1268219b2ee8SDavid du Colombiercannot be decoded 1269219b2ee8SDavid du Colombier.CW follow 1270219b2ee8SDavid du Colombierraises an error. 1271219b2ee8SDavid du Colombier.CW follow 1272219b2ee8SDavid du Colombieris used to plant breakpoints on 1273219b2ee8SDavid du Colombierall potential paths of execution. The following code fragment 1274219b2ee8SDavid du Colombierplants breakpoints on top of all potential following instructions. 1275219b2ee8SDavid du Colombier.Ex 1276219b2ee8SDavid du Colombierlst = follow(*PC); 1277219b2ee8SDavid du Colombierwhile lst do 1278219b2ee8SDavid du Colombier{ 1279219b2ee8SDavid du Colombier *head lst = bpinst; 1280219b2ee8SDavid du Colombier lst = tail lst; 1281219b2ee8SDavid du Colombier} 1282219b2ee8SDavid du Colombier.Ee 1283219b2ee8SDavid du Colombier.\" 1284219b2ee8SDavid du Colombier.\" 1285219b2ee8SDavid du Colombier.\" 1286219b2ee8SDavid du Colombier.Ip \f(CW{}\fP include string "Take input from a new file 1287219b2ee8SDavid du Colombier.CW include 1288219b2ee8SDavid du Colombieropens the file specified by 1289219b2ee8SDavid du Colombier.I string 1290219b2ee8SDavid du Colombierand uses its contents as command input to the interpreter. 1291219b2ee8SDavid du ColombierThe interpreter restores input to its previous source when it encounters 1292219b2ee8SDavid du Colombiereither an end of file or an error. 1293219b2ee8SDavid du Colombier.CW include 1294219b2ee8SDavid du Colombiercan be used to incrementally load symbol table information without 1295219b2ee8SDavid du Colombierleaving the interpreter. 1296219b2ee8SDavid du Colombier.Ex 1297219b2ee8SDavid du Colombieracid: include("/sys/src/cmd/acme/syms") 1298219b2ee8SDavid du Colombier.Ee 1299219b2ee8SDavid du Colombier.\" 1300219b2ee8SDavid du Colombier.\" 1301219b2ee8SDavid du Colombier.\" 1302219b2ee8SDavid du Colombier.Ip \f(CW{}\fP interpret string "Take input from a string 1303219b2ee8SDavid du Colombier.CW interpret 1304219b2ee8SDavid du Colombierevaluates the 1305219b2ee8SDavid du Colombier.I string 1306219b2ee8SDavid du Colombierexpression and uses its result as command input for the interpreter. 1307219b2ee8SDavid du ColombierThe interpreter restores input to its previous source when it encounters 1308219b2ee8SDavid du Colombiereither the end of string or an error. The 1309219b2ee8SDavid du Colombier.CW interpret 1310219b2ee8SDavid du Colombierfunction allows Acid programs to write Acid code for later evaluation. 1311219b2ee8SDavid du Colombier.Ex 1312219b2ee8SDavid du Colombieracid: interpret("main+10;") 1313219b2ee8SDavid du Colombier0x0000102a 1314219b2ee8SDavid du Colombier.Ee 1315219b2ee8SDavid du Colombier.\" 1316219b2ee8SDavid du Colombier.\" 1317219b2ee8SDavid du Colombier.\" 13189a747e4fSDavid du Colombier.Ip string itoa integer[,string] "Convert integer to string 1319219b2ee8SDavid du Colombier.CW itoa 1320219b2ee8SDavid du Colombiertakes an integer argument and converts it into an ASCII string 1321219b2ee8SDavid du Colombierin the 1322219b2ee8SDavid du Colombier.CW D 13239a747e4fSDavid du Colombierformat. 13249a747e4fSDavid du Colombieran alternate format string 13259a747e4fSDavid du Colombiermay be provided in the 13269a747e4fSDavid du Colombier.CW % 13279a747e4fSDavid du Colombierstyle of 13289a747e4fSDavid du Colombier.I print (2). 13299a747e4fSDavid du ColombierThis function is commonly used to build 1330219b2ee8SDavid du Colombier.CW rc 1331219b2ee8SDavid du Colombiercommand lines. 1332219b2ee8SDavid du Colombier.Ex 1333219b2ee8SDavid du Colombieracid: rc("cat /proc/"+itoa(pid)+"/segment") 1334219b2ee8SDavid du ColombierStack 7fc00000 80000000 1 1335219b2ee8SDavid du ColombierData 00001000 00009000 1 1336219b2ee8SDavid du ColombierData 00009000 0000a000 1 1337219b2ee8SDavid du ColombierBss 0000a000 0000c000 1 1338219b2ee8SDavid du Colombier.Ee 1339219b2ee8SDavid du Colombier.\" 1340219b2ee8SDavid du Colombier.\" 1341219b2ee8SDavid du Colombier.\" 1342219b2ee8SDavid du Colombier.Ip \f(CW{}\fP kill integer "Kill a process 1343219b2ee8SDavid du Colombier.CW kill 1344219b2ee8SDavid du Colombierwrites a kill control message into the control file of the process 1345219b2ee8SDavid du Colombierspecified by the 1346219b2ee8SDavid du Colombier.I integer 1347219b2ee8SDavid du Colombierpid. 1348219b2ee8SDavid du ColombierIf the process was previously installed by 1349219b2ee8SDavid du Colombier.CW setproc 1350219b2ee8SDavid du Colombierit will be removed from the list of active processes. 1351219b2ee8SDavid du ColombierIf the 1352219b2ee8SDavid du Colombier.I integer 1353219b2ee8SDavid du Colombierhas the same value as 1354219b2ee8SDavid du Colombier.CW pid , 1355219b2ee8SDavid du Colombierthen 1356219b2ee8SDavid du Colombier.CW pid 1357219b2ee8SDavid du Colombierwill be set to 0. 1358219b2ee8SDavid du ColombierTo continue debugging, a new process must be selected using 1359219b2ee8SDavid du Colombier.CW setproc . 1360219b2ee8SDavid du ColombierFor example, to kill all the active processes: 1361219b2ee8SDavid du Colombier.Ex 1362219b2ee8SDavid du Colombierwhile proclist do { 1363219b2ee8SDavid du Colombier kill(head proclist); 1364219b2ee8SDavid du Colombier proclist = tail proclist; 1365219b2ee8SDavid du Colombier} 1366219b2ee8SDavid du Colombier.Ee 1367219b2ee8SDavid du Colombier.\" 1368219b2ee8SDavid du Colombier.\" 1369219b2ee8SDavid du Colombier.\" 1370219b2ee8SDavid du Colombier.Ip list map list "Set or retrieve process memory map 1371219b2ee8SDavid du Colombier.CW map 1372219b2ee8SDavid du Colombiereither retrieves all the mappings associated with a process or sets a single 1373219b2ee8SDavid du Colombiermap entry to a new value. 1374219b2ee8SDavid du ColombierIf the 1375219b2ee8SDavid du Colombier.I list 1376219b2ee8SDavid du Colombierargument is omitted then 1377219b2ee8SDavid du Colombier.CW map 1378219b2ee8SDavid du Colombierreturns a list of lists. Each sublist has four values and describes a 1379219b2ee8SDavid du Colombiersingle region of contiguous addresses in the 1380219b2ee8SDavid du Colombiermemory or file image of the debugged program. The first entry is the name of the 1381219b2ee8SDavid du Colombiermapping. If the name begins with 1382219b2ee8SDavid du Colombier.CW * 1383219b2ee8SDavid du Colombierit denotes a map into the memory of an active process. 1384219b2ee8SDavid du ColombierThe second and third values specify the base and end 1385219b2ee8SDavid du Colombieraddress of the region and the fourth number specifies the offset in the file 1386219b2ee8SDavid du Colombiercorresponding to the first location of the region. 1387219b2ee8SDavid du ColombierA map entry may be set by supplying a list in the same format as the sublist 1388219b2ee8SDavid du Colombierdescribed above. The name of the mapping must match a region already defined 1389219b2ee8SDavid du Colombierby the current map. 1390219b2ee8SDavid du ColombierMaps are set automatically for Plan 9 processes and some kernels; they may 1391219b2ee8SDavid du Colombierneed to be set by hand for other kernels and programs that run on bare hardware. 1392219b2ee8SDavid du Colombier.Ex 1393219b2ee8SDavid du Colombieracid: map({"text", _start, end, 0x30}) 1394219b2ee8SDavid du Colombier.Ee 1395219b2ee8SDavid du Colombier.\" 1396219b2ee8SDavid du Colombier.\" 1397219b2ee8SDavid du Colombier.\" 1398219b2ee8SDavid du Colombier.Ip integer match item,list "Search list for matching value 1399219b2ee8SDavid du Colombier.CW match 1400219b2ee8SDavid du Colombiercompares each item in 1401219b2ee8SDavid du Colombier.I list 1402219b2ee8SDavid du Colombierusing the equality operator 1403219b2ee8SDavid du Colombier.CW == 1404219b2ee8SDavid du Colombierwith 1405219b2ee8SDavid du Colombier.I item . 1406219b2ee8SDavid du ColombierThe 1407219b2ee8SDavid du Colombier.I item 1408219b2ee8SDavid du Colombiercan be of any type. If the match succeeds the result is the integer index 1409219b2ee8SDavid du Colombierof the matching value, otherwise -1. 1410219b2ee8SDavid du Colombier.Ex 1411219b2ee8SDavid du Colombieracid: list={8,9,10,11} 1412219b2ee8SDavid du Colombieracid: print(list[match(10, list)]\eD) 1413219b2ee8SDavid du Colombier10 1414219b2ee8SDavid du Colombier.Ee 1415219b2ee8SDavid du Colombier.\" 1416219b2ee8SDavid du Colombier.\" 1417219b2ee8SDavid du Colombier.\" 1418219b2ee8SDavid du Colombier.Ip \f(CW{}\fP newproc string "Create a new process 1419219b2ee8SDavid du Colombier.CW newproc 1420219b2ee8SDavid du Colombierstarts a new process with an argument vector constructed from 1421219b2ee8SDavid du Colombier.I string . 1422219b2ee8SDavid du ColombierThe argument vector excludes the name of the program to execute and 1423219b2ee8SDavid du Colombiereach argument in 1424219b2ee8SDavid du Colombier.I string 1425219b2ee8SDavid du Colombiermust be space separated. A new process can accept no more 1426219b2ee8SDavid du Colombierthan 512 arguments. The internal variable 1427219b2ee8SDavid du Colombier.CW pid 1428219b2ee8SDavid du Colombieris set to the pid of the newly created process. The new pid 1429219b2ee8SDavid du Colombieris also appended to the list of active processes stored in the variable 1430219b2ee8SDavid du Colombier.CW proclist . 1431219b2ee8SDavid du ColombierThe new process is created then halted at the first instruction, causing 1432219b2ee8SDavid du Colombierthe debugger to call 1433219b2ee8SDavid du Colombier.CW stopped . 1434219b2ee8SDavid du ColombierThe library functions 1435219b2ee8SDavid du Colombier.CW new 1436219b2ee8SDavid du Colombierand 1437219b2ee8SDavid du Colombier.CW win 1438219b2ee8SDavid du Colombiershould be used to start processes when using the standard debugging 1439219b2ee8SDavid du Colombierenvironment. 1440219b2ee8SDavid du Colombier.Ex 1441219b2ee8SDavid du Colombieracid: newproc("-l .") 1442219b2ee8SDavid du Colombier56720: system call _main ADD $-0x14,R29 1443219b2ee8SDavid du Colombier.Ee 1444219b2ee8SDavid du Colombier.\" 1445219b2ee8SDavid du Colombier.\" 1446219b2ee8SDavid du Colombier.\" 1447219b2ee8SDavid du Colombier.Ip string pcfile integer "Convert text address to source file name 1448219b2ee8SDavid du Colombier.CW pcfile 1449219b2ee8SDavid du Colombierinterprets its 1450219b2ee8SDavid du Colombier.I integer 1451219b2ee8SDavid du Colombierargument as a text address in the debugged program. The address and symbol table 1452219b2ee8SDavid du Colombierare used to generate a string containing the name of the source file 1453219b2ee8SDavid du Colombiercorresponding to the text address. If the address does not lie within the 1454219b2ee8SDavid du Colombierprogram the string 1455219b2ee8SDavid du Colombier.CW ?file? 1456219b2ee8SDavid du Colombieris returned. 1457219b2ee8SDavid du Colombier.Ex 1458219b2ee8SDavid du Colombieracid: print("Now at ", pcfile(*PC), ":", pcline(*PC)) 1459219b2ee8SDavid du ColombierNow at ls.c:46 1460219b2ee8SDavid du Colombier.Ee 1461219b2ee8SDavid du Colombier.\" 1462219b2ee8SDavid du Colombier.\" 1463219b2ee8SDavid du Colombier.\" 1464219b2ee8SDavid du Colombier.Ip integer pcline integer "Convert text address to source line number 1465219b2ee8SDavid du Colombier.CW pcline 1466219b2ee8SDavid du Colombierinterprets its 1467219b2ee8SDavid du Colombier.I integer 1468219b2ee8SDavid du Colombierargument as a text address in the debugged program. The address and symbol table 1469219b2ee8SDavid du Colombierare used to generate an integer containing the line number in the source file 1470219b2ee8SDavid du Colombiercorresponding to the text address. If the address does not lie within the 1471219b2ee8SDavid du Colombierprogram the integer 0 is returned. 1472219b2ee8SDavid du Colombier.Ex 1473219b2ee8SDavid du Colombieracid: +file("main.c")[pcline(main)] 1474219b2ee8SDavid du Colombiermain(int argc, char *argv[]) 1475219b2ee8SDavid du Colombier.Ee 1476219b2ee8SDavid du Colombier.\" 1477219b2ee8SDavid du Colombier.\" 1478219b2ee8SDavid du Colombier.\" 1479219b2ee8SDavid du Colombier.Ip \f(CW{}\fP print item,item,... "Print expressions 1480219b2ee8SDavid du Colombier.CW print 1481219b2ee8SDavid du Colombierevaluates each 1482219b2ee8SDavid du Colombier.I item 1483219b2ee8SDavid du Colombiersupplied in its argument list and prints it to standard output. Each 1484219b2ee8SDavid du Colombierargument will be printed according to its associated format character. 1485219b2ee8SDavid du ColombierWhen the interpreter is executing, output is buffered and flushed every 1486219b2ee8SDavid du Colombier5000 statements or when the interpreter returns to interactive mode. 1487219b2ee8SDavid du Colombier.CW print 1488219b2ee8SDavid du Colombieraccepts a maximum of 512 arguments. 1489219b2ee8SDavid du Colombier.Ex 1490219b2ee8SDavid du Colombieracid: print(10, "decimal ", 10\eD, "octal ", 10\eo) 1491bd389b36SDavid du Colombier0x0000000a decimal 10 octal 000000000012 1492bd389b36SDavid du Colombieracid: print({1, 2, 3}) 1493bd389b36SDavid du Colombier{0x00000001 , 0x00000002 , 0x00000003 } 1494219b2ee8SDavid du Colombieracid: print(main, main\ea, "\et", @main\ei) 1495bd389b36SDavid du Colombier0x00001020 main ADD $-64,R29 1496219b2ee8SDavid du Colombier.Ee 1497219b2ee8SDavid du Colombier.\" 1498219b2ee8SDavid du Colombier.\" 1499219b2ee8SDavid du Colombier.\" 1500219b2ee8SDavid du Colombier.Ip \f(CW{}\fP printto string,item,item,... "Print expressions to file 1501219b2ee8SDavid du Colombier.CW printto 1502219b2ee8SDavid du Colombieroffers a limited form of output redirection. The first 1503bd389b36SDavid du Colombier.I string 1504219b2ee8SDavid du Colombierargument is used as the path name of a new file to create. 1505219b2ee8SDavid du ColombierEach 1506219b2ee8SDavid du Colombier.I item 1507219b2ee8SDavid du Colombieris then evaluated and printed to the newly created file. When all items 1508219b2ee8SDavid du Colombierhave been printed the file is closed. 1509219b2ee8SDavid du Colombier.CW printto 1510219b2ee8SDavid du Colombieraccepts a maximum of 512 arguments. 1511219b2ee8SDavid du Colombier.Ex 1512219b2ee8SDavid du Colombieracid: printto("/env/foo", "hello") 1513219b2ee8SDavid du Colombieracid: rc("echo -n $foo") 1514219b2ee8SDavid du Colombierhello 1515219b2ee8SDavid du Colombier.Ee 1516219b2ee8SDavid du Colombier.\" 1517219b2ee8SDavid du Colombier.\" 1518219b2ee8SDavid du Colombier.\" 1519219b2ee8SDavid du Colombier.Ip string rc string "Execute a shell command 1520219b2ee8SDavid du Colombier.CW rc 1521219b2ee8SDavid du Colombierevaluates 1522219b2ee8SDavid du Colombier.I string 1523219b2ee8SDavid du Colombierto form a shell command. A new command interpreter is started 1524219b2ee8SDavid du Colombierto execute the command. The Acid interpreter blocks until the command 1525219b2ee8SDavid du Colombiercompletes. The return value is the empty string 1526219b2ee8SDavid du Colombierif the command succeeds, otherwise the exit status of the failed command. 1527219b2ee8SDavid du Colombier.Ex 1528219b2ee8SDavid du Colombieracid: rc("B "+itoa(-pcline(addr))+" "+pcfile(addr)); 1529219b2ee8SDavid du Colombier.Ee 1530219b2ee8SDavid du Colombier.\" 1531219b2ee8SDavid du Colombier.\" 1532219b2ee8SDavid du Colombier.\" 1533219b2ee8SDavid du Colombier.Ip string readfile string "Read file contents into a string 1534219b2ee8SDavid du Colombier.CW readfile 1535219b2ee8SDavid du Colombiertakes the contents of the file specified by 1536219b2ee8SDavid du Colombier.I string 1537219b2ee8SDavid du Colombierand returns its contents as a new string. 1538bd389b36SDavid du ColombierIf 1539219b2ee8SDavid du Colombier.CW readfile 1540219b2ee8SDavid du Colombierencounters a zero byte in the file, it terminates. 1541219b2ee8SDavid du ColombierIf 1542219b2ee8SDavid du Colombier.CW readfile 1543219b2ee8SDavid du Colombierencounters an error opening or reading the file then the empty list 1544219b2ee8SDavid du Colombieris returned. 1545219b2ee8SDavid du Colombier.CW readfile 1546219b2ee8SDavid du Colombiercan be used to read the contents of device files whose lines are not 1547219b2ee8SDavid du Colombierterminated with newline characters. 1548219b2ee8SDavid du Colombier.Ex 1549219b2ee8SDavid du Colombieracid: ""+readfile("/dev/label") 1550219b2ee8SDavid du Colombierhelix 1551219b2ee8SDavid du Colombier.Ee 1552219b2ee8SDavid du Colombier.\" 1553219b2ee8SDavid du Colombier.\" 1554219b2ee8SDavid du Colombier.\" 1555219b2ee8SDavid du Colombier.Ip string reason integer "Print cause of program stoppage 1556219b2ee8SDavid du Colombier.CW reason 1557219b2ee8SDavid du Colombieruses machine-dependent information to generate a string explaining 1558219b2ee8SDavid du Colombierwhy a process has stopped. The 1559219b2ee8SDavid du Colombier.I integer 1560219b2ee8SDavid du Colombierargument is the value of an architecture dependent status register, 1561219b2ee8SDavid du Colombierfor example 1562219b2ee8SDavid du Colombier.CW CAUSE 1563219b2ee8SDavid du Colombieron the MIPS. 1564219b2ee8SDavid du Colombier.Ex 1565219b2ee8SDavid du Colombieracid: print(reason(*CAUSE)) 1566219b2ee8SDavid du Colombiersystem call 1567219b2ee8SDavid du Colombier.Ee 1568219b2ee8SDavid du Colombier.\" 1569219b2ee8SDavid du Colombier.\" 1570219b2ee8SDavid du Colombier.\" 1571219b2ee8SDavid du Colombier.Ip integer regexp pattern,string "Regular expression match 1572219b2ee8SDavid du Colombier.CW regexp 1573219b2ee8SDavid du Colombiermatches the 1574219b2ee8SDavid du Colombier.I pattern 1575219b2ee8SDavid du Colombierstring supplied as its first argument with the 1576bd389b36SDavid du Colombier.I string 1577219b2ee8SDavid du Colombiersupplied as its second. 1578219b2ee8SDavid du ColombierIf the pattern matches the result is the value 1, otherwise 0. 1579219b2ee8SDavid du Colombier.Ex 1580219b2ee8SDavid du Colombieracid: print(regexp(".*bar", "foobar")) 1581219b2ee8SDavid du Colombier1 1582219b2ee8SDavid du Colombier.Ee 1583219b2ee8SDavid du Colombier.\" 1584219b2ee8SDavid du Colombier.\" 1585219b2ee8SDavid du Colombier.\" 1586219b2ee8SDavid du Colombier.Ip \f(CW{}\fP setproc integer "Set debugger focus 1587219b2ee8SDavid du Colombier.CW setproc 1588219b2ee8SDavid du Colombierselects the default process used for memory and control operations. It effectively 1589219b2ee8SDavid du Colombiershifts the focus of control between processes. The 1590219b2ee8SDavid du Colombier.I integer 1591219b2ee8SDavid du Colombierargument specifies the pid of the process to look at. 1592219b2ee8SDavid du ColombierThe variable 1593bd389b36SDavid du Colombier.CW pid 1594219b2ee8SDavid du Colombieris set to the pid of the selected process. If the process is being 1595219b2ee8SDavid du Colombierselected for the first time its pid is added to the list of active 1596219b2ee8SDavid du Colombierprocesses 1597219b2ee8SDavid du Colombier.CW proclist . 1598219b2ee8SDavid du Colombier.Ex 1599219b2ee8SDavid du Colombieracid: setproc(68382) 1600219b2ee8SDavid du Colombieracid: procs() 1601219b2ee8SDavid du Colombier>68382: Stopped at main+0x4 setproc(68382) 1602219b2ee8SDavid du Colombier.Ee 1603219b2ee8SDavid du Colombier.\" 1604219b2ee8SDavid du Colombier.\" 1605219b2ee8SDavid du Colombier.\" 1606219b2ee8SDavid du Colombier.Ip \f(CW{}\fP start integer "Restart execution 1607219b2ee8SDavid du Colombier.CW start 1608219b2ee8SDavid du Colombierwrites a 1609219b2ee8SDavid du Colombier.CW start 1610219b2ee8SDavid du Colombiermessage to the control file of the process specified by the pid 1611219b2ee8SDavid du Colombiersupplied as its 1612219b2ee8SDavid du Colombier.I integer 1613219b2ee8SDavid du Colombierargument. 1614219b2ee8SDavid du Colombier.CW start 1615219b2ee8SDavid du Colombierdraws an error if the process is not in the 1616219b2ee8SDavid du Colombier.CW Stopped 1617219b2ee8SDavid du Colombierstate. 1618219b2ee8SDavid du Colombier.Ex 1619219b2ee8SDavid du Colombieracid: start(68382) 1620219b2ee8SDavid du Colombieracid: procs() 1621219b2ee8SDavid du Colombier>68382: Running at main+0x4 setproc(68382) 1622219b2ee8SDavid du Colombier.Ee 1623219b2ee8SDavid du Colombier.\" 1624219b2ee8SDavid du Colombier.\" 1625219b2ee8SDavid du Colombier.\" 1626219b2ee8SDavid du Colombier.Ip \f(CW{}\fP startstop integer "Restart execution, block until stopped 1627219b2ee8SDavid du Colombier.CW startstop 1628219b2ee8SDavid du Colombierperforms the same actions as a call to 1629219b2ee8SDavid du Colombier.CW start 1630219b2ee8SDavid du Colombierfollowed by a call to 1631219b2ee8SDavid du Colombier.CW stop . 1632219b2ee8SDavid du ColombierThe 1633219b2ee8SDavid du Colombier.I integer 1634219b2ee8SDavid du Colombierargument specifies the pid of the process to control. The process 1635219b2ee8SDavid du Colombiermust be in the 1636219b2ee8SDavid du Colombier.CW Stopped 1637219b2ee8SDavid du Colombierstate. 1638219b2ee8SDavid du ColombierExecution is restarted, the debugger then waits for the process to 1639219b2ee8SDavid du Colombierreturn to the 1640219b2ee8SDavid du Colombier.CW Stopped 1641219b2ee8SDavid du Colombierstate. A process will stop if a startstop message has been written to its control 1642219b2ee8SDavid du Colombierfile and any of the following conditions becomes true: the process executes or returns from 1643219b2ee8SDavid du Colombiera system call, the process generates a trap or the process receives a note. 1644219b2ee8SDavid du Colombier.CW startstop 1645219b2ee8SDavid du Colombieris used to implement single stepping. 1646219b2ee8SDavid du Colombier.Ex 1647219b2ee8SDavid du Colombieracid: startstop(pid) 1648219b2ee8SDavid du Colombier75374: breakpoint ls ADD $-0x16c8,R29 1649219b2ee8SDavid du Colombier.Ee 1650219b2ee8SDavid du Colombier.\" 1651219b2ee8SDavid du Colombier.\" 1652219b2ee8SDavid du Colombier.\" 1653219b2ee8SDavid du Colombier.Ip string status integer "Return process state 1654219b2ee8SDavid du Colombier.CW status 1655219b2ee8SDavid du Colombieruses the pid supplied by its 1656219b2ee8SDavid du Colombier.I integer 1657219b2ee8SDavid du Colombierargument to generate a string describing the state of the process. 1658219b2ee8SDavid du ColombierThe string corresponds to the state returned by the 1659219b2ee8SDavid du Colombiersixth column of the 1660219b2ee8SDavid du Colombier.I ps (1) 1661219b2ee8SDavid du Colombiercommand. 1662219b2ee8SDavid du ColombierA process must be in the 1663219b2ee8SDavid du Colombier.CW Stopped 1664219b2ee8SDavid du Colombierstate to modify its memory or registers. 1665219b2ee8SDavid du Colombier.Ex 1666219b2ee8SDavid du Colombieracid: ""+status(pid) 1667219b2ee8SDavid du ColombierStopped 1668219b2ee8SDavid du Colombier.Ee 1669219b2ee8SDavid du Colombier.\" 1670219b2ee8SDavid du Colombier.\" 1671219b2ee8SDavid du Colombier.\" 1672219b2ee8SDavid du Colombier.Ip \f(CW{}\fP stop integer "Wait for a process to stop 1673219b2ee8SDavid du Colombier.CW stop 1674219b2ee8SDavid du Colombierwrites a 1675219b2ee8SDavid du Colombier.CW stop 1676219b2ee8SDavid du Colombiermessage to the control file of the process specified by the 1677219b2ee8SDavid du Colombierpid supplied as its 1678219b2ee8SDavid du Colombier.I integer 1679219b2ee8SDavid du Colombierargument. 1680219b2ee8SDavid du ColombierThe interpreter blocks until the debugged process enters the 1681219b2ee8SDavid du Colombier.CW Stopped 1682219b2ee8SDavid du Colombierstate. 1683219b2ee8SDavid du ColombierA process will stop if a stop message has been written to its control 1684219b2ee8SDavid du Colombierfile and any of the following conditions becomes true: the process executes or returns from 1685219b2ee8SDavid du Colombiera system call, the process generates a trap, the process is scheduled or the 1686219b2ee8SDavid du Colombierprocess receives a note. 1687219b2ee8SDavid du Colombier.CW stop 1688219b2ee8SDavid du Colombieris used to wait for a process to halt before planting a breakpoint since Plan 9 1689219b2ee8SDavid du Colombieronly allows a process's memory to be written while it is in the 1690219b2ee8SDavid du Colombier.CW Stopped 1691219b2ee8SDavid du Colombierstate. 1692219b2ee8SDavid du Colombier.Ex 1693219b2ee8SDavid du Colombierdefn bpset(addr) { 1694219b2ee8SDavid du Colombier if (status(pid)!="Stopped") then { 1695219b2ee8SDavid du Colombier print("Waiting...\en"); 1696219b2ee8SDavid du Colombier stop(pid); 1697219b2ee8SDavid du Colombier } 1698219b2ee8SDavid du Colombier ... 1699219b2ee8SDavid du Colombier} 1700219b2ee8SDavid du Colombier.Ee 1701219b2ee8SDavid du Colombier.\" 1702219b2ee8SDavid du Colombier.\" 1703219b2ee8SDavid du Colombier.\" 1704219b2ee8SDavid du Colombier.Ip list strace pc,sp,linkreg "Stack trace 1705219b2ee8SDavid du Colombier.CW strace 1706219b2ee8SDavid du Colombiergenerates a list of lists corresponding to procedures called by the debugged 1707219b2ee8SDavid du Colombierprogram. Each sublist describes a single stack frame in the active process. 1708219b2ee8SDavid du ColombierThe first element is an 1709219b2ee8SDavid du Colombier.I integer 1710219b2ee8SDavid du Colombierof format 1711219b2ee8SDavid du Colombier.CW X 1712219b2ee8SDavid du Colombierspecifying the address of the called function. The second element is the value 1713219b2ee8SDavid du Colombierof the program counter when the function was called. The third and fourth elements 1714219b2ee8SDavid du Colombiercontain lists of parameter and automatic variables respectively. 1715219b2ee8SDavid du ColombierEach element of these lists 1716219b2ee8SDavid du Colombiercontains a string with the name of the variable and an 1717219b2ee8SDavid du Colombier.I integer 1718219b2ee8SDavid du Colombiervalue of format 1719219b2ee8SDavid du Colombier.CW X 1720219b2ee8SDavid du Colombiercontaining the current value of the variable. 1721219b2ee8SDavid du ColombierThe arguments to 1722219b2ee8SDavid du Colombier.CW strace 1723219b2ee8SDavid du Colombierare the current value of the program counter, the current value of the 1724219b2ee8SDavid du Colombierstack pointer, and the address of the link register. All three parameters 1725219b2ee8SDavid du Colombiermust be integers. 1726219b2ee8SDavid du ColombierThe setting of 1727219b2ee8SDavid du Colombier.I linkreg 1728219b2ee8SDavid du Colombieris architecture dependent. On the MIPS linkreg is set to the address of saved 1729219b2ee8SDavid du Colombier.CW R31 , 1730219b2ee8SDavid du Colombieron the SPARC to the address of saved 1731219b2ee8SDavid du Colombier.CW R15 . 1732219b2ee8SDavid du ColombierFor the other architectures 1733219b2ee8SDavid du Colombier.I linkreg 1734219b2ee8SDavid du Colombieris not used, but must point to valid memory. 1735219b2ee8SDavid du Colombier.Ex 1736219b2ee8SDavid du Colombieracid: print(strace(*PC, *SP, linkreg)) 1737219b2ee8SDavid du Colombier{{0x0000141c, 0xc0000f74, 1738219b2ee8SDavid du Colombier{{"s", 0x0000004d}, {"multi", 0x00000000}}, 1739219b2ee8SDavid du Colombier{{"db", 0x00000000}, {"fd", 0x000010a4}, 1740219b2ee8SDavid du Colombier{"n", 0x00000001}, {"i", 0x00009824}}}} 1741219b2ee8SDavid du Colombier.Ee 1742219b2ee8SDavid du Colombier.\" 1743219b2ee8SDavid du Colombier.\" 1744219b2ee8SDavid du Colombier.\" 1745219b2ee8SDavid du Colombier.Ip \f(CW{}\fP waitstop integer "Wait for a process to stop 1746219b2ee8SDavid du Colombier.CW waitstop 1747219b2ee8SDavid du Colombierwrites a waitstop message to the control file of the process specified by the 1748219b2ee8SDavid du Colombierpid supplied as its 1749219b2ee8SDavid du Colombier.I integer 1750219b2ee8SDavid du Colombierargument. 1751219b2ee8SDavid du ColombierThe interpreter will remain blocked until the debugged process enters the 1752219b2ee8SDavid du Colombier.CW Stopped 1753219b2ee8SDavid du Colombierstate. 1754219b2ee8SDavid du ColombierA process will stop if a waitstop message has been written to its control 1755219b2ee8SDavid du Colombierfile and any of the following conditions becomes true: the process generates a trap 1756219b2ee8SDavid du Colombieror receives a note. Unlike 1757219b2ee8SDavid du Colombier.CW stop , 1758219b2ee8SDavid du Colombierthe 1759219b2ee8SDavid du Colombier.CW waitstop 1760219b2ee8SDavid du Colombierfunction is passive; it does not itself cause the program to stop. 1761219b2ee8SDavid du Colombier.Ex 1762219b2ee8SDavid du Colombieracid: waitstop(pid) 1763219b2ee8SDavid du Colombier75374: breakpoint ls ADD $-0x16c8,R29 1764219b2ee8SDavid du Colombier.Ee 1765219b2ee8SDavid du Colombier.\" 1766219b2ee8SDavid du Colombier.\" 1767219b2ee8SDavid du Colombier.\" 1768bd389b36SDavid du Colombier.SH 1769bd389b36SDavid du ColombierLibrary Functions 1770bd389b36SDavid du Colombier.PP 1771219b2ee8SDavid du ColombierA standard debugging environment is provided by modules automatically 1772219b2ee8SDavid du Colombierloaded when 1773219b2ee8SDavid du ColombierAcid is started. 1774219b2ee8SDavid du ColombierThese modules are located in the directory 1775219b2ee8SDavid du Colombier.CW /sys/lib/acid . 1776219b2ee8SDavid du ColombierThese functions may be overridden, personalized, or added to by code defined in 1777bd389b36SDavid du Colombier.CW $home/lib/acid . 1778219b2ee8SDavid du ColombierThe implementation of these functions can be examined using the 1779219b2ee8SDavid du Colombier.CW whatis 1780219b2ee8SDavid du Colombieroperator and then modified during debugging sessions. 1781219b2ee8SDavid du Colombier.\" 1782219b2ee8SDavid du Colombier.\" 1783219b2ee8SDavid du Colombier.\" 17847dd7cddfSDavid du Colombier.Ip \f(CW{}\fP Bsrc integer "Load editor with source 1785219b2ee8SDavid du Colombier.CW Bsrc 1786219b2ee8SDavid du Colombierinterprets the 1787219b2ee8SDavid du Colombier.I integer 1788219b2ee8SDavid du Colombierargument as a text address. The text address is used to produce a pathname 17897dd7cddfSDavid du Colombierand line number suitable for the 1790219b2ee8SDavid du Colombier.CW B 1791219b2ee8SDavid du Colombiercommand 17927dd7cddfSDavid du Colombierto send to the text editor 17937dd7cddfSDavid du Colombier.I sam (1) 17947dd7cddfSDavid du Colombieror 17957dd7cddfSDavid du Colombier.I acme (1). 1796219b2ee8SDavid du Colombier.CW Bsrc 1797219b2ee8SDavid du Colombierbuilds an 1798219b2ee8SDavid du Colombier.I rc (1) 1799219b2ee8SDavid du Colombiercommand to invoke 1800219b2ee8SDavid du Colombier.CW B , 18017dd7cddfSDavid du Colombierwhich either selects an existing source file or loads a new source file into the editor. 1802219b2ee8SDavid du ColombierThe line of source corresponding to the text address is then selected. 1803219b2ee8SDavid du ColombierIn the following example 1804bd389b36SDavid du Colombier.CW stopped 18057dd7cddfSDavid du Colombieris redefined so that the editor 1806219b2ee8SDavid du Colombierfollows and displays the source line currently being executed. 1807219b2ee8SDavid du Colombier.Ex 1808219b2ee8SDavid du Colombierdefn stopped(pid) { 1809219b2ee8SDavid du Colombier pstop(pid); 1810219b2ee8SDavid du Colombier Bsrc(*PC); 1811219b2ee8SDavid du Colombier} 1812219b2ee8SDavid du Colombier.Ee 1813219b2ee8SDavid du Colombier.\" 1814219b2ee8SDavid du Colombier.\" 1815219b2ee8SDavid du Colombier.\" 1816219b2ee8SDavid du Colombier.Ip \f(CW{}\fP Fpr "" "Display double precision floating registers 1817219b2ee8SDavid du ColombierFor machines equipped with floating point, 1818219b2ee8SDavid du Colombier.CW Fpr 1819219b2ee8SDavid du Colombierdisplays the contents of the floating point registers as double precision 1820219b2ee8SDavid du Colombiervalues. 1821219b2ee8SDavid du Colombier.Ex 1822219b2ee8SDavid du Colombieracid: Fpr() 1823219b2ee8SDavid du ColombierF0 0. F2 0. 1824219b2ee8SDavid du ColombierF4 0. F6 0. 1825219b2ee8SDavid du ColombierF8 0. F10 0. 1826219b2ee8SDavid du Colombier\&... 1827219b2ee8SDavid du Colombier.Ee 1828219b2ee8SDavid du Colombier.\" 1829219b2ee8SDavid du Colombier.\" 1830219b2ee8SDavid du Colombier.\" 1831219b2ee8SDavid du Colombier.Ip \f(CW{}\fP Ureg integer "Display contents of Ureg structure 1832219b2ee8SDavid du Colombier.CW Ureg 1833219b2ee8SDavid du Colombierinterprets the integer passed as its first argument as the address of a 1834219b2ee8SDavid du Colombierkernel 1835219b2ee8SDavid du Colombier.CW Ureg 1836219b2ee8SDavid du Colombierstructure. Each element of the structure is retrieved and printed. 1837219b2ee8SDavid du ColombierThe size and contents of the 1838219b2ee8SDavid du Colombier.CW Ureg 1839219b2ee8SDavid du Colombierstructure are architecture dependent. 1840219b2ee8SDavid du ColombierThis function can be used to decode the first argument passed to a 1841219b2ee8SDavid du Colombier.I notify (2) 1842219b2ee8SDavid du Colombierfunction after a process has received a note. 1843219b2ee8SDavid du Colombier.Ex 1844219b2ee8SDavid du Colombieracid: Ureg(*notehandler:ur) 1845219b2ee8SDavid du Colombier status 0x3000f000 1846219b2ee8SDavid du Colombier pc 0x1020 1847219b2ee8SDavid du Colombier sp 0x7ffffe00 1848219b2ee8SDavid du Colombier cause 0x00004002 1849219b2ee8SDavid du Colombier\&... 1850219b2ee8SDavid du Colombier.Ee 1851219b2ee8SDavid du Colombier.\" 1852219b2ee8SDavid du Colombier.\" 1853219b2ee8SDavid du Colombier.\" 1854219b2ee8SDavid du Colombier.Ip \f(CW{}\fP acidinit "" "Interpreter startup 1855219b2ee8SDavid du Colombier.CW acidinit 1856219b2ee8SDavid du Colombieris called by the interpreter after all 1857219b2ee8SDavid du Colombiermodules have been loaded at initialization time. 1858219b2ee8SDavid du ColombierIt is used to set up machine specific variables and the default source path. 1859219b2ee8SDavid du Colombier.CW acidinit 1860219b2ee8SDavid du Colombiershould not be called by user code. 1861219b2ee8SDavid du Colombier.KE 1862219b2ee8SDavid du Colombier.\" 1863219b2ee8SDavid du Colombier.\" 1864219b2ee8SDavid du Colombier.\" 1865219b2ee8SDavid du Colombier.Ip \f(CW{}\fP addsrcdir string "Add element to source search path 1866219b2ee8SDavid du Colombier.CW addsrcdir 1867219b2ee8SDavid du Colombierinterprets its string argument as a new directory 1868219b2ee8SDavid du Colombier.CW findsrc 1869219b2ee8SDavid du Colombiershould search when looking for source code files. 1870219b2ee8SDavid du Colombier.CW addsrcdir 1871219b2ee8SDavid du Colombierdraws an error if the directory is already in the source search path. The search 1872219b2ee8SDavid du Colombierpath may be examined by looking at the variable 1873219b2ee8SDavid du Colombier.CW srcpath . 1874219b2ee8SDavid du Colombier.Ex 1875219b2ee8SDavid du Colombieracid: rc("9fs fornax") 1876219b2ee8SDavid du Colombieracid: addsrcpath("/n/fornax/sys/src/cmd") 1877219b2ee8SDavid du Colombier.Ee 1878219b2ee8SDavid du Colombier.\" 1879219b2ee8SDavid du Colombier.\" 1880219b2ee8SDavid du Colombier.\" 1881219b2ee8SDavid du Colombier.Ip \f(CW{}\fP asm integer "Disassemble machine instructions 1882219b2ee8SDavid du Colombier.CW asm 1883219b2ee8SDavid du Colombierinterprets its integer argument as a text address from which to disassemble 1884219b2ee8SDavid du Colombiermachine instructions. 1885219b2ee8SDavid du Colombier.CW asm 1886219b2ee8SDavid du Colombierprints the instruction address in symbolic and hexadecimal form, then prints 1887219b2ee8SDavid du Colombierthe instructions with addressing modes. Up to twenty instructions will 1888219b2ee8SDavid du Colombierbe disassembled. 1889219b2ee8SDavid du Colombier.CW asm 1890219b2ee8SDavid du Colombierstops disassembling when it reaches the end of the current function. 1891219b2ee8SDavid du ColombierInstructions are read from the file image using the 1892219b2ee8SDavid du Colombier.CW @ 1893219b2ee8SDavid du Colombieroperator. 1894219b2ee8SDavid du Colombier.Ex 1895219b2ee8SDavid du Colombieracid: asm(main) 1896219b2ee8SDavid du Colombiermain 0x00001020 ADD $-0x64,R29 1897219b2ee8SDavid du Colombiermain+0x4 0x00001024 MOVW R31,0x0(R29) 1898219b2ee8SDavid du Colombiermain+0x8 0x00001028 MOVW R1,argc+4(FP) 1899219b2ee8SDavid du Colombiermain+0xc 0x0000102c MOVW $bin(SB),R1 1900219b2ee8SDavid du Colombier.Ee 1901219b2ee8SDavid du Colombier.\" 1902219b2ee8SDavid du Colombier.\" 1903219b2ee8SDavid du Colombier.\" 1904219b2ee8SDavid du Colombier.Ip \f(CW{}\fP bpdel integer "Delete breakpoint 1905219b2ee8SDavid du Colombier.CW bpdel 1906219b2ee8SDavid du Colombierremoves a previously set breakpoint from memory. 1907219b2ee8SDavid du ColombierThe 1908219b2ee8SDavid du Colombier.I integer 1909219b2ee8SDavid du Colombiersupplied as its argument must be the address of a previously set breakpoint. 1910219b2ee8SDavid du ColombierThe breakpoint address is deleted from the active breakpoint list 1911219b2ee8SDavid du Colombier.CW bplist , 1912219b2ee8SDavid du Colombierthen the original instruction is copied from the file image to the memory 1913219b2ee8SDavid du Colombierimage so that the breakpoint is removed. 1914219b2ee8SDavid du Colombier.Ex 1915219b2ee8SDavid du Colombieracid: bpdel(main+4) 1916219b2ee8SDavid du Colombier.Ee 1917219b2ee8SDavid du Colombier.\" 1918219b2ee8SDavid du Colombier.\" 1919219b2ee8SDavid du Colombier.\" 1920219b2ee8SDavid du Colombier.Ip \f(CW{}\fP bpset integer "Set a breakpoint 1921219b2ee8SDavid du Colombier.CW bpset 1922219b2ee8SDavid du Colombierplaces a breakpoint instruction at the address specified 1923219b2ee8SDavid du Colombierby its 1924219b2ee8SDavid du Colombier.I integer 1925219b2ee8SDavid du Colombierargument, which must be in the text segment. 1926219b2ee8SDavid du Colombier.CW bpset 1927219b2ee8SDavid du Colombierdraws an error if a breakpoint has already been set at the specified address. 1928219b2ee8SDavid du ColombierA list of current breakpoints is maintained in the variable 1929219b2ee8SDavid du Colombier.CW bplist . 1930219b2ee8SDavid du ColombierUnlike in 1931219b2ee8SDavid du Colombier.I db (1), 1932219b2ee8SDavid du Colombierbreakpoints are left in memory even when a process is stopped, and 1933219b2ee8SDavid du Colombierthe process must exist, perhaps by being 1934219b2ee8SDavid du Colombiercreated by either 1935219b2ee8SDavid du Colombier.CW new 1936219b2ee8SDavid du Colombieror 1937219b2ee8SDavid du Colombier.CW win , 1938219b2ee8SDavid du Colombierin order to place a breakpoint. 1939219b2ee8SDavid du Colombier.CW Db "" ( 1940219b2ee8SDavid du Colombieraccepts breakpoint commands before the process is started.) 1941219b2ee8SDavid du ColombierOn the 1942219b2ee8SDavid du ColombierMIPS and SPARC architectures, 1943219b2ee8SDavid du Colombierbreakpoints at function entry points should be set 4 bytes into the function 1944219b2ee8SDavid du Colombierbecause the 1945219b2ee8SDavid du Colombierinstruction scheduler may fill 1946219b2ee8SDavid du Colombier.CW JAL 1947219b2ee8SDavid du Colombierbranch delay slots with the first instruction of the function. 1948219b2ee8SDavid du Colombier.Ex 1949219b2ee8SDavid du Colombieracid: bpset(main+4) 1950219b2ee8SDavid du Colombier.Ee 1951219b2ee8SDavid du Colombier.\" 1952219b2ee8SDavid du Colombier.\" 1953219b2ee8SDavid du Colombier.\" 1954219b2ee8SDavid du Colombier.Ip \f(CW{}\fP bptab "" "List active breakpoints 1955219b2ee8SDavid du Colombier.CW bptab 1956219b2ee8SDavid du Colombierprints a list of currently installed breakpoints. The list contains the 1957219b2ee8SDavid du Colombierbreakpoint address in symbolic and hexadecimal form as well as the instruction 1958219b2ee8SDavid du Colombierthe breakpoint replaced. Breakpoints are not maintained across process creation 1959219b2ee8SDavid du Colombierusing 1960219b2ee8SDavid du Colombier.CW new 1961219b2ee8SDavid du Colombierand 1962219b2ee8SDavid du Colombier.CW win . 1963219b2ee8SDavid du ColombierThey are maintained across a fork, but care must be taken to keep control of 1964219b2ee8SDavid du Colombierthe child process. 1965219b2ee8SDavid du Colombier.Ex 1966219b2ee8SDavid du Colombieracid: bpset(ls+4) 1967219b2ee8SDavid du Colombieracid: bptab() 1968219b2ee8SDavid du Colombier 0x00001420 ls+0x4 MOVW R31,0x0(R29) 1969219b2ee8SDavid du Colombier.Ee 1970219b2ee8SDavid du Colombier.\" 1971219b2ee8SDavid du Colombier.\" 1972219b2ee8SDavid du Colombier.\" 1973219b2ee8SDavid du Colombier.Ip \f(CW{}\fP casm "" "Continue disassembly 1974219b2ee8SDavid du Colombier.CW casm 1975219b2ee8SDavid du Colombiercontinues to disassemble instructions from where the last 1976219b2ee8SDavid du Colombier.CW asm 1977219b2ee8SDavid du Colombieror 1978219b2ee8SDavid du Colombier.CW casm 1979219b2ee8SDavid du Colombiercommand stopped. Like 1980219b2ee8SDavid du Colombier.CW asm , 1981219b2ee8SDavid du Colombierthis command stops disassembling at function boundaries. 1982219b2ee8SDavid du Colombier.Ex 1983219b2ee8SDavid du Colombieracid: casm() 1984219b2ee8SDavid du Colombiermain+0x10 0x00001030 MOVW $0x1,R3 1985219b2ee8SDavid du Colombiermain+0x14 0x00001034 MOVW R3,0x8(R29) 1986219b2ee8SDavid du Colombiermain+0x18 0x00001038 MOVW $0x1,R5 1987219b2ee8SDavid du Colombiermain+0x1c 0x0000103c JAL Binit(SB) 1988219b2ee8SDavid du Colombier.Ee 1989219b2ee8SDavid du Colombier.\" 1990219b2ee8SDavid du Colombier.\" 1991219b2ee8SDavid du Colombier.\" 1992219b2ee8SDavid du Colombier.Ip \f(CW{}\fP cont "" "Continue program execution 1993219b2ee8SDavid du Colombier.CW cont 1994219b2ee8SDavid du Colombierrestarts execution of the currently active process. 1995219b2ee8SDavid du ColombierIf the process is stopped on a breakpoint, the breakpoint is first removed, 1996219b2ee8SDavid du Colombierthe program is single stepped, the breakpoint is replaced and the program 1997219b2ee8SDavid du Colombieris then set executing. This may cause 1998219b2ee8SDavid du Colombier.CW stopped() 1999219b2ee8SDavid du Colombierto be called twice. 2000219b2ee8SDavid du Colombier.CW cont 2001219b2ee8SDavid du Colombiercauses the interpreter to block until the process enters the 2002bd389b36SDavid du Colombier.CW Stopped 2003219b2ee8SDavid du Colombierstate. 2004219b2ee8SDavid du Colombier.Ex 2005219b2ee8SDavid du Colombieracid: cont() 2006219b2ee8SDavid du Colombier95197: breakpoint ls+0x4 MOVW R31,0x0(R29) 2007219b2ee8SDavid du Colombier.Ee 2008219b2ee8SDavid du Colombier.\" 2009219b2ee8SDavid du Colombier.\" 2010219b2ee8SDavid du Colombier.\" 2011219b2ee8SDavid du Colombier.Ip \f(CW{}\fP dump integer,integer,string "Formatted memory dump 2012219b2ee8SDavid du Colombier.CW dump 2013219b2ee8SDavid du Colombierinterprets its first argument as an address, its second argument as a 2014219b2ee8SDavid du Colombiercount and its third as a format string. 2015219b2ee8SDavid du Colombier.CW dump 2016219b2ee8SDavid du Colombierfetches an object from memory at the current address and prints it according 2017219b2ee8SDavid du Colombierto the format. The address is incremented by the number of bytes specified by 2018219b2ee8SDavid du Colombierthe format and the process is repeated count times. The format string is any 2019219b2ee8SDavid du Colombiercombination of format characters, each preceded by an optional count. 2020219b2ee8SDavid du ColombierFor each object, 2021219b2ee8SDavid du Colombier.CW dump 2022219b2ee8SDavid du Colombierprints the address in hexadecimal, a colon, the object and then a newline. 2023219b2ee8SDavid du Colombier.CW dump 2024219b2ee8SDavid du Colombieruses 2025219b2ee8SDavid du Colombier.CW mem 2026219b2ee8SDavid du Colombierto fetch each object. 2027219b2ee8SDavid du Colombier.Ex 2028219b2ee8SDavid du Colombieracid: dump(main+35, 4, "X2bi") 2029219b2ee8SDavid du Colombier0x00001043: 0x0c8fa700 108 143 lwc2 r0,0x528f(R4) 2030219b2ee8SDavid du Colombier0x0000104d: 0xa9006811 0 0 swc3 r0,0x0(R24) 2031219b2ee8SDavid du Colombier0x00001057: 0x2724e800 4 37 ADD $-0x51,R23,R31 2032219b2ee8SDavid du Colombier0x00001061: 0xa200688d 6 0 NOOP 2033219b2ee8SDavid du Colombier0x0000106b: 0x2710c000 7 0 BREAK 2034219b2ee8SDavid du Colombier.Ee 2035219b2ee8SDavid du Colombier.\" 2036219b2ee8SDavid du Colombier.\" 2037219b2ee8SDavid du Colombier.\" 2038219b2ee8SDavid du Colombier.Ip \f(CW{}\fP findsrc string "Use source path to load source file 2039219b2ee8SDavid du Colombier.CW findsrc 2040219b2ee8SDavid du Colombierinterprets its 2041219b2ee8SDavid du Colombier.I string 2042219b2ee8SDavid du Colombierargument as a source file. Each directory in the source path is searched 2043219b2ee8SDavid du Colombierin turn for the file. If the file is found, the source text is loaded using 2044219b2ee8SDavid du Colombier.CW file 2045219b2ee8SDavid du Colombierand stored in the list of active source files called 2046219b2ee8SDavid du Colombier.CW srctext . 2047219b2ee8SDavid du ColombierThe name of the file is added to the source file name list 2048219b2ee8SDavid du Colombier.CW srcfiles . 2049219b2ee8SDavid du ColombierUsers are unlikely to call 2050219b2ee8SDavid du Colombier.CW findsrc 2051219b2ee8SDavid du Colombierfrom the command line, but may use it from scripts to preload source files 2052219b2ee8SDavid du Colombierfor a debugging session. This function is used by 2053219b2ee8SDavid du Colombier.CW src 2054219b2ee8SDavid du Colombierand 2055219b2ee8SDavid du Colombier.CW line 2056219b2ee8SDavid du Colombierto locate and load source code. The default search path for the MIPS 2057219b2ee8SDavid du Colombieris 2058219b2ee8SDavid du Colombier.CW ./ , 2059219b2ee8SDavid du Colombier.CW /sys/src/libc/port , 2060219b2ee8SDavid du Colombier.CW /sys/src/libc/9sys , 2061219b2ee8SDavid du Colombier.CW /sys/src/libc/mips . 2062219b2ee8SDavid du Colombier.Ex 2063219b2ee8SDavid du Colombieracid: findsrc(pcfile(main)); 2064219b2ee8SDavid du Colombier.Ee 2065219b2ee8SDavid du Colombier.\" 2066219b2ee8SDavid du Colombier.\" 2067219b2ee8SDavid du Colombier.\" 2068219b2ee8SDavid du Colombier.Ip \f(CW{}\fP fpr "" "Display single precision floating registers 2069219b2ee8SDavid du ColombierFor machines equipped with floating point, 2070219b2ee8SDavid du Colombier.CW fpr 2071219b2ee8SDavid du Colombierdisplays the contents of the floating point registers as single precision 2072219b2ee8SDavid du Colombiervalues. When the interpreter stores or manipulates floating point values 2073219b2ee8SDavid du Colombierit converts into double precision values. 2074219b2ee8SDavid du Colombier.Ex 2075219b2ee8SDavid du Colombieracid: fpr() 2076219b2ee8SDavid du ColombierF0 0. F1 0. 2077219b2ee8SDavid du ColombierF2 0. F3 0. 2078219b2ee8SDavid du ColombierF4 0. F5 0. 2079219b2ee8SDavid du Colombier\&... 2080219b2ee8SDavid du Colombier.Ee 2081219b2ee8SDavid du Colombier.\" 2082219b2ee8SDavid du Colombier.\" 2083219b2ee8SDavid du Colombier.\" 2084219b2ee8SDavid du Colombier.Ip \f(CW{}\fP func "" "Step while in function 2085219b2ee8SDavid du Colombier.CW func 2086219b2ee8SDavid du Colombiersingle steps the active process until it leaves the current function 2087219b2ee8SDavid du Colombierby either calling another function or returning to its caller. 2088219b2ee8SDavid du Colombier.CW func 2089219b2ee8SDavid du Colombierwill execute a single instruction after leaving the current function. 2090219b2ee8SDavid du Colombier.Ex 2091219b2ee8SDavid du Colombieracid: func() 2092219b2ee8SDavid du Colombier95197: breakpoint ls+0x8 MOVW R1,R8 2093219b2ee8SDavid du Colombier95197: breakpoint ls+0xc MOVW R8,R1 2094219b2ee8SDavid du Colombier95197: breakpoint ls+0x10 MOVW R8,s+4(FP) 2095219b2ee8SDavid du Colombier95197: breakpoint ls+0x14 MOVW $0x2f,R5 2096219b2ee8SDavid du Colombier95197: breakpoint ls+0x18 JAL utfrrune(SB) 2097219b2ee8SDavid du Colombier95197: breakpoint utfrrune ADD $-0x18,R29 2098219b2ee8SDavid du Colombier.Ee 2099219b2ee8SDavid du Colombier.\" 2100219b2ee8SDavid du Colombier.\" 2101219b2ee8SDavid du Colombier.\" 2102219b2ee8SDavid du Colombier.Ip \f(CW{}\fP gpr "" "Display general purpose registers 2103219b2ee8SDavid du Colombier.CW gpr 2104219b2ee8SDavid du Colombierprints the values of the general purpose processor registers. 2105219b2ee8SDavid du Colombier.Ex 2106219b2ee8SDavid du Colombieracid: gpr() 2107219b2ee8SDavid du ColombierR1 0x00009562 R2 0x000010a4 R3 0x00005d08 2108219b2ee8SDavid du ColombierR4 0x0000000a R5 0x0000002f R6 0x00000008 2109219b2ee8SDavid du Colombier\&... 2110219b2ee8SDavid du Colombier.Ee 2111219b2ee8SDavid du Colombier.\" 2112219b2ee8SDavid du Colombier.\" 2113219b2ee8SDavid du Colombier.\" 2114219b2ee8SDavid du Colombier.Ip \f(CW{}\fP labstk integer "Print stack trace from label 2115219b2ee8SDavid du Colombier.CW labstk 2116219b2ee8SDavid du Colombierperforms a stack trace from a Plan 9 2117219b2ee8SDavid du Colombier.I label. 2118219b2ee8SDavid du ColombierThe kernel, 21197dd7cddfSDavid du ColombierC compilers store continuations in a common format. Since the 2120219b2ee8SDavid du Colombiercompilers all use caller save conventions a continuation may be saved by 2121219b2ee8SDavid du Colombierstoring a 2122219b2ee8SDavid du Colombier.CW PC 2123219b2ee8SDavid du Colombierand 2124219b2ee8SDavid du Colombier.CW SP 21257dd7cddfSDavid du Colombierpair. This data structure is called a label and is used by the 21267dd7cddfSDavid du Colombierthe C function 21277dd7cddfSDavid du Colombier.CW longjmp 2128219b2ee8SDavid du Colombierand the kernel to schedule threads and processes. 2129219b2ee8SDavid du Colombier.CW labstk 2130219b2ee8SDavid du Colombierinterprets its 2131219b2ee8SDavid du Colombier.I integer 2132219b2ee8SDavid du Colombierargument as the address of a label and produces a stack trace for 2133219b2ee8SDavid du Colombierthe thread of execution. The value of the function 2134219b2ee8SDavid du Colombier.CW ALEF_tid 2135219b2ee8SDavid du Colombieris a suitable argument for 2136219b2ee8SDavid du Colombier.CW labstk . 2137219b2ee8SDavid du Colombier.Ex 2138219b2ee8SDavid du Colombieracid: labstk(*mousetid) 2139219b2ee8SDavid du ColombierAt pc:0x00021a70:Rendez_Sleep+0x178 rendez.l:44 2140219b2ee8SDavid du ColombierRendez_Sleep(r=0xcd7d8,bool=0xcd7e0,t=0x0) rendez.l:5 2141219b2ee8SDavid du Colombier called from ALEF_rcvmem+0x198 recvmem.l:45 2142219b2ee8SDavid du ColombierALEF_rcvmem(c=0x000cd764,l=0x00000010) recvmem.l:6 2143219b2ee8SDavid du Colombier\&... 2144219b2ee8SDavid du Colombier.Ee 2145219b2ee8SDavid du Colombier.\" 2146219b2ee8SDavid du Colombier.\" 2147219b2ee8SDavid du Colombier.\" 2148219b2ee8SDavid du Colombier.Ip \f(CW{}\fP lstk "" "Stack trace with local variables 2149219b2ee8SDavid du Colombier.CW lstk 2150219b2ee8SDavid du Colombierproduces a long format stack trace. 2151219b2ee8SDavid du ColombierThe stack trace includes each function in the stack, 2152219b2ee8SDavid du Colombierwhere it was called from, and the value of the parameters and automatic 2153219b2ee8SDavid du Colombiervariables for each function. 2154219b2ee8SDavid du Colombier.CW lstk 2155219b2ee8SDavid du Colombierdisplays the value rather than the address of each variable and all 2156219b2ee8SDavid du Colombiervariables are assumed to be an integer in format 2157219b2ee8SDavid du Colombier.CW X . 2158219b2ee8SDavid du ColombierTo print a variable in its correct format use the 2159219b2ee8SDavid du Colombier.CW : 2160219b2ee8SDavid du Colombieroperator to find the address and apply the appropriate format before indirection 2161219b2ee8SDavid du Colombierwith the 2162219b2ee8SDavid du Colombier.CW * 2163219b2ee8SDavid du Colombieroperator. It may be necessary to single step a couple of instructions into 2164219b2ee8SDavid du Colombiera function to get a correct stack trace because the frame pointer adjustment 2165219b2ee8SDavid du Colombierinstruction may get scheduled down into the body of the function. 2166219b2ee8SDavid du Colombier.Ex 2167219b2ee8SDavid du Colombieracid: lstk() 2168219b2ee8SDavid du ColombierAt pc:0x00001024:main+0x4 ls.c:48 2169219b2ee8SDavid du Colombiermain(argc=0x00000001,argv=0x7fffefec) ls.c:48 2170219b2ee8SDavid du Colombier called from _main+0x20 main9.s:10 2171219b2ee8SDavid du Colombier _argc=0x00000000 2172219b2ee8SDavid du Colombier _args=0x00000000 2173219b2ee8SDavid du Colombier fd=0x00000000 2174219b2ee8SDavid du Colombier buf=0x00000000 2175219b2ee8SDavid du Colombier i=0x00000000 2176219b2ee8SDavid du Colombier.Ee 2177219b2ee8SDavid du Colombier.\" 2178219b2ee8SDavid du Colombier.\" 2179219b2ee8SDavid du Colombier.\" 2180219b2ee8SDavid du Colombier.Ip \f(CW{}\fP mem integer,string "Print memory object 2181219b2ee8SDavid du Colombier.CW mem 2182219b2ee8SDavid du Colombierinterprets its first 2183219b2ee8SDavid du Colombier.I integer 2184219b2ee8SDavid du Colombierargument as the address of an object to be printed according to the 2185219b2ee8SDavid du Colombierformat supplied in its second 2186219b2ee8SDavid du Colombier.I string 2187219b2ee8SDavid du Colombierargument. 2188219b2ee8SDavid du ColombierThe format string can be any combination of format characters, each preceded 2189219b2ee8SDavid du Colombierby an optional count. 2190219b2ee8SDavid du Colombier.Ex 2191219b2ee8SDavid du Colombieracid: mem(bdata+0x326, "2c2Xb") 2192219b2ee8SDavid du ColombierP = 0xa94bc464 0x3e5ae44d 19 2193219b2ee8SDavid du Colombier.Ee 2194219b2ee8SDavid du Colombier.\" 2195219b2ee8SDavid du Colombier.\" 2196219b2ee8SDavid du Colombier.\" 2197219b2ee8SDavid du Colombier.Ip \f(CW{}\fP new "" "Create new process 2198219b2ee8SDavid du Colombier.CW new 2199219b2ee8SDavid du Colombierstarts a new copy of the debugged program. The new program is started 2200219b2ee8SDavid du Colombierwith the program arguments set by the variable 2201219b2ee8SDavid du Colombier.CW progargs . 2202219b2ee8SDavid du ColombierThe new program is stopped in the second instruction of 2203219b2ee8SDavid du Colombier.CW main . 2204219b2ee8SDavid du ColombierThe breakpoint list is reinitialized. 2205219b2ee8SDavid du Colombier.CW new 2206219b2ee8SDavid du Colombiermay be used several times to instantiate several copies of a program 2207219b2ee8SDavid du Colombiersimultaneously. The user can rotate between the copies using 2208219b2ee8SDavid du Colombier.CW setproc . 2209219b2ee8SDavid du Colombier.Ex 2210219b2ee8SDavid du Colombieracid: progargs="-l" 2211219b2ee8SDavid du Colombieracid: new() 2212219b2ee8SDavid du Colombier60: external interrupt _main ADD $-0x14,R29 2213219b2ee8SDavid du Colombier60: breakpoint main+0x4 MOVW R31,0x0(R29) 2214219b2ee8SDavid du Colombier.Ee 2215219b2ee8SDavid du Colombier.\" 2216219b2ee8SDavid du Colombier.\" 2217219b2ee8SDavid du Colombier.\" 2218219b2ee8SDavid du Colombier.Ip \f(CW{}\fP next "" "Step through language statement 2219219b2ee8SDavid du Colombier.CW next 2220219b2ee8SDavid du Colombiersteps through a single language level statement without tracing down 2221219b2ee8SDavid du Colombierthrough each statement in a called function. For each statement, 2222219b2ee8SDavid du Colombier.CW next 2223219b2ee8SDavid du Colombierprints the machine instructions executed as part of the statement. After 2224219b2ee8SDavid du Colombierthe statement has executed, source lines around the current program 2225219b2ee8SDavid du Colombiercounter are displayed. 2226219b2ee8SDavid du Colombier.Ex 2227219b2ee8SDavid du Colombieracid: next() 2228219b2ee8SDavid du Colombier60: breakpoint Binit+0x4 MOVW R31,0x0(R29) 2229219b2ee8SDavid du Colombier60: breakpoint Binit+0x8 MOVW f+8(FP),R4 2230219b2ee8SDavid du Colombierbinit.c:93 2231219b2ee8SDavid du Colombier 88 2232219b2ee8SDavid du Colombier 89 int 2233219b2ee8SDavid du Colombier 90 Binit(Biobuf *bp, int f, int mode) 2234219b2ee8SDavid du Colombier 91 { 2235219b2ee8SDavid du Colombier>92 return Binits(bp, f, mode, bp->b, BSIZE); 2236219b2ee8SDavid du Colombier 93 } 2237219b2ee8SDavid du Colombier.Ee 2238219b2ee8SDavid du Colombier.\" 2239219b2ee8SDavid du Colombier.\" 2240219b2ee8SDavid du Colombier.\" 2241219b2ee8SDavid du Colombier.Ip \f(CW{}\fP notestk integer "Stack trace after receiving a note 2242219b2ee8SDavid du Colombier.CW notestk 2243219b2ee8SDavid du Colombierinterprets its 2244219b2ee8SDavid du Colombier.I integer 2245219b2ee8SDavid du Colombierargument as the address of a 2246219b2ee8SDavid du Colombier.CW Ureg 2247219b2ee8SDavid du Colombierstructure passed by the kernel to a 2248219b2ee8SDavid du Colombier.I notify (2) 2249219b2ee8SDavid du Colombierfunction during note processing. 2250219b2ee8SDavid du Colombier.CW notestk 2251219b2ee8SDavid du Colombieruses the 2252219b2ee8SDavid du Colombier.CW PC , 2253219b2ee8SDavid du Colombier.CW SP , 2254219b2ee8SDavid du Colombierand link register from the 2255219b2ee8SDavid du Colombier.CW Ureg 2256219b2ee8SDavid du Colombierto print a stack trace corresponding to the point in the program where the note 2257219b2ee8SDavid du Colombierwas received. 2258219b2ee8SDavid du ColombierTo get a valid stack trace on the MIPS and SPARC architectures from a notify 2259219b2ee8SDavid du Colombierroutine, the program must stop in a new function called from the notify routine 2260219b2ee8SDavid du Colombierso that the link register is valid and the notify routine's parameters are 2261219b2ee8SDavid du Colombieraddressable. 2262219b2ee8SDavid du Colombier.Ex 2263219b2ee8SDavid du Colombieracid: notestk(*notify:ur) 2264219b2ee8SDavid du ColombierNote pc:0x00001024:main+0x4 ls.c:48 2265219b2ee8SDavid du Colombiermain(argc=0x00000001,argv=0x7fffefec) ls.c:48 2266219b2ee8SDavid du Colombier called from _main+0x20 main9.s:10 2267219b2ee8SDavid du Colombier _argc=0x00000000 2268219b2ee8SDavid du Colombier _args=0x00000000 2269219b2ee8SDavid du Colombier.Ee 2270219b2ee8SDavid du Colombier.\" 2271219b2ee8SDavid du Colombier.\" 2272219b2ee8SDavid du Colombier.\" 2273219b2ee8SDavid du Colombier.Ip \f(CW{}\fP pfl integer "Print source file and line 2274219b2ee8SDavid du Colombier.CW pfl 2275219b2ee8SDavid du Colombierinterprets its argument as a text address and uses it to print 2276219b2ee8SDavid du Colombierthe source file and line number corresponding to the address. The output 2277219b2ee8SDavid du Colombierhas the same format as file addresses in 2278219b2ee8SDavid du Colombier.I acme (1). 2279219b2ee8SDavid du Colombier.Ex 2280219b2ee8SDavid du Colombieracid: pfl(main) 2281219b2ee8SDavid du Colombierls.c:48 2282219b2ee8SDavid du Colombier.Ee 2283219b2ee8SDavid du Colombier.\" 2284219b2ee8SDavid du Colombier.\" 2285219b2ee8SDavid du Colombier.\" 2286219b2ee8SDavid du Colombier.Ip \f(CW{}\fP procs "" "Print active process list 2287219b2ee8SDavid du Colombier.CW procs 2288219b2ee8SDavid du Colombierprints a list of active process attached to the debugger. Each process 2289219b2ee8SDavid du Colombierproduces a single line of output giving the pid, process state, the address 2290219b2ee8SDavid du Colombierthe process is currently executing, and the 2291219b2ee8SDavid du Colombier.CW setproc 2292219b2ee8SDavid du Colombiercommand required to make that process current. 2293219b2ee8SDavid du ColombierThe current process is marked in the first column with a 2294219b2ee8SDavid du Colombier.CW > 2295219b2ee8SDavid du Colombiercharacter. The debugger maintains a list of processes in the variable 2296219b2ee8SDavid du Colombier.CW proclist . 2297219b2ee8SDavid du Colombier.Ex 2298219b2ee8SDavid du Colombieracid: procs() 2299219b2ee8SDavid du Colombier>62: Stopped at main+0x4 setproc(62) 2300219b2ee8SDavid du Colombier 60: Stopped at Binit+0x8 setproc(60) 2301219b2ee8SDavid du Colombier.Ee 2302219b2ee8SDavid du Colombier.\" 2303219b2ee8SDavid du Colombier.\" 2304219b2ee8SDavid du Colombier.\" 2305219b2ee8SDavid du Colombier.Ip \f(CW{}\fP pstop integer "Print reason process stopped 2306219b2ee8SDavid du Colombier.CW pstop 2307219b2ee8SDavid du Colombierprints the status of the process specified by the 2308219b2ee8SDavid du Colombier.I integer 2309219b2ee8SDavid du Colombierpid supplied as its argument. 2310219b2ee8SDavid du Colombier.CW pstop 2311219b2ee8SDavid du Colombieris usually called from 2312219b2ee8SDavid du Colombier.CW stopped 2313219b2ee8SDavid du Colombierevery time a process enters the 2314219b2ee8SDavid du Colombier.CW Stopped 2315219b2ee8SDavid du Colombierstate. 2316219b2ee8SDavid du Colombier.Ex 2317219b2ee8SDavid du Colombieracid: pstop(62) 2318219b2ee8SDavid du Colombier0x0000003e: breakpoint main+0x4 MOVW R31,0x0(R29) 2319219b2ee8SDavid du Colombier.Ee 2320219b2ee8SDavid du Colombier.\" 2321219b2ee8SDavid du Colombier.\" 2322219b2ee8SDavid du Colombier.\" 2323219b2ee8SDavid du Colombier.Ip \f(CW{}\fP regs "" "Print registers 2324219b2ee8SDavid du Colombier.CW regs 2325219b2ee8SDavid du Colombierprints the contents of both the general and special purpose registers. 2326219b2ee8SDavid du Colombier.CW regs 2327219b2ee8SDavid du Colombiercalls 2328219b2ee8SDavid du Colombier.CW spr 2329219b2ee8SDavid du Colombierthen 2330219b2ee8SDavid du Colombier.CW gpr 2331219b2ee8SDavid du Colombierto display the contents of the registers. 2332219b2ee8SDavid du Colombier.KE 2333219b2ee8SDavid du Colombier.\" 2334219b2ee8SDavid du Colombier.\" 2335219b2ee8SDavid du Colombier.\" 2336219b2ee8SDavid du Colombier.Ip \f(CW{}\fP source "" "Summarize source data base 2337219b2ee8SDavid du Colombier.CW source 2338219b2ee8SDavid du Colombierprints the directory search path followed by a list of currently loaded 2339219b2ee8SDavid du Colombiersource files. The source management functions 2340219b2ee8SDavid du Colombier.CW src 2341219b2ee8SDavid du Colombierand 2342219b2ee8SDavid du Colombier.CW findsrc 2343219b2ee8SDavid du Colombieruse the search path to locate and load source files. Source files are 2344219b2ee8SDavid du Colombierloaded incrementally into a source data base during debugging. A list 2345219b2ee8SDavid du Colombierof loaded files is stored in the variable 2346219b2ee8SDavid du Colombier.CW srcfiles 2347219b2ee8SDavid du Colombierand the contents of each source file in the variable 2348219b2ee8SDavid du Colombier.CW srctext . 2349219b2ee8SDavid du Colombier.Ex 2350219b2ee8SDavid du Colombieracid: source() 2351219b2ee8SDavid du Colombier/n/bootes/sys/src/libbio/ 2352219b2ee8SDavid du Colombier./ 2353219b2ee8SDavid du Colombier/sys/src/libc/port/ 2354219b2ee8SDavid du Colombier/sys/src/libc/9sys/ 2355219b2ee8SDavid du Colombier/sys/src/libc/mips/ 2356219b2ee8SDavid du Colombier binit.c 2357219b2ee8SDavid du Colombier.Ee 2358219b2ee8SDavid du Colombier.\" 2359219b2ee8SDavid du Colombier.\" 2360219b2ee8SDavid du Colombier.\" 2361219b2ee8SDavid du Colombier.Ip \f(CW{}\fP spr "" "Print special purpose registers 2362219b2ee8SDavid du Colombier.CW spr 2363219b2ee8SDavid du Colombierprints the contents of the processor control and memory management 2364219b2ee8SDavid du Colombierregisters. Where possible, the contents of the registers are decoded 2365219b2ee8SDavid du Colombierto provide extra information; for example the 2366219b2ee8SDavid du Colombier.CW CAUSE 2367219b2ee8SDavid du Colombierregister on the MIPS is 2368219b2ee8SDavid du Colombierprinted both in hexadecimal and using the 2369219b2ee8SDavid du Colombier.CW reason 2370219b2ee8SDavid du Colombierfunction. 2371219b2ee8SDavid du Colombier.Ex 2372219b2ee8SDavid du Colombieracid: spr() 2373219b2ee8SDavid du ColombierPC 0x00001024 main+0x4 ls.c:48 2374219b2ee8SDavid du ColombierSP 0x7fffef68 LINK 0x00006264 _main+0x28 main9.s:12 2375219b2ee8SDavid du ColombierSTATUS 0x0000ff33 CAUSE 0x00000024 breakpoint 2376219b2ee8SDavid du ColombierTLBVIR 0x000000d3 BADVADR 0x00001020 2377219b2ee8SDavid du ColombierHI 0x00000004 LO 0x00001ff7 2378219b2ee8SDavid du Colombier.Ee 2379219b2ee8SDavid du Colombier.\" 2380219b2ee8SDavid du Colombier.\" 2381219b2ee8SDavid du Colombier.\" 2382219b2ee8SDavid du Colombier.Ip \f(CW{}\fP src integer "Print lines of source 2383219b2ee8SDavid du Colombier.CW src 2384219b2ee8SDavid du Colombierinterprets its 2385219b2ee8SDavid du Colombier.I integer 2386219b2ee8SDavid du Colombierargument as a text address and uses this address to print 5 lines 2387219b2ee8SDavid du Colombierof source before and after the address. The current line is marked with a 2388bd389b36SDavid du Colombier.CW > 2389bd389b36SDavid du Colombiercharacter. 2390bd389b36SDavid du Colombier.CW src 2391219b2ee8SDavid du Colombieruses the source search path maintained by 2392219b2ee8SDavid du Colombier.CW source 2393219b2ee8SDavid du Colombierand 2394219b2ee8SDavid du Colombier.CW addsrcdir 2395219b2ee8SDavid du Colombierto locate the required source files. 2396219b2ee8SDavid du Colombier.Ex 2397219b2ee8SDavid du Colombieracid: src(*PC) 2398219b2ee8SDavid du Colombierls.c:47 2399219b2ee8SDavid du Colombier 42 Biobuf bin; 2400219b2ee8SDavid du Colombier 43 2401219b2ee8SDavid du Colombier 44 #define HUNK 50 2402219b2ee8SDavid du Colombier 45 2403219b2ee8SDavid du Colombier 46 void 2404219b2ee8SDavid du Colombier>47 main(int argc, char *argv[]) 2405219b2ee8SDavid du Colombier 48 { 2406219b2ee8SDavid du Colombier 49 int i, fd; 2407219b2ee8SDavid du Colombier 50 char buf[64]; 2408219b2ee8SDavid du Colombier 51 2409219b2ee8SDavid du Colombier 52 Binit(&bin, 1, OWRITE); 2410219b2ee8SDavid du Colombier.Ee 2411219b2ee8SDavid du Colombier.\" 2412219b2ee8SDavid du Colombier.\" 2413219b2ee8SDavid du Colombier.\" 2414219b2ee8SDavid du Colombier.Ip \f(CW{}\fP step "" "Single step process 2415219b2ee8SDavid du Colombier.CW step 2416219b2ee8SDavid du Colombiercauses the debugged process to execute a single machine level instruction. 2417219b2ee8SDavid du ColombierIf the program is stopped on a breakpoint set by 2418219b2ee8SDavid du Colombier.CW bpset 2419219b2ee8SDavid du Colombierit is first removed, the single step executed, and the breakpoint replaced. 2420219b2ee8SDavid du Colombier.CW step 2421219b2ee8SDavid du Colombieruses 2422219b2ee8SDavid du Colombier.CW follow 2423219b2ee8SDavid du Colombierto predict the address of the program counter after the current instruction 2424219b2ee8SDavid du Colombierhas been executed. A breakpoint is placed at each of these predicted addresses 2425219b2ee8SDavid du Colombierand the process is started. When the process stops the breakpoints are removed. 2426219b2ee8SDavid du Colombier.Ex 2427219b2ee8SDavid du Colombieracid: step() 2428219b2ee8SDavid du Colombier62: breakpoint main+0x8 MOVW R1,argc+4(FP) 2429219b2ee8SDavid du Colombier.Ee 2430219b2ee8SDavid du Colombier.\" 2431219b2ee8SDavid du Colombier.\" 2432219b2ee8SDavid du Colombier.\" 2433219b2ee8SDavid du Colombier.Ip \f(CW{}\fP stk "" "Stack trace 2434219b2ee8SDavid du Colombier.CW stk 2435219b2ee8SDavid du Colombierproduces a short format stack trace. The stack trace includes each function 2436219b2ee8SDavid du Colombierin the stack, where it was called from, and the value of the parameters. 2437219b2ee8SDavid du ColombierThe short format omits the values of automatic variables. 2438219b2ee8SDavid du ColombierParameters are assumed to be integer values in the format 2439219b2ee8SDavid du Colombier.CW X ; 2440219b2ee8SDavid du Colombierto print a parameter in the correct format use the 2441219b2ee8SDavid du Colombier.CW : 2442219b2ee8SDavid du Colombierto obtain its address, apply the correct format, and use the 2443219b2ee8SDavid du Colombier.CW * 2444219b2ee8SDavid du Colombierindirection operator to find its value. 2445219b2ee8SDavid du ColombierIt may be necessary to single step a couple of instructions into 2446219b2ee8SDavid du Colombiera function to get a correct stack trace because the frame pointer adjustment 2447219b2ee8SDavid du Colombierinstruction may get scheduled down into the body of the function. 2448219b2ee8SDavid du Colombier.Ex 2449219b2ee8SDavid du Colombieracid: stk() 2450219b2ee8SDavid du ColombierAt pc:0x00001028:main+0x8 ls.c:48 2451219b2ee8SDavid du Colombiermain(argc=0x00000002,argv=0x7fffefe4) ls.c:48 2452219b2ee8SDavid du Colombier called from _main+0x20 main9.s:10 2453219b2ee8SDavid du Colombier.Ee 2454219b2ee8SDavid du Colombier.\" 2455219b2ee8SDavid du Colombier.\" 2456219b2ee8SDavid du Colombier.\" 2457219b2ee8SDavid du Colombier.Ip \f(CW{}\fP stmnt "" "Execute a single statement 2458219b2ee8SDavid du Colombier.CW stmnt 2459219b2ee8SDavid du Colombierexecutes a single language level statement. 2460219b2ee8SDavid du Colombier.CW stmnt 2461219b2ee8SDavid du Colombierdisplays each machine level instruction as it is executed. When the executed 2462219b2ee8SDavid du Colombierstatement is completed the source for the next statement is displayed. 2463219b2ee8SDavid du ColombierUnlike 2464219b2ee8SDavid du Colombier.CW next , 2465219b2ee8SDavid du Colombierthe 2466219b2ee8SDavid du Colombier.CW stmnt 2467219b2ee8SDavid du Colombierfunction will trace down through function calls. 2468219b2ee8SDavid du Colombier.Ex 2469219b2ee8SDavid du Colombieracid: stmnt() 2470219b2ee8SDavid du Colombier62: breakpoint main+0x18 MOVW R5,0xc(R29) 2471219b2ee8SDavid du Colombier62: breakpoint main+0x1c JAL Binit(SB) 2472219b2ee8SDavid du Colombier62: breakpoint Binit ADD $-0x18,R29 2473219b2ee8SDavid du Colombierbinit.c:91 2474219b2ee8SDavid du Colombier 89 int 2475219b2ee8SDavid du Colombier 90 Binit(Biobuf *bp, int f, int mode) 2476219b2ee8SDavid du Colombier>91 { 2477219b2ee8SDavid du Colombier.Ee 2478219b2ee8SDavid du Colombier.\" 2479219b2ee8SDavid du Colombier.\" 2480219b2ee8SDavid du Colombier.\" 2481219b2ee8SDavid du Colombier.Ip \f(CW{}\fP stopped integer "Report status of stopped process 2482219b2ee8SDavid du Colombier.CW stopped 2483219b2ee8SDavid du Colombieris called automatically by the interpreter 2484219b2ee8SDavid du Colombierevery time a process enters the 2485219b2ee8SDavid du Colombier.CW Stopped 2486219b2ee8SDavid du Colombierstate, such as when it hits a breakpoint. 2487219b2ee8SDavid du ColombierThe pid is passed as the 2488219b2ee8SDavid du Colombier.I integer 2489219b2ee8SDavid du Colombierargument. The default implementation just calls 2490219b2ee8SDavid du Colombier.CW pstop , 2491219b2ee8SDavid du Colombierbut the function may be changed to provide more information or perform fine control 2492219b2ee8SDavid du Colombierof execution. Note that 2493219b2ee8SDavid du Colombier.CW stopped 2494219b2ee8SDavid du Colombiershould return; for example, calling 2495219b2ee8SDavid du Colombier.CW step 2496219b2ee8SDavid du Colombierin 2497219b2ee8SDavid du Colombier.CW stopped 2498219b2ee8SDavid du Colombierwill recur until the interpreter runs out of stack space. 2499219b2ee8SDavid du Colombier.Ex 2500219b2ee8SDavid du Colombieracid: defn stopped(pid) { 2501219b2ee8SDavid du Colombier if *lflag != 0 then error("lflag modified"); 2502219b2ee8SDavid du Colombier } 2503219b2ee8SDavid du Colombieracid: progargs = "-l" 2504219b2ee8SDavid du Colombieracid: new(); 2505219b2ee8SDavid du Colombieracid: while 1 do step(); 2506219b2ee8SDavid du Colombier<stdin>:7: (error) lflag modified 2507219b2ee8SDavid du Colombieracid: stk() 2508219b2ee8SDavid du ColombierAt pc:0x00001220:main+0x200 ls.c:54 2509219b2ee8SDavid du Colombiermain(argc=0x00000001,argv=0x7fffffe8) ls.c:48 2510219b2ee8SDavid du Colombier called from _main+0x20 main9.s:10 2511219b2ee8SDavid du Colombier.Ee 2512219b2ee8SDavid du Colombier.\" 2513219b2ee8SDavid du Colombier.\" 2514219b2ee8SDavid du Colombier.\" 2515219b2ee8SDavid du Colombier.Ip \f(CW{}\fP symbols string "Search symbol table 2516219b2ee8SDavid du Colombier.CW symbols 2517219b2ee8SDavid du Colombieruses the regular expression supplied by 2518219b2ee8SDavid du Colombier.I string 2519219b2ee8SDavid du Colombierto search the symbol table for symbols whose name matches the 2520219b2ee8SDavid du Colombierregular expression. 2521219b2ee8SDavid du Colombier.Ex 2522219b2ee8SDavid du Colombieracid: symbols("main") 2523219b2ee8SDavid du Colombiermain T 0x00001020 2524219b2ee8SDavid du Colombier_main T 0x0000623c 2525219b2ee8SDavid du Colombier.Ee 2526219b2ee8SDavid du Colombier.\" 2527219b2ee8SDavid du Colombier.\" 2528219b2ee8SDavid du Colombier.\" 2529219b2ee8SDavid du Colombier.Ip \f(CW{}\fP win "" "Start new process in a window 2530219b2ee8SDavid du Colombier.CW win 2531219b2ee8SDavid du Colombierperforms exactly the same function as 2532219b2ee8SDavid du Colombier.CW new 2533219b2ee8SDavid du Colombierbut uses the window system to create a new window for the debugged process. 2534219b2ee8SDavid du ColombierThe variable 2535219b2ee8SDavid du Colombier.CW progargs 2536219b2ee8SDavid du Colombiersupplies arguments to the new process. 2537219b2ee8SDavid du ColombierThe environment variable 2538219b2ee8SDavid du Colombier.CW $8½srv 2539219b2ee8SDavid du Colombiermust be set to allow the interpreter to locate the mount channel for the 2540219b2ee8SDavid du Colombierwindow system. 2541219b2ee8SDavid du ColombierThe window is created in the top left corner of the screen and is 2542219b2ee8SDavid du Colombier400x600 pixels in size. The 2543219b2ee8SDavid du Colombier.CW win 2544219b2ee8SDavid du Colombierfunction may be modified to alter the geometry. 2545219b2ee8SDavid du ColombierThe window system will not be able to deliver notes in the new window 2546219b2ee8SDavid du Colombiersince the pid of the created process is not passed when the server is 2547219b2ee8SDavid du Colombiermounted to create a new window. 2548219b2ee8SDavid du Colombier.Ex 2549219b2ee8SDavid du Colombieracid: win() 2550219b2ee8SDavid du Colombier.Ee 2551