Added code to remap symbolic debug name in lookup table if editted via gui.
This commit is contained in:
parent
98008bcd4d
commit
e4749425ba
|
@ -21,12 +21,72 @@ debugSymbolTable_t debugSymbolTable;
|
||||||
|
|
||||||
static char dbgSymTblErrMsg[256] = {0};
|
static char dbgSymTblErrMsg[256] = {0};
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
|
// debugSymbol_t
|
||||||
|
//--------------------------------------------------------------
|
||||||
|
void debugSymbol_t::updateName( const char *name, int arrayIndex )
|
||||||
|
{
|
||||||
|
_name.assign( name );
|
||||||
|
|
||||||
|
trimTrailingSpaces();
|
||||||
|
|
||||||
|
if (arrayIndex >= 0)
|
||||||
|
{
|
||||||
|
char stmp[32];
|
||||||
|
|
||||||
|
sprintf( stmp, "[%i]", arrayIndex );
|
||||||
|
|
||||||
|
_name.append(stmp);
|
||||||
|
}
|
||||||
|
debugSymbolTable.updateSymbol(this);
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------
|
||||||
|
void debugSymbol_t::trimTrailingSpaces(void)
|
||||||
|
{
|
||||||
|
while ( _name.size() > 0 )
|
||||||
|
{
|
||||||
|
if ( isspace( _name.back() ) )
|
||||||
|
{
|
||||||
|
_name.pop_back();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while ( _comment.size() > 0 )
|
||||||
|
{
|
||||||
|
if ( isspace( _comment.back() ) )
|
||||||
|
{
|
||||||
|
_comment.pop_back();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------
|
||||||
// debugSymbolPage_t
|
// debugSymbolPage_t
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
debugSymbolPage_t::debugSymbolPage_t(void)
|
debugSymbolPage_t::debugSymbolPage_t(int page)
|
||||||
{
|
{
|
||||||
pageNum = -1;
|
_pageNum = page;
|
||||||
|
|
||||||
|
_pageName[0] = 0;
|
||||||
|
|
||||||
|
if (page == -2)
|
||||||
|
{
|
||||||
|
strcpy( _pageName, "REG");
|
||||||
|
}
|
||||||
|
else if (page == -1)
|
||||||
|
{
|
||||||
|
strcpy( _pageName, "RAM");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
snprintf( _pageName, sizeof(_pageName), "%X", page);
|
||||||
|
_pageName[sizeof(_pageName)-1] = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
debugSymbolPage_t::~debugSymbolPage_t(void)
|
debugSymbolPage_t::~debugSymbolPage_t(void)
|
||||||
|
@ -42,17 +102,19 @@ int debugSymbolPage_t::addSymbol( debugSymbol_t*sym )
|
||||||
// Check if symbol already is loaded by that name or offset
|
// Check if symbol already is loaded by that name or offset
|
||||||
if ( symMap.count( sym->offset() ) )
|
if ( symMap.count( sym->offset() ) )
|
||||||
{
|
{
|
||||||
snprintf( dbgSymTblErrMsg, sizeof(dbgSymTblErrMsg), "Error: symbol offset 0x%04x already has an entry on page:%i\n", sym->offset(), pageNum );
|
snprintf( dbgSymTblErrMsg, sizeof(dbgSymTblErrMsg), "Error: symbol offset 0x%04x already has an entry on %s page\n", sym->offset(), _pageName );
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if ( (sym->name().size() > 0) && symNameMap.count( sym->name() ) )
|
if ( (sym->name().size() > 0) && symNameMap.count( sym->name() ) )
|
||||||
{
|
{
|
||||||
snprintf( dbgSymTblErrMsg, sizeof(dbgSymTblErrMsg), "Error: symbol name '%s' already exists on page:%i\n", sym->name().c_str(), pageNum );
|
snprintf( dbgSymTblErrMsg, sizeof(dbgSymTblErrMsg), "Error: symbol name '%s' already exists on %s page\n", sym->name().c_str(), _pageName );
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
symMap[ sym->offset() ] = sym;
|
symMap[ sym->offset() ] = sym;
|
||||||
|
|
||||||
|
sym->page = this;
|
||||||
|
|
||||||
// Comment only lines don't need to have a name.
|
// Comment only lines don't need to have a name.
|
||||||
if (sym->name().size() > 0)
|
if (sym->name().size() > 0)
|
||||||
{
|
{
|
||||||
|
@ -86,7 +148,7 @@ int debugSymbolPage_t::deleteSymbolAtOffset( int ofs )
|
||||||
{
|
{
|
||||||
auto itName = symNameMap.find( sym->name() );
|
auto itName = symNameMap.find( sym->name() );
|
||||||
|
|
||||||
if ( itName != symNameMap.end() )
|
if ( (itName != symNameMap.end()) && (itName->second == sym) )
|
||||||
{
|
{
|
||||||
symNameMap.erase(itName);
|
symNameMap.erase(itName);
|
||||||
}
|
}
|
||||||
|
@ -99,6 +161,41 @@ int debugSymbolPage_t::deleteSymbolAtOffset( int ofs )
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
|
int debugSymbolPage_t::updateSymbol(debugSymbol_t *sym)
|
||||||
|
{
|
||||||
|
auto itName = symNameMap.begin();
|
||||||
|
|
||||||
|
while (itName != symNameMap.end())
|
||||||
|
{
|
||||||
|
if (itName->second == sym)
|
||||||
|
{
|
||||||
|
if (sym->name().size() == 0 || sym->name().compare( itName->first ) )
|
||||||
|
{
|
||||||
|
//printf("Changing Name: %s %s\n", itName->first.c_str(), sym->name().c_str() );
|
||||||
|
itName = symNameMap.erase(itName);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
itName++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (sym->name().size() > 0)
|
||||||
|
{
|
||||||
|
symNameMap[ sym->name() ] = sym;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sanity Check
|
||||||
|
auto it = symMap.find( sym->offset() );
|
||||||
|
|
||||||
|
if ( it == symMap.end() )
|
||||||
|
{ // This shouldn't happen
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------
|
||||||
int debugSymbolPage_t::save(void)
|
int debugSymbolPage_t::save(void)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
@ -114,7 +211,7 @@ int debugSymbolPage_t::save(void)
|
||||||
//printf("Skipping Empty Debug Page Save\n");
|
//printf("Skipping Empty Debug Page Save\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if ( pageNum == -2 )
|
if ( _pageNum == -2 )
|
||||||
{
|
{
|
||||||
//printf("Skipping Register Debug Page Save\n");
|
//printf("Skipping Register Debug Page Save\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -141,7 +238,7 @@ int debugSymbolPage_t::save(void)
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( pageNum < 0 )
|
if ( _pageNum < 0 )
|
||||||
{
|
{
|
||||||
filename.append(".ram.nl" );
|
filename.append(".ram.nl" );
|
||||||
}
|
}
|
||||||
|
@ -149,7 +246,7 @@ int debugSymbolPage_t::save(void)
|
||||||
{
|
{
|
||||||
char suffix[32];
|
char suffix[32];
|
||||||
|
|
||||||
sprintf( suffix, ".%X.nl", pageNum );
|
sprintf( suffix, ".%X.nl", _pageNum );
|
||||||
|
|
||||||
filename.append( suffix );
|
filename.append( suffix );
|
||||||
}
|
}
|
||||||
|
@ -218,7 +315,7 @@ void debugSymbolPage_t::print(void)
|
||||||
|
|
||||||
fp = stdout;
|
fp = stdout;
|
||||||
|
|
||||||
fprintf( fp, "Page: %X \n", pageNum );
|
fprintf( fp, "Page: %X \n", _pageNum );
|
||||||
|
|
||||||
for (it=symMap.begin(); it!=symMap.end(); it++)
|
for (it=symMap.begin(); it!=symMap.end(); it++)
|
||||||
{
|
{
|
||||||
|
@ -347,11 +444,9 @@ int debugSymbolTable_t::loadFileNL( int bank )
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
page = new debugSymbolPage_t;
|
page = new debugSymbolPage_t(bank);
|
||||||
|
|
||||||
page->pageNum = bank;
|
pageMap[ page->pageNum() ] = page;
|
||||||
|
|
||||||
pageMap[ page->pageNum ] = page;
|
|
||||||
|
|
||||||
while ( fgets( line, sizeof(line), fp ) != 0 )
|
while ( fgets( line, sizeof(line), fp ) != 0 )
|
||||||
{
|
{
|
||||||
|
@ -574,9 +669,7 @@ int debugSymbolTable_t::loadRegisterMap(void)
|
||||||
FCEU::autoScopedLock alock(cs);
|
FCEU::autoScopedLock alock(cs);
|
||||||
debugSymbolPage_t *page;
|
debugSymbolPage_t *page;
|
||||||
|
|
||||||
page = new debugSymbolPage_t();
|
page = new debugSymbolPage_t(-2);
|
||||||
|
|
||||||
page->pageNum = -2;
|
|
||||||
|
|
||||||
page->addSymbol( new debugSymbol_t( 0x2000, "PPU_CTRL" ) );
|
page->addSymbol( new debugSymbol_t( 0x2000, "PPU_CTRL" ) );
|
||||||
page->addSymbol( new debugSymbol_t( 0x2001, "PPU_MASK" ) );
|
page->addSymbol( new debugSymbol_t( 0x2001, "PPU_MASK" ) );
|
||||||
|
@ -611,7 +704,7 @@ int debugSymbolTable_t::loadRegisterMap(void)
|
||||||
page->addSymbol( new debugSymbol_t( 0x4016, "JOY1" ) );
|
page->addSymbol( new debugSymbol_t( 0x4016, "JOY1" ) );
|
||||||
page->addSymbol( new debugSymbol_t( 0x4017, "JOY2_FRAME" ) );
|
page->addSymbol( new debugSymbol_t( 0x4017, "JOY2_FRAME" ) );
|
||||||
|
|
||||||
pageMap[ page->pageNum ] = page;
|
pageMap[ page->pageNum() ] = page;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -675,8 +768,7 @@ int debugSymbolTable_t::addSymbolAtBankOffset( int bank, int ofs, debugSymbol_t
|
||||||
|
|
||||||
if ( it == pageMap.end() )
|
if ( it == pageMap.end() )
|
||||||
{
|
{
|
||||||
page = new debugSymbolPage_t();
|
page = new debugSymbolPage_t(bank);
|
||||||
page->pageNum = bank;
|
|
||||||
pageMap[ bank ] = page;
|
pageMap[ bank ] = page;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -708,6 +800,17 @@ int debugSymbolTable_t::deleteSymbolAtBankOffset( int bank, int ofs )
|
||||||
return page->deleteSymbolAtOffset( ofs );
|
return page->deleteSymbolAtOffset( ofs );
|
||||||
}
|
}
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
|
int debugSymbolTable_t::updateSymbol(debugSymbol_t *sym)
|
||||||
|
{
|
||||||
|
FCEU::autoScopedLock alock(cs);
|
||||||
|
|
||||||
|
if (sym->page == nullptr)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return sym->page->updateSymbol(sym);
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------
|
||||||
debugSymbol_t *debugSymbolTable_t::getSymbolAtBankOffset( int bank, int ofs )
|
debugSymbol_t *debugSymbolTable_t::getSymbolAtBankOffset( int bank, int ofs )
|
||||||
{
|
{
|
||||||
FCEU::autoScopedLock alock(cs);
|
FCEU::autoScopedLock alock(cs);
|
||||||
|
|
|
@ -15,6 +15,7 @@ class debugSymbol_t
|
||||||
debugSymbol_t(void)
|
debugSymbol_t(void)
|
||||||
{
|
{
|
||||||
ofs = 0;
|
ofs = 0;
|
||||||
|
page = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
debugSymbol_t( int ofs, const char *name = nullptr, const char *comment = nullptr )
|
debugSymbol_t( int ofs, const char *name = nullptr, const char *comment = nullptr )
|
||||||
|
@ -29,6 +30,7 @@ class debugSymbol_t
|
||||||
{
|
{
|
||||||
this->_comment.assign( comment );
|
this->_comment.assign( comment );
|
||||||
}
|
}
|
||||||
|
page = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string &name(void)
|
const std::string &name(void)
|
||||||
|
@ -66,53 +68,16 @@ class debugSymbol_t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateName( const char *name, int arrayIndex = -1 )
|
void updateName( const char *name, int arrayIndex = -1 );
|
||||||
{
|
|
||||||
_name.assign( name );
|
|
||||||
|
|
||||||
trimTrailingSpaces();
|
void trimTrailingSpaces(void);
|
||||||
|
|
||||||
if (arrayIndex >= 0)
|
|
||||||
{
|
|
||||||
char stmp[32];
|
|
||||||
|
|
||||||
sprintf( stmp, "[%i]", arrayIndex );
|
|
||||||
|
|
||||||
_name.append(stmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void trimTrailingSpaces(void)
|
|
||||||
{
|
|
||||||
while ( _name.size() > 0 )
|
|
||||||
{
|
|
||||||
if ( isspace( _name.back() ) )
|
|
||||||
{
|
|
||||||
_name.pop_back();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while ( _comment.size() > 0 )
|
|
||||||
{
|
|
||||||
if ( isspace( _comment.back() ) )
|
|
||||||
{
|
|
||||||
_comment.pop_back();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
int ofs;
|
int ofs;
|
||||||
std::string _name;
|
std::string _name;
|
||||||
std::string _comment;
|
std::string _comment;
|
||||||
|
debugSymbolPage_t *page;
|
||||||
|
|
||||||
friend class debugSymbolPage_t;
|
friend class debugSymbolPage_t;
|
||||||
friend class debugSymbolTable_t;
|
friend class debugSymbolTable_t;
|
||||||
|
@ -121,7 +86,7 @@ class debugSymbol_t
|
||||||
class debugSymbolPage_t
|
class debugSymbolPage_t
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
debugSymbolPage_t(void);
|
debugSymbolPage_t(int page);
|
||||||
~debugSymbolPage_t(void);
|
~debugSymbolPage_t(void);
|
||||||
|
|
||||||
int save(void);
|
int save(void);
|
||||||
|
@ -132,12 +97,25 @@ class debugSymbolPage_t
|
||||||
|
|
||||||
int deleteSymbolAtOffset( int ofs );
|
int deleteSymbolAtOffset( int ofs );
|
||||||
|
|
||||||
|
int updateSymbol( debugSymbol_t *sym );
|
||||||
|
|
||||||
debugSymbol_t *getSymbolAtOffset( int ofs );
|
debugSymbol_t *getSymbolAtOffset( int ofs );
|
||||||
|
|
||||||
debugSymbol_t *getSymbol( const std::string &name );
|
debugSymbol_t *getSymbol( const std::string &name );
|
||||||
|
|
||||||
|
int pageNum(void)
|
||||||
|
{
|
||||||
|
return _pageNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *pageName(void)
|
||||||
|
{
|
||||||
|
return _pageName;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int pageNum;
|
int _pageNum;
|
||||||
|
char _pageName[8];
|
||||||
std::map <int, debugSymbol_t*> symMap;
|
std::map <int, debugSymbol_t*> symMap;
|
||||||
std::map <std::string, debugSymbol_t*> symNameMap;
|
std::map <std::string, debugSymbol_t*> symNameMap;
|
||||||
|
|
||||||
|
@ -171,6 +149,8 @@ class debugSymbolTable_t
|
||||||
|
|
||||||
int deleteSymbolAtBankOffset( int bank, int ofs );
|
int deleteSymbolAtBankOffset( int bank, int ofs );
|
||||||
|
|
||||||
|
int updateSymbol( debugSymbol_t *sym );
|
||||||
|
|
||||||
const char *errorMessage(void);
|
const char *errorMessage(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue