/* Read the files list */
ObjReadFiles (L->F, O->Start + O->Header.FileOffs, O);
- /* Read the spans */
- ObjReadSpans (L->F, O->Start + O->Header.SpanOffs, O);
-
/* Read the line infos */
ObjReadLineInfos (L->F, O->Start + O->Header.LineInfoOffs, O);
*/
ObjReadScopes (L->F, O->Start + O->Header.ScopeOffs, O);
+ /* Read the spans */
+ ObjReadSpans (L->F, O->Start + O->Header.SpanOffs, O);
+
/* All references to strings are now resolved, so we can delete
* the module string pool.
*/
LI->Pos.Name = INVALID_STRING_ID;
LI->Pos.Line = 0;
LI->Pos.Col = 0;
- LI->Spans = EmptyCollection;
+ LI->Spans = 0;
/* Return the new struct */
return LI;
void FreeLineInfo (LineInfo* LI)
/* Free a LineInfo structure. */
{
- /* Free the collections */
- DoneCollection (&LI->Spans);
+ /* Free the span list */
+ xfree (LI->Spans);
/* Free the structure itself */
xfree (LI);
LI->File = CollAt (&O->Files, ReadVar (F));
LI->Pos.Name = LI->File->Name;
LI->Type = ReadVar (F);
- ReadSpanList (&LI->Spans, F, O);
+ LI->Spans = ReadSpanList (F);
/* Return the struct read */
return LI;
void PrintDbgLineInfo (FILE* F)
/* Output the line infos to a debug info file */
{
- unsigned I, J, K;
+ unsigned I, J;
/* Print line infos from all modules we have linked into the output file */
for (I = 0; I < CollCount (&ObjDataList); ++I) {
unsigned Type = LI_GET_TYPE (LI->Type);
unsigned Count = LI_GET_COUNT (LI->Type);
- /* Get a pointer to the spans */
- const Collection* Spans = &LI->Spans;
-
/* Print the start of the line */
fprintf (F,
"line\tid=%u,file=%u,line=%u",
}
/* 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)));
- }
- }
+ PrintDbgSpanList (F, O, LI->Spans);
/* Terminate line */
fputc ('\n', F);
struct FileInfo* File; /* File struct for this line if any */
unsigned Type; /* Type of line info */
FilePos Pos; /* Position in file */
- Collection Spans; /* Spans for this line */
+ unsigned* Spans; /* Spans for this line */
};
/* Read the files list from the object file */
ObjReadFiles (Obj, O->Header.FileOffs, O);
- /* Read the spans from the object file */
- ObjReadSpans (Obj, O->Header.SpanOffs, O);
-
/* Read the line infos from the object file */
ObjReadLineInfos (Obj, O->Header.LineInfoOffs, O);
*/
ObjReadScopes (Obj, O->Header.ScopeOffs, O);
+ /* Read the spans from the object file */
+ ObjReadSpans (Obj, O->Header.SpanOffs, O);
+
/* Mark this object file as needed */
O->Flags |= OBJ_REF;
S->Obj = Obj;
S->Size = 0;
S->LabelId = ~0U;
- S->Spans = EmptyCollection;
+ S->Spans = 0;
/* Return the new entry */
return S;
if (SCOPE_HAS_LABEL (S->Flags)) {
S->LabelId = ReadVar (F);
}
-
- /* Read the spans for this scope */
- ReadSpanList (&S->Spans, F, Obj);
+ S->Spans = ReadSpanList (F);
/* Return the new Scope */
return S;
void PrintDbgScopes (FILE* F)
/* Output the scopes to a debug info file */
{
- unsigned I, J, K;
+ unsigned I, J;
/* Print scopes from all modules we have linked into the output file */
for (I = 0; I < CollCount (&ObjDataList); ++I) {
for (J = 0; J < CollCount (&O->Scopes); ++J) {
const Scope* S = CollConstAt (&O->Scopes, J);
+ /* Output the first chunk of data */
fprintf (F,
"scope\tid=%u,name=\"%s\",mod=%u",
O->ScopeBaseId + S->Id,
fprintf (F, ",sym=%u", O->SymBaseId + S->LabelId);
}
/* Print the list of spans for this scope */
- if (CollCount (&S->Spans) > 0) {
- fprintf (F, ",span=%u", SpanId (O, CollConstAt (&S->Spans, 0)));
- for (K = 1; K < CollCount (&S->Spans); ++K) {
- fprintf (F, "+%u", SpanId (O, CollConstAt (&S->Spans, K)));
- }
- }
+ PrintDbgSpanList (F, O, S->Spans);
/* Terminate the output line */
fputc ('\n', F);
unsigned Type; /* Type of scope */
unsigned Name; /* Name of scope */
unsigned long Size; /* Size of scope */
- Collection Spans; /* Spans for this scope */
+ unsigned* Spans; /* Spans for this scope */
};
-void ReadSpanList (Collection* Spans, FILE* F, ObjData* O)
-/* Read a list of span ids from a file and return the spans for the ids */
+unsigned* ReadSpanList (FILE* F)
+/* Read a list of span ids from a file. The list is returned as an array of
+ * unsigneds, the first being the number of spans (never zero) followed by
+ * the span ids. If the number of spans is zero, NULL is returned.
+ */
{
+ unsigned* Spans;
+
/* First is number of Spans */
unsigned Count = ReadVar (F);
+ if (Count == 0) {
+ return 0;
+ }
- /* Preallocate enough entries in the collection */
- CollGrow (Spans, Count);
+ /* Allocate memory for the list and set the count */
+ Spans = xmalloc ((Count + 1) * sizeof (*Spans));
+ *Spans = Count;
/* Read the spans and add them */
- while (Count--) {
- CollAppend (Spans, CollAt (&O->Spans, ReadVar (F)));
+ while (Count) {
+ Spans[Count] = ReadVar (F);
+ --Count;
}
+
+ /* Return the list */
+ return Spans;
}
-unsigned SpanId (const struct ObjData* O, const Span* S)
-/* Return the global id of a span */
-{
- return O->SpanBaseId + S->Id;
-}
-
-
-
unsigned SpanCount (void)
/* Return the total number of spans */
{
+void PrintDbgSpanList (FILE* F, const ObjData* O, const unsigned* List)
+/* Output a string ",span=x[+y...]" for the given list. If the list is empty
+ * or NULL, output nothing. This is a helper function for other modules to
+ * print a list of spans read by ReadSpanList to the debug info file.
+ */
+{
+ if (List && *List) {
+ unsigned I;
+ const char* Format = ",span=%u";
+ for (I = 0; I < *List; ++I) {
+ fprintf (F, Format, O->SpanBaseId + List[I+1]);
+ Format = "+%u";
+ }
+ }
+}
+
+
+
void PrintDbgSpans (FILE* F)
/* Output the spans to a debug info file */
{
Span* ReadSpan (FILE* F, struct ObjData* O, unsigned Id);
/* Read a Span from a file and return it */
-void ReadSpanList (Collection* Spans, FILE* F, struct ObjData* O);
-/* Read a list of span ids from a file and return the spans for the ids */
+unsigned* ReadSpanList (FILE* F);
+/* Read a list of span ids from a file. The list is returned as an array of
+ * unsigneds, the first being the number of spans (never zero) followed by
+ * the span ids. If the number of spans is zero, NULL is returned.
+ */
void FreeSpan (Span* S);
/* Free a span structure */
-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 */
+void PrintDbgSpanList (FILE* F, const struct ObjData* O, const unsigned* List);
+/* Output a string ",span=x[+y...]" for the given list. If the list is empty
+ * or NULL, output nothing. This is a helper function for other modules to
+ * print a list of spans read by ReadSpanList to the debug info file.
+ */
+
void PrintDbgSpans (FILE* F);
/* Output the spans to a debug info file */