From 14e567aed27cff392c353c6106fd67ec6bbef4ac Mon Sep 17 00:00:00 2001 From: uz Date: Sun, 8 Aug 2010 20:32:13 +0000 Subject: [PATCH] Another format change: Record the output file and offset for each segment written to the output. Make this information available in the debug info file. git-svn-id: svn://svn.cc65.org/cc65/trunk@4797 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/ld65/bin.c | 2 +- src/ld65/o65.c | 4 ++-- src/ld65/segments.c | 53 +++++++++++++++++++++++++-------------------- src/ld65/segments.h | 4 +++- 4 files changed, 35 insertions(+), 28 deletions(-) diff --git a/src/ld65/bin.c b/src/ld65/bin.c index df8991305..3c7c4a7a7 100644 --- a/src/ld65/bin.c +++ b/src/ld65/bin.c @@ -225,7 +225,7 @@ static void BinWriteMem (BinDesc* D, Memory* M) if (DoWrite) { unsigned long P = ftell (D->F); S->Seg->FillVal = M->FillVal; - SegWrite (D->F, S->Seg, BinWriteExpr, D); + SegWrite (D->Filename, D->F, S->Seg, BinWriteExpr, D); PrintNumVal ("Wrote", (unsigned long) (ftell (D->F) - P)); } else if (M->Flags & MF_FILL) { WriteMult (D->F, M->FillVal, S->Seg->Size); diff --git a/src/ld65/o65.c b/src/ld65/o65.c index 7dbcd8f9b..e583bb8c3 100644 --- a/src/ld65/o65.c +++ b/src/ld65/o65.c @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 1999-2009, Ullrich von Bassewitz */ +/* (C) 1999-2010, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -786,7 +786,7 @@ static void O65WriteSeg (O65Desc* D, SegDesc** Seg, unsigned Count, int DoWrite) /* Write this segment */ if (DoWrite) { - SegWrite (D->F, S->Seg, O65WriteExpr, D); + SegWrite (D->Filename, D->F, S->Seg, O65WriteExpr, D); } /* Mark the segment as dumped */ diff --git a/src/ld65/segments.c b/src/ld65/segments.c index 9d3627113..25959ff56 100644 --- a/src/ld65/segments.c +++ b/src/ld65/segments.c @@ -96,6 +96,8 @@ static Segment* NewSegment (unsigned Name, unsigned char AddrSize) S->PC = 0; S->Size = 0; S->AlignObj = 0; + S->OutputName = 0; + S->OutputOffs = 0; S->Align = 0; S->FillVal = 0; S->AddrSize = AddrSize; @@ -481,7 +483,7 @@ unsigned SegWriteConstExpr (FILE* F, ExprNode* E, int Signed, unsigned Size) -void SegWrite (FILE* Tgt, Segment* S, SegWriteFunc F, void* Data) +void SegWrite (const char* TgtName, FILE* Tgt, Segment* S, SegWriteFunc F, void* Data) /* Write the data from the given segment to a file. For expressions, F is * called (see description of SegWriteFunc above). */ @@ -489,18 +491,22 @@ void SegWrite (FILE* Tgt, Segment* S, SegWriteFunc F, void* Data) int Sign; unsigned long Offs = 0; + /* Remember the output file and offset for the segment */ + S->OutputName = TgtName; + S->OutputOffs = (unsigned long) ftell (Tgt); + /* Loop over all sections in this segment */ Section* Sec = S->SecRoot; while (Sec) { - Fragment* Frag; + Fragment* Frag; - /* If we have fill bytes, write them now */ - WriteMult (Tgt, S->FillVal, Sec->Fill); - Offs += Sec->Fill; + /* If we have fill bytes, write them now */ + WriteMult (Tgt, S->FillVal, Sec->Fill); + Offs += Sec->Fill; - /* Loop over all fragments in this section */ - Frag = Sec->FragRoot; - while (Frag) { + /* Loop over all fragments in this section */ + Frag = Sec->FragRoot; + while (Frag) { /* Do fragment alignment checks */ @@ -523,13 +529,13 @@ void SegWrite (FILE* Tgt, Segment* S, SegWriteFunc F, void* Data) break; case SEG_EXPR_RANGE_ERROR: - Error ("Range error in module `%s', line %lu", + Error ("Range error in module `%s', line %lu", GetFragmentSourceName (Frag), GetFragmentSourceLine (Frag)); break; case SEG_EXPR_TOO_COMPLEX: - Error ("Expression too complex in module `%s', line %lu", + Error ("Expression too complex in module `%s', line %lu", GetFragmentSourceName (Frag), GetFragmentSourceLine (Frag)); break; @@ -553,7 +559,7 @@ void SegWrite (FILE* Tgt, Segment* S, SegWriteFunc F, void* Data) Internal ("Invalid fragment type: %02X", Frag->Type); } - /* Update the offset */ + /* Update the offset */ Offs += Frag->Size; /* Next fragment */ @@ -651,22 +657,21 @@ void PrintSegmentMap (FILE* F) void PrintDbgSegments (FILE* F) /* Output the segments to the debug file */ { - Segment* S; - /* Walk over all segments */ - S = SegRoot; + Segment* S = SegRoot; while (S) { - /* Ignore empty segments */ - if (S->Size > 0) { - - /* Print the segment data */ - fprintf (F, - "segment\tid=%u,name=\"%s\",start=0x%06lX,size=0x%04lX,addrsize=%s,type=%s\n", - S->Id, GetString (S->Name), S->PC, S->Size, - AddrSizeToStr (S->AddrSize), - S->ReadOnly? "ro" : "rw"); - } + /* Print the segment data */ + fprintf (F, + "segment\tid=%u,name=\"%s\",start=0x%06lX,size=0x%04lX,addrsize=%s,type=%s", + S->Id, GetString (S->Name), S->PC, S->Size, + AddrSizeToStr (S->AddrSize), + S->ReadOnly? "ro" : "rw"); + if (S->OutputName) { + fprintf (F, ",outputname=\"%s\",outputoffs=%lu", + S->OutputName, S->OutputOffs); + } + fputc ('\n', F); /* Follow the linked list */ S = S->List; diff --git a/src/ld65/segments.h b/src/ld65/segments.h index 6e5f628ed..c61d7839e 100644 --- a/src/ld65/segments.h +++ b/src/ld65/segments.h @@ -63,6 +63,8 @@ struct Segment { unsigned long PC; /* PC were this segment is located */ unsigned long Size; /* Size of data so far */ struct ObjData* AlignObj; /* Module that requested the alignment */ + const char* OutputName; /* Name of output file or NULL */ + unsigned long OutputOffs; /* Offset in output file */ unsigned char Align; /* Alignment needed */ unsigned char FillVal; /* Value to use for fill bytes */ unsigned char AddrSize; /* Address size of segment */ @@ -139,7 +141,7 @@ unsigned SegWriteConstExpr (FILE* F, ExprNode* E, int Signed, unsigned Size); * check and return one of the SEG_EXPR_xxx codes. */ -void SegWrite (FILE* Tgt, Segment* S, SegWriteFunc F, void* Data); +void SegWrite (const char* TgtName, FILE* Tgt, Segment* S, SegWriteFunc F, void* Data); /* Write the data from the given segment to a file. For expressions, F is * called (see description of SegWriteFunc above). */ -- 2.39.5