X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=rmac;a=blobdiff_plain;f=symbol.c;fp=symbol.c;h=490d4f077fb388ae5c1508fb4454a505846b7f72;hp=0a50eeb6c34c77ca39db4371e50fa171fcae7c24;hb=e8f9d55bc7aaf40ad5f55de6b3b3cb007d61c865;hpb=3bdb75018beeefb1b9ce2f431011f0db55721eb5 diff --git a/symbol.c b/symbol.c index 0a50eeb..490d4f0 100644 --- a/symbol.c +++ b/symbol.c @@ -88,7 +88,7 @@ SYM * NewSymbol(uint8_t * name, int type, int envno) } // Fill-in the symbol - symbol->sname = strdup(name); + symbol->sname = name ? strdup(name) : NULL; symbol->stype = (uint8_t)type; symbol->senv = (uint16_t)envno; // We don't set this as DEFINED, as it could be a forward reference! @@ -99,14 +99,22 @@ SYM * NewSymbol(uint8_t * name, int type, int envno) symbol->svalue = 0; symbol->sorder = NULL; symbol->uid = currentUID++; + // We don't set st_type, st_desc, or st_other here because they are only + // used by stabs debug symbols, which are always initialized by + // NewDebugSymbol(), which always sets these fields. Hence, initializing + // them here would be redundant. - // Record filename the symbol is defined (for now only used by macro error reporting) + // Record filename the symbol is defined (Used by macro error reporting and some debug symbols) symbol->cfileno = cfileno; - // Install symbol in the symbol table - int hash = HashSymbol(name, envno); - symbol->snext = symbolTable[hash]; - symbolTable[hash] = symbol; + // Don't hash debug symbols: they are never looked up and may have no name. + if (type != DBGSYM) + { + // Install symbol in the symbol table + int hash = HashSymbol(name, envno); + symbol->snext = symbolTable[hash]; + symbolTable[hash] = symbol; + } // Append symbol to the symbol-order list if (sorder == NULL) @@ -235,7 +243,16 @@ uint32_t AssignSymbolNos(uint8_t * buf, uint8_t *(* construct)()) // them. We also pick which symbols should be global or not here. for(SYM * sy=sdecl; sy!=NULL; sy=sy->sdecl) { - // Skip non-labels + // Always export debug symbols. Don't force them global. + if (DBGSYM == sy->stype) { + sy->senv = scount++; + + if (buf != NULL) + buf = construct(buf, sy, 0); + continue; + } + + // Skip non-labels. if (sy->stype != LABEL) continue; @@ -547,3 +564,19 @@ int symtable(void) return 0; } + +SYM * NewDebugSymbol(uint8_t * str, uint8_t type, uint8_t other, uint16_t desc) +{ + SYM * symbol = NewSymbol(str, DBGSYM, 0); + + if (NULL == symbol) + return NULL; + + AddToSymbolDeclarationList(symbol); + + symbol->st_type = type; + symbol->st_other = other; + symbol->st_desc = desc; + + return symbol; +}