1
0
mirror of https://github.com/cc65/cc65.git synced 2025-01-21 00:31:53 +00:00

Adapted to new line infos and spans as written to the object file by the

assembler.


git-svn-id: svn://svn.cc65.org/cc65/trunk@5163 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2011-08-14 19:24:03 +00:00
parent b8549f0af8
commit 17e2276f38
13 changed files with 105 additions and 204 deletions

View File

@ -201,9 +201,6 @@ static void BinWriteMem (BinDesc* D, MemoryArea* M)
Addr = NewAddr;
}
/* Relocate line information for this segment */
RelocLineInfo (S->Seg);
} else if (S->Load == M) {
/* Handle ALIGN_LOAD */

View File

@ -68,6 +68,7 @@ static void AssignIds (void)
unsigned I;
unsigned SymBaseId = 0;
unsigned ScopeBaseId = 0;
unsigned SpanBaseId = 0;
for (I = 0; I < CollCount (&ObjDataList); ++I) {
/* Get this module */
@ -79,10 +80,12 @@ static void AssignIds (void)
/* Assign base ids */
O->SymBaseId = SymBaseId;
O->ScopeBaseId = ScopeBaseId;
O->SpanBaseId = SpanBaseId;
/* Bump the base ids */
SymBaseId += CollCount (&O->DbgSyms);
ScopeBaseId += CollCount (&O->Scopes);
SpanBaseId += CollCount (&O->Spans);
}
/* Assign the ids to the file infos */
@ -102,7 +105,7 @@ void CreateDbgFile (void)
/* Output version information */
fprintf (F, "version\tmajor=2,minor=0\n");
/* Output a line with the item numbers so the debug info module is able
* to preallocate the required memory.
*/

View File

@ -97,20 +97,3 @@ Fragment* NewFragment (unsigned char Type, unsigned Size, Section* S)
void FragResolveLineInfos (Fragment* F)
/* Resolve the back pointers for the line infos */
{
unsigned I;
/* Walk over all line infos for this fragment */
for (I = 0; I < CollCount (&F->LineInfos); ++I) {
/* Get a pointer to this line info */
LineInfo* LI = CollAtUnchecked (&F->LineInfos, I);
/* Add the back pointer to the line info */
CollAppend (&LI->Fragments, F);
}
}

View File

@ -87,9 +87,6 @@ struct Fragment {
Fragment* NewFragment (unsigned char Type, unsigned Size, struct Section* S);
/* Create a new fragment and insert it into the section S */
void FragResolveLineInfos (Fragment* F);
/* Resolve the back pointers for the line infos */
#if defined(HAVE_INLINE)
INLINE const char* GetFragmentSourceName (const Fragment* F)
/* Return the name of the source file for this fragment */

View File

@ -42,7 +42,6 @@
#include "error.h"
#include "fileinfo.h"
#include "fileio.h"
#include "fragment.h"
#include "lineinfo.h"
#include "objdata.h"
#include "segments.h"
@ -67,7 +66,6 @@ static LineInfo* NewLineInfo (void)
LI->Pos.Name = INVALID_STRING_ID;
LI->Pos.Line = 0;
LI->Pos.Col = 0;
LI->Fragments = EmptyCollection;
LI->Spans = EmptyCollection;
/* Return the new struct */
@ -77,20 +75,8 @@ static LineInfo* NewLineInfo (void)
void FreeLineInfo (LineInfo* LI)
/* Free a LineInfo structure. This function will not handle a non empty
* Fragments collection, it can only be used to free incomplete line infos.
*/
/* Free a LineInfo structure. */
{
unsigned I;
/* Check, check, ... */
PRECONDITION (CollCount (&LI->Fragments) == 0);
/* Free all the code ranges */
for (I = 0; I < CollCount (&LI->Spans); ++I) {
FreeSpan (CollAtUnchecked (&LI->Spans, I));
}
/* Free the collections */
DoneCollection (&LI->Spans);
@ -122,11 +108,12 @@ LineInfo* ReadLineInfo (FILE* F, ObjData* O)
LineInfo* LI = NewLineInfo ();
/* Read/fill the fields in the new LineInfo */
LI->Type = ReadVar (F);
LI->Pos.Line = ReadVar (F);
LI->Pos.Col = ReadVar (F);
LI->File = CollAt (&O->Files, ReadVar (F));
LI->Pos.Name = LI->File->Name;
LI->Type = ReadVar (F);
ReadSpans (&LI->Spans, F, O);
/* Return the struct read */
return LI;
@ -165,45 +152,6 @@ void ReadLineInfoList (FILE* F, ObjData* O, Collection* LineInfos)
void RelocLineInfo (Segment* S)
/* Relocate the line info for a segment. */
{
unsigned long Offs = S->PC;
/* Loop over all sections in this segment */
Section* Sec = S->SecRoot;
while (Sec) {
Fragment* Frag;
/* Adjust for fill bytes */
Offs += Sec->Fill;
/* Loop over all fragments in this section */
Frag = Sec->FragRoot;
while (Frag) {
unsigned I;
/* Add the range for this fragment to all line infos */
for (I = 0; I < CollCount (&Frag->LineInfos); ++I) {
LineInfo* LI = CollAtUnchecked (&Frag->LineInfos, I);
AddSpan (&LI->Spans, S, Offs, Frag->Size);
}
/* Update the offset */
Offs += Frag->Size;
/* Next fragment */
Frag = Frag->Next;
}
/* Next section */
Sec = Sec->Next;
}
}
void PrintDbgLineInfo (FILE* F)
/* Output the line infos to a debug info file */
{
@ -229,30 +177,33 @@ void PrintDbgLineInfo (FILE* F)
/* Get a pointer to the spans */
const Collection* Spans = &LI->Spans;
/* Spans */
for (K = 0; K < CollCount (Spans); ++K) {
/* Get this code range */
const Span* S = CollConstAt (Spans, K);
/* Print it */
fprintf (F,
"line\tid=%u,file=%u,line=%lu,seg=%u,range=0x%lX-0x%lX",
Id++, LI->File->Id, GetSourceLine (LI), S->Seg->Id,
S->Offs, S->Offs + S->Size - 1);
/* Print type if not LI_TYPE_ASM and count if not zero */
if (Type != LI_TYPE_ASM) {
fprintf (F, ",type=%u", Type);
}
if (Count != 0) {
fprintf (F, ",count=%u", Count);
}
/* Terminate line */
fputc ('\n', F);
/* Print the start of the line */
fprintf (F,
"line\tid=%u,file=%u,line=%lu",
Id++, LI->File->Id, GetSourceLine (LI));
/* Print type if not LI_TYPE_ASM and count if not zero */
if (Type != LI_TYPE_ASM) {
fprintf (F, ",type=%u", Type);
}
if (Count != 0) {
fprintf (F, ",count=%u", Count);
}
/* Add spans if the line info has it */
if (CollCount (Spans) > 0) {
/* Output the first span */
fprintf (F, ",span=%u", SpanId (O, CollConstAt (Spans, 0)));
/* Output the other spans */
for (K = 1; K < CollCount (Spans); ++K) {
fprintf (F, "+%u", SpanId (O, CollConstAt (Spans, K)));
}
}
/* Terminate line */
fputc ('\n', F);
}
}
}

View File

@ -76,7 +76,6 @@ struct LineInfo {
struct FileInfo* File; /* File struct for this line if any */
unsigned Type; /* Type of line info */
FilePos Pos; /* Position in file */
Collection Fragments; /* Fragments for this line */
Collection Spans; /* Spans for this line */
};
@ -95,18 +94,13 @@ LineInfo* ReadLineInfo (FILE* F, struct ObjData* O);
/* Read a line info from a file and return it */
void FreeLineInfo (LineInfo* LI);
/* Free a LineInfo structure. This function will not handle a non empty
* Fragments collection, it can only be used to free incomplete line infos.
*/
/* Free a LineInfo structure. */
void ReadLineInfoList (FILE* F, struct ObjData* O, Collection* LineInfos);
/* Read a list of line infos stored as a list of indices in the object file,
* make real line infos from them and place them into the passed collection.
*/
void RelocLineInfo (struct Segment* S);
/* Relocate the line info for a segment. */
#if defined(HAVE_INLINE)
INLINE const FilePos* GetSourcePos (const LineInfo* LI)
/* Return the source file position from the given line info */

View File

@ -779,9 +779,6 @@ static void O65WriteSeg (O65Desc* D, SegDesc** Seg, unsigned Count, int DoWrite)
/* Get the segment from the list node */
S = Seg [I];
/* Relocate line info for this segment */
RelocLineInfo (S->Seg);
/* Keep the user happy */
Print (stdout, 1, " Writing `%s'\n", GetString (S->Name));

View File

@ -81,6 +81,7 @@ ObjData* NewObjData (void)
O->Flags = 0;
O->SymBaseId = 0;
O->ScopeBaseId = 0;
O->SpanBaseId = 0;
O->Files = EmptyCollection;
O->Sections = EmptyCollection;
O->Exports = EmptyCollection;
@ -91,6 +92,7 @@ ObjData* NewObjData (void)
O->Strings = 0;
O->Assertions = EmptyCollection;
O->Scopes = EmptyCollection;
O->Spans = EmptyCollection;
/* Return the new entry */
return O;
@ -128,6 +130,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);
}

