From 9c773451f3353829c8225fad3d6834957f6050c0 Mon Sep 17 00:00:00 2001 From: Dave Beazley Date: Sat, 24 Feb 2001 00:08:23 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@1025 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Tools/WAD/Include/wad.h | 4 +- Tools/WAD/Wad/default.c | 13 ++++++- Tools/WAD/Wad/memory.c | 41 +++++---------------- Tools/WAD/Wad/object.c | 28 ++++++++++---- Tools/WAD/Wad/signal.c | 3 -- Tools/WAD/Wad/stab.c | 81 ++++++++++++++++++++++++++++++++++++++++- Tools/WAD/Wad/vars.c | 28 +++++++++++++- 7 files changed, 147 insertions(+), 51 deletions(-) diff --git a/Tools/WAD/Include/wad.h b/Tools/WAD/Include/wad.h index dfad57360..e1a16431c 100644 --- a/Tools/WAD/Include/wad.h +++ b/Tools/WAD/Include/wad.h @@ -39,10 +39,8 @@ extern "C" { extern int wad_memory_init(); extern void *wad_malloc(int nbytes); -extern void *wad_pmalloc(int nbytes); extern void wad_release_memory(); extern char *wad_strdup(const char *c); -extern char *wad_pstrdup(const char *c); /* --- I/O, Debugging --- */ @@ -90,7 +88,7 @@ extern void wad_set_return_func(void (*f)(void)); typedef struct WadLocal { char *name; /* Name of the local */ void *ptr; /* Pointer to the actual data (if known) */ - int size; /* Size of the data */ + int size; /* Size of the data (if known) */ int type; /* Data type */ /* Debugging information */ diff --git a/Tools/WAD/Wad/default.c b/Tools/WAD/Wad/default.c index 8d3a2622b..0f25c588a 100644 --- a/Tools/WAD/Wad/default.c +++ b/Tools/WAD/Wad/default.c @@ -24,25 +24,34 @@ char *wad_arg_string(WadFrame *frame) { WadLocal *wp; long *stack; long *nextstack; + long *prevstack; int i; WadFrame *nf; - + WadFrame *pf; + nf = frame->next; if (nf) nextstack = (long *) nf->stack; else nextstack = 0; + pf = frame->prev; + if (pf) + prevstack = (long *) pf->stack; + else + prevstack = 0; + str[0] = 0; stack = (long *) frame->stack; + #ifdef WAD_LINUX if (!nf) { return ""; } #endif - if (frame->debug_nargs < 0) { + if ((frame->debug_nargs < 0) || (0)){ /* No argument information is available. If we are on SPARC, we'll dump the %in registers since these usually hold input parameters. On Linux, we do nothing */ diff --git a/Tools/WAD/Wad/memory.c b/Tools/WAD/Wad/memory.c index f1e216b06..6b113caac 100644 --- a/Tools/WAD/Wad/memory.c +++ b/Tools/WAD/Wad/memory.c @@ -26,6 +26,7 @@ static WadMemory *current = 0; /* Current memory block */ static WadMemory *persistent = 0; /* Persistent memory data */ static int pagesize = 0; /* System page size */ static int devzero = 0; +static int npalloc = 8; /* Number of pages per alloc */ /* ----------------------------------------------------------------------------- * wad_memory_init() @@ -72,14 +73,14 @@ void *wad_malloc(int nbytes) { char *c; int npages; /* wad_printf("wad_malloc: %d\n", nbytes); */ - if (nbytes >= (pagesize >> 2)) { + if (nbytes >= ((npalloc*pagesize) >> 2)) { /* Large allocation. */ npages = ((nbytes + sizeof(WadMemory))/pagesize) + 1; ptr = wad_page_alloc(npages); if (!ptr) return 0; wm = (WadMemory *)ptr; wm->npages = npages; - wm->last = sizeof(WadMemory); + wm->last = sizeof(WadMemory) + 8; wm->next = current; current = wm; c = (char *) current + (current->last); @@ -97,9 +98,9 @@ void *wad_malloc(int nbytes) { } if (!wm) { /* wad_printf("wad_malloc: new page\n", nbytes);*/ - wm = (WadMemory *) wad_page_alloc(1); + wm = (WadMemory *) wad_page_alloc(npalloc); if (!wm) return 0; - wm->npages = 1; + wm->npages = npalloc; wm->last = sizeof(WadMemory); wm->next = current; current = wm; @@ -109,33 +110,17 @@ void *wad_malloc(int nbytes) { return c; } -/* ----------------------------------------------------------------------------- - * wad_pmalloc() - * - * Persistent memory allocation. Allocates memory that will never be reclaimed. - * This is only really used to store information pertaining to object files. - * ----------------------------------------------------------------------------- */ - -void *wad_pmalloc(int nbytes) { - void *ptr; - WadMemory *tmp; - tmp = current; - current = persistent; - ptr = wad_malloc(nbytes); - persistent = current; - current = tmp; - return ptr; -} - /* ----------------------------------------------------------------------------- * wad_release_memory() * - * Releases all memory previously allocated by wad_malloc() + * Releases all memory previously allocated by wad_malloc(). This is inherently + * dangerous. * ----------------------------------------------------------------------------- */ void wad_release_memory() { WadMemory *wm, *next; - + + return; wm = current; while (wm) { next = wm->next; @@ -159,11 +144,3 @@ char *wad_strdup(const char *c) { return t; } -char *wad_pstrdup(const char *c) { - char *t; - if (!c) c = ""; - t = (char *) wad_pmalloc(strlen(c)+1); - strcpy(t,c); - return t; -} - diff --git a/Tools/WAD/Wad/object.c b/Tools/WAD/Wad/object.c index 23dd5ab42..82797ffdd 100644 --- a/Tools/WAD/Wad/object.c +++ b/Tools/WAD/Wad/object.c @@ -54,8 +54,8 @@ load_file(const char *path) { return 0; /* Doesn't exist. Oh well */ } if (wad_debug_mode & DEBUG_FILE) wad_printf("loaded.\n"); - wf = (WadFile *) wad_pmalloc(sizeof(WadFile)); - wf->path = wad_pstrdup(path); + wf = (WadFile *) wad_malloc(sizeof(WadFile)); + wf->path = wad_strdup(path); /* Get file length */ wf->size = lseek(fd,0,SEEK_END); @@ -116,10 +116,18 @@ wad_object_load(const char *path) { WadObjectFile *wad_arobject_load(const char *path, const char *name); if (wad_debug_mode & DEBUG_OBJECT) { - wad_printf("wad: Loading object '%s'\n", path); + wad_printf("wad: Loading object '%s'", path); } for (wo = wad_objects; wo; wo=wo->next) { - if (strcmp(wo->path,path) == 0) return wo; + if (strcmp(wo->path,path) == 0) { + if (wad_debug_mode & DEBUG_OBJECT) { + wad_printf(" (cached)\n"); + } + return wo; + } + } + if (wad_debug_mode & DEBUG_OBJECT) { + wad_printf("\n"); } /* Didn't find it. Now we need to go load some files */ @@ -142,7 +150,9 @@ wad_object_load(const char *path) { wo = wad_arobject_load(realfile,objfile); if (wo) { /* Reset the path */ - wo->path = wad_pstrdup(path); + wo->path = wad_strdup(path); + wo->next = wad_objects; + wad_objects = wo; return wo; } } @@ -150,10 +160,12 @@ wad_object_load(const char *path) { wf = load_file(path); if (!wf) return 0; - wo = (WadObjectFile *) wad_pmalloc(sizeof(WadObjectFile)); - wo->path = wad_pstrdup(path); + wo = (WadObjectFile *) wad_malloc(sizeof(WadObjectFile)); + wo->path = wad_strdup(path); wo->ptr = wf->addr; wo->len = wf->size; + wo->next = wad_objects; + wad_objects = wo; return wo; } @@ -235,7 +247,7 @@ wad_arobject_load(const char *arpath, const char *robjname) { /* Compare the names */ if (strncmp(mname,objname,sobjname) == 0) { /* Found the archive */ - wo = (WadObjectFile *) wad_pmalloc(sizeof(WadObjectFile)); + wo = (WadObjectFile *) wad_malloc(sizeof(WadObjectFile)); wo->ptr = (void *) (arptr + offset); wo->len = msize; wo->path = 0; diff --git a/Tools/WAD/Wad/signal.c b/Tools/WAD/Wad/signal.c index 9583273d7..48c6e2d14 100644 --- a/Tools/WAD/Wad/signal.c +++ b/Tools/WAD/Wad/signal.c @@ -255,9 +255,6 @@ void wad_signalhandler(int sig, siginfo_t *si, void *vcontext) { char *retname = 0; unsigned long current_brk; - - wad_release_memory(); - wad_nlr_func = 0; context = (ucontext_t *) vcontext; diff --git a/Tools/WAD/Wad/stab.c b/Tools/WAD/Wad/stab.c index a16f8a7a6..edf5a3a1f 100644 --- a/Tools/WAD/Wad/stab.c +++ b/Tools/WAD/Wad/stab.c @@ -33,6 +33,75 @@ typedef struct Stab { #define N_PSYM 0xa0 /* Parameter */ #define N_LBRAC 0xc0 /* Left brace */ + +/* ----------------------------------------------------------------------------- + * stabs type handler + * + * Type names are defined as N_LSYM types. We need to keep a hash table of + * logical type names and stabs type names. + * + * We also need to keep a hash table of stabs types. + * ----------------------------------------------------------------------------- */ + +typedef struct stabtype { + char *name; + char *value; + struct stabtype *next; +} stabtype; + +#define HASH_SIZE 113 + +static int stab_type_init = 0; +static stabtype *lnames[HASH_SIZE]; /* Hash of local names */ + +/* Initialize the hash table */ + +static void init_hash() { + int i; + for (i = 0; i < HASH_SIZE; i++) { + lnames[i] = 0; + } +} + +static int thash(char *name) { + unsigned int h = 0; + int i; + for (i = 0; i < 8 && (*name); i++, name++) { + h = ((h << 7) + *name) % HASH_SIZE; + } + return h; +} + +/* Add a symbol to the hash */ + +static void type_add(char *name, char *value) { + int h; + stabtype *s; + if (!stab_type_init) { + init_hash(); + stab_type_init = 1; + } + h = thash(name); + s = lnames[h]; + while (s) { + if (strcmp(s->name,name) == 0) { + if (strcmp(s->value,value) == 0) { + return; + } + s->value = (char *) wad_strdup(value); + return; + } + s = s->next; + } + s = (stabtype *) wad_malloc(sizeof(stabtype)); + s->name = wad_strdup(name); + s->value = wad_strdup(value); + s->next = lnames[h]; + lnames[h] = s; +} + + + /* ----------------------------------------------------------------------------- * match_stab_symbol() * @@ -63,15 +132,23 @@ stab_string_parm(char *str) { static void stab_symbol(Stab *s, char *stabstr) { + char *str; char *pstr; + char name[1024]; int a; - pstr = stab_string_parm(stabstr+s->n_strx); + str = stabstr+s->n_strx; + pstr = stab_string_parm(str); if (!pstr) return; - + + strncpy(name,str, pstr-str); + name[(int)(pstr-str)] = 0; if (pstr[1] == 't') { + /* A stabs type definition */ /* wad_printf("stab lsym: other=%d, desc=%d, value=%d, str='%s'\n", s->n_other,s->n_desc,s->n_value, stabstr+s->n_strx); */ + /* wad_printf("name = '%s', pstr='%s'\n", name, pstr+2); */ + type_add(name,pstr+2); } } diff --git a/Tools/WAD/Wad/vars.c b/Tools/WAD/Wad/vars.c index 66a72b81a..11b455f13 100644 --- a/Tools/WAD/Wad/vars.c +++ b/Tools/WAD/Wad/vars.c @@ -47,20 +47,46 @@ void wad_build_vars(WadFrame *f) { } else if (loc->stack < 0) { loc->ptr = (void *) (stack + f->stack_size + loc->stack); } + loc->size = sizeof(long); } + if (loc->loc == PARM_REGISTER) { + /* Parameter is located in a register */ +#ifdef WAD_SOLARIS + if ((loc->reg >= 24) && (loc->reg < 32)) { + /* Value is located in the %in registers. */ + loc->ptr = (void *) (stack + (loc->reg - 16)*sizeof(int)); + loc->size = sizeof(int); + } else if ((loc->reg >= 8) && (loc->reg < 16)) { + + /* Value is located in the %on registers */ + if (nstack) { + loc->ptr = (void *) (stack + (loc->reg)*sizeof(int)); + loc->size = sizeof(int); + } + } else if ((loc->reg >= 16) && (loc->reg < 24)) { + /* Value has been placed in the %ln registers */ + loc->ptr = (void *) (stack + (loc->reg - 16)*sizeof(int)); + loc->size = sizeof(int); + } +#endif + } +#ifdef OLD if (lastloc) { /* Figure out the size */ if (!lastloc->size) lastloc->size = abs(loc->stack - lastloc->stack); } lastloc = loc; +#endif + loc = loc->next; } - +#ifdef OLD /* If last size is not set. Assume that it is a word */ if (lastloc && (!lastloc->size)) { lastloc->size = 4; } +#endif }