]> git.sur5r.net Git - cc65/commitdiff
Added line infos
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Wed, 23 May 2001 19:03:40 +0000 (19:03 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Wed, 23 May 2001 19:03:40 +0000 (19:03 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@748 b7a2c559-68d2-44c3-8de9-860c34a00d81

26 files changed:
src/ar65/objfile.c
src/ca65/dbginfo.c
src/ca65/lineinfo.c
src/ca65/lineinfo.h
src/ca65/main.c
src/ca65/objcode.c
src/ca65/objfile.c
src/ca65/pseudo.c
src/cc65/codeseg.c
src/common/libdefs.h
src/common/objdefs.h
src/ld65/fragment.c
src/ld65/fragment.h
src/ld65/lineinfo.c [new file with mode: 0644]
src/ld65/lineinfo.h [new file with mode: 0644]
src/ld65/make/gcc.mak
src/ld65/objdata.c
src/ld65/objdata.h
src/ld65/objfile.c
src/ld65/segments.c
src/ld65/segments.h
src/od65/dump.c
src/od65/dump.h
src/od65/fileio.c
src/od65/global.h
src/od65/main.c

index 6fb40f9af7082e6becaeae85fa828d458a5dad5f..28d13320127bbd66b1a3c97fd637e9483a73e5f0 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                          */
 /*                                                                          */
 /*                                                                          */
-/* (C) 1998    Ullrich von Bassewitz                                        */
-/*             Wacholderweg 14                                              */
-/*             D-70597 Stuttgart                                            */
-/* EMail:      uz@musoftware.de                                             */
+/* (C) 1998-2001 Ullrich von Bassewitz                                      */
+/*              Wacholderweg 14                                             */
+/*              D-70597 Stuttgart                                           */
+/* EMail:       uz@cc65.org                                                 */
 /*                                                                          */
 /*                                                                          */
 /* This software is provided 'as-is', without any expressed or implied      */
@@ -47,7 +47,7 @@
 
 /* common */
 #include "xmalloc.h"
-
+                                       
 /* ar65 */
 #include "error.h"
 #include "objdata.h"
@@ -94,19 +94,21 @@ void ObjReadHeader (FILE* Obj, ObjHeader* H, const char* Name)
     if (H->Version != OBJ_VERSION) {
        Error ("Object file `%s' has wrong version", Name);
     }
-    H->Flags     = Read16 (Obj);
-    H->OptionOffs = Read32 (Obj);
-    H->OptionSize = Read32 (Obj);
-    H->FileOffs   = Read32 (Obj);
-    H->FileSize   = Read32 (Obj);
-    H->SegOffs   = Read32 (Obj);
-    H->SegSize   = Read32 (Obj);
-    H->ImportOffs = Read32 (Obj);
-    H->ImportSize = Read32 (Obj);
-    H->ExportOffs = Read32 (Obj);
-    H->ExportSize = Read32 (Obj);
-    H->DbgSymOffs = Read32 (Obj);
-    H->DbgSymSize = Read32 (Obj);
+    H->Flags               = Read16 (Obj);
+    H->OptionOffs   = Read32 (Obj);
+    H->OptionSize   = Read32 (Obj);
+    H->FileOffs     = Read32 (Obj);
+    H->FileSize     = Read32 (Obj);
+    H->SegOffs             = Read32 (Obj);
+    H->SegSize             = Read32 (Obj);
+    H->ImportOffs   = Read32 (Obj);
+    H->ImportSize   = Read32 (Obj);
+    H->ExportOffs   = Read32 (Obj);
+    H->ExportSize   = Read32 (Obj);
+    H->DbgSymOffs   = Read32 (Obj);
+    H->DbgSymSize   = Read32 (Obj);
+    H->LineInfoOffs = Read32 (Obj);
+    H->LineInfoSize = Read32 (Obj);
 }
 
 
@@ -129,6 +131,8 @@ void ObjWriteHeader (FILE* Obj, ObjHeader* H)
     Write32 (Obj, H->ExportSize);
     Write32 (Obj, H->DbgSymOffs);
     Write32 (Obj, H->DbgSymSize);
+    Write32 (Obj, H->LineInfoOffs);
+    Write32 (Obj, H->LineInfoSize);
 }
 
 
@@ -173,9 +177,9 @@ void ObjAdd (const char* Name)
     }
 
     /* Initialize the object module data structure */
-    O->Name      = xstrdup (Module);
-    O->Flags     = OBJ_HAVEDATA;
-    O->MTime     = StatBuf.st_mtime;
+    O->Name      = xstrdup (Module);
+    O->Flags     = OBJ_HAVEDATA;
+    O->MTime     = StatBuf.st_mtime;
     O->ImportSize = H.ImportSize;
     O->Imports   = xmalloc (O->ImportSize);
     O->ExportSize = H.ExportSize;
