Added logic to load debug symbols from files.

This commit is contained in:
Matthew Budd 2020-09-14 21:08:38 -04:00
parent f442404149
commit a4df1e3c06
4 changed files with 374 additions and 9 deletions

View File

@ -1199,6 +1199,20 @@ int QAsmView::getAsmLineFromAddr(int addr)
}
else
{
nextLine = line - 1;
if ( nextLine >= 0 )
{
while ( asmEntry[nextLine]->addr == asmEntry[line]->addr )
{
line = nextLine;
nextLine--;
if ( nextLine < 0 )
{
break;
}
}
}
run = 0; break;
}
}
@ -1217,6 +1231,20 @@ int QAsmView::getAsmLineFromAddr(int addr)
}
else
{
nextLine = line - 1;
if ( nextLine >= 0 )
{
while ( asmEntry[nextLine]->addr == asmEntry[line]->addr )
{
line = nextLine;
nextLine--;
if ( nextLine < 0 )
{
break;
}
}
}
run = 0; break;
}
line = nextLine;
@ -1282,7 +1310,7 @@ void QAsmView::updateAssemblyView(void)
char chr[64];
uint8 opcode[3];
const char *disassemblyText = NULL;
dbg_asm_entry_t *a;
dbg_asm_entry_t *a, *d;
//GtkTextIter iter, next_iter;
char pc_found = 0;
@ -1423,6 +1451,70 @@ void QAsmView::updateAssemblyView(void)
line.append("-------------------------");
}
if ( symbolicDebugEnable )
{
debugSymbol_t *dbgSym;
dbgSym = debugSymbolTable.getSymbolAtBankOffset( a->bank, a->addr );
if ( dbgSym != NULL )
{
int i,j;
const char *c;
char stmp[256];
printf("Debug symbol Found at $%04X \n", dbgSym->ofs );
d = new dbg_asm_entry_t();
*d = *a;
d->type = dbg_asm_entry_t::SYMBOL_NAME;
d->text.assign( dbgSym->name );
d->line = asmEntry.size();
asmEntry.push_back(d);
i=0; j=0;
c = dbgSym->comment.c_str();
while ( c[i] != 0 )
{
if ( c[i] == '\n' )
{
if ( j > 0 )
{
stmp[j] = 0;
d = new dbg_asm_entry_t();
*d = *a;
d->type = dbg_asm_entry_t::SYMBOL_COMMENT;
d->text.assign( stmp );
d->line = asmEntry.size();
asmEntry.push_back(d);
}
i++; j=0;
}
else
{
stmp[j] = c[i]; j++; i++;
}
}
stmp[j] = 0;
if ( j > 0 )
{
d = new dbg_asm_entry_t();
*d = *a;
d->type = dbg_asm_entry_t::SYMBOL_COMMENT;
d->text.assign( stmp );
d->line = asmEntry.size();
asmEntry.push_back(d);
}
}
}
a->text.assign( line );
a->line = asmEntry.size();
@ -1434,8 +1526,6 @@ void QAsmView::updateAssemblyView(void)
line.append("\n");
//asmText->insertPlainText( tr(line.c_str()) );
asmEntry.push_back(a);
}
@ -1816,6 +1906,7 @@ QAsmView::QAsmView(QWidget *parent)
hbar = NULL;
asmPC = NULL;
displayROMoffsets = false;
symbolicDebugEnable = true;
maxLineLen = 0;
lineOffset = 0;
maxLineOffset = 0;
@ -2104,12 +2195,16 @@ void QAsmView::paintEvent(QPaintEvent *event)
{
if ( l == asmPC->line )
{
painter.fillRect( 0, y - pxLineSpacing + pxLineLead, viewWidth, pxLineSpacing, QColor("light blue") );
painter.fillRect( 0, y - pxLineSpacing + pxLineLead, viewWidth, pxLineSpacing, QColor("pink") );
}
}
if ( l < asmEntry.size() )
{
if ( asmEntry[l]->type != dbg_asm_entry_t::ASM_TEXT )
{
painter.fillRect( 0, y - pxLineSpacing + pxLineLead, viewWidth, pxLineSpacing, QColor("light blue") );
}
painter.drawText( x, y, tr(asmEntry[l]->text.c_str()) );
}
y += pxLineSpacing;

