X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fld65%2Fdbgsyms.c;h=f52e082d75d99283e9a396c6f59f07c984bdda89;hb=0807da74bd7c3ebe3e6e75129a07a810b17174b2;hp=5df33aaf4c782bbc9d09ac7aa62b335198977599;hpb=2767f66146ff0af2d26933a2f9cae6282c4bd6b6;p=cc65 diff --git a/src/ld65/dbgsyms.c b/src/ld65/dbgsyms.c index 5df33aaf4..f52e082d7 100644 --- a/src/ld65/dbgsyms.c +++ b/src/ld65/dbgsyms.c @@ -2,14 +2,14 @@ /* */ /* dbgsyms.c */ /* */ -/* Debug symbol handing for the ld65 linker */ +/* Debug symbol handling for the ld65 linker */ /* */ /* */ /* */ -/* (C) 1998 Ullrich von Bassewitz */ -/* Wacholderweg 14 */ -/* D-70597 Stuttgart */ -/* EMail: uz@musoftware.de */ +/* (C) 1998-2010, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -35,15 +35,20 @@ #include -#include "../common/symdefs.h" -#include "../common/xmalloc.h" +/* common */ +#include "addrsize.h" +#include "check.h" +#include "symdefs.h" +#include "xmalloc.h" -#include "global.h" +/* ld65 */ +#include "dbgsyms.h" #include "error.h" +#include "expr.h" #include "fileio.h" +#include "global.h" #include "objdata.h" -#include "expr.h" -#include "dbgsyms.h" +#include "spool.h" @@ -56,7 +61,7 @@ /* We will collect all debug symbols in the following array and remove * duplicates before outputing them. */ -static DbgSym* DbgSymPool [256]; +static DbgSym* DbgSymPool[256]; @@ -66,23 +71,20 @@ static DbgSym* DbgSymPool [256]; -static DbgSym* NewDbgSym (unsigned char Type, const char* Name, ObjData* O) +static DbgSym* NewDbgSym (unsigned char Type, unsigned char AddrSize, ObjData* O) /* Create a new DbgSym and return it */ { - /* Get the length of the symbol name */ - unsigned Len = strlen (Name); - /* Allocate memory */ - DbgSym* D = xmalloc (sizeof (DbgSym) + Len); + DbgSym* D = xmalloc (sizeof (DbgSym)); /* Initialize the fields */ D->Next = 0; D->Flags = 0; D->Obj = O; D->Expr = 0; + D->Name = 0; D->Type = Type; - memcpy (D->Name, Name, Len); - D->Name [Len] = '\0'; + D->AddrSize = AddrSize; /* Return the new entry */ return D; @@ -97,15 +99,15 @@ static DbgSym* GetDbgSym (DbgSym* D, long Val) { /* Create the hash. We hash over the symbol value */ unsigned Hash = ((Val >> 24) & 0xFF) ^ - ((Val >> 16) & 0xFF) ^ - ((Val >> 8) & 0xFF) ^ - ((Val >> 0) & 0xFF); + ((Val >> 16) & 0xFF) ^ + ((Val >> 8) & 0xFF) ^ + ((Val >> 0) & 0xFF); /* Check for this symbol */ - DbgSym* Sym = DbgSymPool [Hash]; + DbgSym* Sym = DbgSymPool[Hash]; while (Sym) { /* Is this symbol identical? */ - if (strcmp (Sym->Name, D->Name) == 0 && EqualExpr (Sym->Expr, D->Expr)) { + if (Sym->Name == D->Name && EqualExpr (Sym->Expr, D->Expr)) { /* Found */ return Sym; } @@ -139,21 +141,18 @@ static void InsertDbgSym (DbgSym* D, long Val) DbgSym* ReadDbgSym (FILE* F, ObjData* O) /* Read a debug symbol from a file, insert and return it */ { - unsigned char Type; - char Name [256]; - DbgSym* D; - - /* Read the type */ - Type = Read8 (F); + /* Read the type and address size */ + unsigned char Type = Read8 (F); + unsigned char AddrSize = Read8 (F); - /* Read the name */ - ReadStr (F, Name); + /* Create a new debug symbol */ + DbgSym* D = NewDbgSym (Type, AddrSize, O); - /* Create a new export */ - D = NewDbgSym (Type, Name, O); + /* Read and assign the name */ + D->Name = MakeGlobalStringId (O, ReadVar (F)); /* Read the value */ - if (Type & EXP_EXPR) { + if (IS_EXP_EXPR (D->Type)) { D->Expr = ReadExpr (F, O); } else { D->Expr = LiteralExpr (Read32 (F), O); @@ -168,7 +167,24 @@ DbgSym* ReadDbgSym (FILE* F, ObjData* O) -long GetDbgSymVal (DbgSym* D) +void ClearDbgSymTable (void) +/* Clear the debug symbol table */ +{ + unsigned I; + for (I = 0; I < sizeof (DbgSymPool) / sizeof (DbgSymPool[0]); ++I) { + DbgSym* Sym = DbgSymPool[I]; + DbgSymPool[I] = 0; + while (Sym) { + DbgSym* NextSym = Sym->Next; + Sym->Next = 0; + Sym = NextSym; + } + } +} + + + +long GetDbgSymVal (const DbgSym* D) /* Get the value of this symbol */ { CHECK (D->Expr != 0); @@ -177,19 +193,64 @@ long GetDbgSymVal (DbgSym* D) +void PrintDbgSyms (ObjData* O, FILE* F) +/* Print the debug symbols in a debug file */ +{ + unsigned I; + + /* Walk through all debug symbols in this module */ + for (I = 0; I < CollCount (&O->DbgSyms); ++I) { + + long Val; + + /* Get the next debug symbol */ + DbgSym* D = CollAt (&O->DbgSyms, I); + + /* Get the symbol value */ + Val = GetDbgSymVal (D); + + /* Lookup this symbol in the table. If it is found in the table, it was + * already written to the file, so don't emit it twice. If it is not in + * the table, insert and output it. + */ + if (GetDbgSym (D, Val) == 0) { + + /* Emit the debug file line */ + fprintf (F, + "sym\t\"%s\",value=0x%08lX,addrsize=%s,type=%s\n", + GetString (D->Name), + Val, + AddrSizeToStr (D->AddrSize), + IS_EXP_LABEL (D->Type)? "label" : "equate"); + + /* Insert the symbol into the table */ + InsertDbgSym (D, Val); + } + } +} + + + void PrintDbgSymLabels (ObjData* O, FILE* F) /* Print the debug symbols in a VICE label file */ { unsigned I; /* Walk through all debug symbols in this module */ - for (I = 0; I < O->DbgSymCount; ++I) { + for (I = 0; I < CollCount (&O->DbgSyms); ++I) { + + long Val; /* Get the next debug symbol */ - DbgSym* D = O->DbgSyms [I]; + DbgSym* D = CollAt (&O->DbgSyms, I); + + /* Emit this symbol only if it is a label (ignore equates) */ + if (IS_EXP_EQUATE (D->Type)) { + continue; + } /* Get the symbol value */ - long Val = GetDbgSymVal (D); + Val = GetDbgSymVal (D); /* Lookup this symbol in the table. If it is found in the table, it was * already written to the file, so don't emit it twice. If it is not in @@ -198,7 +259,7 @@ void PrintDbgSymLabels (ObjData* O, FILE* F) if (GetDbgSym (D, Val) == 0) { /* Emit the VICE label line */ - fprintf (F, "al %06lX .%s\n", Val, D->Name); + fprintf (F, "al %06lX .%s\n", Val, GetString (D->Name)); /* Insert the symbol into the table */ InsertDbgSym (D, Val); @@ -208,3 +269,4 @@ void PrintDbgSymLabels (ObjData* O, FILE* F) +