1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-31 11:32:00 +00:00

Write out global symbols to the debug file. Added some fixes for unusual

situations (extern symbols without attached import, because the import wasn't
referenced and therefore removed by the assembler).


git-svn-id: svn://svn.cc65.org/cc65/trunk@5290 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2011-08-31 20:48:40 +00:00
parent f204ec956a
commit 8fc851b338
6 changed files with 69 additions and 37 deletions

View File

@ -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) {

View File

@ -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 ();

View File

@ -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 */

View File

@ -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;
}
}
}

View File

@ -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 */

View File

@ -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);
}