X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fld65%2Fobjdata.c;h=2a7a0ac1d9a9f1161c6fe246da4e2294193c68fc;hb=35e1184901ca38bdb2e56d154ed3b71f6096eacc;hp=9e3d5692c823e6656360508acff607e11bc8c5f5;hpb=af3a5e6e15d7a7cc7042727b9f34ad808fdd01bc;p=cc65 diff --git a/src/ld65/objdata.c b/src/ld65/objdata.c index 9e3d5692c..2a7a0ac1d 100644 --- a/src/ld65/objdata.c +++ b/src/ld65/objdata.c @@ -43,6 +43,7 @@ #include "error.h" #include "exports.h" #include "fileinfo.h" +#include "library.h" #include "objdata.h" #include "spool.h" @@ -78,19 +79,22 @@ ObjData* NewObjData (void) O->MTime = 0; O->Start = 0; O->Flags = 0; - O->FileBaseId = 0; + O->HLLSymBaseId = 0; O->SymBaseId = 0; O->ScopeBaseId = 0; + O->SpanBaseId = 0; O->Files = EmptyCollection; O->Sections = EmptyCollection; O->Exports = EmptyCollection; O->Imports = EmptyCollection; O->DbgSyms = EmptyCollection; + O->HLLDbgSyms = EmptyCollection; O->LineInfos = EmptyCollection; O->StringCount = 0; O->Strings = 0; O->Assertions = EmptyCollection; O->Scopes = EmptyCollection; + O->Spans = EmptyCollection; /* Return the new entry */ return O; @@ -106,6 +110,9 @@ void FreeObjData (ObjData* O) { unsigned I; + for (I = 0; I < CollCount (&O->Files); ++I) { + CollDeleteItem (&((FileInfo*) CollAtUnchecked (&O->Files, I))->Modules, O); + } DoneCollection (&O->Files); DoneCollection (&O->Sections); for (I = 0; I < CollCount (&O->Exports); ++I) { @@ -117,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)); @@ -125,6 +133,11 @@ void FreeObjData (ObjData* O) xfree (O->Strings); DoneCollection (&O->Assertions); DoneCollection (&O->Scopes); + for (I = 0; I < CollCount (&O->Spans); ++I) { + FreeSpan (CollAtUnchecked (&O->Spans, I)); + } + DoneCollection (&O->Spans); + xfree (O); } @@ -189,7 +202,15 @@ const char* GetObjFileName (const ObjData* O) -struct Section* GetObjSection (ObjData* O, unsigned Id) +const struct StrBuf* GetObjString (const ObjData* Obj, unsigned Id) +/* Get a string from an object file checking for an invalid index */ +{ + return GetStrBuf (MakeGlobalStringId (Obj, Id)); +} + + + +struct Section* GetObjSection (const ObjData* O, unsigned Id) /* Get a section from an object file checking for a valid index */ { if (Id >= CollCount (&O->Sections)) { @@ -201,7 +222,43 @@ struct Section* GetObjSection (ObjData* O, unsigned Id) -struct Scope* GetObjScope (ObjData* O, unsigned Id) +struct Import* GetObjImport (const 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 (const 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 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 */ { if (Id >= CollCount (&O->Scopes)) { @@ -213,3 +270,46 @@ struct Scope* GetObjScope (ObjData* O, unsigned Id) +unsigned ObjDataCount (void) +/* Return the total number of modules */ +{ + return CollCount (&ObjDataList); +} + + + +void PrintDbgModules (FILE* F) +/* Output the modules to a debug info file */ +{ + unsigned I; + + /* Output modules */ + for (I = 0; I < CollCount (&ObjDataList); ++I) { + + /* Get this object file */ + const ObjData* O = CollConstAt (&ObjDataList, I); + + /* The main source file is the one at index zero */ + const FileInfo* Source = CollConstAt (&O->Files, 0); + + /* Output the module line */ + fprintf (F, + "mod\tid=%u,name=\"%s\",file=%u", + I, + GetObjFileName (O), + Source->Id); + + /* Add library if any */ + if (O->Lib != 0) { + fprintf (F, ",lib=%u", GetLibId (O->Lib)); + } + + /* Terminate the output line */ + fputc ('\n', F); + } + +} + + + +