void ScfgRuleWriter::WriteSymbol(const Symbol &symbol, std::ostream &out) { if (symbol.GetType() == NonTerminal) { out << "[" << symbol.GetValue() << "]"; } else { out << symbol.GetValue(); } }
static inline bool is_array_of_arrays(const Symbol* pSym) { if(!pSym) return 0; if(pSym->GetType()!=SYMBOL_ARRAY) return 0; SymbolArray* pSymArr = (SymbolArray*)pSym; if(pSymArr->GetArr().size()==0) return 0; Symbol* pSymInArr = pSymArr->GetArr()[0]; return (pSymInArr->GetType()==SYMBOL_ARRAY); }
string SymbolTable::GetAddress(string name, string off) { Symbol* sym = LookUp(name); if (sym) { if (sym->GetType() == SYMBOL_PARAM) { if (sym->GetLoc() < 0) { sym->SetLoc(next_temp); return "Param"; } else { stringstream ss; if (off == "") { ss<<"local["<<sym->GetLoc()<<"]"; } else { ss<<"local["<<sym->GetLoc()<<"+"<<off<<"]"; } return ss.str(); } } else if (sym->GetType() == SYMBOL_FUNC) { return sym->GetName(); } else if (sym->GetType() == SYMBOL_GLOBAL) { stringstream ss; if (off == "") { ss<<"global["<<sym->GetLoc()<<"]"; } else { ss<<"global["<<sym->GetLoc()<<"+"<<off<<"]"; } return ss.str(); } else { stringstream ss; if (off == "") { ss<<"local["<<sym->GetLoc()<<"]"; } else { ss<<"local["<<sym->GetLoc()<<"+"<<off<<"]"; } return ss.str(); } } else { return ""; } }
AddressClass ObjectFile::GetAddressClass (addr_t file_addr) { Symtab *symtab = GetSymtab(ObjectFile::eSymtabFromUnifiedSectionList); if (symtab) { Symbol *symbol = symtab->FindSymbolContainingFileAddress(file_addr); if (symbol) { if (symbol->ValueIsAddress()) { const SectionSP section_sp (symbol->GetAddress().GetSection()); if (section_sp) { const SectionType section_type = section_sp->GetType(); switch (section_type) { case eSectionTypeInvalid: return eAddressClassUnknown; case eSectionTypeCode: return eAddressClassCode; case eSectionTypeContainer: return eAddressClassUnknown; case eSectionTypeData: case eSectionTypeDataCString: case eSectionTypeDataCStringPointers: case eSectionTypeDataSymbolAddress: case eSectionTypeData4: case eSectionTypeData8: case eSectionTypeData16: case eSectionTypeDataPointers: case eSectionTypeZeroFill: case eSectionTypeDataObjCMessageRefs: case eSectionTypeDataObjCCFStrings: return eAddressClassData; case eSectionTypeDebug: case eSectionTypeDWARFDebugAbbrev: case eSectionTypeDWARFDebugAranges: case eSectionTypeDWARFDebugFrame: case eSectionTypeDWARFDebugInfo: case eSectionTypeDWARFDebugLine: case eSectionTypeDWARFDebugLoc: case eSectionTypeDWARFDebugMacInfo: case eSectionTypeDWARFDebugPubNames: case eSectionTypeDWARFDebugPubTypes: case eSectionTypeDWARFDebugRanges: case eSectionTypeDWARFDebugStr: case eSectionTypeDWARFAppleNames: case eSectionTypeDWARFAppleTypes: case eSectionTypeDWARFAppleNamespaces: case eSectionTypeDWARFAppleObjC: return eAddressClassDebug; case eSectionTypeEHFrame: return eAddressClassRuntime; case eSectionTypeELFSymbolTable: case eSectionTypeELFDynamicSymbols: case eSectionTypeELFRelocationEntries: case eSectionTypeELFDynamicLinkInfo: case eSectionTypeOther: return eAddressClassUnknown; } } } const SymbolType symbol_type = symbol->GetType(); switch (symbol_type) { case eSymbolTypeAny: return eAddressClassUnknown; case eSymbolTypeAbsolute: return eAddressClassUnknown; case eSymbolTypeCode: return eAddressClassCode; case eSymbolTypeTrampoline: return eAddressClassCode; case eSymbolTypeResolver: return eAddressClassCode; case eSymbolTypeData: return eAddressClassData; case eSymbolTypeRuntime: return eAddressClassRuntime; case eSymbolTypeException: return eAddressClassRuntime; case eSymbolTypeSourceFile: return eAddressClassDebug; case eSymbolTypeHeaderFile: return eAddressClassDebug; case eSymbolTypeObjectFile: return eAddressClassDebug; case eSymbolTypeCommonBlock: return eAddressClassDebug; case eSymbolTypeBlock: return eAddressClassDebug; case eSymbolTypeLocal: return eAddressClassData; case eSymbolTypeParam: return eAddressClassData; case eSymbolTypeVariable: return eAddressClassData; case eSymbolTypeVariableType: return eAddressClassDebug; case eSymbolTypeLineEntry: return eAddressClassDebug; case eSymbolTypeLineHeader: return eAddressClassDebug; case eSymbolTypeScopeBegin: return eAddressClassDebug; case eSymbolTypeScopeEnd: return eAddressClassDebug; case eSymbolTypeAdditional: return eAddressClassUnknown; case eSymbolTypeCompiler: return eAddressClassDebug; case eSymbolTypeInstrumentation:return eAddressClassDebug; case eSymbolTypeUndefined: return eAddressClassUnknown; case eSymbolTypeObjCClass: return eAddressClassRuntime; case eSymbolTypeObjCMetaClass: return eAddressClassRuntime; case eSymbolTypeObjCIVar: return eAddressClassRuntime; } } } return eAddressClassUnknown; }
AddressClass ObjectFile::GetAddressClass(addr_t file_addr) { Symtab *symtab = GetSymtab(); if (symtab) { Symbol *symbol = symtab->FindSymbolContainingFileAddress(file_addr); if (symbol) { if (symbol->ValueIsAddress()) { const SectionSP section_sp(symbol->GetAddressRef().GetSection()); if (section_sp) { const SectionType section_type = section_sp->GetType(); switch (section_type) { case eSectionTypeInvalid: return eAddressClassUnknown; case eSectionTypeCode: return eAddressClassCode; case eSectionTypeContainer: return eAddressClassUnknown; case eSectionTypeData: case eSectionTypeDataCString: case eSectionTypeDataCStringPointers: case eSectionTypeDataSymbolAddress: case eSectionTypeData4: case eSectionTypeData8: case eSectionTypeData16: case eSectionTypeDataPointers: case eSectionTypeZeroFill: case eSectionTypeDataObjCMessageRefs: case eSectionTypeDataObjCCFStrings: case eSectionTypeGoSymtab: return eAddressClassData; case eSectionTypeDebug: case eSectionTypeDWARFDebugAbbrev: case eSectionTypeDWARFDebugAddr: case eSectionTypeDWARFDebugAranges: case eSectionTypeDWARFDebugFrame: case eSectionTypeDWARFDebugInfo: case eSectionTypeDWARFDebugLine: case eSectionTypeDWARFDebugLoc: case eSectionTypeDWARFDebugMacInfo: case eSectionTypeDWARFDebugMacro: case eSectionTypeDWARFDebugPubNames: case eSectionTypeDWARFDebugPubTypes: case eSectionTypeDWARFDebugRanges: case eSectionTypeDWARFDebugStr: case eSectionTypeDWARFDebugStrOffsets: case eSectionTypeDWARFAppleNames: case eSectionTypeDWARFAppleTypes: case eSectionTypeDWARFAppleNamespaces: case eSectionTypeDWARFAppleObjC: return eAddressClassDebug; case eSectionTypeEHFrame: case eSectionTypeARMexidx: case eSectionTypeARMextab: case eSectionTypeCompactUnwind: return eAddressClassRuntime; case eSectionTypeELFSymbolTable: case eSectionTypeELFDynamicSymbols: case eSectionTypeELFRelocationEntries: case eSectionTypeELFDynamicLinkInfo: case eSectionTypeOther: return eAddressClassUnknown; case eSectionTypeAbsoluteAddress: // In case of absolute sections decide the address class based on // the symbol // type because the section type isn't specify if it is a code or a // data // section. break; } } } const SymbolType symbol_type = symbol->GetType(); switch (symbol_type) { case eSymbolTypeAny: return eAddressClassUnknown; case eSymbolTypeAbsolute: return eAddressClassUnknown; case eSymbolTypeCode: return eAddressClassCode; case eSymbolTypeTrampoline: return eAddressClassCode; case eSymbolTypeResolver: return eAddressClassCode; case eSymbolTypeData: return eAddressClassData; case eSymbolTypeRuntime: return eAddressClassRuntime; case eSymbolTypeException: return eAddressClassRuntime; case eSymbolTypeSourceFile: return eAddressClassDebug; case eSymbolTypeHeaderFile: return eAddressClassDebug; case eSymbolTypeObjectFile: return eAddressClassDebug; case eSymbolTypeCommonBlock: return eAddressClassDebug; case eSymbolTypeBlock: return eAddressClassDebug; case eSymbolTypeLocal: return eAddressClassData; case eSymbolTypeParam: return eAddressClassData; case eSymbolTypeVariable: return eAddressClassData; case eSymbolTypeVariableType: return eAddressClassDebug; case eSymbolTypeLineEntry: return eAddressClassDebug; case eSymbolTypeLineHeader: return eAddressClassDebug; case eSymbolTypeScopeBegin: return eAddressClassDebug; case eSymbolTypeScopeEnd: return eAddressClassDebug; case eSymbolTypeAdditional: return eAddressClassUnknown; case eSymbolTypeCompiler: return eAddressClassDebug; case eSymbolTypeInstrumentation: return eAddressClassDebug; case eSymbolTypeUndefined: return eAddressClassUnknown; case eSymbolTypeObjCClass: return eAddressClassRuntime; case eSymbolTypeObjCMetaClass: return eAddressClassRuntime; case eSymbolTypeObjCIVar: return eAddressClassRuntime; case eSymbolTypeReExported: return eAddressClassRuntime; } } } return eAddressClassUnknown; }