]> git.sur5r.net Git - cc65/commitdiff
Allow to dump scope information.
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 31 Jul 2011 12:25:44 +0000 (12:25 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 31 Jul 2011 12:25:44 +0000 (12:25 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@5092 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/od65/dump.c
src/od65/dump.h
src/od65/global.h
src/od65/main.c

index de9fa3c39ce03c3aea25b3c786a07debc01bbd79..b5b3f2a837884d24a798ef2f08ba2376ac287618 100644 (file)
@@ -285,6 +285,12 @@ void DumpObjHeader (FILE* F, unsigned long Offset)
 
     /* String pool */
     DumpObjHeaderSection ("String pool", H.StrPoolOffs, H.StrPoolSize);
+
+    /* Assertions */
+    DumpObjHeaderSection ("Assertions", H.AssertOffs, H.AssertSize);
+
+    /* Scopes */
+    DumpObjHeaderSection ("Scopes", H.ScopeOffs, H.ScopeSize);
 }
 
 
@@ -754,6 +760,81 @@ void DumpObjLineInfo (FILE* F, unsigned long Offset)
 
 
 
+void DumpObjScopes (FILE* F, unsigned long Offset)
+/* Dump the scopes from an object file */
+{
+    ObjHeader   H;
+    Collection  StrPool = AUTO_COLLECTION_INITIALIZER;
+    unsigned    Count;
+    unsigned    I;
+
+    /* Seek to the header position and read the header */
+    FileSetPos (F, Offset);
+    ReadObjHeader (F, &H);
+
+    /* Seek to the start of the string pool and read it */
+    FileSetPos (F, Offset + H.StrPoolOffs);
+    ReadStrPool (F, &StrPool);
+
+    /* Seek to the start of scopes */
+    FileSetPos (F, Offset + H.ScopeOffs);
+
+    /* Output a header */
+    printf ("  Scopes:\n");
+
+    /* Check if the object file was compiled with debug info */
+    if ((H.Flags & OBJ_FLAGS_DBGINFO) == 0) {
+       /* Print that there no scopes and bail out */
+       printf ("    Count:%27u\n", 0);
+       return;
+    }
+
+    /* Read the number of scopes and print it */
+    Count = ReadVar (F);
+    printf ("    Count:%27u\n", Count);
+
+    /* Read and print all scopes */
+    for (I = 0; I < Count; ++I) {
+
+        const char*     Name;
+        unsigned        Len;
+        unsigned        SegCount;
+        unsigned        J;
+
+       /* Print the header */
+       printf ("    Index:%27u\n", I);
+
+       /* Print the data */
+        printf ("      Id:%28lu\n",             ReadVar (F));
+        printf ("      Parent id:%21lu\n",      ReadVar (F));
+        printf ("      Lexical level:%17lu\n",  ReadVar (F));
+        printf ("      Flags:%25lu\n",          ReadVar (F));
+        printf ("      Type:%26lu\n",           ReadVar (F));
+
+        /* Resolve and print the name */
+               Name = GetString (&StrPool, ReadVar (F));
+       Len  = strlen (Name);
+       printf ("      Name:%*s\"%s\"\n", (int)(24-Len), "", Name);
+
+        /* Segment ranges */
+        SegCount = ReadVar (F);
+        printf ("      Segment ranges:\n");
+        printf ("        Count:%23u\n", SegCount);
+
+        for (J = 0; J < SegCount; ++J) {
+            printf ("        Index:%23u\n", J);
+            printf ("          Segment:%19lu\n", ReadVar (F));
+            printf ("          Start:%13s0x%06lX\n", "", ReadVar (F));
+            printf ("          End:%15s0x%06lX\n", "", ReadVar (F));
+        }
+    }
+
+    /* Destroy the string pool */
+    DestroyStrPool (&StrPool);
+}
+
+
+
 void DumpObjSegSize (FILE* F, unsigned long Offset)
 /* Dump the sizes of the segment in the object file */
 {
index 43d96a7e14a2ab2a8f289ad9f575e68134040fc2..23971fe83f1dafa72910f75aaed1aecc3a7af033 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000-2002 Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
-/* EMail:        uz@cc65.org                                                 */
+/* (C) 2000-2011, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -72,6 +72,9 @@ void DumpObjDbgSyms (FILE* F, unsigned long Offset);
 void DumpObjLineInfo (FILE* F, unsigned long Offset);
 /* Dump the line infos from an object file */
 
+void DumpObjScopes (FILE* F, unsigned long Offset);
+/* Dump the scopes from an object file */
+
 void DumpObjSegSize (FILE* F, unsigned long Offset);
 /* Dump the sizes of the segment in the object file */
 
index 09eab2c110f7100b785e57ee1e226ee2351e045b..7cc531f6e044503a826fd3a9f35e256ce4368901 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000-2002 Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* (C) 2000-2011, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -39,7 +39,7 @@
 
 
 /*****************************************************************************/
-/*                                  Data                                    */
+/*                                  Data                                    */
 /*****************************************************************************/
 
 
@@ -52,7 +52,8 @@
 #define D_EXPORTS              0x0020U         /* Dump exported symbols */
 #define D_DBGSYMS              0x0040U         /* Dump debug symbols */
 #define D_LINEINFO      0x0080U         /* Dump line infos */
-#define D_SEGSIZE       0x0100U         /* Dump segment sizes */
+#define D_SCOPES        0x0100U         /* Dump scopes */
+#define D_SEGSIZE       0x0200U         /* Dump segment sizes */
 #define D_ALL                  0xFFFFU         /* Dump anything */
 
 
@@ -67,4 +68,3 @@ extern unsigned       What;           /* What should get dumped? */
 
 
 
-
index aa046634f0a16117346acf3e9c0aa54a70ba907c..a637b76517d289bcda2188577e8d91a0d6b962b9 100644 (file)
@@ -168,8 +168,17 @@ static void OptDumpOptions (const char* Opt attribute ((unused)),
 
 
 
+static void OptDumpScopes (const char* Opt attribute ((unused)),
+                          const char* Arg attribute ((unused)))
+/* Dump the scopes in the object file */
+{
+    What |= D_SCOPES;
+}
+
+
+
 static void OptDumpSegments (const char* Opt attribute ((unused)),
-                            const char* Arg attribute ((unused)))
+                            const char* Arg attribute ((unused)))
 /* Dump the segments in the object file */
 {
     What |= D_SEGMENTS;
@@ -262,6 +271,9 @@ static void DumpFile (const char* Name)
        if (What & D_LINEINFO) {
            DumpObjLineInfo (F, 0);
        }
+               if (What & D_SCOPES) {
+           DumpObjScopes (F, 0);
+       }
        if (What & D_SEGSIZE) {
                    DumpObjSegSize (F, 0);
        }
@@ -286,6 +298,7 @@ int main (int argc, char* argv [])
        { "--dump-imports",     0,      OptDumpImports          },
         { "--dump-lineinfo",    0,      OptDumpLineInfo         },
        { "--dump-options",     0,      OptDumpOptions          },
+        { "--dump-scopes",      0,      OptDumpScopes           },
        { "--dump-segments",    0,      OptDumpSegments         },
                { "--dump-segsize",     0,      OptDumpSegSize          },
        { "--help",             0,      OptHelp                 },