home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / alt / sources / 3070 < prev    next >
Encoding:
Text File  |  1993-01-23  |  49.3 KB  |  1,319 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 2/6
  5. Message-ID: <1993Jan22.034402.21027@csservices.Princeton.EDU>
  6. Sender: news@csservices.Princeton.EDU (USENET News System)
  7. Organization: Department of Computer Science, Princeton University
  8. Date: Fri, 22 Jan 1993 03:44:02 GMT
  9. Lines: 1308
  10.  
  11. Submitted-by: mg@cs.princeton.edu
  12. Archive-name: duel/part02
  13.  
  14. #!/bin/sh
  15. # This is part 02 of duel
  16. if touch 2>&1 | fgrep 'amc' > /dev/null
  17.  then TOUCH=touch
  18.  else TOUCH=true
  19. fi
  20. # ============= gnu-vs-duel.doc ==============
  21. echo "x - extracting gnu-vs-duel.doc (Text)"
  22. sed 's/^X//' << 'SHAR_EOF' > gnu-vs-duel.doc &&
  23. XGNU VS DUEL, or why DUEL is not part of the GNU project.
  24. X
  25. XDUEL IS PUBLIC DOMAIN SOFTWARE
  26. X
  27. XDUEL is public domain software. There is *no* copyright.
  28. XTherefor you may copy it, change a few lines, remove my name,
  29. Xclaim credit for it all and sell it. Feel free to do so! Of course, 
  30. XI'd rather see people who modify the code give me credit and the 
  31. Xcode for free. However, I encourage you, for the sake of society, 
  32. Xto use this code even if you can't give me credit for it (i.e. if 
  33. Xyour company won't allow my name to be kept, but you want to use the 
  34. Xcode to develop a new product, go ahead and delete my name!).
  35. X
  36. XDUEL is not under the "GNU Public License" (GPL). I disagree with 
  37. Xmany of the "GNU ideas", even though I like to see public domain 
  38. Xsoftware available. GPL software is not public domain nor "free" for 
  39. Xmany reasons. If you develop code and distribute it freely, I
  40. Xurge you not to apply the GPL restrictions to it. Keep it free! 
  41. X
  42. XBy making code "freely available", you loose almost all of your rights, 
  43. Xfor all practical purposes. I am unaware of a case where someone who used 
  44. Xfreely available source code in violation of the copyright notice
  45. Xhas been sued. (Since such a case has probably never made it to court, 
  46. Xthe legality of notices like "use this for anything but not commercially" 
  47. Xis unclear. Some lawyers believe such notices to be invalid. 
  48. XConsider "Use this freely unless you are a black male" to realize why.)
  49. XBesides, when you release free code but attach some "rules" to its use, 
  50. Xyou only prevent honest people from using the code. 
  51. X
  52. X
  53. XThe rest of this file discuss the GPL. You probably won't agree with many of 
  54. Xthe arguments, but even one of these is a good reason to avoid the GNU license.
  55. X
  56. X
  57. XTHE GNU LICENSE
  58. X
  59. XWhat is wrong with the GNU license?
  60. X
  61. X1) It seem to be unenforceable.
  62. X   Many lawyers claim it isn't. There isn't really a license (you don't sign
  63. X   anything nor negotiate), and the mention of the code as "free" means a 
  64. X   very weak, if any, copyright protection. Since copyright law  protects 
  65. X   the holder from monetary damages, and since the FSF doesn't want nor 
  66. X   intend to make any money, it seems that even a ruling in their favor
  67. X   won't mean much. Propagating the GPL seems like propagating FUD, the
  68. X   kind that the worst and lowest commercial companies sometimes use.
  69. X
  70. X2) It seem no one will ever try to enforce it.
  71. X   FSF don't have the money nor the will to try to enforce the GPL.
  72. X   I am unaware of anyone who violates it, but I am certain there are such
  73. X   cases. By not enforcing it, FSF most likely loose their ability to do so
  74. X   in the future, making the license useless. Even if they went to court
  75. X   and won, there is no way the judge would require anyone to surrender his
  76. X   source code. They can only demand money (the amount of which is unclear,
  77. X   since they didn't loose any). For that matter, I wonder if the GNU 
  78. X   software was even sent to the copyright office. If it haven't, they can't
  79. X   win any kind of case (ask a lawyer if you don't believe me. And don't
  80. X   bother to claim code you released is copyrighted at all if you didn't 
  81. X   file it with the copyright office).
  82. X
  83. X3) The license can be easily circumvented with your own smart license.
  84. X   By making your own special license, you could give people only "diff"
  85. X   files and ask them to apply it to original GNU code. The diff files
  86. X   being independent code, they can't give them aways unless you allow it.
  87. X   Under the same license you can also provide "installation" of this code,
  88. X   and provide them with a binary image as a service ... While clearly 
  89. X   against the intent of the GPL, it practically sell binaries only:
  90. X   "We here by agree that I sell you:"
  91. X     (a) a file of source changes, which you may use only ONCE
  92. X     to patch source code for GNU product x, and compile into
  93. X     a binary program to be used on a single machine. You must
  94. X     destroy the diff file and the patched gnu code immediately
  95. X     after it has been compiled.
  96. X     (b) a service of applying the diff file you acquired in (a) 
  97. X     to a publicly available GNU code of product x. I will give you 
  98. X    only the binary result from this service.
  99. X
  100. X   Lawyers could refine this, I am sure. For example, (a) might cost $100
  101. X   and (b) another $100. A total of $200 for the bin file only. You may 
  102. X   choose only (a), but then you must apply it on my premises, pay rent...
  103. X   This makes (a) and (b) independent, like the 'no purchase necessary' rules.
  104. X
  105. X4) The license hurts people who can not use this code.
  106. X   Many people won't use GNU products, let alone code, just to prevent
  107. X   legal problems. In some cases companies disallow use of such code.
  108. X   In many cases, all you really want is a few GNU functions which you
  109. X   have learned/used while developing GNU code yourself. Yet, you can't
  110. X   use them! You end up spending time re-implementing something you have
  111. X   on your disk already (example: GNU pattern matching code).
  112. X   DUEL provided me with a good example of this. While developing DUEL,
  113. X   I spend lots of time reading GDB code. Some of this code could be useful
  114. X   in a commercial package I am developing, but I can't use it. Morally,
  115. X   can I look at the code while I re-implement it? What if I use the same
  116. X   actual code, from memory? Did I infringe on the copyright? Do I have to
  117. X   go out of my way to implement it "differently"?
  118. X
  119. X5) The GNU project seems to be promoted by a small group of people for
  120. X   their own agenda. The same people use this power, knowledge and position
  121. X   to advance their own interests in a fight against security, private
  122. X   enterprise, patents, etc. By making your code GNUish, you are
  123. X   helping them to advance ALL of their causes. Make sure you understand
  124. X   what these causes are, before adding your implicit support.
  125. X   
  126. X6) GNU gives lawyers work!
  127. X   Amazingly, many companies spend time and money on lawyers concerning
  128. X   GNU and GNU-like "free" software. Lawyers are suspicious of any
  129. X   rules or contracts that aren't standard, especially if they accompany
  130. X   a "free" package. For example, in AT&T, you can purchase commercial
  131. X   software in 24 hours, but to get permission to use "free" tools like GNU
  132. X   the lawyers must check and verify the contract is "ok". This can 
  133. X   take months (I ain't joking!)
  134. X
  135. XIt seems the GNU project has outrun itself, and is now slowing down
  136. Xinnovation. By not allowing anyone to build upon it and still make 
  137. Xany money, the GNU project sets a minimal standard that any software 
  138. Xdeveloper must overcome, before developing improved software. As a 
  139. Xresult, while the GNU project has improved the minimal software standard 
  140. Xoverall, it has also reduced the development of new, better software. 
  141. XHad the GNU code been public domain, it could have been built upon by 
  142. Xsmall companies, to produce better software.
  143. X
  144. X
  145. XIF YOU WRITE "FREE PROGRAMS"
  146. X
  147. XI urge you to make your program public domain. Any honest person who
  148. Xuse you code will give you proper credit anyway. The less honest people
  149. Xwill use your code against your wishes either way. 
  150. X
  151. XIf you insist on making your program copyrighted, I suggest that you either:
  152. X
  153. X1. Allow people to grab some parts of your source code and use it as public 
  154. X   domain. In other words, allow people who hacked your code and got familiar
  155. X   with it to use a few of your functions in a big in-house project without 
  156. X   having to rewrite them from scratch (or illegally steal them!).
  157. X
  158. X2. Retain only the copyright notice. Demand that your copyright notice 
  159. X   be  kept in the sources, and/or in manual pages and binary code if it is
  160. X   distributed. This allows people to base commercial products on it,
  161. X   but not without giving you some fame or glory.
  162. X
  163. X3. Use the "artistic license" provided with Perl.
  164. X
  165. X
  166. X
  167. X
  168. SHAR_EOF
  169. $TOUCH -am 0121190893 gnu-vs-duel.doc &&
  170. chmod 0644 gnu-vs-duel.doc ||
  171. echo "restore of gnu-vs-duel.doc failed"
  172. set `wc -c gnu-vs-duel.doc`;Wc_c=$1
  173. if test "$Wc_c" != "7719"; then
  174.     echo original size 7719, current size $Wc_c
  175. fi
  176. # ============= duelgdb.c ==============
  177. echo "x - extracting duelgdb.c (Text)"
  178. sed 's/^X//' << 'SHAR_EOF' > duelgdb.c &&
  179. X/*   DUEL - A Very High Level Debugging Langauge.  */
  180. X/*   Public domain code                            */
  181. X/*   Written by Michael Golan mg@cs.princeton.edu  */
  182. X/*$Header: /tmp_mnt/n/fs/grad2/mg/duel/RCS/duelgdb.c,v 1.11 93/01/21 21:22:15 mg Exp $*/
  183. X
  184. X/* debugger dependent module, it contains all of duel's access to
  185. X * the outside world (debuggee, symbol table, etc)
  186. X */
  187. X
  188. X/*
  189. X * $Log:    duelgdb.c,v $
  190. X * Revision 1.11  93/01/21  21:22:15  mg
  191. X * *** empty log message ***
  192. X * 
  193. X * Revision 1.10  93/01/13  16:19:33  mg
  194. X * support mini symbol table lookup (malloc, printf on SUN didnt work)
  195. X * 
  196. X * Revision 1.9  93/01/12  21:30:04  mg
  197. X * cleanup and set for release
  198. X * 
  199. X * Revision 1.8  93/01/06  23:59:21  mg
  200. X * new memory alloc/release. moved target's malloc into duel code
  201. X * allow ^c to work, fixed help, fixed variable lookup for specific frame.
  202. X * 
  203. X * Revision 1.7  93/01/03  07:27:11  mg
  204. X * support function calls!
  205. X * 
  206. X * Revision 1.6  92/12/24  23:33:13  mg
  207. X * frames support
  208. X * 
  209. X * Revision 1.5  92/10/19  15:06:29  mg
  210. X * made lcc happy
  211. X * no svalues
  212. X * new registers support and way of getting vars.
  213. X * these are temporary changes, new frames supports soon
  214. X * 
  215. X * Revision 1.4  92/10/14  02:03:53  mg
  216. X * misc/gdb4.6/duel vars using malloc
  217. X * 
  218. X * Revision 1.3  92/09/16  11:06:22  mg
  219. X * a lot more functions: get typedef/tags, alloc debuggee mem. +cosmetics
  220. X * 
  221. X * Revision 1.2  92/09/15  05:37:28  mg
  222. X * fix enum size bug. added headers
  223. X * 
  224. X */
  225. X
  226. X
  227. X#include <stddef.h>   /* used for ptrdiff_t and size_t */
  228. X#include <stdio.h>
  229. X#include <string.h>
  230. X#include <assert.h>
  231. X
  232. X#include "defs.h"
  233. X#include "symtab.h"
  234. X#include "gdbtypes.h"
  235. X#include "gdbcore.h"
  236. X#include "frame.h"
  237. X#include "target.h"
  238. X#include "value.h"
  239. X#include "symfile.h"
  240. X#include "objfiles.h"
  241. X#include "gdbcmd.h"
  242. X#include "call-cmds.h"
  243. X
  244. X#include "duel/src/global.h"
  245. X#include "duel/src/proto.h"
  246. X
  247. X/* all duel memory allocation go thru here */
  248. X
  249. XFUNC void* duel_malloc(size_t size)
  250. X{
  251. X  void *p ;
  252. X  immediate_quit-- ;    /* disable ^C while xmalloc */
  253. X  p=xmalloc(size);      /* gdb's malloc, incl zero return chk */
  254. X  immediate_quit++ ;
  255. X  QUIT ;                /* check if ^C while xmalloc called */
  256. X  return p ;
  257. X}
  258. X
  259. XPROC duel_free(void *p)
  260. X{
  261. X  immediate_quit-- ;
  262. X  free(p);
  263. X  immediate_quit++ ;
  264. X  QUIT ;
  265. X}
  266. X
  267. X
  268. X/* fetch n bytes from the target at the given memory address.
  269. X * the address to fetch from is given by (from).
  270. X * the value is stored at the 'to' location, which points to space for
  271. X * n bytes in the debugger.
  272. X * if the address can not be accessed, false is returned (if all ok, ret true)
  273. X */
  274. X
  275. XFUNC bool duel_get_target_bytes(ttarget_ptr from,void *to,size_t n)
  276. X{
  277. X  return target_read_memory((CORE_ADDR)from,to,n)==0;
  278. X}
  279. X
  280. X/* store n bytes to the debuggee. reverse parms from above */
  281. XFUNC bool duel_put_target_bytes(ttarget_ptr to,void *from,size_t n)
  282. X{
  283. X   return target_write_memory((CORE_ADDR)to,from,n)==0;
  284. X}
  285. X
  286. X/* fetch the value of a bitfield of a given structure.
  287. X * struct_at - a pointer to the structure
  288. X * bitpos    - the position of the field, in bits (as given in the type)
  289. X * bitlen    - the length of the field in bits
  290. X * to        - pointer to uint  where value will be stored.
  291. X * tkind     - the type kind of the field (used to do sign extention if needed)
  292. X * note: I'm unaware of any compiler with bitfields that are not int/uint.
  293. X */
  294. X
  295. XFUNC bool duel_get_target_bitfield(ttarget_ptr struct_at,int bitpos,
  296. X                                    int bitlen,void *to,tctype_kind tkind)
  297. X{
  298. X  uint bits ;  
  299. X  duel_assert(tkind==CTK_INT || tkind==CTK_UINT);
  300. X  if(!duel_get_target_bytes(struct_at+bitpos/8,&bits,sizeof(bits))) 
  301. X      return FALSE;
  302. X
  303. X  /* now, move the field to the 'bottom' of bits, by shifting right */
  304. X  bitpos%=8 ;                   /* fix it to a bit offset inside the 'bits' */
  305. X#if BITS_BIG_ENDIAN             /* defined by gdb's src code */
  306. X  bits >>= (sizeof(bits)*8-bitpos-bitlen) ;
  307. X#else
  308. X  bits >>= bitpos ;
  309. X#endif  
  310. X
  311. X /* finally chop down 'bits' to only bitlen significant bits,
  312. X  * or sign-extend it if output field is 'int' and the sign is 1.
  313. X  * ~0 is all ones, shift it to have bitlen zeros. Complement to get 
  314. X  * a bitlen string of 1's in the low-order bits. Common ugly hacks.
  315. X  * Note: this code assume 2's complement
  316. X  */
  317. X
  318. X  if(tkind==CTK_INT && (bits & 1<<(bitlen-1))) /* int field, negative sign */
  319. X         bits|= ~0<<bitlen ;    /*sign extend */
  320. X  else   bits&= ~(~0<<bitlen) ; /* clear all bits above the sign bit */
  321. X  *(uint*) to= bits ;
  322. X
  323. X  return TRUE ;
  324. X}
  325. X
  326. XLFUNC struct type* duel_convert_type_to_gdb(tctype *ct);
  327. XLFUNC tctype* duel_convert_type_from_gdb(struct type *gv);
  328. X
  329. X/* convert gdb value into duel's. Used to fetch const, registers, func ret val
  330. X * and convert a symbol into a reference.
  331. X * otherwise, duel access target's memory directly.
  332. X */
  333. X
  334. XLPROC duel_convert_value_from_gdb(value gv, tvalue *dv)
  335. X{
  336. X  dv->ctype=duel_convert_type_from_gdb(VALUE_TYPE(gv));
  337. X  if(VALUE_LVAL(gv) == lval_memory) {
  338. X      dv->val_kind=VK_LVALUE ;
  339. X      dv->u.lvalue= (ttarget_ptr) VALUE_ADDRESS(gv) ; /*address of variable*/
  340. X  }
  341. X  else
  342. X  if(ctype_kind_scalar(dv->ctype) && (VALUE_LVAL(gv) == not_lval ||
  343. X     VALUE_LVAL(gv) == lval_register || 
  344. X     VALUE_LVAL(gv) == lval_reg_frame_relative )) {
  345. X      dv->val_kind=VK_RVALUE ;
  346. X      duel_bcopy(&dv->u,VALUE_CONTENTS_RAW(gv),dv->ctype->size);
  347. X  }
  348. X  else
  349. X  duel_fatal("unsupported value type returned by gdb");
  350. X}
  351. X
  352. X
  353. X/* helper function converts duel values to gdb's values. used only to make
  354. X * function calls to the target, so current support is weak.
  355. X * gdb thinks long=int=pointers, so we go along with that.
  356. X * To support arbitrary types like struct/union, we can probably fake it
  357. X * by making a gdb lvalue. but i am not sure how/what
  358. X */
  359. X
  360. XLFUNC value convert_duel_val_to_gdb_val(tvalue *v)
  361. X{
  362. X   value gv ; 
  363. X   if(v->val_kind!=VK_RVALUE) return 0 ; /* cant handle lvals */
  364. X   switch(v->ctype->type_kind) {
  365. X/* duel standardize func parms, so this code is not required. if this
  366. X * function is used for more than func parms, as its name implies, we will
  367. X * need to do better than this.
  368. X   case CTK_CHAR:   
  369. X     gv=value_from_longest(builtin_type_char,v->u.rval_char);          break;
  370. X   case CTK_UCHAR:  
  371. X     gv=value_from_longest(builtin_type_unsigned_char,v->u.rval_char); break;
  372. X   case CTK_USHORT: 
  373. X     gv=value_from_longest(builtin_type_unsigned_short,v->u.rval_ushort);break;
  374. X   case CTK_SHORT:  
  375. X     gv=value_from_longest(builtin_type_unsigned_short,v->u.rval_short);break;
  376. X*/
  377. X   case CTK_INT:    
  378. X     gv=value_from_longest(builtin_type_int, v->u.rval_int);            break;
  379. X   case CTK_UINT:   
  380. X     gv=value_from_longest(builtin_type_unsigned_int, v->u.rval_uint) ; break ;
  381. X   case CTK_LONG:   
  382. X     gv=value_from_longest(builtin_type_long, v->u.rval_long)         ; break ;
  383. X   case CTK_ULONG:  
  384. X     gv=value_from_longest(builtin_type_unsigned_long,v->u.rval_ulong); break ;
  385. X   case CTK_FLOAT:  
  386. X     gv=value_from_double(builtin_type_float, v->u.rval_float) ; break ;
  387. X   case CTK_DOUBLE: 
  388. X     gv=value_from_double(builtin_type_double, v->u.rval_double) ; break ;
  389. X   case CTK_PTR:    
  390. X     gv=value_from_longest(lookup_pointer_type(builtin_type_void),
  391. X                        (long) v->u.rval_ptr) ;break ;
  392. X   default: duel_assert(0);
  393. X   }
  394. X   return gv ;
  395. X}       
  396. X
  397. X/* make a function call to the target.
  398. X * this is the only case where we convert duel tvalue into gdb's values.
  399. X * gdb thinks long=int=pointers, so we go along with that.
  400. X */
  401. X
  402. XPROC duel_target_func_call(tvalue *func, tvalue *parms[],
  403. X                            int parms_no,tvalue *rval)
  404. X{
  405. X    value gfunc, grval, gparms[20] ;
  406. X    int i ;
  407. X    struct type *gftype ;
  408. X
  409. X    duel_assert(func->val_kind==VK_LVALUE);
  410. X    for(i=0 ; i<parms_no ; i++) {
  411. X        gparms[i]=convert_duel_val_to_gdb_val(parms[i]) ;
  412. X        if(gparms[i]==NULL)
  413. X            duel_op_error("unsupported func call parm type",0,parms[i],0);
  414. X    }
  415. X    gftype =duel_convert_type_to_gdb(func->ctype);
  416. X    if(!gftype) duel_op_error("unsupported func return parm type",0,func,0);
  417. X    gftype = lookup_pointer_type(gftype);
  418. X    if(!gftype)
  419. X            duel_op_error("unsupproted func return type",0,func,0);
  420. X    gfunc = value_from_longest(gftype,(LONGEST) func->u.lvalue);
  421. X    
  422. X    grval=call_function_by_hand(gfunc,parms_no,gparms);
  423. X    if(func->ctype->u.kid->type_kind==CTK_VOID) return ; /* no return val*/
  424. X    duel_convert_value_from_gdb(grval,rval);
  425. X}
  426. X
  427. X
  428. X
  429. X#define TYPE_HASH_SIZE 1024
  430. X#define type_hash_func(t) ( (((long)t&0xffff) + (((long)t>>16)&0xffff)) \
  431. X                             % TYPE_HASH_SIZE )
  432. Xstruct {
  433. X    struct type *t ;    /* gdb type ptr */
  434. X    tctype *ct ;        /* duel type ptr */
  435. X} duel_thash[TYPE_HASH_SIZE] ;
  436. X
  437. XLPROC duel_add_hash(struct type *t, tctype *ct)
  438. X{
  439. X    int start,i=type_hash_func(t);
  440. X    start=i ; 
  441. X    do {
  442. X        if(duel_thash[i].t==0) {
  443. X            duel_thash[i].t=t ;
  444. X            duel_thash[i].ct=ct ;
  445. X            return ;
  446. X        }
  447. X        if(duel_thash[i].t==t) {
  448. X            if(duel_thash[i].ct==ct) return ;
  449. X            duel_fatal("type hash table inconsistency ");
  450. X        }
  451. X        i= (i+1)%TYPE_HASH_SIZE ;
  452. X    } while(i!=start);
  453. X    duel_fatal("type hash table is full");
  454. X}
  455. X
  456. XLFUNC tctype* duel_find_hash(struct type *t)
  457. X{
  458. X    int start,i=type_hash_func(t);
  459. X    start=i ; 
  460. X    do {
  461. X        if(duel_thash[i].t==0) break ;
  462. X        if(duel_thash[i].t==t) return duel_thash[i].ct ;
  463. X        i= (i+1)%TYPE_HASH_SIZE ;
  464. X    } while(i!=start);
  465. X    return NULL ;
  466. X}
  467. X
  468. X/* a simple conversion back to gdb types, used only for target func calls */
  469. X/* this is a hack and based on the assumption that the type was first
  470. X * converted FROM gdb to duel. (turn out to be false for int func from
  471. X * minimal symbols, so we do this as a special case.)
  472. X */
  473. XLFUNC struct type* duel_convert_type_to_gdb(tctype *ct)
  474. X{
  475. X   int i ;
  476. X   for(i=0 ; i<TYPE_HASH_SIZE ; i++) 
  477. X       if(duel_thash[i].ct==ct) return duel_thash[i].t ;
  478. X
  479. X   if(ct->type_kind==CTK_FUNC && ct->u.kid->type_kind==CTK_INT) 
  480. X      return  lookup_function_type (builtin_type_int);
  481. X   return NULL ;
  482. X}
  483. X
  484. X  /* given a gdb type t, return an equivalent duel type */
  485. X
  486. XLFUNC tctype* duel_convert_type_from_gdb(struct type *t)
  487. X{
  488. X  tctype *ct=duel_find_hash(t);
  489. X  if(ct) return ct ;
  490. X
  491. X  switch (TYPE_CODE (t)) {
  492. X   case TYPE_CODE_INT:
  493. X      if(     strcmp(TYPE_NAME(t),"char")==0)  ct=ctype_char ;
  494. X      else if(strcmp(TYPE_NAME(t),"short")==0) ct=ctype_short ;
  495. X      else if(strcmp(TYPE_NAME(t),"int")==0)   ct=ctype_int ;
  496. X      else if(strcmp(TYPE_NAME(t),"long")==0)  ct=ctype_long ;
  497. X      else if(strcmp(TYPE_NAME(t),"unsigned char")==0)  ct=ctype_uchar ;
  498. X      else if(strcmp(TYPE_NAME(t),"unsigned short")==0) ct=ctype_ushort ;
  499. X      else if(strcmp(TYPE_NAME(t),"unsigned int")==0)   ct=ctype_uint ;
  500. X      else if(strcmp(TYPE_NAME(t),"unsigned long")==0)  ct=ctype_ulong ;
  501. X      break;
  502. X   case TYPE_CODE_FLT:
  503. X      if(strcmp(TYPE_NAME(t),"float")==0)  ct=ctype_float ;
  504. X      else
  505. X      if(strcmp(TYPE_NAME(t),"double")==0) ct=ctype_double ;
  506. X      break;
  507. X   case TYPE_CODE_VOID:
  508. X      if(strcmp(TYPE_NAME(t),"void")==0) ct=ctype_void ;
  509. X      break;
  510. X   case TYPE_CODE_PTR:
  511. X      {  
  512. X       /* the pointer might get defined when converting the target, so
  513. X        * check the hashing again (reason: self-referencing structs)
  514. X        */
  515. X        tctype *target=duel_convert_type_from_gdb(TYPE_TARGET_TYPE(t));
  516. X        if((ct=duel_find_hash(t))==NULL) ct=duel_mkctype_ptr(target);
  517. X      }
  518. X      break ;
  519. X   case TYPE_CODE_FUNC:
  520. X      ct=duel_mkctype_func(duel_convert_type_from_gdb(TYPE_TARGET_TYPE(t)));
  521. X      break ;
  522. X   case TYPE_CODE_ARRAY:
  523. X      { int n=TYPE_LENGTH(TYPE_TARGET_TYPE(t));
  524. X        if(n!=0) n=TYPE_LENGTH(t)/n;
  525. X        ct=duel_mkctype_array(
  526. X               duel_convert_type_from_gdb(TYPE_TARGET_TYPE(t)),n);
  527. X      }
  528. X      break;
  529. X   case TYPE_CODE_STRUCT:
  530. X   case TYPE_CODE_UNION:
  531. X      { int i,n=TYPE_NFIELDS(t);
  532. X        char *name=TYPE_NAME(t);
  533. X        if(strncmp(name,"struct ",7)==0) name+=7 ;
  534. X        if(strncmp(name,"union ",6)==0) name+=6 ;
  535. X        ct=duel_mkctype_struct(name,TYPE_LENGTH(t),n,
  536. X                        TYPE_CODE(t)==TYPE_CODE_UNION);
  537. X        duel_add_hash(t,ct);  /* so a pointer to myself is recognized */
  538. X        for(i=0 ; i<n ; i++) 
  539. X           duel_mkctype_struct_field(ct,i,TYPE_FIELD_NAME(t,i),
  540. X                TYPE_FIELD_BITPOS(t,i), TYPE_FIELD_BITSIZE(t,i),
  541. X                duel_convert_type_from_gdb(TYPE_FIELD_TYPE(t,i)));
  542. X      }
  543. X   break ;
  544. X   case TYPE_CODE_ENUM:
  545. X        /* TYPE_LENGTH(t) tell how big it is. I assume signed integral types.
  546. X         * it is unclear if gdb supports unsigned enums and how
  547. X         * (e.g. enum { x=0,y=250 } stored in uchar 
  548. X         * FIELDS contain the tags, BITPOS is the assigned value.
  549. X         */
  550. X      { int i,n=TYPE_NFIELDS(t),len=TYPE_LENGTH(t);
  551. X        tctype_kind k ;
  552. X        /* select 'real' stored type. note order important if short==int.
  553. X         * long is not allowed as far as I know ANSI C (enums are conv. to int)
  554. X         */
  555. X        if(len==sizeof(int))        k=CTK_INT ;
  556. X        else if(len==sizeof(short)) k=CTK_SHORT ;
  557. X        else if(len==sizeof(char))  k=CTK_CHAR ;
  558. X        else duel_assert(0);    
  559. X           
  560. X        ct=duel_mkctype_enum(TYPE_NAME(t),k,len,n);
  561. X        for(i=0 ; i<n ; i++) 
  562. X           duel_mkctype_enumerator(ct,i,TYPE_FIELD_NAME(t,i),
  563. X                TYPE_FIELD_BITPOS(t,i));
  564. X      }
  565. X   break ;
  566. X   case TYPE_CODE_UNDEF:
  567. X      break;
  568. X  }
  569. X  if(ct==0) duel_fatal("unsupported C type returned by gdb");
  570. X  duel_add_hash(t,ct);
  571. X  return ct ;
  572. X}
  573. X
  574. X/* optimize frame access so frame(100..0) doesnt start the search from 0
  575. X * everytime. similar to selected_frame etc, but we dont want to mess up
  576. X * gdb's own frame setup (for up/down/print etc)
  577. X * this optimization should have been part of gdb, not here. 
  578. X * ie. duel_select_frame should be a simple fast gdb call.
  579. X * we dont optimze going to frame 7 from frame 5 etc, this isn't typical.
  580. X * set last/tot frames to -2 to assure recomputeations (-1 is not good enuf)
  581. X */
  582. X
  583. Xstatic FRAME last_frame ;       /* last frame pointer we used */
  584. Xstatic int  last_frame_no ;     /* last frame number we used */
  585. Xstatic int  tot_frames_no ;     /* tot number of frames */
  586. X
  587. XLFUNC FRAME duel_select_frame(int frame_no) 
  588. X{
  589. X    FRAME frame ;
  590. X    if(last_frame_no==frame_no)   frame=last_frame ;
  591. X    else
  592. X    if(last_frame_no==frame_no-1) frame=get_prev_frame(last_frame);
  593. X    else
  594. X    if(last_frame_no==frame_no+1) frame=get_next_frame(last_frame);
  595. X    else {
  596. X        int count=frame_no ;
  597. X        frame=get_current_frame();
  598. X        while (frame && --count >= 0) 
  599. X            frame = get_prev_frame (frame);
  600. X    }
  601. X    duel_assert(frame); /* callee should have checked frames no*/
  602. X    last_frame = frame ; 
  603. X    last_frame_no = frame_no ;
  604. X    return frame ;
  605. X}
  606. X
  607. XFUNC bool duel_get_target_variable(char *name, int frame_no, tvalue *v)
  608. X{
  609. X  struct symbol *sym;
  610. X  FRAME frame ;
  611. X  struct block *blk ;
  612. X  int len ;
  613. X  value gv ;                    /* gdb value */
  614. X
  615. X  if(frame_no== -1) {           /* use the user selected frame and block */
  616. X      frame = selected_frame ;  
  617. X      blk = get_selected_block() ;     
  618. X  }
  619. X  else {
  620. X      frame=duel_select_frame(frame_no) ;
  621. X      blk = get_frame_block(frame);
  622. X  }
  623. X  sym = lookup_symbol (name, blk, VAR_NAMESPACE,0,0);
  624. X  if(!sym && frame_no== -1) {    /* look up the symbol that has no debug info*/
  625. X     struct minimal_symbol *m ;
  626. X     m=lookup_minimal_symbol (name,NULL); /* find printf, malloc etc */
  627. X     if(m == NULL) return FALSE ;
  628. X     v->val_kind=VK_LVALUE ;
  629. X     v->u.lvalue=(ttarget_ptr) m->address ;
  630. X    /* guess it is an int if it is a data type, an int func if text */
  631. X     if(m->type == mst_data || m->type == mst_bss) v->ctype=ctype_int ;
  632. X     else
  633. X     if(m->type == mst_text) v->ctype=duel_mkctype_func(ctype_int);
  634. X     else return FALSE ;     
  635. X     return TRUE ;     
  636. X  }
  637. X  if(SYMBOL_CLASS(sym)==LOC_TYPEDEF) return FALSE ;
  638. X  /* if frame specificed, allow only local variables to be found */
  639. X  if(frame_no!= -1 && (SYMBOL_CLASS(sym)==LOC_STATIC ||
  640. X   SYMBOL_CLASS(sym)==LOC_BLOCK || SYMBOL_CLASS(sym)==LOC_CONST)) return FALSE;
  641. X  gv=read_var_value(sym,frame);
  642. X  if(gv==0) return FALSE ; /* frame not found or illegal */
  643. X  duel_convert_value_from_gdb(gv,v);
  644. X  return TRUE ;         
  645. X}
  646. X
  647. X
  648. X/* return the total number of frames on the stack */
  649. X
  650. XFUNC int duel_get_frames_number(void)
  651. X{
  652. X    int n ;
  653. X    FRAME frame ;
  654. X    if(tot_frames_no!= -2) return tot_frames_no ;
  655. X    frame=get_current_frame();
  656. X    for(n=0 ; frame ; n++)
  657. X        frame = get_prev_frame (frame);
  658. X    return tot_frames_no=n ;
  659. X}
  660. X
  661. XFUNC ttarget_ptr duel_get_function_for_frame(int frame_no)
  662. X{
  663. X   FRAME frame=duel_select_frame(frame_no);
  664. X   struct symbol *sym = get_frame_function(frame);
  665. X   value val = read_var_value(sym,frame);
  666. X   duel_assert(val!=0 && VALUE_LVAL(val) == lval_memory);
  667. X
  668. X   return (ttarget_ptr) VALUE_ADDRESS(val) ;
  669. X}
  670. X
  671. XFUNC tctype* duel_get_target_typedef(char *name)
  672. X{
  673. X  struct symbol *sym;
  674. X  sym = lookup_symbol (name, get_selected_block(), VAR_NAMESPACE,0,0);
  675. X  if(!sym || SYMBOL_CLASS(sym)!=LOC_TYPEDEF) {
  676. X      sym = lookup_symbol (name, 0, VAR_NAMESPACE, 0,0);
  677. X      if(!sym || SYMBOL_CLASS(sym)!=LOC_TYPEDEF) return NULL ;
  678. X  }
  679. X  return duel_convert_type_from_gdb(SYMBOL_TYPE(sym));
  680. X}
  681. X
  682. XFUNC tctype* duel_get_target_struct_tag(char *name)
  683. X{
  684. X  struct symbol *sym;
  685. X  sym = lookup_symbol (name, get_selected_block(), STRUCT_NAMESPACE,0,0);
  686. X  if(!sym || TYPE_CODE(SYMBOL_TYPE(sym))!=TYPE_CODE_STRUCT) {
  687. X      sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0,0);
  688. X      if(!sym || TYPE_CODE(SYMBOL_TYPE(sym))!=TYPE_CODE_STRUCT) return NULL ;
  689. X  }
  690. X  return duel_convert_type_from_gdb(SYMBOL_TYPE(sym));
  691. X}
  692. X
  693. XFUNC tctype* duel_get_target_union_tag(char *name)
  694. X{
  695. X  struct symbol *sym;
  696. X  sym = lookup_symbol (name, get_selected_block(), STRUCT_NAMESPACE,0,0);
  697. X  if(!sym || TYPE_CODE(SYMBOL_TYPE(sym))!=TYPE_CODE_UNION) {
  698. X      sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0,0);
  699. X      if(!sym || TYPE_CODE(SYMBOL_TYPE(sym))!=TYPE_CODE_UNION) return NULL ;
  700. X  }
  701. X  return duel_convert_type_from_gdb(SYMBOL_TYPE(sym));
  702. X}
  703. X
  704. XFUNC tctype* duel_get_target_enum_tag(char *name)
  705. X{
  706. X  struct symbol *sym;
  707. X  sym = lookup_symbol (name, get_selected_block(), STRUCT_NAMESPACE,0,0);
  708. X  if(!sym || TYPE_CODE(SYMBOL_TYPE(sym))!=TYPE_CODE_ENUM) {
  709. X      sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0,0);
  710. X      if(!sym || TYPE_CODE(SYMBOL_TYPE(sym))!=TYPE_CODE_ENUM) return NULL ;
  711. X  }
  712. X  return duel_convert_type_from_gdb(SYMBOL_TYPE(sym));
  713. X}
  714. X
  715. X/* a short command summary for those who can't manage with gdb help command*/
  716. X
  717. XLPROC gdb_help(void)
  718. X{       printf("\
  719. XNO NONSENSE SUMMARY OF GDB COMMANDS for DUEL users\n\
  720. X\n\
  721. XTo COMPILE:  cc -g myprog.c -o myprog. \n\
  722. XTo RUN: gdb myprog  <ret> (gdb) b main <ret>  (gdb) r arg1 arg2 <ret>\n");
  723. X        printf("\n\
  724. XBREAKPOINTS                                LISTING\n\
  725. Xb 59         # in line 59                  l 25        # line 25..<ret> more\n\
  726. Xb qsort      # in function qsort           l xsort     # func xsort\n\
  727. Xb eval.c:33  # in file eval.c, line 33     l eval.c:12 # file eval.c line 12\n\
  728. Xd 3          # delete breakpoint 3.        info break  # show breakpoints\n");
  729. X        printf("\n\
  730. XTypical: 'l func' to list func, <ret> to show more, 'b 59' to set break \n\
  731. Xat line 59. When breakpoint occurs, gdb gives its number. 'd 3' delete\n\
  732. Xbreakpoint number 3.\n");
  733. X        printf("\n\
  734. XSTEPPING                         DISPLAY             \n\
  735. Xs   # trace into functions       bt        # show stack \n\
  736. Xn   # step over functions        p exp     # evaluate and print exp\n\
  737. Xc   # continue execution         pt exp    # print exp's type\n\
  738. Xr   # restart program (run)      dl exp    # Duel\n\
  739. Xn 5 # repeat n 5 times (s too)   up/down   # move up/down the frames stack\n");
  740. X}
  741. X
  742. X/* 
  743. X * entry point from gdb.
  744. X * produce help in gdb's format, or call duel enter point.
  745. X * we allow ^c to quit immidiatly, and setup memory release cleanup.
  746. X */
  747. X
  748. Xvoid duel_command(char *exp,int from_tty)
  749. X{
  750. X  last_frame_no = -2 ;  /* recompute frame location on each dl command */
  751. X  tot_frames_no = -2 ;
  752. X
  753. X  if(exp && strcmp(exp,"gdb")==0) gdb_help();
  754. X  else {
  755. X      make_cleanup(duel_cleanup);       /* clear all allocated mem */
  756. X      immediate_quit++ ;
  757. X      duel_parse_and_eval(exp);
  758. X      immediate_quit-- ;
  759. X      if(!exp || strcmp(exp,"help")==0 || strcmp(exp,"?")==0) 
  760. X          printf("Try \"dl gdb\" for a summary of useful gdb commands\n");
  761. X  }
  762. X}
  763. X
  764. X_initialize_duel()
  765. X{
  766. X  add_com ("duel", class_vars, duel_command,
  767. X"Evaluate Duel expressions. Duel is a very high level debugging langauge.\n\
  768. X\"dl help\" for help. \"dl gdb\" for summary of GDB commands\n");
  769. X  add_com_alias ("dl", "duel", class_vars, 1);
  770. X
  771. X}
  772. SHAR_EOF
  773. $TOUCH -am 0121212893 duelgdb.c &&
  774. chmod 0644 duelgdb.c ||
  775. echo "restore of duelgdb.c failed"
  776. set `wc -c duelgdb.c`;Wc_c=$1
  777. if test "$Wc_c" != "20549"; then
  778.     echo original size 20549, current size $Wc_c
  779. fi
  780. # ============= src/Makefile ==============
  781. if test ! -d 'src'; then
  782.     echo "x - creating directory src"
  783.     mkdir 'src'
  784. fi
  785. echo "x - extracting src/Makefile (Text)"
  786. sed 's/^X//' << 'SHAR_EOF' > src/Makefile &&
  787. X#
  788. X# generic makefile for Duel 1.00.0
  789. X# nothing fancy is required: yacc/bison of parse.y, compile all other modules,
  790. X# and put all of the OBJ= modules into duel.a library.
  791. X# gdb is compiled with its own makefile (you add duel.a and duelgdb.c)
  792. X# selfduel, for testing, is compiled and linked with duel.a
  793. X
  794. X# NOTE:
  795. X# for SUN (sparc) you must use gcc or another ANSI compiler. cc doesnt
  796. X# support prototypes! 
  797. X# Also for SUN, yacc inserts a declaration of malloc() at the first line
  798. X# of y.tab.c, which is WRONG (return char*). just delete it.
  799. X
  800. XCFLAGS= -g
  801. XCC= cc             # won't work on SUN. need ANSI C prototypes support.
  802. X#CC= gcc 
  803. X#CC = gcc -U__GNU__    # if you get __eprintf undefined (assert.h problem)
  804. XYACC=yacc
  805. X
  806. XOBJ= duel.o types.o eval.o misc.o y.tab.o error.o evalops.o print.o 
  807. X
  808. Xall:    duel.a duelself
  809. X
  810. Xduelself: duel.a duelself.o
  811. X    $(CC) duelself.o duel.a -o duelself
  812. X
  813. Xduel.a:  $(OBJ)
  814. X    ar ru duel.a $(OBJ)
  815. X    ranlib duel.a
  816. X
  817. Xy.tab.c: parse.y
  818. X    $(YACC) parse.y
  819. Xclean:
  820. X    rm -f $(OBJ) y.tab.c duelself.o
  821. X
  822. SHAR_EOF
  823. $TOUCH -am 0121204093 src/Makefile &&
  824. chmod 0644 src/Makefile ||
  825. echo "restore of src/Makefile failed"
  826. set `wc -c src/Makefile`;Wc_c=$1
  827. if test "$Wc_c" != "993"; then
  828.     echo original size 993, current size $Wc_c
  829. fi
  830. # ============= src/patchlevel.h ==============
  831. echo "x - extracting src/patchlevel.h (Text)"
  832. sed 's/^X//' << 'SHAR_EOF' > src/patchlevel.h &&
  833. X#define PATCHLEVEL 0
  834. SHAR_EOF
  835. $TOUCH -am 0113165193 src/patchlevel.h &&
  836. chmod 0644 src/patchlevel.h ||
  837. echo "restore of src/patchlevel.h failed"
  838. set `wc -c src/patchlevel.h`;Wc_c=$1
  839. if test "$Wc_c" != "21"; then
  840.     echo original size 21, current size $Wc_c
  841. fi
  842. # ============= src/duel.h ==============
  843. echo "x - extracting src/duel.h (Text)"
  844. sed 's/^X//' << 'SHAR_EOF' > src/duel.h &&
  845. X/*   DUEL - A Very High Level Debugging Langauge.  */
  846. X/*   Public domain code                       */
  847. X/*   Written by Michael Golan mg@cs.princeton.edu  */
  848. X/*$Header: /tmp_mnt/n/fs/grad2/mg/duel/RCS/duel.h,v 1.4 93/01/12 21:28:47 mg Exp $*/
  849. X
  850. X/* duel.h - include file to be used with all duel source code.
  851. X * it defines important global constants & data types, as well as some
  852. X * global variables. prototypes should go in the duelprot.h file
  853. X */
  854. X
  855. X
  856. X/* common duel include files. I dunno why people don't like recursive
  857. X * includes, as long as it is consistent. Note only one level of recursion.
  858. X * the debugger module itself dont use this file, instead it includes what
  859. X * it needs directly.
  860. X * as for including "everything", unless one redefine some standard lib func,
  861. X * I feel safer including most standard lib files. It seems to prevent errors
  862. X * even if it garble the name space a bit.
  863. X */
  864. X
  865. X#include <stdio.h>
  866. X#include <stdlib.h>
  867. X#include <stddef.h>
  868. X#include <string.h>
  869. X#include <assert.h>
  870. X#include <ctype.h>
  871. X#include <limits.h>
  872. X#include <math.h>
  873. X/* global data and types */
  874. X
  875. X#include "global.h"
  876. X
  877. X/* prototypes for all global functions follows */
  878. X
  879. X#include "proto.h"
  880. SHAR_EOF
  881. $TOUCH -am 0113165193 src/duel.h &&
  882. chmod 0644 src/duel.h ||
  883. echo "restore of src/duel.h failed"
  884. set `wc -c src/duel.h`;Wc_c=$1
  885. if test "$Wc_c" != "1162"; then
  886.     echo original size 1162, current size $Wc_c
  887. fi
  888. # ============= src/global.h ==============
  889. echo "x - extracting src/global.h (Text)"
  890. sed 's/^X//' << 'SHAR_EOF' > src/global.h &&
  891. X/*   DUEL - A Very High Level Debugging Langauge.  */
  892. X/*   Public domain code                       */
  893. X/*   Written by Michael Golan mg@cs.princeton.edu  */
  894. X/*$Header: /tmp_mnt/n/fs/grad2/mg/duel/RCS/global.h,v 1.9 93/01/12 21:52:11 mg Exp $*/
  895. X
  896. X/* this include file contains global definitions for duel. All global info
  897. X * is shared thru this single file.
  898. X */
  899. X
  900. X/*
  901. X * $Log:    global.h,v $
  902. X * Revision 1.9  93/01/12  21:52:11  mg
  903. X * cleanup and set for release
  904. X * 
  905. X * Revision 1.8  93/01/07  00:10:53  mg
  906. X * macros for func ptr auto-convert
  907. X * 
  908. X * Revision 1.7  93/01/03  07:30:23  mg
  909. X * *** empty log message ***
  910. X * 
  911. X * Revision 1.6  92/12/24  23:49:25  mg
  912. X * *** empty log message ***
  913. X * 
  914. X * Revision 1.5  92/10/19  15:07:58  mg
  915. X * fvalue added (not ready yet), svalues dropped
  916. X * 
  917. X * Revision 1.4  92/10/14  02:05:37  mg
  918. X * misc
  919. X * 
  920. X * Revision 1.3  92/09/16  11:11:54  mg
  921. X * add builtin ctype_charptr
  922. X * 
  923. X * Revision 1.2  92/09/15  05:47:49  mg
  924. X * some ops added
  925. X * 
  926. X */
  927. X
  928. X
  929. X/* The following definitions are common programming tricks that I use
  930. X * in every program I write. I hope they are obvious. the FUNC/PROC
  931. X * constants are useful mainly when editing (to find a function def.)
  932. X * or when grep'ing on source files. DEF is set to "extern" by default,
  933. X * allowing declaration and definition of globals in one source. only
  934. X * duel.c should have #define DEF before including duel.h
  935. X */
  936. X
  937. X#define FUNC
  938. X#define PROC void
  939. X#define LPROC static void
  940. X#define LFUNC static
  941. X
  942. X#ifndef DEF
  943. X#define DEF extern            /* declare only, 'int x' become 'extern int x'*/
  944. X#endif
  945. X
  946. X/* use simpler names for unsigned types, very common, I hope */
  947. X
  948. Xtypedef unsigned int uint ;
  949. Xtypedef unsigned char uchar ;
  950. Xtypedef unsigned short ushort ;
  951. Xtypedef unsigned long ulong ;
  952. X
  953. Xtypedef int bool ;            /* suppose to be just 0,1 */
  954. X#define FALSE 0
  955. X#define TRUE  1
  956. X
  957. X /* these should be inline functions, they replace common lib func which
  958. X  * change from system to system.
  959. X  * duel_assert can be modified to call duel_fatal, so gdb itself isn't
  960. X  * aborted because on an internal duel error.
  961. X  */
  962. X
  963. X#define duel_assert(x)       assert(x)
  964. X#define duel_bzero(x,y)   memset(x,0,y)
  965. X#define duel_bcopy(x,y,s) memcpy(x,y,s)
  966. X
  967. X
  968. X
  969. X/*************
  970. X Parsing: the expression is converted into a tree.
  971. X Each node of this tree is of 'tnode' type.
  972. X Nodes can be:
  973. X An operator (like '+', or ':=' or 'for')
  974. X A  constant (numbers. Strings are pointers to space!)
  975. X A  symbol.
  976. X A  regular expression (really a symbol extention)
  977. X
  978. X The evaluation of any node results in:
  979. X 1. 'Environment': duel variables and their values
  980. X 2. symbolic expression which describe the computation
  981. X    meaning: keep the parentethis. in the expression a<<(3+b) (even if not needed!)
  982. X 3. A type & value
  983. X Values:
  984. X Values are always a fixed length area of bytes; Any C type is like that.
  985. X**************/
  986. X
  987. X
  988. X/****** TYPES *******
  989. X  A type described in the typical compiler's way, and also gdb's original
  990. X  way. That is, a type is made of an 'atomic' types, like 'pointer to',
  991. X  'array of', etc. Each atomic type is described by a 'ctype' node. Ctype
  992. X  node points to other ctype nodes as required. For example, a ctype node
  993. X  of 'array of' will point to the node 'int' for the 'C' type array of int.
  994. X  [The name ctype is used to indicate the C language type; 'type' is too
  995. X   generic a term]
  996. X  Example:
  997. X   char *(*f[])() ;
  998. X  Here, f is an array of pointers to functions returning a pointer to char.
  999. X  The type is described with the top node being of CTK_ARRAY type. It
  1000. X  points to a 'CTK_PTR' node, which points to a 'CTK_FUNC' node which
  1001. X  points to a 'CTK_PTR' node which points to a 'CTK_CHAR' node which has,
  1002. X  as size, 1.
  1003. X
  1004. X  The size of a type is the number of bytes occupied by it. it is zero
  1005. X  for types like 'function'. An array of 10 integers will have as size
  1006. X  10*sizeof(int)
  1007. X ********************/
  1008. X
  1009. Xtypedef enum {       /* 'C' Type atomic primitive Kinds (CTK_) */
  1010. X   CTK_VOID=0,       /* void type   'void'     */
  1011. X   CTK_CHAR=1,       /* primitive types        */     
  1012. X   CTK_UCHAR=2,      /* note order is used in some macros */
  1013. X   CTK_SHORT=3,
  1014. X   CTK_USHORT=4,
  1015. X   CTK_INT=5,
  1016. X   CTK_UINT=6,
  1017. X   CTK_LONG=7,
  1018. X   CTK_ULONG=8,
  1019. X   CTK_FLOAT=9,
  1020. X   CTK_DOUBLE=10,
  1021. X   CTK_PTR=11,          /* pointer '*'            */
  1022. X   CTK_ARRAY=12,        /* array   '[]'           */
  1023. X   CTK_FUNC=13,         /* a function '()'        */
  1024. X   CTK_STRUCT=14,       /* a sturcture 'struct{}' */
  1025. X   CTK_UNION=15,        /* a union     'union{}'  */
  1026. X   CTK_ENUM=16          /* enum type   'enum{}'   */
  1027. X } tctype_kind ;
  1028. X
  1029. Xtypedef struct {        /* a field (of struct) info */
  1030. X  char *name ;            /* field name */ 
  1031. X  struct sctype *ctype ;    /* field type */
  1032. X  int bitpos, bitlen ;        /* for bit fields only */
  1033. X} tctype_field ;
  1034. X
  1035. Xtypedef struct {        /* an enumerator (constant of an enum)  info */
  1036. X  char *name ;            /* enumerator name */
  1037. X  int val ;            /* value assigned to the name */
  1038. X                /* question: ansi-C say cosnt fit in int?*/
  1039. X} tctype_enumerator ;
  1040. X
  1041. X
  1042. Xtypedef struct sctype {       /* a 'C' type description  */
  1043. X   tctype_kind type_kind ;
  1044. X   char *name ;               /* named of this type, if any       */
  1045. X   size_t size ;              /* size (total bytes) for this type */
  1046. X   union {
  1047. X    struct sctype *kid ;       /* pointer to next atomic type               */
  1048. X    struct {
  1049. X      int fields_no ;
  1050. X      tctype_field *fields ;     /* union/struct fields */
  1051. X    } f ;
  1052. X    struct {
  1053. X       tctype_kind real_type_kind ; /* the type used for storage of the enum */
  1054. X       int enumerators_no ;
  1055. X       tctype_enumerator *enumerators ;    /* enum's type enumerators list */
  1056. X    } e; 
  1057. X   } u ;
  1058. X } tctype ;
  1059. X
  1060. X
  1061. X/**** BASIC C TYPES
  1062. X  these are initialized at run type to point to the basic C types.
  1063. X  basic types are never created again, e.g. pointer comparison with
  1064. X  these is sufficient to check type equality.
  1065. X  the voidptr is (void*) which is a basic type (what zero is converted 
  1066. X  to when it is a pointer).
  1067. X  ptrdiff_t and size_t are actually pointing to their actualy types,
  1068. X  ie. normally point to ctype_int.
  1069. X ****/
  1070. X
  1071. XDEF tctype *ctype_int,  *ctype_uint, *ctype_short, *ctype_ushort, 
  1072. X           *ctype_char, *ctype_uchar, *ctype_long, *ctype_ulong,
  1073. X           *ctype_float, *ctype_double,
  1074. X           *ctype_void, *ctype_charptr,
  1075. X           *ctype_voidptr,*ctype_ptrdiff_t,*ctype_size_t ;
  1076. X
  1077. X/* type checking macros */
  1078. X
  1079. X/** tell if type is a struct or union */
  1080. X#define ctype_kind_struct_like(t) ((t)->type_kind==CTK_STRUCT || \
  1081. X                   (t)->type_kind==CTK_UNION)
  1082. X
  1083. X/** tell if type is a pointer or can be made one (array, func) */
  1084. X#define ctype_kind_ptr_like(t)   ((t)->type_kind==CTK_PTR || \
  1085. X                         (t)->type_kind==CTK_ARRAY || (t)->type_kind==CTK_FUNC)
  1086. X/* tell if type is numeric */
  1087. X#define ctype_kind_numeric(t) ((t)->type_kind>=CTK_CHAR && \
  1088. X                     (t)->type_kind<=CTK_DOUBLE || (t)->type_kind==CTK_ENUM) 
  1089. X
  1090. X/* tell if type is integral */
  1091. X#define ctype_kind_integral(t) ((t)->type_kind>=CTK_CHAR && \
  1092. X                     (t)->type_kind<=CTK_ULONG || (t)->type_kind==CTK_ENUM)
  1093. X
  1094. X/* tell if type fits into fixed memory size (void not included) */
  1095. X#define ctype_kind_scalar(t) (ctype_kind_numeric(t) || ctype_kind_ptr_like(t))
  1096. X
  1097. X/* tell if type is a "base" ie can't have kids */
  1098. X
  1099. X#define ctype_kind_base(t) ((t)->type_kind>=CTK_VOID && \
  1100. X                (t)->type_kind<=CTK_DOUBLE)
  1101. X
  1102. X/* tell if a type is a function pointer or like a func ptr (ie a func!) */
  1103. X#define ctype_kind_func_ptr_like(t) ((t)->type_kind==CTK_FUNC || \
  1104. X            (t)->type_kind==CTK_PTR && t->u.kid->type_kind==CTK_FUNC)
  1105. X
  1106. X
  1107. X/***** VALUES
  1108. X   used to keep information when evaluating an expression. A value is
  1109. X   either:
  1110. X   1) a right-value, which is represented in a fixed number of bytes that
  1111. X      actually contain its value. Example: result of '+' operation.
  1112. X   2) a left-value. This is a reference to the actual value, which
  1113. X      resides in the debuggee's address space.
  1114. X   3) a special-value. This contains a long value specifying a special
  1115. X      target location (e.g. register) from which values can be fetched
  1116. X      or written to. However, special-values can not be manipulated (i.e
  1117. X      have an offset added to them, as done to an lvalue struct).
  1118. X
  1119. X   Note that the operation '*x' starts with x as an lvalue - a pointer to
  1120. X   x is kept. Then, '*x' is executed, fetching the value of x and creating
  1121. X   another lvalue, which points to where x has pointed to! This allows
  1122. X   &*x to be executed, as well as *x=1 or &x[1] ...
  1123. X   When the value of an lvalue is actually needed, it must be fetched
  1124. X   from the debugge's space.
  1125. X *****/
  1126. X
  1127. X#define VALUE_MAX_CONST_SIZE        8
  1128. X#define VALUE_MAX_SYMBOLIC_SIZE     128
  1129. X
  1130. Xtypedef int tptrsize_int ;        /* type so that 
  1131. X                   tptrsize x; char *p ;
  1132. X                   p == (char*) (tptrsize) p
  1133. X                 */
  1134. X
  1135. X  /* type that represent a target address space location.  */
  1136. X
  1137. Xtypedef char* ttarget_ptr ; /* pointer to target's address */
  1138. X
  1139. Xtypedef struct {
  1140. X    ttarget_ptr lvalue ;    /* pointer to target's location of struct*/
  1141. X    int bitpos,bitlen ;        /* as specified in the field info of stuct*/
  1142. X } tbvalue_info ;
  1143. X
  1144. Xtypedef enum {
  1145. X  VK_RVALUE,      /* this value represent a constant, in the rval_ union */
  1146. X  VK_LVALUE,      /* this value represent a left-value. address in lvalue*/
  1147. X  VK_BVALUE,      /* a bit-field lvalue, given as point and bitpos/bitlen*/
  1148. X  VK_FVALUE,      /* a frame, fvalue contains it number */
  1149. X } tval_kind ;
  1150. X
  1151. Xtypedef struct {
  1152. X   tval_kind val_kind ;
  1153. X   tctype *ctype ;       /* type of this value */
  1154. X   union {
  1155. X      ttarget_ptr lvalue ; /* location in target of the value */
  1156. X      tbvalue_info bvalue ; /* location in target of a bitfield */
  1157. X      int        fvalue ; /* a frame number (0 = top of stack) */
  1158. X      char   rval_char ;
  1159. X      uchar  rval_uchar ;
  1160. X      short  rval_short ;
  1161. X      ushort rval_ushort ;
  1162. X      int    rval_int ;
  1163. X      uint   rval_uint ;
  1164. X      long   rval_long ;
  1165. X      ulong  rval_ulong ;
  1166. X      float  rval_float ;
  1167. X      double rval_double ;
  1168. X      ttarget_ptr rval_ptr ;
  1169. X      ptrdiff_t rval_ptrdiff_t ; /* Synonyms to one of the above fields! */
  1170. X      size_t    rval_size_t ;     /* normally these are simply = rval_int */
  1171. X   } u ;
  1172. X   char symb_val[VALUE_MAX_SYMBOLIC_SIZE];
  1173. X }  tvalue ;
  1174. X
  1175. X
  1176. Xtypedef struct sval_lcell {    /* a cell on a linked-list containing a tvalue*/
  1177. X    tvalue val ;
  1178. X    struct sval_lcell *next ;
  1179. X } tval_lcell ;
  1180. X
  1181. Xtypedef struct {           /* a linked list of tvalue's */
  1182. X    tval_lcell *head ;
  1183. X    tval_lcell *tail ;
  1184. X} tval_list ;
  1185. X
  1186. X/**** OP CODES ****
  1187. X Opcodes are divided into groups, or 'kinds'. For example, all the
  1188. X C regular unary operators, binary operators, etc.
  1189. X An opcode is defined by its 'kind' and actual value. The value is,
  1190. X in most cases, a single char. For example, the C plus operator is
  1191. X defined as op_kind=OPK_BIN and op='+'. The C operator '+=' is
  1192. X defined as op_kind=OPK_ASSIGN and op='+'.
  1193. X some operators are uniquely identified by type alone (e.g. func call).
  1194. X In the lexer there is a table of actual operators as tokens, and
  1195. X the kind & value assigned to each.
  1196. X Several opertors use more than one char, and are defined below.
  1197. X the OPK_SBIN, etc kinds are special in the sense that A op B isn't
  1198. X computed in the normal way of the C language (i.e. compute both sides,
  1199. X then apply the operator). Such operators include ',' '&&', etc.
  1200. X **********/
  1201. Xtypedef enum {
  1202. X    /* '+' '-' etc are used directly and have their ascii value */
  1203. X    OP_LSH = 300,     /* '<<' */
  1204. X    OP_RSH = 301,     /* '>>' */
  1205. X    OP_INC = 302,     /* '++' */
  1206. X    OP_DEC = 303,     /* '--' */
  1207. X    OP_ARR = 304,     /* '->' */
  1208. X    OP_AND = 305,     /* '&&' */
  1209. X    OP_OR  = 306,     /* '||' */
  1210. X    OP_EQ  = 307,     /* '==' */
  1211. X    OP_GE  = 308,     /* '>=' */
  1212. X    OP_LE  = 309,     /* '<=' */
  1213. X    OP_NE  = 310,     /* '!=' */
  1214. X    OP_SIZ = 311,     /* 'sizeof' */
  1215. X    OP_TO  = 312,     /* '..' */
  1216. X    OP_EQQ  = 313,     /* '==?' */
  1217. X    OP_NEQ  = 314,     /* '!=?' */
  1218. X    OP_GEQ  = 315,     /* '>=?' */
  1219. X    OP_LEQ  = 316,     /* '<=?' */
  1220. X    OP_GTQ  = 317,     /* '>?'  */
  1221. X    OP_LSQ  = 318,     /* '<?'  */
  1222. X    OP_IMP  = 319,     /* '=>'  */
  1223. X    OP_IF   = 320,     /* if()  */
  1224. X    OP_DEF  = 321,     /* ':='  */
  1225. X    OP_DFS  = 322,     /* '-->' */
  1226. X    OP_BFS  = 323,     /* '->>' */
  1227. X    OP_POS  = 324,     /* '>--' */
  1228. X    OP_IOS  = 325,     /* '->-' */
  1229. X    OP_SEL  = 326,     /*'x[[y]]'*/
  1230. X    OP_FOR  = 327,     /*for(;;)'*/
  1231. X    OP_WHILE= 328,     /*while() */
  1232. X    OP_DECL = 329,     /* var decl*/
  1233. X    OP_FRAME= 330,     /* frame(i)*/
  1234. X   } topcode ;
  1235. X
  1236. X/**** OPCODE KINDS ****/
  1237. X
  1238. Xtypedef enum {          /* the kind of the opcode, 'OPK_' = OPcode Kind */
  1239. X   OPK_UNARY      =0,   /* regular unary operator                       */
  1240. X   OPK_SUNARY     =1,   /* special unary operator (sizeof)              */
  1241. X   OPK_POST_UNARY =2,   /* post unary operator (x++ etc)                */
  1242. X   OPK_BIN        =3,   /* regular binary operator                      */
  1243. X   OPK_SBIN       =4,   /* special binary operator                      */
  1244. X   OPK_TRI        =5,   /* trinary (eg ?:) operator                     */
  1245. X   OPK_QUAD      =6,   /* quad (e.g.for(;;)) operator            */
  1246. X   OPK_ASSIGN     =7,   /* assignment ie =, +=, -= etc                  */
  1247. X   OPK_FUNC       =8,   /* function call. 2nd kid made of ',' kids for parms */
  1248. X   OPK_CAST       =9,   /* type cast.  2nd kid convert to type in 1st kid */
  1249. X   OPK_NUM_OF     =10   /* number of OPK_* op kinds                       */
  1250. X } top_kind ;
  1251. X
  1252. X
  1253. X/**** NODE KINDS ****/
  1254. X
  1255. Xtypedef enum {           /* the kind of node        */
  1256. X   NK_OP,               /* contain an operator     */
  1257. X   NK_CONST,            /* contains a constant     */
  1258. X   NK_NAME,             /* contains a name/symbol  */
  1259. X   NK_CTYPE,            /* contain a 'C' type      */
  1260. X } tnode_kind ;
  1261. X
  1262. X#define NODE_MAX_KIDS      4     /* maximum no of kids per node         */
  1263. X#define NODE_MAX_SYM_LEN  50     /* maximum length for a symbol         */
  1264. X
  1265. X/* the following structure is used to store one node of the expression tree.
  1266. X * It contains two parts: (a) information to describe the node and (b)
  1267. X * information used during the evaluation of the node.
  1268. X *
  1269. X * This structure could/should be optimized with ugly unions (e.g., for
  1270. X * a node describing a constant(node_kind==NK_CONST) there is no need for
  1271. X * the op, kids or any eval stuff!). However, only few nodes (less than 100?)
  1272. X * are expected to be in memory at any time (how complex can a user
  1273. X * expression be?). Hence, for clarity, no unions where used.
  1274. X * 
  1275. X * All nodes have kids in the typical way. the opcode OPK_FUNC node is tricky:
  1276. X * see parsing - the commas are handled as operators and not as part of the
  1277. X * syntax. when a func call is evaluated, the top comma nodes are used to
  1278. X * separate the arguments (this hack prevents complex parsing and complex tnode
  1279. X * with variable num of kids, which would force the kids[] to be malloc etc.)
  1280. X */
  1281. X
  1282. Xtypedef struct snode {           /* a single node on an expression tree     */
  1283. X   tnode_kind node_kind ;        /* what kind of note this is               */
  1284. X                /* NK_OP node info: op_kind,op,kids       */
  1285. X   int src_pos ;           /* starting source code location (op etc)  */
  1286. X   top_kind op_kind ;        /* opcode type (unary,bin etc)   */
  1287. X   topcode op ;            /* actual opcode: '-' for both unary&bin '-'*/
  1288. X   struct snode *kids[NODE_MAX_KIDS] ;      /* pointers to node's kids     */
  1289. X   tvalue cnst ;        /* NK_CONST info - constant value    */
  1290. X   char *name ;            /* NK_NAME  info - variable name        */
  1291. X   tctype *ctype ;        /* NK_CTYPE info - a type           */
  1292. X
  1293. X   struct {            /* information used during node evaluation   */
  1294. X       int level ;        /* evaluation level (0=none, 1=left in x etc)*/
  1295. X       tvalue  v1,v2 ;        /* keep last computed operands, etc          */
  1296. X       tval_list vlist ;    /* value list for node (used in --> etc ops) */
  1297. X       int counter ;        /* used for counting         */
  1298. X   } eval ;        
  1299. X } tnode ;
  1300. X
  1301. X
  1302. XDEF bool duel_debug ;       /* debugging duel-itself mode   */
  1303. X
  1304. X/* this things are machine dependent stuff */
  1305. X
  1306. X#define BITS_PER_BYTE 8  /* no of bits in (char) (right. try '9' :-) */
  1307. SHAR_EOF
  1308. $TOUCH -am 0113165193 src/global.h &&
  1309. chmod 0644 src/global.h ||
  1310. echo "restore of src/global.h failed"
  1311. set `wc -c src/global.h`;Wc_c=$1
  1312. if test "$Wc_c" != "15898"; then
  1313.     echo original size 15898, current size $Wc_c
  1314. fi
  1315. echo "End of part 2, continue with part 3"
  1316. exit 0
  1317.