Fixed Tracer, changed Symbolic Names and Comments display

This commit is contained in:
ansstuff 2012-09-30 18:56:12 +00:00
parent 07fa1f268f
commit 572ac98f02
4 changed files with 66 additions and 45 deletions

View File

@ -86,7 +86,9 @@ bool debuggerSaveLoadDEBFiles = true;
bool debuggerDisplayROMoffsets = false; bool debuggerDisplayROMoffsets = false;
char debug_str[35000] = {0}; char debug_str[35000] = {0};
char debug_str_decoration[NL_MAX_MULTILINE_COMMENT_LEN + NL_MAX_NAME_LEN + 10] = {0}; char* debug_decoration_name;
char* debug_decoration_comment;
char debug_str_decoration_comment[NL_MAX_MULTILINE_COMMENT_LEN + 2] = {0};
// this is used to keep track of addresses that lines of Disassembly window correspont to // this is used to keep track of addresses that lines of Disassembly window correspont to
std::vector<unsigned int> disassembly_addresses; std::vector<unsigned int> disassembly_addresses;
@ -390,21 +392,34 @@ void Disassemble(HWND hWnd, int id, int scrollid, unsigned int addr)
if (symbDebugEnabled) if (symbDebugEnabled)
{ {
// Insert Name and Comment lines if needed // Insert Name and Comment lines if needed
debug_str_decoration[0] = 0; debug_decoration_name = 0;
decorateAddress(addr, debug_str_decoration); debug_decoration_comment = 0;
if (debug_str_decoration[0]) decorateAddress(addr, &debug_decoration_name, &debug_decoration_comment);
if (debug_decoration_name)
{ {
// divide the str_decoration into strings (Name, Comment1, Comment2, ...) strcat(debug_str, debug_decoration_name);
char* start_pos = debug_str_decoration; strcat(debug_str, ": \r\n");
char* end_pos = strstr(debug_str_decoration, "\r"); // we added one line to the disassembly window
disassembly_addresses.push_back(addr);
i++;
}
if (debug_decoration_comment)
{
// make a copy
strcpy(debug_str_decoration_comment, debug_decoration_comment);
strcat(debug_str_decoration_comment, "\r\n");
debug_decoration_comment = debug_str_decoration_comment;
// divide the debug_str_decoration_comment into strings (Comment1, Comment2, ...)
char* end_pos = strstr(debug_decoration_comment, "\r");
while (end_pos) while (end_pos)
{ {
end_pos[0] = 0; // set \0 instead of \r end_pos[0] = 0; // set \0 instead of \r
strcat(debug_str, start_pos); strcat(debug_str, "// ");
strcat(debug_str, debug_decoration_comment);
strcat(debug_str, "\r\n"); strcat(debug_str, "\r\n");
end_pos += 2; end_pos += 2;
start_pos = end_pos; debug_decoration_comment = end_pos;
end_pos = strstr(end_pos, "\r"); end_pos = strstr(debug_decoration_comment, "\r");
// we added one line to the disassembly window // we added one line to the disassembly window
disassembly_addresses.push_back(addr); disassembly_addresses.push_back(addr);
i++; i++;

View File

@ -40,6 +40,7 @@ extern char LoadedRomFName[2048];
char NLfilename[2048]; char NLfilename[2048];
char symbDebugEnabled = 0; char symbDebugEnabled = 0;
int debuggerWasActive = 0; int debuggerWasActive = 0;
char temp_chr[40] = {0};
extern BOOL CALLBACK nameBookmarkCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); extern BOOL CALLBACK nameBookmarkCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
extern char bookmarkDescription[]; extern char bookmarkDescription[];
@ -600,16 +601,12 @@ void loadNameFiles()
} }
/** /**
* Adds label and comment to an offset in the disassembly output string * Returns pointers to name and comment to an offset in the disassembly output string
* *
* @param addr Address of the currently processed line
* @param str Disassembly output string
**/ **/
void decorateAddress(unsigned int addr, char* str) void decorateAddress(unsigned int addr, char** str_name, char** str_comment)
{ {
Name* n; Name* n;
char temp_chr[40];
sprintf(temp_chr, "$%04X", addr); sprintf(temp_chr, "$%04X", addr);
if (addr < 0x8000) if (addr < 0x8000)
@ -622,24 +619,15 @@ void decorateAddress(unsigned int addr, char* str)
n = addr >= 0xC000 ? searchNode(lastBankNames, temp_chr) : searchNode(loadedBankNames, temp_chr); n = addr >= 0xC000 ? searchNode(lastBankNames, temp_chr) : searchNode(loadedBankNames, temp_chr);
} }
// If a node was found there's a name or comment to add do so if (n)
if (n && (n->name || n->comment))
{ {
// Add name // Return pointer to name
if (n->name && *n->name) if (n->name && *n->name)
{ *str_name = n->name;
strcat(str, "Name: ");
strcat(str, n->name);
strcat(str,"\r\n");
}
// Add comment // Return pointer to comment
if (n->comment && *n->comment) if (n->comment && *n->comment)
{ *str_comment = n->comment;
strcat(str, "Comment: ");
strcat(str, n->comment);
strcat(str, "\r\n");
}
} }
} }

View File

@ -39,7 +39,7 @@ extern int debuggerWasActive;
int checkCondition(const char* buffer, int num); int checkCondition(const char* buffer, int num);
void loadNameFiles(); void loadNameFiles();
void decorateAddress(unsigned int addr, char* str); void decorateAddress(unsigned int addr, char** str_name, char** str_comment);
void replaceNames(Name* list, char* str); void replaceNames(Name* list, char* str);
void AddDebuggerBookmark(HWND hwnd); void AddDebuggerBookmark(HWND hwnd);
void AddDebuggerBookmark2(HWND hwnd, unsigned int addr); void AddDebuggerBookmark2(HWND hwnd, unsigned int addr);

View File

@ -76,7 +76,10 @@ int tracelogbufusedsize;
char str_axystate[LOG_AXYSTATE_MAX_LEN] = {0}, str_procstatus[LOG_PROCSTATUS_MAX_LEN] = {0}; char str_axystate[LOG_AXYSTATE_MAX_LEN] = {0}, str_procstatus[LOG_PROCSTATUS_MAX_LEN] = {0};
char str_tabs[LOG_TABS_MASK+1] = {0}, str_address[LOG_ADDRESS_MAX_LEN] = {0}, str_data[LOG_DATA_MAX_LEN] = {0}, str_disassembly[LOG_DISASSEMBLY_MAX_LEN] = {0}; char str_tabs[LOG_TABS_MASK+1] = {0}, str_address[LOG_ADDRESS_MAX_LEN] = {0}, str_data[LOG_DATA_MAX_LEN] = {0}, str_disassembly[LOG_DISASSEMBLY_MAX_LEN] = {0};
char str_temp[LOG_LINE_MAX_LEN] = {0}; char str_temp[LOG_LINE_MAX_LEN] = {0};
char str_decoration[NL_MAX_MULTILINE_COMMENT_LEN + NL_MAX_NAME_LEN + 10] = {0}; char* tracer_decoration_name;
char* tracer_decoration_comment;
char str_decoration[NL_MAX_MULTILINE_COMMENT_LEN + 2] = {0};
char str_decoration_comment[NL_MAX_MULTILINE_COMMENT_LEN + 2] = {0};
bool log_old_emu_paused = true; // thanks to this flag the window only updates once after the game is paused bool log_old_emu_paused = true; // thanks to this flag the window only updates once after the game is paused
extern bool JustFrameAdvanced; extern bool JustFrameAdvanced;
@ -385,7 +388,7 @@ void FCEUD_TraceInstruction(uint8 *opcode, int size)
case 1: case 1:
{ {
sprintf(str_data, "%02X ", opcode[0]); sprintf(str_data, "%02X ", opcode[0]);
a = Disassemble(addr, opcode); a = Disassemble(addr + 1, opcode);
// special case: an RTS opcode // special case: an RTS opcode
if (opcode[0] == 0x60) if (opcode[0] == 0x60)
{ {
@ -399,11 +402,11 @@ void FCEUD_TraceInstruction(uint8 *opcode, int size)
} }
case 2: case 2:
sprintf(str_data, "%02X %02X ", opcode[0],opcode[1]); sprintf(str_data, "%02X %02X ", opcode[0],opcode[1]);
a = Disassemble(addr, opcode); a = Disassemble(addr + 2, opcode);
break; break;
case 3: case 3:
sprintf(str_data, "%02X %02X %02X ", opcode[0],opcode[1],opcode[2]); sprintf(str_data, "%02X %02X %02X ", opcode[0],opcode[1],opcode[2]);
a = Disassemble(addr, opcode); a = Disassemble(addr + 3, opcode);
break; break;
} }
@ -412,20 +415,32 @@ void FCEUD_TraceInstruction(uint8 *opcode, int size)
if (logging_options & LOG_SYMBOLIC) if (logging_options & LOG_SYMBOLIC)
{ {
// Insert Name and Comment lines if needed // Insert Name and Comment lines if needed
str_decoration[0] = 0; tracer_decoration_name = 0;
decorateAddress(addr, str_decoration); tracer_decoration_comment = 0;
if (str_decoration[0]) decorateAddress(addr, &tracer_decoration_name, &tracer_decoration_comment);
if (tracer_decoration_name)
{ {
// divide the str_decoration into strings (Name, Comment1, Comment2, ...) strcpy(str_decoration, tracer_decoration_name);
char* start_pos = str_decoration; strcat(str_decoration, ": ");
char* end_pos = strstr(str_decoration, "\r"); OutputLogLine(str_decoration, true);
}
if (tracer_decoration_comment)
{
// make a copy
strcpy(str_decoration_comment, tracer_decoration_comment);
strcat(str_decoration_comment, "\r\n");
tracer_decoration_comment = str_decoration_comment;
// divide the str_decoration_comment into strings (Comment1, Comment2, ...)
char* end_pos = strstr(tracer_decoration_comment, "\r");
while (end_pos) while (end_pos)
{ {
end_pos[0] = 0; // set \0 instead of \r end_pos[0] = 0; // set \0 instead of \r
OutputLogLine(start_pos, true); strcpy(str_decoration, "// ");
strcat(str_decoration, tracer_decoration_comment);
OutputLogLine(str_decoration, true);
end_pos += 2; end_pos += 2;
start_pos = end_pos; tracer_decoration_comment = end_pos;
end_pos = strstr(end_pos, "\r"); end_pos = strstr(tracer_decoration_comment, "\r");
} }
} }
replaceNames(ramBankNames, a); replaceNames(ramBankNames, a);
@ -601,8 +616,11 @@ void UpdateLogText(void)
int i, j; int i, j;
char str[3000]; char str[3000];
str[0] = 0; str[0] = 0;
int last_line = tracesi.nPos + tracesi.nPage;
if (last_line > tracesi.nMax)
last_line = tracesi.nMax;
for(i = tracesi.nPos;i < std::min(tracesi.nMax,tracesi.nPos+21);i++) for(i = tracesi.nPos; i < last_line; i++)
{ {
j = i; j = i;
if(tracelogbufusedsize == tracelogbufsize) if(tracelogbufusedsize == tracelogbufsize)