@@ -200,6 +204,8 @@ void ObjAdd (const char* Name)
     H.SegOffs = LibCopyTo (Obj, H.SegSize) - O->Start;
     fseek (Obj, H.FileOffs, SEEK_SET);
     H.FileOffs = LibCopyTo (Obj, H.FileSize) - O->Start;
+    fseek (Obj, H.LineInfoOffs, SEEK_SET);
+    H.LineInfoOffs = LibCopyTo (Obj, H.LineInfoSize) - O->Start;
 
     /* Calculate the amount of data written */
     O->Size = ftell (NewLib) - O->Start;
index ade483c15fa5330880ca594bce504125723d3edf..62b76fd7184a1202a702cfaadf4a3c3cf2c5c763 100644 (file)
@@ -58,6 +58,9 @@ void DbgInfoFile (void)
     unsigned long Size;
     unsigned long MTime;
 
+    /* Parameters are separated by a comma */
+    ConsumeComma ();
+
     /* Name */
     if (Tok != TOK_STRCON) {
                ErrorSkip (ERR_STRCON_EXPECTED);
@@ -90,6 +93,17 @@ void DbgInfoLine (void)
     unsigned Index;
     long LineNum;
 
+    /* If a parameters follow, this is actual line info. If no parameters
+     * follow, the last line info is terminated.
+     */
+    if (Tok == TOK_SEP) {
+       ClearLineInfo ();
+       return;
+    }
+
+    /* Parameters are separated by a comma */
+    ConsumeComma ();
+
     /* The name of the file follows */
     if (Tok != TOK_STRCON) {
        ErrorSkip (ERR_STRCON_EXPECTED);
index 5634c5a9b41143ce9fb6ca94ccb8807254e6ce76..26e12fff5b56a3bd8fd04cc3e520155771ad52f3 100644 (file)
@@ -48,6 +48,7 @@
 #include "xmalloc.h"
 
 /* ca65 */
+#include "objfile.h"
 #include "lineinfo.h"
 
 
@@ -128,6 +129,14 @@ void GenLineInfo (unsigned FileIndex, unsigned long LineNum)
 
 
 
+void ClearLineInfo (void)
+/* Clear the current line info */
+{
+    CurLineInfo = 0;
+}
+
+
+
 void MakeLineInfoIndex (void)
 /* Walk over the line info list and make an index of all entries ignoring
  * those with a usage count of zero.
@@ -145,3 +154,37 @@ void MakeLineInfoIndex (void)
 
 
 
+void WriteLineInfo (void)
+/* Write a list of all line infos to the object file. */
+{
+    LineInfo* LI;
+
+    /* Tell the object file module that we're about to write line infos */
+    ObjStartLineInfos ();
+
+    /* Check if debug info is requested */
+    if (DbgSyms) {
+
+       /* Write the line info count to the list */
+               ObjWriteVar (LineInfoValid);
+
+               /* Walk through list and write all line infos that have references */
+       LI = LineInfoRoot;
+       while (LI) {
+           if (LI->Usage) {
+               /* Write the source file position */
+               ObjWritePos (&LI->Pos);
+           }
+           LI = LI->Next;
+       }
+
+    } else {
+
+       /* No line infos */
+       ObjWriteVar (0);
+
+    }
+}
+
+
+
index f00843b82cc4a0ad48a156d3af487fb05ead4c1a..faf69f284df65426480cba9222fb28683de8a3d4 100644 (file)
@@ -51,6 +51,9 @@
 /* common */
 #include "filepos.h"
 
+/* ca65 */
+#include "global.h"
+
 
 
 /*****************************************************************************/
@@ -95,6 +98,17 @@ LineInfo* UseLineInfo (LineInfo* LI);
 void GenLineInfo (unsigned FileIndex, unsigned long LineNum);
 /* Generate a new line info */
 
+void ClearLineInfo (void);
+/* Clear the current line info */
+
+void MakeLineInfoIndex (void);
+/* Walk over the line info list and make an index of all entries ignoring
+ * those with a usage count of zero.
+ */
+
+void WriteLineInfo (void);
+/* Write a list of all line infos to the object file. */
+
 
 
 /* End of lineinfo.h */
index 61e72d8857a0d025da0efc69b202b5609a43d0b6..b029e2f0cc64b67255ec5102819d2143cf6c9f64 100644 (file)
@@ -56,6 +56,7 @@
 #include "incpath.h"
 #include "instr.h"
 #include "istack.h"
+#include "lineinfo.h"
 #include "listing.h"
 #include "macro.h"
 #include "nexttok.h"
@@ -480,6 +481,9 @@ static void CreateObjFile (void)
     /* Write debug symbols if requested */
     WriteDbgSyms ();
 
+    /* Write line infos if requested */
+    WriteLineInfo ();
+
     /* Write an updated header and close the file */
     ObjClose ();
 }
@@ -636,6 +640,9 @@ int main (int argc, char* argv [])
         SegCheck ();
     }
 
