diff --git a/src/debugsymboltable.cpp b/src/debugsymboltable.cpp index 4c7106c8..76b4b0b8 100644 --- a/src/debugsymboltable.cpp +++ b/src/debugsymboltable.cpp @@ -38,6 +38,7 @@ debugSymbolPage_t::~debugSymbolPage_t(void) //-------------------------------------------------------------- int debugSymbolPage_t::addSymbol( debugSymbol_t*sym ) { + // Check if symbol already is loaded by that name or offset if ( symMap.count( sym->ofs ) || symNameMap.count( sym->name ) ) { return -1; @@ -631,9 +632,23 @@ int debugSymbolTable_t::loadGameSymbols(void) return 0; } +int debugSymbolTable_t::addSymbolAtBankOffset(int bank, int ofs, const char *name, const char *comment) +{ + int result = -1; + debugSymbol_t *sym = new debugSymbol_t(ofs, name, comment); + + result = addSymbolAtBankOffset(bank, ofs, sym); + + if (result) + { // Symbol add failed + delete sym; + } + return result; +} //-------------------------------------------------------------- int debugSymbolTable_t::addSymbolAtBankOffset( int bank, int ofs, debugSymbol_t *sym ) { + int result = -1; debugSymbolPage_t *page; std::map ::iterator it; FCEU::autoScopedLock alock(cs); @@ -650,9 +665,9 @@ int debugSymbolTable_t::addSymbolAtBankOffset( int bank, int ofs, debugSymbol_t { page = it->second; } - page->addSymbol( sym ); + result = page->addSymbol( sym ); - return 0; + return result; } //-------------------------------------------------------------- int debugSymbolTable_t::deleteSymbolAtBankOffset( int bank, int ofs ) diff --git a/src/debugsymboltable.h b/src/debugsymboltable.h index e77d0aca..31027c94 100644 --- a/src/debugsymboltable.h +++ b/src/debugsymboltable.h @@ -17,11 +17,14 @@ struct debugSymbol_t ofs = 0; }; - debugSymbol_t( int ofs, const char *name, const char *comment = NULL ) + debugSymbol_t( int ofs, const char *name, const char *comment = nullptr ) { this->ofs = ofs; - this->name.assign( name ); + if (name) + { + this->name.assign(name); + } if ( comment ) { this->comment.assign( comment ); @@ -101,6 +104,8 @@ class debugSymbolTable_t int addSymbolAtBankOffset( int bank, int ofs, debugSymbol_t *sym ); + int addSymbolAtBankOffset(int bank, int ofs, const char* name, const char* comment = nullptr); + int deleteSymbolAtBankOffset( int bank, int ofs ); private: diff --git a/src/drivers/win/debuggersp.cpp b/src/drivers/win/debuggersp.cpp index 20b1a838..6cb47a90 100644 --- a/src/drivers/win/debuggersp.cpp +++ b/src/drivers/win/debuggersp.cpp @@ -25,6 +25,7 @@ #include "../../fceu.h" #include "../../ines.h" #include "../../debug.h" +#include "../../debugsymboltable.h" #include "../../conddebug.h" #include @@ -671,6 +672,16 @@ char* generateNLFilenameForAddress(uint16 address) } return NLfilename; } +static int getRomPageIndexForAddress(uint16 address) +{ + int page = -1; + + if (address >= 0x8000) + { + page = RomPageIndexForAddress(address); + } + return page; +} Name* getNamesPointerForAddress(uint16 address) { if(address >= 0x8000) @@ -1107,6 +1118,7 @@ void AddNewSymbolicName(uint16 newAddress, char* newOffset, char* newName, char* if (*newName || *newComment) { int i = 0; + int bank = -1; char* tmpNewOffset = (char*)malloc(strlen(newOffset) + 1); strcpy(tmpNewOffset, newOffset); uint16 tmpNewAddress = newAddress; @@ -1150,6 +1162,8 @@ void AddNewSymbolicName(uint16 newAddress, char* newOffset, char* newName, char* node->next = 0; setNamesPointerForAddress(tmpNewAddress, node); + + debugSymbolTable.addSymbolAtBankOffset(getRomPageIndexForAddress(tmpNewAddress), tmpNewAddress, node->name, node->comment); } else { @@ -1233,6 +1247,7 @@ void AddNewSymbolicName(uint16 newAddress, char* newOffset, char* newName, char* newNode->next = 0; node->next = newNode; + debugSymbolTable.addSymbolAtBankOffset(getRomPageIndexForAddress(tmpNewAddress), tmpNewAddress, newNode->name, newNode->comment); break; } } @@ -1270,6 +1285,7 @@ void DeleteSymbolicName(uint16 address, int size) prev = node; node = node->next; } + debugSymbolTable.deleteSymbolAtBankOffset(getRomPageIndexForAddress(tmpAddress), tmpAddress); ++tmpAddress; } while (++i < size); } diff --git a/src/drivers/win/window.cpp b/src/drivers/win/window.cpp index 5c3382f7..47fb1352 100644 --- a/src/drivers/win/window.cpp +++ b/src/drivers/win/window.cpp @@ -28,6 +28,7 @@ #include "../../cheat.h" //adelikat: For FCEU_LoadGameCheats() #include "../../version.h" #include "../../video.h" //adelikat: For ScreenshotAs Get/Set functions +#include "../../debugsymboltable.h" #include "window.h" #include "main.h" #include "state.h" @@ -1073,6 +1074,7 @@ void CloseGame() updateGameDependentMenus(); updateGameDependentMenusDebugger(); SetMainWindowText(); + debugSymbolTable.clear(); } } @@ -1153,6 +1155,9 @@ bool ALoad(const char *nameo, char* innerFilename, bool silent) { DoDebug(0); } + // Clear and Load core debug symbol table + debugSymbolTable.clear(); + debugSymbolTable.loadGameSymbols(); } else {