diff --git a/src/debugsymboltable.cpp b/src/debugsymboltable.cpp index 956f8153..968e1614 100644 --- a/src/debugsymboltable.cpp +++ b/src/debugsymboltable.cpp @@ -23,11 +23,23 @@ static char dbgSymTblErrMsg[256] = {0}; //-------------------------------------------------------------- // debugSymbol_t //-------------------------------------------------------------- -void debugSymbol_t::updateName( const char *name, int arrayIndex ) +int debugSymbol_t::updateName( const char *name, int arrayIndex ) { - _name.assign( name ); + std::string newName; - trimTrailingSpaces(); + newName.assign( name ); + + while ( newName.size() > 0 ) + { + if ( isspace( newName.back() ) ) + { + newName.pop_back(); + } + else + { + break; + } + } if (arrayIndex >= 0) { @@ -35,9 +47,24 @@ void debugSymbol_t::updateName( const char *name, int arrayIndex ) sprintf( stmp, "[%i]", arrayIndex ); - _name.append(stmp); + newName.append(stmp); } + + if (page) + { + debugSymbol_t *dupSym = debugSymbolTable.getSymbol( page->pageNum(), newName ); + + if (dupSym != nullptr && dupSym != this) + { + snprintf( dbgSymTblErrMsg, sizeof(dbgSymTblErrMsg), "Error: debug symbol '%s' already exists in %s page.\n", newName.c_str(), page->pageName() ); + return -1; + } + } + _name = newName; + debugSymbolTable.updateSymbol(this); + + return 0; } //-------------------------------------------------------------- void debugSymbol_t::trimTrailingSpaces(void) diff --git a/src/debugsymboltable.h b/src/debugsymboltable.h index 81b7d9d1..caf0dc5a 100644 --- a/src/debugsymboltable.h +++ b/src/debugsymboltable.h @@ -68,7 +68,7 @@ class debugSymbol_t } } - void updateName( const char *name, int arrayIndex = -1 ); + int updateName( const char *name, int arrayIndex = -1 ); void trimTrailingSpaces(void); diff --git a/src/drivers/Qt/SymbolicDebug.cpp b/src/drivers/Qt/SymbolicDebug.cpp index a86fb434..cf9cea88 100644 --- a/src/drivers/Qt/SymbolicDebug.cpp +++ b/src/drivers/Qt/SymbolicDebug.cpp @@ -879,7 +879,13 @@ int SymbolEditWindow::exec(void) } else { - sym->updateName( nameEntry->text().toStdString().c_str() ); + if ( sym->updateName( nameEntry->text().toStdString().c_str() ) ) + { + if (consoleWindow) + { + consoleWindow->QueueErrorMsgWindow( debugSymbolTable.errorMessage() ); + } + } sym->commentAssign( commentEntry->toPlainText().toStdString().c_str() ); sym->trimTrailingSpaces(); } @@ -990,14 +996,12 @@ void SymbolEditWindow::setSymNameWithArray(int idx) } // Reform with base string and new index. - sym->updateName( stmp, idx ); - //sym->name.assign( stmp ); - - //sym->trimTrailingSpaces(); - - //sprintf( stmp, "[%i]", idx ); - - //sym->name.append( stmp ); - + if ( sym->updateName( stmp, idx ) ) + { + if (consoleWindow) + { + consoleWindow->QueueErrorMsgWindow( debugSymbolTable.errorMessage() ); + } + } } //--------------------------------------------------------------