home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume15 / dmake-3.6 / part23 < prev    next >
Text File  |  1990-10-14  |  40KB  |  1,345 lines

  1. Newsgroups: comp.sources.misc
  2. X-UNIX-From: dvadura@watdragon.waterloo.edu
  3. subject: v15i075: dmake version 3.6 (part 23/25)
  4. from: Dennis Vadura <dvadura@watdragon.waterloo.edu>
  5. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  6.  
  7. Posting-number: Volume 15, Issue 75
  8. Submitted-by: Dennis Vadura <dvadura@watdragon.waterloo.edu>
  9. Archive-name: dmake-3.6/part23
  10.  
  11. #!/bin/sh
  12. # this is part 23 of a multipart archive
  13. # do not concatenate these parts, unpack them in order with /bin/sh
  14. # file common/malloc.c continued
  15. #
  16. CurArch=23
  17. if test ! -r s2_seq_.tmp
  18. then echo "Please unpack part 1 first!"
  19.      exit 1; fi
  20. ( read Scheck
  21.   if test "$Scheck" != $CurArch
  22.   then echo "Please unpack part $Scheck next!"
  23.        exit 1;
  24.   else exit 0; fi
  25. ) < s2_seq_.tmp || exit 1
  26. echo "x - Continuing file common/malloc.c"
  27. sed 's/^X//' << 'SHAR_EOF' >> common/malloc.c
  28. X
  29. X   free( ptr );
  30. X}
  31. X
  32. X
  33. Xchar *
  34. XMy_malloc( n, fil, line )/*
  35. X===========================
  36. X   A routine that check alloc */
  37. Xunsigned int n;
  38. Xchar *fil;
  39. Xint  line;
  40. X{
  41. X#ifdef DB_MALLOC
  42. X   _malldstr( "alloc: file:" );
  43. X   _malldstr( fil );
  44. X   _malldstr( " line: " );
  45. X   _dbdumpint( line );
  46. X   _malldstr( " ::  " );
  47. X#endif
  48. X
  49. X   return( malloc( n ));
  50. X}
  51. X
  52. X
  53. X
  54. Xchar *
  55. XMy_calloc( n, size, fil, line )/*
  56. X=================================
  57. X   A routine that check alloc */
  58. Xunsigned int n;
  59. Xunsigned int size;
  60. Xchar *fil;
  61. Xint  line;
  62. X{
  63. X#ifdef DB_MALLOC
  64. X   _malldstr( "alloc: file:" );
  65. X   _malldstr( fil );
  66. X   _malldstr( " line: " );
  67. X   _dbdumpint( line );
  68. X   _malldstr( " ::  " );
  69. X#endif
  70. X
  71. X   return( calloc( n, size ));
  72. X}
  73. X
  74. X
  75. X
  76. X#ifdef DB_MALLOC
  77. X
  78. Xstruct _Dmi {
  79. X    struct _Dmi *m_next;
  80. X    struct _Dmi *m_prev;
  81. X    long m_size;
  82. X    char m_blk[1];
  83. X};
  84. X
  85. Xstatic struct _Dmi *_fab = (struct _Dmi *) 0;
  86. Xstatic struct _Dmi *_ffb = (struct _Dmi *) 0;
  87. Xstatic char *_xbrk = 0;
  88. Xstatic int _in_malloc = 0;
  89. Xstatic int _st_malloc = 0;
  90. Xint _mall_opt = 1;
  91. X
  92. X/*
  93. X * initialize stuff, we want to _malldmp() on a bus/seg error
  94. X */
  95. X
  96. Xstatic _mall_sig(sig) {
  97. X    if (sig == SIGSEGV)
  98. X        _malldstr("\nsegmentation violation\n\n");
  99. X    else if (sig == SIGBUS)
  100. X        _malldstr("\nbus error\n\n");
  101. X    else if (sig == SIGSYS)
  102. X        _malldstr("\ninvalid syscall arg\n\n");
  103. X    else {
  104. X        _malldstr("\nsignal ");
  105. X        _malldptr(sig);
  106. X        _malldstr("\n\n");
  107. X    }
  108. X    _malldmp();
  109. X    kill(getpid(), sig);
  110. X}
  111. X
  112. Xstatic _mall_init() {
  113. X    if (_st_malloc)
  114. X        return;
  115. X    signal(SIGSEGV, _mall_sig);
  116. X    signal(SIGBUS, _mall_sig);
  117. X    _st_malloc = 1;
  118. X}
  119. X
  120. X/*
  121. X * figure out which allocation block this pointer came from
  122. X * return NULL if none
  123. X */
  124. X
  125. Xstatic struct _Dmi *_mallgb(s)
  126. Xchar *s; {
  127. X    register struct _Dmi *blk;
  128. X
  129. X    for (blk = _fab; blk != (struct _Dmi *) 0; blk = blk->m_next)
  130. X        if (blk->m_blk == s)
  131. X            break;
  132. X    return blk;
  133. X}
  134. X
  135. X
  136. X/*
  137. X * internal: write a pointer in hex without using stdio
  138. X */
  139. X
  140. Xstatic _malldptr(x)
  141. Xregister long x; {
  142. X    char buf[20];
  143. X    static char hex[] = "0123456789abcdef";
  144. X    register long dx;
  145. X    register char *p;
  146. X
  147. X    if (x == 0)
  148. X        return _malldstr("0x0(0)");
  149. X    _malldstr("0x");
  150. X    p = buf;
  151. X    dx = x;
  152. X    while (x > 0)
  153. X        *p++ = hex[x % 16], x = x / 16;
  154. X    while (p != buf)
  155. X        write(2, --p, 1);
  156. X    _malldstr("(");
  157. X    p = buf;
  158. X    x = dx;
  159. X    while (x > 0)
  160. X        *p++ = hex[x % 10], x /= 10;
  161. X    while (p != buf)
  162. X        write(2, --p, 1);
  163. X    _malldstr(")");
  164. X}
  165. X
  166. X/*
  167. X * internal: dump a string
  168. X */
  169. X
  170. Xstatic _malldstr(s)
  171. Xregister char *s; {
  172. X    register int len;
  173. X
  174. X    for (len = 0; s[len] != '\0'; len++)
  175. X        ;
  176. X    write(2, s, len);
  177. X}
  178. X
  179. X
  180. Xstatic _dbdumpint(x)
  181. Xregister int x; {
  182. X    char buf[20];
  183. X    static char hex[] = "0123456789abcdef";
  184. X    register long dx;
  185. X    register char *p;
  186. X
  187. X    if (x == 0) return _malldstr("0");
  188. X    p = buf;
  189. X    while (x > 0)
  190. X        *p++ = hex[x % 10], x /= 10;
  191. X    while (p != buf)
  192. X        write(2, --p, 1);
  193. X}
  194. X
  195. X
  196. X/*
  197. X * dump arena; can be called externally, and is non-destructive
  198. X */
  199. X
  200. X_malldmp() {
  201. X    register struct _Dmi *blk;
  202. X    int oldf;
  203. X
  204. X    oldf = _in_malloc;
  205. X    _in_malloc = 0;
  206. X    _malldstr("brk = ");
  207. X    _malldptr(sbrk(0));
  208. X    _malldstr("  xbrk = ");
  209. X    _malldptr(_xbrk);
  210. X    _malldstr("\n_fab = ");
  211. X    _malldptr(_fab);
  212. X    _malldstr("  _ffb = ");
  213. X    _malldptr(_ffb);
  214. X    _malldstr("  blksiz = ");
  215. X    _malldptr(sizeof (struct _Dmi));
  216. X    _malldstr("\netext = ");
  217. X    _malldptr(etext);
  218. X    _malldstr("  edata = ");
  219. X    _malldptr(edata);
  220. X    _malldstr("  end = ");
  221. X    _malldptr(end);
  222. X    _malldstr("\n\nallocated blocks\n\n");
  223. X    if (_fab == (struct _Dmi *) 0)
  224. X        _malldstr("(none)\n");
  225. X    else {
  226. X        for (blk = _fab; blk != (struct _Dmi *) 0 && (char *) blk >= _xbrk && (char *) blk < sbrk(0); blk = blk->m_next) {
  227. X            _malldstr("(");
  228. X            _malldptr(blk);
  229. X            _malldstr(")  ");
  230. X            _malldptr(blk->m_prev);
  231. X            _malldstr("<  ");
  232. X            _malldptr(blk->m_size);
  233. X            _malldstr("  >");
  234. X            _malldptr(blk->m_next);
  235. X            _malldstr("\n");
  236. X        }
  237. X        if (blk != (struct _Dmi *) 0)
  238. X            _malldstr("(subsequent block pointers corrupted)\n");
  239. X    }
  240. X    _malldstr("\nfree blocks\n\n");
  241. X    if (_ffb == (struct _Dmi *) 0)
  242. X        _malldstr("(none)\n");
  243. X    else {
  244. X        for (blk = _ffb; blk != (struct _Dmi *) 0 && (char *) blk >= _xbrk && (char *) blk < sbrk(0); blk = blk->m_next) {
  245. X            _malldstr("(");
  246. X            _malldptr(blk);
  247. X            _malldstr(")  ");
  248. X            _malldptr(blk->m_prev);
  249. X            _malldstr("<  ");
  250. X            _malldptr(blk->m_size);
  251. X            _malldstr("  >");
  252. X            _malldptr(blk->m_next);
  253. X            _malldstr("\n");
  254. X        }
  255. X        if (blk != (struct _Dmi *) 0)
  256. X            _malldstr("(subsequent block pointers corrupted)\n");
  257. X    }
  258. X    _in_malloc = oldf;
  259. X}
  260. X
  261. X/*
  262. X * internal error routine: print error message (without using stdio) and
  263. X * drop core
  264. X */
  265. X
  266. Xstatic _mallerr(fn, s, ptr)
  267. Xchar *fn, *s;
  268. Xlong ptr; {
  269. X    _malldstr(fn);
  270. X    _malldstr(": ");
  271. X    _malldstr(s);
  272. X    _malldptr(ptr);
  273. X    _malldstr("\n");
  274. X    _malldmp();
  275. X    signal(SIGQUIT, SIG_DFL);
  276. X    kill(getpid(), SIGQUIT);
  277. X}
  278. X    
  279. Xchar *malloc(n )
  280. Xregister unsigned n;
  281. X{
  282. X    register struct _Dmi *blk;
  283. X
  284. X    _in_malloc = 1;
  285. X    _mall_init();
  286. X    if (_mall_opt)
  287. X    {
  288. X         _malldstr("malloc: size: " );
  289. X         _malldptr(n);
  290. X         _malldstr("\n");
  291. X    }
  292. X    _mallchk("malloc");
  293. X    if (n == 0) {
  294. X        _malldstr("malloc(0) is illegal!\n");
  295. X        _mall_sig(SIGSYS);
  296. X    }
  297. X    for (blk = _ffb; blk != (struct _Dmi *) 0; blk = blk->m_next)
  298. X        if (blk->m_size >= n) {
  299. X            if (blk->m_next != (struct _Dmi *) 0)
  300. X                blk->m_next->m_prev = blk->m_prev;
  301. X            if (blk->m_prev != (struct _Dmi *) 0)
  302. X                blk->m_prev->m_next = blk->m_next;
  303. X            if (blk == _ffb)
  304. X                _ffb = blk->m_next;
  305. X            blk->m_next = _fab;
  306. X            blk->m_prev = (struct _Dmi *) 0;
  307. X            if (_fab != (struct _Dmi *) 0)
  308. X                _fab->m_prev = blk;
  309. X            _fab = blk;
  310. X            _in_malloc = 0;
  311. X            return blk->m_blk;
  312. X        }
  313. X    if ((blk = (struct _Dmi *) sbrk(sizeof (struct _Dmi) + n - 1)) == (struct _Dmi *) -1) {
  314. X        _in_malloc = 0;
  315. X        return (char *) 0;    /* no space */
  316. X    }
  317. X    if (_xbrk == (char *) 0)
  318. X        _xbrk = (char *) blk;
  319. X    blk->m_next = _fab;
  320. X    blk->m_prev = (struct _Dmi *) 0;
  321. X    if (_fab != (struct _Dmi *) 0)
  322. X        _fab->m_prev = blk;
  323. X    _fab = blk;
  324. X    blk->m_size = n;
  325. X    _in_malloc = 0;
  326. X    return blk->m_blk;
  327. X}
  328. X
  329. X/* The free-block list is sorted in size order */
  330. X
  331. Xfree(s)
  332. Xregister char *s;
  333. X{
  334. X    register struct _Dmi *blk, *fblk;
  335. X    int didit;
  336. X
  337. X    _in_malloc = 1;
  338. X    _mall_init();
  339. X    if (_mall_opt)
  340. X    {
  341. X         _malldstr("free: ptr: ");
  342. X         _malldptr(s);
  343. X         _malldstr("\n");
  344. X    }
  345. X    _mallchk("free");
  346. X    if (s == (char *) 0) {
  347. X        _malldstr("free((char *) 0) is illegal!\n");
  348. X        _mall_sig(SIGSYS);
  349. X    }
  350. X    if ((blk = _mallgb(s)) == (struct _Dmi *) 0)
  351. X        _mallerr("non-allocated pointer passed to free(): ", s);
  352. X    if (blk->m_prev != (struct _Dmi *) 0)
  353. X        blk->m_prev->m_next = blk->m_next;
  354. X    if (blk->m_next != (struct _Dmi *) 0)
  355. X        blk->m_next->m_prev = blk->m_prev;
  356. X    if (blk == _fab)
  357. X        _fab = blk->m_next;
  358. X    if (_ffb == (struct _Dmi *) 0) {
  359. X        _ffb = blk;
  360. X        blk->m_next = (struct _Dmi *) 0;
  361. X        blk->m_prev = (struct _Dmi *) 0;
  362. X        goto crunch;
  363. X    }
  364. X    for (fblk = _ffb; fblk->m_next != (struct _Dmi *) 0; fblk = fblk->m_next)
  365. X        if (fblk->m_next->m_size >= blk->m_size)
  366. X            break;
  367. X    blk->m_next = fblk->m_next;
  368. X    if (fblk->m_next != (struct _Dmi *) 0)
  369. X        fblk->m_next->m_prev = blk;
  370. X    blk->m_prev = fblk;
  371. X    fblk->m_next = blk;
  372. X
  373. X/*
  374. X * crunch the free list by dropping consecutive end-of-brk until we hit xbrk
  375. X * or a "hole" (i.e. allocated block).  coalescing is possible but not supp-
  376. X * orted in malloc, so we don't bother here.
  377. X */
  378. X
  379. Xcrunch:
  380. X    didit = 1;
  381. X    while (_ffb != (struct _Dmi *) 0 && didit) {
  382. X        didit = 0;
  383. X        for (fblk = _ffb; fblk != (struct _Dmi *) 0; fblk = fblk->m_next)
  384. X            if ((char *) fblk + sizeof *fblk + fblk->m_size - 1 == sbrk(0)) {
  385. X                didit = 1;
  386. X                if (fblk->m_next != (struct _Dmi *) 0)
  387. X                    fblk->m_next->m_prev = fblk->m_prev;
  388. X                if (fblk->m_prev != (struct _Dmi *) 0)
  389. X                    fblk->m_prev->m_next = fblk->m_next;
  390. X                if (fblk == _ffb)
  391. X                    _ffb = fblk->m_next;
  392. X                sbrk(- fblk->m_size);
  393. X                break;
  394. X            }
  395. X    }
  396. X    _in_malloc = 0;
  397. X}
  398. X
  399. Xchar *realloc(s, n)
  400. Xregister char *s;
  401. Xregister unsigned n; {
  402. X    register char *s1, *d, *d1;
  403. X    register struct _Dmi *blk;
  404. X
  405. X    if (_mall_opt)
  406. X        _malldstr("called realloc("), _malldptr(s), _malldstr(", "), _malldptr(n), _malldstr(")\n");
  407. X    _mallchk("realloc");
  408. X    if (s == (char *) 0) {
  409. X        _malldstr("realloc((char *) 0, size) is illegal!\n");
  410. X        _mall_sig(SIGSYS);
  411. X    }
  412. X    if (n == 0) {
  413. X        _malldstr("realloc(ptr, 0) is illegal!\n");
  414. X        _mall_sig(SIGSYS);
  415. X    }
  416. X    if ((blk = _mallgb(s)) == (struct _Dmi *) 0)
  417. X        _mallerr("non-allocated pointer passed to realloc(): ", s);
  418. X    if ((s1 = malloc(n)) == (char *) 0)
  419. X        return (char *) 0;
  420. X    if (blk->m_size < n)
  421. X        n = blk->m_size;
  422. X    d1 = s1;
  423. X    d = s;
  424. X    while (n-- != 0)
  425. X        *d1++ = *d++;
  426. X    free(s);
  427. X    return s1;
  428. X}
  429. X
  430. X/*
  431. X * _mallchk() is global, so external routines can do discreet checks on the
  432. X * arena.  If the arena is detectibly corrupted, it will abort().
  433. X */
  434. X
  435. X_mallchk(fn)
  436. Xchar *fn; {
  437. X    register struct _Dmi *blk, *cblk;
  438. X    register char *send;
  439. X    register int cnt;
  440. X
  441. X    send = sbrk(0);
  442. X    cblk = (struct _Dmi *) 0;
  443. X    for (blk = _fab; blk != (struct _Dmi *) 0; cblk = blk, blk = blk->m_next) {
  444. X        if ((char *) blk < _xbrk || (char *) blk >= send)
  445. X            _mallerr(fn, "allocated block list corrupted: blkptr = ", blk);
  446. X        if (blk->m_prev != cblk)
  447. X            _mallerr(fn, "allocated block list corrupted: back pointer incorrect blk ", blk);
  448. X        if (blk->m_size < 0)
  449. X            _mallerr(fn, "allocated block list corrupted: blk->m_size = ", blk->m_size);
  450. X    }
  451. X    cblk = (struct _Dmi *) 0;
  452. X    for (blk = _ffb; blk != (struct _Dmi *) 0; cblk = blk, blk = blk->m_next) {
  453. X        if ((char *) blk < _xbrk || (char *) blk >= sbrk(0))
  454. X            _mallerr(fn, "free block list corrupted: blkptr = ", blk);
  455. X        if (blk->m_prev != cblk)
  456. X            _mallerr(fn, "free block list corrupted: back pointer incorrect blk ", blk);
  457. X        if (blk->m_size < 0)
  458. X            _mallerr(fn, "free block list corrupted: blk->m_size = ", blk->m_size);
  459. X    }
  460. X    for (blk = _fab; blk != (struct _Dmi *) 0; blk = blk->m_next) {
  461. X        if ((char *) blk + sizeof *blk + blk->m_size - 1 > send) {
  462. X            _malldstr("(brk = ");
  463. X            _malldptr(send);
  464. X            _malldstr(", eblk = ");
  465. X            _malldptr((char *) blk + sizeof *blk + blk->m_size - 1);
  466. X            _malldstr(")\n");
  467. X            _mallerr(fn, "allocated block extends past brk: ", blk);
  468. X        }
  469. X        cnt = 0;
  470. X        for (cblk = _fab; cblk != (struct _Dmi *) 0; cblk = cblk->m_next) {
  471. X            if (blk == cblk)
  472. X                if (cnt++ == 0)
  473. X                    continue;
  474. X                else
  475. X                    _mallerr(fn, "block allocated twice: ", blk);
  476. X            if (blk > cblk && (char *) blk < (char *) cblk + sizeof *cblk + cblk->m_size - 1) {
  477. X                _malldstr("(blk = ");
  478. X                _malldptr(blk);
  479. X                _malldstr(", cblk = ");
  480. X                _malldptr((char *) cblk + sizeof *cblk + cblk->m_size - 1);
  481. X                _malldstr(")\n");
  482. X                _mallerr(fn, "nested block in allocated list: ", blk);
  483. X            }
  484. X        }
  485. X        for (cblk = _ffb; cblk != (struct _Dmi *) 0; cblk = cblk->m_next) {
  486. X            if (blk == cblk)
  487. X                _mallerr(fn, "block on allocated and free lists: ", blk);
  488. X            if (blk > cblk && (char *) blk < (char *) cblk + sizeof *cblk + cblk->m_size - 1) {
  489. X                _malldstr("(blk = ");
  490. X                _malldptr(blk);
  491. X                _malldstr(", cblk = ");
  492. X                _malldptr((char *) cblk + sizeof *cblk + cblk->m_size - 1);
  493. X                _malldstr(")\n");
  494. X                _mallerr(fn, "allocated block nested in free block: ", blk);
  495. X            }
  496. X        }
  497. X    }
  498. X    for (blk = _ffb; blk != (struct _Dmi *) 0; blk = blk->m_next) {
  499. X        if ((char *) blk + sizeof *blk + blk->m_size - 1 > send) {
  500. X            _malldstr("(brk = ");
  501. X            _malldptr(send);
  502. X            _malldstr(", eblk = ");
  503. X            _malldptr((char *) blk + sizeof *blk + blk->m_size - 1);
  504. X            _malldstr(")\n");
  505. X            _mallerr(fn, "free block extends past brk: ", blk);
  506. X        }
  507. X        cnt = 0;
  508. X        for (cblk = _ffb; cblk != (struct _Dmi *) 0; cblk = cblk->m_next) {
  509. X            if (blk == cblk)
  510. X                if (cnt++ == 0)
  511. X                    continue;
  512. X                else
  513. X                    _mallerr(fn, "block freed twice: ", blk);
  514. X            if (blk > cblk && (char *) blk < (char *) cblk + sizeof *cblk + cblk->m_size - 1) {
  515. X                _malldstr("(blk = ");
  516. X                _malldptr(blk);
  517. X                _malldstr(", cblk = ");
  518. X                _malldptr((char *) cblk + sizeof *cblk + cblk->m_size - 1);
  519. X                _malldstr(")\n");
  520. X                _mallerr(fn, "nested block in free list: ", blk);
  521. X            }
  522. X        }
  523. X        for (cblk = _fab; cblk != (struct _Dmi *) 0; cblk = cblk->m_next) {
  524. X            if (blk == cblk)
  525. X                _mallerr(fn, "block on allocated and free lists: ", blk);
  526. X            if (blk > cblk && (char *) blk < (char *) cblk + sizeof *cblk + cblk->m_size - 1) {
  527. X                _malldstr("(blk = ");
  528. X                _malldptr(blk);
  529. X                _malldstr(", cblk = ");
  530. X                _malldptr((char *) cblk + sizeof *cblk + cblk->m_size - 1);
  531. X                _malldstr(")\n");
  532. X                _mallerr(fn, "free block nested in allocated block: ", blk);
  533. X            }
  534. X        }
  535. X    }
  536. X}
  537. X
  538. X/*
  539. X * malloc objects and zero storage
  540. X */
  541. X
  542. Xchar *calloc(n, size )
  543. Xregister unsigned n, size;
  544. X{
  545. X    register char *s, *s1;
  546. X
  547. X    if (_mall_opt)
  548. X    {
  549. X         _malldstr("calloc: num: ");
  550. X         _malldptr(n);
  551. X         _malldstr( " size: " );
  552. X         _malldptr(size);
  553. X         _malldstr("\n");
  554. X    }
  555. X    n *= size;
  556. X    if ((s = malloc(n)) == (char *) 0)
  557. X        return (char *) 0;
  558. X    for (s1 = s; n != 0; n--)
  559. X        *s1++ = 0;
  560. X    return s;
  561. X}
  562. X
  563. X/*
  564. X * for some reason this is in /lib/libc.a(calloc.o)
  565. X */
  566. X
  567. Xcfree(s)
  568. Xchar *s; {
  569. X    free(s);
  570. X}
  571. X#endif
  572. X#endif
  573. X
  574. SHAR_EOF
  575. echo "File common/malloc.c is complete"
  576. chmod 0440 common/malloc.c || echo "restore of common/malloc.c fails"
  577. echo "x - extracting common/itypes.h (Text)"
  578. sed 's/^X//' << 'SHAR_EOF' > common/itypes.h &&
  579. X/* RCS      -- $Header: /u2/dvadura/src/generic/dmake/src/common/RCS/itypes.h,v 1.1 90/10/06 12:04:45 dvadura Exp $
  580. X-- SYNOPSIS -- type declarations for common types
  581. X-- 
  582. X-- DESCRIPTION
  583. X--     portable type declarations.
  584. X--
  585. X-- AUTHOR
  586. X--      Dennis Vadura, dvadura@watdragon.uwaterloo.ca
  587. X--      CS DEPT, University of Waterloo, Waterloo, Ont., Canada
  588. X--
  589. X-- COPYRIGHT
  590. X--      Copyright (c) 1990 by Dennis Vadura.  All rights reserved.
  591. X-- 
  592. X--      This program is free software; you can redistribute it and/or
  593. X--      modify it under the terms of the GNU General Public License
  594. X--      (version 1), as published by the Free Software Foundation, and
  595. X--      found in the file 'LICENSE' included with this distribution.
  596. X-- 
  597. X--      This program is distributed in the hope that it will be useful,
  598. X--      but WITHOUT ANY WARRANTY; without even the implied warrant of
  599. X--      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  600. X--      GNU General Public License for more details.
  601. X-- 
  602. X--      You should have received a copy of the GNU General Public License
  603. X--      along with this program;  if not, write to the Free Software
  604. X--      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  605. X--
  606. X-- LOG
  607. X--     $Log:    itypes.h,v $
  608. X * Revision 1.1  90/10/06  12:04:45  dvadura
  609. X * dmake Release, Version 3.6
  610. X * 
  611. X*/
  612. X
  613. X
  614. X#ifndef ITYPES_h
  615. X#define    ITYPES_h
  616. X
  617. X#if defined(M_I86) || defined(MC68000)
  618. Xtypedef char  int8;               /* typedefs for right size ints */
  619. Xtypedef int   int16;
  620. Xtypedef long  int32;
  621. Xtypedef unsigned char  uint8;
  622. Xtypedef unsigned int   uint16;
  623. Xtypedef unsigned long  uint32;
  624. X#else
  625. Xtypedef char  int8;               /* typedefs for right size ints */
  626. Xtypedef short int16;
  627. Xtypedef long  int32;
  628. Xtypedef unsigned char  uint8;
  629. Xtypedef unsigned short uint16;
  630. Xtypedef unsigned long  uint32;
  631. X#endif
  632. X
  633. X#endif
  634. X
  635. SHAR_EOF
  636. chmod 0440 common/itypes.h || echo "restore of common/itypes.h fails"
  637. echo "x - extracting common/dbug.h (Text)"
  638. sed 's/^X//' << 'SHAR_EOF' > common/dbug.h &&
  639. X/******************************************************************************
  640. X *                                          *
  641. X *                               N O T I C E                      *
  642. X *                                          *
  643. X *                  Copyright Abandoned, 1987, Fred Fish              *
  644. X *                                          *
  645. X *                                          *
  646. X *    This previously copyrighted work has been placed into the  public     *
  647. X *    domain  by  the  author  and  may be freely used for any purpose,     *
  648. X *    private or commercial.                              *
  649. X *                                          *
  650. X *    Because of the number of inquiries I was receiving about the  use     *
  651. X *    of this product in commercially developed works I have decided to     *
  652. X *    simply make it public domain to further its unrestricted use.   I     *
  653. X *    specifically  would  be  most happy to see this material become a     *
  654. X *    part of the standard Unix distributions by AT&T and the  Berkeley     *
  655. X *    Computer  Science  Research Group, and a standard part of the GNU     *
  656. X *    system from the Free Software Foundation.                  *
  657. X *                                          *
  658. X *    I would appreciate it, as a courtesy, if this notice is  left  in     *
  659. X *    all copies and derivative works.  Thank you.                  *
  660. X *                                          *
  661. X *    The author makes no warranty of any kind  with  respect  to  this     *
  662. X *    product  and  explicitly disclaims any implied warranties of mer-     *
  663. X *    chantability or fitness for any particular purpose.              *
  664. X *                                          *
  665. X ******************************************************************************
  666. X */
  667. X
  668. X
  669. X/*
  670. X *  FILE
  671. X *
  672. X *    dbug.h    user include file for programs using the dbug package
  673. X *
  674. X *  SYNOPSIS
  675. X *
  676. X *    #include <local/dbug.h>
  677. X *
  678. X *  SCCS ID
  679. X *
  680. X *    @(#)dbug.h    1.11 9/5/87
  681. X *
  682. X *  DESCRIPTION
  683. X *
  684. X *    Programs which use the dbug package must include this file.
  685. X *    It contains the appropriate macros to call support routines
  686. X *    in the dbug runtime library.
  687. X *
  688. X *    To disable compilation of the macro expansions define the
  689. X *    preprocessor symbol "DBUG_OFF".  This will result in null
  690. X *    macros expansions so that the resulting code will be smaller
  691. X *    and faster.  (The difference may be smaller than you think
  692. X *    so this step is recommended only when absolutely necessary).
  693. X *    In general, tradeoffs between space and efficiency are
  694. X *    decided in favor of efficiency since space is seldom a
  695. X *    problem on the new machines).
  696. X *
  697. X *    All externally visible symbol names follow the pattern
  698. X *    "_db_xxx..xx_" to minimize the possibility of a dbug package
  699. X *    symbol colliding with a user defined symbol.
  700. X *    
  701. X *    The DBUG_<N> style macros are obsolete and should not be used
  702. X *    in new code.  Macros to map them to instances of DBUG_PRINT
  703. X *    are provided for compatibility with older code.  They may go
  704. X *    away completely in subsequent releases.
  705. X *
  706. X *  AUTHOR
  707. X *
  708. X *    Fred Fish
  709. X *    (Currently employed by Motorola Computer Division, Tempe, Az.)
  710. X *    hao!noao!mcdsun!fnf
  711. X *    (602) 438-3614
  712. X *
  713. X */
  714. X
  715. X
  716. X/*
  717. X *    Internally used dbug variables which must be global.
  718. X */
  719. X
  720. X#ifndef DBUG_OFF
  721. X    extern int _db_on_;            /* TRUE if debug currently enabled */
  722. X    extern FILE *_db_fp_;        /* Current debug output stream */
  723. X    extern char *_db_process_;        /* Name of current process */
  724. X    extern int _db_keyword_ ();        /* Accept/reject keyword */
  725. X    extern void _db_push_ ();        /* Push state, set up new state */
  726. X    extern void _db_pop_ ();        /* Pop previous debug state */
  727. X    extern void _db_enter_ ();        /* New user function entered */
  728. X    extern void _db_return_ ();        /* User function return */
  729. X    extern void _db_pargs_ ();        /* Remember args for line */
  730. X    extern void _db_doprnt_ ();        /* Print debug output */
  731. X    extern void _db_setjmp_ ();        /* Save debugger environment */
  732. X    extern void _db_longjmp_ ();    /* Restore debugger environment */
  733. X# endif
  734. X
  735. X
  736. X/*
  737. X *    These macros provide a user interface into functions in the
  738. X *    dbug runtime support library.  They isolate users from changes
  739. X *    in the MACROS and/or runtime support.
  740. X *
  741. X *    The symbols "__LINE__" and "__FILE__" are expanded by the
  742. X *    preprocessor to the current source file line number and file
  743. X *    name respectively.
  744. X *
  745. X *    WARNING ---  Because the DBUG_ENTER macro allocates space on
  746. X *    the user function's stack, it must precede any executable
  747. X *    statements in the user function.
  748. X *
  749. X */
  750. X
  751. X# ifdef DBUG_OFF
  752. X#    define DBUG_ENTER(a1)
  753. X#    define DBUG_RETURN(a1) return(a1)
  754. X#    define DBUG_VOID_RETURN return
  755. X#    define DBUG_EXECUTE(keyword,a1)
  756. X#    define DBUG_PRINT(keyword,arglist)
  757. X#    define DBUG_2(keyword,format)        /* Obsolete */
  758. X#    define DBUG_3(keyword,format,a1)        /* Obsolete */
  759. X#    define DBUG_4(keyword,format,a1,a2)    /* Obsolete */
  760. X#    define DBUG_5(keyword,format,a1,a2,a3)    /* Obsolete */
  761. X#    define DBUG_PUSH(a1)
  762. X#    define DBUG_POP()
  763. X#    define DBUG_PROCESS(a1)
  764. X#    define DBUG_FILE (stderr)
  765. X#    define DBUG_SETJMP setjmp
  766. X#    define DBUG_LONGJMP longjmp
  767. X# else
  768. X#    define DBUG_ENTER(a) \
  769. X    auto char *_db_func_, *_db_file_; \
  770. X    int _db_level_; \
  771. X    _db_enter_ (a,__FILE__,__LINE__,&_db_func_,&_db_file_,&_db_level_)
  772. X#    define DBUG_LEAVE \
  773. X    (_db_return_ (__LINE__, &_db_func_, &_db_file_, &_db_level_))
  774. X#    define DBUG_RETURN(a1) return (DBUG_LEAVE, (a1))
  775. X/*   define DBUG_RETURN(a1) {DBUG_LEAVE; return(a1);}  Alternate form */
  776. X#    define DBUG_VOID_RETURN DBUG_LEAVE; return
  777. X#    define DBUG_EXECUTE(keyword,a1) \
  778. X    {if (_db_on_) {if (_db_keyword_ (keyword)) { a1 }}}
  779. X#    define DBUG_PRINT(keyword,arglist) \
  780. X    {if (_db_on_) {_db_pargs_(__LINE__,keyword); _db_doprnt_ arglist;}}
  781. X#    define DBUG_2(keyword,format) \
  782. X    DBUG_PRINT(keyword,(format))        /* Obsolete */
  783. X#    define DBUG_3(keyword,format,a1) \
  784. X    DBUG_PRINT(keyword,(format,a1))        /* Obsolete */
  785. X#    define DBUG_4(keyword,format,a1,a2) \
  786. X    DBUG_PRINT(keyword,(format,a1,a2))    /* Obsolete */
  787. X#    define DBUG_5(keyword,format,a1,a2,a3) \
  788. X    DBUG_PRINT(keyword,(format,a1,a2,a3))    /* Obsolete */
  789. X#    define DBUG_PUSH(a1) _db_push_ (a1)
  790. X#    define DBUG_POP() _db_pop_ ()
  791. X#    define DBUG_PROCESS(a1) (_db_process_ = a1)
  792. X#    define DBUG_FILE (_db_fp_)
  793. X#    define DBUG_SETJMP(a1) (_db_setjmp_ (), setjmp (a1))
  794. X#    define DBUG_LONGJMP(a1,a2) (_db_longjmp_ (), longjmp (a1, a2))
  795. X# endif
  796. X
  797. SHAR_EOF
  798. chmod 0440 common/dbug.h || echo "restore of common/dbug.h fails"
  799. echo "x - extracting common/dbug.c (Text)"
  800. sed 's/^X//' << 'SHAR_EOF' > common/dbug.c &&
  801. X/******************************************************************************
  802. X *                                          *
  803. X *                               N O T I C E                      *
  804. X *                                          *
  805. X *                  Copyright Abandoned, 1987, Fred Fish              *
  806. X *                                          *
  807. X *                                          *
  808. X *    This previously copyrighted work has been placed into the  public     *
  809. X *    domain  by  the  author  and  may be freely used for any purpose,     *
  810. X *    private or commercial.                              *
  811. X *                                          *
  812. X *    Because of the number of inquiries I was receiving about the  use     *
  813. X *    of this product in commercially developed works I have decided to     *
  814. X *    simply make it public domain to further its unrestricted use.   I     *
  815. X *    specifically  would  be  most happy to see this material become a     *
  816. X *    part of the standard Unix distributions by AT&T and the  Berkeley     *
  817. X *    Computer  Science  Research Group, and a standard part of the GNU     *
  818. X *    system from the Free Software Foundation.                  *
  819. X *                                          *
  820. X *    I would appreciate it, as a courtesy, if this notice is  left  in     *
  821. X *    all copies and derivative works.  Thank you.                  *
  822. X *                                          *
  823. X *    The author makes no warranty of any kind  with  respect  to  this     *
  824. X *    product  and  explicitly disclaims any implied warranties of mer-     *
  825. X *    chantability or fitness for any particular purpose.              *
  826. X *                                          *
  827. X ******************************************************************************
  828. X */
  829. X
  830. X
  831. X/*
  832. X *  FILE
  833. X *
  834. X *    dbug.c   runtime support routines for dbug package
  835. X *
  836. X *  SCCS
  837. X *
  838. X *    @(#)dbug.c    1.19 9/5/87
  839. X *
  840. X *  DESCRIPTION
  841. X *
  842. X *    These are the runtime support routines for the dbug package.
  843. X *    The dbug package has two main components; the user include
  844. X *    file containing various macro definitions, and the runtime
  845. X *    support routines which are called from the macro expansions.
  846. X *
  847. X *    Externally visible functions in the runtime support module
  848. X *    use the naming convention pattern "_db_xx...xx_", thus
  849. X *    they are unlikely to collide with user defined function names.
  850. X *
  851. X *  AUTHOR(S)
  852. X *
  853. X *    Fred Fish        (base code)
  854. X *    (Currently at Motorola Computer Division, Tempe, Az.)
  855. X *    hao!noao!mcdsun!fnf
  856. X *    (602) 438-3614
  857. X *
  858. X *    Binayak Banerjee    (profiling enhancements)
  859. X *    seismo!bpa!sjuvax!bbanerje
  860. X */
  861. X
  862. X
  863. X#include <stdio.h>
  864. X#ifdef amiga
  865. X#define AMIGA
  866. X#endif
  867. X
  868. X#ifdef AMIGA
  869. X#define HZ (50)            /* Probably in some header somewhere */
  870. X#endif
  871. X
  872. X/*
  873. X *    Manifest constants that should not require any changes.
  874. X */
  875. X
  876. X#define FALSE        0    /* Boolean FALSE */
  877. X#define TRUE        1    /* Boolean TRUE */
  878. X#define EOS        '\000'    /* End Of String marker */
  879. X
  880. X/*
  881. X *    Manifest constants which may be "tuned" if desired.
  882. X */
  883. X
  884. X#define PRINTBUF    1024    /* Print buffer size */
  885. X#define INDENT        4    /* Indentation per trace level */
  886. X#define MAXDEPTH    200    /* Maximum trace depth default */
  887. X
  888. X/*
  889. X *    The following flags are used to determine which
  890. X *    capabilities the user has enabled with the state
  891. X *    push macro.
  892. X */
  893. X
  894. X#define TRACE_ON    000001    /* Trace enabled */
  895. X#define DEBUG_ON    000002    /* Debug enabled */
  896. X#define FILE_ON     000004    /* File name print enabled */
  897. X#define LINE_ON        000010    /* Line number print enabled */
  898. X#define DEPTH_ON    000020    /* Function nest level print enabled */
  899. X#define PROCESS_ON    000040    /* Process name print enabled */
  900. X#define NUMBER_ON    000100    /* Number each line of output */
  901. X#define PROFILE_ON    000200    /* Print out profiling code */
  902. X
  903. X#define TRACING (stack -> flags & TRACE_ON)
  904. X#define DEBUGGING (stack -> flags & DEBUG_ON)
  905. X#define PROFILING (stack -> flags & PROFILE_ON)
  906. X#define STREQ(a,b) (strcmp(a,b) == 0)
  907. X
  908. X/*
  909. X *    Typedefs to make things more obvious.
  910. X */
  911. X
  912. X#define VOID void        /* Can't use typedef for most compilers */
  913. Xtypedef int BOOLEAN;
  914. X
  915. X/*
  916. X *    Make it easy to change storage classes if necessary.
  917. X */
  918. X
  919. X#define LOCAL static        /* Names not needed by outside world */
  920. X#define IMPORT extern        /* Names defined externally */
  921. X#define EXPORT            /* Allocated here, available globally */
  922. X#define AUTO auto        /* Names to be allocated on stack */
  923. X#define REGISTER register    /* Names to be placed in registers */
  924. X
  925. X/*
  926. X *    The following define is for the variable arguments kluge, see
  927. X *    the comments in _db_doprnt_().
  928. X *
  929. X *    Also note that the longer this list, the less prone to failing
  930. X *    on long argument lists, but the more stuff that must be moved
  931. X *    around for each call to the runtime support routines.  The
  932. X *    length may really be critical if the machine convention is
  933. X *    to pass arguments in registers.
  934. X *
  935. X *    Note that the default define allows up to 16 integral arguments,
  936. X *    or 8 floating point arguments (doubles), on most machines.
  937. X *
  938. X *    Someday this may be replaced with true varargs support, when
  939. X *    ANSI C has had time to take root.
  940. X */
  941. X
  942. X#define ARGLIST a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15
  943. X
  944. X/*
  945. X * The default file for profiling.  Could also add another flag
  946. X * (G?) which allowed the user to specify this.
  947. X */
  948. X
  949. X#define PROF_FILE    "dbugmon.out"
  950. X
  951. X/*
  952. X *    Variables which are available externally but should only
  953. X *    be accessed via the macro package facilities.
  954. X */
  955. X
  956. XEXPORT FILE *_db_fp_ = stderr;        /* Output stream, default stderr */
  957. XEXPORT FILE *_db_pfp_ = (FILE *)0;    /* Profile stream, 'dbugmon.out' */
  958. XEXPORT char *_db_process_ = "dbug";    /* Pointer to process name; argv[0] */
  959. XEXPORT BOOLEAN _db_on_ = FALSE;        /* TRUE if debugging currently on */
  960. XEXPORT BOOLEAN _db_pon_ = FALSE;    /* TRUE if debugging currently on */
  961. X
  962. X/*
  963. X *    Externally supplied functions.
  964. X */
  965. X
  966. X#ifdef unix            /* Only needed for unix */
  967. XIMPORT VOID perror ();        /* Print system/library error */
  968. XIMPORT int chown ();        /* Change owner of a file */
  969. XIMPORT int getgid ();        /* Get real group id */
  970. XIMPORT int getuid ();        /* Get real user id */
  971. XIMPORT int access ();        /* Test file for access */
  972. X#else
  973. X#if !(AMIGA && LATTICE)
  974. XLOCAL VOID perror ();        /* Fake system/library error print routine */
  975. X#endif
  976. X#endif
  977. X
  978. X# if BSD4_3 || sun
  979. XIMPORT int getrusage ();
  980. X#endif
  981. X
  982. XIMPORT int atoi ();        /* Convert ascii to integer */
  983. XIMPORT VOID exit ();        /* Terminate execution */
  984. XIMPORT int fclose ();        /* Close a stream */
  985. XIMPORT FILE *fopen ();        /* Open a stream */
  986. XIMPORT int fprintf ();        /* Formatted print on file */
  987. XIMPORT VOID free ();
  988. XIMPORT char *malloc ();        /* Allocate memory */
  989. XIMPORT int strcmp ();        /* Compare strings */
  990. XIMPORT char *strcpy ();        /* Copy strings around */
  991. XIMPORT int strlen ();        /* Find length of string */
  992. X
  993. X#ifndef fflush            /* This is sometimes a macro */
  994. XIMPORT int fflush ();        /* Flush output for stream */
  995. X#endif
  996. X
  997. X
  998. X/*
  999. X *    The user may specify a list of functions to trace or 
  1000. X *    debug.  These lists are kept in a linear linked list,
  1001. X *    a very simple implementation.
  1002. X */
  1003. X
  1004. Xstruct link {
  1005. X    char *string;        /* Pointer to link's contents */
  1006. X    struct link *next_link;    /* Pointer to the next link */
  1007. X};
  1008. X
  1009. X
  1010. X/*
  1011. X *    Debugging states can be pushed or popped off of a
  1012. X *    stack which is implemented as a linked list.  Note
  1013. X *    that the head of the list is the current state and the
  1014. X *    stack is pushed by adding a new state to the head of the
  1015. X *    list or popped by removing the first link.
  1016. X */
  1017. X
  1018. Xstruct state {
  1019. X    int flags;                /* Current state flags */
  1020. X    int maxdepth;            /* Current maximum trace depth */
  1021. X    unsigned int delay;            /* Delay after each output line */
  1022. X    int level;                /* Current function nesting level */
  1023. X    FILE *out_file;            /* Current output stream */
  1024. X    FILE *prof_file;            /* Current profiling stream */
  1025. X    struct link *functions;        /* List of functions */
  1026. X    struct link *p_functions;        /* List of profiled functions */
  1027. X    struct link *keywords;        /* List of debug keywords */
  1028. X    struct link *processes;        /* List of process names */
  1029. X    struct state *next_state;        /* Next state in the list */
  1030. X};
  1031. X
  1032. XLOCAL struct state *stack = NULL;    /* Linked list of stacked states */
  1033. X
  1034. X/*
  1035. X *    Local variables not seen by user.
  1036. X */
  1037. X
  1038. XLOCAL int lineno = 0;        /* Current debugger output line number */
  1039. XLOCAL char *func = "?func";    /* Name of current user function */
  1040. XLOCAL char *file = "?file";    /* Name of current user file */
  1041. XLOCAL BOOLEAN init_done = FALSE;/* Set to TRUE when initialization done */
  1042. X
  1043. X/*#if unix || AMIGA || M_I86*/
  1044. XLOCAL int jmplevel;        /* Remember nesting level at setjmp () */
  1045. XLOCAL char *jmpfunc;        /* Remember current function for setjmp */
  1046. XLOCAL char *jmpfile;        /* Remember current file for setjmp */
  1047. X/*#endif*/
  1048. X
  1049. XLOCAL struct link *ListParse ();/* Parse a debug command string */
  1050. XLOCAL char *StrDup ();        /* Make a fresh copy of a string */
  1051. XLOCAL VOID OpenFile ();        /* Open debug output stream */
  1052. XLOCAL VOID OpenProfile ();    /* Open profile output stream */
  1053. XLOCAL VOID CloseFile ();    /* Close debug output stream */
  1054. XLOCAL VOID PushState ();    /* Push current debug state */
  1055. XLOCAL VOID ChangeOwner ();    /* Change file owner and group */
  1056. XLOCAL BOOLEAN DoTrace ();    /* Test for tracing enabled */
  1057. XLOCAL BOOLEAN Writable ();    /* Test to see if file is writable */
  1058. XLOCAL unsigned long Clock ();    /* Return current user time (ms) */
  1059. XLOCAL char *DbugMalloc ();    /* Allocate memory for runtime support */
  1060. XLOCAL char *BaseName ();    /* Remove leading pathname components */
  1061. XLOCAL VOID DoPrefix ();        /* Print debugger line prefix */
  1062. XLOCAL VOID FreeList ();        /* Free memory from linked list */
  1063. XLOCAL VOID Indent ();        /* Indent line to specified indent */
  1064. X
  1065. X                /* Supplied in Sys V runtime environ */
  1066. XLOCAL char *strtok ();        /* Break string into tokens */
  1067. XLOCAL char *strrchr ();        /* Find last occurance of char */
  1068. X
  1069. X/*
  1070. X *    The following local variables are used to hold the state information
  1071. X *    between the call to _db_pargs_() and _db_doprnt_(), during
  1072. X *    expansion of the DBUG_PRINT macro.  This is the only macro
  1073. X *    that currently uses these variables.  The DBUG_PRINT macro
  1074. X *    and the new _db_doprnt_() routine replace the older DBUG_N macros
  1075. X *    and their corresponding runtime support routine _db_printf_().
  1076. X *
  1077. X *    These variables are currently used only by _db_pargs_() and
  1078. X *    _db_doprnt_().
  1079. X */
  1080. X
  1081. XLOCAL int u_line = 0;        /* User source code line number */
  1082. XLOCAL char *u_keyword = "?";    /* Keyword for current macro */
  1083. X
  1084. X/*
  1085. X *    Miscellaneous printf format strings.
  1086. X */
  1087. X#define ERR_MISSING_RETURN "%s: missing DBUG_RETURN or DBUG_VOID_RETURN macro in function \"%s\"\n"
  1088. X#define ERR_OPEN "%s: can't open debug output stream \"%s\": "
  1089. X#define ERR_CLOSE "%s: can't close debug file: "
  1090. X#define ERR_ABORT "%s: debugger aborting because %s\n"
  1091. X#define ERR_CHOWN "%s: can't change owner/group of \"%s\": "
  1092. X#define ERR_PRINTF "%s: obsolete object file for '%s', please recompile!\n"
  1093. X
  1094. X/*
  1095. X *    Macros and defines for testing file accessibility under UNIX.
  1096. X */
  1097. X
  1098. X#ifdef unix
  1099. X#  define A_EXISTS    00        /* Test for file existance */
  1100. X#  define A_EXECUTE    01        /* Test for execute permission */
  1101. X#  define A_WRITE    02        /* Test for write access */
  1102. X#  define A_READ    03        /* Test for read access */
  1103. X#  define EXISTS(pathname) (access (pathname, A_EXISTS) == 0)
  1104. X#  define WRITABLE(pathname) (access (pathname, A_WRITE) == 0)
  1105. X#else
  1106. X#  define EXISTS(pathname) (FALSE)    /* Assume no existance */
  1107. X#endif
  1108. X
  1109. X/*
  1110. X *    Translate some calls among different systems.
  1111. X */
  1112. X
  1113. X#ifdef unix
  1114. X# define XDelay sleep
  1115. XIMPORT unsigned int sleep ();    /* Pause for given number of seconds */
  1116. X#endif
  1117. X
  1118. X#ifdef AMIGA
  1119. XIMPORT int XDelay ();        /* Pause for given number of ticks */
  1120. X#endif
  1121. X
  1122. X
  1123. X/*
  1124. X *  FUNCTION
  1125. X *
  1126. X *    _db_push_    push current debugger state and set up new one
  1127. X *
  1128. X *  SYNOPSIS
  1129. X *
  1130. X *    VOID _db_push_ (control)
  1131. X *    char *control;
  1132. X *
  1133. X *  DESCRIPTION
  1134. X *
  1135. X *    Given pointer to a debug control string in "control", pushes
  1136. X *    the current debug state, parses the control string, and sets
  1137. X *    up a new debug state.
  1138. X *
  1139. X *    The only attribute of the new state inherited from the previous
  1140. X *    state is the current function nesting level.  This can be
  1141. X *    overridden by using the "r" flag in the control string.
  1142. X *
  1143. X *    The debug control string is a sequence of colon separated fields
  1144. X *    as follows:
  1145. X *
  1146. X *        <field_1>:<field_2>:...:<field_N>
  1147. X *
  1148. X *    Each field consists of a mandatory flag character followed by
  1149. X *    an optional "," and comma separated list of modifiers:
  1150. X *
  1151. X *        flag[,modifier,modifier,...,modifier]
  1152. X *
  1153. X *    The currently recognized flag characters are:
  1154. X *
  1155. X *        d    Enable output from DBUG_<N> macros for
  1156. X *            for the current state.  May be followed
  1157. X *            by a list of keywords which selects output
  1158. X *            only for the DBUG macros with that keyword.
  1159. X *            A null list of keywords implies output for
  1160. X *            all macros.
  1161. X *
  1162. X *        D    Delay after each debugger output line.
  1163. X *            The argument is the number of tenths of seconds
  1164. X *            to delay, subject to machine capabilities.
  1165. X *            I.E.  -#D,20 is delay two seconds.
  1166. X *
  1167. X *        f    Limit debugging and/or tracing, and profiling to the
  1168. X *            list of named functions.  Note that a null list will
  1169. X *            disable all functions.  The appropriate "d" or "t"
  1170. X *            flags must still be given, this flag only limits their
  1171. X *            actions if they are enabled.
  1172. X *
  1173. X *        F    Identify the source file name for each
  1174. X *            line of debug or trace output.
  1175. X *
  1176. X *        g    Enable profiling.  Create a file called 'dbugmon.out'
  1177. X *            containing information that can be used to profile
  1178. X *            the program.  May be followed by a list of keywords
  1179. X *            that select profiling only for the functions in that
  1180. X *            list.  A null list implies that all functions are
  1181. X *            considered.
  1182. X *
  1183. X *        L    Identify the source file line number for
  1184. X *            each line of debug or trace output.
  1185. X *
  1186. X *        n    Print the current function nesting depth for
  1187. X *            each line of debug or trace output.
  1188. X *    
  1189. X *        N    Number each line of dbug output.
  1190. X *
  1191. X *        p    Limit debugger actions to specified processes.
  1192. X *            A process must be identified with the
  1193. X *            DBUG_PROCESS macro and match one in the list
  1194. X *            for debugger actions to occur.
  1195. X *
  1196. X *        P    Print the current process name for each
  1197. X *            line of debug or trace output.
  1198. X *
  1199. X *        r    When pushing a new state, do not inherit
  1200. X *            the previous state's function nesting level.
  1201. X *            Useful when the output is to start at the
  1202. X *            left margin.
  1203. X *
  1204. X *        t    Enable function call/exit trace lines.
  1205. X *            May be followed by a list (containing only
  1206. X *            one modifier) giving a numeric maximum
  1207. X *            trace level, beyond which no output will
  1208. X *            occur for either debugging or tracing
  1209. X *            macros.  The default is a compile time
  1210. X *            option.
  1211. X *
  1212. X *    Some examples of debug control strings which might appear
  1213. X *    on a shell command line (the "-#" is typically used to
  1214. X *    introduce a control string to an application program) are:
  1215. X *
  1216. X *        -#d:t
  1217. X *        -#d:f,main,subr1:F:L:t,20
  1218. X *        -#d,input,output,files:n
  1219. X *
  1220. X *    For convenience, any leading "-#" is stripped off.
  1221. X *
  1222. X */
  1223. X
  1224. X
  1225. XVOID _db_push_ (control)
  1226. Xchar *control;
  1227. X{
  1228. X    REGISTER char *scan;
  1229. X    REGISTER struct link *temp;
  1230. X
  1231. X    if (control && *control == '-') {
  1232. X    if (*++control == '#') {
  1233. X        control++;
  1234. X    }    
  1235. X    }
  1236. X    control = StrDup (control);
  1237. X    PushState ();
  1238. X    scan = strtok (control, ":");
  1239. X    for (; scan != NULL; scan = strtok ((char *)NULL, ":")) {
  1240. X    switch (*scan++) {
  1241. X        case 'd': 
  1242. X        _db_on_ = TRUE;
  1243. X        stack -> flags |= DEBUG_ON;
  1244. X        if (*scan++ == ',') {
  1245. X            stack -> keywords = ListParse (scan);
  1246. X        }
  1247. X            break;
  1248. X        case 'D': 
  1249. X        stack -> delay = 0;
  1250. X        if (*scan++ == ',') {
  1251. X            temp = ListParse (scan);
  1252. X            stack -> delay = DelayArg (atoi (temp -> string));
  1253. X            FreeList (temp);
  1254. X        }
  1255. X        break;
  1256. X        case 'f': 
  1257. X        if (*scan++ == ',') {
  1258. X            stack -> functions = ListParse (scan);
  1259. X        }
  1260. X        break;
  1261. X        case 'F': 
  1262. X        stack -> flags |= FILE_ON;
  1263. X        break;
  1264. X        case 'g': 
  1265. X        _db_pon_ = TRUE;
  1266. X        OpenProfile(PROF_FILE);
  1267. X        stack -> flags |= PROFILE_ON;
  1268. X        if (*scan++ == ',') {
  1269. X            stack -> p_functions = ListParse (scan);
  1270. X        }
  1271. X        break;
  1272. X        case 'L': 
  1273. X        stack -> flags |= LINE_ON;
  1274. X        break;
  1275. X        case 'n': 
  1276. X        stack -> flags |= DEPTH_ON;
  1277. X        break;
  1278. X        case 'N':
  1279. X        stack -> flags |= NUMBER_ON;
  1280. X        break;
  1281. X        case 'o': 
  1282. X        if (*scan++ == ',') {
  1283. X            temp = ListParse (scan);
  1284. X            OpenFile (temp -> string);
  1285. X            FreeList (temp);
  1286. X        } else {
  1287. X            OpenFile ("-");
  1288. X        }
  1289. X        break;
  1290. X        case 'p':
  1291. X        if (*scan++ == ',') {
  1292. X            stack -> processes = ListParse (scan);
  1293. X        }
  1294. X        break;
  1295. X        case 'P': 
  1296. X        stack -> flags |= PROCESS_ON;
  1297. X        break;
  1298. X        case 'r': 
  1299. X        stack -> level = 0;
  1300. X        break;
  1301. X        case 't': 
  1302. X        stack -> flags |= TRACE_ON;
  1303. X        if (*scan++ == ',') {
  1304. X            temp = ListParse (scan);
  1305. X            stack -> maxdepth = atoi (temp -> string);
  1306. X            FreeList (temp);
  1307. X        }
  1308. X        break;
  1309. X    }
  1310. X    }
  1311. X    free (control);
  1312. X}
  1313. X
  1314. X
  1315. X
  1316. X/*
  1317. X *  FUNCTION
  1318. X *
  1319. X *    _db_pop_    pop the debug stack
  1320. X *
  1321. X *  DESCRIPTION
  1322. X *
  1323. X *    Pops the debug stack, returning the debug state to its
  1324. X *    condition prior to the most recent _db_push_ invocation.
  1325. X *    Note that the pop will fail if it would remove the last
  1326. X *    valid state from the stack.  This prevents user errors
  1327. X *    in the push/pop sequence from screwing up the debugger.
  1328. X *    Maybe there should be some kind of warning printed if the
  1329. X *    user tries to pop too many states.
  1330. X *
  1331. X */
  1332. X
  1333. XVOID _db_pop_ ()
  1334. X{
  1335. X    REGISTER struct state *discard;
  1336. X
  1337. X    discard = stack;
  1338. SHAR_EOF
  1339. echo "End of part 23"
  1340. echo "File common/dbug.c is continued in part 24"
  1341. echo "24" > s2_seq_.tmp
  1342. exit 0
  1343.  
  1344.