home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / alt / sources / 3069 < prev    next >
Encoding:
Text File  |  1993-01-23  |  51.6 KB  |  1,247 lines

  1. Newsgroups: alt.sources
  2. Path: sparky!uunet!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!newsserver.jvnc.net!princeton!csservices!tyrolia!mg
  3. From: mg@tyrolia (Michael Golan)
  4. Subject: Duel - a language for debugging C programs part 1/6
  5. Message-ID: <1993Jan22.034007.20953@csservices.Princeton.EDU>
  6. Followup-To: alt.sources.d
  7. Summary: great add-on to gdb!
  8. Keywords: debugging gdb debugger duel C bug
  9. Sender: news@csservices.Princeton.EDU (USENET News System)
  10. Organization: Department of Computer Science, Princeton University
  11. Date: Fri, 22 Jan 1993 03:40:07 GMT
  12. Lines: 1233
  13.  
  14. Submitted-by: mg@cs.princeton.edu
  15. Archive-name: duel/part01
  16.  
  17. -----------------------------------------------------------------------------
  18. DUEL -  A high level language for debugging C programs.
  19. -----------------------------------------------------------------------------
  20.  
  21. Duel is a special purpose language designed for concise state 
  22. exploration of debugged C programs under existing debuggers.
  23. It allows you to explore your program's state better than either 
  24. the debugger's commands, a C interpreter, or print statements
  25. added to your programs. The debugger is extended with the new 
  26. 'dl' command for Duel expressions:
  27.  
  28.      gdb> dl x[1..10] >? 5
  29.      x[3] = 14
  30.      x[8] = 6
  31.  
  32. prints the array elements x[1] to x[10] that are greater than 5. 
  33. The output includes the values 14 and 6, as well as their 
  34. symbolic representation "x[3]" and "x[8]".
  35.  
  36. Duel is debugger-independent, but the current distribution interface only
  37. with gdb. You will need the source for gdb-4.6, or 4.7. Duel is public 
  38. domain code. Do whatever you like with it - add it to commercial debuggers, 
  39. to dbx/sdb or even make it part of the GNU project. 
  40. No part of this distribution contains any copyright or derived code,
  41. (i.e. no GPL code, either). Free and public domain code need no disclaimer, 
  42. which is obvious to anyone in the software business.
  43.  
  44. Even if you don't normally use debuggers, but you are programming in C, give
  45. Duel a try! The man page & help even include summary of useful gdb commands.
  46.  
  47. Duel is available for anonymous ftp from ftp.cs.princeton.edu, in 
  48. /duel/duel.tar.Z. "tar.Z" format means you should use the command
  49.  "zcat duel.tar.Z | tar xf -" to unpack the files.
  50. The Usenix Jan/93 paper about Duel is also available as tech report 399,
  51. in /reports/1992/399.ps.Z on ftp.cs.princeton.edu
  52.  
  53. DUEL is "Debugging U (might) Even Like" or "Don't Use this Exotic Language"
  54. you should judge which is better!
  55.  
  56. Michael Golan
  57. mg@cs.princeton.edu
  58. -----------------------------------------------------------------------------
  59. The tutorial part from the manual page follows:
  60.  
  61.      Duel is based on expressions which return    multiple  values.   The  x..y
  62.      operator  returns    the  integers from x to y; the x,y operator returns x
  63.      and then y, e.g.
  64.  
  65.      gdb> dl (1,9,12..15,22)
  66.  
  67.      prints 1, 9, 12, 13, 14, 15 and 22. Such expressions can be  used    wher-
  68.      ever a single value is used, e.g.
  69.  
  70.      gdb> dl x[0..99]=0 ;
  71.  
  72.      assigns zero to the first 100 elements of array x. The semantics of x[i]
  73.      are  the  same as in C. They are applied for each of the values returned
  74.      by 0..99, which can be thought of as  an  implied    external  loop.   The
  75.      trailing  semicolon  indicates evaluation for side-effects only, with no
  76.      output. Duel incorporates C operators, casts  C  statements  as  expres-
  77.      sions, and supports limited  variable declaration:
  78.  
  79.      gdb> dl int i;for(i=0;i<100;i++)
  80.               if(x[i]<0) printf("x[%d]=%d\n",i,x[i]);
  81.      x[7] = -4
  82.  
  83.      The semicolon prevents Duel output; only output from printf is  printed.
  84.      Aliases  are  defined  with  x:=y and provide an alternative to variable
  85.      declaration. We could also return x[i] instead of using printf:
  86.  
  87.      gdb> dl if(x[i:=0..99]<0) x[i]
  88.      x[i] = -4
  89.  
  90.      The symbolic output "x[i]" can be fixed by surrounding i with {}, i.e.
  91.  
  92.      gdb> dl if(x[i:=0..99]<0) x[{i}]
  93.      x[7] = -4
  94.  
  95.      The {} are like (), but force the symbolic evaluation to use i's  value,
  96.      instead  of  "i". You can usually avoid this altogether with direct Duel
  97.      operators:
  98.  
  99.      gdb> dl x[..100] <? 0
  100.      x[7] = -4
  101.  
  102.      The ..n operator is a shorthand for 0..n-1, i.e. ..100 is    the  same  as
  103.      0..99.   The x<?y, x==?y, x>=?y, etc., operators compare their left side
  104.      operand to their right side operand as in C, but return  the  left  side
  105.      value  if    the  comparison  result is true. Otherwise, they look for the
  106.      next values to compare, without returning anything.
  107.  
  108.      Duel's x.y and x->y allow an expression y, evaluated under x's scope:
  109.  
  110.      gdb> dl emp[..100].(if(code>400) (code,name))
  111.      emp[46].code = 682
  112.      emp[46].name = "Ela"
  113.  
  114.      The if() expression is evaluated under the  scope    of  each  element  of
  115.      emp[], an array of structures. In C terms, we had to write:
  116.  
  117.      gdb> dl int i; for(i=0; i<100 ; i++)
  118.        if(emp[i].code>400) emp[{i}].code,emp[{i}].name
  119.  
  120.      A useful alternative to loops is the x=>y operator.  It  returns  y  for
  121.      each value of x, setting `_' to reference x's value, e.g.
  122.  
  123.      gdb> ..100 => if(emp[_].code>400) emp[_].code,emp[_].name
  124.  
  125.      Using `_' instead of `i' also avoids the  need  for  {i}.    Finally,  the
  126.      x-->y  operator  expands lists and other data structures. If head points
  127.      to a linked list threaded through the next field, then:
  128.  
  129.      gdb> dl head-->next->data
  130.      head->data = 12
  131.      head->next->data = 14
  132.      head-->next[[2]]->data = 20
  133.      head-->next[[3]]->data = 26
  134.  
  135.      produce the data field for each node in the list. x-->y returns x, x->y,
  136.      x->y->y,  x->y->y->y,  ...  until    a  NULL is found. The symbolic output
  137.      "x-->y[[n]]" indicates that ->y was applied n times. x[[y]] is also  the
  138.      selection operator:
  139.  
  140.      gdb> dl head-->next[[50..60]]->data
  141.  
  142.      return the 50th through the 60th elements in the list. The #/x  operator
  143.      counts the number of values, so
  144.  
  145.      gdb> dl #/( head-->next->data >? 50 )
  146.  
  147.      counts the number of data elements over 50 on the list.
  148.  
  149.  
  150.  
  151. #!/bin/sh
  152. # This is duel, a shell archive (shar 3.32)
  153. # made 01/22/1993 03:34 UTC by mg@cs.princeton.edu
  154. # Source directory /tmp_mnt/n/fs/grad2/mg/duel/distr
  155. #
  156. # existing files WILL be overwritten
  157. #
  158. # This shar contains:
  159. # length  mode       name
  160. # ------ ---------- ------------------------------------------
  161. #   2443 -rw-r--r-- README
  162. #   7232 -rw-r--r-- INSTALL
  163. #  22468 -rw-r--r-- duel.1
  164. #   5550 -rw-r--r-- internals.doc
  165. #   5186 -rw-r--r-- wishlist.doc
  166. #   7719 -rw-r--r-- gnu-vs-duel.doc
  167. #  20549 -rw-r--r-- duelgdb.c
  168. #    993 -rw-r--r-- src/Makefile
  169. #     21 -rw-r--r-- src/patchlevel.h
  170. #   1162 -rw-r--r-- src/duel.h
  171. #  15898 -rw-r--r-- src/global.h
  172. #   3352 -rw-r--r-- src/proto.h
  173. #   6871 -rw-r--r-- src/duel.c
  174. #  29171 -rw-r--r-- src/parse.y
  175. #  27680 -rw-r--r-- src/eval.c
  176. #  45286 -rw-r--r-- src/evalops.c
  177. #   2715 -rw-r--r-- src/error.c
  178. #   7498 -rw-r--r-- src/print.c
  179. #   5857 -rw-r--r-- src/types.c
  180. #   3378 -rw-r--r-- src/misc.c
  181. #   5695 -rw-r--r-- src/duelself.c
  182. #    262 -rw-r--r-- src/tsuite.c
  183. #   1206 -rw-r--r-- src/tsuite.gdb
  184. #   1095 -rw-r--r-- src/tsuite.self
  185. #   3214 -rw-r--r-- src/tsuite.gdb.out
  186. #   4576 -rw-r--r-- src/tsuite.self.out
  187. #
  188. if touch 2>&1 | fgrep 'amc' > /dev/null
  189.  then TOUCH=touch
  190.  else TOUCH=true
  191. fi
  192. # ============= README ==============
  193. echo "x - extracting README (Text)"
  194. sed 's/^X//' << 'SHAR_EOF' > README &&
  195. X-------------------------------------------------------------------------------
  196. XREADME for DUEL 1.00.0 distribution   mg@cs.princeton.edu (M. Golan) January 93
  197. X-------------------------------------------------------------------------------
  198. X
  199. XDUEL -  A high level language for debugging C programs.
  200. X
  201. XEven if you don't normally use debuggers, but you are programming in C, give
  202. XDuel a try! The man page & help even include summary of useful gdb commands.
  203. XTo show positive elements of array x, index 0 to 1023, in Duel: x[..1024]>?0
  204. X
  205. XDuel is debugger-independent, but the current distribution interface only
  206. Xwith gdb. You will need the source for gdb-4.6, or 4.7. Duel is public 
  207. Xdomain code. Do whatever you like with it - add it to commercial debuggers, 
  208. Xto dbx/sdb or even make it part of the GNU project. 
  209. XNo part of this distribution contains any copyright or derived code,
  210. X(i.e. no GPL code, either). Free and public domain code need no disclaimer, 
  211. Xwhich is obvious to anyone in the software business.
  212. X
  213. X
  214. XDuel is available for anonymous ftp from ftp.cs.princeton.edu, in 
  215. X/duel/duel.tar.Z. "tar.Z" format means you should use the command
  216. X "zcat duel.tar.Z | tar xf -" to unpack the files.
  217. XThe Usenix Jan/93 paper about Duel is also available as tech report 399,
  218. Xin /reports/1992/399.ps.Z on ftp.cs.princeton.edu
  219. X
  220. XThe distribution contains:
  221. X
  222. XREADME            - this file
  223. XINSTALL         - how to install duel (you need gdb4.6 or later first!)
  224. Xduel.1            - man page
  225. Xinternals.doc   - documents internals
  226. Xwishlist.doc    - things that could be added/improved/hacked
  227. Xgnu-vs-duel.doc - explains why Duel is not GNU and why you should release 
  228. X              public domain code and not GNUish code.
  229. Xduelgdb.c       - module linked in with gdb (sets 'dl' command, etc)
  230. X
  231. XIn ./src directory:
  232. X
  233. X*.h         - include files: duel.h proto.h global.h patchlevel.h
  234. X*.c         - source: duel.c eval.c evalops.c print.c error.c misc.c types.c
  235. Xparse.y      - yacc/bison parser & lexer.
  236. Xduelself.c   - stand alone link module (for testing only)
  237. XMakefile     - vanilla make file
  238. X
  239. Xtsuite.self - a test suite for duelself (includes intentional errors!)
  240. Xtsuite.gdb  - a test suite for duelgdb        -"-
  241. Xtsuite.c    - file being "debug" by tsuite.gdb (cc -g tsuite.c -o tsuite)
  242. Xtsuite.self.out - expected test suite self output 
  243. Xtsuite.gdb.out  - expected test suite gdb output 
  244. X        (note different machines will have different addresses)
  245. X
  246. X
  247. XMichael Golan
  248. Xmg@cs.princeton.edu
  249. X
  250. SHAR_EOF
  251. $TOUCH -am 0121222593 README &&
  252. chmod 0644 README ||
  253. echo "restore of README failed"
  254. set `wc -c README`;Wc_c=$1
  255. if test "$Wc_c" != "2443"; then
  256.     echo original size 2443, current size $Wc_c
  257. fi
  258. # ============= INSTALL ==============
  259. echo "x - extracting INSTALL (Text)"
  260. sed 's/^X//' << 'SHAR_EOF' > INSTALL &&
  261. X-------------------------------------------------------------------------------
  262. XINSTALLING DUEL 1.00.0 distribution   mg@cs.princeton.edu (M. Golan) January 93
  263. X-------------------------------------------------------------------------------
  264. X
  265. XAll files in the distribution are public domain (not gnuish!) code.
  266. X
  267. X
  268. XBASICS
  269. XDuel is a library, normally linked with a debugger. Currently only gdb
  270. Xis supported. However, the code in the distribution contains a self-link
  271. Xmodule which can be used to test duel expressions w/o gdb (useful only
  272. Xto verify duel, or if you plan to port or use as a portable debugging tool).
  273. X
  274. XNormally, Duel runs on top of the GNU debugger gdb(1). In order to use it, 
  275. Xyou must first install gdb. Duel should work with gdb version 4.6 and 
  276. Xlater. For older versions, some minor changes might be needed to 
  277. Xthe interface module duelgdb.c. Before duel is installed, unpack
  278. Xand compile the regular gdb distribution. The Duel distribution 
  279. Xfiles should be unpacked in subdirectory 'duel' of
  280. Xgdb. Duel is then compiled into the library duel.a. Then, you
  281. Xmodify the gdb Makefile to include the module duel/duelgdb.c and
  282. Xto link with duel/src/duel.a. You also need to modify one source line
  283. Xin gdb's code, to change comments to start with '##' instead of '#'.
  284. XIf everything goes well, after another 'make' the new gdb executable 
  285. Xshould support the 'duel' command (alias 'dl').  You can test it by 
  286. Xrunning gdb and giving a command like "dl 1..10". There is also
  287. Xa test suite.
  288. X
  289. XSUN EXAMPLE
  290. X
  291. X% mkdir ~/duelgdb
  292. X% cd ~/duelgdb
  293. X% ftp ftp.cs.princeton.edu
  294. X  ftp  cd /pub/duel
  295. X  ftp> get gdb-4.7.tar.Z
  296. X  ftp> get duel.tar.Z
  297. X% zcat gdb-4.7.tar | tar xvf -
  298. X% cd gdb-4.7
  299. X% ./configure sparc
  300. X% cd gdb
  301. X% vi Makefile    - modifiy "GCC=gcc" to "CC=gcc"
  302. X% cd ..
  303. X% make
  304. X% cd gdb
  305. X% gdb         - check gdb works. try "print 1+2"
  306. X% mkdir duel
  307. X% cd duel
  308. X% zcat ~/duelgdb/duel.tar | tar xvf -
  309. X% cd src
  310. X% make
  311. X% vi y.tab.c     - SUN yacc add "char *malloc" which is wrong. remove it
  312. X% make         - try again
  313. X% selftest < tsuite.self > self.out
  314. X% diff tsuite.self.out self.out        - see diffs. @xxxx diffs are ok
  315. X% cd ..                    - back to duel
  316. X% cd ..                    - up to gdb's src
  317. X% mv duel/duelgdb.c .
  318. X% vi Makefile     - add SFILES_MAINDIR=duelgdb.c OBS=duelgdb.o 
  319. X            CLIBS=duel/src/duel.a  CDEPS=duel/src/duel.a
  320. X% vi main.c     - "else if (c == '#')"  --> "else if (c=='#' && *p1=='#')"
  321. X% make
  322. X% gdb         - test new gdb, with duel
  323. X  gdb> dl 1..4     - should print 1 2 3 4
  324. X
  325. X% cd duel/src
  326. X% cc -g tsuite.c -o tsuite        - prepare program tsuite.gdb use
  327. X% ../../gdb <tsuite.gdb >gdb.out    - run test suite
  328. X% diff gdb.out tsuite.gdb.out gdb.out     - see diffs @xxx diffs are ok
  329. X
  330. X
  331. XDETAILS
  332. X1. Get the gdb distribution, install, configure, compile and test it.
  333. X   The configure script works pretty well, but watch out for weird 
  334. X   utilities in your path (e.g. GNU sed was in my PATH before the 
  335. X   standard sed. It was incompatible and caused lots of trouble).
  336. X   Most common use is ./configure sparc or ./configure decstation
  337. X   and then just "make". 
  338. X
  339. X   SUN sparc: use gcc on SUN, since duel uses prototypes and SUN's cc 
  340. X   can't handle them. Change gdb/Makefile: from GCC=gdb to CC=gdb, but note 
  341. X   the warnings about the ioctrl in the makefile (I had no problems with 
  342. X   gcc 2.1; I am not sure what these warnings imply).
  343. X
  344. X   SGI iris machines: use ./configure iris4. Note that gdb is broken on
  345. X   the irises (can't write to the target), so it cripples the use of duel
  346. X   as well (no declared variables (use aliases), no strings).
  347. X
  348. X   DEC mips machines: This is what duel was developed on, should work fine.
  349. X   use straight cc, shouldn't have any problems.
  350. X
  351. X   Other machines: you should test gdb's ability to allocate and write into 
  352. X   the target's memory. Compile tsuite.c and start it under gdb (single step
  353. X   twice). Now, enter the command 
  354. X    gdb> print "test"
  355. X   If it fails, gdb can not find "malloc", can't call it, or can't write
  356. X   to the target's memory; duel will be limited in functionality.
  357. X   
  358. X
  359. X2. Unpack the duel source code into a subdirectory duel of gdb.
  360. X   DO NOT unpack it in the gdb directory, since duel source files
  361. X   like eval.c will clash with gdb source files. The gdb directory
  362. X   is the one that contains files like 'values.c', 'valops.c'.
  363. X
  364. X3. In gdb/duel/src, run make. This compiles the Duel source code into 
  365. X   duel.a, to be later linked with gdb. The makefile is pretty
  366. X   simple. You can used either cc or gcc, but it must support ANSI
  367. X   prototypes. All system include files are in duel.h. 
  368. X   On SUN machines, you must use gcc (cc doesn't support prototypes)
  369. X   you will need to modify y.tab.c, because it declares malloc 
  370. X   incorrectly (first line in the file, delete it)
  371. X
  372. X   The program duelself will also be created (A stand-alone duel code
  373. X   for testing)
  374. X
  375. X4. Verify that duel is compiled ok by running duelself and giving
  376. X   a command like (1..4)*(4,2.5). You can also run the whole
  377. X   test suite with "duelself <tsuite.self >self.out" and compare
  378. X   the tsuite.self.out and self.out files. Note that memory
  379. X   references are likely to be different. Also, beware that the
  380. X   test suite has intentional errors (not all marked clearly).
  381. X
  382. X5. Add a link from gdb/duel/duelgdb.c to gdb/duelgdb.c, or just
  383. X   move the duel/duelgdb.c file to gdb's main dir.
  384. X
  385. X6. Edit gdb's Makefile. The Makefile is produced automatically,
  386. X   so any changes you made will be undone if you reconfigure gdb.
  387. X   You may change either the Makefile, or the Makefile.in (in
  388. X   which case gdb should re-configure itself automatically,
  389. X   and might require a total recompile). If you only going to
  390. X   compile duel once, and you already compiled gdb, I suggest
  391. X   you just modify the Makefile.
  392. X   
  393. X   A. Locate the SFILES_MAINDIR = macro. add duelgdb.c
  394. X   B. Locate OBS = macro. add duelgdb.o
  395. X   C. Locate CLIBS = macro. add duel/src/duel.a
  396. X   D. You can also add duel/src/duel.a to CDEPS = if you want to
  397. X      rebuild gdb automatically each time duel.a changes.
  398. X
  399. X7. Modify gdb's comments to start with '##' instead of '#', since
  400. X   duel uses '#' as an operator. This step is optional -- you could
  401. X   use %/ and %% for #/ and # (see duel/parse.y).
  402. X   in file main.c line 1529 or near by, "else if (c == '#')"
  403. X   modify to "else if (c == '#' && *p1 == '#')"
  404. X
  405. X8. run make in gdb's directory. The new gdb binary should support
  406. X   the duel (alias dl) commands. You can test it by running gdb
  407. X   and trying 'dl 1..10' which should print the numbers from 1 to 10.
  408. X   A test suite tsuite.gdb is in duel/src. to use, first compile
  409. X   tsuite.c, cc -g tsuite.c -o tsuite, then run gdb <tsuite.gdb >gdb.out
  410. X   and compare the output to tsuite.gdb.out. Again, beware that there
  411. X   are intentional errors in the test suite, and that output of 
  412. X   addresses/pointer is likely to differ.
  413. X   Possible problems: duel uses assert.h. If you use gcc, you could
  414. X   end up with an undefined __eprintf from gdb's assert.h. Either use
  415. X   cc, point to the standard assert.h, or use gcc -U__GNU__.
  416. X
  417. X9. Install the new gdb as "duel" instead of "gdb". Also install the
  418. X   manual page duel/duel.1
  419. X
  420. XWHY SO MANY STEPS?
  421. XBecause I don't want to distribute a modified version of any GNU stuff.
  422. Xthis protects you from being GNU-ized if you only want the duel code.
  423. X
  424. X
  425. XMichael Golan
  426. Xmg@cs.princeton.edu
  427. X
  428. SHAR_EOF
  429. $TOUCH -am 0121201193 INSTALL &&
  430. chmod 0644 INSTALL ||
  431. echo "restore of INSTALL failed"
  432. set `wc -c INSTALL`;Wc_c=$1
  433. if test "$Wc_c" != "7232"; then
  434.     echo original size 7232, current size $Wc_c
  435. fi
  436. # ============= duel.1 ==============
  437. echo "x - extracting duel.1 (Text)"
  438. sed 's/^X//' << 'SHAR_EOF' > duel.1 &&
  439. X'\" t
  440. X.\" This document and the Duel source code are in the public domain.
  441. X.\" Note that the duel executable contains GNU code and is not public domain.
  442. X.TH Duel 1 "Jan 93" "Version 1.0" 
  443. X.SH NAME
  444. Xduel \- A high level C debugging language extension to gdb
  445. X.SH SYNOPSIS
  446. X.B duel 
  447. X[gdb options] 
  448. X.RB "[\|" \c
  449. X.I prog\c
  450. X.RB "[\|" \c
  451. X.IR core \||\| procID\c
  452. X\&\|]\&\|]
  453. X.ad b
  454. X.SH DESCRIPTION
  455. XDuel is a special purpose language designed for concise state exploration 
  456. Xof debugged C programs, currently implemented under the GNU debugger
  457. X.IR gdb (1).
  458. XDuel is invoked by entering the shell command 
  459. X.I duel 
  460. Xinstead of 
  461. X.I gdb.
  462. XIt is identical to gdb except for 
  463. Xcomments, which begin with `##' instead of `#', and the new
  464. X.I dl
  465. Xcommand for Duel expressions:
  466. X.nf
  467. X
  468. X\f2gdb>\f1 dl x[1..10] >? 5
  469. Xx[3] = 14
  470. Xx[8] = 6
  471. X
  472. X.fi
  473. Xprints the array elements x[1] to x[10] that are greater than 5. 
  474. XThe output includes the values 14 and 6, as well as their
  475. Xsymbolic representation "x[3]" and "x[8]".
  476. X.SH IF YOU NEVER USED GDB
  477. XThe improved functionality added by Duel merits a fresh look
  478. Xeven by debugger shunners.
  479. XGdb is a powerful debugger with many commands, a thick manual and 
  480. Xvarious interfaces including 
  481. X.IR emacs (1) 
  482. Xand 
  483. X.IR xxgdb (1). 
  484. XThese gdb commands should help you get started:
  485. X
  486. X.TS
  487. Xl l.
  488. X\f2b line\f1    set a breakpoint at the line (b func to break at a function)
  489. X\f2d n\f1    delete breakpoint number n (gdb prints n when bp occurs)
  490. X\f2l line\f1    list the source beginning at line (l file.c:line for module)
  491. X\f2r parm\f1    run/restart the program with the given parameters
  492. X\f2s\f1    single-step to the next statement (steps into function calls)
  493. X\f2n\f1    single-step to the next line, skipping over function calls
  494. X\f2c\f1    continue execution 
  495. X\f2bt\f1    show a stack trace
  496. X\f2p exp\f1    evaluate a symbolic expression
  497. X\f2dl exp\f1    evaluate a Duel expression
  498. X\f2dl gdb\f1    give a gdb command summary
  499. X.TE
  500. X
  501. XThe most common use is `b func' followed by `r' followed by several 
  502. X`n' and `s', evaluating expressions in between. 
  503. X.SH DUEL QUICK START
  504. XDuel is implemented by adding the 
  505. X.I dl 
  506. Xcommand to gdb. All gdb commands
  507. Xwork as before. The dl command, however, is interpreted by duel.
  508. XGdb concepts (such as the value history) do not work in the dl command,
  509. Xand duel concepts are not understood by other gdb command.
  510. X
  511. XDuel is based on expressions which return multiple values.
  512. XThe x..y operator returns
  513. Xthe integers from x to y; the x,y operator returns x and then y, e.g.
  514. X.sp
  515. X\f2gdb>\f1 dl (1,9,12..15,22)
  516. X.sp
  517. Xprints 1, 9, 12, 13, 14, 15 and 22. Such expressions can
  518. Xbe used wherever a single value is used, e.g.
  519. X.sp
  520. X\f2gdb>\f1 dl x[0..99]=0 ;
  521. X.sp
  522. Xassigns zero to the first 100 elements of array x. The semantics of x[i]
  523. Xare the same as in C. They are applied for each of the values
  524. Xreturned by 0..99, which can be thought of as an implied external loop.
  525. XThe trailing semicolon indicates evaluation for side-effects only, with no 
  526. Xoutput. 
  527. XDuel incorporates C operators, casts C statements as
  528. Xexpressions, and supports limited  variable declaration:
  529. X.sp
  530. X.br
  531. X\f2gdb>\f1 dl int i;for(i=0;i<100;i++) 
  532. X.br
  533. X                 if(x[i]<0) printf("x[%d]=%d\\n",i,x[i]); 
  534. X.br
  535. Xx[7] = -4
  536. X.sp
  537. XThe semicolon prevents Duel output;
  538. Xonly output from printf is printed.
  539. XAliases are defined with x:=y and provide an alternative to variable 
  540. Xdeclaration. We could also return x[i] instead of using printf:
  541. X.sp
  542. X\f2gdb>\f1 dl if(x[i:=0..99]<0) x[i]
  543. X.br
  544. Xx[i] = -4
  545. X.sp
  546. XThe symbolic output "x[i]" can be fixed by surrounding i with {}, i.e.
  547. X.sp
  548. X\f2gdb>\f1 dl if(x[i:=0..99]<0) x[{i}]
  549. X.br
  550. Xx[7] = -4
  551. X.sp
  552. XThe {} are like (), but force the symbolic evaluation to use i's value, 
  553. Xinstead of "i". You can usually avoid this altogether
  554. Xwith direct Duel operators:
  555. X.sp
  556. X\f2gdb>\f1 dl x[..100] <? 0
  557. X.br
  558. Xx[7] = -4
  559. X.sp
  560. XThe ..n operator is a shorthand for 0..n-1, i.e. ..100 is the same as 0..99.
  561. XThe x<?y, x==?y, x>=?y, etc., operators compare their left side operand to
  562. Xtheir right side operand as in C, but return the left side value if
  563. Xthe comparison result is true. Otherwise, they look for the next
  564. Xvalues to compare, without returning anything.
  565. X
  566. XDuel's x.y and x->y allow an expression y, evaluated under x's scope:
  567. X.sp
  568. X\f2gdb>\f1 dl emp[..100].(if(code>400) (code,name))
  569. X.br
  570. Xemp[46].code = 682
  571. X.br
  572. Xemp[46].name = "Ela"
  573. X.sp
  574. XThe if() expression is evaluated under the scope of each element 
  575. Xof emp[], an array of structures. In C terms, we had to write:
  576. X.sp
  577. X\f2gdb>\f1 dl int i; for(i=0; i<100 ; i++) 
  578. X.br
  579. X    if(emp[i].code>400) emp[{i}].code,emp[{i}].name
  580. X.sp
  581. XA useful alternative to loops is the x=>y operator. It returns y for each
  582. Xvalue of x, setting `_' to reference x's value, e.g.
  583. X.sp
  584. X\f2gdb>\f1 ..100 => if(emp[_].code>400) emp[_].code,emp[_].name
  585. X.sp
  586. XUsing `_' instead of `i' also avoids the need for {i}. Finally,
  587. Xthe x\-\->y operator expands lists and other data structures. If head points
  588. Xto a linked list threaded through the next field, then:
  589. X.sp
  590. X\f2gdb>\f1 dl head-->next->data
  591. X.br
  592. Xhead->data = 12
  593. X.br
  594. Xhead->next->data = 14
  595. X.br
  596. Xhead-->next[[2]]->data = 20
  597. X.br
  598. Xhead-->next[[3]]->data = 26
  599. X.sp
  600. Xproduce the data field for each node in the list. x\-\->y
  601. Xreturns x, x->y, x->y->y, x->y->y->y, ... until a NULL is found. 
  602. XThe symbolic output "x\-\->y[[n]]"
  603. Xindicates that ->y was applied n times. x[[y]] is also the selection
  604. Xoperator:
  605. X.sp
  606. X\f2gdb>\f1 dl head-->next[[50..60]]->data
  607. X.sp
  608. Xreturn the 50th through the 60th elements in the list. The #/x operator
  609. Xcounts the number of values, so
  610. X.sp
  611. X\f2gdb>\f1 dl #/( head-->next->data >? 50 )
  612. X.sp
  613. Xcounts the number of data elements over 50 on the list.
  614. XSeveral other operators, including x@y, x#y and 
  615. Xactive call stack access are described in the operators section.
  616. X.SH OPERATORS SUMMARY
  617. X.\"All the C operators have the same precedence and associativity as in C. C
  618. X.\"statements have precedence just below `,' and `;' has the lowest precedence. 
  619. X.\"Most Duel operators have the same precedence as their C counterparts. The
  620. X.\"following table is in decreasing precedence:
  621. X.TS
  622. Xl l l.
  623. XAssoc    Operators    Details
  624. Xleft    {} () [] -> . f() -->    x-->y expands x->y x->y->y ...
  625. X    x[[y]] x#y x@y    generate x; select, index or stop-at y
  626. Xright    #/ - * & ! ~ ++ -- (cast)    #/x number of x values
  627. X    frame(n) sizeof    reference to call stack level n
  628. Xleft    x/y x*y x%y    multiply, divide, reminder
  629. Xleft    x-y x+y    add, subtract
  630. Xleft    x<<y x>>y    shift left/right
  631. Xnone    x..y ..y x..    ..y = 0..y-1. x..y return x, x+1...y
  632. Xleft    < > <= >= <? >? <=? >=?    x>?y return x if x>y
  633. Xleft    == != ==? !=?    x==?y return x if x==y
  634. Xleft    x&y    bit-and
  635. Xleft    x^y    bit-xor
  636. Xleft    x|y    bit-or
  637. Xleft    x&&y &&/x    &&/x are all x values non-zero?
  638. Xleft    x||y ||/x    ||/x is any x value non-zero?
  639. Xright    x? y:z    foreach x, if(x) y else z
  640. Xright    x:=y x=y x+=y ...    x:=y set x as an alias to y
  641. Xleft    x,y    return x, then y
  642. Xright    x=>y    foreach x, evaluate y with x value `_'
  643. Xright    if() else  while()  for()    C statements cast as operators
  644. Xleft    x;y    evaluate and ignore x, return y
  645. X.TE
  646. X
  647. X.SH EXAMPLES
  648. X.TS
  649. Xl l.
  650. Xdl (0xff-0x12)*3    compute simple expression
  651. Xdl (1..10)*(1..10)    display multiplication table
  652. Xdl x[10..20,22,24,40..60]    display x[i] for the selected indexes
  653. Xdl x[9..0]    display x[i] backwards
  654. Xdl x[..100] >? 5    display x[i] that are greater than 5
  655. Xdl x[..100] >? 5 <? 10    display x[i] if 5<x[i]<10
  656. Xdl x[..100] ==? (6..9)    same
  657. Xdl x[0..99]=>if(_>5 && _<10) _    same
  658. Xdl y[x[..100] !=? 0]    display y[x[i]] for each non-zero x[i]
  659. Xdl emp[..50].code    display emp[i].code for i=0 to 49
  660. Xdl emp[..50].(code,name)    display emp[i].code & emp[i].name
  661. Xdl val[..50].(is_dbl? x:y)    display val[i].x or val[i].y depending 
  662. X     on val[i].is_dbl. 
  663. Xdl val[..50].if(is_dbl) x else y    same as above
  664. Xdl x[..100]=0 ;    assign 0 to x[i]
  665. Xdl x[i:=..100]=y[i] ;    assign y[i] to x[i]
  666. Xdl x[..100]=y[..100] *ERR*    assign y[99] to each x[j]
  667. Xdl x[i:=..3]=(4,5,9)[[i]]    assign x[0]=4 x[1]=5 x[2]=9
  668. Xdl x[..3]=(4,5,9)    *ERR*    assign 9 to each element
  669. Xdl if(x[i:=..100]<0) x[i]=0 ;    assign 0 to negative x[i]
  670. Xdl (hash[..1024]!=?0)->scope    hash[i].scope for non-null hash[i]
  671. Xdl x[i:=..100] >? x[i+1]    check if x[i] is not sorted
  672. Xdl x[i:=..100] ==? x[j:=..100]=>    checks if x has non-unique elements
  673. X   if(i<j) x[{i,j}]    
  674. Xdl if(x[i:=..99] ==     same
  675. X   x[j:=i+1..99]) x[{i,j}]
  676. Xdl (x[..100] >? 0)[[0]]    the 1st (0th element) positive x[i] 
  677. Xdl (x[..100] >? 0)[[2]]    return the 3rd positive x[i] 
  678. Xdl (x[..100] >? 0)[[..5]]    return the first 5 positive x[i]
  679. Xdl (x[0..] >? 6)[[0]]    return the first x[i]>6, no limit on i
  680. Xdl argv[0..]@0    argv[0] argv[1] .. until first null
  681. Xdl x[0..]@-1 >? 9    x[0..n]>9 where n is first x[n]== -1
  682. Xdl emp[0..]@(code==0)    emp[0]..emp[n-1] where emp[n].code==0
  683. X
  684. Xdl head-->next->val    val of each element in a linked list
  685. Xdl head-->next[[20]]    the 21st element of a linked list
  686. Xdl *head-->next[[20]]    display above as a struct
  687. Xdl #/head-->next    count elements on a linked list
  688. Xdl x-->y[[#/x-->y - 1]]    last element of a linked list
  689. Xdl x-->y[[#/x-->y - 10..1]]    last 10 elements of a linked list
  690. Xdl head-->next->    check if the list is sorted by val
  691. X   if(next) val >? next->val
  692. X
  693. Xdl head-->(next!=?head)    expand cyclic linked list (tail->head)
  694. Xdl head-->(next!=?_)    handle termination with p->next==p 
  695. Xdl root-->(left,right)->key    expand binary tree, show keys
  696. X
  697. Xdl (T mytype) x    convert x to a user defined type mytype
  698. Xdl (struct s*) x    convert x to struct s pointer
  699. Xdl if(x) y; else z *ERR*    ';' must be followed by an expression
  700. Xdl {x} y *ERR*    '}' requires ';' if followed by exp
  701. X.TE
  702. X.SH SEMANTICS
  703. XDuel's semantics are modeled after the Icon programming language.
  704. XThe input consists of expressions which return sequences of values. 
  705. XC statements are cast as expressions, too. 
  706. XExpressions are parsed into abstract syntax trees, which are
  707. Xtraversed during evaluation. The evaluation of most nodes (operators)
  708. Xrecursively evaluates the next value for each operand, and then applies the
  709. Xoperator to produce the next result. Only one value is produced each time,
  710. Xand Duel's eval function keeps a `state' for each node 
  711. X(backtracking, co-routines, consumer-producer or threads are good metaphors 
  712. Xfor the evaluation mechanism.)
  713. X
  714. XFor example, in (5,3)+6..8, the 
  715. Xevaluation of `+' first retrieves the operands 5 and 6, to compute and
  716. Xreturn 5+6. Then 7, the next right operand is retrieved
  717. Xand 5+7 is returned, followed by 5+8.
  718. XSince there are no other right operand value, the next left operand, 3
  719. Xis fetched. The right operand's computation is restarted returning
  720. X6, and 3+6 is returned. The final return values are 3+7 and 3+8.
  721. X
  722. XThe computation for operators like x>?y is similar, but when x<=y,
  723. Xthe next values are fetched instead of returning a value,
  724. Xforming the basis for an implicit search. Operators like `..' return a 
  725. Xsequence of values for each pair of operands. For a better understanding
  726. Xof the evaluation mechanism, see the USENIX Winter/93 conference paper
  727. X"DUEL - A Very High Level Debugging Language".
  728. X
  729. XDuel values follow the C semantics. A value is either an
  730. X"lvalue" (can be used as the left hand side of assignment), or an "rvalue".
  731. XTherefor, objects like arrays can not be directly manipulated (However,
  732. Xoperators like x..y can accomplish such tasks.)
  733. X
  734. XDuel types also follow the C semantics, but there are important
  735. Xdifferences. C types are checked  statically. In Duel, types are checked 
  736. Xwhen an operator is applied, e.g. (1,1.0)/2 return the integer zero and
  737. Xthe double 0.5, and (x,y).z returns x.z and y.z even if 
  738. Xx and y are of different types, as long as they both have a field z.
  739. XValues and types of symbols are looked up at run-time (using gdb's lookup
  740. Xrules), to allow dynamic scoping and types. This results in a parsing
  741. Xproblem, where operators must be well defined: (x)(y) can be parsed as
  742. Xeither a function call x(y) or a cast (x)y. To avoid this ambiguity, the
  743. Xcapital T keyword is required before a user defined type.
  744. XFor example,
  745. Xif value is a typedef, C's (value *) x is written in Duel as:
  746. X(T value *) x. Types that begin with a reserved keyword don't
  747. Xneed T, e.g. (struct value*) x and (long *[5]) y are accepted.
  748. X.SH OPERATORS
  749. X.sp
  750. X.I "x+y  x-y  x*y  x/y  x%y  x^y  x|y  x&y  x<<y  x>>y "
  751. X.br
  752. X.I "x>y  x<y  x>=y  x<=y  x==y  x!=y  x=y  x[y]"
  753. X.sp
  754. XThese binary operators follow their C semantics. For each value of x,
  755. Xthey are evaluated for every value of y, .e.g. (5,2)>(4,1)
  756. Xevaluates as 5>4, 5>1, 2>4, 2>1 returning  1, 1, 0, 1.
  757. XThe y values are re-evaluated for each new value of x, e.g. 
  758. Xi=4; (4,5)>i++ evaluates as 4>4 and 5>5.
  759. XBeware of multiple y values in assignment, e.g. x[..3]=(4,6,9) does not
  760. Xset x[0]=4, x[1]=6 and x[2]=9. It assigns 4, 6 and 9 to each element, having
  761. Xthe same effect as x[..3]=9. Use x[i:=..3]=(4,6,9)[[i]] to achieve the
  762. Xdesired effect.
  763. X.sp
  764. X.I "-x  ~x  &x  *x  !x  ++x  --x  x++  x--  sizeof(x)  (type)x"
  765. X.sp
  766. XThese unary operators follow their C semantics. They are applied
  767. Xto each value of x. The increment and decrement operators require an
  768. Xlvalue, so i:=0 ; i++ produces an error because i is an alias to 0, 
  769. Xan rvalue. Cast to user defined type must begin with T, e.g. (T val*) x.
  770. XSee variable declaration for more details.
  771. X.sp
  772. X.I "x&&y   x||y"
  773. X.sp
  774. XThese logical operators also follow their C semantics, but have non-intuitive
  775. Xresults for multi-valued x and y, e.g. (1,0,0) || (1,0) returns 1,1,0,1,0 --
  776. Xthe right hand-side (1,0) is returned for each left-hand side 0. It is best
  777. Xto use these operators only in single value expressions.
  778. X.sp
  779. X.I "x? y:z   if(x)y   if(x)y else z"
  780. X.sp
  781. XThese expressions return the values of y for each non-zero value
  782. Xreturned by x, and the values of z for each zero value returned by x, e.g. 
  783. Xif(x[..100]==0) y returns y for every x[i]==0, not if all x[i] are zero 
  784. X(if(&&/(x[..100]==0)) y  does that).
  785. XAlso, "if(x) y; else z" is illegal. Duel's semicolon is
  786. Xan expression separator, not a terminator.
  787. X.sp
  788. X.I "while(x)y   for(w;x;y)z"
  789. X.sp
  790. XThe while(x)y expression returns y as long as all values of x are non-zero.
  791. XThe for() expression is similar and both have the expected C semantics. For
  792. Xexample, "for(i=0 ; i<100 ; i++) x[i]" is the same as x[..100]. Unlike
  793. Xthe if() expression, while(x[..100]==0) continue to execute only if all 
  794. Xelements of x are zero, i.e. the condition is evaluated into a single value
  795. Xusing an implicit &&/x.
  796. X.sp
  797. X.BI "Variable declaration:  "  "type name [,name ...] ; ..."
  798. X.sp
  799. XExpressions can begin with variables declaration (but not initialization).
  800. XInternally, a declaration sets an alias to space allocated 
  801. Xin the target by calling malloc(), e.g. `int x' is the same as
  802. X"x:= *(int *) malloc(sizeof(int))". This is oblivious to the user.
  803. XThe allocated memory is not claimed when a variable is redeclared. 
  804. XDeclared variables addresses can be passed to functions and used in other 
  805. Xdata structures. The keyword `T' must precede user defined types (typedef),
  806. Xe.g. if val is a user defined type, The C code "val *p=(val*) x" becomes 
  807. X"T val *p; p=(T val *) x" in Duel.
  808. X.sp
  809. X.BI "Function calls:  "  "func(parm,...)"
  810. X.sp
  811. XFunction calls to the debugged program can be intermixed with Duel 
  812. Xcode. Multi-valued parameters are handled as with binary operators.
  813. XThe call value can have multiple values, e.g. (x,y)() calls x()
  814. Xand y(). Currently, struct/union parameters and return values are not
  815. Xsupported.
  816. X.sp
  817. X.I "x,y   x..y   ..x    x.."
  818. X.sp
  819. XThese operators produce multiple values for single value operands. 
  820. Xx,y returns x, then y. x..y returns the integers from x to y. 
  821. XWhen x>y the sequence is returned in descending order, i.e. 5..3 
  822. Xreturns 5, 4, 3. 
  823. XThe operator ..x is a shorthand for 0..x-1, e.g. ..3 returns 0, 1, 2. 
  824. XThe x.. operator is a shorthand for x..maxint. It returns increasing 
  825. Xinteger values starting at x indefinitely, and should be bounded 
  826. Xby [[n]] or @n operators.
  827. X`,' retains its precedence level in C. The precedence of `..'
  828. Xis above `<' and below arithmetic operators, so 0..n-1 and x==1..9 work
  829. Xas expected.
  830. X.sp
  831. X.I  "x<?y  x>?y  x>=?y  x<=?y  x!=?y  x==?y"
  832. X.sp
  833. XThese operators work like their C counterparts but return x if the comparison
  834. Xis true. If the comparison is false, the next (x,y) value is tried, forming
  835. Xthe basis of an implicit search.
  836. X.sp
  837. X.I  "(x)  {x}  x;y  x=>y"
  838. X.sp
  839. XBoth () and {} act as C parenthesis. 
  840. XThe curly braces set the returned symbolic value 
  841. Xas the actual value, e.g. if i=5 and x[5]=3, then
  842. Xx[i] produces the output "x[i] = 3", x[{i}] produces
  843. X"x[5] = 3" and {x[i]} produces just "3". 
  844. XThe semicolon is an operator. x;y evaluates x, ignoring the results, 
  845. Xthen evaluate and return y, e.g. (i:=1..3 ; i+5) sets i to 3 and return 8. 
  846. XThe x=>y operator evaluate and return y for each value of x, 
  847. Xe.g. (i:=1..3 => i+5) returns 6, 7 and 8. The value returned by x is
  848. Xalso stored implicitly in `_' which can be used in y, e.g. 1..5 => z[_][_]
  849. Xwill output z[1][1], z[2][2] etc. The symbolic value for _ is that of the
  850. Xleft side value, hence {_} is not needed.
  851. X.br
  852. XSemicolon has the lowest precedence, so it must be used inside () or {}
  853. Xfor compound expressions. The precedence of `=>' is just below `,'.
  854. XBeware that "if(a) x; else {y;} z" is illegal; a semicolon is not allowed
  855. Xbefore '}' or 'else' and must be inserted before z.
  856. X.sp
  857. X.IB "x->y   x.y"
  858. X.sp
  859. XThese expression work as in C for a symbol y. If y is an expression, it
  860. Xis evaluated under the scope of x. e.g. x.(a+b) is the same as x.a+x.b,
  861. Xif a and b are field of x (if they are not, they are looked up as local
  862. Xor global variables). x may return multiple values of different types,
  863. Xe.g. (u,v).a returns u.a and v.a, even if u and v are different structures.
  864. XAlso, the value of x is available as `_' inside y, e.g. x[..100].(if(a) _) 
  865. Xproduces x[i] for each x[i].a!=0. Nested x.y are allowed, e.g.
  866. Xu.(v.(a+b)) would lookup a and b first under v, then under u.
  867. X.sp
  868. X.BI Aliases: "  x:=y"
  869. X.sp
  870. XAliases store a reference to y in x. Any reference to x is 
  871. Xthen replaced by y. If y is a constant or an rvalue, its
  872. Xvalue is replaced for x. If y is an lvalue (e.g. a variable), a reference
  873. Xto same lvalue is returned. for example, x:=emp[5] ; x=9 assigns 9 to
  874. Xemp[5].
  875. XAliases retain their values across invocation of the "dl" command. An alias
  876. Xto a local variable will reference a stray address when the variable
  877. Xgoes out of scope.
  878. XThe special command "dl clear" delete all the aliases, and "dl alias"
  879. Xshow all current aliases. Symbols are looked up
  880. Xas aliases first, so an alias x will hide a local x.
  881. X.sp
  882. X.I x-->y
  883. X.sp
  884. XThe expansion operator x-->y expands a data structure x following the y links.
  885. XIt returns x, x->y, x->y->y, until a null is found. If x is null, no values 
  886. Xare produced. If y returns multiple values, they are stacked and each is 
  887. Xfurther expanded in a depth-first notion. For example, if r is the root of 
  888. Xa tree with children u->childs[..u->nchilds], then
  889. Xu-->(childs[..nchilds]) expands the whole tree. y is an arbitrary
  890. Xexpression, evaluated exactly like x->y (this includes `_'.)
  891. X.sp
  892. X.I x@y
  893. X.sp
  894. XThe expression x@y produces the values of x until x.y is non-zero, e.g.
  895. Xfor(i=0 ; x[i].code!= -1 && i<100 ; i++) x[i] can be written as 
  896. Xx[..100]@(code==-1). 
  897. XThe evaluation of x is stopped as soon as y evaluates to true. 
  898. Xx->y or x=>y are used to evaluate y when x is not a struct or a union. If
  899. Xy is a constant,(_==y) is used. e.g. s[0..]@0 produces the characters in 
  900. Xstring s up to but not including the terminating null.
  901. X.sp
  902. X.IB "#/x   &&/x   ||/x"
  903. X.sp
  904. XThese operator return a single "summary" value for all the values returned by
  905. Xx. #/x returns the number of values returned by x, e.g. 
  906. X#/(x[..100]>?0) counts the number of positive x[i]. &&/x returns 1 if all 
  907. Xthe values produced by x are non-zero, and ||/x returns 1 if any of x's values
  908. Xare non-zero. Like in C, the evaluation stops as soon as possible.
  909. XFor example, ||/(x[..100]==0) and &&/(x[..100]==0) check if one or all of
  910. Xx[i] are zero, respectively.
  911. X.sp
  912. X.IB "x#y  x[[y]]"
  913. X.sp
  914. XThe operator x#y produces the values of x and arranges for y to be an alias 
  915. Xfor the index of each value in x. It is commonly used with x-->y to produce
  916. Xthe element's index, e.g. head-->next->val#i=i  assigns each val field
  917. Xits element number in the list.
  918. X.br
  919. XThe selection operator x[[y]] produces the yth result of x. If y returns
  920. Xmultiple value, each select a value of x, e.g. (5,7,11,13)[3,0,2]
  921. Xreturns 13, 5 and 11 (13 is the 3rd element, 5 is the 0th element).
  922. XDon't use side effects in x, since its evaluation can be restarted depending 
  923. Xon y, e.g. after (x[0..i++])[[3,5]] the value of i is unpredictable.
  924. X.sp
  925. X.IB "frame(n)   frames_no   func.x"
  926. X.sp
  927. Xframe(n) for an integer n returns a reference to the nth frame
  928. Xon the stack (0 is the inner most function and frame(frames_no-1) is main()). 
  929. XFrame values can be compared to function pointers, 
  930. Xe.g. frame(3)==myfunc is true if the 4th frame is a call to myfunc, and in 
  931. Xscope resolution, e.g. frame(3).x return the local variable x of the 4th frame.
  932. Xframes_no is the number of active frames on the stack, e.g. 
  933. X(frames(..frames_no) ==? myfunc).x displays x for all active 
  934. Xinvocations of myfunc. As a special case, (frames(..frames_no)==?f)[[0]].x 
  935. Xcan be written as f.x (x can be an expression).
  936. X.sp
  937. X.SH BUGS
  938. XBoth `{}' and `;' are operators, not statements or expression separators;
  939. X"if(x) y; else {z;} u" is illegal; use "if(x) y else {z} ; u".
  940. X.br
  941. Xuser-defined types (typedef) must be preceded by the keyword T, e.g. if
  942. Xvalue is a user type, C's "(value *)x"  must be written as "(T value *)x".
  943. X.br
  944. XNot all C idiom are implemented, including: modified-assignment operators
  945. X(x+=y), switch, break, continue, do, goto, scopes, and function declarations.
  946. X.br
  947. XYou can not call a function with a struct/union parameter or return value.
  948. X.br
  949. XValues stored in registers are fetched as rvalues and can not be assigned to.
  950. X.br
  951. XAssignment to bit-fields is not supported.
  952. X.br
  953. XDeclared variables can not be initialized. Use assignment instead.
  954. X.br 
  955. Xgdb does not store function prototypes, so parameters are not checked.
  956. X
  957. XGdb itself is buggy, which shows up, especially in symbol tables and 
  958. Xcalling target functions. Before you report bug, try to do the closest 
  959. Xthing under gdb's "print". Send bug reports, fixes, improvements, etc. 
  960. Xto: mg@cs.princeton.edu.
  961. X.SH AUTHOR
  962. XDuel is public domain code -- no copy left or right. See the internals
  963. Xdocumentation for details on porting Duel and using its code.
  964. XDuel was designed and written by Michael Golan as part of a PhD thesis
  965. Xin the Computer Science Department of Princeton University.
  966. XI would like to thank my advisor, David R. Hanson, who helped in all phases
  967. Xof this project and to Matt Blaze for his support and useful insight.
  968. X.sp
  969. XDuel stands for Debugging U (might) Even Like, or Don't Use this Exotic 
  970. XLanguage. Judge for yourself!
  971. X
  972. X
  973. SHAR_EOF
  974. $TOUCH -am 0121191893 duel.1 &&
  975. chmod 0644 duel.1 ||
  976. echo "restore of duel.1 failed"
  977. set `wc -c duel.1`;Wc_c=$1
  978. if test "$Wc_c" != "22468"; then
  979.     echo original size 22468, current size $Wc_c
  980. fi
  981. # ============= internals.doc ==============
  982. echo "x - extracting internals.doc (Text)"
  983. sed 's/^X//' << 'SHAR_EOF' > internals.doc &&
  984. XDUEL 1.0 INTERNALS
  985. XThis documents some of the basics internal info, and might help porting
  986. Xduel. Incomplete and probably badly written. sorry.
  987. X
  988. XEntry points and modules
  989. X--------------------------
  990. Xduel_eval_and_parse is entry point into duel, in duel.c
  991. Xduel_parse in parse.y does all parsing
  992. Xduel_eval  in eval.y makes the evaluation 
  993. Xevalop.c contains low-level evaluation
  994. Xmisc.c   contains misc stuff
  995. Xtypes.c  type create/manage
  996. X
  997. Xstart reading the code from duel.c, then global.h, then eval.c.
  998. Xeval.c is hairy, especially the state-keeping code. The goto's are
  999. Xintentional, they convey control better than other constructs. 
  1000. X
  1001. XTypes
  1002. X------
  1003. XA relatively straight-forward system, if you have read code of real C
  1004. Xcompilers. A type is a "graph" with each node being a base type or
  1005. Xa composition of other types. see global.h and types.c
  1006. X
  1007. XValue system
  1008. X-------------
  1009. Xalso pretty simple, either an LVALUE, which have u.lvalue point to it,
  1010. Xor an RVALUE, so u.rval_type contains the actual value. There is also
  1011. Xa special BVALUE hack to hold lvalued bitfields, which is only useful
  1012. Xis someone implements modifying a bitfield. and there is an FVALUE, which
  1013. Xis just stored in u.rval_int but has the special value type (it was either
  1014. Xthis or add a new TYPE, i preferred a new value).
  1015. XNote the there is no "register" type support. You must read register variables
  1016. Xas rvalues (duelgdb.c does that). I don't think it is essential, since 
  1017. Xgdb can be used directly to modify such values (this might be a
  1018. Xproblem in watchpoint/cond.breaks however). Also cc -g don't usually keep
  1019. Xstuff in registers. We could add "SVALUE" for these.
  1020. XBitfields are a pain, but bvalue is really needed, eg for x[..100].bitfield=0
  1021. X
  1022. XMemory allocation
  1023. X-----------------
  1024. Xgo through duel_malloc/duel_free. 
  1025. XMemory is allocated only for (a) a new node, while parsing, (b) a value pushed
  1026. Xon stack for x-->y operator (c) duel aliases.
  1027. XIt is always safe to call duel_free_nodes  which free everything except
  1028. Xfor aliases. 
  1029. XMemory spill can occur in asynchronous interrupts (^C), but they at most
  1030. Xreflect items moved from one list to another. This isn't too bad.
  1031. X
  1032. XInterrupts
  1033. X----------
  1034. XDuel ignores the issues of interrupts, but is written so it can be
  1035. Xinterrupted at any time. Naturally, some memory could be lost if an
  1036. Xoperation is interrupted, since Duel does not setup critical sections.
  1037. XHowever, interrupts will no result in bad internal structures, so it is
  1038. Xsafe to call duel_free_nodes after an interrupt.
  1039. Xduelgdb.c implements exactly that - interrupts at all times, and cleanup
  1040. Xusing duel_free_nodes.
  1041. X
  1042. XParsing
  1043. X--------
  1044. Xyacc is pretty weak, especially when I tried complex ops like x\y#z 
  1045. X(as a single, 3 val op!). I have up on such things and the syntax is
  1046. Xpretty clean. Things to watch for are the semicolon nonsense,
  1047. Xespecially with optional-expressions (as in for(a;b;c);), the T hack
  1048. Xfor user types (only fix is to delay decision on (x)(y) till runtime
  1049. Xor make clearer rules (consider   something; (x)(y), do you parse x as a type 
  1050. Xand ignore the possible x:=printf in "something", etc), and the use of ","
  1051. Xregular op and nodes for function parameters (the parser knows only about
  1052. Xa single parameter, an exp!).
  1053. X
  1054. XSearch ops
  1055. X-----------
  1056. XStraight forward stacking in dfs_... in eval.c 
  1057. XNote things are put in reversed, so root-->(left,right) does what you 
  1058. Xexpect. Also linked-lists could be greatly optimized.
  1059. XThe functionality for ->> (BFS) is already in, all you need is to
  1060. Xmake the stack into a queue by pushing from the other side (really append)
  1061. X
  1062. XMulti-expressions
  1063. X--------------------
  1064. XAs far as I know, you could save root (in duel.h) and use it to evaluate
  1065. Xas often as needed (e.g for breakpoints/watchpoints), the internals
  1066. Xof the nodes hold all eval info. You must reset the expression 
  1067. Xwith eval_stop, if u dont eval it to the last value. Also make sure you
  1068. Xcleanup the dot stack. Aliases (in misc.c) could become scoped, of course.
  1069. X
  1070. XInterface to the debugger
  1071. X-------------------------
  1072. X
  1073. XWhat DUEL needs:
  1074. X1. A way to access the symbol table for variable names, types, etc.
  1075. X2. A way to access the value of a variable, both for read and writes.
  1076. X3. A way to call debuggee functions.
  1077. X4. A way to get locals of frame n
  1078. X5. misc functions, eg memory alloc, entery/exit code
  1079. X
  1080. XIn practice, you will probably take duelgdb.c and modify it until you
  1081. Xget the "right thing" for your debugger.
  1082. XNOTE: duelgdb.c was written from scratch and has *no* GNU code in it.
  1083. X
  1084. XThe most complex issue is types - you must pass names in a tvalue,
  1085. Xwhich include a tctype (the C reminds one of a "C" type, not just 'type'
  1086. Xwhich is ambiguous). The code to convert gdb types into duel types is
  1087. Xtypical. Watch out for recursive struct pointers (the hash table handles
  1088. Xthese problems), and for partial types, e.g. pointer to struct which
  1089. Xcontains no fields (size zero!).
  1090. X
  1091. XYou can return a BVALUE an LVALUE (preferred) or an RVALUE for a name 
  1092. Xlookup. use RVALUE for names found in registers, and return the actual
  1093. Xvalue. 
  1094. X
  1095. Xif a frame number is given for symbol lookup, only local variables 
  1096. Xallocated in that frame should be returned. (else return none. don't
  1097. Xreturn a global if it exist with the same name, this will make the dot
  1098. Xstack compute things wrong). 
  1099. X
  1100. XNode that this doesnt help with scoping problems (for duel)- e.g. 
  1101. Xyou can't do myfunc.x if x is a static variable in myfunc. There needs to
  1102. Xbe a more complex & general way in the language to specify this (i.e.
  1103. Xspecify a source location in which the variable is visible, AND a frame
  1104. Xto use if the value is kept on a frame)  frame(n).(scope(file,line).x)?
  1105. X
  1106. SHAR_EOF
  1107. $TOUCH -am 0115021793 internals.doc &&
  1108. chmod 0644 internals.doc ||
  1109. echo "restore of internals.doc failed"
  1110. set `wc -c internals.doc`;Wc_c=$1
  1111. if test "$Wc_c" != "5550"; then
  1112.     echo original size 5550, current size $Wc_c
  1113. fi
  1114. # ============= wishlist.doc ==============
  1115. echo "x - extracting wishlist.doc (Text)"
  1116. sed 's/^X//' << 'SHAR_EOF' > wishlist.doc &&
  1117. X += -= etc operators
  1118. X initialize variables e.g. int x=0 , maybe even scopes 
  1119. X +/ */ &/ |/ ^/   ==/ !=/ </ >/ <=/ >=/
  1120. X src(location) as scope
  1121. X istype(type,x)  to check type of x
  1122. X ?x to check for x in current scope
  1123. X conditional break points, watchpoints
  1124. X better type checking of structs.
  1125. X bitfield assignment
  1126. X better builtin commands, help
  1127. X output formatting, duel/xodus, more general out(v)
  1128. X duel macros/functions
  1129. X \x and \\x
  1130. X check array bounds
  1131. X x->>y  x->-y x>--y
  1132. X check cycles in --> expansion
  1133. X  ..:+ ..:-
  1134. X print types, do so better
  1135. X
  1136. X
  1137. XChecking for cycles in --> expansion
  1138. X------------------------------------
  1139. XOne can easily add code to handle head-->(next!=?head), as well as
  1140. Xhead-->(next!=?_). If you don't know what these do, you should RTFM again :-)
  1141. X
  1142. XYou can also keep all pointers that have been expanded already,
  1143. Xhence detecting any kind of cycle. However, what to do in
  1144. Xsuch cases is debatable. Some users would like to see
  1145. Xcycles terminate expansion quietly, while others will want a fatal error
  1146. Xto be produced. This could be handled by an operator like x-->?y which
  1147. Xwould indicate that cycles are ok and expansion should terminate quietly,
  1148. Xwhile x-->y produce an error on cycles.
  1149. X
  1150. XIf you have a strong opinion on this subject, or a better idea, lemme know!
  1151. X
  1152. XOther expansions: x->>y x->-y x>--y
  1153. X------------------------------------
  1154. Xx-->y applies DFS (Depth First Search). Another useful expansion would be
  1155. XBFS (Breath First Search). It is simple to implement - y's values should
  1156. Xbe put on a queue instead of a stack, and the code in place has been written
  1157. Xwith this in mind (eval.c).
  1158. XOthers will probably want a post-order or in-order search instead of preorder
  1159. Xsearch as done by x-->y. I am not sure this is important enough to merit
  1160. Xnew operators, but ->- for inorder and >-- for post order are reserved.
  1161. XThese, too, should be easy to implement, but it is very unclear that the
  1162. Xadded complexity to the language is worth it. If you really need such
  1163. Xoperators, lemme know.
  1164. X
  1165. XIncrement count for x..y   (x..y:+z and x..y:-z)
  1166. X------------------------------------------------
  1167. XThe x..y operator could be extended to support an increment or decrement
  1168. Xvalue. This would allow 1..n to be written as 1..n:+1 so when n==0 it
  1169. Xwill not produce the surprising 1,0 results. 
  1170. XHowever, 0..10:+2 could also be written as (0..5)*2, so it is unclear
  1171. Xthat such operators are really needed (maybe just x..+y, x..-y to force
  1172. Xthe direction).
  1173. X
  1174. X
  1175. XDuel functions / print procedures
  1176. X-------------------------------------
  1177. Xthe command:  dl define x expr
  1178. Xwill define x to be duel procedure for expression expr.
  1179. Xx can then be used like an alias (indeed, it will probably be kept in
  1180. Xthe alias table with a special value). x evaluation returns multiple 
  1181. Xvalues. 
  1182. XThere is no need parameters, since emp.x would call "x" using the implicit
  1183. Xparameter "_" set as emp. the expression for x is essentially put into
  1184. Xthe code for the execution. Having no parameters (except implicit ones)
  1185. Xmake it easier to document, use etc.
  1186. X
  1187. XSuch functions (macros?) are most useful for output. e.g.
  1188. Xdl define empout  val_type,a, u.if(val_type==0) code*6,name else code,z
  1189. Xdl emp.empout
  1190. Xwill produce output for 
  1191. X  struct {
  1192. X   int val_type,code ;
  1193. X   char a;
  1194. X   union { char *name ; double z ; } u 
  1195. X   } emp ;
  1196. X
  1197. Xthe empout procedure can be defined just once, and used to output such
  1198. Xunions as needed.
  1199. X
  1200. XThe next step is to call such functions automatically for output and
  1201. Xfor expansion. We add syntax like  dl define out(type) expr
  1202. X
  1203. Xthen whenever an expression of the given type is to be printed, this
  1204. Xcode is evaluated instead, e.g.:
  1205. Xdl define out(struct emp) ...
  1206. Xdl emp       ## this calls the above out code for the output.
  1207. X
  1208. XWe can also expand expressions by calling the right function, e.g.
  1209. XThe operator "\" calls a function to expand a specific type:
  1210. Xdl define \(struct list *)  (_-->next)
  1211. Xdl if(\head#i == \head#j && i<j) \head[[i,j]]
  1212. X
  1213. Xinstead of writing this code (find non unique elements of linked list):
  1214. X   if(head-->next#i == head-->next#j && i<j) head-->next[[i,j]]
  1215. X
  1216. XBoth printing and expansion occurs automatically based on TYPE.
  1217. XIt is unclear if the an array is allowed to be expanded by a pointer
  1218. Xtype expansion or not (i.e. is \(int *) to expand "int x[40]").
  1219. Xthis might require an extension to types allowing \(int [n]) which matches
  1220. Xany int array and set n for the specific bound. Types could be extended
  1221. Xin a similar way, e.g. \(type **) _[0..]@0
  1222. Xwhich expands any array of pointers (e.g. argv).
  1223. XThis can quickly require scope-nesting for local aliases/variables.
  1224. X
  1225. XAs before, it is unclear what of these is useful. Unless people depends on
  1226. Xduel heavily, and write such "output/expansion" functions for the project,
  1227. Xthe features are useless (who is going to use this interactively?)
  1228. X
  1229. XRegular expressions for names. $xxx and `xxx`
  1230. X----------------------------------------------
  1231. Xthis allows things like emp.`value_*` to return all the value_something
  1232. Xfields. it is really useful with structs, especially if a grep-style hat (^)
  1233. Xis supported. Obviously extends to func.rexp, to show all locals, etc,
  1234. Xwhich will make it possible to write a  stack-trace display in duel.
  1235. X
  1236. Xexact semantics (e.g. what is matched and how) unclear.
  1237. SHAR_EOF
  1238. $TOUCH -am 0121191493 wishlist.doc &&
  1239. chmod 0644 wishlist.doc ||
  1240. echo "restore of wishlist.doc failed"
  1241. set `wc -c wishlist.doc`;Wc_c=$1
  1242. if test "$Wc_c" != "5186"; then
  1243.     echo original size 5186, current size $Wc_c
  1244. fi
  1245. echo "End of part 1, continue with part 2"
  1246. exit 0
  1247.