More work on high level language debug symbols. They are now passed correctly

via the object files to the linker and written to the debug info file.


git-svn-id: svn://svn.cc65.org/cc65/trunk@5285 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz
2011-08-30 11:42:26 +00:00
parent 2f82cb4fb8
commit aaa21c6417
16 changed files with 339 additions and 45 deletions

View File

@@ -67,9 +67,10 @@ static void AssignIds (void)
{
/* Walk over all modules */
unsigned I;
unsigned ScopeBaseId = 0;
unsigned SpanBaseId = 0;
unsigned SymBaseId = 0;
unsigned HLLSymBaseId = 0;
unsigned ScopeBaseId = 0;
unsigned SpanBaseId = 0;
unsigned SymBaseId = 0;
for (I = 0; I < CollCount (&ObjDataList); ++I) {
/* Get this module */
@@ -79,11 +80,13 @@ static void AssignIds (void)
O->Id = I;
/* Assign base ids */
O->ScopeBaseId = ScopeBaseId;
O->SpanBaseId = SpanBaseId;
O->SymBaseId = SymBaseId;
O->HLLSymBaseId = HLLSymBaseId;
O->ScopeBaseId = ScopeBaseId;
O->SpanBaseId = SpanBaseId;
O->SymBaseId = SymBaseId;
/* Bump the base ids */
HLLSymBaseId += CollCount (&O->HLLDbgSyms);
ScopeBaseId += CollCount (&O->Scopes);
SpanBaseId += CollCount (&O->Spans);
SymBaseId += CollCount (&O->DbgSyms);
@@ -115,7 +118,8 @@ void CreateDbgFile (void)
*/
fprintf (
F,
"info\tfile=%u,lib=%u,line=%u,mod=%u,scope=%u,seg=%u,span=%u,type=%u\n",
"info\tcsym=%u,file=%u,lib=%u,line=%u,mod=%u,scope=%u,seg=%u,span=%u,sym=%u,type=%u\n",
HLLDbgSymCount (),
FileInfoCount (),
LibraryCount (),
LineInfoCount (),
@@ -123,12 +127,16 @@ void CreateDbgFile (void)
ScopeCount (),
SegmentCount (),
SpanCount (),
DbgSymCount (),
TypeCount ()
);
/* Assign the ids to the items */
AssignIds ();
/* Output high level language symbols */
PrintHLLDbgSyms (F);
/* Output files */
PrintDbgFileInfo (F);

View File

@@ -37,7 +37,9 @@
/* common */
#include "addrsize.h"
#include "attrib.h"
#include "check.h"
#include "hlldbgsym.h"
#include "symdefs.h"
#include "xmalloc.h"
@@ -51,6 +53,7 @@
#include "lineinfo.h"
#include "objdata.h"
#include "spool.h"
#include "tpool.h"
@@ -76,8 +79,19 @@ struct DbgSym {
unsigned short AddrSize; /* Address size of symbol */
};
/* Structure used for a high level language function or symbol */
typedef struct HLLDbgSym HLLDbgSym;
struct HLLDbgSym {
unsigned Flags; /* See above */
unsigned Name; /* String id of name */
DbgSym* Sym; /* Assembler symbol */
int Offs; /* Offset if any */
unsigned Type; /* String id of type */
unsigned ScopeId; /* Parent scope */
};
/* We will collect all debug symbols in the following array and remove
* duplicates before outputing them.
* duplicates before outputing them into a label file.
*/
static DbgSym* DbgSymPool[256];
@@ -116,6 +130,15 @@ static DbgSym* NewDbgSym (unsigned Id, unsigned Type, unsigned char AddrSize,
static HLLDbgSym* NewHLLDbgSym (void)
/* Create a new HLLDbgSym and return it */
{
/* Allocate memory and return it */
return xmalloc (sizeof (HLLDbgSym));
}
static DbgSym* GetDbgSym (DbgSym* D, long Val)
/* Check if we find the same debug symbol in the table. If we find it, return
* a pointer to the other occurrence, if we didn't find it, return NULL.
@@ -213,6 +236,38 @@ DbgSym* ReadDbgSym (FILE* F, ObjData* O, unsigned Id)
HLLDbgSym* ReadHLLDbgSym (FILE* F, ObjData* O, unsigned Id attribute ((unused)))
/* Read a hll debug symbol from a file, insert and return it */
{
unsigned SC;
/* Create a new HLLDbgSym */
HLLDbgSym* S = NewHLLDbgSym ();
/* Read the data */
S->Flags = ReadVar (F);
SC = HLL_GET_SC (S->Flags);
S->Name = MakeGlobalStringId (O, ReadVar (F));
if (SC != HLL_SC_AUTO) {
S->Sym = GetObjDbgSym (O, ReadVar (F));
} else {
/* Auto variables aren't attached to asm symbols */
S->Sym = 0;
}
if (SC == HLL_SC_AUTO || SC == HLL_SC_REG) {
S->Offs = ReadVar (F);
} else {
S->Offs = 0;
}
S->Type = GetTypeId (GetObjString (O, ReadVar (F)));
S->ScopeId = ReadVar (F);
/* Return the (now initialized) hll debug symbol */
return S;
}
static void ClearDbgSymTable (void)
/* Clear the debug symbol table */
{
@@ -255,6 +310,44 @@ static void PrintLineInfo (FILE* F, const Collection* LineInfos, const char* For
unsigned DbgSymCount (void)
/* Return the total number of debug symbols */
{
/* Walk over all object files */
unsigned I;
unsigned Count = 0;
for (I = 0; I < CollCount (&ObjDataList); ++I) {
/* Get this object file */
const ObjData* O = CollAtUnchecked (&ObjDataList, I);
/* Count debug symbols */
Count += CollCount (&O->DbgSyms);
}
return Count;
}
unsigned HLLDbgSymCount (void)
/* Return the total number of high level language debug symbols */
{
/* Walk over all object files */
unsigned I;
unsigned Count = 0;
for (I = 0; I < CollCount (&ObjDataList); ++I) {
/* Get this object file */
const ObjData* O = CollAtUnchecked (&ObjDataList, I);
/* Count debug symbols */
Count += CollCount (&O->HLLDbgSyms);
}
return Count;
}
void PrintDbgSyms (FILE* F)
/* Print the debug symbols in a debug file */
{
@@ -349,6 +442,59 @@ void PrintDbgSyms (FILE* F)
void PrintHLLDbgSyms (FILE* F)
/* Print the high level language debug symbols in a debug file */
{
unsigned I, J;
for (I = 0; I < CollCount (&ObjDataList); ++I) {
/* Get the object file */
ObjData* O = CollAtUnchecked (&ObjDataList, I);
/* Walk through all hll debug symbols in this module */
for (J = 0; J < CollCount (&O->HLLDbgSyms); ++J) {
/* Get the next debug symbol */
const HLLDbgSym* S = CollConstAt (&O->HLLDbgSyms, J);
/* Get the storage class */
unsigned SC = HLL_GET_SC (S->Flags);
/* Output the base info */
fprintf (F, "csym\tid=%u,name=\"%s\",scope=%u,type=%u,sc=",
O->HLLSymBaseId + J,
GetString (S->Name),
O->ScopeBaseId + S->ScopeId,
S->Type);
switch (SC) {
case HLL_SC_AUTO: fputs ("auto", F); break;
case HLL_SC_REG: fputs ("reg", F); break;
case HLL_SC_STATIC: fputs ("static", F); break;
case HLL_SC_EXTERN: fputs ("extern", F); break;
default:
Error ("Invalid storage class %u for hll symbol", SC);
break;
}
/* Output the offset if it is not zero */
if (S->Offs) {
fprintf (F, ",offs=%d", S->Offs);
}
/* For non auto symbols output the debug symbol id of the asm sym */
if (SC != HLL_SC_AUTO) {
fprintf (F, ",sym=%u", S->Sym->Id);
}
/* Terminate the output line */
fputc ('\n', F);
}
}
}
void PrintDbgSymLabels (FILE* F)
/* Print the debug symbols in a VICE label file */
{

View File

@@ -57,6 +57,7 @@
/* Forwards */
struct Scope;
struct HLLDbgSym;
/* Opaque debug symbol structure */
typedef struct DbgSym DbgSym;
@@ -72,9 +73,21 @@ typedef struct DbgSym DbgSym;
DbgSym* ReadDbgSym (FILE* F, ObjData* Obj, unsigned Id);
/* Read a debug symbol from a file, insert and return it */
struct HLLDbgSym* ReadHLLDbgSym (FILE* F, ObjData* Obj, unsigned Id);
/* Read a hll debug symbol from a file, insert and return it */
void PrintDbgSyms (FILE* F);
/* Print the debug symbols in a debug file */
unsigned DbgSymCount (void);
/* Return the total number of debug symbols */
unsigned HLLDbgSymCount (void);
/* Return the total number of high level language debug symbols */
void PrintHLLDbgSyms (FILE* F);
/* Print the high level language debug symbols in a debug file */
void PrintDbgSymLabels (FILE* F);
/* Print the debug symbols in a VICE label file */

View File

@@ -79,6 +79,7 @@ ObjData* NewObjData (void)
O->MTime = 0;
O->Start = 0;
O->Flags = 0;
O->HLLSymBaseId = 0;
O->SymBaseId = 0;
O->ScopeBaseId = 0;
O->SpanBaseId = 0;
@@ -87,6 +88,7 @@ ObjData* NewObjData (void)
O->Exports = EmptyCollection;
O->Imports = EmptyCollection;
O->DbgSyms = EmptyCollection;
O->HLLDbgSyms = EmptyCollection;
O->LineInfos = EmptyCollection;
O->StringCount = 0;
O->Strings = 0;
@@ -122,6 +124,7 @@ void FreeObjData (ObjData* O)
}
DoneCollection (&O->Imports);
DoneCollection (&O->DbgSyms);
DoneCollection (&O->HLLDbgSyms);
for (I = 0; I < CollCount (&O->LineInfos); ++I) {
FreeLineInfo (CollAtUnchecked (&O->LineInfos, I));
@@ -243,6 +246,18 @@ struct Export* GetObjExport (const ObjData* O, unsigned Id)
struct DbgSym* GetObjDbgSym (const ObjData* O, unsigned Id)
/* Get a debug symbol from an object file checking for a valid index */
{
if (Id >= CollCount (&O->DbgSyms)) {
Error ("Invalid debug symbol index (%u) in module `%s'",
Id, GetObjFileName (O));
}
return CollAtUnchecked (&O->DbgSyms, Id);
}
struct Scope* GetObjScope (const ObjData* O, unsigned Id)
/* Get a scope from an object file checking for a valid index */
{
@@ -297,3 +312,4 @@ void PrintDbgModules (FILE* F)

View File

@@ -74,6 +74,7 @@ struct ObjData {
unsigned long Start; /* Start offset of data in library */
unsigned Flags;
unsigned HLLSymBaseId; /* Debug info base id for hll symbols */
unsigned SymBaseId; /* Debug info base id for symbols */
unsigned ScopeBaseId; /* Debug info base id for scopes */
unsigned SpanBaseId; /* Debug info base id for spans */
@@ -83,6 +84,7 @@ struct ObjData {
Collection Exports; /* List of all exports */
Collection Imports; /* List of all imports */
Collection DbgSyms; /* List of debug symbols */
Collection HLLDbgSyms; /* List of hll debug symbols */
Collection LineInfos; /* List of line infos */
unsigned StringCount; /* Count of strings */
unsigned* Strings; /* List of global string indices */
@@ -156,6 +158,9 @@ struct Import* GetObjImport (const ObjData* Obj, unsigned Id);
struct Export* GetObjExport (const ObjData* Obj, unsigned Id);
/* Get an export from an object file checking for a valid index */
struct DbgSym* GetObjDbgSym (const ObjData* Obj, unsigned Id);
/* Get a debug symbol from an object file checking for a valid index */
struct Scope* GetObjScope (const ObjData* Obj, unsigned Id);
/* Get a scope from an object file checking for a valid index */

View File

@@ -198,11 +198,18 @@ void ObjReadDbgSyms (FILE* F, unsigned long Pos, ObjData* O)
/* Seek to the correct position */
FileSetPos (F, Pos);
/* Read the data */
/* Read the asm debug symbols */
DbgSymCount = ReadVar (F);
CollGrow (&O->DbgSyms, DbgSymCount);
for (I = 0; I < DbgSymCount; ++I) {
CollAppend (&O->DbgSyms, ReadDbgSym (F, O, I));
CollAppend (&O->DbgSyms, ReadDbgSym (F, O, I));
}
/* Read the hll debug symbols */
DbgSymCount = ReadVar (F);
CollGrow (&O->HLLDbgSyms, DbgSymCount);
for (I = 0; I < DbgSymCount; ++I) {
CollAppend (&O->HLLDbgSyms, ReadHLLDbgSym (F, O, I));
}
}