home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-07-17 | 40.5 KB | 1,330 lines |
- Newsgroups: alt.sources
- From: jtsillas@sprite.ma30.bull.com (James Tsillas)
- Subject: mxgdb Part 7/9
- Date: 16 Jul 91 13:13:10
- Message-ID: <JTSILLAS.91Jul16131310@sprite.ma30.bull.com>
-
-
-
- ---- Cut Here and feed the following to sh ----
- #!/bin/sh
- # this is mxgdb.07 (part 7 of a multipart archive)
- # do not concatenate these parts, unpack them in order with /bin/sh
- # file mxgdb/handler.c continued
- #
- if test ! -r _shar_seq_.tmp; then
- echo 'Please unpack part 1 first!'
- exit 1
- fi
- (read Scheck
- if test "$Scheck" != 7; then
- echo Please unpack part "$Scheck" next!
- exit 1
- else
- exit 0
- fi
- ) < _shar_seq_.tmp || exit 1
- if test ! -f _shar_wnt_.tmp; then
- echo 'x - still skipping mxgdb/handler.c'
- else
- echo 'x - continuing file mxgdb/handler.c'
- sed 's/^X//' << 'SHAR_EOF' >> 'mxgdb/handler.c' &&
- X * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- X * FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF TEXAS OR MCC BE LIABLE FOR
- X * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
- X * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
- X * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- X * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- X *
- X * Author: Po Cheung
- X * Created: March 10, 1989
- X *
- X *****************************************************************************
- X *
- X * xxgdb - X Window System interface to the gdb debugger
- X *
- X * Copyright 1990 Thomson Consumer Electronics, Inc.
- X *
- X * Permission to use, copy, modify, and distribute this software and its
- X * documentation for any purpose and without fee is hereby granted,
- X * provided that the above copyright notice appear in all copies and that
- X * both that copyright notice and this permission notice appear in
- X * supporting documentation, and that the name of Thomson Consumer
- X * Electronics (TCE) not be used in advertising or publicity pertaining
- X * to distribution of the software without specific, written prior
- X * permission. TCE makes no representations about the suitability of
- X * this software for any purpose. It is provided "as is" without express
- X * or implied warranty.
- X *
- X * TCE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
- X * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
- X * SHALL TCE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
- X * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- X * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
- X * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- X * SOFTWARE.
- X *
- X * Adaptation to GDB: Pierre Willard
- X * XXGDB Created: December, 1990
- X *
- X *****************************************************************************/
- X
- /* handler.c
- X *
- X * Contain action handlers for the parser to invoke upon a dbx command.
- X *
- X * TextSetTopPosition(): Set the top character position of textdisplayed
- X * AdjustText(): Adjust the portion of text displayed.
- X * exec_handler(): Update file, line label, arrow position.
- X * done_handler(): Progrm execution completed, clear breakpoints
- X * stop_at_handler(): Place stop sign on line specified.
- X * stop_in_handler(): Place stop sign on function specified.
- X * updown_handler(): Update file, line label, updown arrow position.
- X * clear_handler(): Remove stop sign.
- X * func_handler(): Display function, if specified.
- X * file_handler(): Display file, if specified.
- X * debug_handler(): Check directory use list, display source file.
- X * cd_handler(): Record current working directory.
- X * use_handler(): Record directory paths.
- X * search_handler(): Adjust source file to display matched line.
- X * list_handler(); Adjust source file to display result.
- X * display_handler(): Display results in display window.
- X */
- X
- #include <ctype.h>
- #include "global.h"
- #include <Xm/Xm.h>
- #include <Xm/Text.h>
- X
- #ifdef BSD
- #define BRACKET "[%d]"
- #else
- #define BRACKET "(%d)"
- #endif
- X
- Boolean Echo = True; /* display dbx output if true */
- static Boolean Skip_func_handler = False;
- X
- /* Display text starting from the top position specified by pos */
- X
- void TextSetTopPosition(w, pos)
- X Widget w;
- X XmTextPosition pos;
- {
- X Arg args[MAXARGS];
- X
- X XtSetArg(args[0], XmNtopCharacter, (XtArgVal) pos);
- X XtSetValues(w, args, 1);
- }
- X
- short currpos;
- X
- /*
- X * Adjust text so that 'line' will fall into the viewable part of the
- X * source window.
- X * Arrows, stop signs, and line label and Vertical Scroll bar
- X * are updated accordingly.
- X */
- void AdjustText(line)
- X int line;
- {
- X FileRec *file;
- X int nlines = 0;
- X int i;
- X XmTextPosition pos;
- X Dimension width;
- X Arg args[5];
- X
- X if ((file = displayedFile) == NULL || line <= 0) return;
- X file->currentline = line;
- X
- X if (line < file->topline || line > file->bottomline ) {
- X /* Position line about 30% from the top */
- X nlines = file->lines*0.3;
- X if (line < nlines) /* near top */
- X file->topline = 1;
- X else if (line > file->lastline - nlines) /* near bottom */
- X file->topline = MAX(file->lastline - file->lines + 1, 1);
- X else
- X file->topline = line - nlines;
- X file->bottomline = MIN(file->topline + file->lines - 1,
- X file->lastline);
- X TextSetTopPosition(sourceWindow, file->linepos[file->topline]);
- X file->topPosition = file->linepos[file->topline];
- X }
- X XmTextSetInsertionPosition(sourceWindow, file->linepos[line]);
- X
- X /* Text window might have scrolled, check topline & bottomline */
- X pos = XmTextGetTopCharacter(sourceWindow);
- X
- X for (i=1; pos >= file->linepos[i]; i++);
- X if (file->topline != i-1) {
- X file->topline = i-1;
- X file->bottomline = MIN (file->topline + file->lines - 1,
- X file->lastline);
- X }
- X
- X if(pos != currpos && XtIsManaged(scrollV))
- X {
- X XtSetArg(args[0], XmNvalue, TextPositionToLine(pos));
- X XtSetValues(scrollV, args, 1);
- X currpos = pos;
- X }
- X
- X XtMapWidget(sourceWindow);
- X
- X UpdateLineLabel(line);
- X UpdateStops(file, -1);
- X UpdateArrow(file);
- X UpdateUpdown(file);
- X UpdateBomb(file);
- }
- X
- #include "gdb_handler.c"
- X
- SHAR_EOF
- echo 'File mxgdb/handler.c is complete' &&
- chmod 0664 mxgdb/handler.c ||
- echo 'restore of mxgdb/handler.c failed'
- Wc_c="`wc -c < 'mxgdb/handler.c'`"
- test 6523 -eq "$Wc_c" ||
- echo 'mxgdb/handler.c: original size 6523, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= mxgdb/malloc.c ==============
- if test -f 'mxgdb/malloc.c' -a X"$1" != X"-c"; then
- echo 'x - skipping mxgdb/malloc.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting mxgdb/malloc.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'mxgdb/malloc.c' &&
- static char rcsid[] = "$Id: malloc.c,v 1.1.1.1 1991/05/16 21:42:28 jtsillas Exp $";
- X
- /* dynamic memory allocation for GNU.
- X Copyright (C) 1985, 1987 Free Software Foundation, Inc.
- X
- X NO WARRANTY
- X
- X BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
- NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW. EXCEPT
- WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
- RICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
- WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
- BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY
- AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
- DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
- CORRECTION.
- X
- X IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
- STALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
- WHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
- LIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
- OTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
- USE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
- DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
- A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
- PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
- DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
- X
- X GENERAL PUBLIC LICENSE TO COPY
- X
- X 1. You may copy and distribute verbatim copies of this source file
- as you receive it, in any medium, provided that you conspicuously and
- appropriately publish on each copy a valid copyright notice "Copyright
- (C) 1985 Free Software Foundation, Inc."; and include following the
- copyright notice a verbatim copy of the above disclaimer of warranty
- and of this License. You may charge a distribution fee for the
- physical act of transferring a copy.
- X
- X 2. You may modify your copy or copies of this source file or
- any portion of it, and copy and distribute such modifications under
- the terms of Paragraph 1 above, provided that you also do the following:
- X
- X a) cause the modified files to carry prominent notices stating
- X that you changed the files and the date of any change; and
- X
- X b) cause the whole of any work that you distribute or publish,
- X that in whole or in part contains or is a derivative of this
- X program or any part thereof, to be licensed at no charge to all
- X third parties on terms identical to those contained in this
- X License Agreement (except that you may choose to grant more extensive
- X warranty protection to some or all third parties, at your option).
- X
- X c) You may charge a distribution fee for the physical act of
- X transferring a copy, and you may at your option offer warranty
- X protection in exchange for a fee.
- X
- Mere aggregation of another unrelated program with this program (or its
- derivative) on a volume of a storage or distribution medium does not bring
- the other program under the scope of these terms.
- X
- X 3. You may copy and distribute this program (or a portion or derivative
- of it, under Paragraph 2) in object code or executable form under the terms
- of Paragraphs 1 and 2 above provided that you also do one of the following:
- X
- X a) accompany it with the complete corresponding machine-readable
- X source code, which must be distributed under the terms of
- X Paragraphs 1 and 2 above; or,
- X
- X b) accompany it with a written offer, valid for at least three
- X years, to give any third party free (except for a nominal
- X shipping charge) a complete machine-readable copy of the
- X corresponding source code, to be distributed under the terms of
- X Paragraphs 1 and 2 above; or,
- X
- X c) accompany it with the information you received as to where the
- X corresponding source code may be obtained. (This alternative is
- X allowed only for noncommercial distribution and only if you
- X received the program in object code or executable form alone.)
- X
- For an executable file, complete source code means all the source code for
- all modules it contains; but, as a special exception, it need not include
- source code for modules which are standard libraries that accompany the
- operating system on which the executable file runs.
- X
- X 4. You may not copy, sublicense, distribute or transfer this program
- except as expressly provided under this License Agreement. Any attempt
- otherwise to copy, sublicense, distribute or transfer this program is void and
- your rights to use the program under this License agreement shall be
- automatically terminated. However, parties who have received computer
- software programs from you with this License Agreement will not have
- their licenses terminated so long as such parties remain in full compliance.
- X
- X 5. If you wish to incorporate parts of this program into other free
- programs whose distribution conditions are different, write to the Free
- Software Foundation at 675 Mass Ave, Cambridge, MA 02139. We have not yet
- worked out a simple rule that can be stated here, but we will often permit
- this. We will be guided by the two goals of preserving the free status of
- all derivatives of our free software and of promoting the sharing and reuse of
- software.
- X
- X
- In other words, you are welcome to use, share and improve this program.
- You are forbidden to forbid anyone else to use, share and improve
- what you give them. Help stamp out software-hoarding! */
- X
- X
- /*
- X * @(#)nmalloc.c 1 (Caltech) 2/21/82
- X *
- X * U of M Modified: 20 Jun 1983 ACT: strange hacks for Emacs
- X *
- X * Nov 1983, Mike@BRL, Added support for 4.1C/4.2 BSD.
- X *
- X * This is a very fast storage allocator. It allocates blocks of a small
- X * number of different sizes, and keeps free lists of each size. Blocks
- X * that don't exactly fit are passed up to the next larger size. In this
- X * implementation, the available sizes are (2^n)-4 (or -16) bytes long.
- X * This is designed for use in a program that uses vast quantities of
- X * memory, but bombs when it runs out. To make it a little better, it
- X * warns the user when he starts to get near the end.
- X *
- X * June 84, ACT: modified rcheck code to check the range given to malloc,
- X * rather than the range determined by the 2-power used.
- X *
- X * Jan 85, RMS: calls malloc_warning to issue warning on nearly full.
- X * No longer Emacs-specific; can serve as all-purpose malloc for GNU.
- X * You should call malloc_init to reinitialize after loading dumped Emacs.
- X * Call malloc_stats to get info on memory stats if MSTATS turned on.
- X * realloc knows how to return same block given, just changing its size,
- X * if the power of 2 is correct.
- X */
- X
- /*
- X * nextf[i] is the pointer to the next free block of size 2^(i+3). The
- X * smallest allocatable block is 8 bytes. The overhead information will
- X * go in the first int of the block, and the returned pointer will point
- X * to the second.
- X *
- #ifdef MSTATS
- X * nmalloc[i] is the difference between the number of mallocs and frees
- X * for a given block size.
- #endif MSTATS
- X */
- X
- #ifdef emacs
- /* config.h specifies which kind of system this is. */
- #include "config.h"
- #else
- X
- /* Determine which kind of system this is. */
- #ifndef USG
- #include <signal.h>
- #ifndef SIGTSTP
- #ifndef VMS
- #ifndef USG
- #define USG
- #endif
- #endif /* not VMS */
- #else /* SIGTSTP */
- #ifdef SIGIO
- #define BSD4_2
- #endif /* SIGIO */
- #endif /* SIGTSTP */
- #endif
- X
- #endif /* not emacs */
- X
- /* Define getpagesize () if the system does not. */
- #include "getpagesize.h"
- X
- #ifndef BSD4_2
- #ifndef USG
- #include <sys/vlimit.h> /* warn the user when near the end */
- #endif /* not USG */
- #else /* if BSD4_2 */
- #include <sys/time.h>
- #include <sys/resource.h>
- #endif /* BSD4_2 */
- X
- extern char *start_of_data ();
- X
- #ifdef BSD
- #ifndef DATA_SEG_BITS
- #define start_of_data() &etext
- #endif
- #endif
- X
- #ifndef emacs
- #define start_of_data() &etext
- #endif
- X
- #define ISALLOC ((char) 0xf7) /* magic byte that implies allocation */
- #define ISFREE ((char) 0x54) /* magic byte that implies free block */
- X /* this is for error checking only */
- #define ISMEMALIGN ((char) 0xd6) /* Stored before the value returned by
- X memalign, with the rest of the word
- X being the distance to the true
- X beginning of the block. */
- X
- extern char etext;
- X
- /* These two are for user programs to look at, when they are interested. */
- X
- unsigned int malloc_sbrk_used; /* amount of data space used now */
- unsigned int malloc_sbrk_unused; /* amount more we can have */
- X
- /* start of data space; can be changed by calling init_malloc */
- static char *data_space_start;
- X
- #ifdef MSTATS
- static int nmalloc[30];
- static int nmal, nfre;
- #endif /* MSTATS */
- X
- /* If range checking is not turned on, all we have is a flag indicating
- X whether memory is allocated, an index in nextf[], and a size field; to
- X realloc() memory we copy either size bytes or 1<<(index+3) bytes depending
- X on whether the former can hold the exact size (given the value of
- X 'index'). If range checking is on, we always need to know how much space
- X is allocated, so the 'size' field is never used. */
- X
- struct mhead {
- X char mh_alloc; /* ISALLOC or ISFREE */
- X char mh_index; /* index in nextf[] */
- /* Remainder are valid only when block is allocated */
- X unsigned short mh_size; /* size, if < 0x10000 */
- #ifdef rcheck
- X unsigned mh_nbytes; /* number of bytes allocated */
- X int mh_magic4; /* should be == MAGIC4 */
- #endif /* rcheck */
- };
- X
- /* Access free-list pointer of a block.
- X It is stored at block + 4.
- X This is not a field in the mhead structure
- X because we want sizeof (struct mhead)
- X to describe the overhead for when the block is in use,
- X and we do not want the free-list pointer to count in that. */
- X
- #define CHAIN(a) \
- X (*(struct mhead **) (sizeof (char *) + (char *) (a)))
- X
- #ifdef rcheck
- X
- /* To implement range checking, we write magic values in at the beginning and
- X end of each allocated block, and make sure they are undisturbed whenever a
- X free or a realloc occurs. */
- /* Written in each of the 4 bytes following the block's real space */
- #define MAGIC1 0x55
- /* Written in the 4 bytes before the block's real space */
- #define MAGIC4 0x55555555
- #define ASSERT(p) if (!(p)) botch("p"); else
- #define EXTRA 4 /* 4 bytes extra for MAGIC1s */
- #else
- #define ASSERT(p)
- #define EXTRA 0
- #endif /* rcheck */
- X
- X
- /* nextf[i] is free list of blocks of size 2**(i + 3) */
- X
- static struct mhead *nextf[30];
- X
- /* busy[i] is nonzero while allocation of block size i is in progress. */
- X
- static char busy[30];
- X
- /* Number of bytes of writable memory we can expect to be able to get */
- static unsigned int lim_data;
- X
- /* Level number of warnings already issued.
- X 0 -- no warnings issued.
- X 1 -- 75% warning already issued.
- X 2 -- 85% warning already issued.
- */
- static int warnlevel;
- X
- /* Function to call to issue a warning;
- X 0 means don't issue them. */
- static void (*warnfunction) ();
- X
- /* nonzero once initial bunch of free blocks made */
- static int gotpool;
- X
- char *_malloc_base;
- X
- static void getpool ();
- X
- /* Cause reinitialization based on job parameters;
- X also declare where the end of pure storage is. */
- void
- malloc_init (start, warnfun)
- X char *start;
- X void (*warnfun) ();
- {
- X if (start)
- X data_space_start = start;
- X lim_data = 0;
- X warnlevel = 0;
- X warnfunction = warnfun;
- }
- X
- /* Return the maximum size to which MEM can be realloc'd
- X without actually requiring copying. */
- X
- int
- malloc_usable_size (mem)
- X char *mem;
- {
- X int blocksize = 8 << (((struct mhead *) mem) - 1) -> mh_index;
- X
- X return blocksize - sizeof (struct mhead) - EXTRA;
- }
- X
- static void
- morecore (nu) /* ask system for more memory */
- X register int nu; /* size index to get more of */
- {
- X char *sbrk ();
- X register char *cp;
- X register int nblks;
- X register unsigned int siz;
- X int oldmask;
- X
- #ifdef BSD
- #ifndef BSD4_1
- X /* ?? There was a suggestion not to block SIGILL, somehow for GDB's sake. */
- X oldmask = sigsetmask (-1);
- #endif
- #endif
- X
- X if (!data_space_start)
- X {
- X data_space_start = start_of_data ();
- X }
- X
- X if (lim_data == 0)
- X get_lim_data ();
- X
- X /* On initial startup, get two blocks of each size up to 1k bytes */
- X if (!gotpool)
- X { getpool (); getpool (); gotpool = 1; }
- X
- X /* Find current end of memory and issue warning if getting near max */
- X
- #ifndef VMS
- X /* Maximum virtual memory on VMS is difficult to calculate since it
- X * depends on several dynmacially changing things. Also, alignment
- X * isn't that important. That is why much of the code here is ifdef'ed
- X * out for VMS systems.
- X */
- X cp = sbrk (0);
- X siz = cp - data_space_start;
- X
- X if (warnfunction)
- X switch (warnlevel)
- X {
- X case 0:
- X if (siz > (lim_data / 4) * 3)
- X {
- X warnlevel++;
- X (*warnfunction) ("Warning: past 75% of memory limit");
- X }
- X break;
- X case 1:
- X if (siz > (lim_data / 20) * 17)
- X {
- X warnlevel++;
- X (*warnfunction) ("Warning: past 85% of memory limit");
- X }
- X break;
- X case 2:
- X if (siz > (lim_data / 20) * 19)
- X {
- X warnlevel++;
- X (*warnfunction) ("Warning: past 95% of memory limit");
- X }
- X break;
- X }
- X
- X if ((int) cp & 0x3ff) /* land on 1K boundaries */
- X sbrk (1024 - ((int) cp & 0x3ff));
- #endif /* not VMS */
- X
- X /* Take at least 2k, and figure out how many blocks of the desired size
- X we're about to get */
- X nblks = 1;
- X if ((siz = nu) < 8)
- X nblks = 1 << ((siz = 8) - nu);
- X
- X if ((cp = sbrk (1 << (siz + 3))) == (char *) -1)
- X {
- #ifdef BSD
- #ifndef BSD4_1
- X sigsetmask (oldmask);
- #endif
- #endif
- X return; /* no more room! */
- X }
- X malloc_sbrk_used = siz;
- X malloc_sbrk_unused = lim_data - siz;
- X
- #ifndef VMS
- X if ((int) cp & 7)
- X { /* shouldn't happen, but just in case */
- X cp = (char *) (((int) cp + 8) & ~7);
- X nblks--;
- X }
- #endif /* not VMS */
- X
- X /* save new header and link the nblks blocks together */
- X nextf[nu] = (struct mhead *) cp;
- X siz = 1 << (nu + 3);
- X while (1)
- X {
- X ((struct mhead *) cp) -> mh_alloc = ISFREE;
- X ((struct mhead *) cp) -> mh_index = nu;
- X if (--nblks <= 0) break;
- X CHAIN ((struct mhead *) cp) = (struct mhead *) (cp + siz);
- X cp += siz;
- X }
- X CHAIN ((struct mhead *) cp) = 0;
- X
- #ifdef BSD
- #ifndef BSD4_1
- X sigsetmask (oldmask);
- #endif
- #endif
- }
- X
- static void
- getpool ()
- {
- X register int nu;
- X char * sbrk ();
- X register char *cp = sbrk (0);
- X
- X if ((int) cp & 0x3ff) /* land on 1K boundaries */
- X sbrk (1024 - ((int) cp & 0x3ff));
- X
- X /* Record address of start of space allocated by malloc. */
- X if (_malloc_base == 0)
- X _malloc_base = cp;
- X
- X /* Get 2k of storage */
- X
- X cp = sbrk (04000);
- X if (cp == (char *) -1)
- X return;
- X
- X /* Divide it into an initial 8-word block
- X plus one block of size 2**nu for nu = 3 ... 10. */
- X
- X CHAIN (cp) = nextf[0];
- X nextf[0] = (struct mhead *) cp;
- X ((struct mhead *) cp) -> mh_alloc = ISFREE;
- X ((struct mhead *) cp) -> mh_index = 0;
- X cp += 8;
- X
- X for (nu = 0; nu < 7; nu++)
- X {
- X CHAIN (cp) = nextf[nu];
- X nextf[nu] = (struct mhead *) cp;
- X ((struct mhead *) cp) -> mh_alloc = ISFREE;
- X ((struct mhead *) cp) -> mh_index = nu;
- X cp += 8 << nu;
- X }
- }
- X
- char *
- malloc (n) /* get a block */
- X unsigned n;
- {
- X register struct mhead *p;
- X register unsigned int nbytes;
- X register int nunits = 0;
- X
- X /* Figure out how many bytes are required, rounding up to the nearest
- X multiple of 8, then figure out which nestf[] area to use.
- X Both the beginning of the header and the beginning of the
- X block should be on an eight byte boundary. */
- X nbytes = (n + ((sizeof *p + 7) & ~7) + EXTRA + 7) & ~7;
- X {
- X register unsigned int shiftr = (nbytes - 1) >> 2;
- X
- X while (shiftr >>= 1)
- X nunits++;
- X }
- X
- X /* In case this is reentrant use of malloc from signal handler,
- X pick a block size that no other malloc level is currently
- X trying to allocate. That's the easiest harmless way not to
- X interfere with the other level of execution. */
- X while (busy[nunits]) nunits++;
- X busy[nunits] = 1;
- X
- X /* If there are no blocks of the appropriate size, go get some */
- X /* COULD SPLIT UP A LARGER BLOCK HERE ... ACT */
- X if (nextf[nunits] == 0)
- X morecore (nunits);
- X
- X /* Get one block off the list, and set the new list head */
- X if ((p = nextf[nunits]) == 0)
- X {
- X busy[nunits] = 0;
- X return 0;
- X }
- X nextf[nunits] = CHAIN (p);
- X busy[nunits] = 0;
- X
- X /* Check for free block clobbered */
- X /* If not for this check, we would gobble a clobbered free chain ptr */
- X /* and bomb out on the NEXT allocate of this size block */
- X if (p -> mh_alloc != ISFREE || p -> mh_index != nunits)
- #ifdef rcheck
- X botch ("block on free list clobbered");
- #else /* not rcheck */
- X abort ();
- #endif /* not rcheck */
- X
- X /* Fill in the info, and if range checking, set up the magic numbers */
- X p -> mh_alloc = ISALLOC;
- #ifdef rcheck
- X p -> mh_nbytes = n;
- X p -> mh_magic4 = MAGIC4;
- X {
- X /* Get the location n after the beginning of the user's space. */
- X register char *m = (char *) p + ((sizeof *p + 7) & ~7) + n;
- X
- X *m++ = MAGIC1, *m++ = MAGIC1, *m++ = MAGIC1, *m = MAGIC1;
- X }
- #else /* not rcheck */
- X p -> mh_size = n;
- #endif /* not rcheck */
- #ifdef MSTATS
- X nmalloc[nunits]++;
- X nmal++;
- #endif /* MSTATS */
- X return (char *) p + ((sizeof *p + 7) & ~7);
- }
- X
- free (mem)
- X char *mem;
- {
- X register struct mhead *p;
- X {
- X register char *ap = mem;
- X
- X if (ap == 0)
- X return;
- X
- X p = (struct mhead *) (ap - ((sizeof *p + 7) & ~7));
- X if (p -> mh_alloc == ISMEMALIGN)
- X {
- X ap -= p->mh_size;
- X p = (struct mhead *) (ap - ((sizeof *p + 7) & ~7));
- X }
- X
- #ifndef rcheck
- X if (p -> mh_alloc != ISALLOC)
- X abort ();
- X
- #else /* rcheck */
- X if (p -> mh_alloc != ISALLOC)
- X {
- X if (p -> mh_alloc == ISFREE)
- X botch ("free: Called with already freed block argument\n");
- X else
- X botch ("free: Called with bad argument\n");
- X }
- X
- X ASSERT (p -> mh_magic4 == MAGIC4);
- X ap += p -> mh_nbytes;
- X ASSERT (*ap++ == MAGIC1); ASSERT (*ap++ == MAGIC1);
- X ASSERT (*ap++ == MAGIC1); ASSERT (*ap == MAGIC1);
- #endif /* rcheck */
- X }
- X {
- X register int nunits = p -> mh_index;
- X
- X ASSERT (nunits <= 29);
- X p -> mh_alloc = ISFREE;
- X
- X /* Protect against signal handlers calling malloc. */
- X busy[nunits] = 1;
- X /* Put this block on the free list. */
- X CHAIN (p) = nextf[nunits];
- X nextf[nunits] = p;
- X busy[nunits] = 0;
- X
- #ifdef MSTATS
- X nmalloc[nunits]--;
- X nfre++;
- #endif /* MSTATS */
- X }
- }
- X
- char *
- realloc (mem, n)
- X char *mem;
- X register unsigned n;
- {
- X register struct mhead *p;
- X register unsigned int tocopy;
- X register unsigned int nbytes;
- X register int nunits;
- X
- X if (mem == 0)
- X return malloc (n);
- X p = (struct mhead *) (mem - ((sizeof *p + 7) & ~7));
- X nunits = p -> mh_index;
- X ASSERT (p -> mh_alloc == ISALLOC);
- #ifdef rcheck
- X ASSERT (p -> mh_magic4 == MAGIC4);
- X {
- X register char *m = mem + (tocopy = p -> mh_nbytes);
- X ASSERT (*m++ == MAGIC1); ASSERT (*m++ == MAGIC1);
- X ASSERT (*m++ == MAGIC1); ASSERT (*m == MAGIC1);
- X }
- #else /* not rcheck */
- X if (p -> mh_index >= 13)
- X tocopy = (1 << (p -> mh_index + 3)) - ((sizeof *p + 7) & ~7);
- X else
- X tocopy = p -> mh_size;
- #endif /* not rcheck */
- X
- X /* See if desired size rounds to same power of 2 as actual size. */
- X nbytes = (n + ((sizeof *p + 7) & ~7) + EXTRA + 7) & ~7;
- X
- X /* If ok, use the same block, just marking its size as changed. */
- X if (nbytes > (4 << nunits) && nbytes <= (8 << nunits))
- X {
- #ifdef rcheck
- X register char *m = mem + tocopy;
- X *m++ = 0; *m++ = 0; *m++ = 0; *m++ = 0;
- X p-> mh_nbytes = n;
- X m = mem + n;
- X *m++ = MAGIC1; *m++ = MAGIC1; *m++ = MAGIC1; *m++ = MAGIC1;
- #else /* not rcheck */
- X p -> mh_size = n;
- #endif /* not rcheck */
- X return mem;
- X }
- X
- X if (n < tocopy)
- X tocopy = n;
- X {
- X register char *new;
- X
- X if ((new = malloc (n)) == 0)
- X return 0;
- X bcopy (mem, new, tocopy);
- X free (mem);
- X return new;
- X }
- }
- X
- #ifndef VMS
- X
- char *
- memalign (alignment, size)
- X unsigned alignment, size;
- {
- X register char *ptr = malloc (size + alignment);
- X register char *aligned;
- X register struct mhead *p;
- X
- X if (ptr == 0)
- X return 0;
- X /* If entire block has the desired alignment, just accept it. */
- X if (((int) ptr & (alignment - 1)) == 0)
- X return ptr;
- X /* Otherwise, get address of byte in the block that has that alignment. */
- X aligned = (char *) (((int) ptr + alignment - 1) & -alignment);
- X
- X /* Store a suitable indication of how to free the block,
- X so that free can find the true beginning of it. */
- X p = (struct mhead *) aligned - 1;
- X p -> mh_size = aligned - ptr;
- X p -> mh_alloc = ISMEMALIGN;
- X return aligned;
- }
- X
- #ifndef HPUX
- /* This runs into trouble with getpagesize on HPUX.
- X Patching out seems cleaner than the ugly fix needed. */
- char *
- valloc (size)
- {
- X return memalign (getpagesize (), size);
- }
- #endif /* not HPUX */
- #endif /* not VMS */
- X
- #ifdef MSTATS
- /* Return statistics describing allocation of blocks of size 2**n. */
- X
- struct mstats_value
- X {
- X int blocksize;
- X int nfree;
- X int nused;
- X };
- X
- struct mstats_value
- malloc_stats (size)
- X int size;
- {
- X struct mstats_value v;
- X register int i;
- X register struct mhead *p;
- X
- X v.nfree = 0;
- X
- X if (size < 0 || size >= 30)
- X {
- X v.blocksize = 0;
- X v.nused = 0;
- X return v;
- X }
- X
- X v.blocksize = 1 << (size + 3);
- X v.nused = nmalloc[size];
- X
- X for (p = nextf[size]; p; p = CHAIN (p))
- X v.nfree++;
- X
- X return v;
- }
- int
- malloc_mem_used ()
- {
- X int i;
- X int size_used;
- X
- X size_used = 0;
- X
- X for (i = 0; i < 30; i++)
- X {
- X int allocation_size = 1 << (i + 3);
- X struct mhead *p;
- X
- X size_used += nmalloc[i] * allocation_size;
- X }
- X
- X return size_used;
- }
- X
- int
- malloc_mem_free ()
- {
- X int i;
- X int size_unused;
- X
- X size_unused = 0;
- X
- X for (i = 0; i < 30; i++)
- X {
- X int allocation_size = 1 << (i + 3);
- X struct mhead *p;
- X
- X for (p = nextf[i]; p ; p = CHAIN (p))
- X size_unused += allocation_size;
- X }
- X
- X return size_unused;
- }
- #endif /* MSTATS */
- X
- /*
- X * This function returns the total number of bytes that the process
- X * will be allowed to allocate via the sbrk(2) system call. On
- X * BSD systems this is the total space allocatable to stack and
- X * data. On USG systems this is the data space only.
- X */
- X
- #ifdef USG
- X
- get_lim_data ()
- {
- X extern long ulimit ();
- X
- #ifdef ULIMIT_BREAK_VALUE
- X lim_data = ULIMIT_BREAK_VALUE;
- #else
- X lim_data = ulimit (3, 0);
- #endif
- X
- X lim_data -= (long) data_space_start;
- }
- X
- #else /* not USG */
- #ifndef BSD4_2
- X
- get_lim_data ()
- {
- X lim_data = vlimit (LIM_DATA, -1);
- }
- X
- #else /* BSD4_2 */
- X
- get_lim_data ()
- {
- X struct rlimit XXrlimit;
- X
- X getrlimit (RLIMIT_DATA, &XXrlimit);
- #ifdef RLIM_INFINITY
- X lim_data = XXrlimit.rlim_cur & RLIM_INFINITY; /* soft limit */
- #else
- X lim_data = XXrlimit.rlim_cur; /* soft limit */
- #endif
- }
- X
- #endif /* BSD4_2 */
- #endif /* not USG */
- X
- #ifdef VMS
- /* There is a problem when dumping and restoring things on VMS. Calls
- X * to SBRK don't necessarily result in contiguous allocation. Dumping
- X * doesn't work when it isn't. Therefore, we make the initial
- X * allocation contiguous by allocating a big chunk, and do SBRKs from
- X * there. Once Emacs has dumped there is no reason to continue
- X * contiguous allocation, malloc doesn't depend on it.
- X *
- X * There is a further problem of using brk and sbrk while using VMS C
- X * run time library routines malloc, calloc, etc. The documentation
- X * says that this is a no-no, although I'm not sure why this would be
- X * a problem. In any case, we remove the necessity to call brk and
- X * sbrk, by calling calloc (to assure zero filled data) rather than
- X * sbrk.
- X *
- X * VMS_ALLOCATION_SIZE is the size of the allocation array. This
- X * should be larger than the malloc size before dumping. Making this
- X * too large will result in the startup procedure slowing down since
- X * it will require more space and time to map it in.
- X *
- X * The value for VMS_ALLOCATION_SIZE in the following define was determined
- X * by running emacs linked (and a large allocation) with the debugger and
- X * looking to see how much storage was used. The allocation was 201 pages,
- X * so I rounded it up to a power of two.
- X */
- #ifndef VMS_ALLOCATION_SIZE
- #define VMS_ALLOCATION_SIZE (512*256)
- #endif
- X
- /* Use VMS RTL definitions */
- #undef sbrk
- #undef brk
- #undef malloc
- int vms_out_initial = 0;
- char vms_initial_buffer[VMS_ALLOCATION_SIZE];
- static char *vms_current_brk = &vms_initial_buffer;
- static char *vms_end_brk = &vms_initial_buffer[VMS_ALLOCATION_SIZE-1];
- X
- #include <stdio.h>
- X
- char *
- sys_sbrk (incr)
- X int incr;
- {
- X char *sbrk(), *temp, *ptr;
- X
- X if (vms_out_initial)
- X {
- X /* out of initial allocation... */
- X if (!(temp = malloc (incr)))
- X temp = (char *) -1;
- X }
- X else
- X {
- X /* otherwise, go out of our area */
- X ptr = vms_current_brk + incr; /* new current_brk */
- X if (ptr <= vms_end_brk)
- X {
- X temp = vms_current_brk;
- X vms_current_brk = ptr;
- X }
- X else
- X {
- X vms_out_initial = 1; /* mark as out of initial allocation */
- X if (!(temp = malloc (incr)))
- X temp = (char *) -1;
- X }
- X }
- X return temp;
- }
- #endif /* VMS */
- SHAR_EOF
- chmod 0664 mxgdb/malloc.c ||
- echo 'restore of mxgdb/malloc.c failed'
- Wc_c="`wc -c < 'mxgdb/malloc.c'`"
- test 25023 -eq "$Wc_c" ||
- echo 'mxgdb/malloc.c: original size 25023, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= mxgdb/parser.c ==============
- if test -f 'mxgdb/parser.c' -a X"$1" != X"-c"; then
- echo 'x - skipping mxgdb/parser.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting mxgdb/parser.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'mxgdb/parser.c' &&
- static char rcsid[] = "$Id: parser.c,v 1.1.1.1 1991/05/16 21:42:31 jtsillas Exp $";
- X
- /*****************************************************************************
- X *
- X * xdbx - X Window System interface to the dbx debugger
- X *
- X * Copyright 1989 The University of Texas at Austin
- X * Copyright 1990 Microelectronics and Computer Technology Corporation
- X *
- X * Permission to use, copy, modify, and distribute this software and its
- X * documentation for any purpose and without fee is hereby granted,
- X * provided that the above copyright notice appear in all copies and that
- X * both that copyright notice and this permission notice appear in
- X * supporting documentation, and that the name of The University of Texas
- X * and Microelectronics and Computer Technology Corporation (MCC) not be
- X * used in advertising or publicity pertaining to distribution of
- X * the software without specific, written prior permission. The
- X * University of Texas and MCC makes no representations about the
- X * suitability of this software for any purpose. It is provided "as is"
- X * without express or implied warranty.
- X *
- X * THE UNIVERSITY OF TEXAS AND MCC DISCLAIMS ALL WARRANTIES WITH REGARD TO
- X * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- X * FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF TEXAS OR MCC BE LIABLE FOR
- X * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
- X * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
- X * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- X * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- X *
- X * Author: Po Cheung
- X * Created: March 10, 1989
- X *
- X *****************************************************************************
- X *
- X * xxgdb - X Window System interface to the gdb debugger
- X *
- X * Copyright 1990 Thomson Consumer Electronics, Inc.
- X *
- X * Permission to use, copy, modify, and distribute this software and its
- X * documentation for any purpose and without fee is hereby granted,
- X * provided that the above copyright notice appear in all copies and that
- X * both that copyright notice and this permission notice appear in
- X * supporting documentation, and that the name of Thomson Consumer
- X * Electronics (TCE) not be used in advertising or publicity pertaining
- X * to distribution of the software without specific, written prior
- X * permission. TCE makes no representations about the suitability of
- X * this software for any purpose. It is provided "as is" without express
- X * or implied warranty.
- X *
- X * TCE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
- X * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
- X * SHALL TCE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
- X * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- X * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
- X * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- X * SOFTWARE.
- X *
- X * Adaptation to GDB: Pierre Willard
- X * XXGDB Created: December, 1990
- X *
- X *****************************************************************************/
- X
- /* parser.c:
- X *
- X * Parse output messages from dbx using regular expression pattern matching,
- X * and take appropriate action.
- X *
- X * compile(): Compile the regular expressions in a table.
- X * match(): Try to best match a given string with the regular
- X * expressions found in the table and return an index.
- X * parser_init(): Initialization.
- X * parse(): Parse the dbx output and invoke the appropriate action
- X * handler.
- X * filter(): Modify the dbx output before it gets displayed on the
- X * dialog window.
- X * query_dbx(): Send a query command to dbx and process it.
- X */
- X
- #include "global.h"
- #include "regex.h"
- #include "gdb_regex.h"
- #include "datadpy.h"
- X
- #define BYTEWIDTH 8
- #define RE_BUFFER 100
- X
- Tokens Token; /* gloabl token structure */
- Boolean Parse = True; /* Parse flag for parse routine */
- X
- /*
- X * Compile all the regular expression patterns in a pattern table.
- X * A pattern table is an array of pattern records.
- X * Each pattern record consists of a regular
- X * expression, a buffer for the to-be-compiled regular expression,
- X * and an array to associate a given token with a matched register number.
- X */
- static void compile(patternTable)
- PatternRec *patternTable;
- {
- X PatternRec *p;
- X char fastmap[(1 << BYTEWIDTH)];
- X int i;
- X
- X for (i=0; patternTable[i].pat; i++) {
- X p = &patternTable[i];
- X p->buf = (struct re_pattern_buffer *)
- X XtMalloc (sizeof (struct re_pattern_buffer));
- X p->buf->allocated = RE_BUFFER;
- X p->buf->buffer = (char *) XtMalloc (p->buf->allocated);
- X p->buf->fastmap = fastmap;
- X p->buf->translate = NULL;
- X re_compile_pattern(p->pat, strlen(p->pat), p->buf);
- X re_compile_fastmap(p->buf);
- X }
- }
- X
- /*
- X * This routine tries to match a given string with each regular
- X * expression in a given pattern table. The best match is found, and
- X * the function returns an index to the pattern table.
- X */
- int match(patternTable, string, type)
- X PatternRec *patternTable;
- X char *string;
- X int type;
- {
- X struct re_registers regs;
- X int m, bestmatch = -1, index = -1, i, j, r, start, n;
- X char *s;
- X
- X if (!strcmp(string, "")) return -1;
- X for (i=0; patternTable[i].pat; i++) {
- X if (type != C_ANY && type != i)
- X continue;
- X m = re_match(patternTable[i].buf, string, strlen(string), 0, ®s);
- X if (m == -2 ) { /* match error - failure stack overflow */
- X fprintf(stderr, "mxgdb error: regular expression matching failed \
- (failure stack overflow)\n");
- X return (-1);
- X }
- X if (m > bestmatch) {
- X bestmatch = m;
- X index = i;
- X /* for GDB, free memory (if not done earlier) */
- X XtFree(Token.mesg);
- X XtFree(Token.file);
- X XtFree(Token.func);
- X XtFree(Token.display);
- X Token.mesg = Token.file = Token.func = Token.display = NULL;
- X Token.line = Token.stop = 0;
- X for (j=0; j<NTOKENS; j++) {
- X if ((r = patternTable[i].reg_token[j]) >= 0) {
- X start = regs.start[r];
- X if ((n = regs.end[r] - start) > 0) {
- X /* The following error could happen if the pattern table is not correct,
- X better test it here.. */
- X
- X if ( n > strlen(string)) /* Something is wrong here ! */
- X {
- X fprintf(stderr,"Error match() : n = %d is too big\n",n);
- X n = 0;
- X }
- X s = (char *) XtMalloc ((n+1) * sizeof(char));
- X strncpy(s, string+start, n);
- X s[n] = '\0';
- X switch (j) {
- X case TK_MESG: Token.mesg = s; break;
- X case TK_STOP: Token.stop = atoi(s); XtFree(s); break;
- X case TK_FUNC: Token.func = s; break;
- X case TK_LINE: Token.line = atoi(s); XtFree(s); break;
- X case TK_FILE: Token.file = s; break;
- X case TK_DISP: Token.display = s; break;
- X }
- X }
- X }
- X }
- X }
- X }
- X return index;
- }
- X
- /* Compile the regular expressions in the output and command pattern tables. */
- X
- void parser_init()
- {
- X compile(output_pattern);
- X compile(command_pattern);
- X compile(dataPattern);
- }
- X
- #include "gdb_parser.c"
- X
- SHAR_EOF
- chmod 0664 mxgdb/parser.c ||
- echo 'restore of mxgdb/parser.c failed'
- Wc_c="`wc -c < 'mxgdb/parser.c'`"
- test 7042 -eq "$Wc_c" ||
- echo 'mxgdb/parser.c: original size 7042, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= mxgdb/patchlevel.h ==============
- if test -f 'mxgdb/patchlevel.h' -a X"$1" != X"-c"; then
- echo 'x - skipping mxgdb/patchlevel.h (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting mxgdb/patchlevel.h (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'mxgdb/patchlevel.h' &&
- /* $Id: patchlevel.h,v 1.1.1.1 1991/05/16 21:42:34 jtsillas Exp $ */
- SHAR_EOF
- true || echo 'restore of mxgdb/patchlevel.h failed'
- fi
- echo 'End of part 7'
- echo 'File mxgdb/patchlevel.h is continued in part 8'
- echo 8 > _shar_seq_.tmp
- exit 0
- --
- == James Tsillas Bull HN Information Systems Inc. ==
- == (508) 294-2937 300 Concord Road 826A ==
- == jtsillas@bubba.ma30.bull.com Billerica, MA 01821 ==
- == ==
- == The opinions expressed above are solely my own and do not reflect ==
- == those of my employer. ==
- -== no solicitations please ==-
-