View File

@ -72,7 +72,8 @@ struct ObjData {
unsigned Flags;
unsigned SymBaseId; /* Debug info base id for symbols */
unsigned ScopeBaseId; /* Debug info base if for scopes */
unsigned ScopeBaseId; /* Debug info base id for scopes */
unsigned SpanBaseId; /* Debug info base id for spans */
Collection Files; /* List of input files */
Collection Sections; /* List of all sections */
@ -84,6 +85,7 @@ struct ObjData {
unsigned* Strings; /* List of global string indices */
Collection Assertions; /* List of module assertions */
Collection Scopes; /* List of scopes */
Collection Spans; /* List of spans */
};

View File

@ -166,11 +166,9 @@ void PrintDbgScopes (FILE* F)
}
/* Print the list of spans for this scope */
if (CollCount (&S->Spans) > 0) {
const Span* SP = CollConstAt (&S->Spans, 0);
fprintf (F, ",span=%u", SP->Id);
fprintf (F, ",span=%u", SpanId (O, CollConstAt (&S->Spans, 0)));
for (K = 1; K < CollCount (&S->Spans); ++K) {
SP = CollConstAt (&S->Spans, K);
fprintf (F, "+%u", SP->Id);
fprintf (F, "+%u", SpanId (O, CollConstAt (&S->Spans, K)));
}
}

