1
0

acid.ms 64 KB

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