This should fix some, if not all, of the live range problems
[fw/sdcc] / debugger / mcs51 / symtab.c
index 3ea0e8fd18bc5137bdc37c94009c57817704bcbd..1305cc3ee8f610f8b2bbc8a5fdc982db4e98997d 100644 (file)
@@ -1,28 +1,29 @@
 /*-------------------------------------------------------------------------
   symtab.c - Header file for symbol table for sdcdb ( debugger )
 /*-------------------------------------------------------------------------
   symtab.c - Header file for symbol table for sdcdb ( debugger )
-             Written By -  Sandeep Dutta . sandeep.dutta@usa.net (1999)
+        Written By -  Sandeep Dutta . sandeep.dutta@usa.net (1999)
 
    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the
    Free Software Foundation; either version 2, or (at your option) any
    later version.
 
    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the
    Free Software Foundation; either version 2, or (at your option) any
    later version.
-   
+
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-   
+
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-   
+
    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
    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!  
+   what you give them.   Help stamp out software-hoarding!
 -------------------------------------------------------------------------*/
 
 #include "sdcdb.h"
 #include "symtab.h"
 -------------------------------------------------------------------------*/
 
 #include "sdcdb.h"
 #include "symtab.h"
+#include "newalloc.h"
 
 extern char *currModName ;
 structdef *structWithName (char *);
 
 extern char *currModName ;
 structdef *structWithName (char *);
@@ -34,50 +35,50 @@ unsigned int   getSize ( link *p )
 {
     /* if nothing return 0 */
     if ( ! p )
 {
     /* if nothing return 0 */
     if ( ! p )
-       return 0 ;
-    
+  return 0 ;
+
     if ( IS_SPEC(p) ) { /* if this is the specifier then */
     if ( IS_SPEC(p) ) { /* if this is the specifier then */
-       
-       switch (SPEC_NOUN(p)) { /* depending on the specifier type */
-       case V_INT:
-           return (IS_LONG(p) ? LONGSIZE : ( IS_SHORT(p) ? SHORTSIZE: INTSIZE)) ;
-       case V_FLOAT:
-           return FLOATSIZE ;
-       case V_CHAR:
-           return   CHARSIZE ;
-       case V_VOID:
-           return   0 ;
-       case V_STRUCT:
-           return   SPEC_STRUCT(p)->size ;
-       case V_LABEL:
-           return 0 ;
-       case V_SBIT:
-           return BITSIZE ;
-       case V_BIT:
-           return ((SPEC_BLEN(p) / 8) + (SPEC_BLEN(p) % 8 ? 1 : 0)) ;
-       default  :
-           return 0 ;
-       }
+
+  switch (SPEC_NOUN(p)) { /* depending on the specifier type */
+  case V_INT:
+      return (IS_LONG(p) ? LONGSIZE : ( IS_SHORT(p) ? SHORTSIZE: INTSIZE)) ;
+  case V_FLOAT:
+      return FLOATSIZE ;
+  case V_CHAR:
+      return   CHARSIZE ;
+  case V_VOID:
+      return   0 ;
+  case V_STRUCT:
+      return   SPEC_STRUCT(p)->size ;
+  case V_LABEL:
+      return 0 ;
+  case V_SBIT:
+      return BITSIZE ;
+  case V_BIT:
+      return ((SPEC_BLEN(p) / 8) + (SPEC_BLEN(p) % 8 ? 1 : 0)) ;
+  default  :
+      return 0 ;
+  }
     }
     }
-    
+
     /* this is a specifier  */
     switch (DCL_TYPE(p))  {
     case FUNCTION:
     /* this is a specifier  */
     switch (DCL_TYPE(p))  {
     case FUNCTION:
-       return 2;
+  return 2;
     case ARRAY:
     case ARRAY:
-       return DCL_ELEM(p) * getSize (p->next) ;
+  return DCL_ELEM(p) * getSize (p->next) ;
     case IPOINTER:
     case PPOINTER:
     case POINTER:
     case IPOINTER:
     case PPOINTER:
     case POINTER:
-       return ( PTRSIZE ) ;
+  return ( PTRSIZE ) ;
     case FPOINTER:
     case CPOINTER:
     case FPOINTER:
     case CPOINTER:
-       return ( FPTRSIZE );
+  return ( FPTRSIZE );
     case GPOINTER:
     case GPOINTER:
-       return ( GPTRSIZE );
-       
+  return ( GPTRSIZE );
+
     default     :
     default     :
-       return  0 ;
+  return  0 ;
     }
 }
 
     }
 }
 
