acid.ms 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513
  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. Subtraction is undefined for
  807. these two types.
  808. .DS
  809. shift-expression:
  810. additive-expression
  811. shift-expression \f(CW<<\fP additive-expression
  812. shift-expression \f(CW>>\fP additive-expression
  813. .DE
  814. The
  815. .CW >>
  816. and
  817. .CW <<
  818. operators perform bitwise right and left shifts respectively. Both
  819. require operands of
  820. .I integer
  821. type.
  822. .DS
  823. relational-expression:
  824. relational-expression \f(CW<\fP shift-expression
  825. relational-expression \f(CW>\fP shift-expression
  826. relational-expression \f(CW<=\fP shift-expression
  827. relational-expression \f(CW>=\fP shift-expression
  828. equality-expression:
  829. relational-expression
  830. relational-expression \f(CW==\fP equality-expression
  831. relational-expression \f(CW!=\fP equality-expression
  832. .DE
  833. The comparison operators are
  834. .CW <
  835. (less than),
  836. .CW >
  837. (greater than),
  838. .CW <=
  839. (less than or equal to),
  840. .CW >=
  841. (greater than or equal to),
  842. .CW ==
  843. (equal to) and
  844. .CW !=
  845. (not equal to). The result of a comparison is 0
  846. if the condition is false, otherwise 1. The relational operators can only be
  847. applied to operands of
  848. .I integer
  849. and
  850. .I float
  851. type. The equality operators apply to all types. Comparing mixed types is legal.
  852. Mixed integer and float compare on the integral value. Other mixtures are always unequal.
  853. Two lists are equal if they
  854. have the same number of members and a pairwise comparison of the members results
  855. in equality.
  856. .DS
  857. AND-expression:
  858. equality-expression
  859. AND-expression \f(CW&\fP equality-expression
  860. XOR-expression:
  861. AND-expression
  862. XOR-expression \f(CW^\fP AND-expression
  863. OR-expression:
  864. XOR-expression
  865. OR-expression \f(CW|\fP XOR-expression
  866. .DE
  867. These operators perform bitwise logical operations and apply only to the
  868. .I integer
  869. type.
  870. The operators are
  871. .CW &
  872. (logical and),
  873. .CW ^
  874. (exclusive or) and
  875. .CW |
  876. (inclusive or).
  877. .DS
  878. logical-AND-expression:
  879. OR-expression
  880. logical-AND-expression \f(CW&&\fP OR-expression
  881. logical-OR-expression:
  882. logical-AND-expression
  883. logical-OR-expression \f(CW||\fP logical-AND-expression
  884. .DE
  885. The
  886. .CW &&
  887. operator returns 1 if both of its operands evaluate to boolean true, otherwise 0.
  888. The
  889. .CW ||
  890. operator returns 1 if either of its operands evaluates to boolean true,
  891. otherwise 0.
  892. .SH
  893. Statements
  894. .PP
  895. .DS
  896. \f(CWif\fP expression \f(CWthen\fP statement \f(CWelse\fP statement
  897. \f(CWif\fP expression \f(CWthen\fP statement
  898. .DE
  899. The
  900. .I expression
  901. is evaluated as a boolean. If its value is true the statement after
  902. the
  903. .CW then
  904. is executed, otherwise the statement after the
  905. .CW else
  906. is executed. The
  907. .CW else
  908. portion may be omitted.
  909. .DS
  910. \f(CWwhile\fP expression \f(CWdo\fP statement
  911. .DE
  912. In a while loop, the
  913. .I statement
  914. is executed while the boolean
  915. .I expression
  916. evaluates
  917. true.
  918. .DS
  919. \f(CWloop\fP startexpr, endexpr \f(CWdo\fP statement
  920. .DE
  921. The two expressions
  922. .I startexpr
  923. and
  924. .I endexpr
  925. are evaluated prior to loop entry.
  926. .I Statement
  927. is evaluated while the value of
  928. .I startexpr
  929. is less than or equal to
  930. .I endexpr .
  931. Both expressions must yield
  932. .I integer
  933. values. The value of
  934. .I startexpr
  935. is
  936. incremented by one for each loop iteration.
  937. Note that there is no explicit loop variable; the
  938. .I expressions
  939. are just values.
  940. .DS
  941. \f(CWreturn\fP expression
  942. .DE
  943. .CW return
  944. terminates execution of the current function and returns to its caller.
  945. The value of the function is given by expression. Since
  946. .CW return
  947. requires an argument, nil-valued functions should return the empty list
  948. .CW {} .
  949. .DS
  950. \f(CWlocal\fP variable
  951. .DE
  952. The
  953. .CW local
  954. statement creates a local instance of
  955. .I variable ,
  956. which exists for the duration
  957. of the instance of the function in which it is declared. Binding is dynamic: the local variable,
  958. rather than the previous value of
  959. .I variable ,
  960. is visible to called functions.
  961. After a return from the current function the previous value of
  962. .I variable
  963. is
  964. restored.
  965. .PP
  966. If Acid is interrupted, the values of all local variables are lost,
  967. as if the function returned.
  968. .DS
  969. \f(CWdefn\fP function-name \f(CW(\fP parameter-list \f(CW)\fP body
  970. parameter-list:
  971. variable
  972. parameter-list , variable
  973. body:
  974. \f(CW{\fP statement \f(CW}\fP
  975. .DE
  976. Functions are introduced by the
  977. .CW defn
  978. statement. The definition of parameter names suppresses any variables
  979. of the same name until the function returns. The body of a function is a list
  980. of statements enclosed by braces.
  981. .SH
  982. Code variables
  983. .PP
  984. Acid permits the delayed evaluation of a parameter to a function. The parameter
  985. may then be evaluated at any time with the
  986. .CW eval
  987. operator. Such parameters are called
  988. .I "code variables
  989. and are defined by prefixing their name with an asterisk in their declaration.
  990. .PP
  991. For example, this function wraps up an expression for later evaluation:
  992. .P1
  993. acid: defn code(*e) { return e; }
  994. acid: x = code(v+atoi("100")\eD)
  995. acid: print(x)
  996. (v+atoi("100"))\eD;
  997. acid: eval x
  998. <stdin>:5: (error) v used but not set
  999. acid: v=5
  1000. acid: eval x
  1001. 105
  1002. .P2
  1003. .SH
  1004. Source Code Management
  1005. .PP
  1006. Acid provides the means to examine source code. Source code is
  1007. represented by lists of strings. Builtin functions provide mapping
  1008. from address to lines and vice-versa. The default debugging environment
  1009. has the means to load and display source files.
  1010. .SH
  1011. Builtin Functions
  1012. .PP
  1013. The Acid interpreter has a number of builtin functions, which cannot be redefined.
  1014. These functions perform machine- or operating system-specific functions such as
  1015. symbol table and process management.
  1016. The following section presents a description of each builtin function.
  1017. The notation
  1018. .CW {}
  1019. is used to denote the empty list, which is the default value of a function that
  1020. does not execute a
  1021. .CW return
  1022. statement.
  1023. The type and number of parameters for each function are specified in the
  1024. description; where a parameter can be of any type it is specified as type
  1025. .I item .
  1026. .de Ip
  1027. .KS
  1028. .LP
  1029. .tl '\f2\\$1\fP\ \ \f(CW\\$2(\f2\\$3\f(CW)\f1''\\$4'
  1030. .IP
  1031. ..
  1032. .de Ex
  1033. .KE
  1034. .KS
  1035. .IP
  1036. .ft CW
  1037. .ta 4n +4n +4n +4n +4n +4n +4n +4n +4n +4n +4n +4n +4n +4n +4n +4n
  1038. .nf
  1039. .in +4n
  1040. .br
  1041. ..
  1042. .de Ee
  1043. .fi
  1044. .ft 1
  1045. .br
  1046. .KE
  1047. ..
  1048. .\"
  1049. .\"
  1050. .\"
  1051. .Ip integer access string "Check if a file can be read
  1052. .CW Access
  1053. returns the integer 1 if the file name in
  1054. .I string
  1055. can be read by the builtin functions
  1056. .CW file ,
  1057. .CW readfile ,
  1058. or
  1059. .CW include ,
  1060. otherwise 0. A typical use of this function is to follow
  1061. a search path looking for a source file; it is used by
  1062. .CW findsrc .
  1063. .Ex
  1064. if access("main.c") then
  1065. return file("main.c");
  1066. .Ee
  1067. .\"
  1068. .\"
  1069. .\"
  1070. .Ip float atof string "Convert a string to float
  1071. .CW atof
  1072. converts the string supplied as its argument into a floating point
  1073. number. The function accepts strings in the same format as the C
  1074. function of the same name. The value returned has the format code
  1075. .CW f .
  1076. .CW atof
  1077. returns the value 0.0 if it is unable to perform the conversion.
  1078. .Ex
  1079. acid: +atof("10.4e6")
  1080. 1.04e+07
  1081. .Ee
  1082. .\"
  1083. .\"
  1084. .\"
  1085. .Ip integer atoi string "Convert a string to an integer
  1086. .CW atoi
  1087. converts the argument
  1088. .i string
  1089. to an integer value.
  1090. The function accepts strings in the same format as the C function of the
  1091. same name. The value returned has the format code
  1092. .CW D .
  1093. .CW atoi
  1094. returns the integer 0 if it is unable to perform a conversion.
  1095. .Ex
  1096. acid: +atoi("-1255")
  1097. -1255
  1098. .Ee
  1099. .\"
  1100. .\"
  1101. .\"
  1102. .Ip \f(CW{}\fP error string "Generate an interpreter error
  1103. .CW error
  1104. generates an error message and returns the interpreter to interactive
  1105. mode. If an Acid program is running, it is aborted.
  1106. Processes being debugged are not affected. The values of all local variables are lost.
  1107. .CW error
  1108. is commonly used to stop the debugger when some interesting condition arises
  1109. in the debugged program.
  1110. .Ex
  1111. while 1 do {
  1112. step();
  1113. if *main != @main then
  1114. error("memory corrupted");
  1115. }
  1116. .Ee
  1117. .\"
  1118. .\"
  1119. .\"
  1120. .Ip list file string "Read the contents of a file into a list
  1121. .CW file
  1122. reads the contents of the file specified by
  1123. .I string
  1124. into a list.
  1125. Each element in the list is a string corresponding to a line in the file.
  1126. .CW file
  1127. breaks lines at the newline character, but the newline
  1128. characters are not returned as part each string.
  1129. .CW file
  1130. returns the empty list if it encounters an error opening or reading the data.
  1131. .Ex
  1132. acid: print(file("main.c")[0])
  1133. #include <u.h>
  1134. .Ee
  1135. .\"
  1136. .\"
  1137. .\"
  1138. .Ip integer filepc string "Convert source address to text address
  1139. .CW filepc
  1140. interprets its
  1141. .I string
  1142. argument as a source file address in the form of a file name and line offset.
  1143. .CW filepc
  1144. uses the symbol table to map the source address into a text address
  1145. in the debugged program. The
  1146. .I integer
  1147. return value has the format
  1148. .CW X .
  1149. .CW filepc
  1150. returns an address of -1 if the source address is invalid.
  1151. The source file address uses the same format as
  1152. .I acme (1).
  1153. This function is commonly used to set breakpoints from the source text.
  1154. .Ex
  1155. acid: bpset(filepc("main:10"))
  1156. acid: bptab()
  1157. 0x00001020 usage ADD $-0xc,R29
  1158. .Ee
  1159. .\"
  1160. .\"
  1161. .\"
  1162. .Ip item fmt item,fmt "Set print, \f(CW@\fP and \f(CW*\fP formats
  1163. .CW fmt
  1164. evaluates the expression
  1165. .I item
  1166. and sets the format of the result to
  1167. .I fmt .
  1168. The format of a value determines how it will be printed and
  1169. what kind of object will be fetched by the
  1170. .CW *
  1171. and
  1172. .CW @
  1173. operators. The
  1174. .CW \e
  1175. operator is a short-hand form of the
  1176. .CW fmt
  1177. builtin function. The
  1178. .CW fmt
  1179. function leaves the format of the
  1180. .I item
  1181. unchanged.
  1182. .Ex
  1183. acid: main=fmt(main, 'i') // as instructions
  1184. acid: print(main\eX, "\et", *main)
  1185. 0x00001020 ADD $-64,R29
  1186. .Ee
  1187. .\"
  1188. .\"
  1189. .\"
  1190. .Ip list fnbound integer "Find start and end address of a function
  1191. .CW fnbound
  1192. interprets its
  1193. .I integer
  1194. argument as an address in the text of the debugged program.
  1195. .CW fnbound
  1196. returns a list containing two integers corresponding to
  1197. the start and end addresses of the function containing the supplied address.
  1198. If the
  1199. .I integer
  1200. address is not in the text segment of the program then the empty list is returned.
  1201. .CW fnbound
  1202. is used by
  1203. .CW next
  1204. to detect stepping into new functions.
  1205. .Ex
  1206. acid: print(fnbound(main))
  1207. {0x00001050, 0x000014b8}
  1208. .Ee
  1209. .\"
  1210. .\"
  1211. .\"
  1212. .Ip \f(CW{}\fP follow integer "Compute follow set
  1213. The follow set is defined as the set of program counter values that could result
  1214. from executing an instruction.
  1215. .CW follow
  1216. interprets its
  1217. .I integer
  1218. argument as a text address, decodes the instruction at
  1219. that address and, with the current register set, builds a list of possible
  1220. next program counter values. If the instruction at the specified address
  1221. cannot be decoded
  1222. .CW follow
  1223. raises an error.
  1224. .CW follow
  1225. is used to plant breakpoints on
  1226. all potential paths of execution. The following code fragment
  1227. plants breakpoints on top of all potential following instructions.
  1228. .Ex
  1229. lst = follow(*PC);
  1230. while lst do
  1231. {
  1232. *head lst = bpinst;
  1233. lst = tail lst;
  1234. }
  1235. .Ee
  1236. .\"
  1237. .\"
  1238. .\"
  1239. .Ip \f(CW{}\fP include string "Take input from a new file
  1240. .CW include
  1241. opens the file specified by
  1242. .I string
  1243. and uses its contents as command input to the interpreter.
  1244. The interpreter restores input to its previous source when it encounters
  1245. either an end of file or an error.
  1246. .CW include
  1247. can be used to incrementally load symbol table information without
  1248. leaving the interpreter.
  1249. .Ex
  1250. acid: include("/sys/src/cmd/acme/syms")
  1251. .Ee
  1252. .\"
  1253. .\"
  1254. .\"
  1255. .Ip \f(CW{}\fP interpret string "Take input from a string
  1256. .CW interpret
  1257. evaluates the
  1258. .I string
  1259. expression and uses its result as command input for the interpreter.
  1260. The interpreter restores input to its previous source when it encounters
  1261. either the end of string or an error. The
  1262. .CW interpret
  1263. function allows Acid programs to write Acid code for later evaluation.
  1264. .Ex
  1265. acid: interpret("main+10;")
  1266. 0x0000102a
  1267. .Ee
  1268. .\"
  1269. .\"
  1270. .\"
  1271. .Ip string itoa integer[,string] "Convert integer to string
  1272. .CW itoa
  1273. takes an integer argument and converts it into an ASCII string
  1274. in the
  1275. .CW D
  1276. format.
  1277. an alternate format string
  1278. may be provided in the
  1279. .CW %
  1280. style of
  1281. .I print (2).
  1282. This function is commonly used to build
  1283. .CW rc
  1284. command lines.
  1285. .Ex
  1286. acid: rc("cat /proc/"+itoa(pid)+"/segment")
  1287. Stack 7fc00000 80000000 1
  1288. Data 00001000 00009000 1
  1289. Data 00009000 0000a000 1
  1290. Bss 0000a000 0000c000 1
  1291. .Ee
  1292. .\"
  1293. .\"
  1294. .\"
  1295. .Ip \f(CW{}\fP kill integer "Kill a process
  1296. .CW kill
  1297. writes a kill control message into the control file of the process
  1298. specified by the
  1299. .I integer
  1300. pid.
  1301. If the process was previously installed by
  1302. .CW setproc
  1303. it will be removed from the list of active processes.
  1304. If the
  1305. .I integer
  1306. has the same value as
  1307. .CW pid ,
  1308. then
  1309. .CW pid
  1310. will be set to 0.
  1311. To continue debugging, a new process must be selected using
  1312. .CW setproc .
  1313. For example, to kill all the active processes:
  1314. .Ex
  1315. while proclist do {
  1316. kill(head proclist);
  1317. proclist = tail proclist;
  1318. }
  1319. .Ee
  1320. .\"
  1321. .\"
  1322. .\"
  1323. .Ip list map list "Set or retrieve process memory map
  1324. .CW map
  1325. either retrieves all the mappings associated with a process or sets a single
  1326. map entry to a new value.
  1327. If the
  1328. .I list
  1329. argument is omitted then
  1330. .CW map
  1331. returns a list of lists. Each sublist has four values and describes a
  1332. single region of contiguous addresses in the
  1333. memory or file image of the debugged program. The first entry is the name of the
  1334. mapping. If the name begins with
  1335. .CW *
  1336. it denotes a map into the memory of an active process.
  1337. The second and third values specify the base and end
  1338. address of the region and the fourth number specifies the offset in the file
  1339. corresponding to the first location of the region.
  1340. A map entry may be set by supplying a list in the same format as the sublist
  1341. described above. The name of the mapping must match a region already defined
  1342. by the current map.
  1343. Maps are set automatically for Plan 9 processes and some kernels; they may
  1344. need to be set by hand for other kernels and programs that run on bare hardware.
  1345. .Ex
  1346. acid: map({"text", _start, end, 0x30})
  1347. .Ee
  1348. .\"
  1349. .\"
  1350. .\"
  1351. .Ip integer match item,list "Search list for matching value
  1352. .CW match
  1353. compares each item in
  1354. .I list
  1355. using the equality operator
  1356. .CW ==
  1357. with
  1358. .I item .
  1359. The
  1360. .I item
  1361. can be of any type. If the match succeeds the result is the integer index
  1362. of the matching value, otherwise -1.
  1363. .Ex
  1364. acid: list={8,9,10,11}
  1365. acid: print(list[match(10, list)]\eD)
  1366. 10
  1367. .Ee
  1368. .\"
  1369. .\"
  1370. .\"
  1371. .Ip \f(CW{}\fP newproc string "Create a new process
  1372. .CW newproc
  1373. starts a new process with an argument vector constructed from
  1374. .I string .
  1375. The argument vector excludes the name of the program to execute and
  1376. each argument in
  1377. .I string
  1378. must be space separated. A new process can accept no more
  1379. than 512 arguments. The internal variable
  1380. .CW pid
  1381. is set to the pid of the newly created process. The new pid
  1382. is also appended to the list of active processes stored in the variable
  1383. .CW proclist .
  1384. The new process is created then halted at the first instruction, causing
  1385. the debugger to call
  1386. .CW stopped .
  1387. The library functions
  1388. .CW new
  1389. and
  1390. .CW win
  1391. should be used to start processes when using the standard debugging
  1392. environment.
  1393. .Ex
  1394. acid: newproc("-l .")
  1395. 56720: system call _main ADD $-0x14,R29
  1396. .Ee
  1397. .\"
  1398. .\"
  1399. .\"
  1400. .Ip string pcfile integer "Convert text address to source file name
  1401. .CW pcfile
  1402. interprets its
  1403. .I integer
  1404. argument as a text address in the debugged program. The address and symbol table
  1405. are used to generate a string containing the name of the source file
  1406. corresponding to the text address. If the address does not lie within the
  1407. program the string
  1408. .CW ?file?
  1409. is returned.
  1410. .Ex
  1411. acid: print("Now at ", pcfile(*PC), ":", pcline(*PC))
  1412. Now at ls.c:46
  1413. .Ee
  1414. .\"
  1415. .\"
  1416. .\"
  1417. .Ip integer pcline integer "Convert text address to source line number
  1418. .CW pcline
  1419. interprets its
  1420. .I integer
  1421. argument as a text address in the debugged program. The address and symbol table
  1422. are used to generate an integer containing the line number in the source file
  1423. corresponding to the text address. If the address does not lie within the
  1424. program the integer 0 is returned.
  1425. .Ex
  1426. acid: +file("main.c")[pcline(main)]
  1427. main(int argc, char *argv[])
  1428. .Ee
  1429. .\"
  1430. .\"
  1431. .\"
  1432. .Ip \f(CW{}\fP print item,item,... "Print expressions
  1433. .CW print
  1434. evaluates each
  1435. .I item
  1436. supplied in its argument list and prints it to standard output. Each
  1437. argument will be printed according to its associated format character.
  1438. When the interpreter is executing, output is buffered and flushed every
  1439. 5000 statements or when the interpreter returns to interactive mode.
  1440. .CW print
  1441. accepts a maximum of 512 arguments.
  1442. .Ex
  1443. acid: print(10, "decimal ", 10\eD, "octal ", 10\eo)
  1444. 0x0000000a decimal 10 octal 000000000012
  1445. acid: print({1, 2, 3})
  1446. {0x00000001 , 0x00000002 , 0x00000003 }
  1447. acid: print(main, main\ea, "\et", @main\ei)
  1448. 0x00001020 main ADD $-64,R29
  1449. .Ee
  1450. .\"
  1451. .\"
  1452. .\"
  1453. .Ip \f(CW{}\fP printto string,item,item,... "Print expressions to file
  1454. .CW printto
  1455. offers a limited form of output redirection. The first
  1456. .I string
  1457. argument is used as the path name of a new file to create.
  1458. Each
  1459. .I item
  1460. is then evaluated and printed to the newly created file. When all items
  1461. have been printed the file is closed.
  1462. .CW printto
  1463. accepts a maximum of 512 arguments.
  1464. .Ex
  1465. acid: printto("/env/foo", "hello")
  1466. acid: rc("echo -n $foo")
  1467. hello
  1468. .Ee
  1469. .\"
  1470. .\"
  1471. .\"
  1472. .Ip string rc string "Execute a shell command
  1473. .CW rc
  1474. evaluates
  1475. .I string
  1476. to form a shell command. A new command interpreter is started
  1477. to execute the command. The Acid interpreter blocks until the command
  1478. completes. The return value is the empty string
  1479. if the command succeeds, otherwise the exit status of the failed command.
  1480. .Ex
  1481. acid: rc("B "+itoa(-pcline(addr))+" "+pcfile(addr));
  1482. .Ee
  1483. .\"
  1484. .\"
  1485. .\"
  1486. .Ip string readfile string "Read file contents into a string
  1487. .CW readfile
  1488. takes the contents of the file specified by
  1489. .I string
  1490. and returns its contents as a new string.
  1491. If
  1492. .CW readfile
  1493. encounters a zero byte in the file, it terminates.
  1494. If
  1495. .CW readfile
  1496. encounters an error opening or reading the file then the empty list
  1497. is returned.
  1498. .CW readfile
  1499. can be used to read the contents of device files whose lines are not
  1500. terminated with newline characters.
  1501. .Ex
  1502. acid: ""+readfile("/dev/label")
  1503. helix
  1504. .Ee
  1505. .\"
  1506. .\"
  1507. .\"
  1508. .Ip string reason integer "Print cause of program stoppage
  1509. .CW reason
  1510. uses machine-dependent information to generate a string explaining
  1511. why a process has stopped. The
  1512. .I integer
  1513. argument is the value of an architecture dependent status register,
  1514. for example
  1515. .CW CAUSE
  1516. on the MIPS.
  1517. .Ex
  1518. acid: print(reason(*CAUSE))
  1519. system call
  1520. .Ee
  1521. .\"
  1522. .\"
  1523. .\"
  1524. .Ip integer regexp pattern,string "Regular expression match
  1525. .CW regexp
  1526. matches the
  1527. .I pattern
  1528. string supplied as its first argument with the
  1529. .I string
  1530. supplied as its second.
  1531. If the pattern matches the result is the value 1, otherwise 0.
  1532. .Ex
  1533. acid: print(regexp(".*bar", "foobar"))
  1534. 1
  1535. .Ee
  1536. .\"
  1537. .\"
  1538. .\"
  1539. .Ip \f(CW{}\fP setproc integer "Set debugger focus
  1540. .CW setproc
  1541. selects the default process used for memory and control operations. It effectively
  1542. shifts the focus of control between processes. The
  1543. .I integer
  1544. argument specifies the pid of the process to look at.
  1545. The variable
  1546. .CW pid
  1547. is set to the pid of the selected process. If the process is being
  1548. selected for the first time its pid is added to the list of active
  1549. processes
  1550. .CW proclist .
  1551. .Ex
  1552. acid: setproc(68382)
  1553. acid: procs()
  1554. >68382: Stopped at main+0x4 setproc(68382)
  1555. .Ee
  1556. .\"
  1557. .\"
  1558. .\"
  1559. .Ip \f(CW{}\fP start integer "Restart execution
  1560. .CW start
  1561. writes a
  1562. .CW start
  1563. message to the control file of the process specified by the pid
  1564. supplied as its
  1565. .I integer
  1566. argument.
  1567. .CW start
  1568. draws an error if the process is not in the
  1569. .CW Stopped
  1570. state.
  1571. .Ex
  1572. acid: start(68382)
  1573. acid: procs()
  1574. >68382: Running at main+0x4 setproc(68382)
  1575. .Ee
  1576. .\"
  1577. .\"
  1578. .\"
  1579. .Ip \f(CW{}\fP startstop integer "Restart execution, block until stopped
  1580. .CW startstop
  1581. performs the same actions as a call to
  1582. .CW start
  1583. followed by a call to
  1584. .CW stop .
  1585. The
  1586. .I integer
  1587. argument specifies the pid of the process to control. The process
  1588. must be in the
  1589. .CW Stopped
  1590. state.
  1591. Execution is restarted, the debugger then waits for the process to
  1592. return to the
  1593. .CW Stopped
  1594. state. A process will stop if a startstop message has been written to its control
  1595. file and any of the following conditions becomes true: the process executes or returns from
  1596. a system call, the process generates a trap or the process receives a note.
  1597. .CW startstop
  1598. is used to implement single stepping.
  1599. .Ex
  1600. acid: startstop(pid)
  1601. 75374: breakpoint ls ADD $-0x16c8,R29
  1602. .Ee
  1603. .\"
  1604. .\"
  1605. .\"
  1606. .Ip string status integer "Return process state
  1607. .CW status
  1608. uses the pid supplied by its
  1609. .I integer
  1610. argument to generate a string describing the state of the process.
  1611. The string corresponds to the state returned by the
  1612. sixth column of the
  1613. .I ps (1)
  1614. command.
  1615. A process must be in the
  1616. .CW Stopped
  1617. state to modify its memory or registers.
  1618. .Ex
  1619. acid: ""+status(pid)
  1620. Stopped
  1621. .Ee
  1622. .\"
  1623. .\"
  1624. .\"
  1625. .Ip \f(CW{}\fP stop integer "Wait for a process to stop
  1626. .CW stop
  1627. writes a
  1628. .CW stop
  1629. message to the control file of the process specified by the
  1630. pid supplied as its
  1631. .I integer
  1632. argument.
  1633. The interpreter blocks until the debugged process enters the
  1634. .CW Stopped
  1635. state.
  1636. A process will stop if a stop message has been written to its control
  1637. file and any of the following conditions becomes true: the process executes or returns from
  1638. a system call, the process generates a trap, the process is scheduled or the
  1639. process receives a note.
  1640. .CW stop
  1641. is used to wait for a process to halt before planting a breakpoint since Plan 9
  1642. only allows a process's memory to be written while it is in the
  1643. .CW Stopped
  1644. state.
  1645. .Ex
  1646. defn bpset(addr) {
  1647. if (status(pid)!="Stopped") then {
  1648. print("Waiting...\en");
  1649. stop(pid);
  1650. }
  1651. ...
  1652. }
  1653. .Ee
  1654. .\"
  1655. .\"
  1656. .\"
  1657. .Ip list strace pc,sp,linkreg "Stack trace
  1658. .CW strace
  1659. generates a list of lists corresponding to procedures called by the debugged
  1660. program. Each sublist describes a single stack frame in the active process.
  1661. The first element is an
  1662. .I integer
  1663. of format
  1664. .CW X
  1665. specifying the address of the called function. The second element is the value
  1666. of the program counter when the function was called. The third and fourth elements
  1667. contain lists of parameter and automatic variables respectively.
  1668. Each element of these lists
  1669. contains a string with the name of the variable and an
  1670. .I integer
  1671. value of format
  1672. .CW X
  1673. containing the current value of the variable.
  1674. The arguments to
  1675. .CW strace
  1676. are the current value of the program counter, the current value of the
  1677. stack pointer, and the address of the link register. All three parameters
  1678. must be integers.
  1679. The setting of
  1680. .I linkreg
  1681. is architecture dependent. On the MIPS linkreg is set to the address of saved
  1682. .CW R31 ,
  1683. on the SPARC to the address of saved
  1684. .CW R15 .
  1685. For the other architectures
  1686. .I linkreg
  1687. is not used, but must point to valid memory.
  1688. .Ex
  1689. acid: print(strace(*PC, *SP, linkreg))
  1690. {{0x0000141c, 0xc0000f74,
  1691. {{"s", 0x0000004d}, {"multi", 0x00000000}},
  1692. {{"db", 0x00000000}, {"fd", 0x000010a4},
  1693. {"n", 0x00000001}, {"i", 0x00009824}}}}
  1694. .Ee
  1695. .\"
  1696. .\"
  1697. .\"
  1698. .Ip \f(CW{}\fP waitstop integer "Wait for a process to stop
  1699. .CW waitstop
  1700. writes a waitstop message to the control file of the process specified by the
  1701. pid supplied as its
  1702. .I integer
  1703. argument.
  1704. The interpreter will remain blocked until the debugged process enters the
  1705. .CW Stopped
  1706. state.
  1707. A process will stop if a waitstop message has been written to its control
  1708. file and any of the following conditions becomes true: the process generates a trap
  1709. or receives a note. Unlike
  1710. .CW stop ,
  1711. the
  1712. .CW waitstop
  1713. function is passive; it does not itself cause the program to stop.
  1714. .Ex
  1715. acid: waitstop(pid)
  1716. 75374: breakpoint ls ADD $-0x16c8,R29
  1717. .Ee
  1718. .\"
  1719. .\"
  1720. .\"
  1721. .SH
  1722. Library Functions
  1723. .PP
  1724. A standard debugging environment is provided by modules automatically
  1725. loaded when
  1726. Acid is started.
  1727. These modules are located in the directory
  1728. .CW /sys/lib/acid .
  1729. These functions may be overridden, personalized, or added to by code defined in
  1730. .CW $home/lib/acid .
  1731. The implementation of these functions can be examined using the
  1732. .CW whatis
  1733. operator and then modified during debugging sessions.
  1734. .\"
  1735. .\"
  1736. .\"
  1737. .Ip \f(CW{}\fP Bsrc integer "Load editor with source
  1738. .CW Bsrc
  1739. interprets the
  1740. .I integer
  1741. argument as a text address. The text address is used to produce a pathname
  1742. and line number suitable for the
  1743. .CW B
  1744. command
  1745. to send to the text editor
  1746. .I sam (1)
  1747. or
  1748. .I acme (1).
  1749. .CW Bsrc
  1750. builds an
  1751. .I rc (1)
  1752. command to invoke
  1753. .CW B ,
  1754. which either selects an existing source file or loads a new source file into the editor.
  1755. The line of source corresponding to the text address is then selected.
  1756. In the following example
  1757. .CW stopped
  1758. is redefined so that the editor
  1759. follows and displays the source line currently being executed.
  1760. .Ex
  1761. defn stopped(pid) {
  1762. pstop(pid);
  1763. Bsrc(*PC);
  1764. }
  1765. .Ee
  1766. .\"
  1767. .\"
  1768. .\"
  1769. .Ip \f(CW{}\fP Fpr "" "Display double precision floating registers
  1770. For machines equipped with floating point,
  1771. .CW Fpr
  1772. displays the contents of the floating point registers as double precision
  1773. values.
  1774. .Ex
  1775. acid: Fpr()
  1776. F0 0. F2 0.
  1777. F4 0. F6 0.
  1778. F8 0. F10 0.
  1779. \&...
  1780. .Ee
  1781. .\"
  1782. .\"
  1783. .\"
  1784. .Ip \f(CW{}\fP Ureg integer "Display contents of Ureg structure
  1785. .CW Ureg
  1786. interprets the integer passed as its first argument as the address of a
  1787. kernel
  1788. .CW Ureg
  1789. structure. Each element of the structure is retrieved and printed.
  1790. The size and contents of the
  1791. .CW Ureg
  1792. structure are architecture dependent.
  1793. This function can be used to decode the first argument passed to a
  1794. .I notify (2)
  1795. function after a process has received a note.
  1796. .Ex
  1797. acid: Ureg(*notehandler:ur)
  1798. status 0x3000f000
  1799. pc 0x1020
  1800. sp 0x7ffffe00
  1801. cause 0x00004002
  1802. \&...
  1803. .Ee
  1804. .\"
  1805. .\"
  1806. .\"
  1807. .Ip \f(CW{}\fP acidinit "" "Interpreter startup
  1808. .CW acidinit
  1809. is called by the interpreter after all
  1810. modules have been loaded at initialization time.
  1811. It is used to set up machine specific variables and the default source path.
  1812. .CW acidinit
  1813. should not be called by user code.
  1814. .KE
  1815. .\"
  1816. .\"
  1817. .\"
  1818. .Ip \f(CW{}\fP addsrcdir string "Add element to source search path
  1819. .CW addsrcdir
  1820. interprets its string argument as a new directory
  1821. .CW findsrc
  1822. should search when looking for source code files.
  1823. .CW addsrcdir
  1824. draws an error if the directory is already in the source search path. The search
  1825. path may be examined by looking at the variable
  1826. .CW srcpath .
  1827. .Ex
  1828. acid: rc("9fs fornax")
  1829. acid: addsrcpath("/n/fornax/sys/src/cmd")
  1830. .Ee
  1831. .\"
  1832. .\"
  1833. .\"
  1834. .Ip \f(CW{}\fP asm integer "Disassemble machine instructions
  1835. .CW asm
  1836. interprets its integer argument as a text address from which to disassemble
  1837. machine instructions.
  1838. .CW asm
  1839. prints the instruction address in symbolic and hexadecimal form, then prints
  1840. the instructions with addressing modes. Up to twenty instructions will
  1841. be disassembled.
  1842. .CW asm
  1843. stops disassembling when it reaches the end of the current function.
  1844. Instructions are read from the file image using the
  1845. .CW @
  1846. operator.
  1847. .Ex
  1848. acid: asm(main)
  1849. main 0x00001020 ADD $-0x64,R29
  1850. main+0x4 0x00001024 MOVW R31,0x0(R29)
  1851. main+0x8 0x00001028 MOVW R1,argc+4(FP)
  1852. main+0xc 0x0000102c MOVW $bin(SB),R1
  1853. .Ee
  1854. .\"
  1855. .\"
  1856. .\"
  1857. .Ip \f(CW{}\fP bpdel integer "Delete breakpoint
  1858. .CW bpdel
  1859. removes a previously set breakpoint from memory.
  1860. The
  1861. .I integer
  1862. supplied as its argument must be the address of a previously set breakpoint.
  1863. The breakpoint address is deleted from the active breakpoint list
  1864. .CW bplist ,
  1865. then the original instruction is copied from the file image to the memory
  1866. image so that the breakpoint is removed.
  1867. .Ex
  1868. acid: bpdel(main+4)
  1869. .Ee
  1870. .\"
  1871. .\"
  1872. .\"
  1873. .Ip \f(CW{}\fP bpset integer "Set a breakpoint
  1874. .CW bpset
  1875. places a breakpoint instruction at the address specified
  1876. by its
  1877. .I integer
  1878. argument, which must be in the text segment.
  1879. .CW bpset
  1880. draws an error if a breakpoint has already been set at the specified address.
  1881. A list of current breakpoints is maintained in the variable
  1882. .CW bplist .
  1883. Unlike in
  1884. .I db (1),
  1885. breakpoints are left in memory even when a process is stopped, and
  1886. the process must exist, perhaps by being
  1887. created by either
  1888. .CW new
  1889. or
  1890. .CW win ,
  1891. in order to place a breakpoint.
  1892. .CW Db "" (
  1893. accepts breakpoint commands before the process is started.)
  1894. On the
  1895. MIPS and SPARC architectures,
  1896. breakpoints at function entry points should be set 4 bytes into the function
  1897. because the
  1898. instruction scheduler may fill
  1899. .CW JAL
  1900. branch delay slots with the first instruction of the function.
  1901. .Ex
  1902. acid: bpset(main+4)
  1903. .Ee
  1904. .\"
  1905. .\"
  1906. .\"
  1907. .Ip \f(CW{}\fP bptab "" "List active breakpoints
  1908. .CW bptab
  1909. prints a list of currently installed breakpoints. The list contains the
  1910. breakpoint address in symbolic and hexadecimal form as well as the instruction
  1911. the breakpoint replaced. Breakpoints are not maintained across process creation
  1912. using
  1913. .CW new
  1914. and
  1915. .CW win .
  1916. They are maintained across a fork, but care must be taken to keep control of
  1917. the child process.
  1918. .Ex
  1919. acid: bpset(ls+4)
  1920. acid: bptab()
  1921. 0x00001420 ls+0x4 MOVW R31,0x0(R29)
  1922. .Ee
  1923. .\"
  1924. .\"
  1925. .\"
  1926. .Ip \f(CW{}\fP casm "" "Continue disassembly
  1927. .CW casm
  1928. continues to disassemble instructions from where the last
  1929. .CW asm
  1930. or
  1931. .CW casm
  1932. command stopped. Like
  1933. .CW asm ,
  1934. this command stops disassembling at function boundaries.
  1935. .Ex
  1936. acid: casm()
  1937. main+0x10 0x00001030 MOVW $0x1,R3
  1938. main+0x14 0x00001034 MOVW R3,0x8(R29)
  1939. main+0x18 0x00001038 MOVW $0x1,R5
  1940. main+0x1c 0x0000103c JAL Binit(SB)
  1941. .Ee
  1942. .\"
  1943. .\"
  1944. .\"
  1945. .Ip \f(CW{}\fP cont "" "Continue program execution
  1946. .CW cont
  1947. restarts execution of the currently active process.
  1948. If the process is stopped on a breakpoint, the breakpoint is first removed,
  1949. the program is single stepped, the breakpoint is replaced and the program
  1950. is then set executing. This may cause
  1951. .CW stopped()
  1952. to be called twice.
  1953. .CW cont
  1954. causes the interpreter to block until the process enters the
  1955. .CW Stopped
  1956. state.
  1957. .Ex
  1958. acid: cont()
  1959. 95197: breakpoint ls+0x4 MOVW R31,0x0(R29)
  1960. .Ee
  1961. .\"
  1962. .\"
  1963. .\"
  1964. .Ip \f(CW{}\fP dump integer,integer,string "Formatted memory dump
  1965. .CW dump
  1966. interprets its first argument as an address, its second argument as a
  1967. count and its third as a format string.
  1968. .CW dump
  1969. fetches an object from memory at the current address and prints it according
  1970. to the format. The address is incremented by the number of bytes specified by
  1971. the format and the process is repeated count times. The format string is any
  1972. combination of format characters, each preceded by an optional count.
  1973. For each object,
  1974. .CW dump
  1975. prints the address in hexadecimal, a colon, the object and then a newline.
  1976. .CW dump
  1977. uses
  1978. .CW mem
  1979. to fetch each object.
  1980. .Ex
  1981. acid: dump(main+35, 4, "X2bi")
  1982. 0x00001043: 0x0c8fa700 108 143 lwc2 r0,0x528f(R4)
  1983. 0x0000104d: 0xa9006811 0 0 swc3 r0,0x0(R24)
  1984. 0x00001057: 0x2724e800 4 37 ADD $-0x51,R23,R31
  1985. 0x00001061: 0xa200688d 6 0 NOOP
  1986. 0x0000106b: 0x2710c000 7 0 BREAK
  1987. .Ee
  1988. .\"
  1989. .\"
  1990. .\"
  1991. .Ip \f(CW{}\fP findsrc string "Use source path to load source file
  1992. .CW findsrc
  1993. interprets its
  1994. .I string
  1995. argument as a source file. Each directory in the source path is searched
  1996. in turn for the file. If the file is found, the source text is loaded using
  1997. .CW file
  1998. and stored in the list of active source files called
  1999. .CW srctext .
  2000. The name of the file is added to the source file name list
  2001. .CW srcfiles .
  2002. Users are unlikely to call
  2003. .CW findsrc
  2004. from the command line, but may use it from scripts to preload source files
  2005. for a debugging session. This function is used by
  2006. .CW src
  2007. and
  2008. .CW line
  2009. to locate and load source code. The default search path for the MIPS
  2010. is
  2011. .CW ./ ,
  2012. .CW /sys/src/libc/port ,
  2013. .CW /sys/src/libc/9sys ,
  2014. .CW /sys/src/libc/mips .
  2015. .Ex
  2016. acid: findsrc(pcfile(main));
  2017. .Ee
  2018. .\"
  2019. .\"
  2020. .\"
  2021. .Ip \f(CW{}\fP fpr "" "Display single precision floating registers
  2022. For machines equipped with floating point,
  2023. .CW fpr
  2024. displays the contents of the floating point registers as single precision
  2025. values. When the interpreter stores or manipulates floating point values
  2026. it converts into double precision values.
  2027. .Ex
  2028. acid: fpr()
  2029. F0 0. F1 0.
  2030. F2 0. F3 0.
  2031. F4 0. F5 0.
  2032. \&...
  2033. .Ee
  2034. .\"
  2035. .\"
  2036. .\"
  2037. .Ip \f(CW{}\fP func "" "Step while in function
  2038. .CW func
  2039. single steps the active process until it leaves the current function
  2040. by either calling another function or returning to its caller.
  2041. .CW func
  2042. will execute a single instruction after leaving the current function.
  2043. .Ex
  2044. acid: func()
  2045. 95197: breakpoint ls+0x8 MOVW R1,R8
  2046. 95197: breakpoint ls+0xc MOVW R8,R1
  2047. 95197: breakpoint ls+0x10 MOVW R8,s+4(FP)
  2048. 95197: breakpoint ls+0x14 MOVW $0x2f,R5
  2049. 95197: breakpoint ls+0x18 JAL utfrrune(SB)
  2050. 95197: breakpoint utfrrune ADD $-0x18,R29
  2051. .Ee
  2052. .\"
  2053. .\"
  2054. .\"
  2055. .Ip \f(CW{}\fP gpr "" "Display general purpose registers
  2056. .CW gpr
  2057. prints the values of the general purpose processor registers.
  2058. .Ex
  2059. acid: gpr()
  2060. R1 0x00009562 R2 0x000010a4 R3 0x00005d08
  2061. R4 0x0000000a R5 0x0000002f R6 0x00000008
  2062. \&...
  2063. .Ee
  2064. .\"
  2065. .\"
  2066. .\"
  2067. .Ip \f(CW{}\fP labstk integer "Print stack trace from label
  2068. .CW labstk
  2069. performs a stack trace from a Plan 9
  2070. .I label.
  2071. The kernel,
  2072. C compilers store continuations in a common format. Since the
  2073. compilers all use caller save conventions a continuation may be saved by
  2074. storing a
  2075. .CW PC
  2076. and
  2077. .CW SP
  2078. pair. This data structure is called a label and is used by the
  2079. the C function
  2080. .CW longjmp
  2081. and the kernel to schedule threads and processes.
  2082. .CW labstk
  2083. interprets its
  2084. .I integer
  2085. argument as the address of a label and produces a stack trace for
  2086. the thread of execution. The value of the function
  2087. .CW ALEF_tid
  2088. is a suitable argument for
  2089. .CW labstk .
  2090. .Ex
  2091. acid: labstk(*mousetid)
  2092. At pc:0x00021a70:Rendez_Sleep+0x178 rendez.l:44
  2093. Rendez_Sleep(r=0xcd7d8,bool=0xcd7e0,t=0x0) rendez.l:5
  2094. called from ALEF_rcvmem+0x198 recvmem.l:45
  2095. ALEF_rcvmem(c=0x000cd764,l=0x00000010) recvmem.l:6
  2096. \&...
  2097. .Ee
  2098. .\"
  2099. .\"
  2100. .\"
  2101. .Ip \f(CW{}\fP lstk "" "Stack trace with local variables
  2102. .CW lstk
  2103. produces a long format stack trace.
  2104. The stack trace includes each function in the stack,
  2105. where it was called from, and the value of the parameters and automatic
  2106. variables for each function.
  2107. .CW lstk
  2108. displays the value rather than the address of each variable and all
  2109. variables are assumed to be an integer in format
  2110. .CW X .
  2111. To print a variable in its correct format use the
  2112. .CW :
  2113. operator to find the address and apply the appropriate format before indirection
  2114. with the
  2115. .CW *
  2116. operator. It may be necessary to single step a couple of instructions into
  2117. a function to get a correct stack trace because the frame pointer adjustment
  2118. instruction may get scheduled down into the body of the function.
  2119. .Ex
  2120. acid: lstk()
  2121. At pc:0x00001024:main+0x4 ls.c:48
  2122. main(argc=0x00000001,argv=0x7fffefec) ls.c:48
  2123. called from _main+0x20 main9.s:10
  2124. _argc=0x00000000
  2125. _args=0x00000000
  2126. fd=0x00000000
  2127. buf=0x00000000
  2128. i=0x00000000
  2129. .Ee
  2130. .\"
  2131. .\"
  2132. .\"
  2133. .Ip \f(CW{}\fP mem integer,string "Print memory object
  2134. .CW mem
  2135. interprets its first
  2136. .I integer
  2137. argument as the address of an object to be printed according to the
  2138. format supplied in its second
  2139. .I string
  2140. argument.
  2141. The format string can be any combination of format characters, each preceded
  2142. by an optional count.
  2143. .Ex
  2144. acid: mem(bdata+0x326, "2c2Xb")
  2145. P = 0xa94bc464 0x3e5ae44d 19
  2146. .Ee
  2147. .\"
  2148. .\"
  2149. .\"
  2150. .Ip \f(CW{}\fP new "" "Create new process
  2151. .CW new
  2152. starts a new copy of the debugged program. The new program is started
  2153. with the program arguments set by the variable
  2154. .CW progargs .
  2155. The new program is stopped in the second instruction of
  2156. .CW main .
  2157. The breakpoint list is reinitialized.
  2158. .CW new
  2159. may be used several times to instantiate several copies of a program
  2160. simultaneously. The user can rotate between the copies using
  2161. .CW setproc .
  2162. .Ex
  2163. acid: progargs="-l"
  2164. acid: new()
  2165. 60: external interrupt _main ADD $-0x14,R29
  2166. 60: breakpoint main+0x4 MOVW R31,0x0(R29)
  2167. .Ee
  2168. .\"
  2169. .\"
  2170. .\"
  2171. .Ip \f(CW{}\fP next "" "Step through language statement
  2172. .CW next
  2173. steps through a single language level statement without tracing down
  2174. through each statement in a called function. For each statement,
  2175. .CW next
  2176. prints the machine instructions executed as part of the statement. After
  2177. the statement has executed, source lines around the current program
  2178. counter are displayed.
  2179. .Ex
  2180. acid: next()
  2181. 60: breakpoint Binit+0x4 MOVW R31,0x0(R29)
  2182. 60: breakpoint Binit+0x8 MOVW f+8(FP),R4
  2183. binit.c:93
  2184. 88
  2185. 89 int
  2186. 90 Binit(Biobuf *bp, int f, int mode)
  2187. 91 {
  2188. >92 return Binits(bp, f, mode, bp->b, BSIZE);
  2189. 93 }
  2190. .Ee
  2191. .\"
  2192. .\"
  2193. .\"
  2194. .Ip \f(CW{}\fP notestk integer "Stack trace after receiving a note
  2195. .CW notestk
  2196. interprets its
  2197. .I integer
  2198. argument as the address of a
  2199. .CW Ureg
  2200. structure passed by the kernel to a
  2201. .I notify (2)
  2202. function during note processing.
  2203. .CW notestk
  2204. uses the
  2205. .CW PC ,
  2206. .CW SP ,
  2207. and link register from the
  2208. .CW Ureg
  2209. to print a stack trace corresponding to the point in the program where the note
  2210. was received.
  2211. To get a valid stack trace on the MIPS and SPARC architectures from a notify
  2212. routine, the program must stop in a new function called from the notify routine
  2213. so that the link register is valid and the notify routine's parameters are
  2214. addressable.
  2215. .Ex
  2216. acid: notestk(*notify:ur)
  2217. Note pc:0x00001024:main+0x4 ls.c:48
  2218. main(argc=0x00000001,argv=0x7fffefec) ls.c:48
  2219. called from _main+0x20 main9.s:10
  2220. _argc=0x00000000
  2221. _args=0x00000000
  2222. .Ee
  2223. .\"
  2224. .\"
  2225. .\"
  2226. .Ip \f(CW{}\fP pfl integer "Print source file and line
  2227. .CW pfl
  2228. interprets its argument as a text address and uses it to print
  2229. the source file and line number corresponding to the address. The output
  2230. has the same format as file addresses in
  2231. .I acme (1).
  2232. .Ex
  2233. acid: pfl(main)
  2234. ls.c:48
  2235. .Ee
  2236. .\"
  2237. .\"
  2238. .\"
  2239. .Ip \f(CW{}\fP procs "" "Print active process list
  2240. .CW procs
  2241. prints a list of active process attached to the debugger. Each process
  2242. produces a single line of output giving the pid, process state, the address
  2243. the process is currently executing, and the
  2244. .CW setproc
  2245. command required to make that process current.
  2246. The current process is marked in the first column with a
  2247. .CW >
  2248. character. The debugger maintains a list of processes in the variable
  2249. .CW proclist .
  2250. .Ex
  2251. acid: procs()
  2252. >62: Stopped at main+0x4 setproc(62)
  2253. 60: Stopped at Binit+0x8 setproc(60)
  2254. .Ee
  2255. .\"
  2256. .\"
  2257. .\"
  2258. .Ip \f(CW{}\fP pstop integer "Print reason process stopped
  2259. .CW pstop
  2260. prints the status of the process specified by the
  2261. .I integer
  2262. pid supplied as its argument.
  2263. .CW pstop
  2264. is usually called from
  2265. .CW stopped
  2266. every time a process enters the
  2267. .CW Stopped
  2268. state.
  2269. .Ex
  2270. acid: pstop(62)
  2271. 0x0000003e: breakpoint main+0x4 MOVW R31,0x0(R29)
  2272. .Ee
  2273. .\"
  2274. .\"
  2275. .\"
  2276. .Ip \f(CW{}\fP regs "" "Print registers
  2277. .CW regs
  2278. prints the contents of both the general and special purpose registers.
  2279. .CW regs
  2280. calls
  2281. .CW spr
  2282. then
  2283. .CW gpr
  2284. to display the contents of the registers.
  2285. .KE
  2286. .\"
  2287. .\"
  2288. .\"
  2289. .Ip \f(CW{}\fP source "" "Summarize source data base
  2290. .CW source
  2291. prints the directory search path followed by a list of currently loaded
  2292. source files. The source management functions
  2293. .CW src
  2294. and
  2295. .CW findsrc
  2296. use the search path to locate and load source files. Source files are
  2297. loaded incrementally into a source data base during debugging. A list
  2298. of loaded files is stored in the variable
  2299. .CW srcfiles
  2300. and the contents of each source file in the variable
  2301. .CW srctext .
  2302. .Ex
  2303. acid: source()
  2304. /n/bootes/sys/src/libbio/
  2305. ./
  2306. /sys/src/libc/port/
  2307. /sys/src/libc/9sys/
  2308. /sys/src/libc/mips/
  2309. binit.c
  2310. .Ee
  2311. .\"
  2312. .\"
  2313. .\"
  2314. .Ip \f(CW{}\fP spr "" "Print special purpose registers
  2315. .CW spr
  2316. prints the contents of the processor control and memory management
  2317. registers. Where possible, the contents of the registers are decoded
  2318. to provide extra information; for example the
  2319. .CW CAUSE
  2320. register on the MIPS is
  2321. printed both in hexadecimal and using the
  2322. .CW reason
  2323. function.
  2324. .Ex
  2325. acid: spr()
  2326. PC 0x00001024 main+0x4 ls.c:48
  2327. SP 0x7fffef68 LINK 0x00006264 _main+0x28 main9.s:12
  2328. STATUS 0x0000ff33 CAUSE 0x00000024 breakpoint
  2329. TLBVIR 0x000000d3 BADVADR 0x00001020
  2330. HI 0x00000004 LO 0x00001ff7
  2331. .Ee
  2332. .\"
  2333. .\"
  2334. .\"
  2335. .Ip \f(CW{}\fP src integer "Print lines of source
  2336. .CW src
  2337. interprets its
  2338. .I integer
  2339. argument as a text address and uses this address to print 5 lines
  2340. of source before and after the address. The current line is marked with a
  2341. .CW >
  2342. character.
  2343. .CW src
  2344. uses the source search path maintained by
  2345. .CW source
  2346. and
  2347. .CW addsrcdir
  2348. to locate the required source files.
  2349. .Ex
  2350. acid: src(*PC)
  2351. ls.c:47
  2352. 42 Biobuf bin;
  2353. 43
  2354. 44 #define HUNK 50
  2355. 45
  2356. 46 void
  2357. >47 main(int argc, char *argv[])
  2358. 48 {
  2359. 49 int i, fd;
  2360. 50 char buf[64];
  2361. 51
  2362. 52 Binit(&bin, 1, OWRITE);
  2363. .Ee
  2364. .\"
  2365. .\"
  2366. .\"
  2367. .Ip \f(CW{}\fP step "" "Single step process
  2368. .CW step
  2369. causes the debugged process to execute a single machine level instruction.
  2370. If the program is stopped on a breakpoint set by
  2371. .CW bpset
  2372. it is first removed, the single step executed, and the breakpoint replaced.
  2373. .CW step
  2374. uses
  2375. .CW follow
  2376. to predict the address of the program counter after the current instruction
  2377. has been executed. A breakpoint is placed at each of these predicted addresses
  2378. and the process is started. When the process stops the breakpoints are removed.
  2379. .Ex
  2380. acid: step()
  2381. 62: breakpoint main+0x8 MOVW R1,argc+4(FP)
  2382. .Ee
  2383. .\"
  2384. .\"
  2385. .\"
  2386. .Ip \f(CW{}\fP stk "" "Stack trace
  2387. .CW stk
  2388. produces a short format stack trace. The stack trace includes each function
  2389. in the stack, where it was called from, and the value of the parameters.
  2390. The short format omits the values of automatic variables.
  2391. Parameters are assumed to be integer values in the format
  2392. .CW X ;
  2393. to print a parameter in the correct format use the
  2394. .CW :
  2395. to obtain its address, apply the correct format, and use the
  2396. .CW *
  2397. indirection operator to find its value.
  2398. It may be necessary to single step a couple of instructions into
  2399. a function to get a correct stack trace because the frame pointer adjustment
  2400. instruction may get scheduled down into the body of the function.
  2401. .Ex
  2402. acid: stk()
  2403. At pc:0x00001028:main+0x8 ls.c:48
  2404. main(argc=0x00000002,argv=0x7fffefe4) ls.c:48
  2405. called from _main+0x20 main9.s:10
  2406. .Ee
  2407. .\"
  2408. .\"
  2409. .\"
  2410. .Ip \f(CW{}\fP stmnt "" "Execute a single statement
  2411. .CW stmnt
  2412. executes a single language level statement.
  2413. .CW stmnt
  2414. displays each machine level instruction as it is executed. When the executed
  2415. statement is completed the source for the next statement is displayed.
  2416. Unlike
  2417. .CW next ,
  2418. the
  2419. .CW stmnt
  2420. function will trace down through function calls.
  2421. .Ex
  2422. acid: stmnt()
  2423. 62: breakpoint main+0x18 MOVW R5,0xc(R29)
  2424. 62: breakpoint main+0x1c JAL Binit(SB)
  2425. 62: breakpoint Binit ADD $-0x18,R29
  2426. binit.c:91
  2427. 89 int
  2428. 90 Binit(Biobuf *bp, int f, int mode)
  2429. >91 {
  2430. .Ee
  2431. .\"
  2432. .\"
  2433. .\"
  2434. .Ip \f(CW{}\fP stopped integer "Report status of stopped process
  2435. .CW stopped
  2436. is called automatically by the interpreter
  2437. every time a process enters the
  2438. .CW Stopped
  2439. state, such as when it hits a breakpoint.
  2440. The pid is passed as the
  2441. .I integer
  2442. argument. The default implementation just calls
  2443. .CW pstop ,
  2444. but the function may be changed to provide more information or perform fine control
  2445. of execution. Note that
  2446. .CW stopped
  2447. should return; for example, calling
  2448. .CW step
  2449. in
  2450. .CW stopped
  2451. will recur until the interpreter runs out of stack space.
  2452. .Ex
  2453. acid: defn stopped(pid) {
  2454. if *lflag != 0 then error("lflag modified");
  2455. }
  2456. acid: progargs = "-l"
  2457. acid: new();
  2458. acid: while 1 do step();
  2459. <stdin>:7: (error) lflag modified
  2460. acid: stk()
  2461. At pc:0x00001220:main+0x200 ls.c:54
  2462. main(argc=0x00000001,argv=0x7fffffe8) ls.c:48
  2463. called from _main+0x20 main9.s:10
  2464. .Ee
  2465. .\"
  2466. .\"
  2467. .\"
  2468. .Ip \f(CW{}\fP symbols string "Search symbol table
  2469. .CW symbols
  2470. uses the regular expression supplied by
  2471. .I string
  2472. to search the symbol table for symbols whose name matches the
  2473. regular expression.
  2474. .Ex
  2475. acid: symbols("main")
  2476. main T 0x00001020
  2477. _main T 0x0000623c
  2478. .Ee
  2479. .\"
  2480. .\"
  2481. .\"
  2482. .Ip \f(CW{}\fP win "" "Start new process in a window
  2483. .CW win
  2484. performs exactly the same function as
  2485. .CW new
  2486. but uses the window system to create a new window for the debugged process.
  2487. The variable
  2488. .CW progargs
  2489. supplies arguments to the new process.
  2490. The environment variable
  2491. .CW $8½srv
  2492. must be set to allow the interpreter to locate the mount channel for the
  2493. window system.
  2494. The window is created in the top left corner of the screen and is
  2495. 400x600 pixels in size. The
  2496. .CW win
  2497. function may be modified to alter the geometry.
  2498. The window system will not be able to deliver notes in the new window
  2499. since the pid of the created process is not passed when the server is
  2500. mounted to create a new window.
  2501. .Ex
  2502. acid: win()
  2503. .Ee