Exemple #1
0
void DumpObjDbgSyms (FILE* F, unsigned long Offset)
/* Dump the debug symbols 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 the debug syms */
    FileSetPos (F, Offset + H.DbgSymOffs);

    /* Output a header */
    printf ("  Debug symbols:\n");

    /* Check if the object file was compiled with debug info */
    if ((H.Flags & OBJ_FLAGS_DBGINFO) == 0) {
	/* Print that there no debug symbols and bail out */
	printf ("    Count:%27u\n", 0);
	return;
    }

    /* Read the number of exports and print it */
    Count = ReadVar (F);
    printf ("    Count:%27u\n", Count);

    /* Read and print all debug symbols */
    for (I = 0; I < Count; ++I) {

    	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)) {
	    Value = Read32 (F);
	} else {
	    SkipExpr (F);
	}
        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 both line info lists */
        SkipLineInfoList (F);
        SkipLineInfoList (F);

	/* Print the header */
	printf ("    Index:%27u\n", I);

	/* Print the data */
       	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:%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);
	}
    }

    /* Destroy the string pool */
    DestroyStrPool (&StrPool);
}
Exemple #2
0
void WriteDbgSyms (void)
/* Write a list of all symbols to the object file */
{
    unsigned Count;
    SymEntry* S;

    /* Tell the object file module that we're about to start the debug info */
    ObjStartDbgSyms ();

    /* Check if debug info is requested */
    if (DbgSyms) {

        /* Walk through the list, give each symbol an id and count them */
        Count = 0;
        S = SymList;
        while (S) {
            if (IsDbgSym (S)) {
                S->DebugSymId = Count++;
            }
            S = S->List;
        }

        /* Write the symbol count to the list */
        ObjWriteVar (Count);

        /* Walk through list and write all symbols to the file. Ignore size
        ** symbols.
        */
        S = SymList;
        while (S) {
            if (IsDbgSym (S)) {

                /* Get the expression bits and the value */
                long ConstVal;
                unsigned SymFlags = GetSymInfoFlags (S, &ConstVal);

                /* Check if this symbol has a size. If so, remember it in the
                ** flags.
                */
                long Size;
                SymEntry* SizeSym = FindSizeOfSymbol (S);
                if (SizeSym != 0 && SymIsConst (SizeSym, &Size)) {
                    SymFlags |= SYM_SIZE;
                }

                /* Write the type */
                ObjWriteVar (SymFlags);

                /* Write the address size */
                ObjWrite8 (S->AddrSize);

                /* Write the id of the parent. For normal symbols, this is a
                ** scope (symbol table), for cheap locals, it's a symbol.
                */
                if (SYM_IS_STD (SymFlags)) {
                    ObjWriteVar (S->Sym.Tab->Id);
                } else {
                    ObjWriteVar (S->Sym.Entry->DebugSymId);
                }

                /* Write the name */
                ObjWriteVar (S->Name);

                /* Write the value */
                if (SYM_IS_CONST (SymFlags)) {
                    /* Constant value */
                    ObjWrite32 (ConstVal);
                } else {
                    /* Expression involved */
                    WriteExpr (S->Expr);
                }

                /* If the symbol has a size, write it to the file */
                if (SYM_HAS_SIZE (SymFlags)) {
                    ObjWriteVar (Size);
                }

                /* If the symbol is an im- or export, write out the ids */
                if (SYM_IS_IMPORT (SymFlags)) {
                    ObjWriteVar (GetSymImportId (S));
                }
                if (SYM_IS_EXPORT (SymFlags)) {
                    ObjWriteVar (GetSymExportId (S));
                }

                /* Write the line infos */
                WriteLineInfo (&S->DefLines);
                WriteLineInfo (&S->RefLines);
            }
            S = S->List;
        }

    } else {

        /* No debug symbols */
        ObjWriteVar (0);

    }

    /* Write the high level symbols */
    WriteHLLDbgSyms ();

    /* Done writing debug symbols */
    ObjEndDbgSyms ();
}
Exemple #3
0
void DumpObjExports (FILE* F, unsigned long Offset)
/* Dump the exports in the 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 the exports */
    FileSetPos (F, Offset + H.ExportOffs);

    /* Output a header */
    printf ("  Exports:\n");

    /* Read the number of exports and print it */
    Count = ReadVar (F);
    printf ("    Count:%27u\n", Count);

    /* Read and print all exports */
    for (I = 0; I < Count; ++I) {

	unsigned long 	Value = 0;
        unsigned long   Size = 0;
       	unsigned char  	ConDes[CD_TYPE_COUNT];
       	const char*    	Name;
	unsigned	Len;


       	/* Read the data for one export */
       	unsigned Type          = ReadVar (F);
        unsigned char AddrSize = Read8 (F);
	ReadData (F, ConDes, SYM_GET_CONDES_COUNT (Type));
       	Name  = GetString (&StrPool, ReadVar (F));
	Len   = strlen (Name);
       	if (SYM_IS_CONST (Type)) {
	    Value = Read32 (F);
	} else {
       	    SkipExpr (F);
	}
        if (SYM_HAS_SIZE (Type)) {
            Size = ReadVar (F);
        }

        /* Skip both line infos lists */
        SkipLineInfoList (F);
        SkipLineInfoList (F);

	/* Print the header */
	printf ("    Index:%27u\n", I);

	/* Print the data */
       	printf ("      Type:%22s0x%02X  (%s)\n", "", Type, GetExportFlags (Type, ConDes));
	printf ("      Address size:%14s0x%02X  (%s)\n", "", AddrSize,
                AddrSizeToStr (AddrSize));
	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);
	}
    }

    /* Destroy the string pool */
    DestroyStrPool (&StrPool);
}
Exemple #4
0
void WriteExports (void)
/* Write the exports list to the object file */
{
    SymEntry* S;
    unsigned Type;

    /* Tell the object file module that we're about to start the exports */
    ObjStartExports ();

    /* Write the export count to the list */
    ObjWriteVar (ExportCount);

    /* Walk throught list and write all exports to the file */
    S = SymList;
    while (S) {
        if ((S->Flags & (SF_UNUSED | SF_EXPORT)) == SF_EXPORT) {

            /* Get the expression bits and the value */
            long ConstVal;
            unsigned SymFlags = GetSymInfoFlags (S, &ConstVal);

            /* Check if this symbol has a size. If so, remember it in the
            ** flags.
            */
            long Size;
            SymEntry* SizeSym = FindSizeOfSymbol (S);
            if (SizeSym != 0 && SymIsConst (SizeSym, &Size)) {
                SymFlags |= SYM_SIZE;
            }

            /* Count the number of ConDes types */
            for (Type = 0; Type < CD_TYPE_COUNT; ++Type) {
                if (S->ConDesPrio[Type] != CD_PRIO_NONE) {
                    SYM_INC_CONDES_COUNT (SymFlags);
                }
            }

            /* Write the type and the export size */
            ObjWriteVar (SymFlags);
            ObjWrite8 (S->ExportSize);

            /* Write any ConDes declarations */
            if (SYM_GET_CONDES_COUNT (SymFlags) > 0) {
                for (Type = 0; Type < CD_TYPE_COUNT; ++Type) {
                    unsigned char Prio = S->ConDesPrio[Type];
                    if (Prio != CD_PRIO_NONE) {
                        ObjWrite8 (CD_BUILD (Type, Prio));
                    }
                }
            }

            /* Write the name */
            ObjWriteVar (S->Name);

            /* Write the value */
            if (SYM_IS_CONST (SymFlags)) {
                /* Constant value */
                ObjWrite32 (ConstVal);
            } else {
                /* Expression involved */
                WriteExpr (S->Expr);
            }

            /* If the symbol has a size, write it to the file */
            if (SYM_HAS_SIZE (SymFlags)) {
                ObjWriteVar (Size);
            }

            /* Write the line infos */
            WriteLineInfo (&S->DefLines);
            WriteLineInfo (&S->RefLines);
        }
        S = S->List;
    }

    /* Done writing exports */
    ObjEndExports ();
}