@@ -90,15 +91,15 @@ void parseFunc (char *line)
     function *func ;
     char *rs;
     int i;
     function *func ;
     char *rs;
     int i;
-    ALLOC(func,sizeof(function));
+    func = Safe_calloc(1,sizeof(function));
     func->sym = parseSymbol(line,&rs);
     func->sym->isfunc = 1;
     func->sym = parseSymbol(line,&rs);
     func->sym->isfunc = 1;
-    func->modName = currModName ;   
+    func->modName = currModName ;
     while(*rs != ',') rs++;
     rs++;
     sscanf(rs,"%d,%d,%d",&i,
     while(*rs != ',') rs++;
     rs++;
     sscanf(rs,"%d,%d,%d",&i,
-          &(SPEC_INTN(func->sym->etype)),
-          &(SPEC_BANK(func->sym->etype)));
+     &(SPEC_INTN(func->sym->etype)),
+     &(SPEC_BANK(func->sym->etype)));
     SPEC_INTRTN(func->sym->etype) = i;
     addSet(&functions,func);
 }
     SPEC_INTRTN(func->sym->etype) = i;
     addSet(&functions,func);
 }
@@ -106,7 +107,7 @@ void parseFunc (char *line)
 /*-----------------------------------------------------------------*/
 /* parseTypeInfo - parse the type info of a symbol expects the type*/
 /*                 info to be of the form                          */
 /*-----------------------------------------------------------------*/
 /* parseTypeInfo - parse the type info of a symbol expects the type*/
 /*                 info to be of the form                          */
