1
0
mirror of https://github.com/cc65/cc65.git synced 2024-11-18 15:05:14 +00:00

Output library information to the debug file.

git-svn-id: svn://svn.cc65.org/cc65/trunk@5127 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2011-08-07 11:33:28 +00:00
parent b418fdf985
commit af3a5e6e15
6 changed files with 110 additions and 23 deletions

View File

@ -43,6 +43,7 @@
#include "error.h"
#include "fileinfo.h"
#include "global.h"
#include "library.h"
#include "lineinfo.h"
#include "scopes.h"
#include "segments.h"
@ -104,7 +105,10 @@ void CreateDbgFile (void)
/* Assign the base ids to the modules */
AssignBaseIds ();
/* Output modules */
/* Output libraries */
PrintDbgLibraries (F);
/* Output modules */
for (I = 0; I < CollCount (&ObjDataList); ++I) {
/* Get this object file */
@ -121,11 +125,8 @@ void CreateDbgFile (void)
Source->Id);
/* Add library if any */
if (O->LibName != INVALID_STRING_ID) {
fprintf (F,
",lib=\"%s\",mtime=0x%08lX",
GetString (O->LibName),
O->MTime);
if (O->Lib != 0) {
fprintf (F, ",lib=%u", GetLibId (O->Lib));
}
/* Terminate the output line */

View File

@ -65,6 +65,7 @@
/* Library data structure */
typedef struct Library Library;
struct Library {
unsigned Id; /* Id of library */
unsigned Name; /* String id of the name */
FILE* F; /* Open file stream */
LibHeader Header; /* Library header */
@ -74,6 +75,9 @@ struct Library {
/* List of open libraries */
static Collection OpenLibs = STATIC_COLLECTION_INITIALIZER;
/* List of used libraries */
static Collection Libraries = STATIC_COLLECTION_INITIALIZER;
/* Flag for library grouping */
static int Grouping = 0;
@ -92,6 +96,7 @@ static Library* NewLibrary (FILE* F, const char* Name)
Library* L = xmalloc (sizeof (*L));
/* Initialize the fields */
L->Id = ~0U;
L->Name = GetStringId (Name);
L->F = F;
L->Modules = EmptyCollection;
@ -102,13 +107,23 @@ static Library* NewLibrary (FILE* F, const char* Name)
static void FreeLibrary (Library* L)
/* Free a library structure */
static void CloseLibrary (Library* L)
/* Close a library file and remove the list of modules */
{
/* Close the library file */
if (fclose (L->F) != 0) {
Error ("Error closing `%s': %s", GetString (L->Name), strerror (errno));
}
L->F = 0;
}
static void FreeLibrary (Library* L)
/* Free a library structure */
{
/* Close the library */
CloseLibrary (L);
/* Free the module index */
DoneCollection (&L->Modules);
@ -196,7 +211,7 @@ static ObjData* ReadIndexEntry (Library* L)
ObjData* O = NewObjData ();
/* Remember from which library this module is */
O->LibName = L->Name;
O->Lib = L;
/* Module name */
O->Name = ReadStr (L->F);
@ -365,7 +380,8 @@ static void LibResolve (void)
/* Walk over all modules in this library and add the files list and
* sections for all referenced modules.
*/
for (J = 0; J < CollCount (&L->Modules); ++J) {
J = 0;
while (J < CollCount (&L->Modules)) {
/* Get the object data */
ObjData* O = CollAtUnchecked (&L->Modules, J);
@ -398,16 +414,30 @@ static void LibResolve (void)
/* Insert the object into the list of all used object files */
InsertObjData (O);
/* Process next object file in library */
++J;
} else {
/* Unreferenced object file, remove it */
FreeObjData (O);
CollDelete (&L->Modules, J);
}
}
/* Close the file and delete the library data */
FreeLibrary (L);
/* If we have referenced modules in this library, assign it an id
* (which is the index in the library collection) and keep it.
*/
if (CollCount (&L->Modules) > 0) {
CloseLibrary (L);
L->Id = CollCount (&Libraries);
CollAppend (&Libraries, L);
} else {
/* Delete the library */
FreeLibrary (L);
CollDelete (&OpenLibs, I);
}
}
/* We're done with all open libraries, clear the OpenLibs collection */
@ -480,3 +510,37 @@ void LibCheckGroup (void)
const char* GetLibFileName (const Library* L)
/* Get the name of a library */
{
return GetString (L->Name);
}
unsigned GetLibId (const Library* L)
/* Get the id of a library file. */
{
return L->Id;
}
void PrintDbgLibraries (FILE* F)
/* Output the libraries to a debug info file */
{
unsigned I;
/* Output information about all libraries */
for (I = 0; I < CollCount (&Libraries); ++I) {
/* Get the library */
const Library* L = CollAtUnchecked (&Libraries, I);
/* Output the info */
fprintf (F, "library\tid=%u,name=\"%s\"\n", L->Id, GetString (L->Name));
}
}

View File

@ -6,10 +6,10 @@
/* */
/* */
/* */
/* (C) 1998-2005 Ullrich von Bassewitz */
/* Römerstraße 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* (C) 1998-2011, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
@ -39,7 +39,18 @@
/*****************************************************************************/
/* Code */
/* Data */
/*****************************************************************************/
/* Opaque structure */
struct Library;
/*****************************************************************************/
/* Code */
/*****************************************************************************/
@ -64,6 +75,15 @@ void LibEndGroup (void);
void LibCheckGroup (void);
/* Check if there are open library groups */
const char* GetLibFileName (const struct Library* L);
/* Get the name of a library */
unsigned GetLibId (const struct Library* L);
/* Get the id of a library file. */
void PrintDbgLibraries (FILE* F);
/* Output the libraries to a debug info file */
/* End of library.h */

View File

@ -43,6 +43,7 @@
#include "exports.h"
#include "global.h"
#include "error.h"
#include "library.h"
#include "mapfile.h"
#include "objdata.h"
#include "segments.h"
@ -80,9 +81,9 @@ void CreateMapFile (int ShortMap)
const ObjData* O = CollConstAt (&ObjDataList, I);
/* Output the data */
if (O->LibName != INVALID_STRING_ID) {
if (O->Lib) {
/* The file is from a library */
fprintf (F, "%s(%s):\n", GetString (O->LibName), GetObjFileName (O));
fprintf (F, "%s(%s):\n", GetLibFileName (O->Lib), GetObjFileName (O));
} else {
fprintf (F, "%s:\n", GetObjFileName (O));
}

View File

@ -74,7 +74,7 @@ ObjData* NewObjData (void)
/* Initialize the data */
O->Next = 0;
O->Name = INVALID_STRING_ID;
O->LibName = INVALID_STRING_ID;
O->Lib = 0;
O->MTime = 0;
O->Start = 0;
O->Flags = 0;

View File

@ -52,6 +52,7 @@
/* Forwards */
struct Library;
struct Scope;
struct Section;
@ -63,11 +64,11 @@ typedef struct ObjData ObjData;
struct ObjData {
ObjData* Next; /* Linked list of all objects */
unsigned Name; /* Module name */
unsigned LibName; /* Name of library */
struct Library* Lib; /* Library where module comes from */
unsigned long MTime; /* Time of last modification */
ObjHeader Header; /* Header of file */
ObjHeader Header; /* Header of file */
unsigned long Start; /* Start offset of data in library */
unsigned Flags;
unsigned Flags;
unsigned FileBaseId; /* Debug info base id for files */
unsigned SymBaseId; /* Debug info base id for symbols */