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 WriteScopes (void) /* Write the scope table to the object file */ { /* Tell the object file module that we're about to start the scopes */ ObjStartScopes (); /* We will write scopes only if debug symbols are requested */ if (DbgSyms) { /* Get head of list */ SymTable* S = RootScope; /* Write the scope count to the file */ ObjWriteVar (ScopeCount); /* Walk through all scopes and write them to the file */ while (S) { /* Flags for this scope */ unsigned Flags = 0; /* Check if this scope has a size. If so, remember it in the ** flags. */ long Size; SymEntry* SizeSym = FindSizeOfScope (S); if (SizeSym != 0 && SymIsConst (SizeSym, &Size)) { Flags |= SCOPE_SIZE; } /* Check if the scope has a label */ if (S->Label) { Flags |= SCOPE_LABELED; } /* Scope must be defined */ CHECK (S->Type != SCOPE_UNDEF); /* Id of parent scope */ if (S->Parent) { ObjWriteVar (S->Parent->Id); } else { ObjWriteVar (0); } /* Lexical level */ ObjWriteVar (S->Level); /* Scope flags */ ObjWriteVar (Flags); /* Type of scope */ ObjWriteVar (S->Type); /* Name of the scope */ ObjWriteVar (S->Name); /* If the scope has a size, write it to the file */ if (SCOPE_HAS_SIZE (Flags)) { ObjWriteVar (Size); } /* If the scope has a label, write its id to the file */ if (SCOPE_HAS_LABEL (Flags)) { ObjWriteVar (S->Label->DebugSymId); } /* Spans for this scope */ WriteSpanList (&S->Spans); /* Next scope */ S = S->Next; } } else { /* No debug info requested */ ObjWriteVar (0); } /* Done writing the scopes */ ObjEndScopes (); }