+    /* If we didn't have an errors, index the line infos */
+    MakeLineInfoIndex ();
+
     /* Dump the data */
     if (Verbosity >= 2) {
         SymDump (stdout);
index 81d16420e444595e93631f0b9f611a83338914b4..a231b289ba3101447bcb70440431eb143608f667 100644 (file)
@@ -460,6 +460,7 @@ static void WriteOneSeg (Segment* Seg)
     Fragment* Frag;
     Fragment* F;
     unsigned long Size;
+    unsigned LineInfoIndex;
 
     /* Write the segment name followed by the byte count in this segment */
     ObjWriteStr (Seg->Name);
@@ -534,6 +535,12 @@ static void WriteOneSeg (Segment* Seg)
                /* Write the file position of this fragment */
        ObjWritePos (&Frag->Pos);
 
+       /* Write extra line info for this fragment. Zero is considered
+        * "no line info", so add one to the value.
+        */                
+       LineInfoIndex = Frag->LI? Frag->LI->Index + 1 : 0;
+       ObjWriteVar (LineInfoIndex);
+
        /* Next fragment */
        Frag = Frag->Next;
     }
index cd5c496228ec775483f59b442baba33eca930c5d..867f771ab0278020ca2c90c1a57310f22a03a466 100644 (file)
@@ -113,12 +113,14 @@ static void ObjWriteHeader (void)
     ObjWrite32 (Header.ExportSize);
     ObjWrite32 (Header.DbgSymOffs);
     ObjWrite32 (Header.DbgSymSize);
+    ObjWrite32 (Header.LineInfoOffs);
+    ObjWrite32 (Header.LineInfoSize);
 }
 
 
 
 /*****************************************************************************/
-/*                                          Code                                    */
+/*                                          Code                                    */
 /*****************************************************************************/
 
 
@@ -241,7 +243,7 @@ void ObjWriteStr (const char* S)
      */
     ObjWriteVar (Len);
     ObjWriteData (S, Len);
-}
+}                             
 
 
 
@@ -370,6 +372,7 @@ void ObjEndDbgSyms (void)
 void ObjStartLineInfos (void)
 /* Mark the start of the line info section */
 {
+    Header.LineInfoOffs = ftell (F);
 }
 
 
@@ -377,6 +380,7 @@ void ObjStartLineInfos (void)
 void ObjEndLineInfos (void)
 /* Mark the end of the line info section */
 {
+    Header.LineInfoSize = ftell (F) - Header.LineInfoOffs;
 }
 
 
index f7dc8bb4e2eb732de9a1773d5d4e01528e72b9d3..801db02bad3365fe81bf43e162d6f2783958d947 100644 (file)
@@ -482,9 +482,6 @@ static void DoDbg (void)
     /* Skip the subkey */
     NextTok ();
 
-    /* Parameters are separated by a comma */
-    ConsumeComma ();
-
     /* Check the key and dispatch to a handler */
     switch (Key) {
        case 0:     DbgInfoFile ();             break;
index 116b67b3027efd3032253490057b62c964fbf0c0..adf023971a60b3f13b9181a239ca6d9a6ae61f0d 100644 (file)
@@ -966,6 +966,11 @@ void OutputCodeSeg (const CodeSeg* S, FILE* F)
        OutputCodeEntry (E, F);
     }
 