-/*                 ({<size>}<type info chain)                      */  
+/*                 ({<size>}<type info chain)                      */
 /*-----------------------------------------------------------------*/
 static char  *parseTypeInfo (symbol *sym, char *s)
 {
 /*-----------------------------------------------------------------*/
 static char  *parseTypeInfo (symbol *sym, char *s)
 {
@@ -116,115 +117,115 @@ static char  *parseTypeInfo (symbol *sym, char *s)
     /* get the size */
     sym->size = strtol (s,&bp,10);
     /* bp now points to '}' ... go past it */
     /* get the size */
     sym->size = strtol (s,&bp,10);
     /* bp now points to '}' ... go past it */
-    s = ++bp;    
+    s = ++bp;
     while (*s != ')') { /* till we reach the end */
     while (*s != ')') { /* till we reach the end */
-       link *type;
-       ALLOC(type,sizeof(link));
-       if (*s == ',') s++;
-
-       /* is a declarator */
-       if (*s == 'D') {
-           s++;
-           switch (*s) {
-           case 'F':           
-               DCL_TYPE(type) = FUNCTION;
-               s++;
-               break;
-           case 'G':           
-               DCL_TYPE(type) = GPOINTER;
-               s++;
-               break;
-           case 'C':
-               DCL_TYPE(type) = CPOINTER;
-               s++;
-               break;
-           case 'X':
-               DCL_TYPE(type) = FPOINTER;
-               s++;
-               break;
-           case 'D':
-               DCL_TYPE(type) = POINTER;
-               s++;
-               break;
-           case 'I':
-               DCL_TYPE(type) = IPOINTER;
-               s++;
-               break;
-           case 'P':
-               DCL_TYPE(type) = PPOINTER;
-               s++;
-               break;
-           case 'A':
-               s++;
-               DCL_TYPE(type) = ARRAY ;
-               DCL_ELEM(type) = strtol(s,&s,10);
-               break;
-           }
-       } else {            
-           /* is a specifier */
-           type->class = SPECIFIER ;
-           s++;
-           switch (*s) {
-           case 'L':
-               SPEC_NOUN(type) = V_INT;
-               SPEC_LONG(type) = 1;
-               s++;
-               break;
-           case 'I':
-               SPEC_NOUN(type) = V_INT;
-               s++;
-               break;
-           case 'S':
-           case 'C':
-               SPEC_NOUN(type) = V_CHAR ;
-               s++;
-               break;
-           case 'V':
-               SPEC_NOUN(type) = V_VOID;
-               s++;
-               break;
-           case 'F':
-               SPEC_NOUN(type) = V_FLOAT;
-               s++;
-               break;
-           case 'T':
-               s++;
-               SPEC_NOUN(type) = V_STRUCT;
-               { 
-                   char *ss = strtok(strdup(s),",):");
-                   
-                   SPEC_STRUCT(type) = structWithName(ss);
-                   free(ss);
-               }
-               break;
-           case 'X':
-               s++;
-               SPEC_NOUN(type) = V_SBIT;
-               break;
-           case 'B':
-               SPEC_NOUN(type) = V_BIT;
-               s++;
-               SPEC_BSTR(type) = strtol(s,&s,10);
-               s++;
-               SPEC_BLEN(type) = strtol(s,&s,10);
-               break;
-           }
-           while (*s != ':') s++;
-           s++;
-           if (*s++ == 'S')
-               SPEC_USIGN(type) = 0;
-           else
-               SPEC_USIGN(type) = 1;
-
-       }
-
-       /* add the type to the symbol's type chain */
-       if (sym->type) 
-           sym->etype = sym->etype->next = type;
-       else
-           sym->type = sym->etype = type;
+  link *type;
+  type = Safe_calloc(1,sizeof(link));
+  if (*s == ',') s++;
+
+  /* is a declarator */
+  if (*s == 'D') {
+      s++;
+      switch (*s) {
+      case 'F':
+    DCL_TYPE(type) = FUNCTION;
+    s++;
+    break;
+      case 'G':
+    DCL_TYPE(type) = GPOINTER;
+    s++;
+    break;
+      case 'C':
+    DCL_TYPE(type) = CPOINTER;
+    s++;
+    break;
+      case 'X':
+    DCL_TYPE(type) = FPOINTER;
+    s++;
+    break;
+      case 'D':
+    DCL_TYPE(type) = POINTER;
+    s++;
+    break;
+      case 'I':
+    DCL_TYPE(type) = IPOINTER;
+    s++;
+    break;
+      case 'P':
+    DCL_TYPE(type) = PPOINTER;
+    s++;
+    break;
+      case 'A':
+    s++;
+    DCL_TYPE(type) = ARRAY ;
+    DCL_ELEM(type) = strtol(s,&s,10);
+    break;
+      }
+  } else {
+      /* is a specifier */
+      type->class = SPECIFIER ;
+      s++;
+      switch (*s) {
+      case 'L':
+    SPEC_NOUN(type) = V_INT;
+    SPEC_LONG(type) = 1;
+    s++;
+    break;
+      case 'I':
+    SPEC_NOUN(type) = V_INT;
+    s++;
+    break;
+      case 'S':
+      case 'C':
+    SPEC_NOUN(type) = V_CHAR ;
+    s++;
+    break;
+      case 'V':
+    SPEC_NOUN(type) = V_VOID;
+    s++;
+    break;
+      case 'F':
+    SPEC_NOUN(type) = V_FLOAT;
+    s++;
+    break;
+      case 'T':
+    s++;
+    SPEC_NOUN(type) = V_STRUCT;
+    {
+        char *ss = strtok(strdup(s),",):");
+
+        SPEC_STRUCT(type) = structWithName(ss);
+        free(ss);
     }
     }
-    
+    break;
+      case 'X':
+    s++;
+    SPEC_NOUN(type) = V_SBIT;
+    break;
+      case 'B':
+    SPEC_NOUN(type) = V_BIT;
+    s++;
+    SPEC_BSTR(type) = strtol(s,&s,10);
+    s++;
+    SPEC_BLEN(type) = strtol(s,&s,10);
+    break;
+      }
+      while (*s != ':') s++;
+      s++;
+      if (*s++ == 'S')
+    SPEC_USIGN(type) = 0;
+      else
+    SPEC_USIGN(type) = 1;
+
+  }
+
+  /* add the type to the symbol's type chain */
+  if (sym->type)
+      sym->etype = sym->etype->next = type;
+  else
+      sym->type = sym->etype = type;
+    }
+
     return ++s;
 
 }
     return ++s;
 
 }
@@ -240,10 +241,10 @@ symbol *parseSymbol (char *s, char **rs)
     symbol *nsym ;
     char *bp = s;
 
     symbol *nsym ;
     char *bp = s;
 
