www.pudn.com > potemkin_sourceforPSP.rar > SymbolMap.cpp
#include "stdafx.h" #include #include "string.h" #include "../../globals.h" //#include "../HW/memmap.h" #include "../../Core/MemMap.h" #include "SymbolMap.h" #include #include //need improvement u32 hasher(u32 last, u32 value) { return _rotl(last,3) ^ value; } //#define BWLINKS u32 ComputeHash(u32 start, u32 size) { u32 hash=0; for (unsigned int i=start; i backwardLinks; #endif BWLINKS char name[128]; void UndecorateName() { // char temp[128]; // char temp2[128]; // strcpy(temp,name); // strcpy(temp2,name); // temp[6]=0; // if (strcmp(temp,"__ct__")) // { // sprintf(temp2,"Constructor: %s",temp+7); // } // else if (strcmp(temp,"__dt__")) // { // sprintf(temp2,"Destructor: %s",temp+7); // } // strcpy(name,temp2); } }; int numEntries; MapEntry entries[65536*2]; int compareEntries(const void *p1, const void *p2) { const MapEntry *e1 = (const MapEntry*)p1, *e2 = (const MapEntry*)p2; return e1->vaddress - e2->vaddress; } void Debugger_SortSymbols() { qsort(entries,numEntries,sizeof(MapEntry),compareEntries); } void Debugger_AnalyzeBackwards() { #ifndef BWLINKS return; #else for (int i=0; i>26) { case 18: { if (LK) //LK { u32 addr; if(AA) addr = SignExt26(LI << 2); else addr = ptr + SignExt26(LI << 2); int funNum = Debugger_GetSymbolNum(addr); if (funNum>=0) entries[funNum].backwardLinks.push_back(ptr); } break; } default: ; } ptr+=4; } } } } #endif } void Debugger_ResetSymbolMap() { #ifdef BWLINKS for (int i=0; i= entries[i].vaddress) start = i; else break; } if (start<0) start=0; for (i=start; i= addr)) { if (address < addr+entries[i].size) { if (entries[i].type & symmask) return i; else return -1; } } else break; } return -1; } char temp[256]; char *Debugger_GetDescription(unsigned int address) { int fun = Debugger_GetSymbolNum(address); //if (address == entries[fun].vaddress) //{ if (fun!=-1) return entries[fun].name; else { sprintf(temp, "(%08x)", address); return temp; } //} //else // return ""; } void Debugger_FillSymbolListBox(HWND listbox,SymbolType symmask) { ShowWindow(listbox,SW_HIDE); ListBox_ResetContent(listbox); //int style = GetWindowLong(listbox,GWL_STYLE); ListBox_AddString(listbox,"(0x80003100)"); ListBox_SetItemData(listbox,0,0x80003100); //ListBox_AddString(listbox,"(0x80002000)"); //ListBox_SetItemData(listbox,1,0x80002000); for (int i=0; i=0) return entries[num].runCount; else return 0; } //deprecated shit since this didn't really work out: // Load an elf with symbols, use debugger_compilefuncsignaturesfile // to make a symbol map, load a dol or somethin without symbols, then apply // the map with debugger_usefuncsignaturesfile. void Debugger_CompileFuncSignaturesFile(const char *filename) { // Store name,length,first instruction,hash into file FILE *f = fopen(filename, "w"); fprintf(f,"00000000\n"); int count=0; for (int i=0; i=16 && entries[i].type == ST_FUNCTION) { u32 inst = ReadMem32Unchecked(entries[i].vaddress); //try to make a bigger number of different vals sometime if (inst != 0) { char temp[64]; strncpy(temp,entries[i].name,63); fprintf(f, "%08x\t%08x\t%08x\t%s\n", inst, size, ComputeHash(entries[i].vaddress,size), temp); count++; } } } fseek(f,0,SEEK_SET); fprintf(f,"%08x",count); fclose(f); } struct Sig { u32 inst; u32 size; u32 hash; char name[64]; Sig(){} Sig(u32 _inst, u32 _size, u32 _hash, char *_name) : inst(_inst), size(_size), hash(_hash) { strncpy(name,_name,63); } }; int compare (const void *s1, const void *s2) { return ((Sig *)s2)->inst - ((Sig *)s1)->inst; } #define MAXSIGS 65536*2 Sig sigs[MAXSIGS]; int numSigs; typedef std::map Sigmap; Sigmap sigmap; void Debugger_UseFuncSignaturesFile(const char *filename, u32 maxAddress) { SetStatusBar("Loading signature file..."); numSigs=0; //Debugger_ResetSymbolMap(); //#1: Read the signature file and put them in a fast data structure FILE *f = fopen(filename, "r"); int count; fscanf(f,"%08x\n",&count); u32 inst,size,hash; char name[256]; for (int a=0; asecond; while (true) { if (sig->inst != inst) break; u32 hash = ComputeHash(addr,sig->size); if (hash==sig->hash) { //MATCH!!!! MapEntry &e = entries[numEntries++]; e.address=addr; e.size= sig->size; e.vaddress = addr; e.type=ST_FUNCTION; strcpy(e.name,sig->name); addr+=sig->size-4; //don't need to check function interior break; } sig++; } } } SetStatusBar("Sorting symbols..."); //ensure code coloring even if symbols were loaded before Debugger_SortSymbols(); SetStatusBar("Ready"); }