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

Write imports out to the debug info file. Add the id of the corresponding

export.


git-svn-id: svn://svn.cc65.org/cc65/trunk@5186 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2011-08-16 13:58:59 +00:00
parent b7c4a4fe01
commit 3996725f44
8 changed files with 165 additions and 69 deletions

View File

@ -44,6 +44,7 @@
/* ld65 */ /* ld65 */
#include "dbgsyms.h" #include "dbgsyms.h"
#include "error.h" #include "error.h"
#include "exports.h"
#include "expr.h" #include "expr.h"
#include "fileio.h" #include "fileio.h"
#include "global.h" #include "global.h"
@ -59,6 +60,21 @@
/* Definition of the debug symbol structure */
struct DbgSym {
unsigned Id; /* Id of debug symbol */
DbgSym* Next; /* Pool linear list link */
ObjData* Obj; /* Object file that exports the name */
Collection LineInfos; /* Line infos of definition */
ExprNode* Expr; /* Expression (0 if not def'd) */
unsigned Size; /* Symbol size if any */
unsigned OwnerId; /* Id of parent/owner */
unsigned ImportId; /* Id of import if this is one */
unsigned Name; /* Name */
unsigned short Type; /* Type of symbol */
unsigned short AddrSize; /* Address size of symbol */
};
/* We will collect all debug symbols in the following array and remove /* We will collect all debug symbols in the following array and remove
* duplicates before outputing them. * duplicates before outputing them.
*/ */
@ -72,19 +88,22 @@ static DbgSym* DbgSymPool[256];
static DbgSym* NewDbgSym (unsigned Type, unsigned char AddrSize, ObjData* O) static DbgSym* NewDbgSym (unsigned Id, unsigned Type, unsigned char AddrSize,
ObjData* O)
/* Create a new DbgSym and return it */ /* Create a new DbgSym and return it */
{ {
/* Allocate memory */ /* Allocate memory */
DbgSym* D = xmalloc (sizeof (DbgSym)); DbgSym* D = xmalloc (sizeof (DbgSym));
/* Initialize the fields */ /* Initialize the fields */
D->Id = Id;
D->Next = 0; D->Next = 0;
D->Obj = O; D->Obj = O;
D->LineInfos = EmptyCollection; D->LineInfos = EmptyCollection;
D->Expr = 0; D->Expr = 0;
D->Size = 0; D->Size = 0;
D->OwnerId = ~0U; D->OwnerId = ~0U;
D->ImportId = ~0U;
D->Name = 0; D->Name = 0;
D->Type = Type; D->Type = Type;
D->AddrSize = AddrSize; D->AddrSize = AddrSize;
@ -141,7 +160,7 @@ static void InsertDbgSym (DbgSym* D, long Val)
DbgSym* ReadDbgSym (FILE* F, ObjData* O) DbgSym* ReadDbgSym (FILE* F, ObjData* O, unsigned Id)
/* Read a debug symbol from a file, insert and return it */ /* Read a debug symbol from a file, insert and return it */
{ {
/* Read the type and address size */ /* Read the type and address size */
@ -149,7 +168,7 @@ DbgSym* ReadDbgSym (FILE* F, ObjData* O)
unsigned char AddrSize = Read8 (F); unsigned char AddrSize = Read8 (F);
/* Create a new debug symbol */ /* Create a new debug symbol */
DbgSym* D = NewDbgSym (Type, AddrSize, O); DbgSym* D = NewDbgSym (Id, Type, AddrSize, O);
/* Read the id of the owner scope/symbol */ /* Read the id of the owner scope/symbol */
D->OwnerId = ReadVar (F); D->OwnerId = ReadVar (F);
@ -169,6 +188,19 @@ DbgSym* ReadDbgSym (FILE* F, ObjData* O)
D->Size = ReadVar (F); D->Size = ReadVar (F);
} }
/* If this is an import, the file contains its id */
if (SYM_IS_IMPORT (D->Type)) {
D->ImportId = ReadVar (F);
}
/* If its an exports, there's also the export id, but we don't remember
* it but use it to let the export point back to us.
*/
if (SYM_IS_EXPORT (D->Type)) {
/* Get the export from the export id, then set the our id */
GetObjExport (O, ReadVar (F))->DbgSymId = Id;
}
/* Last is the list of line infos for this symbol */ /* Last is the list of line infos for this symbol */
ReadLineInfoList (F, O, &D->LineInfos); ReadLineInfoList (F, O, &D->LineInfos);
@ -195,7 +227,7 @@ void ClearDbgSymTable (void)
long GetDbgSymVal (const DbgSym* D) static long GetDbgSymVal (const DbgSym* D)
/* Get the value of this symbol */ /* Get the value of this symbol */
{ {
CHECK (D->Expr != 0); CHECK (D->Expr != 0);
@ -212,42 +244,58 @@ void PrintDbgSyms (FILE* F)
for (I = 0; I < CollCount (&ObjDataList); ++I) { for (I = 0; I < CollCount (&ObjDataList); ++I) {
/* Get the object file */ /* Get the object file */
const ObjData* O = CollAtUnchecked (&ObjDataList, I); ObjData* O = CollAtUnchecked (&ObjDataList, I);
/* Walk through all debug symbols in this module */ /* Walk through all debug symbols in this module */
for (J = 0; J < CollCount (&O->DbgSyms); ++J) { for (J = 0; J < CollCount (&O->DbgSyms); ++J) {
long Val;
SegExprDesc D;
/* Get the next debug symbol */ /* Get the next debug symbol */
const DbgSym* S = CollConstAt (&O->DbgSyms, J); const DbgSym* S = CollConstAt (&O->DbgSyms, J);
/* Get the symbol value */
Val = GetDbgSymVal (S);
/* Emit the base data for the entry */ /* Emit the base data for the entry */
fprintf (F, fprintf (F,
"sym\tid=%u,name=\"%s\",val=0x%lX,addrsize=%s,type=%s", "sym\tid=%u,name=\"%s\",addrsize=%s,type=%s",
O->SymBaseId + J, O->SymBaseId + J,
GetString (S->Name), GetString (S->Name),
Val,
AddrSizeToStr (S->AddrSize), AddrSizeToStr (S->AddrSize),
SYM_IS_LABEL (S->Type)? "lab" : "equ"); SYM_IS_LABEL (S->Type)? "lab" : "equ");
/* Emit the size only if we know it */ /* If this is not an import, output its value and - if we have
if (S->Size != 0) { * it - the segment.
fprintf (F, ",size=%lu", S->Size); */
} if (!SYM_IS_IMPORT (S->Type)) {
/* Check for a segmented expression and add the segment id to the SegExprDesc D;
* debug info if we have one.
/* Get the symbol value */
long Val = GetDbgSymVal (S);
/* Output it */
fprintf (F, ",val=0x%lX", Val);
/* Check for a segmented expression and add the segment id to
* the debug info if we have one.
*/ */
GetSegExprVal (S->Expr, &D); GetSegExprVal (S->Expr, &D);
if (!D.TooComplex && D.Seg != 0) { if (!D.TooComplex && D.Seg != 0) {
fprintf (F, ",seg=%u", D.Seg->Id); fprintf (F, ",seg=%u", D.Seg->Id);
} }
/* Output the type */
fprintf (F, ",type=%s", SYM_IS_LABEL (S->Type)? "lab" : "equ");
} else {
/* Output the type */
fputs (",type=imp", F);
}
/* Emit the size only if we know it */
if (S->Size != 0) {
fprintf (F, ",size=%u", S->Size);
}
/* For cheap local symbols, add the owner symbol, for others, /* For cheap local symbols, add the owner symbol, for others,
* add the owner scope. * add the owner scope.
*/ */
@ -257,6 +305,23 @@ void PrintDbgSyms (FILE* F)
fprintf (F, ",parent=%u", O->SymBaseId + S->OwnerId); fprintf (F, ",parent=%u", O->SymBaseId + S->OwnerId);
} }
/* If this is an import, output the id of the matching export */
if (SYM_IS_IMPORT (S->Type)) {
/* Get the import */
const Import* Imp = GetObjImport (O, S->ImportId);
/* Get the export from the import */
const Export* Exp = Imp->Exp;
/* If this is not a linker generated symbol, output the debug
* symbol id for the export
*/
if (Exp->Obj) {
fprintf (F, ",exp=%u", Exp->Obj->SymBaseId + Exp->DbgSymId);
}
}
/* Terminate the output line */ /* Terminate the output line */
fputc ('\n', F); fputc ('\n', F);
} }
@ -278,8 +343,8 @@ void PrintDbgSymLabels (ObjData* O, FILE* F)
/* Get the next debug symbol */ /* Get the next debug symbol */
DbgSym* D = CollAt (&O->DbgSyms, I); DbgSym* D = CollAt (&O->DbgSyms, I);
/* Emit this symbol only if it is a label (ignore equates) */ /* Emit this symbol only if it is a label (ignore equates and imports) */
if (SYM_IS_EQUATE (D->Type)) { if (SYM_IS_EQUATE (D->Type) || SYM_IS_IMPORT (D->Type)) {
continue; continue;
} }

View File

@ -58,19 +58,8 @@
/* Forwards */ /* Forwards */
struct Scope; struct Scope;
/* Debug symbol structure */ /* Opaque debug symbol structure */
typedef struct DbgSym DbgSym; typedef struct DbgSym DbgSym;
struct DbgSym {
DbgSym* Next; /* Pool linear list link */
ObjData* Obj; /* Object file that exports the name */
Collection LineInfos; /* Line infos of definition */
ExprNode* Expr; /* Expression (0 if not def'd) */
unsigned Size; /* Symbol size if any */
unsigned OwnerId; /* Id of parent/owner */
unsigned Name; /* Name */
unsigned short Type; /* Type of symbol */
unsigned short AddrSize; /* Address size of symbol */
};
@ -80,12 +69,9 @@ struct DbgSym {
DbgSym* ReadDbgSym (FILE* F, ObjData* Obj); DbgSym* ReadDbgSym (FILE* F, ObjData* Obj, unsigned Id);
/* Read a debug symbol from a file, insert and return it */ /* Read a debug symbol from a file, insert and return it */
long GetDbgSymVal (const DbgSym* D);
/* Get the value of this symbol */
void ClearDbgSymTable (void); void ClearDbgSymTable (void);
/* Clear the debug symbol table. Must be called before outputting debug syms /* Clear the debug symbol table. Must be called before outputting debug syms
* or debug labels the first time. * or debug labels the first time.

View File

@ -41,6 +41,7 @@
#include "addrsize.h" #include "addrsize.h"
#include "check.h" #include "check.h"
#include "hashfunc.h" #include "hashfunc.h"
#include "lidefs.h"
#include "symdefs.h" #include "symdefs.h"
#include "xmalloc.h" #include "xmalloc.h"
@ -274,11 +275,21 @@ Import* InsertImport (Import* I)
const LineInfo* GetImportPos (const Import* I) const LineInfo* GetImportPos (const Import* Imp)
/* Return the basic line info of an import */ /* Return the basic line info of an import */
{ {
/* Source file position is always in slot zero */ unsigned I;
return CollConstAt (&I->LineInfos, 0);
/* Search for a line info of LI_TYPE_ASM */
for (I = 0; I < CollCount (&Imp->LineInfos); ++I) {
const LineInfo* LI = CollConstAt (&Imp->LineInfos, I);
if (LI_GET_TYPE (LI->Type) == LI_TYPE_ASM) {
return LI;
}
}
/* Not found - return the one in slot zero */
return CollConstAt (&Imp->LineInfos, 0);
} }
@ -306,6 +317,7 @@ static Export* NewExport (unsigned Type, unsigned char AddrSize,
E->Expr = 0; E->Expr = 0;
E->Size = 0; E->Size = 0;
E->LineInfos = EmptyCollection; E->LineInfos = EmptyCollection;
E->DbgSymId = ~0U;
E->Type = Type | SYM_EXPORT; E->Type = Type | SYM_EXPORT;
E->AddrSize = AddrSize; E->AddrSize = AddrSize;
memset (E->ConDes, 0, sizeof (E->ConDes)); memset (E->ConDes, 0, sizeof (E->ConDes));

View File

@ -85,6 +85,7 @@ struct Export {
ExprNode* Expr; /* Expression (0 if not def'd) */ ExprNode* Expr; /* Expression (0 if not def'd) */
unsigned Size; /* Size of the symbol if any */ unsigned Size; /* Size of the symbol if any */
Collection LineInfos; /* Line info of definition */ Collection LineInfos; /* Line info of definition */
unsigned DbgSymId; /* Id of debug symbol for this export */
unsigned short Type; /* Type of export */ unsigned short Type; /* Type of export */
unsigned short AddrSize; /* Address size of export */ unsigned short AddrSize; /* Address size of export */
unsigned char ConDes[CD_TYPE_COUNT]; /* Constructor/destructor decls */ unsigned char ConDes[CD_TYPE_COUNT]; /* Constructor/destructor decls */

View File

@ -201,8 +201,8 @@ Import* GetExprImport (ExprNode* Expr)
* import pointer. * import pointer.
*/ */
if (Expr->Obj) { if (Expr->Obj) {
/* Return the export */ /* Return the Import */
return CollAt (&Expr->Obj->Imports, Expr->V.ImpNum); return GetObjImport (Expr->Obj, Expr->V.ImpNum);
} else { } else {
return Expr->V.Imp; return Expr->V.Imp;
} }

View File

@ -211,6 +211,30 @@ struct Section* GetObjSection (ObjData* O, unsigned Id)
struct Import* GetObjImport (ObjData* O, unsigned Id)
/* Get an import from an object file checking for a valid index */
{
if (Id >= CollCount (&O->Imports)) {
Error ("Invalid import index (%u) in module `%s'",
Id, GetObjFileName (O));
}
return CollAtUnchecked (&O->Imports, Id);
}
struct Export* GetObjExport (ObjData* O, unsigned Id)
/* Get an export from an object file checking for a valid index */
{
if (Id >= CollCount (&O->Exports)) {
Error ("Invalid export index (%u) in module `%s'",
Id, GetObjFileName (O));
}
return CollAtUnchecked (&O->Exports, Id);
}
struct Scope* GetObjScope (ObjData* O, unsigned Id) struct Scope* GetObjScope (ObjData* O, unsigned Id)
/* Get a scope from an object file checking for a valid index */ /* Get a scope from an object file checking for a valid index */
{ {

View File

@ -52,6 +52,8 @@
/* Forwards */ /* Forwards */
struct Export;
struct Import;
struct Library; struct Library;
struct Scope; struct Scope;
struct Section; struct Section;
@ -144,6 +146,12 @@ INLINE int ObjHasFiles (const ObjData* O)
struct Section* GetObjSection (ObjData* Obj, unsigned Id); struct Section* GetObjSection (ObjData* Obj, unsigned Id);
/* Get a section from an object file checking for a valid index */ /* Get a section from an object file checking for a valid index */
struct Import* GetObjImport (ObjData* Obj, unsigned Id);
/* Get an import from an object file checking for a valid index */
struct Export* GetObjExport (ObjData* Obj, unsigned Id);
/* Get an export from an object file checking for a valid index */
struct Scope* GetObjScope (ObjData* Obj, unsigned Id); struct Scope* GetObjScope (ObjData* Obj, unsigned Id);
/* Get a scope from an object file checking for a valid index */ /* Get a scope from an object file checking for a valid index */

View File

@ -200,7 +200,7 @@ void ObjReadDbgSyms (FILE* F, unsigned long Pos, ObjData* O)
DbgSymCount = ReadVar (F); DbgSymCount = ReadVar (F);
CollGrow (&O->DbgSyms, DbgSymCount); CollGrow (&O->DbgSyms, DbgSymCount);
for (I = 0; I < DbgSymCount; ++I) { for (I = 0; I < DbgSymCount; ++I) {
CollAppend (&O->DbgSyms, ReadDbgSym (F, O)); CollAppend (&O->DbgSyms, ReadDbgSym (F, O, I));
} }
} }