acid.ms 64 KB

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