Exemplo n.º 1
0
bool ObjIeeeAscii::ExternalSymbol(const char *buffer, eParseType ParseType)
{
    if (!file)
        ThrowSyntax(buffer, ParseType);
    int index = 0;
    ObjString name = GetSymbolName(buffer, &index);
    ObjSymbol *sym = factory->MakeExternalSymbol(name, index);
    PutSymbol(externals, index, sym);
    return false;
}
Exemplo n.º 2
0
bool ObjIeeeAscii::LocalSymbol(const char *buffer, eParseType ParseType)
{
    if (!file)
        ThrowSyntax(buffer, ParseType);
    int index = 0;
    ObjString name = GetSymbolName(buffer, &index);
    ObjSymbol *sym = factory->MakeLocalSymbol(name, index);
    PutSymbol(locals, index, sym);
    sym->SetSourceFile(GetFile(0));
    return false;
}
Exemplo n.º 3
0
RVALUE FindWatSymbol( address *addr, syminfo *si, int getsrcinfo )
{
    DWORD       symoff;
    DWORD       line;
    BOOL        ret;
    if( !GetSymbolName( addr, si->name, &symoff ) ) {
        return( NOT_FOUND );
    }
    si->symoff = symoff;
    if( getsrcinfo ) {
        ret = GetLineNum( addr, si->filename, MAX_FILE_NAME, &line );
        if( !ret ) return( NOT_FOUND );
        si->linenum = line;
    }
    return( FOUND );
}
Exemplo n.º 4
0
/******************************************************************************
 * Function Name: AddBindingSymbol
 *
 * Inputs       : 
 * Outputs      : 
 * Returns      : 
 * Globals Used : -
 *
 * Description  : Add a binding symbol entry
 *****************************************************************************/
