From 47b6ecae8f96f86ae72d0a76ada94c943bad54b3 Mon Sep 17 00:00:00 2001 From: Jean-Paul Mari Date: Wed, 22 Aug 2018 01:57:07 -0400 Subject: [PATCH] Local variables window detects now if a variable is used or not by the code --- docs/vj_ReleaseNotes.txt | 1 + src/debugger/DWARFManager.cpp | 19 +++++++++-- src/debugger/localbrowser.cpp | 61 +++++++++++++++++++++-------------- 3 files changed, 54 insertions(+), 27 deletions(-) diff --git a/docs/vj_ReleaseNotes.txt b/docs/vj_ReleaseNotes.txt index b968540..5df4915 100644 --- a/docs/vj_ReleaseNotes.txt +++ b/docs/vj_ReleaseNotes.txt @@ -10,6 +10,7 @@ Release 4 (TBD) 7) ROM cartridge writing detection follow the alpine "allow writes to cartridge rom"'s flag check -- Breakpoint can now occur in the case of a ROM cartridge writing -- Alert box will display a message with possibility to pass or not the breakpoint only if this is related to a 8 or 16 bits ROM access +8) Local variables window detects now if a variable is used or not by the code Release 3 (13th November 2017) ------------------------------ diff --git a/src/debugger/DWARFManager.cpp b/src/debugger/DWARFManager.cpp index 3817763..b6c149e 100644 --- a/src/debugger/DWARFManager.cpp +++ b/src/debugger/DWARFManager.cpp @@ -675,11 +675,18 @@ void DWARFManager_InitDMI(void) case 2: PtrCU[NbCU].PtrSubProgs[PtrCU[NbCU].NbSubProgs].PtrVariables[PtrCU[NbCU].PtrSubProgs[PtrCU[NbCU].NbSubProgs].NbVariables].Offset = *((char *)(return_block->bl_data) + 1); - if (return_tagval == DW_TAG_variable) + switch (return_tagval) { + case DW_TAG_variable: PtrCU[NbCU].PtrSubProgs[PtrCU[NbCU].NbSubProgs].PtrVariables[PtrCU[NbCU].PtrSubProgs[PtrCU[NbCU].NbSubProgs].NbVariables].Offset -= 0x80; + break; + + case DW_TAG_formal_parameter: + break; + + default: + break; } - break; default: break; @@ -709,6 +716,12 @@ void DWARFManager_InitDMI(void) } break; + case DW_AT_decl_file: + break; + + case DW_AT_decl_line: + break; + default: break; } @@ -749,7 +762,9 @@ void DWARFManager_InitDMI(void) // Release the memory used by the source lines for (i = 0; i < (size_t)cnt; ++i) + { dwarf_dealloc(dbg, linebuf[i], DW_DLA_LINE); + } dwarf_dealloc(dbg, linebuf, DW_DLA_LIST); } diff --git a/src/debugger/localbrowser.cpp b/src/debugger/localbrowser.cpp index 77e7102..c5782da 100644 --- a/src/debugger/localbrowser.cpp +++ b/src/debugger/localbrowser.cpp @@ -78,23 +78,27 @@ bool LocalBrowserWindow::UpdateInfos(void) { if (strcmp(FuncName, Ptr)) { - FuncName = (char *)realloc(FuncName, strlen(Ptr) + 1); - strcpy(FuncName, Ptr); - - LocalInfo = (WatchInfo *)realloc(LocalInfo, (sizeof(WatchInfo) * NbLocal)); - for (size_t i = 0; i < NbLocal; i++) + if (FuncName = (char *)realloc(FuncName, strlen(Ptr) + 1)) { - // Get local variable name and his information - if (LocalInfo[i].PtrVariableName = DBGManager_GetLocalVariableName(Adr, i + 1)) + strcpy(FuncName, Ptr); + + if (LocalInfo = (WatchInfo *)realloc(LocalInfo, (sizeof(WatchInfo) * NbLocal))) { - LocalInfo[i].Op = DBGManager_GetLocalVariableOp(Adr, i + 1); - LocalInfo[i].Adr = NULL; - LocalInfo[i].PtrCPURegisterName = NULL; - LocalInfo[i].TypeTag = DBGManager_GetLocalVariableTypeTag(Adr, i + 1); - LocalInfo[i].PtrVariableBaseTypeName = DBGManager_GetLocalVariableTypeName(Adr, i + 1); - LocalInfo[i].TypeEncoding = DBGManager_GetLocalVariableTypeEncoding(Adr, i + 1); - LocalInfo[i].TypeByteSize = DBGManager_GetLocalVariableTypeByteSize(Adr, i + 1); - LocalInfo[i].Offset = DBGManager_GetLocalVariableOffset(Adr, i + 1); + for (size_t i = 0; i < NbLocal; i++) + { + // Get local variable name and his information + if (LocalInfo[i].PtrVariableName = DBGManager_GetLocalVariableName(Adr, i + 1)) + { + LocalInfo[i].Op = DBGManager_GetLocalVariableOp(Adr, i + 1); + LocalInfo[i].Adr = NULL; + LocalInfo[i].PtrCPURegisterName = NULL; + LocalInfo[i].TypeTag = DBGManager_GetLocalVariableTypeTag(Adr, i + 1); + LocalInfo[i].PtrVariableBaseTypeName = DBGManager_GetLocalVariableTypeName(Adr, i + 1); + LocalInfo[i].TypeEncoding = DBGManager_GetLocalVariableTypeEncoding(Adr, i + 1); + LocalInfo[i].TypeByteSize = DBGManager_GetLocalVariableTypeByteSize(Adr, i + 1); + LocalInfo[i].Offset = DBGManager_GetLocalVariableOffset(Adr, i + 1); + } + } } } } @@ -174,26 +178,33 @@ void LocalBrowserWindow::RefreshContents(void) } } - sprintf(string, "%i : %s | %s | ", (i + 1), (LocalInfo[i].PtrVariableBaseTypeName ? LocalInfo[i].PtrVariableBaseTypeName : (char *)"N/A"), LocalInfo[i].PtrVariableName); - Local += QString(string); - if ((unsigned int)LocalInfo[i].Adr) + if (!LocalInfo[i].Op) { - sprintf(string, "0x%06X", (unsigned int)LocalInfo[i].Adr); + sprintf(string, "%i : %s | %s | [Not used]", (i + 1), (LocalInfo[i].PtrVariableBaseTypeName ? LocalInfo[i].PtrVariableBaseTypeName : (char *)"N/A"), LocalInfo[i].PtrVariableName); } else { - if (LocalInfo[i].PtrCPURegisterName) + sprintf(string, "%i : %s | %s | ", (i + 1), (LocalInfo[i].PtrVariableBaseTypeName ? LocalInfo[i].PtrVariableBaseTypeName : (char *)"N/A"), LocalInfo[i].PtrVariableName); + Local += QString(string); + if ((unsigned int)LocalInfo[i].Adr) { - sprintf(string, "%s", LocalInfo[i].PtrCPURegisterName); + sprintf(string, "0x%06X", (unsigned int)LocalInfo[i].Adr); } else { - sprintf(string, "%s", (char *)"N/A"); - } + if (LocalInfo[i].PtrCPURegisterName) + { + sprintf(string, "%s", LocalInfo[i].PtrCPURegisterName); + } + else + { + sprintf(string, "%s", (char *)"N/A"); + } + } + Local += QString(string); + sprintf(string, " | %s", (!PtrValue ? (char *)"N/A" : PtrValue)); } Local += QString(string); - sprintf(string, " | %s", (!PtrValue ? (char *)"N/A" : PtrValue)); - Local += QString(string); sprintf(string, "
"); Local += QString(string); } -- 2.20.1