acid 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. .TH ACID 1
  2. .SH NAME
  3. acid, truss, trump \- debugger
  4. .SH SYNOPSIS
  5. .B acid
  6. [
  7. .BI -l " libfile
  8. ]
  9. [
  10. .B -wq
  11. ] [
  12. .B -m
  13. .I machine
  14. ] [
  15. .I pid
  16. ]
  17. [
  18. .I textfile
  19. ]
  20. .PP
  21. .B acid
  22. .B -l
  23. .B truss
  24. .I textfile
  25. .PP
  26. .B acid
  27. .B -l
  28. .B trump
  29. [
  30. .I pid
  31. ]
  32. [
  33. .I textfile
  34. ]
  35. .SH DESCRIPTION
  36. .I Acid
  37. is a programmable symbolic debugger.
  38. It can inspect one or more processes that share an address space.
  39. A program to be debugged may be specified by the process id of
  40. a running or defunct process,
  41. or by the name of the program's text file
  42. .RB ( 8.out
  43. by default).
  44. At the prompt,
  45. .I acid
  46. will store function definitions or print the value of expressions.
  47. Options are
  48. .TP .9i
  49. .B -w
  50. Allow the textfile to be modified.
  51. .TP
  52. .B -q
  53. Don't print variable renamings at startup.
  54. .TP
  55. .BI -l " library
  56. Load from
  57. .I library
  58. at startup; see below.
  59. .TP
  60. .BI -m " machine
  61. Assume instructions are for the given CPU type
  62. (one of
  63. .BR 3210 ,
  64. .BR 386 ,
  65. etc., as listed in
  66. .IR 2c (1),
  67. or
  68. .B sunsparc
  69. or
  70. .B mipsco
  71. for the manufacturer-defined instruction notation for those processors)
  72. instead of using the magic number to select
  73. the CPU type.
  74. .TP
  75. .BI -k
  76. Debug the kernel state for the process, rather than the user state.
  77. .PP
  78. At startup,
  79. .I acid
  80. obtains standard function definitions from the library file
  81. .BR /sys/lib/acid/port ,
  82. architecture-dependent functions from
  83. .BR /sys/lib/acid/$objtype ,
  84. user-specified functions from
  85. .BR $home/lib/acid ,
  86. and further functions from
  87. .B -l
  88. files.
  89. Definitions in any file may override previously defined functions.
  90. If the function
  91. .IR acidinit ()
  92. is defined, it will be invoked after all modules have been loaded.
  93. See
  94. .IR 2c (1)
  95. for information about creating
  96. .I acid
  97. functions for examining data structures.
  98. .SS Language
  99. Symbols of the program being debugged become integer
  100. variables whose values are addresses.
  101. Contents of addresses are obtained by indirection.
  102. Local variables are qualified by
  103. function name, for example
  104. .BR main:argv .
  105. When program symbols conflict with
  106. .I acid
  107. words, distinguishing
  108. .B $
  109. signs are prefixed.
  110. Such renamings are reported at startup; option
  111. .B -q
  112. suppresses them.
  113. .PP
  114. Variable types
  115. .RI ( "integer, float, list, string" )
  116. and formats are inferred from assignments.
  117. Truth values false/true are attributed to zero/nonzero
  118. integers or floats and to empty/nonempty lists or strings.
  119. Lists are sequences of expressions surrounded by
  120. .BR {\^}
  121. and separated by commas.
  122. .PP
  123. Expressions are much as in C,
  124. but yield both a value and a format.
  125. Casts to complex types are allowed.
  126. Lists admit the following operators, with
  127. subscripts counted from 0.
  128. .IP
  129. .BI head " list
  130. .br
  131. .BI tail " list
  132. .br
  133. .BI append " list", " element
  134. .br
  135. .BI delete " list", " subscript
  136. .PP
  137. Format codes are the same as in
  138. .IR db (1).
  139. Formats may be attached to (unary) expressions with
  140. .BR \e ,
  141. e.g.
  142. .BR (32*7)\eD .
  143. There are two indirection operators,
  144. .B *
  145. to address a core image,
  146. .B @
  147. to address a text file.
  148. The type and format of the result are determined by the format of the operand,
  149. whose type must be integer.
  150. .PP
  151. Statements are
  152. .IP
  153. .BI if " expr " then " statement " "\fR[ \fPelse\fI statement \fR]
  154. .br
  155. .BI while " expr " do " statement
  156. .br
  157. .BI loop " expr" , " expr " do " statement
  158. .br
  159. .BI defn " name" ( args ") {" " statement \fP}
  160. .br
  161. .BI local " name
  162. .br
  163. .BI return " expr
  164. .br
  165. .BR whatis " [ \fI name \fP]
  166. .PP
  167. Here is a partial list of functions; see the manual for a complete list.
  168. .TF asm(address)
  169. .TP
  170. .B stk()
  171. Print a stack trace for current process.
  172. .TP
  173. .B lstk()
  174. Print a stack trace with values of local variables.
  175. .TP
  176. .B gpr()
  177. Print general registers.
  178. Registers can also be accessed by name, for example
  179. .BR *R0 .
  180. .TP
  181. .B spr()
  182. Print special registers such as program counter and stack pointer.
  183. .TP
  184. .B fpr()
  185. Print floating-point registers.
  186. .TP
  187. .B regs()
  188. Same as
  189. .BR spr();gpr() .
  190. .TP
  191. .BI fmt( expr , format )
  192. Expression
  193. .I expr
  194. with format given by the character value of expression
  195. .IR format .
  196. .TP
  197. .BI src( address )
  198. Print 10 lines of source around the program address.
  199. .TP
  200. .BI Bsrc( address )
  201. Get the source line for the program address
  202. into a window of a running
  203. .IR sam (1)
  204. and select it.
  205. .TP
  206. .BI line( address )
  207. Print source line nearest to the program address.
  208. .TP
  209. .B source()
  210. List current source directories.
  211. .TP
  212. .BI addsrcdir( string )
  213. Add a source directory to the list.
  214. .TP
  215. .BI filepc( where )
  216. Convert a string of the form
  217. .IB sourcefile : linenumber
  218. to a machine address.
  219. .TP
  220. .BI pcfile( address )
  221. Convert a machine address to a source file name.
  222. .TP
  223. .BI pcline( address )
  224. Convert a machine address to a source line number.
  225. .TP
  226. .BI bptab()
  227. List breakpoints set in the current process.
  228. .TP
  229. .BI bpset( address )
  230. Set a breakpoint in the current process at the given address.
  231. .TP
  232. .BI bpdel( address )
  233. Delete a breakpoint from the current process.
  234. .TP
  235. .B cont()
  236. Continue execution of current process and wait for it to stop.
  237. .TP
  238. .B step()
  239. Execute a single machine instruction in the current process.
  240. .TP
  241. .B func()
  242. Step repeatedly until after a function return.
  243. .TP
  244. .BI stopped( pid )
  245. This replaceable function is called automatically when the given process
  246. stops.
  247. It normally prints the program counter and returns to the prompt.
  248. .TP
  249. .BI asm( address )
  250. Disassemble 30 machine instructions beginning at the given address.
  251. .TP
  252. .BI mem( address , string )
  253. Print a block of memory
  254. interpreted according to a string of format codes.
  255. .TP
  256. .BI dump( address , n , string\fP)
  257. Like
  258. .BR mem (),
  259. repeated for
  260. .I n
  261. consecutive blocks.
  262. .TP
  263. .BI print( expr , ... )
  264. Print the values of the expressions.
  265. .TP
  266. .BI newproc( arguments )
  267. Start a new process with arguments given as a string
  268. and halt at the first instruction.
  269. .TP
  270. .B new()
  271. Like
  272. .IR newproc (),
  273. but take arguments (except
  274. .BR argv[0] )
  275. from string variable
  276. .BR progargs .
  277. .TP
  278. .B win()
  279. Like
  280. .IR new (),
  281. but run the process in a separate window.
  282. .TP
  283. .BI start( pid )
  284. Start a stopped process.
  285. .TP
  286. .BI kill( pid )
  287. Kill the given process.
  288. .TP
  289. .BI setproc( pid )
  290. Make the given process current.
  291. .TP
  292. .BI rc( string )
  293. Escape to the shell,
  294. .IR rc (1),
  295. to execute the command string.
  296. .SS Libraries
  297. There are a number of
  298. .I acid
  299. `libraries' that provide higher-level debugging facilities. Two notable
  300. examples are
  301. .I truss
  302. and
  303. .IR trump ,
  304. which use
  305. .I acid
  306. to trace system calls
  307. .RI ( truss )
  308. and memory allocation
  309. .RI ( trump ).
  310. Both require starting
  311. .I acid
  312. on the program, either by attaching to a running process or by
  313. executing
  314. .B new()
  315. on a binary (perhaps after setting
  316. .BR progargs ),
  317. stopping the process, and then running
  318. .B truss()
  319. or
  320. .B trump()
  321. to execute the program under the scaffolding.
  322. The output will be a trace of the system calls
  323. .RI ( truss )
  324. or memory allocation and free calls
  325. .RI ( trump )
  326. executed by the program.
  327. When finished tracing, stop the process and execute
  328. .B untruss()
  329. or
  330. .B untrump()
  331. followed by
  332. .B cont()
  333. to resume execution.
  334. .SH EXAMPLES
  335. Start to debug
  336. .BR /bin/ls ;
  337. set some breakpoints; run up to the first one:
  338. .IP
  339. .EX
  340. % acid /bin/ls
  341. /bin/ls: mips plan 9 executable
  342. /sys/lib/acid/port
  343. /sys/lib/acid/mips
  344. acid: new()
  345. 70094: system call _main ADD $-0x14,R29
  346. 70094: breakpoint main+0x4 MOVW R31,0x0(R29)
  347. acid: pid
  348. 70094
  349. acid: argv0 = **main:argv\es
  350. acid: whatis argv0
  351. integer variable format s
  352. acid: *argv0
  353. /bin/ls
  354. acid: bpset(ls)
  355. acid: cont()
  356. 70094: breakpoint ls ADD $-0x16c8,R29
  357. acid:
  358. .EE
  359. .PP
  360. Display elements of a linked list of structures:
  361. .IP
  362. .EX
  363. complex Str { 'D' 0 val; 'X' 4 next; };
  364. complex Str s;
  365. s = *headstr;
  366. while s != 0 do{
  367. print(s.val, "\en");
  368. s = s.next;
  369. }
  370. .EE
  371. .PP
  372. Note the use of the
  373. .B .
  374. operator instead of
  375. .BR -> .
  376. .PP
  377. Display an array of bytes declared in C as
  378. .BR "char array[]" .
  379. .IP
  380. .EX
  381. *(array\es)
  382. .EE
  383. .PP
  384. This example gives
  385. .B array
  386. string format, then prints the string beginning at the address (in
  387. .I acid
  388. notation)
  389. .BR *array .
  390. .PP
  391. Trace the system calls executed by
  392. .IR ls (1):
  393. .IP
  394. .EX
  395. % acid -l truss /bin/ls
  396. /bin/ls:386 plan 9 executable
  397. /sys/lib/acid/port
  398. /sys/lib/acid/kernel
  399. /sys/lib/acid/truss
  400. /sys/lib/acid/386
  401. acid: progargs = "-l lib/profile"
  402. acid: new()
  403. acid: truss()
  404. open("#c/pid", 0)
  405. return value: 3
  406. pread(3, 0x7fffeeac, 20, -1)
  407. return value: 12
  408. data: " 166 "
  409. \&...
  410. stat("lib/profile", 0x0000f8cc, 113)
  411. return value: 65
  412. open("/env/timezone", 0)
  413. return value: 3
  414. pread(3, 0x7fffd7c4, 1680, -1)
  415. return value: 1518
  416. data: "EST -18000 EDT -14400
  417. 9943200 25664400 41392800 57718800 73447200 89168400
  418. 104896800 ..."
  419. close(3)
  420. return value: 0
  421. pwrite(1, "--rw-rw-r-- M 9 rob rob 2519 Mar 22 10:29 lib/profile
  422. ", 54, -1)
  423. --rw-rw-r-- M 9 rob rob 2519 Mar 22 10:29 lib/profile
  424. return value: 54
  425. \&...
  426. 166: breakpoint _exits+0x5 INTB $0x40
  427. acid: cont()
  428. .EE
  429. .SH FILES
  430. .B /proc/*/text
  431. .br
  432. .B /proc/*/mem
  433. .br
  434. .B /proc/*/ctl
  435. .br
  436. .B /proc/*/note
  437. .br
  438. .B /sys/lib/acid/$objtype
  439. .br
  440. .B /sys/lib/acid/port
  441. .br
  442. .B /sys/lib/acid/kernel
  443. .br
  444. .B /sys/lib/acid/trump
  445. .br
  446. .B /sys/lib/acid/truss
  447. .br
  448. .B $home/lib/acid
  449. .SH SOURCE
  450. .B /sys/src/cmd/acid
  451. .SH "SEE ALSO"
  452. .IR 2a (1),
  453. .IR 2c (1),
  454. .IR 2l (1),
  455. .IR mk (1),
  456. .IR db (1)
  457. .br
  458. Phil Winterbottom,
  459. ``Acid Manual''.
  460. .SH DIAGNOSTICS
  461. At termination, kill commands are proposed
  462. for processes that are still active.
  463. .SH BUGS
  464. There is no way to redirect the standard input and standard output
  465. of a new process.
  466. .br
  467. Source line selection near the beginning of a file may pick
  468. an adjacent file.
  469. .br
  470. With the extant stepping commands, one cannot step through instructions
  471. outside the text segment and it is hard to debug across process forks.