-    ALLOC(nsym,sizeof(symbol));
+    nsym = Safe_calloc(1,sizeof(symbol));
 
     /* copy over the mangled name */
 
     /* copy over the mangled name */
-    while (*bp != '(') bp++;   
+    while (*bp != '(') bp++;
      bp -= 1;
     nsym->rname = alloccpy(s,bp - s);
 
      bp -= 1;
     nsym->rname = alloccpy(s,bp - s);
 
@@ -251,39 +252,39 @@ symbol *parseSymbol (char *s, char **rs)
     nsym->scopetype = *s;
     s++ ;
     if (nsym->scopetype != 'G') {
     nsym->scopetype = *s;
     s++ ;
     if (nsym->scopetype != 'G') {
-       /* get the function name it is local to */
-       bp = s;
-       while (*s != '$') s++;
-       nsym->sname = alloccpy(bp,s - bp);
+  /* get the function name it is local to */
+  bp = s;
+  while (*s != '$') s++;
+  nsym->sname = alloccpy(bp,s - bp);
     }
 
     }
 
-    /* next get the name */    
+    /* next get the name */
     bp = ++s;
     while ( *s != '$' ) s++;
     nsym->name = alloccpy(bp,s - bp);
     bp = ++s;
     while ( *s != '$' ) s++;
     nsym->name = alloccpy(bp,s - bp);
-    
+
     s++;
     /* get the level number */
     nsym->level = strtol (s,&bp,10);
     s = ++bp;
     /* skip the '$' & get the block number */
     nsym->block = strtol (s,&bp,10);
     s++;
     /* get the level number */
     nsym->level = strtol (s,&bp,10);
     s = ++bp;
     /* skip the '$' & get the block number */
     nsym->block = strtol (s,&bp,10);
-    
-    s = parseTypeInfo(nsym,bp);        
+
+    s = parseTypeInfo(nsym,bp);
 
     /* get the address space after going past the comma */
     s++;
     nsym->addrspace =*s;
 
 
     /* get the address space after going past the comma */
     s++;
     nsym->addrspace =*s;
 
-    s+= 2;    
+    s+= 2;
     nsym->isonstack = strtol(s,&s,10);
     /* get the stack offset */
     s++;
     nsym->offset = strtol(s,&s,10);
     *rs = s;
     nsym->isonstack = strtol(s,&s,10);
     /* get the stack offset */
     s++;
     nsym->offset = strtol(s,&s,10);
     *rs = s;
-   
+
     addSet(&symbols,nsym);
     addSet(&symbols,nsym);
-    
+
     return nsym;
 }
 
     return nsym;
 }
 
@@ -297,10 +298,10 @@ structdef *parseStruct (char *s)
     structdef *nsdef ;
     char *bp;
     char *name;
     structdef *nsdef ;
     char *bp;
     char *name;
-    symbol *fields = NULL;    
-    
+    symbol *fields = NULL;
+
     while (*s != '$') s++;
     while (*s != '$') s++;
-   
+
     bp =++s;
     while (*s != '[') s++ ;
     name = alloccpy(bp,s - bp);
     bp =++s;
     while (*s != '[') s++ ;
     name = alloccpy(bp,s - bp);
@@ -308,22 +309,22 @@ structdef *parseStruct (char *s)
     nsdef->fields = NULL;
     s++;
     while (*s && *s != ']') {
     nsdef->fields = NULL;
     s++;
     while (*s && *s != ']') {
-       int offset ;
-       symbol *sym ;
-       while (!isdigit(*s)) s++;
-       offset = strtol(s,&s,10);
-       while (*s != ':') s++;
-       s++;
-       sym = parseSymbol(s,&s);
-       sym->offset = offset ;
-       s += 3;
-       if (!fields) 
-           fields = nsdef->fields = sym;
-       else
-           fields = fields->next = sym;
-       
+  int offset ;
+  symbol *sym ;
+  while (!isdigit(*s)) s++;
+  offset = strtol(s,&s,10);
+  while (*s != ':') s++;
+  s++;
+  sym = parseSymbol(s,&s);
+  sym->offset = offset ;
+  s += 3;
+  if (!fields)
+      fields = nsdef->fields = sym;
+  else
+      fields = fields->next = sym;
+
     }
     }