+    /* If debug info is enabled, terminate the last line number information */
+    if (DebugInfo) {
+       fprintf (F, "\t.dbg\tline\n");
+    }
+
     /* If this is a segment for a function, leave the function */
     if (S->Func) {
        fprintf (F, "\n.endproc\n\n");
index f717b4358362ff555954e46ee924d9b93f19692b..2c02a6fdb49f8d17e831e7771b6be932edaafd72 100644 (file)
@@ -46,7 +46,7 @@
 
 /* Defines for magic and version */
 #define LIB_MAGIC      0x7A55616E
-#define LIB_VERSION    0x0008
+#define LIB_VERSION    0x0009
 
 /* Size of an library file header */
 #define        LIB_HDR_SIZE    12
index 7678f4763a40628ebb6e257da969a678b53946f8..c173ba651d6190463758cd95c92a2be1e46d4890 100644 (file)
 
 /* Defines for magic and version */
 #define OBJ_MAGIC      0x616E7A55
-#define OBJ_VERSION    0x0008
+#define OBJ_VERSION    0x0009
 
 /* Size of an object file header */
-#define        OBJ_HDR_SIZE    56
+#define        OBJ_HDR_SIZE    64
 
 /* Flag bits */
 #define OBJ_FLAGS_DBGINFO      0x0001  /* File has debug info */
@@ -74,6 +74,8 @@ struct ObjHeader_ {
     unsigned long      ExportSize;     /* 32: Size of export list */
     unsigned long       DbgSymOffs;            /* 32: Offset to list of debug symbols */
     unsigned long      DbgSymSize;     /* 32: Size of debug symbols */
+    unsigned long       LineInfoOffs;   /* 32: Offset to list of line infos */
+    unsigned long       LineInfoSize;   /* 32: Size of line infos */
 };
 
 
index 991ed3565f982de80c5fa62b8757664d7644dfe8..0051a26d5c0501b3c8acc7a1466a303a7efc541f 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2000 Ullrich von Bassewitz                                       */
+/* (C) 1998-2001 Ullrich von Bassewitz                                       */
 /*               Wacholderweg 14                                             */
 /*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -60,6 +60,7 @@ Fragment* NewFragment (unsigned char Type, unsigned long Size, Section* S)
     F->Size = Size;
     F->Expr = 0;
     InitFilePos (&F->Pos);
+    F->LI   = 0;
     F->Type = Type;
 
     /* Insert the code fragment into the section */
index cae0a1513063ddbe576407f5045292f68b5f482d..9e8fc2f586f0795ac726b01e3af5a4fc21ee9917 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2000 Ullrich von Bassewitz                                       */
+/* (C) 1998-2001 Ullrich von Bassewitz                                       */
 /*               Wacholderweg 14                                             */
 /*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -57,6 +57,7 @@ struct Fragment {
     unsigned long              Size;           /* Size of data/expression */
     struct ExprNode*   Expr;           /* Expression if FRAG_EXPR */
     FilePos            Pos;            /* File position in source */
+    struct LineInfo*    LI;             /* Additional line info */
     unsigned char      Type;           /* Type of fragment */
     unsigned char              LitBuf [1];     /* Dynamically alloc'ed literal buffer */
 };
diff --git a/src/ld65/lineinfo.c b/src/ld65/lineinfo.c
new file mode 100644 (file)
index 0000000..5cc2e19
--- /dev/null
@@ -0,0 +1,81 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                               lineinfo.h                                 */
+/*                                                                           */
+/*                     Source file line info structure                      */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (C) 2001      Ullrich von Bassewitz                                       */
+/*               Wacholderweg 14                                             */
+/*               D-70597 Stuttgart                                           */
+/* EMail:        uz@cc65.org                                                 */
+/*                                                                           */
+/*                                                                           */
+/* This software is provided 'as-is', without any expressed or implied       */
+/* warranty.  In no event will the authors be held liable for any damages    */
+/* arising from the use of this software.                                    */
+/*                                                                           */
+/* Permission is granted to anyone to use this software for any purpose,     */
+/* including commercial applications, and to alter it and redistribute it    */
+/* freely, subject to the following restrictions:                            */
+/*                                                                           */
+/* 1. The origin of this software must not be misrepresented; you must not   */
+/*    claim that you wrote the original software. If you use this software   */
+/*    in a product, an acknowledgment in the product documentation would be  */
+/*    appreciated but is not required.                                       */
+/* 2. Altered source versions must be plainly marked as such, and must not   */
+/*    be misrepresented as being the original software.                      */
+/* 3. This notice may not be removed or altered from any source              */
+/*    distribution.                                                          */
+/*                                                                           */
+/*****************************************************************************/
+
+
+
+/* common */
+#include "xmalloc.h"
+
+/* ld65 */
+#include "fileio.h"
+#include "lineinfo.h"
+
+
+
+/*****************************************************************************/
+/*                                          Code                                    */
+/*****************************************************************************/
+
+
+
+static LineInfo* NewLineInfo (void)
+/* Create and return a new LineInfo struct */
+{
+    /* Allocate memory */
+    LineInfo* LI = xmalloc (sizeof (LineInfo));
+
+    /* Initialize the fields */
+    InitFilePos (&LI->Pos);
+    InitCollection (&LI->Fragments);
+
+    /* Return the new struct */
+    return LI;
+}
+
+
+
+LineInfo* ReadLineInfo (FILE* F, ObjData* O)
+/* Read a line info from a file and return it */
+{
+    /* Allocate a new LineInfo struct and initialize it */
+    LineInfo* LI = NewLineInfo ();
+
+    /* Read the file position */
+    ReadFilePos (F, &LI->Pos);
+
+    /* Return the new LineInfo */
+    return LI;
+}
+
+
+
diff --git a/src/ld65/lineinfo.h b/src/ld65/lineinfo.h
new file mode 100644 (file)
index 0000000..98138c4
--- /dev/null
@@ -0,0 +1,79 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                               lineinfo.h                                 */
+/*                                                                           */
+/*                     Source file line info structure                      */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (C) 2001      Ullrich von Bassewitz                                       */
+/*               Wacholderweg 14                                             */
+/*               D-70597 Stuttgart                                           */
+/* EMail:        uz@cc65.org                                                 */
+/*                                                                           */
+/*                                                                           */
+/* This software is provided 'as-is', without any expressed or implied       */
+/* warranty.  In no event will the authors be held liable for any damages    */
+/* arising from the use of this software.                                    */
+/*                                                                           */
+/* Permission is granted to anyone to use this software for any purpose,     */
+/* including commercial applications, and to alter it and redistribute it    */
+/* freely, subject to the following restrictions:                            */
+/*                                                                           */
+/* 1. The origin of this software must not be misrepresented; you must not   */
+/*    claim that you wrote the original software. If you use this software   */
+/*    in a product, an acknowledgment in the product documentation would be  */
+/*    appreciated but is not required.                                       */
+/* 2. Altered source versions must be plainly marked as such, and must not   */
+/*    be misrepresented as being the original software.                      */
+/* 3. This notice may not be removed or altered from any source              */
+/*    distribution.                                                          */
+/*                                                                           */
+/*****************************************************************************/
+
+
+
+#ifndef LINEINFO_H
+#define LINEINFO_H
+
+
+
+/* common */
+#include "coll.h"
+#include "filepos.h"
+
+/* ld65 */
+#include "objdata.h"
+
+
+
+/*****************************************************************************/
+/*                                  Data                                    */
+/*****************************************************************************/
+
+
+
+typedef struct LineInfo LineInfo;
+struct LineInfo {
+    FilePos         Pos;                  /* File position */
+    Collection      Fragments;            /* Fragments for this line */
+};
+
+
+
+/*****************************************************************************/
+/*                                          Code                                    */
+/*****************************************************************************/
+
+
+
+LineInfo* ReadLineInfo (FILE* F, ObjData* O);
+/* Read a line info from a file and return it */
+
+
+
+/* End of lineinfo.h */
+#endif
+
+
+
index 633b9f36033042b741b974c1aca0cd47b9fe7a4c..f48fc8bc5758de66decc952de61ca3e211651085 100644 (file)
@@ -31,6 +31,7 @@ OBJS =        bin.o           \
        fragment.o      \
        global.o        \
        library.o       \
