mirror of
https://github.com/cc65/cc65.git
synced 2025-08-10 04:25:21 +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:
@@ -201,9 +201,6 @@ static void BinWriteMem (BinDesc* D, MemoryArea* M)
|
|||||||
Addr = NewAddr;
|
Addr = NewAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Relocate line information for this segment */
|
|
||||||
RelocLineInfo (S->Seg);
|
|
||||||
|
|
||||||
} else if (S->Load == M) {
|
} else if (S->Load == M) {
|
||||||
|
|
||||||
/* Handle ALIGN_LOAD */
|
/* Handle ALIGN_LOAD */
|
||||||
|
@@ -68,6 +68,7 @@ static void AssignIds (void)
|
|||||||
unsigned I;
|
unsigned I;
|
||||||
unsigned SymBaseId = 0;
|
unsigned SymBaseId = 0;
|
||||||
unsigned ScopeBaseId = 0;
|
unsigned ScopeBaseId = 0;
|
||||||
|
unsigned SpanBaseId = 0;
|
||||||
for (I = 0; I < CollCount (&ObjDataList); ++I) {
|
for (I = 0; I < CollCount (&ObjDataList); ++I) {
|
||||||
|
|
||||||
/* Get this module */
|
/* Get this module */
|
||||||
@@ -79,10 +80,12 @@ static void AssignIds (void)
|
|||||||
/* Assign base ids */
|
/* Assign base ids */
|
||||||
O->SymBaseId = SymBaseId;
|
O->SymBaseId = SymBaseId;
|
||||||
O->ScopeBaseId = ScopeBaseId;
|
O->ScopeBaseId = ScopeBaseId;
|
||||||
|
O->SpanBaseId = SpanBaseId;
|
||||||
|
|
||||||
/* Bump the base ids */
|
/* Bump the base ids */
|
||||||
SymBaseId += CollCount (&O->DbgSyms);
|
SymBaseId += CollCount (&O->DbgSyms);
|
||||||
ScopeBaseId += CollCount (&O->Scopes);
|
ScopeBaseId += CollCount (&O->Scopes);
|
||||||
|
SpanBaseId += CollCount (&O->Spans);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Assign the ids to the file infos */
|
/* Assign the ids to the file infos */
|
||||||
@@ -102,7 +105,7 @@ void CreateDbgFile (void)
|
|||||||
|
|
||||||
/* Output version information */
|
/* Output version information */
|
||||||
fprintf (F, "version\tmajor=2,minor=0\n");
|
fprintf (F, "version\tmajor=2,minor=0\n");
|
||||||
|
|
||||||
/* Output a line with the item numbers so the debug info module is able
|
/* Output a line with the item numbers so the debug info module is able
|
||||||
* to preallocate the required memory.
|
* to preallocate the required memory.
|
||||||
*/
|
*/
|
||||||
|
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -87,9 +87,6 @@ struct Fragment {
|
|||||||
Fragment* NewFragment (unsigned char Type, unsigned Size, struct Section* S);
|
Fragment* NewFragment (unsigned char Type, unsigned Size, struct Section* S);
|
||||||
/* Create a new fragment and insert it into the 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)
|
#if defined(HAVE_INLINE)
|
||||||
INLINE const char* GetFragmentSourceName (const Fragment* F)
|
INLINE const char* GetFragmentSourceName (const Fragment* F)
|
||||||
/* Return the name of the source file for this fragment */
|
/* Return the name of the source file for this fragment */
|
||||||
|
@@ -42,7 +42,6 @@
|
|||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "fileinfo.h"
|
#include "fileinfo.h"
|
||||||
#include "fileio.h"
|
#include "fileio.h"
|
||||||
#include "fragment.h"
|
|
||||||
#include "lineinfo.h"
|
#include "lineinfo.h"
|
||||||
#include "objdata.h"
|
#include "objdata.h"
|
||||||
#include "segments.h"
|
#include "segments.h"
|
||||||
@@ -67,7 +66,6 @@ static LineInfo* NewLineInfo (void)
|
|||||||
LI->Pos.Name = INVALID_STRING_ID;
|
LI->Pos.Name = INVALID_STRING_ID;
|
||||||
LI->Pos.Line = 0;
|
LI->Pos.Line = 0;
|
||||||
LI->Pos.Col = 0;
|
LI->Pos.Col = 0;
|
||||||
LI->Fragments = EmptyCollection;
|
|
||||||
LI->Spans = EmptyCollection;
|
LI->Spans = EmptyCollection;
|
||||||
|
|
||||||
/* Return the new struct */
|
/* Return the new struct */
|
||||||
@@ -77,20 +75,8 @@ static LineInfo* NewLineInfo (void)
|
|||||||
|
|
||||||
|
|
||||||
void FreeLineInfo (LineInfo* LI)
|
void FreeLineInfo (LineInfo* LI)
|
||||||
/* Free a LineInfo structure. This function will not handle a non empty
|
/* Free a LineInfo structure. */
|
||||||
* Fragments collection, it can only be used to free incomplete line infos.
|
|
||||||
*/
|
|
||||||
{
|
{
|
||||||
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 */
|
/* Free the collections */
|
||||||
DoneCollection (&LI->Spans);
|
DoneCollection (&LI->Spans);
|
||||||
|
|
||||||
@@ -122,11 +108,12 @@ LineInfo* ReadLineInfo (FILE* F, ObjData* O)
|
|||||||
LineInfo* LI = NewLineInfo ();
|
LineInfo* LI = NewLineInfo ();
|
||||||
|
|
||||||
/* Read/fill the fields in the new LineInfo */
|
/* Read/fill the fields in the new LineInfo */
|
||||||
LI->Type = ReadVar (F);
|
|
||||||
LI->Pos.Line = ReadVar (F);
|
LI->Pos.Line = ReadVar (F);
|
||||||
LI->Pos.Col = ReadVar (F);
|
LI->Pos.Col = ReadVar (F);
|
||||||
LI->File = CollAt (&O->Files, ReadVar (F));
|
LI->File = CollAt (&O->Files, ReadVar (F));
|
||||||
LI->Pos.Name = LI->File->Name;
|
LI->Pos.Name = LI->File->Name;
|
||||||
|
LI->Type = ReadVar (F);
|
||||||
|
ReadSpans (&LI->Spans, F, O);
|
||||||
|
|
||||||
/* Return the struct read */
|
/* Return the struct read */
|
||||||
return LI;
|
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)
|
void PrintDbgLineInfo (FILE* F)
|
||||||
/* Output the line infos to a debug info file */
|
/* Output the line infos to a debug info file */
|
||||||
{
|
{
|
||||||
@@ -229,30 +177,33 @@ void PrintDbgLineInfo (FILE* F)
|
|||||||
/* Get a pointer to the spans */
|
/* Get a pointer to the spans */
|
||||||
const Collection* Spans = &LI->Spans;
|
const Collection* Spans = &LI->Spans;
|
||||||
|
|
||||||
/* Spans */
|
/* Print the start of the line */
|
||||||
for (K = 0; K < CollCount (Spans); ++K) {
|
fprintf (F,
|
||||||
|
"line\tid=%u,file=%u,line=%lu",
|
||||||
/* Get this code range */
|
Id++, LI->File->Id, GetSourceLine (LI));
|
||||||
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 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -76,7 +76,6 @@ struct LineInfo {
|
|||||||
struct FileInfo* File; /* File struct for this line if any */
|
struct FileInfo* File; /* File struct for this line if any */
|
||||||
unsigned Type; /* Type of line info */
|
unsigned Type; /* Type of line info */
|
||||||
FilePos Pos; /* Position in file */
|
FilePos Pos; /* Position in file */
|
||||||
Collection Fragments; /* Fragments for this line */
|
|
||||||
Collection Spans; /* Spans 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 */
|
/* Read a line info from a file and return it */
|
||||||
|
|
||||||
void FreeLineInfo (LineInfo* LI);
|
void FreeLineInfo (LineInfo* LI);
|
||||||
/* Free a LineInfo structure. This function will not handle a non empty
|
/* Free a LineInfo structure. */
|
||||||
* Fragments collection, it can only be used to free incomplete line infos.
|
|
||||||
*/
|
|
||||||
|
|
||||||
void ReadLineInfoList (FILE* F, struct ObjData* O, Collection* LineInfos);
|
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,
|
/* 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.
|
* 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)
|
#if defined(HAVE_INLINE)
|
||||||
INLINE const FilePos* GetSourcePos (const LineInfo* LI)
|
INLINE const FilePos* GetSourcePos (const LineInfo* LI)
|
||||||
/* Return the source file position from the given line info */
|
/* Return the source file position from the given line info */
|
||||||
|
@@ -779,9 +779,6 @@ static void O65WriteSeg (O65Desc* D, SegDesc** Seg, unsigned Count, int DoWrite)
|
|||||||
/* Get the segment from the list node */
|
/* Get the segment from the list node */
|
||||||
S = Seg [I];
|
S = Seg [I];
|
||||||
|
|
||||||
/* Relocate line info for this segment */
|
|
||||||
RelocLineInfo (S->Seg);
|
|
||||||
|
|
||||||
/* Keep the user happy */
|
/* Keep the user happy */
|
||||||
Print (stdout, 1, " Writing `%s'\n", GetString (S->Name));
|
Print (stdout, 1, " Writing `%s'\n", GetString (S->Name));
|
||||||
|
|
||||||
|
@@ -81,6 +81,7 @@ ObjData* NewObjData (void)
|
|||||||
O->Flags = 0;
|
O->Flags = 0;
|
||||||
O->SymBaseId = 0;
|
O->SymBaseId = 0;
|
||||||
O->ScopeBaseId = 0;
|
O->ScopeBaseId = 0;
|
||||||
|
O->SpanBaseId = 0;
|
||||||
O->Files = EmptyCollection;
|
O->Files = EmptyCollection;
|
||||||
O->Sections = EmptyCollection;
|
O->Sections = EmptyCollection;
|
||||||
O->Exports = EmptyCollection;
|
O->Exports = EmptyCollection;
|
||||||
@@ -91,6 +92,7 @@ ObjData* NewObjData (void)
|
|||||||
O->Strings = 0;
|
O->Strings = 0;
|
||||||
O->Assertions = EmptyCollection;
|
O->Assertions = EmptyCollection;
|
||||||
O->Scopes = EmptyCollection;
|
O->Scopes = EmptyCollection;
|
||||||
|
O->Spans = EmptyCollection;
|
||||||
|
|
||||||
/* Return the new entry */
|
/* Return the new entry */
|
||||||
return O;
|
return O;
|
||||||
@@ -128,6 +130,11 @@ void FreeObjData (ObjData* O)
|
|||||||
xfree (O->Strings);
|
xfree (O->Strings);
|
||||||
DoneCollection (&O->Assertions);
|
DoneCollection (&O->Assertions);
|
||||||
DoneCollection (&O->Scopes);
|
DoneCollection (&O->Scopes);
|
||||||
|
for (I = 0; I < CollCount (&O->Spans); ++I) {
|
||||||
|
FreeSpan (CollAtUnchecked (&O->Spans, I));
|
||||||
|
}
|
||||||
|
DoneCollection (&O->Spans);
|
||||||
|
|
||||||
xfree (O);
|
xfree (O);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -72,7 +72,8 @@ struct ObjData {
|
|||||||
unsigned Flags;
|
unsigned Flags;
|
||||||
|
|
||||||
unsigned SymBaseId; /* Debug info base id for symbols */
|
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 Files; /* List of input files */
|
||||||
Collection Sections; /* List of all sections */
|
Collection Sections; /* List of all sections */
|
||||||
@@ -84,6 +85,7 @@ struct ObjData {
|
|||||||
unsigned* Strings; /* List of global string indices */
|
unsigned* Strings; /* List of global string indices */
|
||||||
Collection Assertions; /* List of module assertions */
|
Collection Assertions; /* List of module assertions */
|
||||||
Collection Scopes; /* List of scopes */
|
Collection Scopes; /* List of scopes */
|
||||||
|
Collection Spans; /* List of spans */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -166,11 +166,9 @@ void PrintDbgScopes (FILE* F)
|
|||||||
}
|
}
|
||||||
/* Print the list of spans for this scope */
|
/* Print the list of spans for this scope */
|
||||||
if (CollCount (&S->Spans) > 0) {
|
if (CollCount (&S->Spans) > 0) {
|
||||||
const Span* SP = CollConstAt (&S->Spans, 0);
|
fprintf (F, ",span=%u", SpanId (O, CollConstAt (&S->Spans, 0)));
|
||||||
fprintf (F, ",span=%u", SP->Id);
|
|
||||||
for (K = 1; K < CollCount (&S->Spans); ++K) {
|
for (K = 1; K < CollCount (&S->Spans); ++K) {
|
||||||
SP = CollConstAt (&S->Spans, K);
|
fprintf (F, "+%u", SpanId (O, CollConstAt (&S->Spans, K)));
|
||||||
fprintf (F, "+%u", SP->Id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -278,9 +278,6 @@ Section* ReadSection (FILE* F, ObjData* O)
|
|||||||
/* Read the line infos into the list of the fragment */
|
/* Read the line infos into the list of the fragment */
|
||||||
ReadLineInfoList (F, O, &Frag->LineInfos);
|
ReadLineInfoList (F, O, &Frag->LineInfos);
|
||||||
|
|
||||||
/* Resolve the back pointers */
|
|
||||||
FragResolveLineInfos (Frag);
|
|
||||||
|
|
||||||
/* Remember the module we had this fragment from */
|
/* Remember the module we had this fragment from */
|
||||||
Frag->Obj = O;
|
Frag->Obj = O;
|
||||||
}
|
}
|
||||||
|
128
src/ld65/span.c
128
src/ld65/span.c
@@ -50,8 +50,13 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* List of all spans */
|
/* Definition of a span */
|
||||||
static Collection SpanList = STATIC_COLLECTION_INITIALIZER;
|
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 */
|
/* Create and return a new span */
|
||||||
{
|
{
|
||||||
/* Allocate memory */
|
/* Allocate memory */
|
||||||
Span* S = xmalloc (sizeof (*S));
|
Span* S = xmalloc (sizeof (*S));
|
||||||
|
|
||||||
/* Initialize the fields */
|
/* Initialize the fields */
|
||||||
S->Id = CollCount (&SpanList);
|
S->Id = Id;
|
||||||
S->Seg = Seg;
|
S->Sec = SecId;
|
||||||
S->Offs = Offs;
|
S->Offs = Offs;
|
||||||
S->Size = Size;
|
S->Size = Size;
|
||||||
|
|
||||||
/* Remember this span in the global list */
|
|
||||||
CollAppend (&SpanList, S);
|
|
||||||
|
|
||||||
/* Return the result */
|
/* Return the result */
|
||||||
return S;
|
return S;
|
||||||
}
|
}
|
||||||
@@ -85,14 +87,17 @@ Span* NewSpan (struct Segment* Seg, unsigned long Offs, unsigned long Size)
|
|||||||
Span* ReadSpan (FILE* F, ObjData* O)
|
Span* ReadSpan (FILE* F, ObjData* O)
|
||||||
/* Read a Span from a file and return it */
|
/* Read a Span from a file and return it */
|
||||||
{
|
{
|
||||||
/* Read the section id and translate it to a section pointer */
|
/* Create a new Span */
|
||||||
Section* Sec = GetObjSection (O, ReadVar (F));
|
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 */
|
/* Insert it into the collection of all spans of this object file */
|
||||||
unsigned long Offs = ReadVar (F) + Sec->Offs;
|
CollAppend (&O->Spans, S);
|
||||||
|
|
||||||
/* Create and return a new Span */
|
/* And return it */
|
||||||
return NewSpan (Sec->Seg, Offs, ReadVar (F));
|
return S;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -123,55 +128,10 @@ void FreeSpan (Span* S)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void AddSpan (Collection* Spans, struct Segment* Seg, unsigned long Offs,
|
unsigned SpanId (const struct ObjData* O, const Span* S)
|
||||||
unsigned long Size)
|
/* Return the global id of a span */
|
||||||
/* 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 I;
|
return O->SpanBaseId + S->Id;
|
||||||
|
|
||||||
/* 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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -179,7 +139,19 @@ void AddSpan (Collection* Spans, struct Segment* Seg, unsigned long Offs,
|
|||||||
unsigned SpanCount (void)
|
unsigned SpanCount (void)
|
||||||
/* Return the total number of spans */
|
/* 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)
|
void PrintDbgSpans (FILE* F)
|
||||||
/* Output the spans to a debug info file */
|
/* Output the spans to a debug info file */
|
||||||
{
|
{
|
||||||
/* Walk over all spans */
|
unsigned I, J;
|
||||||
unsigned I;
|
|
||||||
for (I = 0; I < CollCount (&SpanList); ++I) {
|
|
||||||
|
|
||||||
/* Get this span */
|
/* Walk over all object files */
|
||||||
const Span* S = CollAtUnchecked (&SpanList, I);
|
for (I = 0; I < CollCount (&ObjDataList); ++I) {
|
||||||
|
|
||||||
/* Output the data */
|
/* Get this object file */
|
||||||
fprintf (F, "span\tid=%u,seg=%u,start=%lu,size=%lu\n",
|
ObjData* O = CollAtUnchecked (&ObjDataList, I);
|
||||||
S->Id, S->Seg->Id, S->Offs, S->Size);
|
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -62,13 +62,8 @@ struct Segment;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Span is an opaque type */
|
||||||
typedef struct Span Span;
|
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);
|
Span* ReadSpan (FILE* F, struct ObjData* O);
|
||||||
/* Read a Span from a file and return it */
|
/* 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);
|
void FreeSpan (Span* S);
|
||||||
/* Free a span structure */
|
/* Free a span structure */
|
||||||
|
|
||||||
void AddSpan (Collection* Spans, struct Segment* Seg, unsigned long Offs,
|
unsigned SpanId (const struct ObjData* O, const Span* S);
|
||||||
unsigned long Size);
|
/* Return the global id of a span */
|
||||||
/* 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 SpanCount (void);
|
unsigned SpanCount (void);
|
||||||
/* Return the total number of spans */
|
/* Return the total number of spans */
|
||||||
|
Reference in New Issue
Block a user