-    
+
     return nsdef;
 }
 
     return nsdef;
 }
 
@@ -335,25 +336,25 @@ module *parseModule (char *s, bool createName )
     module *nmod ;
     char buffer[512];
 
     module *nmod ;
     char buffer[512];
 
-    ALLOC(nmod,sizeof(module));    
-    
+    nmod = Safe_calloc(1,sizeof(module));
+
     addSet (&modules,nmod);
     addSet (&modules,nmod);
-    
-           
+
+
     /* create copy file name */
     nmod->name = s;
     /* create copy file name */
     nmod->name = s;
-    
+
     if (createName) {
     if (createName) {
-       sprintf(buffer,"%s.c",s);
-       
-       ALLOC(nmod->c_name,strlen(buffer)+1);
-       strcpy(nmod->c_name,buffer);       
-       
-       sprintf(buffer,"%s.asm",s);
-       ALLOC(nmod->asm_name,strlen(buffer)+1);
-       strcpy(nmod->asm_name,buffer);              
+  sprintf(buffer,"%s.c",s);
+
+  nmod->c_name = Safe_malloc(strlen(buffer)+1);
+  strcpy(nmod->c_name,buffer);
+
+  sprintf(buffer,"%s.asm",s);
+  nmod->asm_name = Safe_malloc(strlen(buffer)+1);
+  strcpy(nmod->asm_name,buffer);
     }
     }
-    
+
     return nmod;
 }
 
     return nmod;
 }
 
@@ -365,15 +366,15 @@ DEFSETFUNC(moduleWithName)
     module *mod = item;
     V_ARG(char *,s);
     V_ARG(module **,rmod);
     module *mod = item;
     V_ARG(char *,s);
     V_ARG(module **,rmod);
-    
+
     if (*rmod)
     if (*rmod)
-       return 0;
+  return 0;
 
     if (strcmp(mod->name,s) == 0) {
 
     if (strcmp(mod->name,s) == 0) {
-       *rmod = mod ;
-       return 1;
+  *rmod = mod ;
+  return 1;
     }
     }
-    
+
     return 0;
 }
 
     return 0;
 }
 
@@ -385,14 +386,14 @@ DEFSETFUNC(moduleWithCName)
     module *mod = item;
     V_ARG(char *,s);
     V_ARG(module **,rmod);
     module *mod = item;
     V_ARG(char *,s);
     V_ARG(module **,rmod);
-       
+
     if (*rmod)
     if (*rmod)
-       return 0;
+  return 0;
     if (strcmp(mod->c_name,s) == 0) {
     if (strcmp(mod->c_name,s) == 0) {
-       *rmod = mod;
-       return 1;
+  *rmod = mod;
+  return 1;
     }
     }
-    
+
     return 0;
 }
 
     return 0;
 }
 
@@ -404,14 +405,14 @@ DEFSETFUNC(moduleWithAsmName)
     module *mod = item;
     V_ARG(char *,s);
     V_ARG(module **,rmod);
     module *mod = item;
     V_ARG(char *,s);
     V_ARG(module **,rmod);
-       
+
     if (*rmod)
     if (*rmod)
-       return 0;
+  return 0;
     if (strcmp(mod->asm_name,s) == 0) {
     if (strcmp(mod->asm_name,s) == 0) {
-       *rmod = mod;
-       return 1;
+  *rmod = mod;
+  return 1;
     }
     }
-    
+
     return 0;
 }
 
     return 0;
 }
 
@@ -427,15 +428,15 @@ structdef *structWithName (char *s)
     /* go thru the struct table looking for a match */
     for ( i = 0 ; i < nStructs ; i++ ) {
 
     /* go thru the struct table looking for a match */
     for ( i = 0 ; i < nStructs ; i++ ) {
 
-       if (strcmp(currModName,structs[i]->sname) == 0 &&
-           strcmp(s,structs[i]->tag) == 0)
-           return structs[i];
+  if (strcmp(currModName,structs[i]->sname) == 0 &&
+      strcmp(s,structs[i]->tag) == 0)
+      return structs[i];
     }
 
     }
 
-    ALLOC(nsdef,sizeof(structdef));
+    nsdef = Safe_calloc(1,sizeof(structdef));
     nsdef->tag = alloccpy(s,strlen(s));
     nsdef->sname = currModName ;
     nsdef->tag = alloccpy(s,strlen(s));
     nsdef->sname = currModName ;
