]> git.sur5r.net Git - cc65/commitdiff
Added dbg file generation
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Tue, 29 May 2001 07:39:46 +0000 (07:39 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Tue, 29 May 2001 07:39:46 +0000 (07:39 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@764 b7a2c559-68d2-44c3-8de9-860c34a00d81

20 files changed:
src/ld65/bin.c
src/ld65/bin.h
src/ld65/dbgsyms.c
src/ld65/dbgsyms.h
src/ld65/fragment.h
src/ld65/global.c
src/ld65/global.h
src/ld65/library.c
src/ld65/lineinfo.c
src/ld65/lineinfo.h
src/ld65/main.c
src/ld65/make/gcc.mak
src/ld65/make/watcom.mak
src/ld65/mapfile.c
src/ld65/mapfile.h
src/ld65/o65.c
src/ld65/o65.h
src/ld65/objfile.c
src/ld65/objfile.h
src/ld65/segments.c

index 7f4b08551b3eacedfcd3b865b42ad26b79427e0b..318185266ecc3db37fe46724e99a7a96b6732b6c 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1999-2000 Ullrich von Bassewitz                                       */
+/* (C) 1999-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       */
@@ -45,6 +45,7 @@
 #include "global.h"
 #include "error.h"
 #include "fileio.h"
+#include "lineinfo.h"
 #include "segments.h"
 #include "exports.h"
 #include "config.h"
@@ -186,6 +187,7 @@ static void BinWriteMem (BinDesc* D, Memory* M)
         * if the memory area is the load area.
         */
                if (DoWrite) {
+           RelocLineInfo (S->Seg);
            SegWrite (D->F, S->Seg, BinWriteExpr, D);
        } else if (M->Flags & MF_FILL) {
            WriteMult (D->F, M->FillVal, S->Seg->Size);
index 7b32a9fac86e40b02bddecd706ab007411feeba2..753f16dd4e85fa6bb0fafe6b8a7742eba9a66240 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1999     Ullrich von Bassewitz                                        */
-/*              Wacholderweg 14                                              */
-/*              D-70597 Stuttgart                                            */
-/* EMail:       uz@musoftware.de                                             */
+/* (C) 1999-2001 Ullrich von Bassewitz                                       */
+/*               Wacholderweg 14                                             */
+/*               D-70597 Stuttgart                                           */
+/* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
index 413f6cfa853210bbbc127a6b6c234be274e8a20e..e728c2907630d1e789920d07c56e1260e4027745 100644 (file)
@@ -2,7 +2,7 @@
 /*                                                                           */
 /*                                dbgsyms.c                                 */
 /*                                                                           */
-/*                Debug symbol handing for the ld65 linker                  */
+/*                Debug symbol handling for the ld65 linker                 */
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
index 7f8e98f18ab91a17295fd1753aa65e434bba3eeb..6964ca1ba57dd0587a8229eac5f76fddea03af3b 100644 (file)
@@ -2,7 +2,7 @@
 /*                                                                           */
 /*                                dbgsyms.h                                 */
 /*                                                                           */
-/*                Debug symbol handing for the ld65 linker                  */
+/*                Debug symbol handling for the ld65 linker                 */
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
@@ -93,4 +93,4 @@ void PrintDbgSymLabels (ObjData* O, FILE* F);
 
 
 
-            
+
index 9e8fc2f586f0795ac726b01e3af5a4fc21ee9917..be9a8f016ecf3bda1a0573ddd3a1369f71ab310e 100644 (file)
 
 
 
+/*****************************************************************************/
+/*                                Forwards                                  */
+/*****************************************************************************/
+
+
+
+struct LineInfo;
+struct Section;
+
+
+
 /*****************************************************************************/
 /*                                          Data                                    */
 /*****************************************************************************/
index 1a624cadebe25a541fe0d0daca3ec8ad9306e1db..fea95b899bab559923632cf8b9af4cdd077a4127 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       */
@@ -50,6 +50,7 @@ unsigned long StartAddr           = 0x200;    /* Start address */
 unsigned char VerboseMap    = 0;       /* Verbose map file */
 const char* MapFileName            = 0;        /* Name of the map file */
 const char* LabelFileName   = 0;       /* Name of the label file */
+const char* DbgFileName     = 0;        /* Name of the debug file */
 unsigned char WProtSegs     = 0;       /* Mark write protected segments */
 
 
index 288a9d917b721ff8cc98b2d372d7b6982da51751..8244ef7422a9d38293bdad3858129d165632e679 100644 (file)
@@ -1,15 +1,15 @@
 /*****************************************************************************/
 /*                                                                           */
-/*                                global.h                                  */
+/*                                global.h                                  */
 /*                                                                           */
-/*                  Global variables for the ld65 linker                    */
+/*                  Global variables for the ld65 linker                    */
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (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       */
@@ -51,6 +51,7 @@ extern unsigned long  StartAddr;      /* Start address */
 extern unsigned char   VerboseMap;     /* Verbose map file */
 extern const char*     MapFileName;    /* Name of the map file */
 extern const char*     LabelFileName;  /* Name of the label file */
+extern const char*      DbgFileName;    /* Name of the debug file */
 extern unsigned char           WProtSegs;      /* Mark write protected segments */
 
 
index 18b21b84388c51cb49b2857ddeac1f24f12ea3e3..cb59f034d513558f969e143ee9b36436d9bd3919 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      */
@@ -78,29 +78,31 @@ static ObjData**    Index           = 0;
 static void LibReadObjHeader (ObjData* O)
 /* Read the header of the object file checking the signature */
 {
-    O->Header.Magic     = Read32 (Lib);
+    O->Header.Magic = Read32 (Lib);
     if (O->Header.Magic != OBJ_MAGIC) {
-       Error ("Object file `%s' in library `%s' is invalid", 
+       Error ("Object file `%s' in library `%s' is invalid",
               GetObjFileName (O), LibName);
     }
-    O->Header.Version   = Read16 (Lib);
+    O->Header.Version = Read16 (Lib);
     if (O->Header.Version != OBJ_VERSION) {
        Error ("Object file `%s' in library `%s' has wrong version",
               GetObjFileName (O), LibName);
     }
-    O->Header.Flags     = Read16 (Lib);
-    O->Header.OptionOffs = Read32 (Lib);
-    O->Header.OptionSize = Read32 (Lib);
-    O->Header.FileOffs  = Read32 (Lib);
-    O->Header.FileSize  = Read32 (Lib);
-    O->Header.SegOffs   = Read32 (Lib);
-    O->Header.SegSize   = Read32 (Lib);
-    O->Header.ImportOffs = Read32 (Lib);
-    O->Header.ImportSize = Read32 (Lib);
-    O->Header.ExportOffs = Read32 (Lib);
-    O->Header.ExportSize = Read32 (Lib);
-    O->Header.DbgSymOffs = Read32 (Lib);
-    O->Header.DbgSymSize = Read32 (Lib);
+    O->Header.Flags               = Read16 (Lib);
+    O->Header.OptionOffs   = Read32 (Lib);
+    O->Header.OptionSize   = Read32 (Lib);
+    O->Header.FileOffs    = Read32 (Lib);
+    O->Header.FileSize    = Read32 (Lib);
+    O->Header.SegOffs     = Read32 (Lib);
+    O->Header.SegSize     = Read32 (Lib);
+    O->Header.ImportOffs   = Read32 (Lib);
+    O->Header.ImportSize   = Read32 (Lib);
+    O->Header.ExportOffs   = Read32 (Lib);
+    O->Header.ExportSize   = Read32 (Lib);
+    O->Header.DbgSymOffs   = Read32 (Lib);
+    O->Header.DbgSymSize   = Read32 (Lib);
+    O->Header.LineInfoOffs = Read32 (Lib);
+    O->Header.LineInfoSize = Read32 (Lib);
 }
 
 
@@ -187,7 +189,7 @@ static void LibCheckExports (ObjData* O)
        for (I = 0; I < O->ExportCount; ++I) {
            InsertExport (O->Exports [I]);
        }
-       /* Insert the imports */
+       /* Insert the imports */
        for (I = 0; I < O->ImportCount; ++I) {
            InsertImport (O->Imports [I]);
        }
@@ -230,45 +232,52 @@ void LibAdd (FILE* F, const char* Name)
     do {
        Add = 0;
        for (I = 0; I < ModuleCount; ++I) {
-           ObjData* O = Index [I];
-           if ((O->Flags & OBJ_REF) == 0) {
-               LibCheckExports (O);
-               if (O->Flags & OBJ_REF) {
-                   /* The routine added the file */
-                   Add = 1;
-               }
-           }
-       }
+           ObjData* O = Index [I];
+           if ((O->Flags & OBJ_REF) == 0) {
+               LibCheckExports (O);
+               if (O->Flags & OBJ_REF) {
+                   /* The routine added the file */
+                   Add = 1;
+               }
+           }
+       }
     } while (Add);
 
     /* Add the files list and sections for all requested modules */
     for (I = 0; I < ModuleCount; ++I) {
-       ObjData* O = Index [I];
-       if (O->Flags & OBJ_REF) {
+       ObjData* O = Index [I];
+       if (O->Flags & OBJ_REF) {
+
+           /* Seek to the start of the object file and read the header */
+           fseek (Lib, O->Start, SEEK_SET);
+           LibReadObjHeader (O);
 
-           /* Seek to the start of the object file and read the header */
-           fseek (Lib, O->Start, SEEK_SET);
-           LibReadObjHeader (O);
+           /* Seek to the start of the files list and read the files list */
+           fseek (Lib, O->Start + O->Header.FileOffs, SEEK_SET);
+           ObjReadFiles (Lib, O);
 
-           /* Seek to the start of the files list and read the files list */
-           fseek (Lib, O->Start + O->Header.FileOffs, SEEK_SET);
-           ObjReadFiles (Lib, O);
+           /* Seek to the start of the debug info and read the debug info */
+           fseek (Lib, O->Start + O->Header.DbgSymOffs, SEEK_SET);
+           ObjReadDbgSyms (Lib, O);
 
-           /* Seek to the start of the segment list and read the segments */
-           fseek (Lib, O->Start + O->Header.SegOffs, SEEK_SET);
-           ObjReadSections (Lib, O);
+           /* Seek to the start of the line infos and read them */
+           fseek (Lib, O->Start + O->Header.LineInfoOffs, SEEK_SET);
+           ObjReadLineInfos (Lib, O);
 
-           /* Seek to the start of the debug info and read the debug info */
-           fseek (Lib, O->Start + O->Header.DbgSymOffs, SEEK_SET);
-           ObjReadDbgSyms (Lib, O);
+           /* Seek to the start of the segment list and read the segments.
+            * This must be last, since the data here may reference other
+            * stuff.
+            */
+           fseek (Lib, O->Start + O->Header.SegOffs, SEEK_SET);
+           ObjReadSections (Lib, O);
 
            /* We have the data now */
-           O->Flags |= OBJ_HAVEDATA;
+           O->Flags |= OBJ_HAVEDATA;
 
-       }
+       }
 
-       /* Add a pointer to the library name */
-       O->LibName = LibName;
+       /* Add a pointer to the library name */
+       O->LibName = LibName;
     }
 
     /* Done. Close the file, release allocated memory */
index 1811e5a01950b6c294a9a9a50264101a691f8f05..46c3c7a6a933548772610fcb591adffbb7b09bc4 100644 (file)
@@ -39,6 +39,8 @@
 
 /* ld65 */
 #include "fileio.h"
+#include "fragment.h"
+#include "segments.h"
 #include "lineinfo.h"
 
 
 
 
 
+static CodeRange* NewCodeRange (unsigned long Offs, unsigned long Size)
+/* Create and return a new CodeRange struct */
+{
+    /* Allocate memory */
+    CodeRange* R = xmalloc (sizeof (CodeRange));
+
+    /* Initialize the fields */
+    R->Offs = Offs;
+    R->Size = Size;
+
+    /* Return the new struct */
+    return R;
+}
+
+
+
 static LineInfo* NewLineInfo (void)
 /* Create and return a new LineInfo struct */
 {
@@ -59,6 +77,7 @@ static LineInfo* NewLineInfo (void)
     LI->File = 0;
     InitFilePos (&LI->Pos);
     InitCollection (&LI->Fragments);
+    InitCollection (&LI->CodeRanges);
 
     /* Return the new struct */
     return LI;
@@ -85,3 +104,88 @@ LineInfo* ReadLineInfo (FILE* F, ObjData* O)
 
 
 
+static void AddCodeRange (LineInfo* LI, unsigned long Offs, unsigned long Size)
+/* Add a range of code to this line */
+{
+    unsigned I;
+
+    /* Get a pointer to the collection */
+    Collection* CodeRanges = &LI->CodeRanges;
+
+    /* We will keep the CodeRanges collection sorted by starting offset,
+     * so we have to search for the correct insert position. Since in most
+     * cases, the fragments have increasing order, and there is usually not
+     * more than one or two ranges, we do a linear search.
+     */
+    for (I = 0; I < CollCount (CodeRanges); ++I) {
+       CodeRange* R = CollAtUnchecked (CodeRanges, I);
+               if (Offs < R->Offs) {
+
+                   /* Got the insert position */
+                   if (Offs + Size == R->Offs) {
+               /* Merge the two */
+                       R->Offs = Offs;
+                       R->Size += Size;
+                   } else {
+                       /* Insert a new entry */
+                       CollInsert (CodeRanges, NewCodeRange (Offs, Size), I);
+                   }
+
+                   /* Done */
+                   return;
+
+               } else if (R->Offs + R->Size == Offs) {
+
+           /* This is the regular case. Merge the two. */
+                   R->Size += Size;
+
+                   /* Done */
+                   return;
+
+               }
+    }
+
+    /* We must append an entry */
+    CollAppend (CodeRanges, NewCodeRange (Offs, Size));
+}
+
+
+
+void RelocLineInfo (struct Segment* S)
+/* Relocate the line info for a segment. */
+{
+    unsigned long Offs = 0;
+
+    /* 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) {
+
+                   /* Add the range for this fragment to the line info if there
+                    * is any
+                    */
+                   if (Frag->LI) {
+                       AddCodeRange (Frag->LI, Offs, Frag->Size);
+                   }
+
+                   /* Update the offset */
+                   Offs += Frag->Size;
+
+                   /* Next fragment */
+                   Frag = Frag->Next;
+               }
+
+               /* Next section */
+               Sec = Sec->Next;
+    }
+}
+
+
+
index 8a40126f328e695fc4e3d4d704249f37838cadc5..5b2a3a9831d8293640305d606d9646192e791ce1 100644 (file)
 
 
 /*****************************************************************************/
-/*                                  Data                                    */
+/*                                Forwards                                  */
 /*****************************************************************************/
 
 
 
+struct Segment;
+
+
+
+/*****************************************************************************/
+/*                                  Data                                    */
+/*****************************************************************************/
+
+
+
+typedef struct CodeRange CodeRange;
+struct CodeRange {
+    unsigned long Offs;
+    unsigned long Size;
+};
+
+
+
 typedef struct LineInfo LineInfo;
 struct LineInfo {
     struct FileInfo*    File;                /* File struct for this line */
     FilePos             Pos;                  /* File position */
     Collection          Fragments;            /* Fragments for this line */
+    Collection          CodeRanges;           /* Code ranges for this line */
 };
 
 
@@ -71,6 +90,9 @@ struct LineInfo {
 LineInfo* ReadLineInfo (FILE* F, ObjData* O);
 /* Read a line info from a file and return it */
 
+void RelocLineInfo (struct Segment* S);
+/* Relocate the line info for a segment. */
+
 
 
 /* End of lineinfo.h */
index ebc05846dee9fbe5a5420fbdccb7882903f8a0b9..18f93e84cccc84f542aba47a74814ad2e3ed9e5e 100644 (file)
@@ -226,6 +226,14 @@ static void OptConfig (const char* Opt, const char* Arg)
 
 
 
+static void OptDbgFile (const char* Opt, const char* Arg)
+/* Give the name of the debug file */
+{
+    DbgFileName = Arg;
+}
+
+
+
 static void OptHelp (const char* Opt, const char* Arg)
 /* Print usage information and exit */
 {
@@ -288,7 +296,8 @@ int main (int argc, char* argv [])
     /* Program long options */
     static const LongOpt OptTab[] = {
                { "--config",           1,      OptConfig               },
-               { "--help",             0,      OptHelp                 },
+       { "--dbgfile",          1,      OptDbgFile              },
+       { "--help",             0,      OptHelp                 },
        { "--mapfile",          1,      OptMapFile              },
        { "--start-addr",       1,      OptStartAddr            },
        { "--target",           1,      OptTarget               },
@@ -424,6 +433,9 @@ int main (int argc, char* argv [])
     }
     if (LabelFileName) {
        CreateLabelFile ();
+    }  
+    if (DbgFileName) {
+       CreateDbgFile ();
     }
 
     /* Dump the data for debugging */
index 3dfdd26708da49ca755e0fef1b8a246d90a52d6c..cc9b8ab3d1ed5016d0f039a152ab6d737971a536 100644 (file)
@@ -22,6 +22,7 @@ OBJS =        bin.o           \
        binfmt.o        \
        condes.o        \
        config.o        \
+       dbginfo.o       \
        dbgsyms.o       \
        error.o         \
        exports.o       \
@@ -41,7 +42,7 @@ OBJS =        bin.o           \
        scanner.o       \
        segments.o      \
        tgtcfg.o
-
+                        
 # -----------------------------------------------------------------------------
 # List of all config includes
 
index e967e958133b9a1d126275db67271e5dbba3728b..88ff18ddb09f0f9bd62d8b06e01e161daebab02c 100644 (file)
@@ -71,6 +71,7 @@ OBJS =        bin.obj         \
        binfmt.obj      \
        condes.obj      \
        config.obj      \
+       dbginfo.obj     \
        dbgsyms.obj     \
        error.obj       \
        exports.obj     \
@@ -115,6 +116,7 @@ FILE bin.obj
 FILE binfmt.obj
 FILE condes.obj
 FILE config.obj
+FILE dbginfo.obj
 FILE dbgsyms.obj
 FILE error.obj
 FILE exports.obj
@@ -124,7 +126,7 @@ FILE fileinfo.obj
 FILE fileio.obj
 FILE fragment.obj
 FILE global.obj
-FILE library.obj 
+FILE library.obj
 FILE lineinfo.obj
 FILE main.obj
 FILE mapfile.obj
index 8d31666fda0353899b7c33ac1d9b6f7daaf947fa..ff9c74f9865d0feadea18d5fb5ec3fe5d9676012 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       */
@@ -41,6 +41,7 @@
 #include "error.h"
 #include "objdata.h"
 #include "segments.h"
+#include "dbginfo.h"
 #include "dbgsyms.h"
 #include "exports.h"
 #include "config.h"
@@ -82,7 +83,7 @@ void CreateMapFile (void)
            for (I = 0; I < O->SectionCount; ++I) {
                const Section* S = O->Sections [I];
                /* Don't include zero sized sections if not explicitly
-                * requested
+                * requested
                 */
                if (VerboseMap || S->Size > 0) {
                            fprintf (F, "    %-15s   Offs = %06lX   Size = %06lX\n",
@@ -124,7 +125,7 @@ void CreateLabelFile (void)
 {
     ObjData* O;
 
-    /* Open the map file */
+    /* Open the label file */
     FILE* F = fopen (LabelFileName, "w");
     if (F == 0) {
        Error ("Cannot create label file `%s': %s", LabelFileName, strerror (errno));
@@ -168,3 +169,33 @@ void CreateLabelFile (void)
 
 
 
+void CreateDbgFile (void)
+/* Create a debug info file */
+{
+    ObjData* O;
+
+    /* Open the debug info file */
+    FILE* F = fopen (DbgFileName, "w");
+    if (F == 0) {
+       Error ("Cannot create label file `%s': %s", DbgFileName, strerror (errno));
+    }
+
+    /* Print line infos from all modules we have linked into the output file */
+    O = ObjRoot;
+    while (O) {
+       if (O->Flags & OBJ_HAVEDATA) {
+           /* We've linked this module */
+           PrintDbgInfo (O, F);
+
+       }
+       O = O->Next;
+    }
+
+    /* Close the file */
+    if (fclose (F) != 0) {
+       Error ("Error closing map file `%s': %s", DbgFileName, strerror (errno));
+    }
+}
+
+
+
index 5e63d418e5740d51ed3e994181caad735e154b74..91a50f28dd121eef0802fa83211db3aec034a377 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       */
@@ -54,6 +54,9 @@ void CreateMapFile (void);
 void CreateLabelFile (void);
 /* Create a label file */
 
+void CreateDbgFile (void);
+/* Create a debug info file */
+
 
 
 /* End of mapfile.h */
index 841e6df6c74b25de12cf475bc2063d376d1e1fa1..ad41fb77ceb2c14813c46221cdced9f9e42ee8ed 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1999-2000 Ullrich von Bassewitz                                       */
+/* (C) 1999-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       */
@@ -50,6 +50,7 @@
 #include "expr.h"
 #include "fileio.h"
 #include "global.h"
+#include "lineinfo.h"
 #include "o65.h"
 
 
@@ -72,7 +73,7 @@
 #define O65SEG_TEXT    0x02
 #define O65SEG_DATA    0x03
 #define O65SEG_BSS     0x04
-#define O65SEG_ZP      0x05
+#define O65SEG_ZP      0x05
 
 /* Relocation type codes for the o65 format */
 #define O65RELOC_WORD  0x80
@@ -82,8 +83,8 @@
 #define O65RELOC_SEG   0xa0
 
 /* O65 executable file header */
-typedef struct O65Header_ O65Header;
-struct O65Header_ {
+typedef struct O65Header O65Header;
+struct O65Header {
     unsigned       Version;            /* Version number for o65 format */
     unsigned        Mode;                      /* Mode word */
     unsigned long   TextBase;          /* Base address of text segment */
@@ -98,8 +99,8 @@ struct O65Header_ {
 };
 
 /* An o65 option */
-typedef struct O65Option_ O65Option;
-struct O65Option_ {
+typedef struct O65Option O65Option;
+struct O65Option {
     O65Option*     Next;               /* Next in option list */
     unsigned char   Type;              /* Type of option */
     unsigned char   Len;               /* Data length */
@@ -108,54 +109,54 @@ struct O65Option_ {
 
 /* A o65 relocation table */
 #define RELOC_BLOCKSIZE        4096
-typedef struct O65RelocTab_ O65RelocTab;
-struct O65RelocTab_ {
+typedef struct O65RelocTab O65RelocTab;
+struct O65RelocTab {
     unsigned       Size;               /* Size of the table */
     unsigned       Fill;               /* Amount used */
     unsigned char*  Buf;               /* Buffer, dynamically allocated */
 };
 
 /* Structure describing the format */
-struct O65Desc_ {
-    O65Header      Header;             /* File header */
+struct O65Desc {
+    O65Header      Header;             /* File header */
     O65Option*     Options;            /* List of file options */
     ExtSymTab*     Exports;            /* Table with exported symbols */
     ExtSymTab*     Imports;            /* Table with imported symbols */
-    unsigned       Undef;              /* Count of undefined symbols */
-    FILE*          F;                  /* The file we're writing to */
-    char*          Filename;           /* Name of the output file */
+    unsigned       Undef;              /* Count of undefined symbols */
+    FILE*          F;                  /* The file we're writing to */
+    char*          Filename;           /* Name of the output file */
     O65RelocTab*    TextReloc;         /* Relocation table for text segment */
     O65RelocTab*    DataReloc;         /* Relocation table for data segment */
 
-    unsigned       TextCount;          /* Number of segments assigned to .text */
-    SegDesc**      TextSeg;            /* Array of text segments */
-    unsigned       DataCount;          /* Number of segments assigned to .data */
-    SegDesc**      DataSeg;            /* Array of data segments */
-    unsigned       BssCount;           /* Number of segments assigned to .bss */
-    SegDesc**      BssSeg;             /* Array of bss segments */
-    unsigned       ZPCount;            /* Number of segments assigned to .zp */
-    SegDesc**      ZPSeg;              /* Array of zp segments */
+    unsigned       TextCount;          /* Number of segments assigned to .text */
+    SegDesc**      TextSeg;            /* Array of text segments */
+    unsigned       DataCount;          /* Number of segments assigned to .data */
+    SegDesc**      DataSeg;            /* Array of data segments */
+    unsigned       BssCount;           /* Number of segments assigned to .bss */
+    SegDesc**      BssSeg;             /* Array of bss segments */
+    unsigned       ZPCount;            /* Number of segments assigned to .zp */
+    SegDesc**      ZPSeg;              /* Array of zp segments */
 
     /* Temporary data for writing segments */
     unsigned long   SegSize;
     O65RelocTab*    CurReloc;
-    long           LastOffs;
+    long           LastOffs;
 };
 
 /* Structure for parsing expression trees */
-typedef struct ExprDesc_ ExprDesc;
-struct ExprDesc_ {
-    O65Desc*       D;                  /* File format descriptor */
-    long           Val;                /* The offset value */
+typedef struct ExprDesc ExprDesc;
+struct ExprDesc {
+    O65Desc*               D;                  /* File format descriptor */
+    long                   Val;                /* The offset value */
     int                    TooComplex;         /* Expression too complex */
-    Section*       SegRef;             /* Section referenced if any */
-    ExtSym*        ExtRef;             /* External reference if any */
+    Section*               SegRef;             /* Section referenced if any */
+    ExtSym*                ExtRef;             /* External reference if any */
 };
 
 
 
 /*****************************************************************************/
-/*                            Helper functions                              */
+/*                            Helper functions                              */
 /*****************************************************************************/
 
 
@@ -343,7 +344,7 @@ static void O65WriteReloc (O65RelocTab* R, FILE* F)
 
 
 /*****************************************************************************/
-/*                             Option handling                              */
+/*                             Option handling                              */
 /*****************************************************************************/
 
 
@@ -380,7 +381,7 @@ static void FreeO65Option (O65Option* O)
 
 
 /*****************************************************************************/
-/*                    Subroutines to write o65 sections                     */
+/*                    Subroutines to write o65 sections                     */
 /*****************************************************************************/
 
 
@@ -427,7 +428,7 @@ static void O65WriteHeader (O65Desc* D)
 
 
 static unsigned O65WriteExpr (ExprNode* E, int Signed, unsigned Size,
-                                     unsigned long Offs, void* Data)
+                                     unsigned long Offs, void* Data)
 /* Called from SegWrite for an expression. Evaluate the expression, check the
  * range and write the expression value to the file, update the relocation
  * table.
@@ -522,7 +523,7 @@ static unsigned O65WriteExpr (ExprNode* E, int Signed, unsigned Size,
                break;
 
            case 2:
-               RelocType = O65RELOC_WORD;
+               RelocType = O65RELOC_WORD;
                break;
 
            case 3:
@@ -580,6 +581,7 @@ static void O65WriteSeg (O65Desc* D, SegDesc** Seg, unsigned Count, int DoWrite)
 
        /* Write this segment */
        if (DoWrite) {
+           RelocLineInfo (S->Seg);
                    SegWrite (D->F, S->Seg, O65WriteExpr, D);
        }
 
@@ -1069,4 +1071,3 @@ void O65WriteTarget (O65Desc* D, File* F)
 
 
 
-
index d1e6609dd6ec18dae2881dbb01781efd05fb6c1f..f7d1e730553098d80c40222485a8ae5faf5b218e 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1999     Ullrich von Bassewitz                                        */
-/*              Wacholderweg 14                                              */
-/*              D-70597 Stuttgart                                            */
-/* EMail:       uz@musoftware.de                                             */
+/* (C) 1999-2001 Ullrich von Bassewitz                                       */
+/*               Wacholderweg 14                                             */
+/*               D-70597 Stuttgart                                           */
+/* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -52,7 +52,7 @@
 
 
 /* Structure describing the format */
-typedef struct O65Desc_ O65Desc;
+typedef struct O65Desc O65Desc;
 
 /* Option tags */
 #define O65OPT_FILENAME                0
index b11794236c87cefd529c5b84d331781062d0d133..7eabc472ed334c4b8c1fcf2fc51746a162214b7d 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      */
@@ -206,8 +206,8 @@ void ObjAdd (FILE* Obj, const char* Name)
     ObjReadHeader (Obj, &O->Header, Name);
 
     /* Initialize the object module data structure */
-    O->Name              = xstrdup (GetModule (Name));
-    O->Flags             = OBJ_HAVEDATA;
+    O->Name  = xstrdup (GetModule (Name));
+    O->Flags = OBJ_HAVEDATA;
 
     /* Read the files list from the object file */
     fseek (Obj, O->Header.FileOffs, SEEK_SET);
index f2046bbd370929fb046e4d9cc66617f4fa0ac2d8..fbf58d4f2a2d13f7e69e8e501b1e9c4b43568138 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       */
 
 #include <stdio.h>
 
-#include "../common/objdefs.h"
-
+/* common */
+#include "objdefs.h"
+         
+/* ld65 */
 #include "objdata.h"
 
 
@@ -64,6 +66,9 @@ void ObjReadExports (FILE* F, ObjData* O);
 void ObjReadDbgSyms (FILE* F, ObjData* O);
 /* Read the debug symbols from a file at the current position */
 
+void ObjReadLineInfos (FILE* F, ObjData* O);
+/* Read the line infos from a file at the current position */
+
 void ObjReadSections (FILE* F, ObjData* O);
 /* Read the section data from a file at the current position */
 
index 3946fbad6b27c02c3b10ea5b10aee9af42cfbed3..0ae19b6d6398e8db36dd3ca5bf96f884cbf96656 100644 (file)
@@ -312,7 +312,13 @@ Section* ReadSection (FILE* F, ObjData* O)
        LineInfoIndex = ReadVar (F);
        if (LineInfoIndex) {
            --LineInfoIndex;
-           CHECK (LineInfoIndex < O->LineInfoCount);
+           if (LineInfoIndex >= O->LineInfoCount) {
+                       Internal ("In module `%s', file `%s', line %lu: Invalid line "
+                         "info with index %u (max count %u)",
+                         GetObjFileName (O),
+                         GetSourceFileName (O, Frag->Pos.Name),
+                                 Frag->Pos.Line, 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 */
@@ -495,6 +501,7 @@ void SegWrite (FILE* Tgt, Segment* S, SegWriteFunc F, void* Data)
 
        /* 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;