home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / alt / sources / 3074 < prev    next >
Encoding:
Text File  |  1993-01-23  |  37.1 KB  |  1,413 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 6/6
  5. Message-ID: <1993Jan22.034852.21328@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:48:52 GMT
  9. Lines: 1402
  10.  
  11. Submitted-by: mg@cs.princeton.edu
  12. Archive-name: duel/part06
  13.  
  14. #!/bin/sh
  15. # This is part 06 of duel
  16. if touch 2>&1 | fgrep 'amc' > /dev/null
  17.  then TOUCH=touch
  18.  else TOUCH=true
  19. fi
  20. # ============= src/print.c ==============
  21. echo "x - extracting src/print.c (Text)"
  22. sed 's/^X//' << 'SHAR_EOF' > src/print.c &&
  23. X/*   DUEL - A Very High Level Debugging Langauge.  */
  24. X/*   Public domain code                       */
  25. X/*   Written by Michael Golan mg@cs.princeton.edu  */
  26. X/*$Header: /tmp_mnt/n/fs/grad2/mg/duel/RCS/print.c,v 1.3 93/01/12 21:53:45 mg Exp $*/
  27. X
  28. X/* handle value/type printing */
  29. X
  30. X/*
  31. X * $Log:    print.c,v $
  32. X * Revision 1.3  93/01/12  21:53:45  mg
  33. X * cleanup and set for release
  34. X * 
  35. X * Revision 1.2  93/01/07  00:14:34  mg
  36. X * print union name
  37. X * 
  38. X * Revision 1.1  93/01/03  07:31:55  mg
  39. X * Initial revision
  40. X * 
  41. X */
  42. X
  43. X#include "duel.h"
  44. X
  45. X/* print type information (no new lines)
  46. X * parm 'expand' controls expansion level for structs & unions. normally 1.
  47. X */
  48. X
  49. XPROC duel_print_type(tctype *t,int expand)
  50. X{
  51. X   int i ;
  52. X   tctype *kid=t->u.kid ;
  53. X   
  54. X   switch(t->type_kind) {
  55. X      case CTK_VOID:    printf("void ")   ; break ;
  56. X      case CTK_CHAR:    printf("char ")   ; break ;
  57. X      case CTK_UCHAR:   printf("uchar ")  ; break ;
  58. X      case CTK_USHORT:  printf("ushort ") ; break ;
  59. X      case CTK_SHORT:   printf("short ")  ; break ;
  60. X      case CTK_INT:     printf("int ")    ; break ;
  61. X      case CTK_UINT:    printf("uint ")   ; break ;
  62. X      case CTK_LONG:    printf("long ")   ; break ;
  63. X      case CTK_ULONG:   printf("ulong ")  ; break ;
  64. X      case CTK_FLOAT:   printf("float ")  ; break ;
  65. X      case CTK_DOUBLE:  printf("double ") ; break ;
  66. X      case CTK_ENUM:    printf("enum %s ",t->name); break ;
  67. X   
  68. X      case CTK_PTR: 
  69. X                  if(ctype_kind_base(kid)) {
  70. X                      duel_print_type(kid,0);
  71. X                      printf("* ");
  72. X                  }
  73. X                  else {
  74. X                      printf("ptr to ");
  75. X                      duel_print_type(kid,expand-1) ;
  76. X                  }
  77. X      break ;
  78. X      case CTK_ARRAY: {
  79. X                  int n=t->size ;
  80. X                  if(kid->size>0) n/=kid->size ;
  81. X
  82. X                  if(ctype_kind_base(kid)) {
  83. X                      duel_print_type(kid,0);
  84. X                      printf("[%d] ",n);
  85. X                  }
  86. X                  else {
  87. X                      printf("array [%d] of ",n);
  88. X                      duel_print_type(kid,expand) ;
  89. X                  }
  90. X               }
  91. X      break ;
  92. X      case CTK_FUNC:  printf("func returning ");
  93. X                      duel_print_type(kid,expand);
  94. X      break ;
  95. X      case CTK_STRUCT: 
  96. X    if(expand <= 0) {
  97. X        printf("struct %s ",t->name);
  98. X        break ;
  99. X    }
  100. X    printf("struct %s { ",t->name) ; 
  101. X     for(i=0 ; i<t->u.f.fields_no ; i++) {
  102. X           tctype_field *f= &t->u.f.fields[i] ;
  103. X        duel_print_type(f->ctype,expand-1); 
  104. X        printf("%s ",f->name);
  105. X        if(f->bitlen != 0) printf(":%d ",f->bitlen);
  106. X        printf("; ");
  107. X    }
  108. X    printf("} ; ");
  109. X      break ;
  110. X      case CTK_UNION:   printf("union %s",t->name)  ; break ;
  111. X      default: duel_assert(0);
  112. X   }
  113. X}
  114. X
  115. X
  116. X/* print the given scalar value into string s.
  117. X * for none-scalar values, print the lval's address.
  118. X * note: v's value is not modified.
  119. X */
  120. X
  121. XPROC duel_sprint_scalar_value(char *s,tvalue *v)
  122. X{
  123. X   bool ok ;
  124. X   tvalue rval ;  /* copy of v, but as an rval */
  125. X   rval = *v ;
  126. X   if(v->val_kind==VK_FVALUE) {
  127. X        sprintf(s,"frame(%d)",v->u.fvalue);
  128. X        return ;
  129. X   }
  130. X   if(v->val_kind==VK_LVALUE) {
  131. X    if(v->u.lvalue==NULL) sprintf(s,"illegal ref - null");
  132. X        switch(v->ctype->type_kind) {
  133. X          case CTK_STRUCT: sprintf(s,"struct @%p",v->u.lvalue); return;
  134. X          case CTK_UNION:  sprintf(s,"union @%p",v->u.lvalue ); return;
  135. X          case CTK_FUNC:   sprintf(s,"func @%p",v->u.lvalue)  ; return;
  136. X          case CTK_ARRAY:
  137. X         if(v->ctype->u.kid!=ctype_char) {
  138. X                sprintf(s,"array @%p",v->u.lvalue); 
  139. X                return;
  140. X             }
  141. X        }
  142. X        ok=duel_try_get_rvalue(&rval,"");
  143. X        if(!ok) {
  144. X           sprintf(s,"illegal ref @%p",v->u.lvalue);
  145. X           return ;
  146. X        }
  147. X   }
  148. X   else
  149. X   if(v->val_kind==VK_BVALUE) {
  150. X        ok=duel_try_get_rvalue(&rval,"");
  151. X        if(!ok) {
  152. X           sprintf(s,"illegal ref @%p",v->u.bvalue.lvalue);
  153. X           return ;
  154. X        }
  155. X   }
  156. X
  157. X   switch(rval.ctype->type_kind) {
  158. X     case CTK_VOID:   sprintf(s,"void") ; break ;
  159. X     case CTK_CHAR: if(rval.u.rval_char==0) sprintf(s,"'\\0'");
  160. X            else
  161. X                if(!isprint(rval.u.rval_char)|| !isascii(rval.u.rval_char))
  162. X                     sprintf(s,"'\\%3.3o'",rval.u.rval_char & 0377);
  163. X                    else sprintf(s,"'%c'", rval.u.rval_char)   ; 
  164. X      break ;
  165. X      case CTK_SHORT:   sprintf(s,"%d",     rval.u.rval_short)  ; break ;
  166. X      case CTK_INT:     sprintf(s,"%d",     rval.u.rval_int)    ; break ;
  167. X      case CTK_LONG:    sprintf(s,"%ldL",   rval.u.rval_long)   ; break ;
  168. X      case CTK_UCHAR:   if(rval.u.rval_uchar==0) sprintf(s,"'\\0'");
  169. X                else sprintf(s,"'\\x%d'", rval.u.rval_uchar)  ; break ;
  170. X      case CTK_USHORT:  if(rval.u.rval_ushort==0) sprintf(s,"0");
  171. X                else sprintf(s,"0x%x",   rval.u.rval_ushort) ; break ;
  172. X      case CTK_UINT:    if(rval.u.rval_uint==0) sprintf(s,"0");
  173. X                else sprintf(s,"0x%x",   rval.u.rval_uint)   ; break ;
  174. X      case CTK_ULONG:   if(rval.u.rval_ulong==0L) sprintf(s,"0");
  175. X                else sprintf(s,"0x%lxL", rval.u.rval_ulong)  ; break ;
  176. X      case CTK_FLOAT:   rval.u.rval_double=rval.u.rval_float ;
  177. X      case CTK_DOUBLE:  if(fabs(rval.u.rval_double)<=1e-6 ||
  178. X               fabs(rval.u.rval_double)>=1e8)
  179. X                        sprintf(s,"%.4le",rval.u.rval_double);
  180. X                        else {
  181. X                int l;
  182. X                 sprintf(s,"%.8lf",rval.u.rval_double) ; 
  183. X                l=strlen(s)-1;
  184. X                while(s[l]=='0' && s[l-1]!='.') s[l--]=0 ;
  185. X            }
  186. X      break ;
  187. X      case CTK_PTR: 
  188. X      if(rval.u.rval_ptr==NULL) sprintf(s,"NULL");
  189. X      else 
  190. X      if(rval.ctype->u.kid==ctype_char) {
  191. X          char sval[31] ;
  192. X          duel_get_target_bytes(rval.u.lvalue,sval,30);
  193. X          sval[30]=0 ;
  194. X          sprintf(s,"\"%s\"",sval);
  195. X      }
  196. X          else sprintf(s,"@%p",rval.u.rval_ptr);
  197. X      break ;
  198. X      case CTK_ENUM:    {
  199. X      int i, n=rval.ctype->u.e.enumerators_no ;
  200. X      tctype_enumerator *e=rval.ctype->u.e.enumerators ;
  201. X      int val=duel_get_int_val(v,"");
  202. X      for(i=0 ; i<n ; i++)
  203. X          if(e[i].val == val) { strcpy(s,e[i].name); return ;}
  204. X      sprintf(s,"%d",val);
  205. X      }
  206. X      break ;
  207. X      default: duel_assert(0);
  208. X   }
  209. X}
  210. X
  211. X/* print the given value, symbolic+val. Handles structures */
  212. X
  213. XPROC duel_print_value(tvalue *v)
  214. X{
  215. X   tctype *t=v->ctype ;
  216. X   int i ;
  217. X   char s[160];
  218. X
  219. X   if(duel_debug) {
  220. X       printf("`` %s '' ",v->symb_val);
  221. X       printf("{ ");
  222. X       duel_print_type(v->ctype,2);
  223. X       printf("} ");
  224. X       if(v->val_kind==VK_LVALUE) {
  225. X      printf("lval @%p",v->u.lvalue);
  226. X       }
  227. X       else
  228. X       if(v->val_kind==VK_BVALUE) {
  229. X      printf("bval @%p [%d,%d]",v->u.bvalue.lvalue,v->u.bvalue.bitpos,
  230. X                                    v->u.bvalue.bitlen);
  231. X       }
  232. X       printf("\n");
  233. X   }
  234. X
  235. X   if(v->val_kind==VK_LVALUE) {
  236. X      switch(t->type_kind) {
  237. X        case CTK_STRUCT:
  238. X             printf("%s = { ",v->symb_val);
  239. X         for(i=0 ; i<t->u.f.fields_no ; i++) {
  240. X               tvalue u ;
  241. X               char *name=t->u.f.fields[i].name ;
  242. X               duel_get_dot_name(v,name,&u);
  243. X               duel_sprint_scalar_value(s,&u);
  244. X               printf("%s = %s",name,s) ;
  245. X               if(strncmp(s,"illegal",6)==0) break ;
  246. X           if(i < t->u.f.fields_no-1) printf(", ");
  247. X             } 
  248. X         printf(" }");
  249. X        return ;
  250. X        case CTK_ARRAY:
  251. X        case CTK_UNION: ; /* for now, do nothing for these */
  252. X      }
  253. X   }
  254. X
  255. X   duel_sprint_scalar_value(s,v);
  256. X   if(strcmp(v->symb_val,s)==0) printf("%s",s);
  257. X   else
  258. X    printf("%s = %s",v->symb_val,s);
  259. X
  260. X}
  261. X
  262. SHAR_EOF
  263. $TOUCH -am 0113165193 src/print.c &&
  264. chmod 0644 src/print.c ||
  265. echo "restore of src/print.c failed"
  266. set `wc -c src/print.c`;Wc_c=$1
  267. if test "$Wc_c" != "7498"; then
  268.     echo original size 7498, current size $Wc_c
  269. fi
  270. # ============= src/types.c ==============
  271. echo "x - extracting src/types.c (Text)"
  272. sed 's/^X//' << 'SHAR_EOF' > src/types.c &&
  273. X/*   DUEL - A Very High Level Debugging Langauge.  */
  274. X/*   Public domain code                       */
  275. X/*   Written by Michael Golan mg@cs.princeton.edu  */
  276. X/*$Header: /tmp_mnt/n/fs/grad2/mg/duel/RCS/types.c,v 1.6 93/01/12 21:54:25 mg Exp $*/
  277. X
  278. X/* this module contains the duel type system management
  279. X */
  280. X
  281. X/*
  282. X * $Log:    types.c,v $
  283. X * Revision 1.6  93/01/12  21:54:25  mg
  284. X * cleanup and set for release
  285. X * 
  286. X * Revision 1.5  93/01/03  07:31:24  mg
  287. X * *** empty log message ***
  288. X * 
  289. X * Revision 1.4  92/10/19  15:09:28  mg
  290. X * support zero fields/enumerators because gdb have them sometimes.
  291. X * 
  292. X * Revision 1.3  92/10/14  02:07:00  mg
  293. X * misc
  294. X * 
  295. X * Revision 1.2  92/09/16  11:11:43  mg
  296. X * added builtin charptr type
  297. X * 
  298. X */
  299. X
  300. X#include "duel.h"
  301. X
  302. XFUNC tctype* duel_mkctype_ptr(tctype *t)
  303. X{
  304. X  tctype *n ;
  305. X  n=(tctype *) duel_malloc(sizeof(tctype));
  306. X  duel_bzero((char*) n,sizeof(tctype));
  307. X  n->type_kind=CTK_PTR ;
  308. X  n->size=sizeof(void*);
  309. X  n->u.kid=t ;
  310. X  return n ;
  311. X}
  312. X
  313. XFUNC tctype* duel_mkctype_func(tctype *t)
  314. X{
  315. X  tctype *n ;
  316. X  n=(tctype *) duel_malloc(sizeof(tctype));
  317. X  duel_bzero((char*) n,sizeof(tctype));
  318. X  n->size=0 ;
  319. X  n->type_kind=CTK_FUNC ;
  320. X  n->u.kid=t ;
  321. X  return n ;
  322. X}
  323. X
  324. X/* create a struct or union type. The fields are not set here, but
  325. X * filled individually with the next function
  326. X * note the having zero fields is supported. This shouldnt be legal in C
  327. X * but compilers allow pointer to sturct w/o every specifying the struct.
  328. X * this is especially true for gdb itself!
  329. X */
  330. X
  331. XFUNC tctype* duel_mkctype_struct(char *name,size_t size,int fields_no,
  332. X                 bool is_union)
  333. X{
  334. X  tctype *n ;
  335. X  n=(tctype *) duel_malloc(sizeof(tctype));
  336. X  duel_bzero((char*) n,sizeof(tctype));
  337. X  n->name=name ;
  338. X  n->size=size ;
  339. X  if(is_union) n->type_kind=CTK_UNION ;
  340. X  else n->type_kind=CTK_STRUCT ;
  341. X  n->u.f.fields_no=fields_no ;
  342. X  if(fields_no==0) n->u.f.fields=NULL ;
  343. X  else {
  344. X    n->u.f.fields=(tctype_field *) duel_malloc(fields_no*sizeof(tctype_field));
  345. X    duel_bzero((char*) n->u.f.fields,fields_no*sizeof(tctype_field));
  346. X  }
  347. X  return n ;
  348. X}
  349. X
  350. X/* insert field (field_no) into sturct/union (t), with type fctype 
  351. X */
  352. XPROC duel_mkctype_struct_field(tctype *t,int field_no,char *name,
  353. X                   int bitpos,int bitlen, tctype *fctype)
  354. X{
  355. X   tctype_field *f ;
  356. X   duel_assert(t->type_kind==CTK_STRUCT || t->type_kind==CTK_UNION);
  357. X   duel_assert(field_no>=0 && field_no <= t->u.f.fields_no);
  358. X   f= &t->u.f.fields[field_no] ;
  359. X   f->name=name ;
  360. X   f->bitpos=bitpos ;
  361. X   f->bitlen=bitlen ;
  362. X   f->ctype=fctype ;
  363. X}
  364. X
  365. X/* create an enum type. The enumerators are not set here, but
  366. X * filled individually with the next function
  367. X * again like sturct, we support zero enums. I am not sure its needed,
  368. X * but better safe than sorry.
  369. X */
  370. X
  371. XFUNC tctype* duel_mkctype_enum(char *name,tctype_kind real_type_kind,
  372. X                   size_t size,int enumerators_no)
  373. X{
  374. X  tctype *n ;
  375. X  n=(tctype *) duel_malloc(sizeof(tctype));
  376. X  duel_bzero((char*) n,sizeof(tctype));
  377. X  n->name=name ;
  378. X  n->size=size ;
  379. X  n->type_kind=CTK_ENUM ;
  380. X  n->u.e.real_type_kind=real_type_kind ;
  381. X  n->u.e.enumerators_no=enumerators_no ;
  382. X  if(enumerators_no==0) n->u.e.enumerators=NULL ;
  383. X  else {
  384. X      n->u.e.enumerators= (tctype_enumerator *) 
  385. X                   duel_malloc(enumerators_no*sizeof(tctype_enumerator));
  386. X      duel_bzero((char*) n->u.e.enumerators,
  387. X               enumerators_no*sizeof(tctype_enumerator));
  388. X  }
  389. X  return n ;
  390. X}
  391. X
  392. X
  393. X/* insert enumerator (enumerator_no_ into an enum type (t), with given name/val
  394. X */
  395. XPROC duel_mkctype_enumerator(tctype *t,int enumerator_no,char *name,int val)
  396. X{
  397. X   tctype_enumerator *e ;
  398. X   duel_assert(t->type_kind==CTK_ENUM);
  399. X   duel_assert(enumerator_no>=0 && enumerator_no <= t->u.e.enumerators_no);
  400. X   e= &t->u.e.enumerators[enumerator_no] ;
  401. X   e->name=name ;
  402. X   e->val=val ;
  403. X}
  404. X
  405. XFUNC tctype* duel_mkctype_array(tctype *t,int size)
  406. X{
  407. X  tctype *n ;
  408. X  if(t->size==0) duel_gen_error("array of a type of zero size is illegal",0);
  409. X  if(size<=0)      duel_gen_error("array of size zero or negative is illegal",0);
  410. X  n=(tctype *) duel_malloc(sizeof(tctype));
  411. X  duel_bzero((char*) n,sizeof(tctype));
  412. X  n->type_kind=CTK_ARRAY ;
  413. X  n->size=size*t->size ;
  414. X  n->u.kid=t ;
  415. X  return n ;
  416. X}
  417. X
  418. X
  419. XLFUNC tctype* init_basic_ctype(tctype_kind tk,char *name,size_t size)
  420. X{
  421. X    tctype *p = duel_malloc(sizeof(tctype));
  422. X    p->type_kind=tk ;
  423. X    p->name=name ;
  424. X    p->size=size ;
  425. X    return p ;
  426. X}
  427. X
  428. XPROC duel_init_basic_ctypes(void)
  429. X{
  430. X  ctype_void= init_basic_ctype(CTK_VOID, "void", 0);
  431. X
  432. X  ctype_char =init_basic_ctype(CTK_CHAR,    "char", sizeof(char));
  433. X  ctype_short=init_basic_ctype(CTK_SHORT,   "short",sizeof(short));
  434. X  ctype_int  =init_basic_ctype(CTK_INT,     "int",  sizeof(int));
  435. X  ctype_long =init_basic_ctype(CTK_LONG,    "long", sizeof(long));
  436. X
  437. X  ctype_uchar =init_basic_ctype(CTK_UCHAR,  "unsigned char", sizeof(uchar));
  438. X  ctype_ushort=init_basic_ctype(CTK_USHORT, "unsigned short",sizeof(ushort));
  439. X  ctype_uint  =init_basic_ctype(CTK_UINT,   "unsigned int",  sizeof(uint));
  440. X  ctype_ulong =init_basic_ctype(CTK_ULONG,  "unsigned long", sizeof(ulong));
  441. X
  442. X  ctype_double=init_basic_ctype(CTK_DOUBLE, "double", sizeof(double));
  443. X  ctype_float =init_basic_ctype(CTK_FLOAT,  "float",  sizeof(float));
  444. X
  445. X  ctype_voidptr=duel_mkctype_ptr(ctype_void);
  446. X  ctype_charptr=duel_mkctype_ptr(ctype_char);
  447. X  /* find and set the special types.
  448. X   * support only a signed ptrdiff; size_t/ptrdiff must both be int or long
  449. X   */
  450. X  { ptrdiff_t p ; size_t s ;
  451. X    p= -1 ; s= -1 ;
  452. X    if(p>0)  duel_gen_error("bad ptrdiff_t - unsigned",0);
  453. X  
  454. X    if(sizeof(p)==sizeof(int))          ctype_ptrdiff_t=ctype_int ;
  455. X    else if(sizeof(p)==sizeof(long)) ctype_ptrdiff_t=ctype_long ;
  456. X    else duel_gen_error("bad ptrdiff_t size",0);
  457. X
  458. X    if(sizeof(s)==sizeof(int))     ctype_size_t= (s<0)? ctype_int:ctype_uint ;
  459. X    else 
  460. X    if(sizeof(s)==sizeof(long)) ctype_size_t= (s<0)? ctype_long:ctype_ulong ;
  461. X    else duel_gen_error("bad size_t size",0);
  462. X   }
  463. X}
  464. X
  465. X
  466. SHAR_EOF
  467. $TOUCH -am 0113165193 src/types.c &&
  468. chmod 0644 src/types.c ||
  469. echo "restore of src/types.c failed"
  470. set `wc -c src/types.c`;Wc_c=$1
  471. if test "$Wc_c" != "5857"; then
  472.     echo original size 5857, current size $Wc_c
  473. fi
  474. # ============= src/misc.c ==============
  475. echo "x - extracting src/misc.c (Text)"
  476. sed 's/^X//' << 'SHAR_EOF' > src/misc.c &&
  477. X/*   DUEL - A Very High Level Debugging Langauge.  */
  478. X/*   Public domain code                            */
  479. X/*   Written by Michael Golan mg@cs.princeton.edu  */
  480. X/*$Header: /tmp_mnt/n/fs/grad2/mg/duel/RCS/misc.c,v 1.4 93/01/13 16:22:09 mg Exp $*/
  481. X
  482. X/* misc function/library-like */
  483. X
  484. X/*
  485. X * $Log:    misc.c,v $
  486. X * Revision 1.4  93/01/13  16:22:09  mg
  487. X * allow malloc to return int (is a mini symbol on SUN)
  488. X * 
  489. X * Revision 1.3  93/01/12  21:52:43  mg
  490. X * moved aliases mgmt here
  491. X * cleanup and set for release
  492. X * 
  493. X */
  494. X
  495. X#include "duel.h"
  496. X
  497. X/* like strncpy, but put a zero at to[len] anyway.
  498. X * are copied (hence taking len+1 bytes
  499. X */
  500. X
  501. XFUNC char* strncpyz(char *to,char *from,size_t len)
  502. X{
  503. X   strncpy(to,from,len);
  504. X   to[len]=0 ;
  505. X   return to ;
  506. X}
  507. X
  508. X/* allocate n bytes in the target's space. Used for storing constant
  509. X * strings when they are parsed, and for variables declaration
  510. X * note: on SUN (and others?) gdb claims malloc to return an integer. we
  511. X * accept this (silly but probably no harm done)
  512. X */
  513. X
  514. XFUNC ttarget_ptr duel_alloc_target_space(size_t n)
  515. X{
  516. X  tvalue p,f,r,*parms[1] ;
  517. X
  518. X  p.val_kind=VK_RVALUE ;        /* mk n into a value, to pass as parm */
  519. X  p.ctype=ctype_int ;
  520. X  p.u.rval_int=n ;
  521. X  parms[0]= &p ;
  522. X
  523. X  if(!duel_get_target_variable("malloc",-1,&f) || 
  524. X     f.ctype->type_kind!=CTK_FUNC || 
  525. X     f.ctype->u.kid->type_kind!=CTK_INT && f.ctype->u.kid->type_kind!=CTK_PTR) 
  526. X      duel_fatal("malloc() function returning a pointer required in target");
  527. X
  528. X  duel_target_func_call(&f,parms,1,&r);
  529. X  if(r.u.rval_ptr==NULL) duel_fatal("target's malloc() failed");
  530. X  return r.u.rval_ptr ;
  531. X}
  532. X
  533. XPROC duel_free_val_list(tval_list *l)  /*free a val list and mark list empty */
  534. X{
  535. X  tval_lcell *cell,*next ;
  536. X  for(cell=l->head ; cell!=NULL ; cell=next ) {
  537. X      next=cell->next ;
  538. X      duel_free(cell);
  539. X  }
  540. X  l->head=l->tail=NULL ;
  541. X}
  542. X
  543. X/* free all the memory allocated in the parse tree from node */
  544. X
  545. XPROC duel_free_nodes(tnode *n)
  546. X{
  547. X    int i;
  548. X    if(!n) return ;
  549. X    for(i=0 ; i<NODE_MAX_KIDS ; i++) 
  550. X        duel_free_nodes(n->kids[i]);
  551. X    duel_free_val_list(&n->eval.vlist);
  552. X    duel_free(n);
  553. X}
  554. X
  555. X
  556. X
  557. X/* Aliases management */
  558. X
  559. Xtypedef struct sduel_var {      /* an alias */
  560. X    char *name ;
  561. X    tvalue val ;
  562. X    struct sduel_var *next ;
  563. X } tduel_var ;
  564. Xtduel_var *duel_vars_head ;
  565. X
  566. X/* find the value of a duel variable, if exist (else return null */
  567. X
  568. XFUNC tvalue* duel_find_alias(char *name)
  569. X{
  570. X   tduel_var *p ;
  571. X   for(p=duel_vars_head ; p ; p=p->next) {
  572. X        if(strcmp(name,p->name)==0) return(&p->val);
  573. X   }
  574. X   return NULL ;
  575. X}
  576. X
  577. X/* set a value of a duel alias. Create var as needed */
  578. X
  579. XPROC duel_set_alias(char *name,tvalue *v)
  580. X{
  581. X   tduel_var *p ;
  582. X   tvalue *found = duel_find_alias(name) ;
  583. X   if(found!=NULL) *found= *v ;
  584. X   else {
  585. X     p=duel_malloc(sizeof(tduel_var)) ;
  586. X     p->next=duel_vars_head ;
  587. X     p->val= *v ;
  588. X     p->name=name ;
  589. X     duel_vars_head=p ;
  590. X  }
  591. X}
  592. X
  593. XPROC duel_clear_aliases(void)   /* clear all defined aliases */
  594. X{
  595. X   tduel_var *p=duel_vars_head ;
  596. X   while(p) {
  597. X        tduel_var *q=p ;
  598. X        p=p->next ;
  599. X        duel_free(q);
  600. X    }
  601. X   duel_vars_head=0 ;
  602. X}
  603. X
  604. XPROC duel_show_aliases(void)
  605. X{
  606. X   tduel_var *p ;
  607. X   if(!duel_vars_head) printf("No aliases defined\n");
  608. X   else {
  609. X     printf("Aliases table:\n");
  610. X     for(p=duel_vars_head ; p ; p=p->next) {
  611. X        printf("%s:  ",p->name);
  612. X        duel_print_value(&p->val);
  613. X        printf("\n");
  614. X     }
  615. X   }
  616. X}
  617. X
  618. X
  619. X
  620. SHAR_EOF
  621. $TOUCH -am 0113165193 src/misc.c &&
  622. chmod 0644 src/misc.c ||
  623. echo "restore of src/misc.c failed"
  624. set `wc -c src/misc.c`;Wc_c=$1
  625. if test "$Wc_c" != "3378"; then
  626.     echo original size 3378, current size $Wc_c
  627. fi
  628. # ============= src/duelself.c ==============
  629. echo "x - extracting src/duelself.c (Text)"
  630. sed 's/^X//' << 'SHAR_EOF' > src/duelself.c &&
  631. X/*   DUEL - A Very High Level Debugging Langauge.  */
  632. X/*   Public domain code                       */
  633. X/*   Written by Michael Golan mg@cs.princeton.edu  */
  634. X/*$Header: /tmp_mnt/n/fs/grad2/mg/duel/RCS/duelself.c,v 1.3 93/01/13 16:21:40 mg Exp $*/
  635. X
  636. X/* self-debugger module, it contains all of duel's access to
  637. X * the outside world (like duelgdb.c), but is intended to work when duel
  638. X * is linked with the debuggee directly (not with the debugger!)
  639. X * if you link this with duel.a, you get a test suite of duel
  640. X * for the C program: (tsuite.c)
  641. X *
  642. X * int gint ;
  643. X * typedef unsigned int uint ;
  644. X * void main() { 
  645. X *    printf ; malloc ;     / * include them in bin * /
  646. X *    char *s="main string" ; 
  647. X * }
  648. X *
  649. X * You could link this module with your own program and call it at
  650. X * "appropriate places", then ship the program with this code, and
  651. X * use duel at client's site when a crash occurs. However, reading in
  652. X * the symbol table and figuring out the active frames remains a problem.
  653. X */
  654. X
  655. X/*
  656. X * $Log:    duelself.c,v $
  657. X * Revision 1.3  93/01/13  16:21:40  mg
  658. X * made sure printf is declared
  659. X * 
  660. X * Revision 1.2  93/01/12  21:31:01  mg
  661. X * brought uptodate with duelgdb.c
  662. X * cleanup and set for release
  663. X * 
  664. X */
  665. X/* include system dependent stuff here */
  666. X
  667. X#include "duel.h"
  668. Xvoid main(int argc,char **argv);
  669. X
  670. X
  671. XFUNC void* duel_malloc(size_t size)
  672. X{
  673. X  void *p=malloc(size);
  674. X  if(p==0) duel_fatal("out of memory.");
  675. X  return p;
  676. X}
  677. X
  678. XPROC duel_free(void *p)
  679. X{
  680. X   free(p);
  681. X}
  682. X/* fetch n bytes from the target at the given memory address.
  683. X * the address to fetch from is given by (from).
  684. X * the value is stored at the 'to' location, which points to space for
  685. X * n bytes in the debugger.
  686. X * if the address can not be accessed, false is returned (if all ok, ret true)
  687. X */
  688. X
  689. XFUNC bool duel_get_target_bytes(ttarget_ptr from,void *to,size_t n)
  690. X{
  691. X  duel_bcopy(to,from,n);
  692. X  return TRUE ;
  693. X}
  694. X
  695. X/* store n bytes to the debuggee. reverse parms from above */
  696. XFUNC bool duel_put_target_bytes(ttarget_ptr to,void *from,size_t n)
  697. X{
  698. X   duel_bcopy(to,from,n);
  699. X   return TRUE ;
  700. X}
  701. X
  702. X/* fetch the value of a bitfield of a given structure. */
  703. X
  704. XFUNC bool duel_get_target_bitfield(ttarget_ptr struct_at,int bitpos,
  705. X                                    int bitlen,void *to,tctype_kind tkind)
  706. X{
  707. X    return FALSE ; /* not supported in duelself */
  708. X}
  709. X
  710. X/* make a function call to the target. */
  711. X/* support only passing/returing sizeof(int) upto 5 paramaters */
  712. XPROC duel_target_func_call(tvalue *func, tvalue *parms[],
  713. X                            int parms_no,tvalue *rval)
  714. X{
  715. X    int (*f)();
  716. X    int i ;
  717. X    if(parms_no>5) duel_fatal("too many parms");
  718. X    if(sizeof(func->ctype->u.kid)!=sizeof(int) && 
  719. X       func->ctype->u.kid!=ctype_void ) duel_fatal("unsupported func parm");
  720. X    for(i=0 ; i<parms_no ; i++) {
  721. X    if(parms[i]->val_kind!=VK_RVALUE || parms[i]->ctype->size!=sizeof(int))
  722. X        duel_fatal("unsupported paramater");
  723. X    }
  724. X    f=(int (*)()) func->u.lvalue ;
  725. X    switch(parms_no) {
  726. X      case 0:
  727. X    rval->u.rval_int= (*f)();
  728. X      break ;
  729. X      case 1:
  730. X    rval->u.rval_int= (*f)(parms[0]->u.rval_int);
  731. X      break ;
  732. X      case 2:
  733. X    rval->u.rval_int= (*f)(parms[0]->u.rval_int,parms[1]->u.rval_int);
  734. X      break ;
  735. X      case 3:
  736. X    rval->u.rval_int= (*f)(parms[0]->u.rval_int,parms[1]->u.rval_int,
  737. X          parms[2]->u.rval_int);
  738. X      break ;
  739. X      case 4:
  740. X    rval->u.rval_int= (*f)(parms[0]->u.rval_int,parms[1]->u.rval_int,
  741. X          parms[2]->u.rval_int,parms[3]->u.rval_int);
  742. X      break ;
  743. X      case 5:
  744. X    rval->u.rval_int= (*f)(parms[0]->u.rval_int,parms[1]->u.rval_int,
  745. X          parms[2]->u.rval_int,parms[3]->u.rval_int,parms[4]->u.rval_int);
  746. X      break ;
  747. X    }
  748. X    rval->val_kind=VK_RVALUE ;
  749. X    rval->ctype=func->ctype->u.kid ;
  750. X}
  751. X
  752. X/* find debuggee variable.
  753. X * recognize main.s, gint, malloc, printf
  754. X */
  755. X
  756. Xint gint ;    /* global variable recognized */
  757. Xchar **main_s ;    /* point to main's 's' */
  758. X
  759. XFUNC bool duel_get_target_variable(char *name, int frame_no, tvalue *v)
  760. X{
  761. X   v->val_kind=VK_LVALUE ;
  762. X   if(frame_no<=0 && strcmp(name,"s")==0) {
  763. X       v->ctype=duel_mkctype_ptr(ctype_char);
  764. X       v->u.lvalue = (void*) main_s ;
  765. X       return TRUE ;
  766. X   }
  767. X   if(frame_no != -1) return FALSE ;
  768. X   if(strcmp(name,"main")==0) {
  769. X       v->ctype=duel_mkctype_func(ctype_void);
  770. X       v->u.lvalue = (void*) main ;
  771. X       return TRUE ;
  772. X   }
  773. X   if(strcmp(name,"malloc")==0) {
  774. X       v->ctype=duel_mkctype_func(duel_mkctype_ptr(ctype_void));
  775. X       v->u.lvalue = (void*) malloc ;
  776. X       return TRUE ;
  777. X   }
  778. X   if(strcmp(name,"printf")==0) {
  779. X       if(0) printf("");  /* "declare" print */
  780. X       v->ctype=duel_mkctype_func(ctype_int);
  781. X       v->u.lvalue = (void*) printf ;
  782. X       return TRUE ;
  783. X   }
  784. X   if(strcmp(name,"gint")!=0) return FALSE ;
  785. X   v->ctype= ctype_int ;  /* type of this variable */
  786. X   v->u.lvalue= (void*) &gint ;   /* address of variable   */
  787. X   return TRUE ;
  788. X}
  789. X
  790. X
  791. XFUNC int duel_get_frames_number(void)
  792. X{
  793. X    return 1 ; /* main */
  794. X}
  795. X
  796. X
  797. XFUNC ttarget_ptr duel_get_function_for_frame(int frame_no)
  798. X{
  799. X    if(frame_no==0) return (void*) main ;
  800. X    else duel_fatal("bad frame number - internal err");
  801. X}
  802. X
  803. XFUNC tctype* duel_get_target_typedef(char *name)
  804. X{
  805. X    if(strcmp(name,"uint")==0) return ctype_uint ;
  806. X    return NULL ;
  807. X}
  808. X
  809. XFUNC tctype* duel_get_target_struct_tag(char *name) { return 0 ; }
  810. XFUNC tctype* duel_get_target_union_tag(char *name)  { return 0 ; }
  811. XFUNC tctype* duel_get_target_enum_tag(char *name)   { return 0 ; }
  812. X
  813. Xvoid main(int argc,char **argv)
  814. X{
  815. X   char *s="main string" ;
  816. X   main_s = &s ;        /* put s into the "symbol tbl" */
  817. X
  818. X   while(1) {
  819. X       char in[120] ;
  820. X       gets(in);
  821. X       if(feof(stdin)) break ;
  822. X       printf("dl> %s\n",in);
  823. X       if(in[0]==0 || in[0]=='#' && in[1]=='#') continue ;  /* comments */
  824. X       duel_parse_and_eval(in);
  825. X   }
  826. X}
  827. SHAR_EOF
  828. $TOUCH -am 0113165193 src/duelself.c &&
  829. chmod 0644 src/duelself.c ||
  830. echo "restore of src/duelself.c failed"
  831. set `wc -c src/duelself.c`;Wc_c=$1
  832. if test "$Wc_c" != "5695"; then
  833.     echo original size 5695, current size $Wc_c
  834. fi
  835. # ============= src/tsuite.c ==============
  836. echo "x - extracting src/tsuite.c (Text)"
  837. sed 's/^X//' << 'SHAR_EOF' > src/tsuite.c &&
  838. X#include <stdlib.h>
  839. X#include <stdio.h>
  840. X
  841. Xint gint ;
  842. Xtypedef unsigned int uint ;
  843. X
  844. Xvoid main() 
  845. X{ 
  846. X    char *s="main string" ; 
  847. X    FILE *out=stdout ;    /* stdout is not a variable */
  848. X                /* use fflush(out) from debugger */
  849. X    malloc ;
  850. X    printf("trivial tsuite program\n");
  851. X}
  852. SHAR_EOF
  853. $TOUCH -am 0113170393 src/tsuite.c &&
  854. chmod 0644 src/tsuite.c ||
  855. echo "restore of src/tsuite.c failed"
  856. set `wc -c src/tsuite.c`;Wc_c=$1
  857. if test "$Wc_c" != "262"; then
  858.     echo original size 262, current size $Wc_c
  859. fi
  860. # ============= src/tsuite.gdb ==============
  861. echo "x - extracting src/tsuite.gdb (Text)"
  862. sed 's/^X//' << 'SHAR_EOF' > src/tsuite.gdb &&
  863. Xset prompt
  864. X##   DUEL - A Very High Level Debugging Langauge.
  865. X##   Public domain code
  866. X##   Written by Michael Golan mg@cs.princeton.edu
  867. X##$Header$
  868. X##
  869. X## test suite for duel, can be used with duelself or gdb
  870. X## 
  871. Xfile tsuite
  872. Xb main
  873. Xr
  874. Xn
  875. Xn
  876. X## check constants 
  877. Xdl (1..5)*(2,(double) 2/3)
  878. X## declare array x, set it, search it
  879. Xdl int x[100] ; 
  880. Xdl x[0..99]= -1 ;
  881. Xdl x[i:=20..40]=2+i*i ;
  882. Xdl x[20..23,38..40]
  883. Xdl x[..100] >=? 33*33 <=? 35*35 
  884. Xdl x[..100]=> ((_>=33*33) & (_<= 35*35)) ==? 1
  885. Xdl (*(x+(7..9)))++
  886. Xdl y:= &x[7] ;
  887. Xdl y[0..2]
  888. Xdl x+7 == y
  889. Xdl (x[..99]>?0)@(_>100)
  890. Xdl printf("x is: "); printf("%d, ",x[0..99]>? 0); printf("\n");fflush(out);
  891. Xdl int j ; for(j=0 ; j<100 ; j++) if(x[j]>37*37) printf("x[%d]=%d\n",j,x[j]);fflush(out);
  892. X## errors
  893. Xdl i=4 ;
  894. Xdl x=6 ;
  895. Xdl x++ ;
  896. Xdl --i ;
  897. X## cleanup
  898. Xdl alias
  899. Xdl clear
  900. X## access some variables
  901. Xdl s
  902. Xdl s[4..8]
  903. Xdl s[6..]@0
  904. Xdl l:=#/s[0..]@0
  905. Xdl s[l-2..l]
  906. Xdl gint 
  907. Xdl gint++
  908. Xdl gint++
  909. Xdl --gint 
  910. Xdl gint 
  911. Xdl main.s 
  912. Xdl ++main.s
  913. Xdl main ==? main
  914. Xdl main == main
  915. Xdl frames_no
  916. Xdl frame(0).s
  917. Xdl frame(0).gint
  918. Xdl frame(0).(gint)
  919. Xdl T uint myuint ; myuint = -1 
  920. X## some errors 
  921. Xdl main == printf
  922. Xdl main+1
  923. Xdl main > printf
  924. Xdl printf+3
  925. Xdl T int x
  926. Xdl uint y
  927. Xdl T uint z = 5
  928. X## the end
  929. X
  930. SHAR_EOF
  931. $TOUCH -am 0113163293 src/tsuite.gdb &&
  932. chmod 0644 src/tsuite.gdb ||
  933. echo "restore of src/tsuite.gdb failed"
  934. set `wc -c src/tsuite.gdb`;Wc_c=$1
  935. if test "$Wc_c" != "1206"; then
  936.     echo original size 1206, current size $Wc_c
  937. fi
  938. # ============= src/tsuite.self ==============
  939. echo "x - extracting src/tsuite.self (Text)"
  940. sed 's/^X//' << 'SHAR_EOF' > src/tsuite.self &&
  941. X##   DUEL - A Very High Level Debugging Langauge.
  942. X##   Public domain code
  943. X##   Written by Michael Golan mg@cs.princeton.edu
  944. X##$Header$
  945. X
  946. X##
  947. X## test suite for duel, can be used with duelself or gdb
  948. X## 
  949. X
  950. X## check constants 
  951. X(1..5)*(2,(double) 2/3)
  952. X
  953. X## declare array x, set it, search it
  954. X
  955. Xint x[100] ; 
  956. Xx[0..99]= -1 ;
  957. Xx[i:=20..40]=2+i*i ;
  958. Xx[20..23,38..40]
  959. Xx[..100] >=? 33*33 <=? 35*35 
  960. Xx[..100]=> ((_>=33*33) & (_<= 35*35)) ==? 1
  961. Xx
  962. Xx+5
  963. X*(x+7..9)++
  964. X*(x+(7..9))++
  965. X(*(x+(7..9)))++
  966. Xy:= &x[7] ;
  967. Xy[0..2]
  968. Xx+7 == y
  969. X(x[..99]>?0)@(_>100)
  970. X
  971. Xprintf("x is: "); printf("%d, ",x[0..99]>? 0); printf("\n");
  972. Xint j ; for(j=0 ; j<100 ; j++) if(x[j]>37*37) printf("x[%d]=%d\n",j,x[j]);
  973. X
  974. X## errors
  975. X
  976. X&x
  977. Xi=4 ;
  978. Xx=6 ;
  979. Xx++ ;
  980. X--i ;
  981. X
  982. X## cleanup
  983. X
  984. Xalias
  985. Xclear
  986. X
  987. X## access some variables
  988. Xs
  989. Xs[4..8]
  990. Xs[6..]@0
  991. Xl:=#/s[0..]@0
  992. Xs[l-2..l]
  993. X
  994. Xgint 
  995. Xgint++
  996. Xgint++
  997. X--gint 
  998. Xgint 
  999. Xmain.s 
  1000. Xmain.s++
  1001. Xmain.s++
  1002. X
  1003. Xmain
  1004. Xprintf
  1005. Xmain ==? main
  1006. Xmain == main
  1007. X
  1008. Xframes_no
  1009. Xframe(0).s
  1010. Xframe(0).gint
  1011. Xframe(0).(gint)
  1012. X
  1013. XT uint myuint ; myuint = -1 
  1014. X
  1015. X## some errors 
  1016. X
  1017. Xmain == printf
  1018. Xmain+1
  1019. Xmain > printf
  1020. X
  1021. Xmalloc[4]
  1022. X
  1023. Xprintf+3
  1024. X
  1025. XT int x
  1026. Xuint y
  1027. XT uint z = 5
  1028. X
  1029. X## the end
  1030. X
  1031. X
  1032. SHAR_EOF
  1033. $TOUCH -am 0113163293 src/tsuite.self &&
  1034. chmod 0644 src/tsuite.self ||
  1035. echo "restore of src/tsuite.self failed"
  1036. set `wc -c src/tsuite.self`;Wc_c=$1
  1037. if test "$Wc_c" != "1095"; then
  1038.     echo original size 1095, current size $Wc_c
  1039. fi
  1040. # ============= src/tsuite.gdb.out ==============
  1041. echo "x - extracting src/tsuite.gdb.out (Text)"
  1042. sed 's/^X//' << 'SHAR_EOF' > src/tsuite.gdb.out &&
  1043. XGDB is free software and you are welcome to distribute copies of it
  1044. X under certain conditions; type "show copying" to see the conditions.
  1045. XThere is absolutely no warranty for GDB; type "show warranty" for details.
  1046. XGDB 4.6, Copyright 1992 Free Software Foundation, Inc.
  1047. X(gdb)         Reading symbols from tsuite...done.
  1048. X Breakpoint 1 at 0x4001b8: file tsuite.c, line 9.
  1049. X Starting program: /tmp_mnt/n/fs/grad2/mg/duel/tsuite/tsuite 
  1050. X
  1051. XBreakpoint 1, main () at tsuite.c:9
  1052. X9        char *s="main string" ; 
  1053. X 10        FILE *out=stdout ;    /* stdout is not a variable */
  1054. X 13        printf("trivial tsuite program\n");
  1055. X  DUEL 1.00.0, public domain debugging language. "dl" for help
  1056. X1*2 = 2
  1057. X1*(2/3) = 0.66666667
  1058. X2*2 = 4
  1059. X2*(2/3) = 1.33333333
  1060. X3*2 = 6
  1061. X3*(2/3) = 2.0
  1062. X4*2 = 8
  1063. X4*(2/3) = 2.66666667
  1064. X5*2 = 10
  1065. X5*(2/3) = 3.33333333
  1066. X     x[20] = 402
  1067. Xx[21] = 443
  1068. Xx[22] = 486
  1069. Xx[23] = 531
  1070. Xx[38] = 1446
  1071. Xx[39] = 1523
  1072. Xx[40] = 1602
  1073. X x[33] = 1091
  1074. Xx[34] = 1158
  1075. X (x[33]>=33*33)&(x[33]<=35*35) = 1
  1076. X(x[34]>=33*33)&(x[34]<=35*35) = 1
  1077. X (*(x+7))++ = -1
  1078. X(*(x+8))++ = -1
  1079. X(*(x+9))++ = -1
  1080. X  y[0] = 0
  1081. Xy[1] = 0
  1082. Xy[2] = 0
  1083. X x+7==y = 1
  1084. X  x is: 402, 443, 486, 531, 578, 627, 678, 731, 786, 843, 902, 963, 1026, 1091, 1158, 1227, 1298, 1371, 1446, 1523, 1602, 
  1085. X x[37]=1371
  1086. Xx[38]=1446
  1087. Xx[39]=1523
  1088. Xx[40]=1602
  1089. X  Error:   i=4 ;
  1090. X         -^-- left size not an lvalue for operator '='
  1091. Xoperand ``i''     -- type: int 
  1092. X        -- value: 40
  1093. X Error:   x=6 ;
  1094. X         -^-- bad left operand type for operator '='
  1095. Xoperand ``x''     -- type: int [100] 
  1096. X        -- value: array @10002000
  1097. X Error:   x++ ;
  1098. X         -^-- operand x of '++' is not integral
  1099. Xoperand ``x''     -- type: int [100] 
  1100. X        -- value: array @10002000
  1101. X Error:   --i ;
  1102. X         ^-- operand of '--' must be an lvalue
  1103. Xoperand ``i''     -- type: int 
  1104. X        -- value: 40
  1105. X  Aliases table:
  1106. Xj:  j = 100
  1107. Xy:  &x[7] = @1000201c
  1108. Xi:  40
  1109. Xx:  x = array @10002000
  1110. X Aliases table cleared
  1111. X  s = "main string"
  1112. X s[4] = ' '
  1113. Xs[5] = 's'
  1114. Xs[6] = 't'
  1115. Xs[7] = 'r'
  1116. Xs[8] = 'i'
  1117. X s[6] = 't'
  1118. Xs[7] = 'r'
  1119. Xs[8] = 'i'
  1120. Xs[9] = 'n'
  1121. Xs[10] = 'g'
  1122. X 11
  1123. X s[9] = 'n'
  1124. Xs[10] = 'g'
  1125. Xs[11] = '\0'
  1126. X gint = 0
  1127. X gint++ = 0
  1128. X gint++ = 1
  1129. X gint = 1
  1130. X gint = 1
  1131. X main.s = "main string"
  1132. X main.s = "ain string"
  1133. X main = func @004001b0
  1134. X main==main = 1
  1135. X frames_no = 1
  1136. X frame(0).s = "ain string"
  1137. X Error:   frame(0).gint
  1138. X         --------^-- field not found in operator '.'
  1139. Xoperand ``frame(0)''     -- type: int 
  1140. X        -- value: frame(0)
  1141. X frame(0).gint = 1
  1142. X -1 = 0xffffffff
  1143. X  Error:   main == printf
  1144. X         -----^-- incompatible types for op ==
  1145. Xoperand1 ``main''     -- type: ptr to func returning void 
  1146. X        -- value: @004001b0
  1147. Xoperand2 ``printf''     -- type: ptr to func returning int 
  1148. X        -- value: @004004a0
  1149. X Error:   main+1
  1150. X         ----^-- unknown pointer object size for '+' op
  1151. Xoperand ``main''     -- type: ptr to func returning void 
  1152. X        -- value: @004001b0
  1153. X Error:   main > printf
  1154. X         -----^-- incompatible types for op >
  1155. Xoperand1 ``main''     -- type: ptr to func returning void 
  1156. X        -- value: @004001b0
  1157. Xoperand2 ``printf''     -- type: ptr to func returning int 
  1158. X        -- value: @004004a0
  1159. X Error:   printf+3
  1160. X         ------^-- unknown pointer object size for '+' op
  1161. Xoperand ``printf''     -- type: ptr to func returning int 
  1162. X        -- value: @004004a0
  1163. X T int x
  1164. X-----^ syntax error
  1165. X uint y
  1166. X------^ syntax error
  1167. X T uint z = 5
  1168. X----------^ syntax error
  1169. X   
  1170. SHAR_EOF
  1171. $TOUCH -am 0113163293 src/tsuite.gdb.out &&
  1172. chmod 0644 src/tsuite.gdb.out ||
  1173. echo "restore of src/tsuite.gdb.out failed"
  1174. set `wc -c src/tsuite.gdb.out`;Wc_c=$1
  1175. if test "$Wc_c" != "3214"; then
  1176.     echo original size 3214, current size $Wc_c
  1177. fi
  1178. # ============= src/tsuite.self.out ==============
  1179. echo "x - extracting src/tsuite.self.out (Text)"
  1180. sed 's/^X//' << 'SHAR_EOF' > src/tsuite.self.out &&
  1181. Xdl> ##   DUEL - A Very High Level Debugging Langauge.
  1182. Xdl> ##   Public domain code
  1183. Xdl> ##   Written by Michael Golan mg@cs.princeton.edu
  1184. Xdl> ##$Header$
  1185. Xdl> 
  1186. Xdl> ##
  1187. Xdl> ## test suite for duel, can be used with duelself or gdb
  1188. Xdl> ## 
  1189. Xdl> 
  1190. Xdl> ## check constants 
  1191. Xdl> (1..5)*(2,(double) 2/3)
  1192. XDUEL 1.00.0, public domain debugging language. "dl" for help
  1193. X1*2 = 2
  1194. X1*(2/3) = 0.66666667
  1195. X2*2 = 4
  1196. X2*(2/3) = 1.33333333
  1197. X3*2 = 6
  1198. X3*(2/3) = 2.0
  1199. X4*2 = 8
  1200. X4*(2/3) = 2.66666667
  1201. X5*2 = 10
  1202. X5*(2/3) = 3.33333333
  1203. Xdl> 
  1204. Xdl> ## declare array x, set it, search it
  1205. Xdl> 
  1206. Xdl> int x[100] ; 
  1207. Xdl> x[0..99]= -1 ;
  1208. Xdl> x[i:=20..40]=2+i*i ;
  1209. Xdl> x[20..23,38..40]
  1210. Xx[20] = 402
  1211. Xx[21] = 443
  1212. Xx[22] = 486
  1213. Xx[23] = 531
  1214. Xx[38] = 1446
  1215. Xx[39] = 1523
  1216. Xx[40] = 1602
  1217. Xdl> x[..100] >=? 33*33 <=? 35*35 
  1218. Xx[33] = 1091
  1219. Xx[34] = 1158
  1220. Xdl> x[..100]=> ((_>=33*33) & (_<= 35*35)) ==? 1
  1221. X(x[33]>=33*33)&(x[33]<=35*35) = 1
  1222. X(x[34]>=33*33)&(x[34]<=35*35) = 1
  1223. Xdl> x
  1224. Xx = array @10014000
  1225. Xdl> x+5
  1226. Xx+5 = @10014014
  1227. Xdl> *(x+7..9)++
  1228. XError:   *(x+7..9)++
  1229. X         -----^-- operand x of 'x..y' is not integral
  1230. Xoperand ``x+7''     -- type: int * 
  1231. X        -- value: @1001401c
  1232. Xdl> *(x+(7..9))++
  1233. XError:   *(x+(7..9))++
  1234. X         -----------^-- operand of '++' must be an lvalue
  1235. Xoperand ``(x+7)''     -- type: int * 
  1236. X        -- value: @1001401c
  1237. Xdl> (*(x+(7..9)))++
  1238. X(*(x+7))++ = -1
  1239. X(*(x+8))++ = -1
  1240. X(*(x+9))++ = -1
  1241. Xdl> y:= &x[7] ;
  1242. Xdl> y[0..2]
  1243. Xy[0] = 0
  1244. Xy[1] = 0
  1245. Xy[2] = 0
  1246. Xdl> x+7 == y
  1247. Xx+7==y = 1
  1248. Xdl> (x[..99]>?0)@(_>100)
  1249. Xdl> 
  1250. Xdl> printf("x is: "); printf("%d, ",x[0..99]>? 0); printf("\n");
  1251. Xx is: 402, 443, 486, 531, 578, 627, 678, 731, 786, 843, 902, 963, 1026, 1091, 1158, 1227, 1298, 1371, 1446, 1523, 1602, 
  1252. Xdl> int j ; for(j=0 ; j<100 ; j++) if(x[j]>37*37) printf("x[%d]=%d\n",j,x[j]);
  1253. Xx[37]=1371
  1254. Xx[38]=1446
  1255. Xx[39]=1523
  1256. Xx[40]=1602
  1257. Xdl> 
  1258. Xdl> ## errors
  1259. Xdl> 
  1260. Xdl> &x
  1261. X&x = @10014000
  1262. Xdl> i=4 ;
  1263. XError:   i=4 ;
  1264. X         -^-- left size not an lvalue for operator '='
  1265. Xoperand ``i''     -- type: int 
  1266. X        -- value: 40
  1267. Xdl> x=6 ;
  1268. XError:   x=6 ;
  1269. X         -^-- bad left operand type for operator '='
  1270. Xoperand ``x''     -- type: int [100] 
  1271. X        -- value: array @10014000
  1272. Xdl> x++ ;
  1273. XError:   x++ ;
  1274. X         -^-- operand x of '++' is not integral
  1275. Xoperand ``x''     -- type: int [100] 
  1276. X        -- value: array @10014000
  1277. Xdl> --i ;
  1278. XError:   --i ;
  1279. X         ^-- operand of '--' must be an lvalue
  1280. Xoperand ``i''     -- type: int 
  1281. X        -- value: 40
  1282. Xdl> 
  1283. Xdl> ## cleanup
  1284. Xdl> 
  1285. Xdl> alias
  1286. XAliases table:
  1287. Xj:  j = 100
  1288. Xy:  &x[7] = @1001401c
  1289. Xi:  40
  1290. Xx:  x = array @10014000
  1291. Xdl> clear
  1292. XAliases table cleared
  1293. Xdl> 
  1294. Xdl> ## access some variables
  1295. Xdl> s
  1296. Xs = "main string"
  1297. Xdl> s[4..8]
  1298. Xs[4] = ' '
  1299. Xs[5] = 's'
  1300. Xs[6] = 't'
  1301. Xs[7] = 'r'
  1302. Xs[8] = 'i'
  1303. Xdl> s[6..]@0
  1304. Xs[6] = 't'
  1305. Xs[7] = 'r'
  1306. Xs[8] = 'i'
  1307. Xs[9] = 'n'
  1308. Xs[10] = 'g'
  1309. Xdl> l:=#/s[0..]@0
  1310. X11
  1311. Xdl> s[l-2..l]
  1312. Xs[9] = 'n'
  1313. Xs[10] = 'g'
  1314. Xs[11] = '\0'
  1315. Xdl> 
  1316. Xdl> gint 
  1317. Xgint = 0
  1318. Xdl> gint++
  1319. Xgint++ = 0
  1320. Xdl> gint++
  1321. Xgint++ = 1
  1322. Xdl> --gint 
  1323. Xgint = 1
  1324. Xdl> gint 
  1325. Xgint = 1
  1326. Xdl> main.s 
  1327. Xmain.s = "main string"
  1328. Xdl> main.s++
  1329. Xmain.s++ = "main string"
  1330. Xdl> main.s++
  1331. Xmain.s++ = "ain string"
  1332. Xdl> 
  1333. Xdl> main
  1334. Xmain = func @00400918
  1335. Xdl> printf
  1336. Xprintf = func @00410670
  1337. Xdl> main ==? main
  1338. Xmain = func @00400918
  1339. Xdl> main == main
  1340. Xmain==main = 1
  1341. Xdl> 
  1342. Xdl> frames_no
  1343. Xframes_no = 1
  1344. Xdl> frame(0).s
  1345. Xframe(0).s = "in string"
  1346. Xdl> frame(0).gint
  1347. XError:   frame(0).gint
  1348. X         --------^-- field not found in operator '.'
  1349. Xoperand ``frame(0)''     -- type: int 
  1350. X        -- value: frame(0)
  1351. Xdl> frame(0).(gint)
  1352. Xframe(0).gint = 1
  1353. Xdl> 
  1354. Xdl> T uint myuint ; myuint = -1 
  1355. X-1 = 0xffffffff
  1356. Xdl> 
  1357. Xdl> ## some errors 
  1358. Xdl> 
  1359. Xdl> main == printf
  1360. XError:   main == printf
  1361. X         -----^-- incompatible types for op ==
  1362. Xoperand1 ``main''     -- type: ptr to func returning void 
  1363. X        -- value: @00400918
  1364. Xoperand2 ``printf''     -- type: ptr to func returning int 
  1365. X        -- value: @00410670
  1366. Xdl> main+1
  1367. XError:   main+1
  1368. X         ----^-- unknown pointer object size for '+' op
  1369. Xoperand ``main''     -- type: ptr to func returning void 
  1370. X        -- value: @00400918
  1371. Xdl> main > printf
  1372. XError:   main > printf
  1373. X         -----^-- incompatible types for op >
  1374. Xoperand1 ``main''     -- type: ptr to func returning void 
  1375. X        -- value: @00400918
  1376. Xoperand2 ``printf''     -- type: ptr to func returning int 
  1377. X        -- value: @00410670
  1378. Xdl> 
  1379. Xdl> malloc[4]
  1380. XError:   malloc[4]
  1381. X         ------^-- unknown pointer object size for '+' op
  1382. Xoperand ``malloc''     -- type: ptr to func returning void * 
  1383. X        -- value: @004106d0
  1384. Xdl> 
  1385. Xdl> printf+3
  1386. XError:   printf+3
  1387. X         ------^-- unknown pointer object size for '+' op
  1388. Xoperand ``printf''     -- type: ptr to func returning int 
  1389. X        -- value: @00410670
  1390. Xdl> 
  1391. Xdl> T int x
  1392. XT int x
  1393. X-----^ syntax error
  1394. Xdl> uint y
  1395. Xuint y
  1396. X------^ syntax error
  1397. Xdl> T uint z = 5
  1398. XT uint z = 5
  1399. X----------^ syntax error
  1400. Xdl> 
  1401. Xdl> ## the end
  1402. Xdl> 
  1403. Xdl> 
  1404. SHAR_EOF
  1405. $TOUCH -am 0113163293 src/tsuite.self.out &&
  1406. chmod 0644 src/tsuite.self.out ||
  1407. echo "restore of src/tsuite.self.out failed"
  1408. set `wc -c src/tsuite.self.out`;Wc_c=$1
  1409. if test "$Wc_c" != "4576"; then
  1410.     echo original size 4576, current size $Wc_c
  1411. fi
  1412. exit 0
  1413.