-    
+
     nStructs++;
     structs = (struct structdef **)resize((void **)structs,nStructs);
     structs[nStructs-1] = nsdef;
     nStructs++;
     structs = (struct structdef **)resize((void **)structs,nStructs);
     structs[nStructs-1] = nsdef;
@@ -452,12 +453,12 @@ DEFSETFUNC(symWithRName)
     V_ARG(symbol **,rsym);
 
     if (*rsym)
     V_ARG(symbol **,rsym);
 
     if (*rsym)
-       return 0;
+  return 0;
 
     if (strcmp(sym->rname,s) == 0) {
 
     if (strcmp(sym->rname,s) == 0) {
-       *rsym = sym;
-       return 1;
-    }    
+  *rsym = sym;
+  return 1;
+    }
 
     return 0;
 }
 
     return 0;
 }
@@ -472,13 +473,13 @@ DEFSETFUNC(funcWithRName)
     V_ARG(function **,rfunc);
 
     if (*rfunc)
     V_ARG(function **,rfunc);
 
     if (*rfunc)
-       return 0;
-    
+  return 0;
+
     if (strcmp(func->sym->rname,s) == 0) {
     if (strcmp(func->sym->rname,s) == 0) {
-       *rfunc = func;
-       return 1;
-    }    
-    
+  *rfunc = func;
+  return 1;
+    }
+
     return 0;
 }
 
     return 0;
 }
 
@@ -495,20 +496,20 @@ DEFSETFUNC(symLocal)
     V_ARG(symbol **,rsym);
 
     if (strcmp(name,sym->name) == 0 && /* name matches */
     V_ARG(symbol **,rsym);
 
     if (strcmp(name,sym->name) == 0 && /* name matches */
-       sym->scopetype != 'G'       && /* local scope  */
-       (sym->sname && strcmp(sym->sname,sname) == 0) && /* scope == specified scope */
-       sym->block <= block         && /* block & level kindo matches */
-       sym->level <= level) {
-       
-       /* if a symbol was previously found then
-          sure that ones block & level are less
-          then this one */
-       if (*rsym && (*rsym)->block >= block && 
-           (*rsym)->level >= level)
-           return 0;
-
-       *rsym = sym;
-       return 1;       
+  sym->scopetype != 'G'       && /* local scope  */
+  (sym->sname && strcmp(sym->sname,sname) == 0) && /* scope == specified scope */
+  sym->block <= block         && /* block & level kindo matches */
+  sym->level <= level) {
+
+  /* if a symbol was previously found then
+     sure that ones block & level are less
+     then this one */
+  if (*rsym && (*rsym)->block >= block &&
+      (*rsym)->level >= level)
+      return 0;
+
+  *rsym = sym;
+  return 1;
     }
 
     return 0;
     }
 
     return 0;
@@ -524,13 +525,13 @@ DEFSETFUNC(symGlobal)
     V_ARG(symbol **,rsym);
 
     if (*rsym)
     V_ARG(symbol **,rsym);
 
     if (*rsym)
-       return 0;
+  return 0;
 
     /* simple :: global & name matches */
     if (sym->scopetype == 'G' &&
 
     /* simple :: global & name matches */
     if (sym->scopetype == 'G' &&
-       strcmp(sym->name,name) == 0) {
-       *rsym = sym;
-       return 1;
+  strcmp(sym->name,name) == 0) {
+  *rsym = sym;
+  return 1;
     }
 
     return 0;
     }
 
     return 0;