View File

@ -278,9 +278,6 @@ Section* ReadSection (FILE* F, ObjData* O)
/* Read the line infos into the list of the fragment */
ReadLineInfoList (F, O, &Frag->LineInfos);
/* Resolve the back pointers */
FragResolveLineInfos (Frag);
/* Remember the module we had this fragment from */
Frag->Obj = O;
}

View File

@ -50,8 +50,13 @@
/* List of all spans */
static Collection SpanList = STATIC_COLLECTION_INITIALIZER;
/* Definition of a span */
struct Span {
unsigned Id; /* Id of the span */
unsigned Sec; /* Section id of this span */
unsigned long Offs; /* Offset of span within segment */
unsigned long Size; /* Size of span */
};
@ -61,21 +66,18 @@ static Collection SpanList = STATIC_COLLECTION_INITIALIZER;
Span* NewSpan (struct Segment* Seg, unsigned long Offs, unsigned long Size)
static Span* NewSpan (unsigned Id, unsigned SecId, unsigned long Offs, unsigned long Size)
/* Create and return a new span */
{
/* Allocate memory */
Span* S = xmalloc (sizeof (*S));
/* Initialize the fields */
S->Id = CollCount (&SpanList);
S->Seg = Seg;
S->Id = Id;
S->Sec = SecId;
S->Offs = Offs;
S->Size = Size;
/* Remember this span in the global list */
CollAppend (&SpanList, S);
/* Return the result */
return S;
}
@ -85,14 +87,17 @@ Span* NewSpan (struct Segment* Seg, unsigned long Offs, unsigned long Size)
Span* ReadSpan (FILE* F, ObjData* O)
/* Read a Span from a file and return it */
{
/* Read the section id and translate it to a section pointer */
Section* Sec = GetObjSection (O, ReadVar (F));
/* Create a new Span */
unsigned SecId = ReadVar (F);
unsigned long Offs = ReadVar (F);
unsigned Size = ReadVar (F);
Span* S = NewSpan (CollCount (&O->Spans), SecId, Offs, Size);
/* Read the offset and relocate it */
unsigned long Offs = ReadVar (F) + Sec->Offs;
/* Insert it into the collection of all spans of this object file */
CollAppend (&O->Spans, S);
/* Create and return a new Span */
return NewSpan (Sec->Seg, Offs, ReadVar (F));
/* And return it */
return S;
}
@ -123,55 +128,10 @@ void FreeSpan (Span* S)
void AddSpan (Collection* Spans, struct Segment* Seg, unsigned long Offs,
unsigned long Size)
/* Either add a new span to the ones already in the given collection, or - if
* possible - merge it with adjacent ones that already exist.
*/
unsigned SpanId (const struct ObjData* O, const Span* S)
/* Return the global id of a span */
{
unsigned I;
/* We don't have many spans in a collection, so we do a linear search here.
* The collection is kept sorted which eases our work here.
*/
for (I = 0; I < CollCount (Spans); ++I) {
/* Get the next span */
Span* S = CollAtUnchecked (Spans, I);
/* Must be same segment, otherwise we cannot merge */
if (S->Seg != Seg) {
continue;
}
/* Check if we can merge it */
if (Offs < S->Offs) {
/* Got the insert position */
if (Offs + Size == S->Offs) {
/* Merge the two */
S->Offs = Offs;
S->Size += Size;
} else {
/* Insert a new entry */
CollInsert (Spans, NewSpan (Seg, Offs, Size), I);
}
/* Done */
return;
} else if (S->Offs + S->Size == Offs) {
/* This is the regular case. Merge the two. */
S->Size += Size;
/* Done */
return;
}
}
/* We must append an entry */
CollAppend (Spans, NewSpan (Seg, Offs, Size));
return O->SpanBaseId + S->Id;
}
@ -179,7 +139,19 @@ void AddSpan (Collection* Spans, struct Segment* Seg, unsigned long Offs,
unsigned SpanCount (void)
/* Return the total number of spans */
{
return CollCount (&SpanList);
/* 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 spans */
Count += CollCount (&O->Spans);
}
return Count;
}
@ -187,16 +159,30 @@ unsigned SpanCount (void)
void PrintDbgSpans (FILE* F)
/* Output the spans to a debug info file */
{
/* Walk over all spans */
unsigned I;
for (I = 0; I < CollCount (&SpanList); ++I) {
unsigned I, J;
/* Get this span */
const Span* S = CollAtUnchecked (&SpanList, I);
/* Walk over all object files */
for (I = 0; I < CollCount (&ObjDataList); ++I) {
/* Output the data */
fprintf (F, "span\tid=%u,seg=%u,start=%lu,size=%lu\n",
S->Id, S->Seg->Id, S->Offs, S->Size);
/* Get this object file */
ObjData* O = CollAtUnchecked (&ObjDataList, I);
/* Walk over all spans in this object file */
for (J = 0; J < CollCount (&O->Spans); ++J) {
/* Get this span */
Span* S = CollAtUnchecked (&O->Spans, J);
/* Get the section for this span */
const Section* Sec = GetObjSection (O, S->Sec);
/* Output the data */
fprintf (F, "span\tid=%u,seg=%u,start=%lu,size=%lu\n",
O->SpanBaseId + S->Id,
Sec->Seg->Id,
Sec->Offs + S->Offs,
S->Size);
}
}
}

View File

@ -62,13 +62,8 @@ struct Segment;
/* Span is an opaque type */
typedef struct Span Span;
struct Span {
unsigned Id; /* Id of the span */
struct Segment* Seg; /* Segment of this span */
unsigned long Offs; /* Offset of span within segment */
unsigned long Size; /* Size of span */
};
@ -78,9 +73,6 @@ struct Span {
Span* NewSpan (struct Segment* Seg, unsigned long Offs, unsigned long Size);
/* Create and return a new span */
Span* ReadSpan (FILE* F, struct ObjData* O);
/* Read a Span from a file and return it */
@ -90,11 +82,8 @@ void ReadSpans (Collection* Spans, FILE* F, struct ObjData* O);
void FreeSpan (Span* S);
/* Free a span structure */
void AddSpan (Collection* Spans, struct Segment* Seg, unsigned long Offs,
unsigned long Size);
/* Either add a new span to the ones already in the given collection, or - if
* possible - merge it with adjacent ones that already exist.
*/
unsigned SpanId (const struct ObjData* O, const Span* S);
/* Return the global id of a span */
unsigned SpanCount (void);
/* Return the total number of spans */