+       lineinfo.o      \
        main.o          \
        mapfile.o       \
        o65.o           \
index ce88775dc74b30a4b8ae33066e1da22882a9d964..8deecb0f730ad5fd3d427b645771a38f730aa4c8 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2000 Ullrich von Bassewitz                                       */
+/* (C) 1998-2001 Ullrich von Bassewitz                                       */
 /*               Wacholderweg 14                                             */
 /*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -83,6 +83,8 @@ ObjData* NewObjData (void)
     O->Imports         = 0;
     O->DbgSymCount     = 0;
     O->DbgSyms         = 0;
+    O->LineInfoCount    = 0;
+    O->LineInfos        = 0;
 
     /* Link it into the list */
     if (ObjLast) {
@@ -108,7 +110,8 @@ void FreeObjData (ObjData* O)
     xfree (O->Name);
     xfree (O->Imports);
     xfree (O->Exports);
-    xfree (O->DbgSyms);
+    xfree (O->DbgSyms);            
+    xfree (O->LineInfos);
     xfree (O);
 }
 
@@ -143,7 +146,7 @@ const char* GetSourceFileName (const ObjData* O, unsigned Index)
        /* Return the name */
        return O->Files[Index];
 
-    }           
+    }
 }
 
 
index 1fa3399440660dc3638d18f1e1c24163efb1826c..a6d39ace71f96d8b3aad37c3b1f0dfbd2a756199 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998     Ullrich von Bassewitz                                        */
-/*              Wacholderweg 14                                              */
-/*              D-70597 Stuttgart                                            */
-/* EMail:       uz@musoftware.de                                             */
+/* (C) 1998-2001 Ullrich von Bassewitz                                       */
+/*               Wacholderweg 14                                             */
+/*               D-70597 Stuttgart                                           */
+/* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -74,6 +74,8 @@ struct ObjData {
     struct Import**    Imports;        /* List of all imports */
     unsigned           DbgSymCount;    /* Count of debug symbols */
     struct DbgSym**    DbgSyms;        /* List of debug symbols */
+    unsigned            LineInfoCount;  /* Count of additional line infos */
+    struct LineInfo**   LineInfos;      /* List of additional line infos */
 };
 
 
@@ -104,7 +106,7 @@ const char* GetObjFileName (const ObjData* O);
 
 const char* GetSourceFileName (const ObjData* O, unsigned Index);
 /* Get the name of the source file with the given index. If O is NULL, return
- * "[linker generated]" as the file name.                    
+ * "[linker generated]" as the file name.
  */
 
 
