1 #include "DebugUtils.h" 2 #include "string_cast.h" 3 #include "string_format.h" 4 PrintAddressLocation(uint32 address,CMIPS * context,const BiosDebugModuleInfoArray & modules)5std::string DebugUtils::PrintAddressLocation(uint32 address, CMIPS* context, const BiosDebugModuleInfoArray& modules) 6 { 7 auto locationString = string_format(("0x%08X"), address); 8 9 auto module = FindModuleAtAddress(modules, address); 10 const char* functionName = nullptr; 11 if(auto subroutine = context->m_analysis->FindSubroutine(address)) 12 { 13 functionName = context->m_Functions.Find(subroutine->start); 14 } 15 bool hasParenthesis = (functionName != nullptr) || (module != nullptr); 16 if(hasParenthesis) 17 { 18 locationString += (" ("); 19 } 20 if(functionName) 21 { 22 locationString += functionName; 23 } 24 if((functionName != nullptr) && (module != nullptr)) 25 { 26 locationString += (" : "); 27 } 28 if(module) 29 { 30 locationString += module->name; 31 } 32 if(hasParenthesis) 33 { 34 locationString += (")"); 35 } 36 return locationString; 37 } 38 FindModuleAtAddress(const BiosDebugModuleInfoArray & modules,uint32 address)39const BIOS_DEBUG_MODULE_INFO* DebugUtils::FindModuleAtAddress(const BiosDebugModuleInfoArray& modules, uint32 address) 40 { 41 for(auto moduleIterator(std::begin(modules)); 42 moduleIterator != std::end(modules); moduleIterator++) 43 { 44 const auto& module = (*moduleIterator); 45 if(address >= module.begin && address < module.end) 46 { 47 return &module; 48 } 49 } 50 return nullptr; 51 } 52