@@ -543,27 +544,33 @@ symbol *symLookup (char *name, context *ctxt)
 {
     symbol *sym = NULL ;
 
 {
     symbol *sym = NULL ;
 
-    /* first try & find a local variable for the
-       given name */
-    if ( applyToSet(symbols,symLocal,
-                   name, 
-                   ctxt->func->sym->name,
-                   ctxt->block,
-                   ctxt->level,
-                   &sym))
-       return sym;
-    
-    sym = NULL;
-    /* then try local to this module */
-    if (applyToSet(symbols,symLocal,
-                  name,
-                  ctxt->func->mod->name,
-                  0,0,&sym))
-       return sym;
-    sym = NULL;
+    if ((ctxt) && (ctxt->func) &&
+        (ctxt->func->sym) && (ctxt->func->sym->name)) {
+      /* first try & find a local variable for the given name */
+      if ( applyToSet(symbols,symLocal,
+        name,
+        ctxt->func->sym->name,
+        ctxt->block,
+        ctxt->level,
+        &sym))
+         return sym;
+      sym = NULL;
+    }
+
+    if ((ctxt) && (ctxt->func) &&
+        (ctxt->func->mod) && (ctxt->func->mod->name)) {
+      /* then try local to this module */
+      if (applyToSet(symbols,symLocal,
+          name,
+          ctxt->func->mod->name,
+          0,0,&sym))
+             return sym;
+      sym = NULL;
+    }
+
     /* no:: try global */
     if ( applyToSet(symbols,symGlobal,name,&sym))
     /* no:: try global */
     if ( applyToSet(symbols,symGlobal,name,&sym))
-       return sym;
+      return sym;
 
     /* cannot find return null */
     return NULL;
 
     /* cannot find return null */
     return NULL;
@@ -579,19 +586,18 @@ static void lnkFuncEnd (char *s)
 
     /* copy till we get to a ':' */
     while ( *s != ':' )
 
     /* copy till we get to a ':' */
     while ( *s != ':' )
-       *bp++ = *s++;
+  *bp++ = *s++;
     bp -= 1;
     bp -= 1;
-    *bp = '\0';        
+    *bp = '\0';
 
     func = NULL;
     if (!applyToSet(functions,funcWithRName,sname,&func))
 
     func = NULL;
     if (!applyToSet(functions,funcWithRName,sname,&func))
-       return ;
-    
+  return ;
+
     s++;
     sscanf(s,"%x",&func->sym->eaddr);
     s++;
     sscanf(s,"%x",&func->sym->eaddr);
-#ifdef SDCDB_DEBUG    
-    printf("%s(eaddr%x)\n",func->sym->name,func->sym->eaddr);
-#endif
+
+    Dprintf(D_symtab, ("%s(eaddr%x)\n",func->sym->name,func->sym->eaddr));
 }
 
 /*-----------------------------------------------------------------*/
 }
 
 /*-----------------------------------------------------------------*/
@@ -604,20 +610,19 @@ static void lnkSymRec (char *s)
 
     /* copy till we get to a ':' */
     while ( *s != ':')
 
     /* copy till we get to a ':' */
     while ( *s != ':')
-       *bp++ = *s++;
+  *bp++ = *s++;
     bp -= 1;
     *bp = '\0';
     bp -= 1;
     *bp = '\0';
-        
+
 
     sym = NULL;
     if (!applyToSet(symbols,symWithRName,sname,&sym))
 
     sym = NULL;
     if (!applyToSet(symbols,symWithRName,sname,&sym))
-       return ;
-    
+  return ;
+
     s++;
     sscanf(s,"%x",&sym->addr);
     s++;
     sscanf(s,"%x",&sym->addr);
-#ifdef SDCDB_DEBUG
-    printf("%s(%x)\n",sym->name,sym->addr);
-#endif
+
+    Dprintf(D_symtab, ("%s(%x)\n",sym->name,sym->addr));
 }
 
 /*-----------------------------------------------------------------*/
 }
 
 /*-----------------------------------------------------------------*/
@@ -630,26 +635,24 @@ static void lnkAsmSrc (char *s)
     unsigned addr;
     module *mod = NULL;
 
     unsigned addr;
     module *mod = NULL;
 
-    /* input will be of format 
+    /* input will be of format
        filename$<line>:<address> */
     while (*s != '$' && *s != '.')
        filename$<line>:<address> */
     while (*s != '$' && *s != '.')
-       *bp++ = *s++;
+  *bp++ = *s++;
     *bp = '\0';
     /* skip to line stuff */
     while (*s != '$') s++;
     *bp = '\0';
     /* skip to line stuff */
     while (*s != '$') s++;
-    
+
     if (!applyToSet(modules,moduleWithName,mname,&mod))
     if (!applyToSet(modules,moduleWithName,mname,&mod))
-       return ;    
+  return ;
 
     if (sscanf(s,"$%d:%x",&line,&addr) != 2)
 
     if (sscanf(s,"$%d:%x",&line,&addr) != 2)
