home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3645 < prev    next >
Encoding:
Text File  |  1991-07-17  |  40.5 KB  |  1,330 lines

  1. Newsgroups: alt.sources
  2. From: jtsillas@sprite.ma30.bull.com (James Tsillas)
  3. Subject: mxgdb Part 7/9
  4. Date: 16 Jul 91 13:13:10
  5. Message-ID: <JTSILLAS.91Jul16131310@sprite.ma30.bull.com>
  6.  
  7.  
  8.  
  9. ---- Cut Here and feed the following to sh ----
  10. #!/bin/sh
  11. # this is mxgdb.07 (part 7 of a multipart archive)
  12. # do not concatenate these parts, unpack them in order with /bin/sh
  13. # file mxgdb/handler.c continued
  14. #
  15. if test ! -r _shar_seq_.tmp; then
  16.     echo 'Please unpack part 1 first!'
  17.     exit 1
  18. fi
  19. (read Scheck
  20.  if test "$Scheck" != 7; then
  21.     echo Please unpack part "$Scheck" next!
  22.     exit 1
  23.  else
  24.     exit 0
  25.  fi
  26. ) < _shar_seq_.tmp || exit 1
  27. if test ! -f _shar_wnt_.tmp; then
  28.     echo 'x - still skipping mxgdb/handler.c'
  29. else
  30. echo 'x - continuing file mxgdb/handler.c'
  31. sed 's/^X//' << 'SHAR_EOF' >> 'mxgdb/handler.c' &&
  32. X *  THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  33. X *  FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF TEXAS OR MCC BE LIABLE FOR
  34. X *  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  35. X *  RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
  36. X *  CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  37. X *  CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  38. X *
  39. X *  Author:      Po Cheung
  40. X *  Created:       March 10, 1989
  41. X * 
  42. X *****************************************************************************
  43. X * 
  44. X *  xxgdb - X Window System interface to the gdb debugger
  45. X *  
  46. X *     Copyright 1990 Thomson Consumer Electronics, Inc.
  47. X *  
  48. X *  Permission to use, copy, modify, and distribute this software and its
  49. X *  documentation for any purpose and without fee is hereby granted,
  50. X *  provided that the above copyright notice appear in all copies and that
  51. X *  both that copyright notice and this permission notice appear in
  52. X *  supporting documentation, and that the name of Thomson Consumer
  53. X *  Electronics (TCE) not be used in advertising or publicity pertaining
  54. X *  to distribution of the software without specific, written prior
  55. X *  permission.  TCE makes no representations about the suitability of
  56. X *  this software for any purpose.  It is provided "as is" without express
  57. X *  or implied warranty.
  58. X *
  59. X *  TCE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  60. X *  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
  61. X *  SHALL TCE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
  62. X *  OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  63. X *  WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  64. X *  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  65. X *  SOFTWARE.
  66. X *
  67. X *  Adaptation to GDB:  Pierre Willard
  68. X *  XXGDB Created:       December, 1990
  69. X *
  70. X *****************************************************************************/
  71. X
  72. /*  handler.c
  73. X *
  74. X *    Contain action handlers for the parser to invoke upon a dbx command.
  75. X *
  76. X *    TextSetTopPosition():    Set the top character position of textdisplayed
  77. X *    AdjustText():        Adjust the portion of text displayed.
  78. X *    exec_handler():        Update file, line label, arrow position.
  79. X *    done_handler():        Progrm execution completed, clear breakpoints
  80. X *    stop_at_handler():    Place stop sign on line specified.
  81. X *    stop_in_handler():    Place stop sign on function specified.
  82. X *    updown_handler():        Update file, line label, updown arrow position.
  83. X *    clear_handler():        Remove stop sign.
  84. X *    func_handler():        Display function, if specified.
  85. X *    file_handler():        Display file, if specified.
  86. X *    debug_handler():        Check directory use list, display source file.
  87. X *    cd_handler():        Record current working directory.
  88. X *    use_handler():        Record directory paths.
  89. X *    search_handler():        Adjust source file to display matched line.
  90. X *    list_handler();        Adjust source file to display result.
  91. X *    display_handler():    Display results in display window.
  92. X */
  93. X
  94. #include <ctype.h>
  95. #include "global.h"
  96. #include <Xm/Xm.h>
  97. #include <Xm/Text.h>
  98. X
  99. #ifdef BSD
  100. #define    BRACKET    "[%d]"
  101. #else
  102. #define    BRACKET    "(%d)"
  103. #endif
  104. X
  105. Boolean        Echo = True;        /* display dbx output if true */
  106. static Boolean    Skip_func_handler = False;
  107. X
  108. /*  Display text starting from the top position specified by pos */
  109. X
  110. void TextSetTopPosition(w, pos)
  111. X    Widget w;
  112. X    XmTextPosition pos;
  113. {
  114. X    Arg args[MAXARGS];
  115. X
  116. X    XtSetArg(args[0], XmNtopCharacter, (XtArgVal) pos);
  117. X    XtSetValues(w, args, 1);
  118. }
  119. X
  120. short currpos;
  121. X
  122. /*
  123. X *  Adjust text so that 'line' will fall into the viewable part of the
  124. X *  source window.
  125. X *  Arrows, stop signs, and line label and Vertical Scroll bar
  126. X *  are updated accordingly.
  127. X */
  128. void AdjustText(line)
  129. X    int           line;
  130. {
  131. X    FileRec         *file;
  132. X    int                nlines = 0;
  133. X    int            i;
  134. X    XmTextPosition     pos;
  135. X    Dimension width;
  136. X    Arg                 args[5];
  137. X
  138. X    if ((file = displayedFile) == NULL || line <= 0) return;
  139. X    file->currentline = line;
  140. X
  141. X    if (line < file->topline || line > file->bottomline ) {
  142. X    /* Position line about 30% from the top */
  143. X    nlines = file->lines*0.3;
  144. X    if (line < nlines)               /* near top */
  145. X        file->topline = 1;
  146. X    else if (line > file->lastline - nlines)  /* near bottom */
  147. X        file->topline = MAX(file->lastline - file->lines + 1, 1);
  148. X    else
  149. X        file->topline = line - nlines;
  150. X    file->bottomline = MIN(file->topline + file->lines - 1, 
  151. X                   file->lastline);
  152. X    TextSetTopPosition(sourceWindow, file->linepos[file->topline]);
  153. X    file->topPosition = file->linepos[file->topline];
  154. X    }
  155. X    XmTextSetInsertionPosition(sourceWindow, file->linepos[line]);
  156. X
  157. X    /* Text window might have scrolled, check topline & bottomline */
  158. X    pos = XmTextGetTopCharacter(sourceWindow);
  159. X
  160. X    for (i=1; pos >= file->linepos[i]; i++);
  161. X    if (file->topline != i-1) {
  162. X    file->topline = i-1;
  163. X    file->bottomline = MIN (file->topline + file->lines - 1,
  164. X                file->lastline);
  165. X    }
  166. X
  167. X    if(pos != currpos && XtIsManaged(scrollV))
  168. X      {
  169. X    XtSetArg(args[0], XmNvalue, TextPositionToLine(pos));
  170. X    XtSetValues(scrollV, args, 1);
  171. X    currpos = pos;
  172. X      }
  173. X
  174. X    XtMapWidget(sourceWindow);
  175. X
  176. X    UpdateLineLabel(line);
  177. X    UpdateStops(file, -1);
  178. X    UpdateArrow(file);
  179. X    UpdateUpdown(file);
  180. X    UpdateBomb(file);
  181. }
  182. X
  183. #include "gdb_handler.c"
  184. X
  185. SHAR_EOF
  186. echo 'File mxgdb/handler.c is complete' &&
  187. chmod 0664 mxgdb/handler.c ||
  188. echo 'restore of mxgdb/handler.c failed'
  189. Wc_c="`wc -c < 'mxgdb/handler.c'`"
  190. test 6523 -eq "$Wc_c" ||
  191.     echo 'mxgdb/handler.c: original size 6523, current size' "$Wc_c"
  192. rm -f _shar_wnt_.tmp
  193. fi
  194. # ============= mxgdb/malloc.c ==============
  195. if test -f 'mxgdb/malloc.c' -a X"$1" != X"-c"; then
  196.     echo 'x - skipping mxgdb/malloc.c (File already exists)'
  197.     rm -f _shar_wnt_.tmp
  198. else
  199. > _shar_wnt_.tmp
  200. echo 'x - extracting mxgdb/malloc.c (Text)'
  201. sed 's/^X//' << 'SHAR_EOF' > 'mxgdb/malloc.c' &&
  202. static char rcsid[] = "$Id: malloc.c,v 1.1.1.1 1991/05/16 21:42:28 jtsillas Exp $";
  203. X
  204. /* dynamic memory allocation for GNU.
  205. X   Copyright (C) 1985, 1987 Free Software Foundation, Inc.
  206. X
  207. X               NO WARRANTY
  208. X
  209. X  BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
  210. NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW.  EXCEPT
  211. WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
  212. RICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
  213. WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
  214. BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  215. FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY
  216. AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE
  217. DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
  218. CORRECTION.
  219. X
  220. X IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
  221. STALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
  222. WHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
  223. LIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
  224. OTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
  225. USE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
  226. DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
  227. A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
  228. PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
  229. DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
  230. X
  231. X        GENERAL PUBLIC LICENSE TO COPY
  232. X
  233. X  1. You may copy and distribute verbatim copies of this source file
  234. as you receive it, in any medium, provided that you conspicuously and
  235. appropriately publish on each copy a valid copyright notice "Copyright
  236. (C) 1985 Free Software Foundation, Inc."; and include following the
  237. copyright notice a verbatim copy of the above disclaimer of warranty
  238. and of this License.  You may charge a distribution fee for the
  239. physical act of transferring a copy.
  240. X
  241. X  2. You may modify your copy or copies of this source file or
  242. any portion of it, and copy and distribute such modifications under
  243. the terms of Paragraph 1 above, provided that you also do the following:
  244. X
  245. X    a) cause the modified files to carry prominent notices stating
  246. X    that you changed the files and the date of any change; and
  247. X
  248. X    b) cause the whole of any work that you distribute or publish,
  249. X    that in whole or in part contains or is a derivative of this
  250. X    program or any part thereof, to be licensed at no charge to all
  251. X    third parties on terms identical to those contained in this
  252. X    License Agreement (except that you may choose to grant more extensive
  253. X    warranty protection to some or all third parties, at your option).
  254. X
  255. X    c) You may charge a distribution fee for the physical act of
  256. X    transferring a copy, and you may at your option offer warranty
  257. X    protection in exchange for a fee.
  258. X
  259. Mere aggregation of another unrelated program with this program (or its
  260. derivative) on a volume of a storage or distribution medium does not bring
  261. the other program under the scope of these terms.
  262. X
  263. X  3. You may copy and distribute this program (or a portion or derivative
  264. of it, under Paragraph 2) in object code or executable form under the terms
  265. of Paragraphs 1 and 2 above provided that you also do one of the following:
  266. X
  267. X    a) accompany it with the complete corresponding machine-readable
  268. X    source code, which must be distributed under the terms of
  269. X    Paragraphs 1 and 2 above; or,
  270. X
  271. X    b) accompany it with a written offer, valid for at least three
  272. X    years, to give any third party free (except for a nominal
  273. X    shipping charge) a complete machine-readable copy of the
  274. X    corresponding source code, to be distributed under the terms of
  275. X    Paragraphs 1 and 2 above; or,
  276. X
  277. X    c) accompany it with the information you received as to where the
  278. X    corresponding source code may be obtained.  (This alternative is
  279. X    allowed only for noncommercial distribution and only if you
  280. X    received the program in object code or executable form alone.)
  281. X
  282. For an executable file, complete source code means all the source code for
  283. all modules it contains; but, as a special exception, it need not include
  284. source code for modules which are standard libraries that accompany the
  285. operating system on which the executable file runs.
  286. X
  287. X  4. You may not copy, sublicense, distribute or transfer this program
  288. except as expressly provided under this License Agreement.  Any attempt
  289. otherwise to copy, sublicense, distribute or transfer this program is void and
  290. your rights to use the program under this License agreement shall be
  291. automatically terminated.  However, parties who have received computer
  292. software programs from you with this License Agreement will not have
  293. their licenses terminated so long as such parties remain in full compliance.
  294. X
  295. X  5. If you wish to incorporate parts of this program into other free
  296. programs whose distribution conditions are different, write to the Free
  297. Software Foundation at 675 Mass Ave, Cambridge, MA 02139.  We have not yet
  298. worked out a simple rule that can be stated here, but we will often permit
  299. this.  We will be guided by the two goals of preserving the free status of
  300. all derivatives of our free software and of promoting the sharing and reuse of
  301. software.
  302. X
  303. X
  304. In other words, you are welcome to use, share and improve this program.
  305. You are forbidden to forbid anyone else to use, share and improve
  306. what you give them.   Help stamp out software-hoarding!  */
  307. X
  308. X
  309. /*
  310. X * @(#)nmalloc.c 1 (Caltech) 2/21/82
  311. X *
  312. X *    U of M Modified: 20 Jun 1983 ACT: strange hacks for Emacs
  313. X *
  314. X *    Nov 1983, Mike@BRL, Added support for 4.1C/4.2 BSD.
  315. X *
  316. X * This is a very fast storage allocator.  It allocates blocks of a small 
  317. X * number of different sizes, and keeps free lists of each size.  Blocks
  318. X * that don't exactly fit are passed up to the next larger size.  In this 
  319. X * implementation, the available sizes are (2^n)-4 (or -16) bytes long.
  320. X * This is designed for use in a program that uses vast quantities of
  321. X * memory, but bombs when it runs out.  To make it a little better, it
  322. X * warns the user when he starts to get near the end.
  323. X *
  324. X * June 84, ACT: modified rcheck code to check the range given to malloc,
  325. X * rather than the range determined by the 2-power used.
  326. X *
  327. X * Jan 85, RMS: calls malloc_warning to issue warning on nearly full.
  328. X * No longer Emacs-specific; can serve as all-purpose malloc for GNU.
  329. X * You should call malloc_init to reinitialize after loading dumped Emacs.
  330. X * Call malloc_stats to get info on memory stats if MSTATS turned on.
  331. X * realloc knows how to return same block given, just changing its size,
  332. X * if the power of 2 is correct.
  333. X */
  334. X
  335. /*
  336. X * nextf[i] is the pointer to the next free block of size 2^(i+3).  The
  337. X * smallest allocatable block is 8 bytes.  The overhead information will
  338. X * go in the first int of the block, and the returned pointer will point
  339. X * to the second.
  340. X *
  341. #ifdef MSTATS
  342. X * nmalloc[i] is the difference between the number of mallocs and frees
  343. X * for a given block size.
  344. #endif MSTATS
  345. X */
  346. X
  347. #ifdef emacs
  348. /* config.h specifies which kind of system this is.  */
  349. #include "config.h"
  350. #else
  351. X
  352. /* Determine which kind of system this is.  */
  353. #ifndef USG
  354. #include <signal.h>
  355. #ifndef SIGTSTP
  356. #ifndef VMS
  357. #ifndef USG
  358. #define USG
  359. #endif
  360. #endif /* not VMS */
  361. #else /* SIGTSTP */
  362. #ifdef SIGIO
  363. #define BSD4_2
  364. #endif /* SIGIO */
  365. #endif /* SIGTSTP */
  366. #endif
  367. X
  368. #endif /* not emacs */
  369. X
  370. /* Define getpagesize () if the system does not.  */
  371. #include "getpagesize.h"
  372. X
  373. #ifndef BSD4_2
  374. #ifndef USG
  375. #include <sys/vlimit.h>        /* warn the user when near the end */
  376. #endif /* not USG */
  377. #else /* if BSD4_2 */
  378. #include <sys/time.h>
  379. #include <sys/resource.h>
  380. #endif /* BSD4_2 */
  381. X
  382. extern char *start_of_data ();
  383. X
  384. #ifdef BSD
  385. #ifndef DATA_SEG_BITS
  386. #define start_of_data() &etext
  387. #endif
  388. #endif
  389. X
  390. #ifndef emacs
  391. #define start_of_data() &etext
  392. #endif
  393. X
  394. #define ISALLOC ((char) 0xf7)    /* magic byte that implies allocation */
  395. #define ISFREE ((char) 0x54)    /* magic byte that implies free block */
  396. X                /* this is for error checking only */
  397. #define ISMEMALIGN ((char) 0xd6)  /* Stored before the value returned by
  398. X                     memalign, with the rest of the word
  399. X                     being the distance to the true
  400. X                     beginning of the block.  */
  401. X
  402. extern char etext;
  403. X
  404. /* These two are for user programs to look at, when they are interested.  */
  405. X
  406. unsigned int malloc_sbrk_used;       /* amount of data space used now */
  407. unsigned int malloc_sbrk_unused;     /* amount more we can have */
  408. X
  409. /* start of data space; can be changed by calling init_malloc */
  410. static char *data_space_start;
  411. X
  412. #ifdef MSTATS
  413. static int nmalloc[30];
  414. static int nmal, nfre;
  415. #endif /* MSTATS */
  416. X
  417. /* If range checking is not turned on, all we have is a flag indicating
  418. X   whether memory is allocated, an index in nextf[], and a size field; to
  419. X   realloc() memory we copy either size bytes or 1<<(index+3) bytes depending
  420. X   on whether the former can hold the exact size (given the value of
  421. X   'index').  If range checking is on, we always need to know how much space
  422. X   is allocated, so the 'size' field is never used. */
  423. X
  424. struct mhead {
  425. X    char     mh_alloc;    /* ISALLOC or ISFREE */
  426. X    char     mh_index;    /* index in nextf[] */
  427. /* Remainder are valid only when block is allocated */
  428. X    unsigned short mh_size;    /* size, if < 0x10000 */
  429. #ifdef rcheck
  430. X    unsigned mh_nbytes;    /* number of bytes allocated */
  431. X    int      mh_magic4;    /* should be == MAGIC4 */
  432. #endif /* rcheck */
  433. };
  434. X
  435. /* Access free-list pointer of a block.
  436. X  It is stored at block + 4.
  437. X  This is not a field in the mhead structure
  438. X  because we want sizeof (struct mhead)
  439. X  to describe the overhead for when the block is in use,
  440. X  and we do not want the free-list pointer to count in that.  */
  441. X
  442. #define CHAIN(a) \
  443. X  (*(struct mhead **) (sizeof (char *) + (char *) (a)))
  444. X
  445. #ifdef rcheck
  446. X
  447. /* To implement range checking, we write magic values in at the beginning and
  448. X   end of each allocated block, and make sure they are undisturbed whenever a
  449. X   free or a realloc occurs. */
  450. /* Written in each of the 4 bytes following the block's real space */
  451. #define MAGIC1 0x55
  452. /* Written in the 4 bytes before the block's real space */
  453. #define MAGIC4 0x55555555
  454. #define ASSERT(p) if (!(p)) botch("p"); else
  455. #define EXTRA  4        /* 4 bytes extra for MAGIC1s */
  456. #else
  457. #define ASSERT(p)
  458. #define EXTRA  0
  459. #endif /* rcheck */
  460. X
  461. X
  462. /* nextf[i] is free list of blocks of size 2**(i + 3)  */
  463. X
  464. static struct mhead *nextf[30];
  465. X
  466. /* busy[i] is nonzero while allocation of block size i is in progress.  */
  467. X
  468. static char busy[30];
  469. X
  470. /* Number of bytes of writable memory we can expect to be able to get */
  471. static unsigned int lim_data;
  472. X
  473. /* Level number of warnings already issued.
  474. X  0 -- no warnings issued.
  475. X  1 -- 75% warning already issued.
  476. X  2 -- 85% warning already issued.
  477. */
  478. static int warnlevel;
  479. X
  480. /* Function to call to issue a warning;
  481. X   0 means don't issue them.  */
  482. static void (*warnfunction) ();
  483. X
  484. /* nonzero once initial bunch of free blocks made */
  485. static int gotpool;
  486. X
  487. char *_malloc_base;
  488. X
  489. static void getpool ();
  490. X
  491. /* Cause reinitialization based on job parameters;
  492. X  also declare where the end of pure storage is. */
  493. void
  494. malloc_init (start, warnfun)
  495. X     char *start;
  496. X     void (*warnfun) ();
  497. {
  498. X  if (start)
  499. X    data_space_start = start;
  500. X  lim_data = 0;
  501. X  warnlevel = 0;
  502. X  warnfunction = warnfun;
  503. }
  504. X
  505. /* Return the maximum size to which MEM can be realloc'd
  506. X   without actually requiring copying.  */
  507. X
  508. int
  509. malloc_usable_size (mem)
  510. X     char *mem;
  511. {
  512. X  int blocksize = 8 << (((struct mhead *) mem) - 1) -> mh_index;
  513. X
  514. X  return blocksize - sizeof (struct mhead) - EXTRA;
  515. }
  516. X
  517. static void
  518. morecore (nu)            /* ask system for more memory */
  519. X     register int nu;        /* size index to get more of  */
  520. {
  521. X  char *sbrk ();
  522. X  register char *cp;
  523. X  register int nblks;
  524. X  register unsigned int siz;
  525. X  int oldmask;
  526. X
  527. #ifdef BSD
  528. #ifndef BSD4_1
  529. X  /* ?? There was a suggestion not to block SIGILL, somehow for GDB's sake.  */
  530. X  oldmask = sigsetmask (-1);
  531. #endif
  532. #endif
  533. X
  534. X  if (!data_space_start)
  535. X    {
  536. X      data_space_start = start_of_data ();
  537. X    }
  538. X
  539. X  if (lim_data == 0)
  540. X    get_lim_data ();
  541. X
  542. X /* On initial startup, get two blocks of each size up to 1k bytes */
  543. X  if (!gotpool)
  544. X    { getpool (); getpool (); gotpool = 1; }
  545. X
  546. X  /* Find current end of memory and issue warning if getting near max */
  547. X
  548. #ifndef VMS
  549. X  /* Maximum virtual memory on VMS is difficult to calculate since it
  550. X   * depends on several dynmacially changing things. Also, alignment
  551. X   * isn't that important. That is why much of the code here is ifdef'ed
  552. X   * out for VMS systems.
  553. X   */
  554. X  cp = sbrk (0);
  555. X  siz = cp - data_space_start;
  556. X
  557. X  if (warnfunction)
  558. X    switch (warnlevel)
  559. X      {
  560. X      case 0: 
  561. X    if (siz > (lim_data / 4) * 3)
  562. X      {
  563. X        warnlevel++;
  564. X        (*warnfunction) ("Warning: past 75% of memory limit");
  565. X      }
  566. X    break;
  567. X      case 1: 
  568. X    if (siz > (lim_data / 20) * 17)
  569. X      {
  570. X        warnlevel++;
  571. X        (*warnfunction) ("Warning: past 85% of memory limit");
  572. X      }
  573. X    break;
  574. X      case 2: 
  575. X    if (siz > (lim_data / 20) * 19)
  576. X      {
  577. X        warnlevel++;
  578. X        (*warnfunction) ("Warning: past 95% of memory limit");
  579. X      }
  580. X    break;
  581. X      }
  582. X
  583. X  if ((int) cp & 0x3ff)    /* land on 1K boundaries */
  584. X    sbrk (1024 - ((int) cp & 0x3ff));
  585. #endif /* not VMS */
  586. X
  587. X /* Take at least 2k, and figure out how many blocks of the desired size
  588. X    we're about to get */
  589. X  nblks = 1;
  590. X  if ((siz = nu) < 8)
  591. X    nblks = 1 << ((siz = 8) - nu);
  592. X
  593. X  if ((cp = sbrk (1 << (siz + 3))) == (char *) -1)
  594. X    {
  595. #ifdef BSD
  596. #ifndef BSD4_1
  597. X      sigsetmask (oldmask);
  598. #endif
  599. #endif
  600. X      return;            /* no more room! */
  601. X    }
  602. X  malloc_sbrk_used = siz;
  603. X  malloc_sbrk_unused = lim_data - siz;
  604. X
  605. #ifndef VMS
  606. X  if ((int) cp & 7)
  607. X    {        /* shouldn't happen, but just in case */
  608. X      cp = (char *) (((int) cp + 8) & ~7);
  609. X      nblks--;
  610. X    }
  611. #endif /* not VMS */
  612. X
  613. X /* save new header and link the nblks blocks together */
  614. X  nextf[nu] = (struct mhead *) cp;
  615. X  siz = 1 << (nu + 3);
  616. X  while (1)
  617. X    {
  618. X      ((struct mhead *) cp) -> mh_alloc = ISFREE;
  619. X      ((struct mhead *) cp) -> mh_index = nu;
  620. X      if (--nblks <= 0) break;
  621. X      CHAIN ((struct mhead *) cp) = (struct mhead *) (cp + siz);
  622. X      cp += siz;
  623. X    }
  624. X  CHAIN ((struct mhead *) cp) = 0;
  625. X
  626. #ifdef BSD
  627. #ifndef BSD4_1
  628. X  sigsetmask (oldmask);
  629. #endif
  630. #endif
  631. }
  632. X
  633. static void
  634. getpool ()
  635. {
  636. X  register int nu;
  637. X  char * sbrk ();
  638. X  register char *cp = sbrk (0);
  639. X
  640. X  if ((int) cp & 0x3ff)    /* land on 1K boundaries */
  641. X    sbrk (1024 - ((int) cp & 0x3ff));
  642. X
  643. X  /* Record address of start of space allocated by malloc.  */
  644. X  if (_malloc_base == 0)
  645. X    _malloc_base = cp;
  646. X
  647. X  /* Get 2k of storage */
  648. X
  649. X  cp = sbrk (04000);
  650. X  if (cp == (char *) -1)
  651. X    return;
  652. X
  653. X  /* Divide it into an initial 8-word block
  654. X     plus one block of size 2**nu for nu = 3 ... 10.  */
  655. X
  656. X  CHAIN (cp) = nextf[0];
  657. X  nextf[0] = (struct mhead *) cp;
  658. X  ((struct mhead *) cp) -> mh_alloc = ISFREE;
  659. X  ((struct mhead *) cp) -> mh_index = 0;
  660. X  cp += 8;
  661. X
  662. X  for (nu = 0; nu < 7; nu++)
  663. X    {
  664. X      CHAIN (cp) = nextf[nu];
  665. X      nextf[nu] = (struct mhead *) cp;
  666. X      ((struct mhead *) cp) -> mh_alloc = ISFREE;
  667. X      ((struct mhead *) cp) -> mh_index = nu;
  668. X      cp += 8 << nu;
  669. X    }
  670. }
  671. X
  672. char *
  673. malloc (n)        /* get a block */
  674. X     unsigned n;
  675. {
  676. X  register struct mhead *p;
  677. X  register unsigned int nbytes;
  678. X  register int nunits = 0;
  679. X
  680. X  /* Figure out how many bytes are required, rounding up to the nearest
  681. X     multiple of 8, then figure out which nestf[] area to use.
  682. X     Both the beginning of the header and the beginning of the
  683. X     block should be on an eight byte boundary.  */
  684. X  nbytes = (n + ((sizeof *p + 7) & ~7) + EXTRA + 7) & ~7;
  685. X  {
  686. X    register unsigned int   shiftr = (nbytes - 1) >> 2;
  687. X
  688. X    while (shiftr >>= 1)
  689. X      nunits++;
  690. X  }
  691. X
  692. X  /* In case this is reentrant use of malloc from signal handler,
  693. X     pick a block size that no other malloc level is currently
  694. X     trying to allocate.  That's the easiest harmless way not to
  695. X     interfere with the other level of execution.  */
  696. X  while (busy[nunits]) nunits++;
  697. X  busy[nunits] = 1;
  698. X
  699. X  /* If there are no blocks of the appropriate size, go get some */
  700. X  /* COULD SPLIT UP A LARGER BLOCK HERE ... ACT */
  701. X  if (nextf[nunits] == 0)
  702. X    morecore (nunits);
  703. X
  704. X  /* Get one block off the list, and set the new list head */
  705. X  if ((p = nextf[nunits]) == 0)
  706. X    {
  707. X      busy[nunits] = 0;
  708. X      return 0;
  709. X    }
  710. X  nextf[nunits] = CHAIN (p);
  711. X  busy[nunits] = 0;
  712. X
  713. X  /* Check for free block clobbered */
  714. X  /* If not for this check, we would gobble a clobbered free chain ptr */
  715. X  /* and bomb out on the NEXT allocate of this size block */
  716. X  if (p -> mh_alloc != ISFREE || p -> mh_index != nunits)
  717. #ifdef rcheck
  718. X    botch ("block on free list clobbered");
  719. #else /* not rcheck */
  720. X    abort ();
  721. #endif /* not rcheck */
  722. X
  723. X  /* Fill in the info, and if range checking, set up the magic numbers */
  724. X  p -> mh_alloc = ISALLOC;
  725. #ifdef rcheck
  726. X  p -> mh_nbytes = n;
  727. X  p -> mh_magic4 = MAGIC4;
  728. X  {
  729. X    /* Get the location n after the beginning of the user's space.  */
  730. X    register char *m = (char *) p + ((sizeof *p + 7) & ~7) + n;
  731. X
  732. X    *m++ = MAGIC1, *m++ = MAGIC1, *m++ = MAGIC1, *m = MAGIC1;
  733. X  }
  734. #else /* not rcheck */
  735. X  p -> mh_size = n;
  736. #endif /* not rcheck */
  737. #ifdef MSTATS
  738. X  nmalloc[nunits]++;
  739. X  nmal++;
  740. #endif /* MSTATS */
  741. X  return (char *) p + ((sizeof *p + 7) & ~7);
  742. }
  743. X
  744. free (mem)
  745. X     char *mem;
  746. {
  747. X  register struct mhead *p;
  748. X  {
  749. X    register char *ap = mem;
  750. X
  751. X    if (ap == 0)
  752. X      return;
  753. X
  754. X    p = (struct mhead *) (ap - ((sizeof *p + 7) & ~7));
  755. X    if (p -> mh_alloc == ISMEMALIGN)
  756. X      {
  757. X    ap -= p->mh_size;
  758. X    p = (struct mhead *) (ap - ((sizeof *p + 7) & ~7));
  759. X      }
  760. X
  761. #ifndef rcheck
  762. X    if (p -> mh_alloc != ISALLOC)
  763. X      abort ();
  764. X
  765. #else /* rcheck */
  766. X    if (p -> mh_alloc != ISALLOC)
  767. X      {
  768. X    if (p -> mh_alloc == ISFREE)
  769. X      botch ("free: Called with already freed block argument\n");
  770. X    else
  771. X      botch ("free: Called with bad argument\n");
  772. X      }
  773. X
  774. X    ASSERT (p -> mh_magic4 == MAGIC4);
  775. X    ap += p -> mh_nbytes;
  776. X    ASSERT (*ap++ == MAGIC1); ASSERT (*ap++ == MAGIC1);
  777. X    ASSERT (*ap++ == MAGIC1); ASSERT (*ap   == MAGIC1);
  778. #endif /* rcheck */
  779. X  }
  780. X  {
  781. X    register int nunits = p -> mh_index;
  782. X
  783. X    ASSERT (nunits <= 29);
  784. X    p -> mh_alloc = ISFREE;
  785. X
  786. X    /* Protect against signal handlers calling malloc.  */
  787. X    busy[nunits] = 1;
  788. X    /* Put this block on the free list.  */
  789. X    CHAIN (p) = nextf[nunits];
  790. X    nextf[nunits] = p;
  791. X    busy[nunits] = 0;
  792. X
  793. #ifdef MSTATS
  794. X    nmalloc[nunits]--;
  795. X    nfre++;
  796. #endif /* MSTATS */
  797. X  }
  798. }
  799. X
  800. char *
  801. realloc (mem, n)
  802. X     char *mem;
  803. X     register unsigned n;
  804. {
  805. X  register struct mhead *p;
  806. X  register unsigned int tocopy;
  807. X  register unsigned int nbytes;
  808. X  register int nunits;
  809. X
  810. X  if (mem == 0)
  811. X    return malloc (n);
  812. X  p = (struct mhead *) (mem - ((sizeof *p + 7) & ~7));
  813. X  nunits = p -> mh_index;
  814. X  ASSERT (p -> mh_alloc == ISALLOC);
  815. #ifdef rcheck
  816. X  ASSERT (p -> mh_magic4 == MAGIC4);
  817. X  {
  818. X    register char *m = mem + (tocopy = p -> mh_nbytes);
  819. X    ASSERT (*m++ == MAGIC1); ASSERT (*m++ == MAGIC1);
  820. X    ASSERT (*m++ == MAGIC1); ASSERT (*m   == MAGIC1);
  821. X  }
  822. #else /* not rcheck */
  823. X  if (p -> mh_index >= 13)
  824. X    tocopy = (1 << (p -> mh_index + 3)) - ((sizeof *p + 7) & ~7);
  825. X  else
  826. X    tocopy = p -> mh_size;
  827. #endif /* not rcheck */
  828. X
  829. X  /* See if desired size rounds to same power of 2 as actual size. */
  830. X  nbytes = (n + ((sizeof *p + 7) & ~7) + EXTRA + 7) & ~7;
  831. X
  832. X  /* If ok, use the same block, just marking its size as changed.  */
  833. X  if (nbytes > (4 << nunits) && nbytes <= (8 << nunits))
  834. X    {
  835. #ifdef rcheck
  836. X      register char *m = mem + tocopy;
  837. X      *m++ = 0;  *m++ = 0;  *m++ = 0;  *m++ = 0;
  838. X      p-> mh_nbytes = n;
  839. X      m = mem + n;
  840. X      *m++ = MAGIC1;  *m++ = MAGIC1;  *m++ = MAGIC1;  *m++ = MAGIC1;
  841. #else /* not rcheck */
  842. X      p -> mh_size = n;
  843. #endif /* not rcheck */
  844. X      return mem;
  845. X    }
  846. X
  847. X  if (n < tocopy)
  848. X    tocopy = n;
  849. X  {
  850. X    register char *new;
  851. X
  852. X    if ((new = malloc (n)) == 0)
  853. X      return 0;
  854. X    bcopy (mem, new, tocopy);
  855. X    free (mem);
  856. X    return new;
  857. X  }
  858. }
  859. X
  860. #ifndef VMS
  861. X
  862. char *
  863. memalign (alignment, size)
  864. X     unsigned alignment, size;
  865. {
  866. X  register char *ptr = malloc (size + alignment);
  867. X  register char *aligned;
  868. X  register struct mhead *p;
  869. X
  870. X  if (ptr == 0)
  871. X    return 0;
  872. X  /* If entire block has the desired alignment, just accept it.  */
  873. X  if (((int) ptr & (alignment - 1)) == 0)
  874. X    return ptr;
  875. X  /* Otherwise, get address of byte in the block that has that alignment.  */
  876. X  aligned = (char *) (((int) ptr + alignment - 1) & -alignment);
  877. X
  878. X  /* Store a suitable indication of how to free the block,
  879. X     so that free can find the true beginning of it.  */
  880. X  p = (struct mhead *) aligned - 1;
  881. X  p -> mh_size = aligned - ptr;
  882. X  p -> mh_alloc = ISMEMALIGN;
  883. X  return aligned;
  884. }
  885. X
  886. #ifndef HPUX
  887. /* This runs into trouble with getpagesize on HPUX.
  888. X   Patching out seems cleaner than the ugly fix needed.  */
  889. char *
  890. valloc (size)
  891. {
  892. X  return memalign (getpagesize (), size);
  893. }
  894. #endif /* not HPUX */
  895. #endif /* not VMS */
  896. X
  897. #ifdef MSTATS
  898. /* Return statistics describing allocation of blocks of size 2**n. */
  899. X
  900. struct mstats_value
  901. X  {
  902. X    int blocksize;
  903. X    int nfree;
  904. X    int nused;
  905. X  };
  906. X
  907. struct mstats_value
  908. malloc_stats (size)
  909. X     int size;
  910. {
  911. X  struct mstats_value v;
  912. X  register int i;
  913. X  register struct mhead *p;
  914. X
  915. X  v.nfree = 0;
  916. X
  917. X  if (size < 0 || size >= 30)
  918. X    {
  919. X      v.blocksize = 0;
  920. X      v.nused = 0;
  921. X      return v;
  922. X    }
  923. X
  924. X  v.blocksize = 1 << (size + 3);
  925. X  v.nused = nmalloc[size];
  926. X
  927. X  for (p = nextf[size]; p; p = CHAIN (p))
  928. X    v.nfree++;
  929. X
  930. X  return v;
  931. }
  932. int
  933. malloc_mem_used ()
  934. {
  935. X  int i;
  936. X  int size_used;
  937. X
  938. X  size_used = 0;
  939. X  
  940. X  for (i = 0; i < 30; i++)
  941. X    {
  942. X      int allocation_size = 1 << (i + 3);
  943. X      struct mhead *p;
  944. X      
  945. X      size_used += nmalloc[i] * allocation_size;
  946. X    }
  947. X
  948. X  return size_used;
  949. }
  950. X
  951. int 
  952. malloc_mem_free ()
  953. {
  954. X  int i;
  955. X  int size_unused;
  956. X
  957. X  size_unused = 0;
  958. X  
  959. X  for (i = 0; i < 30; i++)
  960. X    {
  961. X      int allocation_size = 1 << (i + 3);
  962. X      struct mhead *p;
  963. X      
  964. X      for (p = nextf[i]; p ; p = CHAIN (p))
  965. X    size_unused += allocation_size;
  966. X    }
  967. X
  968. X  return size_unused;
  969. }
  970. #endif /* MSTATS */
  971. X
  972. /*
  973. X *    This function returns the total number of bytes that the process
  974. X *    will be allowed to allocate via the sbrk(2) system call.  On
  975. X *    BSD systems this is the total space allocatable to stack and
  976. X *    data.  On USG systems this is the data space only.
  977. X */
  978. X
  979. #ifdef USG
  980. X
  981. get_lim_data ()
  982. {
  983. X  extern long ulimit ();
  984. X    
  985. #ifdef ULIMIT_BREAK_VALUE
  986. X  lim_data = ULIMIT_BREAK_VALUE;
  987. #else
  988. X  lim_data = ulimit (3, 0);
  989. #endif
  990. X
  991. X  lim_data -= (long) data_space_start;
  992. }
  993. X
  994. #else /* not USG */
  995. #ifndef BSD4_2
  996. X
  997. get_lim_data ()
  998. {
  999. X  lim_data = vlimit (LIM_DATA, -1);
  1000. }
  1001. X
  1002. #else /* BSD4_2 */
  1003. X
  1004. get_lim_data ()
  1005. {
  1006. X  struct rlimit XXrlimit;
  1007. X
  1008. X  getrlimit (RLIMIT_DATA, &XXrlimit);
  1009. #ifdef RLIM_INFINITY
  1010. X  lim_data = XXrlimit.rlim_cur & RLIM_INFINITY; /* soft limit */
  1011. #else
  1012. X  lim_data = XXrlimit.rlim_cur;    /* soft limit */
  1013. #endif
  1014. }
  1015. X
  1016. #endif /* BSD4_2 */
  1017. #endif /* not USG */
  1018. X
  1019. #ifdef VMS
  1020. /* There is a problem when dumping and restoring things on VMS. Calls
  1021. X * to SBRK don't necessarily result in contiguous allocation. Dumping
  1022. X * doesn't work when it isn't. Therefore, we make the initial
  1023. X * allocation contiguous by allocating a big chunk, and do SBRKs from
  1024. X * there. Once Emacs has dumped there is no reason to continue
  1025. X * contiguous allocation, malloc doesn't depend on it.
  1026. X *
  1027. X * There is a further problem of using brk and sbrk while using VMS C
  1028. X * run time library routines malloc, calloc, etc. The documentation
  1029. X * says that this is a no-no, although I'm not sure why this would be
  1030. X * a problem. In any case, we remove the necessity to call brk and
  1031. X * sbrk, by calling calloc (to assure zero filled data) rather than
  1032. X * sbrk.
  1033. X *
  1034. X * VMS_ALLOCATION_SIZE is the size of the allocation array. This
  1035. X * should be larger than the malloc size before dumping. Making this
  1036. X * too large will result in the startup procedure slowing down since
  1037. X * it will require more space and time to map it in.
  1038. X *
  1039. X * The value for VMS_ALLOCATION_SIZE in the following define was determined
  1040. X * by running emacs linked (and a large allocation) with the debugger and
  1041. X * looking to see how much storage was used. The allocation was 201 pages,
  1042. X * so I rounded it up to a power of two.
  1043. X */
  1044. #ifndef VMS_ALLOCATION_SIZE
  1045. #define VMS_ALLOCATION_SIZE    (512*256)
  1046. #endif
  1047. X
  1048. /* Use VMS RTL definitions */
  1049. #undef sbrk
  1050. #undef brk
  1051. #undef malloc
  1052. int vms_out_initial = 0;
  1053. char vms_initial_buffer[VMS_ALLOCATION_SIZE];
  1054. static char *vms_current_brk = &vms_initial_buffer;
  1055. static char *vms_end_brk = &vms_initial_buffer[VMS_ALLOCATION_SIZE-1];
  1056. X
  1057. #include <stdio.h>
  1058. X
  1059. char *
  1060. sys_sbrk (incr)
  1061. X     int incr;
  1062. {
  1063. X  char *sbrk(), *temp, *ptr;
  1064. X
  1065. X  if (vms_out_initial)
  1066. X    {
  1067. X      /* out of initial allocation... */
  1068. X      if (!(temp = malloc (incr)))
  1069. X    temp = (char *) -1;
  1070. X    }
  1071. X  else
  1072. X    {
  1073. X      /* otherwise, go out of our area */
  1074. X      ptr = vms_current_brk + incr; /* new current_brk */
  1075. X      if (ptr <= vms_end_brk)
  1076. X    {
  1077. X      temp = vms_current_brk;
  1078. X      vms_current_brk = ptr;
  1079. X    }
  1080. X      else
  1081. X    {
  1082. X      vms_out_initial = 1;    /* mark as out of initial allocation */
  1083. X      if (!(temp = malloc (incr)))
  1084. X        temp = (char *) -1;
  1085. X    }
  1086. X    }
  1087. X  return temp;
  1088. }
  1089. #endif /* VMS */
  1090. SHAR_EOF
  1091. chmod 0664 mxgdb/malloc.c ||
  1092. echo 'restore of mxgdb/malloc.c failed'
  1093. Wc_c="`wc -c < 'mxgdb/malloc.c'`"
  1094. test 25023 -eq "$Wc_c" ||
  1095.     echo 'mxgdb/malloc.c: original size 25023, current size' "$Wc_c"
  1096. rm -f _shar_wnt_.tmp
  1097. fi
  1098. # ============= mxgdb/parser.c ==============
  1099. if test -f 'mxgdb/parser.c' -a X"$1" != X"-c"; then
  1100.     echo 'x - skipping mxgdb/parser.c (File already exists)'
  1101.     rm -f _shar_wnt_.tmp
  1102. else
  1103. > _shar_wnt_.tmp
  1104. echo 'x - extracting mxgdb/parser.c (Text)'
  1105. sed 's/^X//' << 'SHAR_EOF' > 'mxgdb/parser.c' &&
  1106. static char rcsid[] = "$Id: parser.c,v 1.1.1.1 1991/05/16 21:42:31 jtsillas Exp $";
  1107. X
  1108. /*****************************************************************************
  1109. X *
  1110. X *  xdbx - X Window System interface to the dbx debugger
  1111. X *
  1112. X *  Copyright 1989 The University of Texas at Austin
  1113. X *  Copyright 1990 Microelectronics and Computer Technology Corporation
  1114. X *
  1115. X *  Permission to use, copy, modify, and distribute this software and its
  1116. X *  documentation for any purpose and without fee is hereby granted,
  1117. X *  provided that the above copyright notice appear in all copies and that
  1118. X *  both that copyright notice and this permission notice appear in
  1119. X *  supporting documentation, and that the name of The University of Texas
  1120. X *  and Microelectronics and Computer Technology Corporation (MCC) not be 
  1121. X *  used in advertising or publicity pertaining to distribution of
  1122. X *  the software without specific, written prior permission.  The
  1123. X *  University of Texas and MCC makes no representations about the 
  1124. X *  suitability of this software for any purpose.  It is provided "as is" 
  1125. X *  without express or implied warranty.
  1126. X *
  1127. X *  THE UNIVERSITY OF TEXAS AND MCC DISCLAIMS ALL WARRANTIES WITH REGARD TO
  1128. X *  THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1129. X *  FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF TEXAS OR MCC BE LIABLE FOR
  1130. X *  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  1131. X *  RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
  1132. X *  CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  1133. X *  CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  1134. X *
  1135. X *  Author:      Po Cheung
  1136. X *  Created:       March 10, 1989
  1137. X * 
  1138. X *****************************************************************************
  1139. X * 
  1140. X *  xxgdb - X Window System interface to the gdb debugger
  1141. X *  
  1142. X *     Copyright 1990 Thomson Consumer Electronics, Inc.
  1143. X *  
  1144. X *  Permission to use, copy, modify, and distribute this software and its
  1145. X *  documentation for any purpose and without fee is hereby granted,
  1146. X *  provided that the above copyright notice appear in all copies and that
  1147. X *  both that copyright notice and this permission notice appear in
  1148. X *  supporting documentation, and that the name of Thomson Consumer
  1149. X *  Electronics (TCE) not be used in advertising or publicity pertaining
  1150. X *  to distribution of the software without specific, written prior
  1151. X *  permission.  TCE makes no representations about the suitability of
  1152. X *  this software for any purpose.  It is provided "as is" without express
  1153. X *  or implied warranty.
  1154. X *
  1155. X *  TCE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  1156. X *  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
  1157. X *  SHALL TCE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
  1158. X *  OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  1159. X *  WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  1160. X *  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  1161. X *  SOFTWARE.
  1162. X *
  1163. X *  Adaptation to GDB:  Pierre Willard
  1164. X *  XXGDB Created:       December, 1990
  1165. X *
  1166. X *****************************************************************************/
  1167. X
  1168. /*  parser.c:
  1169. X *
  1170. X *    Parse output messages from dbx using regular expression pattern matching,
  1171. X *    and take appropriate action.
  1172. X *
  1173. X *    compile():    Compile the regular expressions in a table.
  1174. X *    match():        Try to best match a given string with the regular
  1175. X *            expressions found in the table and return an index.
  1176. X *    parser_init():    Initialization.
  1177. X *    parse():        Parse the dbx output and invoke the appropriate action
  1178. X *            handler.
  1179. X *    filter():        Modify the dbx output before it gets displayed on the
  1180. X *            dialog window.
  1181. X *    query_dbx():    Send a query command to dbx and process it.
  1182. X */
  1183. X
  1184. #include    "global.h"
  1185. #include    "regex.h"
  1186. #include    "gdb_regex.h"
  1187. #include        "datadpy.h"
  1188. X
  1189. #define BYTEWIDTH       8
  1190. #define RE_BUFFER       100
  1191. X
  1192. Tokens     Token;            /* gloabl token structure */
  1193. Boolean    Parse = True;        /* Parse flag for parse routine */
  1194. X
  1195. /*
  1196. X *  Compile all the regular expression patterns in a pattern table.
  1197. X *  A pattern table is an array of pattern records.
  1198. X *  Each pattern record consists of a regular
  1199. X *  expression, a buffer for the to-be-compiled regular expression,
  1200. X *  and an array to associate a given token with a matched register number.
  1201. X */
  1202. static void compile(patternTable)
  1203. PatternRec *patternTable;
  1204. {
  1205. X    PatternRec    *p;
  1206. X    char     fastmap[(1 << BYTEWIDTH)];
  1207. X    int        i;
  1208. X
  1209. X    for (i=0; patternTable[i].pat; i++) {
  1210. X    p = &patternTable[i];
  1211. X    p->buf = (struct re_pattern_buffer *) 
  1212. X      XtMalloc (sizeof (struct re_pattern_buffer));
  1213. X    p->buf->allocated = RE_BUFFER;
  1214. X    p->buf->buffer = (char *) XtMalloc (p->buf->allocated);
  1215. X    p->buf->fastmap = fastmap;
  1216. X    p->buf->translate = NULL;
  1217. X    re_compile_pattern(p->pat, strlen(p->pat), p->buf);
  1218. X    re_compile_fastmap(p->buf);
  1219. X    }
  1220. X
  1221. /*
  1222. X *  This routine tries to match a given string with each regular 
  1223. X *  expression in a given pattern table.  The best match is found, and
  1224. X *  the function returns an index to the pattern table.
  1225. X */
  1226. int match(patternTable, string, type)
  1227. X    PatternRec     *patternTable;
  1228. X    char     *string;
  1229. X    int        type;
  1230. {
  1231. X    struct re_registers    regs;
  1232. X    int            m, bestmatch = -1, index = -1, i, j, r, start, n;
  1233. X    char         *s;
  1234. X
  1235. X    if (!strcmp(string, "")) return -1;
  1236. X    for (i=0; patternTable[i].pat; i++) {
  1237. X    if (type != C_ANY && type != i)
  1238. X        continue;
  1239. X    m = re_match(patternTable[i].buf, string, strlen(string), 0, ®s);
  1240. X    if (m == -2 ) {        /* match error - failure stack overflow */
  1241. X        fprintf(stderr, "mxgdb error: regular expression matching failed \
  1242. (failure stack overflow)\n");
  1243. X        return (-1);
  1244. X    }
  1245. X    if (m > bestmatch) {
  1246. X        bestmatch = m;
  1247. X        index = i;
  1248. X        /* for GDB, free memory (if not done earlier) */
  1249. X        XtFree(Token.mesg);
  1250. X        XtFree(Token.file);
  1251. X        XtFree(Token.func);
  1252. X        XtFree(Token.display);
  1253. X        Token.mesg = Token.file = Token.func = Token.display = NULL;
  1254. X        Token.line = Token.stop = 0;
  1255. X        for (j=0; j<NTOKENS; j++) {
  1256. X        if ((r = patternTable[i].reg_token[j]) >= 0) {
  1257. X            start = regs.start[r];
  1258. X            if ((n = regs.end[r] - start) > 0) {
  1259. X        /* The following error could happen if the pattern table is not correct,
  1260. X        better test it here.. */
  1261. X        
  1262. X            if ( n > strlen(string))    /* Something is wrong here ! */
  1263. X                {
  1264. X                fprintf(stderr,"Error match() : n = %d is too big\n",n);
  1265. X                n = 0;
  1266. X                }
  1267. X            s = (char *) XtMalloc ((n+1) * sizeof(char));
  1268. X            strncpy(s, string+start, n);
  1269. X            s[n] = '\0';
  1270. X                switch (j) {
  1271. X              case TK_MESG: Token.mesg = s; break;
  1272. X              case TK_STOP: Token.stop = atoi(s); XtFree(s); break;
  1273. X              case TK_FUNC: Token.func = s; break;
  1274. X              case TK_LINE: Token.line = atoi(s); XtFree(s); break;
  1275. X              case TK_FILE: Token.file = s; break;
  1276. X              case TK_DISP: Token.display = s; break;
  1277. X                }
  1278. X            }
  1279. X        }
  1280. X        }
  1281. X    }
  1282. X    }
  1283. X    return index;
  1284. }
  1285. X
  1286. /*  Compile the regular expressions in the output and command pattern tables. */
  1287. X
  1288. void parser_init()
  1289. {
  1290. X    compile(output_pattern);
  1291. X    compile(command_pattern);
  1292. X    compile(dataPattern);
  1293. }
  1294. X
  1295. #include "gdb_parser.c"
  1296. X
  1297. SHAR_EOF
  1298. chmod 0664 mxgdb/parser.c ||
  1299. echo 'restore of mxgdb/parser.c failed'
  1300. Wc_c="`wc -c < 'mxgdb/parser.c'`"
  1301. test 7042 -eq "$Wc_c" ||
  1302.     echo 'mxgdb/parser.c: original size 7042, current size' "$Wc_c"
  1303. rm -f _shar_wnt_.tmp
  1304. fi
  1305. # ============= mxgdb/patchlevel.h ==============
  1306. if test -f 'mxgdb/patchlevel.h' -a X"$1" != X"-c"; then
  1307.     echo 'x - skipping mxgdb/patchlevel.h (File already exists)'
  1308.     rm -f _shar_wnt_.tmp
  1309. else
  1310. > _shar_wnt_.tmp
  1311. echo 'x - extracting mxgdb/patchlevel.h (Text)'
  1312. sed 's/^X//' << 'SHAR_EOF' > 'mxgdb/patchlevel.h' &&
  1313. /* $Id: patchlevel.h,v 1.1.1.1 1991/05/16 21:42:34 jtsillas Exp $ */
  1314. SHAR_EOF
  1315. true || echo 'restore of mxgdb/patchlevel.h failed'
  1316. fi
  1317. echo 'End of  part 7'
  1318. echo 'File mxgdb/patchlevel.h is continued in part 8'
  1319. echo 8 > _shar_seq_.tmp
  1320. exit 0
  1321. --
  1322.  == James Tsillas                    Bull HN Information Systems Inc. ==
  1323.  == (508) 294-2937                   300 Concord Road   826A          ==
  1324.  == jtsillas@bubba.ma30.bull.com     Billerica, MA 01821              ==
  1325.  ==                                                                   ==
  1326.  == The opinions expressed above are solely my own and do not reflect ==
  1327.  == those of my employer.                                             ==
  1328.             -== no solicitations please ==-
  1329.