@@ -116,3 +118,4 @@ const char* GetSourceFileName (const ObjData* O, unsigned Index);
 
 
 
+
index 671c496db0675e78a373d1708b3e5ac602dc74a5..f08b147617cff948fcff7838a300271c964f47cb 100644 (file)
@@ -47,6 +47,7 @@
 #include "error.h"
 #include "exports.h"
 #include "fileio.h"
+#include "lineinfo.h"
 #include "objdata.h"
 #include "segments.h"
 #include "objfile.h"
@@ -86,19 +87,21 @@ static void ObjReadHeader (FILE* Obj, ObjHeader* H, const char* Name)
     if (H->Version != OBJ_VERSION) {
                Error ("Object file `%s' has wrong version", Name);
     }
-    H->Flags     = Read16 (Obj);
-    H->OptionOffs = Read32 (Obj);
-    H->OptionSize = Read32 (Obj);
-    H->FileOffs   = Read32 (Obj);
-    H->FileSize   = Read32 (Obj);
-    H->SegOffs   = Read32 (Obj);
-    H->SegSize   = Read32 (Obj);
-    H->ImportOffs = Read32 (Obj);
-    H->ImportSize = Read32 (Obj);
-    H->ExportOffs = Read32 (Obj);
-    H->ExportSize = Read32 (Obj);
-    H->DbgSymOffs = Read32 (Obj);
-    H->DbgSymSize = Read32 (Obj);
+    H->Flags       = Read16 (Obj);
+    H->OptionOffs   = Read32 (Obj);
+    H->OptionSize   = Read32 (Obj);
+    H->FileOffs     = Read32 (Obj);
+    H->FileSize     = Read32 (Obj);
+    H->SegOffs     = Read32 (Obj);
+    H->SegSize     = Read32 (Obj);
+    H->ImportOffs   = Read32 (Obj);
+    H->ImportSize   = Read32 (Obj);
+    H->ExportOffs   = Read32 (Obj);
+    H->ExportSize   = Read32 (Obj);
+    H->DbgSymOffs   = Read32 (Obj);
+    H->DbgSymSize   = Read32 (Obj);
+    H->LineInfoOffs = Read32 (Obj);
+    H->LineInfoSize = Read32 (Obj);
 }
 
 
