diff --git a/src/ca65/dbginfo.c b/src/ca65/dbginfo.c index bed6a919e..4356a9076 100644 --- a/src/ca65/dbginfo.c +++ b/src/ca65/dbginfo.c @@ -495,16 +495,22 @@ void WriteHLLDbgSyms (void) for (I = 0; I < CollCount (&HLLDbgSyms); ++I) { /* Get the next symbol */ - const HLLDbgSym* S = CollAtUnchecked (&HLLDbgSyms, I); + HLLDbgSym* S = CollAtUnchecked (&HLLDbgSyms, I); /* Get the type of the symbol */ unsigned SC = HLL_GET_SC (S->Flags); + /* Remember if the symbol has debug info attached + * ### This should go into DbgInfoCheck + */ + if (S->Sym && S->Sym->DebugSymId) { + S->Flags |= HLL_DATA_SYM; + } + /* Write the symbol data */ ObjWriteVar (S->Flags); ObjWriteVar (S->Name); - if (SC != HLL_SC_AUTO) { - CHECK (S->Sym->DebugSymId != ~0U); + if (HLL_HAS_SYM (S->Flags)) { ObjWriteVar (S->Sym->DebugSymId); } if (SC == HLL_SC_AUTO || SC == HLL_SC_REG) { diff --git a/src/cc65/compile.c b/src/cc65/compile.c index d0545e92b..bff3b9526 100644 --- a/src/cc65/compile.c +++ b/src/cc65/compile.c @@ -397,7 +397,7 @@ void Compile (const char* FileName) void FinishCompile (void) -/* Emit literals, externals, do cleanup and optimizations */ +/* Emit literals, externals, debug info, do cleanup and optimizations */ { SymTable* SymTab; SymEntry* Func; @@ -418,6 +418,9 @@ void FinishCompile (void) /* Output the literal pool */ OutputLiteralPool (); + /* Emit debug infos if enabled */ + EmitDebugInfo (); + /* Write imported/exported symbols */ EmitExternals (); diff --git a/src/cc65/function.c b/src/cc65/function.c index d646167ba..7c9e52cbb 100644 --- a/src/cc65/function.c +++ b/src/cc65/function.c @@ -359,39 +359,18 @@ static void F_RestoreRegVars (Function* F) -static void EmitDebugInfo (void) +static void F_EmitDebugInfo (void) /* Emit debug infos for the current function */ -{ - /* Fetch stuff for the current fuction */ - const SymEntry* Sym = CurrentFunc->FuncEntry; - const FuncDesc* Desc = CurrentFunc->Desc; - const SymTable* Tab = Desc->SymTab; +{ + if (DebugInfo) { + /* Get the current fuction */ + const SymEntry* Sym = CurrentFunc->FuncEntry; - /* Output info for the function itself */ - AddTextLine ("\t.dbg\tfunc, \"%s\", \"00\", %s, \"%s\"", - Sym->Name, - (Sym->Flags & SC_EXTERN)? "extern" : "static", - Sym->AsmName); - - /* Output info for locals */ - Sym = Tab->SymHead; - while (Sym) { - if ((Sym->Flags & (SC_CONST|SC_TYPE)) == 0) { - if (Sym->Flags & SC_AUTO) { - AddTextLine ("\t.dbg\tsym, \"%s\", \"00\", auto, %d", - Sym->Name, Sym->V.Offs); - } else if (Sym->Flags & SC_REGISTER) { - AddTextLine ("\t.dbg\tsym, \"%s\", \"00\", register, \"regbank\", %d", - Sym->Name, Sym->V.R.RegOffs); - - } else { - AddTextLine ("\t.dbg\tsym, \"%s\", \"00\", %s, \"%s\"", - Sym->Name, - (Sym->Flags & SC_EXTERN)? "extern" : "static", - Sym->AsmName); - } - } - Sym = Sym->NextSym; + /* Output info for the function itself */ + AddTextLine ("\t.dbg\tfunc, \"%s\", \"00\", %s, \"%s\"", + Sym->Name, + (Sym->Flags & SC_EXTERN)? "extern" : "static", + Sym->AsmName); } } @@ -593,6 +572,7 @@ void NewFunc (SymEntry* Func) EmitExternals (); /* Emit function debug info */ + F_EmitDebugInfo (); EmitDebugInfo (); /* Leave the lexical level */ diff --git a/src/cc65/symtab.c b/src/cc65/symtab.c index 18b9696d4..db6541ee7 100644 --- a/src/cc65/symtab.c +++ b/src/cc65/symtab.c @@ -946,3 +946,43 @@ void EmitExternals (void) +void EmitDebugInfo (void) +/* Emit debug infos for the locals of the current scope */ +{ + const char* Head; + const SymEntry* Sym; + + /* Output info for locals if enabled */ + if (DebugInfo) { + /* For cosmetic reasons in the output file, we will insert two tabs + * on global level and just one on local level. + */ + if (LexicalLevel == LEX_LEVEL_GLOBAL) { + Head = "\t.dbg\t\tsym"; + } else { + Head = "\t.dbg\tsym"; + } + Sym = SymTab->SymHead; + while (Sym) { + if ((Sym->Flags & (SC_CONST|SC_TYPE)) == 0) { + if (Sym->Flags & SC_AUTO) { + AddTextLine ("%s, \"%s\", \"00\", auto, %d", + Head, Sym->Name, Sym->V.Offs); + } else if (Sym->Flags & SC_REGISTER) { + AddTextLine ("%s, \"%s\", \"00\", register, \"regbank\", %d", + Head, Sym->Name, Sym->V.R.RegOffs); + + } else if (SymIsRef (Sym) && !SymIsDef (Sym)) { + AddTextLine ("%s, \"%s\", \"00\", %s, \"%s\"", + Head, Sym->Name, + (Sym->Flags & SC_EXTERN)? "extern" : "static", + Sym->AsmName); + } + } + Sym = Sym->NextSym; + } + } +} + + + diff --git a/src/cc65/symtab.h b/src/cc65/symtab.h index 18c8ce141..3311e8b73 100644 --- a/src/cc65/symtab.h +++ b/src/cc65/symtab.h @@ -188,6 +188,9 @@ void PrintSymTable (const SymTable* Tab, FILE* F, const char* Header, ...); void EmitExternals (void); /* Write import/export statements for external symbols */ +void EmitDebugInfo (void); +/* Emit debug infos for the locals of the current scope */ + /* End of symtab.h */ diff --git a/src/ld65/dbgsyms.c b/src/ld65/dbgsyms.c index a7c1edde4..db2f8c663 100644 --- a/src/ld65/dbgsyms.c +++ b/src/ld65/dbgsyms.c @@ -248,7 +248,7 @@ HLLDbgSym* ReadHLLDbgSym (FILE* F, ObjData* O, unsigned Id attribute ((unused))) S->Flags = ReadVar (F); SC = HLL_GET_SC (S->Flags); S->Name = MakeGlobalStringId (O, ReadVar (F)); - if (SC != HLL_SC_AUTO) { + if (HLL_HAS_SYM (S->Flags)) { S->Sym = GetObjDbgSym (O, ReadVar (F)); } else { /* Auto variables aren't attached to asm symbols */ @@ -483,7 +483,7 @@ void PrintHLLDbgSyms (FILE* F) } /* For non auto symbols output the debug symbol id of the asm sym */ - if (SC != HLL_SC_AUTO) { + if (HLL_HAS_SYM (S->Flags)) { fprintf (F, ",sym=%u", S->Sym->Id); }