View File

@ -25,6 +25,7 @@
#include <QScrollBar>
#include "Qt/main.h"
#include "Qt/SymbolicDebug.h"
#include "../../debug.h"
struct dbg_asm_entry_t
@ -37,11 +38,17 @@ struct dbg_asm_entry_t
uint8 opcode[3];
std::string text;
enum
{
ASM_TEXT = 0,
SYMBOL_NAME,
SYMBOL_COMMENT
} type;
dbg_asm_entry_t(void)
{
addr = 0; bank = 0; rom = -1;
size = 0; line = 0;
size = 0; line = 0; type = ASM_TEXT;
for (int i=0; i<3; i++)
{
@ -106,6 +113,7 @@ class QAsmView : public QWidget
std::vector <dbg_asm_entry_t*> asmEntry;
bool displayROMoffsets;
bool symbolicDebugEnable;
};
class ConsoleDebugger : public QDialog

View File

@ -32,6 +32,53 @@ debugSymbolPage_t::~debugSymbolPage_t(void)
symMap.clear();
}
//--------------------------------------------------------------
int debugSymbolPage_t::addSymbol( debugSymbol_t*sym )
{
std::map <int, debugSymbol_t*>::iterator it;
it = symMap.find( sym->ofs );
if ( it != symMap.end() )
{
return -1;
}
symMap[ sym->ofs ] = sym;
return 0;
}
//--------------------------------------------------------------
debugSymbol_t *debugSymbolPage_t::getSymbolAtOffset( int ofs )
{
debugSymbol_t*sym = NULL;
std::map <int, debugSymbol_t*>::iterator it;
it = symMap.find( ofs );
if ( it != symMap.end() )
{
sym = it->second;
}
return sym;
}
//--------------------------------------------------------------
void debugSymbolPage_t::print(void)
{
FILE *fp;
debugSymbol_t *sym;
std::map <int, debugSymbol_t*>::iterator it;
fp = stdout;
fprintf( fp, "Page: %X \n", pageNum );
for (it=symMap.begin(); it!=symMap.end(); it++)
{
sym = it->second;
fprintf( fp, " Sym: $%04X '%s' \n", sym->ofs, sym->name.c_str() );
}
}
//--------------------------------------------------------------
// debugSymbolTable_t
//--------------------------------------------------------------
debugSymbolTable_t::debugSymbolTable_t(void)
@ -104,7 +151,11 @@ static int generateNLFilenameForAddress(int address, char *NLfilename)
int debugSymbolTable_t::loadFileNL( int addr )
{
FILE *fp;
char fileName[512], line[256];
int i, j, ofs, lineNum = 0, literal = 0;
char fileName[512], line[512];
char stmp[512];
debugSymbolPage_t *page = NULL;
debugSymbol_t *sym = NULL;
printf("Looking to Load Debug Addr: $%04X \n", addr );
@ -120,9 +171,180 @@ int debugSymbolTable_t::loadFileNL( int addr )
{
return -1;
}
page = new debugSymbolPage_t;
if ( addr >= 0x8000 )
{
page->pageNum = getBank( addr );
}
pageMap[ page->pageNum ] = page;
while ( fgets( line, sizeof(line), fp ) != 0 )
{
printf("%s", line );
i=0; lineNum++;
printf("%4i:%s", lineNum, line );
if ( line[i] == '\\' )
{
// Line is a comment continuation line.
i++;
j=0;
stmp[j] = '\n'; j++;
while ( line[i] != 0 )
{
stmp[j] = line[i]; j++; i++;
}
stmp[j] = 0;
j--;
while ( j >= 0 )
{
if ( isspace( stmp[j] ) )
{
stmp[j] = 0;
}
else
{
break;
}
j--;
}
if ( sym != NULL )
{
sym->comment.append( stmp );
}
}
else if ( line[i] == '$' )
{
// Line is a new debug offset
j=0; i++;
if ( !isxdigit( line[i] ) )
{
printf("Error: Invalid Offset on Line %i of File %s\n", lineNum, fileName );
}
while ( isxdigit( line[i] ) )
{
stmp[j] = line[i]; i++; j++;
}
stmp[j] = 0;
ofs = strtol( stmp, NULL, 16 );
if ( line[i] != '#' )
{
printf("Error: Missing field delimiter following offset $%X on Line %i of File %s\n", ofs, lineNum, fileName );
continue;
}
i++;
while ( isspace(line[i]) ) i++;
j = 0;
while ( line[i] != 0 )
{
if ( line[i] == '\\' )
{
if ( literal )
{
switch ( line[i] )
{
case 'r':
stmp[j] = '\r';
break;
case 'n':
stmp[j] = '\n';
break;
case 't':
stmp[j] = '\t';
break;
default:
stmp[j] = line[i];
break;
}
j++; i++;
literal = 0;
}
else
{
i++;
literal = !literal;
}
}
else if ( line[i] == '#' )
{
break;
}
else
{
stmp[j] = line[i]; j++; i++;
}
}
stmp[j] = 0;
j--;
while ( j >= 0 )
{
if ( isspace( stmp[j] ) )
{
stmp[j] = 0;
}
else
{
break;
}
j--;
}
if ( line[i] != '#' )
{
printf("Error: Missing field delimiter following name '%s' on Line %i of File %s\n", stmp, lineNum, fileName );
continue;
}
i++;
sym = new debugSymbol_t();
if ( sym == NULL )
{
printf("Error: Failed to allocate memory for offset $%04X Name '%s' on Line %i of File %s\n", ofs, stmp, lineNum, fileName );
continue;
}
sym->ofs = ofs;
sym->name.assign( stmp );
while ( isspace( line[i] ) ) i++;
j=0;
while ( line[i] != 0 )
{
stmp[j] = line[i]; j++; i++;
}
stmp[j] = 0;
j--;
while ( j >= 0 )
{
if ( isspace( stmp[j] ) )
{
stmp[j] = 0;
}
else
{
break;
}
j--;
}
sym->comment.assign( stmp );
if ( page->addSymbol( sym ) )
{
printf("Error: Failed to add symbol for offset $%04X Name '%s' on Line %i of File %s\n", ofs, stmp, lineNum, fileName );
delete sym; sym = NULL; // Failed to add symbol
}
}
}
::fclose(fp);
@ -150,6 +372,35 @@ int debugSymbolTable_t::loadGameSymbols(void)
loadFileNL( pageIndexAddress );
}
print();
return 0;
}
//--------------------------------------------------------------
debugSymbol_t *debugSymbolTable_t::getSymbolAtBankOffset( int bank, int ofs )
{
debugSymbol_t*sym = NULL;
std::map <int, debugSymbolPage_t*>::iterator it;
it = pageMap.find( bank );
if ( it != pageMap.end() )
{
sym = (it->second)->getSymbolAtOffset( ofs );
}
return sym;
}
//--------------------------------------------------------------
void debugSymbolTable_t::print(void)
{
debugSymbolPage_t *page;
std::map <int, debugSymbolPage_t*>::iterator it;
for (it=pageMap.begin(); it!=pageMap.end(); it++)
{
page = it->second;
page->print();
}
}
//--------------------------------------------------------------

View File

@ -9,13 +9,13 @@
struct debugSymbol_t
{
int addr;
int ofs;
std::string name;
std::string comment;
debugSymbol_t(void)
{
addr = 0;
ofs = 0;
};
};
@ -26,6 +26,13 @@ struct debugSymbolPage_t
debugSymbolPage_t(void);
~debugSymbolPage_t(void);
void print(void);
int size(void){ return symMap.size(); }
int addSymbol( debugSymbol_t *sym );
debugSymbol_t *getSymbolAtOffset( int ofs );
std::map <int, debugSymbol_t*> symMap;
};
@ -38,8 +45,12 @@ class debugSymbolTable_t
int loadFileNL( int addr );
int loadGameSymbols(void);
int numPages(void){ return pageMap.size(); }
void clear(void);
void print(void);
debugSymbol_t *getSymbolAtBankOffset( int bank, int ofs );
private:
std::map <int, debugSymbolPage_t*> pageMap;