/* */
/* */
/* */
-/* (C) 2002-2011, Ullrich von Bassewitz */
+/* (C) 2002-2012, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
#include "lidefs.h"
#include "objdefs.h"
#include "optdefs.h"
-#include "segdefs.h"
+#include "scopedefs.h"
#include "symdefs.h"
#include "xmalloc.h"
+static void SkipSpanList (FILE* F)
+/* Skip a span list from the given file */
+{
+ /* Count preceeds the list */
+ unsigned long Count = ReadVar (F);
+
+ /* Skip indices */
+ while (Count--) {
+ (void) ReadVar (F);
+ }
+}
+
+
+
static void SkipExpr (FILE* F)
/* Skip an expression from the given file */
{
break;
case EXPR_SECTION:
+ case EXPR_BANK:
/* Read the segment number */
- (void) Read8 (F);
+ (void) ReadVar (F);
break;
default:
+static const char* GetScopeType (unsigned Type)
+/* Return the name of a scope type */
+{
+ switch (Type) {
+ case SCOPE_GLOBAL: return "Global scope";
+ case SCOPE_FILE: return "File scope";
+ case SCOPE_SCOPE: return ".SCOPE or .PROC";
+ case SCOPE_STRUCT: return ".STRUCT";
+ case SCOPE_ENUM: return ".ENUM";
+ case SCOPE_UNDEF: return "Undefined";
+ default: return "Unknown scope type";
+ }
+}
+
+
+
void DumpObjHeader (FILE* F, unsigned long Offset)
/* Dump the header of the given object file */
{
/* String pool */
DumpObjHeaderSection ("String pool", H.StrPoolOffs, H.StrPoolSize);
+
+ /* Assertions */
+ DumpObjHeaderSection ("Assertions", H.AssertOffs, H.AssertSize);
+
+ /* Scopes */
+ DumpObjHeaderSection ("Scopes", H.ScopeOffs, H.ScopeSize);
}
case OPT_ARGNUM:
printf (" Data:%26lu", Val);
- if (Type == OPT_DATETIME) {
+ if (Type == OPT_DATETIME) {
/* Print the time as a string */
printf (" (%s)", TimeToStr (Val));
}
unsigned long NextSeg = ftell (F) + DataSize;
const char* Name = GetString (&StrPool, ReadVar (F));
unsigned Len = strlen (Name);
- unsigned long Size = Read32 (F);
- unsigned Align = (1U << Read8 (F));
+ unsigned Flags = ReadVar (F);
+ unsigned long Size = ReadVar (F);
+ unsigned long Align = ReadVar (F);
unsigned char AddrSize = Read8 (F);
unsigned long FragCount = ReadVar (F);
/* Print the data */
printf (" Name:%*s\"%s\"\n", (int)(24-Len), "", Name);
+ printf (" Flags:%25u\n", Flags);
printf (" Size:%26lu\n", Size);
- printf (" Alignment:%21u\n", Align);
+ printf (" Alignment:%21lu\n", Align);
printf (" Address size:%14s0x%02X (%s)\n", "", AddrSize,
AddrSizeToStr (AddrSize));
printf (" Fragment count:%16lu\n", FragCount);
const char* Name = GetString (&StrPool, ReadVar (F));
unsigned Len = strlen (Name);
- /* Skip the line infos */
+ /* Skip both line info lists */
+ SkipLineInfoList (F);
SkipLineInfoList (F);
/* Print the header */
Size = ReadVar (F);
}
- /* Skip the line infos */
+ /* Skip both line infos lists */
+ SkipLineInfoList (F);
SkipLineInfoList (F);
/* Print the header */
unsigned long Value = 0;
unsigned long Size = 0;
+ unsigned ImportId = 0;
+ unsigned ExportId = 0;
/* Read the data for one symbol */
unsigned Type = ReadVar (F);
unsigned char AddrSize = Read8 (F);
+ unsigned long Owner = ReadVar (F);
const char* Name = GetString (&StrPool, ReadVar (F));
unsigned Len = strlen (Name);
if (SYM_IS_CONST (Type)) {
if (SYM_HAS_SIZE (Type)) {
Size = ReadVar (F);
}
+ if (SYM_IS_IMPORT (Type)) {
+ ImportId = ReadVar (F);
+ }
+ if (SYM_IS_EXPORT (Type)) {
+ ExportId = ReadVar (F);
+ }
- /* Skip the line infos */
+ /* Skip both line info lists */
+ SkipLineInfoList (F);
SkipLineInfoList (F);
/* Print the header */
printf (" Type:%22s0x%02X (%s)\n", "", Type, GetExportFlags (Type, 0));
printf (" Address size:%14s0x%02X (%s)\n", "", AddrSize,
AddrSizeToStr (AddrSize));
+ printf (" Owner:%25lu\n", Owner);
printf (" Name:%*s\"%s\"\n", (int)(24-Len), "", Name);
if (SYM_IS_CONST (Type)) {
printf (" Value:%15s0x%08lX (%lu)\n", "", Value, Value);
}
if (SYM_HAS_SIZE (Type)) {
- printf (" Size:%16s0x%04lX (%lu)\n", "", Size, Size);
+ printf (" Size:%20s0x%04lX (%lu)\n", "", Size, Size);
+ }
+ if (SYM_IS_IMPORT (Type)) {
+ printf (" Import:%24u\n", ImportId);
+ }
+ if (SYM_IS_EXPORT (Type)) {
+ printf (" Export:%24u\n", ExportId);
}
}
for (I = 0; I < Count; ++I) {
FilePos Pos;
-
- /* Type of line info */
- unsigned Type = ReadVar (F);
+ unsigned Type;
/* File position of line info */
ReadFilePos (F, &Pos);
+ /* Type of line info */
+ Type = ReadVar (F);
+
+ /* Skip the spans */
+ SkipSpanList (F);
+
/* Print the header */
printf (" Index:%27u\n", I);
/* Print the data */
printf (" Type:%26u\n", LI_GET_TYPE (Type));
printf (" Count:%25u\n", LI_GET_COUNT (Type));
- printf (" Line:%26lu\n", Pos.Line);
+ printf (" Line:%26u\n", Pos.Line);
printf (" Col:%27u\n", Pos.Col);
printf (" Name:%26u\n", Pos.Name);
}
+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;
+
+ /* Read the data */
+ unsigned ParentId = ReadVar (F);
+ unsigned LexicalLevel = ReadVar (F);
+ unsigned Flags = ReadVar (F);
+ const char* ScopeType = GetScopeType (ReadVar (F));
+
+ /* Print the header */
+ printf (" Index:%27u\n", I);
+
+ /* Print the data */
+ printf (" Parent id:%21u\n", ParentId);
+ printf (" Lexical level:%17u\n", LexicalLevel);
+ printf (" Flags:%21s0x%02X\n", "", Flags);
+ printf (" Type:%26s\n", ScopeType);
+
+ /* Resolve and print the name */
+ Name = GetString (&StrPool, ReadVar (F));
+ Len = strlen (Name);
+ printf (" Name:%*s\"%s\"\n", (int)(24-Len), "", Name);
+
+ /* Size */
+ if (SCOPE_HAS_SIZE (Flags)) {
+ unsigned long Size = ReadVar (F);
+ printf (" Size:%20s0x%04lX (%lu)\n", "", Size, Size);
+ }
+
+ /* Label */
+ if (SCOPE_HAS_LABEL (Flags)) {
+ unsigned LabelId = ReadVar (F);
+ printf (" Label id:%22u\n", LabelId);
+ }
+
+ /* Skip the spans */
+ SkipSpanList (F);
+ }
+
+ /* Destroy the string pool */
+ DestroyStrPool (&StrPool);
+}
+
+
+
void DumpObjSegSize (FILE* F, unsigned long Offset)
/* Dump the sizes of the segment in the object file */
{
unsigned long NextSeg = ftell (F) + DataSize;
const char* Name = GetString (&StrPool, ReadVar (F));
unsigned Len = strlen (Name);
- unsigned long Size = Read32 (F);
+ unsigned long Size = ReadVar (F);
/* Skip alignment, type and fragment count */
- (void) Read8 (F);
+ (void) ReadVar (F);
(void) Read8 (F);
(void) ReadVar (F);
+