@@ -155,7 +158,7 @@ void ObjReadDbgSyms (FILE* F, ObjData* O)
 /* Read the debug symbols from a file at the current position */
 {
     unsigned I;
-
+                    
     O->DbgSymCount = ReadVar (F);
     O->DbgSyms    = xmalloc (O->DbgSymCount * sizeof (DbgSym*));
     for (I = 0; I < O->DbgSymCount; ++I) {
@@ -165,6 +168,20 @@ void ObjReadDbgSyms (FILE* F, ObjData* O)
 
 
 
+void ObjReadLineInfos (FILE* F, ObjData* O)
+/* Read the line infos from a file at the current position */
+{
+    unsigned I;
+
+    O->LineInfoCount = ReadVar (F);
+    O->LineInfos     = xmalloc (O->LineInfoCount * sizeof (LineInfo*));
+    for (I = 0; I < O->LineInfoCount; ++I) {
+               O->LineInfos[I] = ReadLineInfo (F, O);
+    }
+}
+
+
+
 void ObjReadSections (FILE* F, ObjData* O)
 /* Read the section data from a file at the current position */
 {
@@ -211,6 +228,10 @@ void ObjAdd (FILE* Obj, const char* Name)
     fseek (Obj, O->Header.DbgSymOffs, SEEK_SET);
     ObjReadDbgSyms (Obj, O);
 
+    /* Read the line infos from the object file */
+    fseek (Obj, O->Header.LineInfoOffs, SEEK_SET);
+    ObjReadLineInfos (Obj, O);
+
     /* Read the segment list from the object file. This must be last, since
      * the expressions stored in the code may reference segments or imported
      * symbols.
index 684521dcdb467ed6fee402fdd605b3273bc8e45f..3946fbad6b27c02c3b10ea5b10aee9af42cfbed3 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2000 Ullrich von Bassewitz                                       */
+/* (C) 1998-2001 Ullrich von Bassewitz                                       */
 /*               Wacholderweg 14                                             */
 /*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -51,6 +51,7 @@
 #include "fileio.h"
 #include "fragment.h"
 #include "global.h"
+#include "lineinfo.h"
 #include "segments.h"
 
 
@@ -253,6 +254,7 @@ Section* ReadSection (FILE* F, ObjData* O)
     while (Size) {
 
        Fragment* Frag;
+       unsigned  LineInfoIndex;
 
        /* Read the fragment type */
        unsigned char Type = Read8 (F);
@@ -299,13 +301,24 @@ Section* ReadSection (FILE* F, ObjData* O)
            case FRAG_SEXPR:
                /* An expression */
                Frag->Expr = ReadExpr (F, O);
-               break;
+               break;
 
        }
 
        /* Read the file position of the fragment */
        ReadFilePos (F, &Frag->Pos);
 
+       /* Read the additional line info and resolve it */
+       LineInfoIndex = ReadVar (F);
+       if (LineInfoIndex) {
+           --LineInfoIndex;
+           CHECK (LineInfoIndex < O->LineInfoCount);
+           /* Point from the fragment to the line info... */
+           Frag->LI = O->LineInfos[LineInfoIndex];
+           /* ...and back from the line info to the fragment */
+           CollAppend (&Frag->LI->Fragments, Frag);
+       }
+
        /* Remember the module we had this fragment from */
        Frag->Obj = O;
 
index 7a0a6a97454dc39dcdd8459c333eb2ce277c044c..f90ad9c3f19d78807d7ac728f3698872ec4af0de 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2000 Ullrich von Bassewitz                                       */
+/* (C) 1998-2001 Ullrich von Bassewitz                                       */
 /*               Wacholderweg 14                                             */
 /*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
index d44e12efd9d7c4a96b436d84d2cbd64db5de8e8f..431ced5275cbc83ff3e5eceb90c9c7cf2edc0777 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000     Ullrich von Bassewitz                                        */
-/*              Wacholderweg 14                                              */
-/*              D-70597 Stuttgart                                            */
-/* EMail:       uz@musoftware.de                                             */
+/* (C) 2000-2001 Ullrich von Bassewitz                                       */
+/*               Wacholderweg 14                                             */
+/*               D-70597 Stuttgart                                           */
+/* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -191,6 +191,9 @@ static unsigned SkipFragment (FILE* F)
     /* Skip the file position of the fragment */
     ReadFilePos (F, &Pos);
 
+    /* Skip the        additional line info */
+    (void) ReadVar (F);
+
     /* Return the size */
     return Size;
 }
@@ -388,7 +391,7 @@ void DumpObjFiles (FILE* F, unsigned long Offset)
     /* Read the header */
     ReadObjHeader (F, &H);
 
-    /* Seek to the start of the options */
+    /* Seek to the start of the source files */
     FileSeek (F, Offset + H.FileOffs);
 
     /* Output a header */
@@ -436,7 +439,7 @@ void DumpObjSegments (FILE* F, unsigned long Offset)
     /* Read the header */
     ReadObjHeader (F, &H);
 
-    /* Seek to the start of the options */
+    /* Seek to the start of the segments */
     FileSeek (F, Offset + H.SegOffs);
 
     /* Output a header */
@@ -511,7 +514,7 @@ void DumpObjImports (FILE* F, unsigned long Offset)
     /* Read the header */
     ReadObjHeader (F, &H);
 
-    /* Seek to the start of the options */
+    /* Seek to the start of the imports */
     FileSeek (F, Offset + H.ImportOffs);
 
     /* Output a header */
@@ -567,7 +570,7 @@ void DumpObjExports (FILE* F, unsigned long Offset)
     /* Read the header */
     ReadObjHeader (F, &H);
 
-    /* Seek to the start of the options */
+    /* Seek to the start of the exports */
     FileSeek (F, Offset + H.ExportOffs);
 
     /* Output a header */
@@ -633,7 +636,7 @@ void DumpObjDbgSyms (FILE* F, unsigned long Offset)
     /* Read the header */
     ReadObjHeader (F, &H);
 
-    /* Seek to the start of the options */
+    /* Seek to the start of the debug syms */
     FileSeek (F, Offset + H.DbgSymOffs);
 
     /* Output a header */
@@ -691,4 +694,54 @@ void DumpObjDbgSyms (FILE* F, unsigned long Offset)
 
 
 
+void DumpObjLineInfo (FILE* F, unsigned long Offset)
+/* Dump the line info from an object file */
+{
+    ObjHeader H;
+    unsigned  Count;
+    unsigned  I;
+
+    /* Seek to the header position */
+    FileSeek (F, Offset);
+
+    /* Read the header */
+    ReadObjHeader (F, &H);
+
+    /* Seek to the start of line infos */
+    FileSeek (F, Offset + H.LineInfoOffs);
+
+    /* Output a header */
+    printf ("  Line info:\n");
+
+    /* Check if the object file was compiled with debug info */
+    if ((H.Flags & OBJ_FLAGS_DBGINFO) == 0) {
+       /* Print that there no line infos and bail out */
+       printf ("    Count:%27u\n", 0);
+       return;
+    }
+
+    /* Read the number of line infos and print it */
+    Count = ReadVar (F);
+    printf ("    Count:%27u\n", Count);
+
+    /* Read and print all line infos */
+    for (I = 0; I < Count; ++I) {
+
+       FilePos   Pos;
+
+               /* Read one line info */
+       ReadFilePos (F, &Pos);
+
+       /* Print the header */
+       printf ("    Index:%27u\n", I);
+
+       /* Print the data */
+               printf ("      Line:%26lu\n", Pos.Line);
+               printf ("      Col:%27u\n", Pos.Col);
+               printf ("      Name:%26u\n", Pos.Name);
+    }
+}
+
+
+
 
index d35417b9c2de97500f6d906abb61ba670600fb81..96a65f725a2d75674cabc94696eb9c5e0e1a8243 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000     Ullrich von Bassewitz                                        */
-/*              Wacholderweg 14                                              */
-/*              D-70597 Stuttgart                                            */
-/* EMail:       uz@musoftware.de                                             */
+/* (C) 2000-2001 Ullrich von Bassewitz                                       */
+/*               Wacholderweg 14                                             */
+/*               D-70597 Stuttgart                                           */
+/* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -69,6 +69,9 @@ void DumpObjExports (FILE* F, unsigned long Offset);
 void DumpObjDbgSyms (FILE* F, unsigned long Offset);
 /* Dump the debug symbols from an object file */
 
+void DumpObjLineInfo (FILE* F, unsigned long Offset);
+/* Dump the line infos from an object file */
+
 
 
 /* End of dump.h */
index 1950400e080694c1679ce19ed97241167b76e23e..ee0e32372266b0ce4dda1fbdd1c94487f517541d 100644 (file)
@@ -183,7 +183,7 @@ void* ReadData (FILE* F, void* Data, unsigned Size)
     if (Size > 0) {
        if (fread (Data, 1, Size, F) != Size) {
            Error ("Read error (file corrupt?)");
-       }          
+       }
     }
     return Data;
 }
