}
// 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!
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)
// 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;
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;
+}