static GLSLBindingSymbol *AddBindingSymbol(GLSLCompilerPrivateData *psCPD,
										   GLSLUniFlexContext		*psUFContext,
										   HWSYMBOL					*psHWSymbol,
										   GLSLIdentifierData		*psIdentifierData,
										   GLSLBindingSymbolList	*psBindingSymbolList)
{
	GLSLBindingSymbol	*psBindingSymbol = IMG_NULL;
	IMG_CHAR *pszName;
	IMG_BYTE *pbyConstantData = psIdentifierData->pvConstantData;

	/* Get a symbol entry */
	if(psBindingSymbolList->uNumBindings == psBindingSymbolList->uMaxBindingEntries)
	{
		IMG_UINT32 uNewEntries = psBindingSymbolList->uMaxBindingEntries + 32;
		psBindingSymbolList->psBindingSymbolEntries = DebugMemRealloc(psBindingSymbolList->psBindingSymbolEntries, 
			uNewEntries * sizeof(GLSLBindingSymbol));
		if(psBindingSymbolList->psBindingSymbolEntries == IMG_NULL)
		{
			LOG_INTERNAL_ERROR(("AddTopLevelBindingSymbols: Failed to extend the active symbol list \n"));
			return IMG_NULL;
		}

		psBindingSymbolList->uMaxBindingEntries = uNewEntries;
	}

	psBindingSymbol = &psBindingSymbolList->psBindingSymbolEntries[psBindingSymbolList->uNumBindings];

	psBindingSymbolList->uNumBindings++;

	/* Work out the name and fill in */
	pszName = (IMG_CHAR *)GetSymbolName(psUFContext->psSymbolTable, psHWSymbol->uSymbolId);
	psBindingSymbol->pszName = DebugMemAlloc(strlen(pszName) + 1);
	if(psBindingSymbol->pszName == IMG_NULL)
	{
		LOG_INTERNAL_ERROR(("AddTopLevelBindingSymbols: Failed to allocate memory for a symbol name \n"));
		return IMG_NULL;
	}

	strcpy(psBindingSymbol->pszName, pszName);

	/* Fill in other information of the binding symbol */
	ProcessBindingSymbolEntry(psCPD, psUFContext, psHWSymbol, &pbyConstantData, psIdentifierData, psBindingSymbol, psBindingSymbolList);

	return psBindingSymbol;
}
Exemplo n.º 5
0
bool ObjIeeeAscii::AutoSymbol(const char *buffer, eParseType ParseType)
{
    if (!file)
        ThrowSyntax(buffer, ParseType);
    int index = 0;
    ObjString name = GetSymbolName(buffer, &index);
    
    ObjSymbol *sym = GetSymbol(autos,index);
    // autos can be forward declared in function type declarations
    if (sym)
    {
        sym->SetName(name);
    }
    else
    {
         sym = factory->MakeAutoSymbol(name, index);
        PutSymbol(autos, index, sym);
    }
    return false;
}
Exemplo n.º 6
0
void COMF2ASM::MakeExternalSymbolsTable() {
   // Make symbol table and string table entries for external symbols
   uint32 iextsym;                               // External symbol index
   uint32 isymo;                                 // Symbol index in disassembler
   uint32 NumExtSym = SymbolNameOffset.GetNumEntries(); // Number of external symbols
   ExtdefTranslation.SetNum(NumExtSym+1);        // Allocate space in symbol index translation table

   // Loop through external symbol names
   for (iextsym = 1; iextsym < NumExtSym; iextsym++) {

      // Get name
      const char * Name = GetSymbolName(iextsym);

      // Define symbol
      isymo = Disasm.AddSymbol(0, 0, 0, 0, 0x20, 0, Name);

      // Update table for translating old EXTDEF number to disassembler symbol index
      ExtdefTranslation[iextsym] = isymo;
   }
}
Exemplo n.º 7
0
void CCOFF::PublicNames(CMemoryBuffer * Strings, CSList<SStringEntry> * Index, int m) {
   // Make list of public names in object file
   // Strings will receive ASCIIZ strings
   // Index will receive records of type SStringEntry with Member = m

   // Interpret header:
   ParseFile();

   int isym = 0;  // current symbol table entry
   union {        // Pointer to symbol table
      SCOFF_SymTableEntry * p;  // Normal pointer
      int8 * b;                 // Used for address calculation
   } Symtab;

   // Loop through symbol table
   Symtab.p = SymbolTable;
   while (isym < NumberOfSymbols) {
      // Check within buffer
      if (Symtab.b >= Buf() + DataSize) {
         err.submit(2040);
         break;
      }

      // Search for public symbol
      if (Symtab.p->s.SectionNumber > 0 && Symtab.p->s.StorageClass == COFF_CLASS_EXTERNAL) {
         // Public symbol found
         SStringEntry se;
         se.Member = m;

         // Store name
         se.String = Strings->PushString(GetSymbolName(Symtab.p->s.Name));
         // Store name index
         Index->Push(se);
      }
      if ((int8)Symtab.p->s.NumAuxSymbols < 0) Symtab.p->s.NumAuxSymbols = 0;

      // Increment point
      isym += Symtab.p->s.NumAuxSymbols + 1;
      Symtab.b += (1 + Symtab.p->s.NumAuxSymbols) * SIZE_SCOFF_SymTableEntry;
   }
}
Exemplo n.º 8
0
/** Perform shell-like macro path expansion. */
void ExpandPath(char **path) {

   char *name;
   char *value;
   int x;

   Assert(path);

   for(x = 0; (*path)[x]; x++) {

      if((*path)[x] == '$') {
         name = GetSymbolName(*path + x + 1);
         value = getenv(name);
         ReplaceSymbol(path, name, value);
         Release(name);
         if(value) {
            x += strlen(value) - 1;
         }
      }

   }

}
Exemplo n.º 9
0
std::string NOINLINE GetCallstack(const char *indent, const char *ignoreFilter)
{
	static bool symInitialized = false;

	HANDLE currentProcess = GetCurrentProcess();
	HANDLE currentThread = GetCurrentThread();

	if (!symInitialized)
	{
		SymSetOptions(SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS | SYMOPT_LOAD_LINES);
		SymInitialize(currentProcess, NULL, TRUE);
		symInitialized = true;
	}

	CONTEXT context = {};
	STACKFRAME64 stack = {};

#ifdef _M_IX86
	context.ContextFlags = CONTEXT_CONTROL;
	_asm {
		call x
		x: pop eax
		mov context.Eip, eax
		mov context.Ebp, ebp
		mov context.Esp, esp
	}
#else
	RtlCaptureContext(&context);
#endif

	stack.AddrPC.Mode         = AddrModeFlat;
	stack.AddrStack.Mode      = AddrModeFlat;
	stack.AddrFrame.Mode      = AddrModeFlat;

#ifdef _M_X64
	// http://msdn.microsoft.com/en-us/library/windows/desktop/ms680646(v=vs.85).aspx
	stack.AddrPC.Offset       = context.Rip;
	stack.AddrStack.Offset    = context.Rsp;
	stack.AddrFrame.Offset    = context.Rbp;
	const DWORD machineType = IMAGE_FILE_MACHINE_AMD64;
#else
	stack.AddrPC.Offset       = context.Eip;
	stack.AddrStack.Offset    = context.Esp;
	stack.AddrFrame.Offset    = context.Ebp;
	const DWORD machineType = IMAGE_FILE_MACHINE_I386;
#endif
	const PVOID contextRecord = &context;

	std::string callstack;
	for(int i = 0; i < 128; ++i)
	{
		BOOL result = StackWalk64(machineType, currentProcess, currentThread, &stack, contextRecord, NULL, SymFunctionTableAccess64, SymGetModuleBase64, NULL);
		if (!result)
			break;

		std::string symbolName = GetSymbolName((void*)stack.AddrPC.Offset, currentProcess);
		if (symbolName.find(" GetCallstack") == symbolName.length() - strlen(" GetCallstack"))
			continue;
		if (!ignoreFilter || symbolName.find(ignoreFilter) == symbolName.npos)
		{
			if (!symbolName.empty())
			{
				callstack += indent;
				callstack += symbolName;
				callstack += '\n';
			}
			ignoreFilter = 0;
		}
		if (symbolName.find(" main") == symbolName.length() - strlen(" main"))
			break;
		if (stack.AddrReturn.Offset == 0)
			break;
	}
	return callstack;
}
Exemplo n.º 10
0
void PE_Debug::DumpSymbolInfo(std::ostream& dumpBuffer, DWORD relativeAddress )
{
    // Variables to keep track of function symbols
    PIMAGE_SYMBOL currentSym = COFFSymbolTable ;
    PIMAGE_SYMBOL fnSymbol = NULL ;
    DWORD maxFnAddress = 0 ;

#ifdef DUMPRAM
    InitSymbols();
#endif

    // Variables to keep track of file symbols
    PIMAGE_SYMBOL fileSymbol = NULL ;
    PIMAGE_SYMBOL latestFileSymbol = NULL ;
    for ( int i = 0; i < COFFSymbolCount; i++ )	{

        // Look for .text section where relativeAddress belongs to.
        // Keep track of the filename the .text section belongs to.
        if ( currentSym->StorageClass == IMAGE_SYM_CLASS_FILE )	{
            latestFileSymbol = currentSym;
        }

        // Borland uses "CODE" instead of the standard ".text" entry
        // Microsoft uses sections that only _begin_ with .text
        const char* symName = GetSymbolName( currentSym ) ;

        if ( strnicmp( symName, ".text", 5 ) == 0 || strcmpi( symName, "CODE" ) == 0 )	{
            if ( currentSym->Value <= relativeAddress )	{
                PIMAGE_AUX_SYMBOL auxSym = (PIMAGE_AUX_SYMBOL)(currentSym + 1) ;
                if ( currentSym->Value + auxSym->Section.Length >= relativeAddress )	{
                    fileSymbol = latestFileSymbol ;
                }
            }
        }


        // Look for the function with biggest address <= relativeAddress
        BOOL isFunction = ISFCN( currentSym->Type ); // Type == 0x20, See WINNT.H
        if ( isFunction && ( currentSym->StorageClass == IMAGE_SYM_CLASS_EXTERNAL || currentSym->StorageClass == IMAGE_SYM_CLASS_STATIC ) )	{

            if ( currentSym->Value <= relativeAddress && currentSym->Value > maxFnAddress )	{
                maxFnAddress = currentSym->Value ;
                fnSymbol = currentSym ;
            }
        }

#ifdef DUMPRAM
        if ( !isFunction && (currentSym->SectionNumber >= 0) )	{
            if ( (symName[0]=='_' && symName[1]!='$') || (symName[0]=='?') ) {

                char pretty_module[1024];

                if ( fileSymbol )	{
                    const char* auxSym = (const char*)(latestFileSymbol + 1) ;
                    char tmpFile[ VA_MAX_FILENAME_LEN ] ;
                    strcpy_s( tmpFile, auxSym ) ;
                    strcpy_s( pretty_module, tmpFile );
                    char *p = pretty_module+strlen(pretty_module)-1;
                    // Move p to point to first letter of EXE filename
                    while( (*p!='\\') && (*p!='/') && (*p!=':') )
                        p--;
                    p++;
                    if ( strlen(p) < 1 ) {
                        strcpy_s( pretty_module, "<unknown>" );
                    } else {
                        memmove( pretty_module, p, strlen(p)+1 );
                    }
                } else {
                    strcpy_s( pretty_module, "" );
                }

                Add_Symbol( currentSym->SectionNumber, currentSym->Value, symName, pretty_module );
            }
        }
#endif

        // Advance counters, skip aux symbols
        i += currentSym->NumberOfAuxSymbols ;
        currentSym += currentSym->NumberOfAuxSymbols ;
        currentSym++ ;
    }

#ifdef DUMPRAM
    DumpSymbols();
#endif

    // dump symbolic info if found
    if ( fileSymbol )	{
        const char* auxSym = (const char*)(fileSymbol + 1) ;

        if( strcmpi( latestFile, auxSym ) )	{
            strcpy_s( latestFile, auxSym ) ;
            //JAS      dumpBuffer.Printf( "  file: %s\r\n", auxSym ) ;
        }
    } else {
        latestFile[ 0 ] = 0 ;
        //JAS    dumpBuffer.Printf( "  file: unknown\r\n" ) ;
    }

    if ( fnSymbol )	{
        char tmp_name[1024];
        unmangle(tmp_name, GetSymbolName( fnSymbol ) );
        dumpBuffer << "    " << tmp_name << "()";
    } else {
        dumpBuffer << "    <unknown>";
    }
}
Exemplo n.º 11
0
/* static */ wxString
wxDbgHelpDLL::DumpUDT(wxPSYMBOL_INFO pSym, void *pVariable, unsigned level)
{
    wxString s;

    // we have to limit the depth of UDT dumping as otherwise we get in
    // infinite loops trying to dump linked lists... 10 levels seems quite
    // reasonable, full information is in minidump file anyhow
    if ( level > 10 )
        return s;

    s.reserve(512);
    s = GetSymbolName(pSym);

#if !wxUSE_STD_STRING
    // special handling for ubiquitous wxString: although the code below works
    // for it as well, it shows the wxStringBase class and takes 4 lines
    // instead of only one as this branch
    if ( s == wxT("wxString") )
    {
        wxString *ps = (wxString *)pVariable;

        // we can't just dump wxString directly as it could be corrupted or
        // invalid and it could also be locked for writing (i.e. if we're
        // between GetWriteBuf() and UngetWriteBuf() calls) and assert when we
        // try to access it contents using public methods, so instead use our
        // knowledge of its internals
        const wxChar *p = NULL;
        if ( !::IsBadReadPtr(ps, sizeof(wxString)) )
        {
            p = ps->data();
            wxStringData *data = (wxStringData *)p - 1;
            if ( ::IsBadReadPtr(data, sizeof(wxStringData)) ||
                    ::IsBadReadPtr(p, sizeof(wxChar *)*data->nAllocLength) )
            {
                p = NULL; // don't touch this pointer with 10 feet pole
            }
        }

        s << wxT("(\"") << (p ? p : wxT("???")) << wxT(")\"");
    }
    else // any other UDT
#endif // !wxUSE_STD_STRING
    {
        // Determine how many children this type has.
        DWORD dwChildrenCount = 0;
        DoGetTypeInfo(pSym, TI_GET_CHILDRENCOUNT, &dwChildrenCount);

        // Prepare to get an array of "TypeIds", representing each of the children.
        TI_FINDCHILDREN_PARAMS *children = (TI_FINDCHILDREN_PARAMS *)
            malloc(sizeof(TI_FINDCHILDREN_PARAMS) +
                        (dwChildrenCount - 1)*sizeof(ULONG));
        if ( !children )
            return s;

        children->Count = dwChildrenCount;
        children->Start = 0;

        // Get the array of TypeIds, one for each child type
        if ( !DoGetTypeInfo(pSym, TI_FINDCHILDREN, children) )
        {
            free(children);
            return s;
        }

        s << wxT(" {\n");

        // Iterate through all children
        wxSYMBOL_INFO sym;
        wxZeroMemory(sym);
        sym.ModBase = pSym->ModBase;
        for ( unsigned i = 0; i < dwChildrenCount; i++ )
        {
            sym.TypeIndex = children->ChildId[i];

            // children here are in lexicographic sense, i.e. we get all our nested
            // classes and not only our member fields, but we can't get the values
            // for the members of the nested classes, of course!
            DWORD nested;
            if ( DoGetTypeInfo(&sym, TI_GET_NESTED, &nested) && nested )
                continue;

            // avoid infinite recursion: this does seem to happen sometimes with
            // complex typedefs...
            if ( sym.TypeIndex == pSym->TypeIndex )
                continue;

            s += DumpField(&sym, pVariable, level + 1);
        }

        free(children);

        s << wxString(wxT('\t'), level + 1) << wxT('}');
    }

    return s;
}
Exemplo n.º 12
0
char *CoffLoader::GetSymbolName(int index)
{
  SymbolTable_t *sym = &(SymTable[index]);
  return GetSymbolName(sym);
}
Exemplo n.º 13
0
wxString
wxDbgHelpDLL::DumpField(PSYMBOL_INFO pSym, void *pVariable, unsigned level)
{
    wxString s;

    // avoid infinite recursion
    if ( level > 100 )
    {
        return s;
    }

    SymbolTag tag = SYMBOL_TAG_NULL;
    if ( !DoGetTypeInfo(pSym, TI_GET_SYMTAG, &tag) )
    {
        return s;
    }

    switch ( tag )
    {
        case SYMBOL_TAG_UDT:
        case SYMBOL_TAG_BASE_CLASS:
            s = DumpUDT(pSym, pVariable, level);
            break;

        case SYMBOL_TAG_DATA:
            if ( !pVariable )
            {
                s = _T("NULL");
            }
            else // valid location
            {
                wxDbgHelpDLL::DataKind kind;
                if ( !DoGetTypeInfo(pSym, TI_GET_DATAKIND, &kind) ||
                        kind != DATA_MEMBER )
                {
                    // maybe it's a static member? we're not interested in them...
                    break;
                }

                // get the offset of the child member, relative to its parent
                DWORD ofs = 0;
                if ( !DoGetTypeInfo(pSym, TI_GET_OFFSET, &ofs) )
                    break;

                pVariable = (void *)((DWORD_PTR)pVariable + ofs);


                // now pass to the type representing the type of this member
                SYMBOL_INFO sym = *pSym;
                if ( !DoGetTypeInfo(pSym, TI_GET_TYPEID, &sym.TypeIndex) )
                    break;

                ULONG64 size;
                DoGetTypeInfo(&sym, TI_GET_LENGTH, &size);

                switch ( DereferenceSymbol(&sym, &pVariable) )
                {
                    case SYMBOL_TAG_BASE_TYPE:
                        {
                            BasicType bt = GetBasicType(&sym);
                            if ( bt )
                            {
                                s = DumpBaseType(bt, size, pVariable);
                            }
                        }
                        break;

                    case SYMBOL_TAG_UDT:
                    case SYMBOL_TAG_BASE_CLASS:
                        s = DumpUDT(&sym, pVariable, level);
                        break;
                }
            }

            if ( !s.empty() )
            {
                s = GetSymbolName(pSym) + _T(" = ") + s;
            }
            break;
    }

    if ( !s.empty() )
    {
        s = wxString(_T('\t'), level + 1) + s + _T('\n');
    }

    return s;
}
Exemplo n.º 14
0
void CCOF2OMF::MakeSymbolList() {
   // Make temporary symbol conversion list
   int isym = 0;  // current symbol table entry
   int jsym = 0;  // auxiliary entry number
   union {        // Pointer to symbol table
      SCOFF_SymTableEntry * p;  // Normal pointer
      int8 * b;                 // Used for address calculation
   } Symtab;

   Symtab.p = SymbolTable;      // Set pointer to begin of SymbolTable

   // Loop through symbol table
   while (isym < NumberOfSymbols) {
      // Check scope
      if (Symtab.p->s.StorageClass == COFF_CLASS_EXTERNAL) {
         // Scope is public or external

         if (Symtab.p->s.SectionNumber > 0) {

            // Symbol is public
            SymbolBuffer[isym].Scope = S_PUBLIC;               // Scope = public
            SymbolBuffer[isym].NewIndex = ++NumPublicSymbols;  // Public symbol number
            // Get name
            SymbolBuffer[isym].Name = NameBuffer.PushString(GetSymbolName(Symtab.p->s.Name));

            // Find section in SectionBuffer
            uint32 OldSection = Symtab.p->s.SectionNumber;
            SymbolBuffer[isym].Segment = SectionBuffer[OldSection].NewNumber; // New segment number

            // Calculate offset = offset into old section + offset of old section to first section with same name
            SymbolBuffer[isym].Offset = Symtab.p->s.Value + SectionBuffer[OldSection].Offset;
         }
         else if (Symtab.p->s.SectionNumber == 0) {

            // Symbol is external
            SymbolBuffer[isym].Scope = S_EXTERNAL;        // Scope = external
            SymbolBuffer[isym].NewIndex = ++NumExternalSymbols;  // External symbol number
            SymbolBuffer[isym].Name = NameBuffer.PushString(GetSymbolName(Symtab.p->s.Name));
         }
         else if (Symtab.p->s.SectionNumber == COFF_SECTION_ABSOLUTE) {

            // Symbol is public, absolute
            SymbolBuffer[isym].Scope = S_PUBLIC;        // Scope = public
            SymbolBuffer[isym].NewIndex = ++NumPublicSymbols;  // Public symbol number
            // Get name
            SymbolBuffer[isym].Name = NameBuffer.PushString(GetSymbolName(Symtab.p->s.Name));

            SymbolBuffer[isym].Segment = 0;          // 0 indicates absolute

            SymbolBuffer[isym].Offset = Symtab.p->s.Value;   // Store value in Offset
         }
         else {
            // COFF_SECTION_DEBUG, COFF_SECTION_N_TV, COFF_SECTION_P_TV
            // Ignore
         }
      }

      // Skip auxiliary symbol table entries and increment pointer
      isym += Symtab.p->s.NumAuxSymbols + 1;
      Symtab.b += (Symtab.p->s.NumAuxSymbols + 1) * SIZE_SCOFF_SymTableEntry;
   }
}
Exemplo n.º 15
0
void COMF::DumpRelocations() {
   // Dump all LEDATA, LIDATA, COMDAT and FIXUPP records
   uint32 LastDataRecord = 0;          // Index to the data record that relocations refer to
   uint32 LastDataRecordSize = 0;      // Size of the data record that relocations refer to
   int8 * LastDataRecordPointer = 0;   // Pointer to data in the data record that relocations refer to
   uint32 i;                           // Loop counter
   uint32 Segment, Offset, Size;       // Contents of LEDATA or LIDATA record
   uint32 LastOffset = 0;              // Offset of last LEDATA or LIDATA record
   uint32 Frame, Target, TargetDisplacement; // Contents of FIXUPP record
   uint8 byte1, byte2;                 // First two bytes of subrecord

   // Bitfields in subrecords
   OMF_SLocat Locat;         // Structure of first two bytes of FIXUP subrecord swapped = Locat field
   OMF_SFixData FixData;     // Structure of FixData field in FIXUP subrecord of FIXUPP record
   OMF_STrdDat TrdDat;       // Structure of Thread Data field in THREAD subrecord of FIXUPP record

   printf("\n\nLEDATA, LIDATA, COMDAT and FIXUPP records:");
   for (i = 0; i < NumRecords; i++) {
      if (Records[i].Type2 == OMF_LEDATA) {
         // LEDATA record
         Segment = Records[i].GetIndex();             // Read segment and offset
         Offset  = Records[i].GetNumeric();
         Size    = Records[i].End - Records[i].Index; // Calculate size of data
         LastDataRecord = i;                          // Save for later FIXUPP that refers to this record
         LastDataRecordSize = Size;
         LastDataRecordPointer = Records[i].buffer + Records[i].FileOffset + Records[i].Index;
         if (Segment < 0x4000) {
            printf("\n  LEDATA: segment %s, Offset 0x%X, Size 0x%X", // Dump segment, offset, size
               GetSegmentName(Segment), Offset, Size);
            LastOffset = Offset;
         }
         else { // Undocumented Borland communal section
            printf("\n  LEDATA communal section %i, Offset 0x%X, Size 0x%X", // Dump segment, offset, size
               (Segment & ~0x4000), Offset, Size);
            LastOffset = Offset;
         }
      }

      if (Records[i].Type2 == OMF_LIDATA) {
         // LIDATA record
         Segment = Records[i].GetIndex();
         Offset  = Records[i].GetNumeric();
         LastDataRecord = i;
         LastDataRecordSize = Records[i].End - Records[i].Index; // Size before expansion of repeat blocks
         LastDataRecordPointer = Records[i].buffer + Records[i].FileOffset + Records[i].Index;
         printf("\n  LIDATA: segment %s, Offset 0x%X, Size ",
            GetSegmentName(Segment), Offset);
         // Call recursive function to interpret repeat data block
         Size = Records[i].InterpretLIDATABlock();
         printf(" = 0x%X", Size);
         LastOffset = Offset;
      }

      if (Records[i].Type2 == OMF_COMDAT) {
         // COMDAT record
         uint32 Flags = Records[i].GetByte(); // 1 = continuation, 2 = iterated, 4 = local, 8 = data in code segment
         uint32 Attributes = Records[i].GetByte(); 
         uint32 Base = 0;
         // 0 = explicit, 1 = far code, 2 = far data, 3 = code32, 4 = data32
         // 0x00 = no match, 0x10 = pick any, 0x20 = same size, 0x30 = exact match
         uint32 Align = Records[i].GetByte(); // Alignment
         Offset  = Records[i].GetNumeric();    // Offset
         uint32 TypeIndex = Records[i].GetIndex(); // Type index
         if ((Attributes & 0x0F) == 0) {
            Base = Records[i].GetIndex(); // Public base
         }
         uint32 NameIndex = Records[i].GetIndex(); // LNAMES index
         Size    = Records[i].End - Records[i].Index; // Calculate size of data

         printf("\n  COMDAT: name %s, Offset 0x%X, Size 0x%X, Attrib 0x%02X, Align %i, Type %i, Base %i",
            GetLocalName(NameIndex), Offset, Size, Attributes, Align, TypeIndex, Base);
         LastOffset = Offset;
      }

      if (Records[i].Type2 == OMF_FIXUPP) {
         // FIXUPP record
         printf("\n  FIXUPP:");
         Records[i].Index = 3;

         // Loop through entries in record
         while (Records[i].Index < Records[i].End) {

            // Read first byte
            byte1 = Records[i].GetByte();
            if (byte1 & 0x80) {
               // This is a FIXUP subrecord
               Frame = 0; Target = 0; TargetDisplacement = 0;

               // read second byte
               byte2 = Records[i].GetByte();
               // swap bytes and put into byte12 bitfield
               Locat.bytes[1] = byte1;
               Locat.bytes[0] = byte2;
               // Read FixData
               FixData.b = Records[i].GetByte();

               // print mode and location
               printf("\n   %s %s, Offset 0x%X", 
                  Lookup(OMFRelocationModeNames, Locat.s.M),
                  Lookup(OMFFixupLocationNames, Locat.s.Location),
                  Locat.s.Offset + LastOffset);

               // Read conditional fields
               if (FixData.s.F == 0) {
                  if (FixData.s.Frame < 4) {
                     Frame = Records[i].GetIndex();
                  }
                  else Frame = 0;

                  switch (FixData.s.Frame) { // Frame method
                  case 0:  // F0: segment
                     printf(", segment %s", GetSegmentName(Frame));  break;

                  case 1:  // F1: group
                     printf(", group %s", GetGroupName(Frame));  break;

                  case 2:  // F2: external symbol
                     printf(", external frame %s", GetSymbolName(Frame));  break;

                  case 4:  // F4: frame = source, 
                           // or Borland floating point emulation record (undocumented?)
                     printf(", frame = source; or Borland f.p. emulation record");
                     break;

                  case 5:  // F5: frame = target
                     printf(", frame = target");  break;

                  default:
                     printf(", target frame %i method F%i", Frame, FixData.s.Frame);
                  }
               }
               else {
                  printf(", frame uses thread %i", FixData.s.Frame);
               }
               
               if (FixData.s.T == 0) {
                  // Target specified
                  Target = Records[i].GetIndex();
                  uint32 TargetMethod = FixData.s.Target + FixData.s.P * 4;

                  switch (FixData.s.Target) { // = Target method modulo 4
                  case 0: // T0 and T4: Target = segment
                  case 1: // T1 and T5: Target = segment group
                     printf(". Segment %s (T%i)",
                        GetSegmentName(Target), TargetMethod);
                     break;
                  case 2: // T2 and T6: Target = external symbol
                     printf(". Symbol %s (T%i)",
                        GetSymbolName(Target), TargetMethod);
                     break;
                  default: // Unknown method
                     printf(", target %i unknown method T%i", Target, TargetMethod);
                  }
               }
               else {
                  // Target specified in previous thread
                  printf(", target uses thread %i", FixData.s.Target);
               }

               if (FixData.s.P == 0) {
                  TargetDisplacement = Records[i].GetNumeric();
                  printf("\n    target displacement %i", TargetDisplacement);
               }
               // Get inline addend
               if (LastDataRecordPointer && Locat.s.Offset < LastDataRecordSize) {
                  int8 * inlinep = LastDataRecordPointer + Locat.s.Offset;
                  switch (Locat.s.Location) {
                  case 0: case 4:  // 8 bit
                     printf(", inline 0x%X", *inlinep);  break;

                  case 1: case 2: case 5: // 16 bit
                     printf(", inline 0x%X", *(int16*)inlinep);  break;

                  case 3: // 16+16 bit
                     printf(", inline 0x%X:0x%X", *(int16*)(inlinep+2), *(int16*)inlinep);  break;

                  case 9: case 13: // 32 bit
                     printf(", inline 0x%X", *(int32*)inlinep);  break;

                  case 6: case 11: // 16+32 bit
                     printf(", inline 0x%X:0x%X", *(int16*)(inlinep+4), *(int32*)inlinep);  break;
                  }
               }
            }
            else {
               // This is a THREAD subrecord
               TrdDat.b = byte1;                 // Put byte into bitfield

               uint32 Index  = 0;
               if (TrdDat.s.Method < 4) {
                  Index  = Records[i].GetIndex(); // has index field if method < 4 ?
               }
               printf("\n   %s Thread %i. Method %s%i, index %i",
                  (TrdDat.s.D ? "Frame" : "Target"), TrdDat.s.Thread,
                  (TrdDat.s.D ? "F" : "T"), TrdDat.s.Method, Index);
            }
         } // Finished loop through subrecords
         if (Records[i].Index != Records[i].End) err.submit(1203);   // Check for consistency
      }
   } // Finished loop through records
}
Exemplo n.º 16
0
void PrintSymbolName(FILE *f, void *addr) {
    char func[150];
    GetSymbolName(addr, func, 150);
    fprintf(stderr, "%s", func);
}
Exemplo n.º 17
0
void CCOF2ELF<ELFSTRUCTURES>::MakeSymbolTable() {
    // Convert subfunction: Make symbol table and string tables
    int isym;                           // current symbol table entry
    int numaux;                         // Number of auxiliary entries in source record
    int OldSectionIndex;                // Index into old section table. 1-based
    int NewSectionIndex;                // Index into new section table. 0-based
    const int WordSize = sizeof(NewFileHeader.e_entry) * 8; // word size 32 or 64 bits

    TELF_Symbol sym;                    // Temporary symbol table record
    const char * name1;                 // Name of section or main record

    // Pointer to old symbol table
    union {
        SCOFF_SymTableEntry * p;         // Symtab entry pointer
        int8 * b;                        // Used for increment
    } OldSymtab;

    // Make the first record empty
    NewSections[symtab].Push(0, sizeof(TELF_Symbol));

    // Make first string table entries empty
    NewSections[strtab] .PushString("");
    NewSections[stabstr].PushString("");

    // Loop twice through source symbol table to get local symbols first, global symbols last
    // Loop 1: Look for local symbols only
    OldSymtab.p = SymbolTable; // Pointer to source symbol table
    for (isym = 0; isym < this->NumberOfSymbols; isym += numaux+1, OldSymtab.b += SIZE_SCOFF_SymTableEntry*(numaux+1)) {

        if (OldSymtab.b >= Buf() + DataSize) {
            err.submit(2040);
            break;
        }

        // Number of auxiliary records belonging to same symbol
        numaux = OldSymtab.p->s.NumAuxSymbols;
        if (numaux < 0) numaux = 0;

        if (OldSymtab.p->s.StorageClass != COFF_CLASS_EXTERNAL && OldSymtab.p->s.StorageClass != COFF_CLASS_WEAK_EXTERNAL) {
            // Symbol is local

            // Reset destination entry
            memset(&sym, 0, sizeof(sym));

            // Binding
            sym.st_bind = STB_LOCAL;

            // Get first aux record if numaux > 0
            //SCOFF_SymTableEntryAux * sa = (SCOFF_SymTableEntryAux *)(OldSymtab.b + SIZE_SCOFF_SymTableEntry);

            // Symbol name
            name1 = this->GetSymbolName(OldSymtab.p->s.Name);

            // Symbol value
            sym.st_value = OldSymtab.p->s.Value;

            // Get section
            OldSectionIndex = OldSymtab.p->s.SectionNumber;  // 1-based index into old section table
            NewSectionIndex = 0;                 // 0-based index into old section table
            if (OldSectionIndex > 0 && OldSectionIndex <= this->NSections) {
                // Subtract 1 from OldSectionIndex because NewSectIndex[] is zero-based while OldSectionIndex is 1-based
                // Get new section index from translation table
                NewSectionIndex = NewSectIndex[OldSectionIndex-1];
            }
            if (NewSectionIndex == COFF_SECTION_REMOVE_ME) {
                continue; // Section has been removed. Remove symbol too
            }

            sym.st_shndx = (uint16)NewSectionIndex;

            // Check symbol type
            if (OldSymtab.p->s.StorageClass == COFF_CLASS_FILE) {
                // This is a filename record
                if (numaux > 0 && numaux < 20) {
                    // Get filename from subsequent Aux records.
                    // Remove path from filename because the path makes no sense on a different platform.
                    const char * filename = GetShortFileName(OldSymtab.p);
                    // Put file name into string table and debug string table
                    sym.st_name = NewSections[strtab].PushString(filename);
                    NewSections[stabstr].PushString(filename);
                }
                // Attributes for filename record
                sym.st_shndx  = (uint16)SHN_ABS;
                sym.st_type   = STT_FILE;
                sym.st_bind   = STB_LOCAL;
                sym.st_value  = 0;
            }
            else if (numaux && OldSymtab.p->s.StorageClass == COFF_CLASS_STATIC
                     && OldSymtab.p->s.Value == 0 && OldSymtab.p->s.Type != 0x20) {
                // This is a section definition record
                sym.st_name  = 0;
                name1 = 0;
                sym.st_type  = STT_SECTION;
                sym.st_bind  = STB_LOCAL;
                sym.st_value = 0;
                // aux record contains length and number of relocations. Ignore aux record
            }
            else if (OldSymtab.p->s.SectionNumber < 0) {
                // This is an absolute or debug symbol
                sym.st_type  = STT_NOTYPE;
                sym.st_shndx = (uint16)SHN_ABS;
            }
            else if (OldSymtab.p->s.Type == 0 && OldSymtab.p->s.StorageClass == COFF_CLASS_FUNCTION) {
                // This is a .bf, .lf, or .ef record following a function record
                // Contains line number information etc. Ignore this record
                continue;
            }
            else if (OldSymtab.p->s.SectionNumber <= 0) {
                // Unknown
                sym.st_type = STT_NOTYPE;
            }
            else {
                // This is a local data definition record
                sym.st_type = STT_OBJECT;
                // The size is not specified in COFF record,
                // so we may give it an arbitrary size:
                // sym.size = 4;
            }

            // Put symbol name into string table if we have not already done so
            if (sym.st_name == 0 && name1) {
                sym.st_name = NewSections[strtab].PushString(name1);
            }

            // Put record into new symbol table
            NewSections[symtab].Push(&sym, sizeof(sym));

            // Insert into symbol translation table
            NewSymbolIndex[isym] = NewSections[symtab].GetLastIndex();

        } // End if not external
    }  // End loop 1

    // Finished with local symbols
    // Make index to first global symbol
    NewSectionHeaders[symtab].sh_info = NewSections[symtab].GetLastIndex() + 1;

    // Loop 2: Look for global symbols only
    OldSymtab.p = SymbolTable; // Pointer to source symbol table
    for (isym = 0; isym < NumberOfSymbols; isym += numaux+1, OldSymtab.b += SIZE_SCOFF_SymTableEntry*(numaux+1)) {

        // Number of auxiliary records belonging to same symbol
        numaux = OldSymtab.p->s.NumAuxSymbols;
        if (numaux < 0) numaux = 0;

        if (OldSymtab.p->s.StorageClass == COFF_CLASS_EXTERNAL || OldSymtab.p->s.StorageClass == COFF_CLASS_WEAK_EXTERNAL) {
            // Symbol is global (public or external)

            // Reset destination entry
            memset(&sym, 0, sizeof(sym));

            // Binding
            sym.st_bind = STB_GLOBAL;
            if (OldSymtab.p->s.StorageClass == COFF_CLASS_WEAK_EXTERNAL) sym.st_bind = STB_WEAK;

            // Get first aux record if numaux > 0
            SCOFF_SymTableEntry * sa = (SCOFF_SymTableEntry*)(OldSymtab.b + SIZE_SCOFF_SymTableEntry);

            // Symbol name
            name1 = GetSymbolName(OldSymtab.p->s.Name);

            // Symbol value
            sym.st_value = OldSymtab.p->s.Value;

            // Get section
            OldSectionIndex = OldSymtab.p->s.SectionNumber; // 1-based index into old section table
            NewSectionIndex = 0;                          // 0-based index into old section table
            if (OldSectionIndex > 0 && OldSectionIndex <= NSections) {
                // Subtract 1 from OldSectionIndex because NewSectIndex[] is zero-based while OldSectionIndex is 1-based
                // Get new section index from translation table
                NewSectionIndex = NewSectIndex[OldSectionIndex-1];
            }
            if (NewSectionIndex == COFF_SECTION_REMOVE_ME) {
                continue; // Section has been removed. Remove symbol too
            }
            if ((int16)OldSectionIndex == COFF_SECTION_ABSOLUTE) {
                NewSectionIndex = SHN_ABS;
            }

            sym.st_shndx = (uint16)NewSectionIndex;

            // Check symbol type
            if (OldSymtab.p->s.SectionNumber < 0) {
                // This is an absolute or debug symbol
                sym.st_type = STT_NOTYPE;
            }
            else if (OldSymtab.p->s.Type == COFF_TYPE_FUNCTION && OldSymtab.p->s.SectionNumber > 0) {
                // This is a function definition record
                sym.st_type = STT_FUNC;
                if (numaux) {
                    // Get size from aux record
                    sym.st_size = sa->func.TotalSize;
                }
                if (sym.st_size == 0) {
                    // The size is not specified in the COFF file.
                    // We may give it an arbitrary size:
                    // sym.size = 1;
                }
            }
            else if (OldSymtab.p->s.SectionNumber <= 0) {
                // This is an external symbol
                sym.st_type = STT_NOTYPE;
            }
            else {
                // This is a data definition record
                sym.st_type = STT_OBJECT;
                // Symbol must have a size. The size is not specified in COFF record,
                // so we just give it an arbitrary size
                sym.st_size = 4;
            }

            // Put symbol name into string table if we have not already done so
            if (sym.st_name == 0 && name1) {
                sym.st_name = NewSections[strtab].PushString(name1);
            }

            // Put record into new symbol table
            NewSections[symtab].Push(&sym, sizeof(sym));

            // Insert into symbol translation table
            NewSymbolIndex[isym] = NewSections[symtab].GetLastIndex();

        } // End if external
    }  // End loop 2
}
Exemplo n.º 18
0
/******************************************************************************
 * Function Name: ProcessHWSymbolEntry
 *
 * Inputs       : 
 * Outputs      : 
 * Returns      : 
 * Globals Used : -
 *
 * Description  : Process an entry of symbol reg use list
 *****************************************************************************/
