1
0
mirror of https://github.com/cc65/cc65.git synced 2025-01-12 17:30:50 +00:00

Central management of the debug info base ids.

git-svn-id: svn://svn.cc65.org/cc65/trunk@5123 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2011-08-05 13:09:13 +00:00
parent a87d8ec233
commit a17d11cba8
6 changed files with 60 additions and 25 deletions

View File

@ -50,11 +50,43 @@
/*****************************************************************************/
/* Code */
/* Code */
/*****************************************************************************/
static void AssignBaseIds (void)
/* Assign the base ids for debug info output. Within each module, many of the
* items are addressed by ids which are actually the indices of the items in
* the collections. To make them unique, we must assign a unique base to each
* range.
*/
{
unsigned I;
/* Walk over all modules */
unsigned FileBaseId = 0;
unsigned SymBaseId = 0;
unsigned ScopeBaseId = 0;
for (I = 0; I < CollCount (&ObjDataList); ++I) {
/* Get this module */
ObjData* O = CollAt (&ObjDataList, I);
/* Assign ids */
O->FileBaseId = FileBaseId;
O->SymBaseId = SymBaseId;
O->ScopeBaseId = ScopeBaseId;
/* Bump the base ids */
FileBaseId += CollCount (&O->Files);
SymBaseId += CollCount (&O->DbgSyms);
ScopeBaseId += CollCount (&O->Scopes);
}
}
void CreateDbgFile (void)
/* Create a debug info file */
{
@ -69,7 +101,10 @@ void CreateDbgFile (void)
/* Output version information */
fprintf (F, "version\tmajor=1,minor=2\n");
/* Output modules */
/* Assign the base ids to the modules */
AssignBaseIds ();
/* Output modules */
for (I = 0; I < CollCount (&ObjDataList); ++I) {
/* Get this object file */
@ -80,7 +115,7 @@ void CreateDbgFile (void)
/* Output the module line */
fprintf (F,
"module\tid=%u,name=\"%s\",file=%u",
"mod\tid=%u,name=\"%s\",file=%u",
I,
GetObjFileName (O),
Source->Id);

View File

@ -207,10 +207,9 @@ long GetDbgSymVal (const DbgSym* D)
void PrintDbgSyms (FILE* F)
/* Print the debug symbols in a debug file */
{
{
unsigned I, J;
unsigned BaseId = 0;
for (I = 0; I < CollCount (&ObjDataList); ++I) {
/* Get the object file */
@ -230,12 +229,12 @@ void PrintDbgSyms (FILE* F)
/* Emit the base data for the entry */
fprintf (F,
"sym\tid=%u,name=\"%s\",value=0x%lX,addrsize=%s,type=%s",
BaseId + J,
"sym\tid=%u,name=\"%s\",val=0x%lX,addrsize=%s,type=%s",
O->SymBaseId + J,
GetString (S->Name),
Val,
AddrSizeToStr (S->AddrSize),
SYM_IS_LABEL (S->Type)? "label" : "equate");
SYM_IS_LABEL (S->Type)? "lab" : "equ");
/* Emit the size only if we know it */
if (S->Size != 0) {
@ -247,24 +246,21 @@ void PrintDbgSyms (FILE* F)
*/
GetSegExprVal (S->Expr, &D);
if (!D.TooComplex && D.Seg != 0) {
fprintf (F, ",segment=%u", D.Seg->Id);
fprintf (F, ",seg=%u", D.Seg->Id);
}
/* For cheap local symbols, add the owner symbol, for others,
* add the owner scope.
*/
if (SYM_IS_STD (S->Type)) {
fprintf (F, ",scope=%u", S->OwnerId);
fprintf (F, ",scope=%u", O->ScopeBaseId + S->OwnerId);
} else {
fprintf (F, ",parent=%u", S->OwnerId);
fprintf (F, ",parent=%u", O->SymBaseId + S->OwnerId);
}
/* Terminate the output line */
fputc ('\n', F);
}
/* Increment base id */
BaseId += CollCount (&O->DbgSyms);
}
}

View File

@ -78,6 +78,9 @@ ObjData* NewObjData (void)
O->MTime = 0;
O->Start = 0;
O->Flags = 0;
O->FileBaseId = 0;
O->SymBaseId = 0;
O->ScopeBaseId = 0;
O->Files = EmptyCollection;
O->Sections = EmptyCollection;
O->Exports = EmptyCollection;

View File

@ -68,6 +68,11 @@ struct ObjData {
ObjHeader Header; /* Header of file */
unsigned long Start; /* Start offset of data in library */
unsigned Flags;
unsigned FileBaseId; /* Debug info base id for files */
unsigned SymBaseId; /* Debug info base id for symbols */
unsigned ScopeBaseId; /* Debug info base if for scopes */
Collection Files; /* List of input files */
Collection Sections; /* List of all sections */
Collection Exports; /* List of all exports */
@ -136,7 +141,7 @@ INLINE int ObjHasFiles (const ObjData* O)
struct Section* GetObjSection (ObjData* Obj, unsigned Id);
/* Get a section 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 */

View File

@ -100,7 +100,6 @@ void PrintDbgScopes (FILE* F)
unsigned I, J;
/* Print scopes from all modules we have linked into the output file */
unsigned BaseId = 0;
for (I = 0; I < CollCount (&ObjDataList); ++I) {
/* Get the object file */
@ -111,8 +110,8 @@ void PrintDbgScopes (FILE* F)
const Scope* S = CollConstAt (&O->Scopes, J);
fprintf (F,
"scope\tid=%u,name=\"%s\",module=%u,type=%u",
BaseId + S->Id,
"scope\tid=%u,name=\"%s\",mod=%u,type=%u",
O->ScopeBaseId + S->Id,
GetString (S->Name),
I,
S->Type);
@ -123,15 +122,12 @@ void PrintDbgScopes (FILE* F)
}
/* Print parent if available */
if (S->Id != S->ParentId) {
fprintf (F, ",parent=%u", BaseId + S->ParentId);
fprintf (F, ",parent=%u", O->ScopeBaseId + S->ParentId);
}
/* Terminate the output line */
fputc ('\n', F);
}
/* Increment scope base id */
BaseId += CollCount (&O->Scopes);
}
}

View File

@ -641,19 +641,19 @@ void PrintDbgSegments (FILE* F)
/* Print the segment data */
fprintf (F,
"segment\tid=%u,name=\"%s\",start=0x%06lX,size=0x%04lX,addrsize=%s,type=%s",
"seg\tid=%u,name=\"%s\",start=0x%06lX,size=0x%04lX,addrsize=%s,type=%s",
S->Id, GetString (S->Name), S->PC, S->Size,
AddrSizeToStr (S->AddrSize),
S->ReadOnly? "ro" : "rw");
if (S->OutputName) {
fprintf (F, ",outputname=\"%s\",outputoffs=%lu",
fprintf (F, ",oname=\"%s\",ooffs=%lu",
S->OutputName, S->OutputOffs);
}
fputc ('\n', F);
/* Follow the linked list */
S = S->List;
}
}
}