-       return ;
+  return ;
 
     line--;
     if (line < mod->nasmLines) {
 
     line--;
     if (line < mod->nasmLines) {
-       mod->asmLines[line]->addr = addr;
-#ifdef SDCDB_DEBUG
-       printf("%s(%d:%x) %s",mod->asm_name,line,addr,mod->asmLines[line]->src);
-#endif
+  mod->asmLines[line]->addr = addr;
+  Dprintf(D_symtab, ("%s(%d:%x) %s",mod->asm_name,line,addr,mod->asmLines[line]->src));
     }
 }
 
     }
 }
 
@@ -662,39 +665,37 @@ static void lnkCSrc (char *s)
     int block,level,line;
     unsigned int addr;
     module *mod ;
     int block,level,line;
     unsigned int addr;
     module *mod ;
-    
-    /* input will be of format 
+
+    /* input will be of format
        filename.ext$<level>$<block>$<line>:<address> */
     /* get the module name */
     while (*s != '$' )
        filename.ext$<level>$<block>$<line>:<address> */
     /* get the module name */
     while (*s != '$' )
-       *bp++ = *s++;
+  *bp++ = *s++;
     *bp = '\0';
     /* skip the extension */
     while (*s != '$') s++;
 
     if (sscanf(s,"$%d$%d$%d:%x",
     *bp = '\0';
     /* skip the extension */
     while (*s != '$') s++;
 
     if (sscanf(s,"$%d$%d$%d:%x",
-              &line,&level,&block,&addr) != 4)
-       return ;
+         &line,&level,&block,&addr) != 4)
+  return ;
 
     mod = NULL;
 
     mod = NULL;
-    if (!applyToSet(modules,moduleWithCName,mname,&mod)) { 
-       mod = parseModule(mname,FALSE);
-       mod->c_name = alloccpy(mname,strlen(mname));
-       mod->cfullname=searchDirsFname(mod->c_name);
-       mod->cLines = loadFile(mod->c_name,&mod->ncLines);
-    }      
-    
+    if (!applyToSet(modules,moduleWithCName,mname,&mod)) {
+  mod = parseModule(mname,FALSE);
+  mod->c_name = alloccpy(mname,strlen(mname));
+  mod->cfullname=searchDirsFname(mod->c_name);
+  mod->cLines = loadFile(mod->c_name,&mod->ncLines);
+    }
+
     line--;
     if (line < mod->ncLines && line > 0) {
     line--;
     if (line < mod->ncLines && line > 0) {
-       mod->cLines[line]->addr = addr;
-       mod->cLines[line]->block = block;
-       mod->cLines[line]->level = level;
-#ifdef SDCDB_DEBUG
-       printf("%s(%d:%x) %s",mod->c_name,
-              line+1,addr,mod->cLines[line]->src);
-#endif
+  mod->cLines[line]->addr = addr;
+  mod->cLines[line]->block = block;
+  mod->cLines[line]->level = level;
+  Dprintf(D_symtab, ("%s(%d:%x) %s",mod->c_name,
+         line+1,addr,mod->cLines[line]->src));
     }
     }
-    return;    
+    return;
 
 }
 
 
 }
 
@@ -703,26 +704,26 @@ static void lnkCSrc (char *s)
 /*-----------------------------------------------------------------*/
 void parseLnkRec (char *s)
 {
 /*-----------------------------------------------------------------*/
 void parseLnkRec (char *s)
 {
-    /* link records can be several types 
+    /* link records can be several types
        dpeneding on the type do */
        dpeneding on the type do */
-    
+
     switch (*s) {
     switch (*s) {
-       
-       /* c source line address */
-    case 'C': 
-       lnkCSrc(s+2);
-       break;
-       /* assembler source address */
+
+  /* c source line address */
+    case 'C':
+  lnkCSrc(s+2);
+  break;
+  /* assembler source address */
     case 'A':
     case 'A':
-       lnkAsmSrc(s+2);
-       break;
-       
-    case 'X': 
-       lnkFuncEnd(s+1);
-       break; 
-       
+  lnkAsmSrc(s+2);
+  break;
+
+    case 'X':
+  lnkFuncEnd(s+1);
+  break;
+
     default :
     default :
-       lnkSymRec(s);
-       break;
+  lnkSymRec(s);
+  break;
     }
 }
     }
 }