@@ -209,6 +209,8 @@ void ReadObjHeader (FILE* F, ObjHeader* H)
     H->ExportSize   = Read32 (F);
     H->DbgSymOffs   = Read32 (F);
     H->DbgSymSize   = Read32 (F);
+    H->LineInfoOffs = Read32 (F);
+    H->LineInfoSize = Read32 (F);
 }
 
 
index 3f36342fea069e3a36921e7b6d0b3c7801821235..702e5691ab528f09fcbb97521e578aaa53950ab2 100644 (file)
@@ -51,6 +51,7 @@
 #define D_IMPORTS              0x0010U         /* Dump imported symbols */
 #define D_EXPORTS              0x0020U         /* Dump exported symbols */
 #define D_DBGSYMS              0x0040U         /* Dump debug symbols */
+#define D_LINEINFO      0x0080U         /* Dump line infos */
 #define D_ALL                  0xFFFFU         /* Dump anything */
 
 
index 5acb5afe2672679eccbbe62c70ad38a96dab0683..4c194f928a6fb70b9ffef5bc1248be2ce9e7ed79 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000      Ullrich von Bassewitz                                       */
+/* (C) 2000-2001 Ullrich von Bassewitz                                       */
 /*               Wacholderweg 14                                             */
 /*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -83,6 +83,7 @@ static void Usage (void)
             "  --dump-files\t\tDump the source files\n"
             "  --dump-header\t\tDump the object file header\n"
             "  --dump-imports\tDump imported symbols\n"
+            "  --dump-lineinfo\tDump line information\n"
             "  --dump-options\tDump object file options\n"
             "  --dump-segments\tDump the segments in the file\n"
             "  --help\t\tHelp (this text)\n"
@@ -140,6 +141,14 @@ static void OptDumpImports (const char* Opt, const char* Arg)
 
 
 
+static void OptDumpLineInfo (const char* Opt, const char* Arg)
+/* Dump the line infos */
+{
+    What |= D_LINEINFO;
+}
+
+
+
 static void OptDumpOptions (const char* Opt, const char* Arg)
 /* Dump the object file options */
 {
@@ -227,6 +236,9 @@ static void DumpFile (const char* Name)
        if (What & D_DBGSYMS) {
            DumpObjDbgSyms (F, 0);
        }
+       if (What & D_LINEINFO) {
+           DumpObjLineInfo (F, 0);
+       }
     }
 
     /* Close the file */
@@ -246,6 +258,7 @@ int main (int argc, char* argv [])
        { "--dump-files",       0,      OptDumpFiles            },
        { "--dump-header",      0,      OptDumpHeader           },
        { "--dump-imports",     0,      OptDumpImports          },
+        { "--dump-lineinfo",    0,      OptDumpLineInfo         },
        { "--dump-options",     0,      OptDumpOptions          },
        { "--dump-segments",    0,      OptDumpSegments         },
        { "--help",             0,      OptHelp                 },