acid.ms 64 KB

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