static IMG_VOID ProcessHWSymbolEntry(GLSLCompilerPrivateData *psCPD,
									 GLSLUniFlexContext		*psUFContext,
		  							 HWSYMBOL				*psHWSymbol,
									 GLSLBindingSymbolList	*psBindingSymbolList)
{
	GLSLBindingSymbol *psBindingSymbol;
	GLSLIdentifierData *psIdentifierData;

	/* Get psIndentifierData */
	psIdentifierData = (GLSLIdentifierData *)GetSymbolTableData(psUFContext->psSymbolTable, psHWSymbol->uSymbolId);
	if(psIdentifierData == IMG_NULL)
	{
		LOG_INTERNAL_ERROR(("ProcessHWSymbolEntry: Failed to get data for identifier %d\n", psHWSymbol->uSymbolId));
		return;
	}

	psBindingSymbol = AddBindingSymbol(psCPD, psUFContext, psHWSymbol, psIdentifierData, psBindingSymbolList);

	if(GLSL_IS_STRUCT(psBindingSymbol->eTypeSpecifier))
	{
		IMG_CHAR			psName[512];
		IMG_UINT32			uNameLength;
		IMG_CHAR			*pszStructName;
		STRUCT_CONTEXT		sContext;
		GLSLStructureAlloc	*psStructAlloc = GetStructAllocInfo(psCPD, psUFContext, &psHWSymbol->sFullType);
		IMG_UINT32			uArraySize = (IMG_UINT32) (psBindingSymbol->iActiveArraySize);

		pszStructName =	(IMG_CHAR *)GetSymbolName(psUFContext->psSymbolTable, psHWSymbol->uSymbolId);

		strcpy(psName, pszStructName);

		/**
		 * OGL64 Review.
		 * Use size_t for strlen?
		 */
		uNameLength = (IMG_UINT32)strlen(pszStructName);

		/*
			Alloc memory for base type members
		*/
		psBindingSymbol->uNumBaseTypeMembers = psStructAlloc->uNumBaseTypeMembers * uArraySize;
		psBindingSymbol->psBaseTypeMembers = DebugMemAlloc(psBindingSymbol->uNumBaseTypeMembers * sizeof(GLSLBindingSymbol));
		if(psBindingSymbol->psBaseTypeMembers == IMG_NULL)
		{
			LOG_INTERNAL_ERROR(("ProcessHWSymbolEntry: Failed to alloc memory"));
			return ;
		}

		/* Initialise and setup context for processing structure */

		/* Unchanged fields */
		sContext.psStructHWSymbol		= psHWSymbol;
		sContext.psStructStructAlloc	= psStructAlloc;
		sContext.psStructBindingSymbol	= psBindingSymbol;

		/* Changable fields */
		sContext.uStructBaseOffset		= psHWSymbol->u.uCompOffset;
		sContext.uStructTextureUnitBase = psHWSymbol->uTextureUnit;
		sContext.uMemberOffset			= 0;
		sContext.uNameLength			= uNameLength;
		sContext.psName					= psName;
		sContext.psIdentifierData		= psIdentifierData;
		sContext.pbyConstantData		= psIdentifierData->pvConstantData;

		/* Recursive processing structure members */
		RecursivelyAddStructMembers(psCPD, psUFContext, &sContext, psBindingSymbolList);

		/* Doublly check for correctness */
		if(sContext.uMemberOffset != psBindingSymbol->uNumBaseTypeMembers)
		{
			LOG_INTERNAL_ERROR(("ProcessHWSymbolEntry: Number of structure members do not match\n"));
		}

	}

	/* For literal constants etc. we don't need to add to the binding symbol list */
	if( psBindingSymbol->eTypeQualifier == GLSLTQ_INVALID ||
		psBindingSymbol->eTypeQualifier == GLSLTQ_TEMP    ||
		psBindingSymbol->eTypeQualifier == GLSLTQ_CONST )
	{
		if(psBindingSymbol->pszName) DebugMemFree(psBindingSymbol->pszName);

		/* Free base type members */
		if(psBindingSymbol->uNumBaseTypeMembers)
		{
			IMG_UINT32 j;
			for(j = 0; j < psBindingSymbol->uNumBaseTypeMembers; j++)
			{
				if(psBindingSymbol->psBaseTypeMembers[j].pszName)
				{
					DebugMemFree(psBindingSymbol->psBaseTypeMembers[j].pszName);
				}
			}
		
			DebugMemFree(psBindingSymbol->psBaseTypeMembers);

			psBindingSymbol->psBaseTypeMembers = IMG_NULL;
		}

		/* Remove from binding symbol list */
		psBindingSymbolList->uNumBindings--;
	}

}
Exemplo n.º 19
0
/* static */ wxString
wxDbgHelpDLL::DumpUDT(PSYMBOL_INFO pSym, void *pVariable, unsigned level)
{
    wxString s;

    // we have to limit the depth of UDT dumping as otherwise we get in
    // infinite loops trying to dump linked lists... 10 levels seems quite
    // reasonable, full information is in minidump file anyhow
    if ( level > 10 )
        return s;

    s.reserve(512);
    s = GetSymbolName(pSym);

#if !wxUSE_STL
    // special handling for ubiquitous wxString: although the code below works
    // for it as well, it shows the wxStringBase class and takes 4 lines
    // instead of only one as this branch
    if ( s == _T("wxString") )
    {
        wxString *ps = (wxString *)pVariable;
        s << _T("(\"") << *ps << _T(")\"");
    }
    else // any other UDT
#endif // !wxUSE_STL
    {
        // Determine how many children this type has.
        DWORD dwChildrenCount = 0;
        DoGetTypeInfo(pSym, TI_GET_CHILDRENCOUNT, &dwChildrenCount);

        // Prepare to get an array of "TypeIds", representing each of the children.
        TI_FINDCHILDREN_PARAMS *children = (TI_FINDCHILDREN_PARAMS *)
            malloc(sizeof(TI_FINDCHILDREN_PARAMS) +
                        (dwChildrenCount - 1)*sizeof(ULONG));
        if ( !children )
            return s;

        children->Count = dwChildrenCount;
        children->Start = 0;

        // Get the array of TypeIds, one for each child type
        if ( !DoGetTypeInfo(pSym, TI_FINDCHILDREN, children) )
        {
            free(children);
            return s;
        }

        s << _T(" {\n");

        // Iterate through all children
        SYMBOL_INFO sym;
        wxZeroMemory(sym);
        sym.ModBase = pSym->ModBase;
        for ( unsigned i = 0; i < dwChildrenCount; i++ )
        {
            sym.TypeIndex = children->ChildId[i];

            // children here are in lexicographic sense, i.e. we get all our nested
            // classes and not only our member fields, but we can't get the values
            // for the members of the nested classes, of course!
            DWORD nested;
            if ( DoGetTypeInfo(&sym, TI_GET_NESTED, &nested) && nested )
                continue;

            // avoid infinite recursion: this does seem to happen sometimes with
            // complex typedefs...
            if ( sym.TypeIndex == pSym->TypeIndex )
                continue;

            s += DumpField(&sym, pVariable, level + 1);
        }

        free(children);

        s << wxString(_T('\t'), level + 1) << _T('}');
    }

    return s;
}
Exemplo n.º 20
0
void CCOFF::PrintSymbolTable(int symnum) {
   // Print one or all public symbols for object file.
   // Dump symbol table if symnum = -1, or
   // Dump symbol number symnum (zero based) when symnum >= 0
   int isym = 0;  // current symbol table entry
   int jsym = 0;  // auxiliary entry number
   union {        // Pointer to symbol table
      SCOFF_SymTableEntry * p;  // Normal pointer
      int8 * b;                 // Used for address calculation
   } Symtab;

   Symtab.p = SymbolTable;      // Set pointer to begin of SymbolTable
   if (symnum == -1) printf("\n\nSymbol table:");
   if (symnum >= 0) {
      // Print one symbol only
      if (symnum >= NumberOfSymbols) {
         printf("\nSymbol %i not found", symnum);
         return;
      }
      isym = symnum;
      Symtab.b += SIZE_SCOFF_SymTableEntry * isym;
   }
   while (isym < NumberOfSymbols) {
      // Print symbol table entry
      SCOFF_SymTableEntry *s0;
      printf("\n");
      if (symnum >= 0) printf("  ");
      printf("Symbol %i - Name: %s\n  Value=%i, ", 
         isym, GetSymbolName(Symtab.p->s.Name), Symtab.p->s.Value);
      if (Symtab.p->s.SectionNumber > 0) {
         printf("Section=%i", Symtab.p->s.SectionNumber);
      }
      else { // Special section numbers
         switch (Symtab.p->s.SectionNumber) {
         case COFF_SECTION_UNDEF:
            printf("External"); break;
         case COFF_SECTION_ABSOLUTE:
            printf("Absolute"); break;
         case COFF_SECTION_DEBUG:
            printf("Debug"); break;
         case COFF_SECTION_N_TV:
            printf("Preload transfer"); break;
         case COFF_SECTION_P_TV:
            printf("Postload transfer"); break;
         }
      }
      printf(", Type=0x%X, StorClass=%s, NumAux=%i",
         Symtab.p->s.Type,
         GetStorageClassName(Symtab.p->s.StorageClass), Symtab.p->s.NumAuxSymbols);
      if (Symtab.p->s.StorageClass == COFF_CLASS_FILE && Symtab.p->s.NumAuxSymbols > 0) {
         printf("\n  File name: %s", GetFileName(Symtab.p));
      }
      // Increment point
      s0 = Symtab.p;
      Symtab.b += SIZE_SCOFF_SymTableEntry;
      isym++;  jsym = 0;
      // Get auxiliary records
      while (jsym < s0->s.NumAuxSymbols && isym + jsym < NumberOfSymbols) {
         // Print auxiliary symbol table entry
         SCOFF_SymTableEntry * sa = Symtab.p;
         // Detect auxiliary entry type
         if (s0->s.StorageClass == COFF_CLASS_EXTERNAL
            && s0->s.Type == COFF_TYPE_FUNCTION
            && s0->s.SectionNumber > 0) {
            // This is a function definition aux record
            printf("\n  Aux function definition:");
            printf("\n  .bf_tag_index: 0x%X, code_size: %i, PLineNumRec: %i, PNext: %i",
               sa->func.TagIndex, sa->func.TotalSize, sa->func.PointerToLineNumber,
               sa->func.PointerToNextFunction);
         }
         else if (strcmp(s0->s.Name,".bf")==0 || strcmp(s0->s.Name,".ef")==0) {
            // This is a .bf or .ef aux record
            printf("\n  Aux .bf/.ef definition:");
            printf("\n  Source line number: %i",
               sa->bfef.SourceLineNumber);
            if (strcmp(s0->s.Name,".bf")==0 ) {
               printf(", PNext: %i", sa->bfef.PointerToNextFunction);
            }
         }
         else if (s0->s.StorageClass == COFF_CLASS_EXTERNAL && 
            s0->s.SectionNumber == COFF_SECTION_UNDEF &&
            s0->s.Value == 0) {
            // This is a Weak external aux record
            printf("\n  Aux Weak external definition:");
            printf("\n  Symbol2 index: %i, Characteristics: 0x%X",
               sa->weak.TagIndex, sa->weak.Characteristics);
            }
         else if (s0->s.StorageClass == COFF_CLASS_FILE) {
            // This is filename aux record. Contents has already been printed
         }
         else if (s0->s.StorageClass == COFF_CLASS_STATIC) {
            // This is section definition aux record
            printf("\n  Aux section definition record:");
            printf("\n  Length: %i, Num. relocations: %i, Num linenums: %i, checksum 0x%X,"
               "\n  Number: %i, Selection: %i",
               sa->section.Length, sa->section.NumberOfRelocations, sa->section.NumberOfLineNumbers, 
               sa->section.CheckSum, sa->section.Number, sa->section.Selection);
         }
         else {
            // Unknown aux record type
            printf("\n  Unknown Auxiliary record type.");
         }
         Symtab.b += SIZE_SCOFF_SymTableEntry;
         jsym++;
      }
      isym += jsym;
      if (symnum >= 0) break;
   }
}
Exemplo n.º 21
0
void CoffLoader::PrintSymbolTable(void)
{
  int SymIndex;

  printf("COFF SYMBOL TABLE\n");
  for (SymIndex = 0; SymIndex < NumberOfSymbols; SymIndex++)
  {
    printf("%03X ", SymIndex);
    printf("%08lX ", SymTable[SymIndex].Value);

    if (SymTable[SymIndex].SectionNumber == IMAGE_SYM_ABSOLUTE)
      printf("ABS     ");
    else if (SymTable[SymIndex].SectionNumber == IMAGE_SYM_DEBUG)
      printf("DEBUG   ");
    else if (SymTable[SymIndex].SectionNumber == IMAGE_SYM_UNDEFINED)
      printf("UNDEF   ");
    else
    {
      printf("SECT%d ", SymTable[SymIndex].SectionNumber);
      if (SymTable[SymIndex].SectionNumber < 10)
        printf(" ");
      if (SymTable[SymIndex].SectionNumber < 100)
        printf(" ");
    }

    if (SymTable[SymIndex].Type == 0)
      printf("notype       ");
    else
    {
      printf("%X         ", SymTable[SymIndex].Type);
      if (SymTable[SymIndex].Type < 0x10)
        printf(" ");
      if (SymTable[SymIndex].Type < 0x100)
        printf(" ");
      if (SymTable[SymIndex].Type < 0x1000)
        printf(" ");
    }

    if (SymTable[SymIndex].StorageClass == IMAGE_SYM_CLASS_END_OF_FUNCTION)
      printf("End of Function   ");
    if (SymTable[SymIndex].StorageClass == IMAGE_SYM_CLASS_NULL)
      printf("Null              ");
    if (SymTable[SymIndex].StorageClass == IMAGE_SYM_CLASS_AUTOMATIC)
      printf("Automatic         ");
    if (SymTable[SymIndex].StorageClass == IMAGE_SYM_CLASS_EXTERNAL)
      printf("External          ");
    if (SymTable[SymIndex].StorageClass == IMAGE_SYM_CLASS_STATIC)
      printf("Static            ");
    if (SymTable[SymIndex].StorageClass == IMAGE_SYM_CLASS_REGISTER)
      printf("Register          ");
    if (SymTable[SymIndex].StorageClass == IMAGE_SYM_CLASS_EXTERNAL_DEF)
      printf("External Def      ");
    if (SymTable[SymIndex].StorageClass == IMAGE_SYM_CLASS_LABEL)
      printf("Label             ");
    if (SymTable[SymIndex].StorageClass == IMAGE_SYM_CLASS_UNDEFINED_LABEL)
      printf("Undefined Label   ");
    if (SymTable[SymIndex].StorageClass == IMAGE_SYM_CLASS_MEMBER_OF_STRUCT)
      printf("Member Of Struct  ");
    if (SymTable[SymIndex].StorageClass == IMAGE_SYM_CLASS_ARGUMENT)
      printf("Argument          ");
    if (SymTable[SymIndex].StorageClass == IMAGE_SYM_CLASS_STRUCT_TAG)
      printf("Struct Tag        ");
    if (SymTable[SymIndex].StorageClass == IMAGE_SYM_CLASS_MEMBER_OF_UNION)
      printf("Member Of Union   ");
    if (SymTable[SymIndex].StorageClass == IMAGE_SYM_CLASS_UNION_TAG)
      printf("Union Tag         ");
    if (SymTable[SymIndex].StorageClass == IMAGE_SYM_CLASS_TYPE_DEFINITION)
      printf("Type Definition  ");
    if (SymTable[SymIndex].StorageClass == IMAGE_SYM_CLASS_UNDEFINED_STATIC)
      printf("Undefined Static  ");
    if (SymTable[SymIndex].StorageClass == IMAGE_SYM_CLASS_ENUM_TAG)
      printf("Enum Tag          ");
    if (SymTable[SymIndex].StorageClass == IMAGE_SYM_CLASS_MEMBER_OF_ENUM)
      printf("Member Of Enum    ");
    if (SymTable[SymIndex].StorageClass == IMAGE_SYM_CLASS_REGISTER_PARAM)
      printf("Register Param    ");
    if (SymTable[SymIndex].StorageClass == IMAGE_SYM_CLASS_BIT_FIELD)
      printf("Bit Field         ");
    if (SymTable[SymIndex].StorageClass == IMAGE_SYM_CLASS_BLOCK)
      printf("Block             ");
    if (SymTable[SymIndex].StorageClass == IMAGE_SYM_CLASS_FUNCTION)
      printf("Function          ");
    if (SymTable[SymIndex].StorageClass == IMAGE_SYM_CLASS_END_OF_STRUCT)
      printf("End Of Struct     ");
    if (SymTable[SymIndex].StorageClass == IMAGE_SYM_CLASS_FILE)
      printf("File              ");
    if (SymTable[SymIndex].StorageClass == IMAGE_SYM_CLASS_SECTION)
      printf("Section           ");
    if (SymTable[SymIndex].StorageClass == IMAGE_SYM_CLASS_WEAK_EXTERNAL)
      printf("Weak External     ");

    printf("| %s", GetSymbolName(SymIndex));

    SymIndex += SymTable[SymIndex].NumberOfAuxSymbols;
    printf("\n");
  }
  printf("\n");

}
Exemplo n.º 22
0
void CCOF2ASM::MakeSymbolList() {
   // Make Symbols list in Disasm
   uint32 isym;                                  // Symbol index
   uint32 naux = 0;                              // Number of auxiliary entries in old symbol table

   union {                                       // Pointer to old symbol table entries
      SCOFF_SymTableEntry * p;                   // Normal pointer
      int8 * b;                                  // Used for address calculation
   } Sym, SymAux;

   // Set pointer to old SymbolTable
   Sym.p = SymbolTable;

   // Loop through old symbol table
   for (isym = 0; isym < (uint32)NumberOfSymbols; isym += 1+naux, Sym.b += (1+naux) * SIZE_SCOFF_SymTableEntry) {

      // Number of auxiliary entries
      naux = Sym.p->s.NumAuxSymbols;

      if (Sym.p->s.SectionNumber != COFF_SECTION_ABSOLUTE
      && (Sym.p->s.SectionNumber < 0 
      || (Sym.p->s.StorageClass != COFF_CLASS_EXTERNAL && Sym.p->s.StorageClass != COFF_CLASS_STATIC && Sym.p->s.StorageClass != COFF_CLASS_LABEL))) {
         // Ignore irrelevant symbol table entries
         continue;
      }

      // Symbol properties
      uint32 Index   = isym;
      int32  Section = Sym.p->s.SectionNumber;
      uint32 Offset  = Sym.p->s.Value;
      uint32 Size    = 0;
      uint32 Type    = (Sym.p->s.Type == COFF_TYPE_FUNCTION) ? 0x83 : 0;

      // Identify segment entries in symbol table
      if (Sym.p->s.Value == 0 && Sym.p->s.StorageClass == COFF_CLASS_STATIC 
      && naux && Sym.p->s.Type != 0x20) {
         // Note: The official MS specification says that a symbol table entry 
         // is a section if the storage class is static and the value is 0,
         // but I have encountered static functions that meet these criteria.
         // Therefore, I am also checking Type and naux.
         Type = 0x80000082;
      }

      const char * Name = GetSymbolName(Sym.p->s.Name);

      // Get scope. Note that these values are different from the constants defined in maindef.h
      uint32 Scope = 0;
      if (Sym.p->s.StorageClass == COFF_CLASS_STATIC || Sym.p->s.StorageClass == COFF_CLASS_LABEL) {
         Scope = 2;             // Local
      }
      else if (Sym.p->s.SectionNumber > 0 || (Sym.p->s.SectionNumber == -1 && Sym.p->s.StorageClass == COFF_CLASS_EXTERNAL)) {
         Scope = 4;             // Public
      }
      else {
         Scope = 0x20;          // External
      }

      // Check auxiliary symbol table entries
      if (naux && Sym.p->s.Type == COFF_TYPE_FUNCTION) {
         // Function symbol has auxiliary entry. Get information about size
         SymAux.b = Sym.b + SIZE_SCOFF_SymTableEntry;
         Size = SymAux.p->func.TotalSize;
      }
      // Check for special section values
      if (Section < 0) {
         if (Section == COFF_SECTION_ABSOLUTE) {
            // Symbol is an absolute constant
            Section = ASM_SEGMENT_ABSOLUTE;
         }
         else {
            // Debug symbols, etc
            Section = ASM_SEGMENT_ERROR;
         }
      }

      // Store new symbol record
      Disasm.AddSymbol(Section, Offset, Size, Type, Scope, Index, Name);
   }
}