From: Jean-Paul Mari Date: Fri, 12 Oct 2018 07:06:23 +0000 (-0400) Subject: Added search paths in case of missing DWARF directories information X-Git-Tag: v2.1.3-R4~18 X-Git-Url: http://git.hcoop.net/clinton/Virtual-Jaguar-Rx.git/commitdiff_plain/f0dd2f7b7cc2f165b00dedcbc5bf6fbaa2ca136d Added search paths in case of missing DWARF directories information --- diff --git a/Win-VS2017/virtualjaguar.vcxproj b/Win-VS2017/virtualjaguar.vcxproj index 3ee9d8b..24f7707 100644 --- a/Win-VS2017/virtualjaguar.vcxproj +++ b/Win-VS2017/virtualjaguar.vcxproj @@ -505,10 +505,7 @@ true true - - true - true - + true true diff --git a/docs/vj_ReleaseNotes.txt b/docs/vj_ReleaseNotes.txt index fb3e78b..ccb55e6 100644 --- a/docs/vj_ReleaseNotes.txt +++ b/docs/vj_ReleaseNotes.txt @@ -68,6 +68,8 @@ Git commit: TBD 35) Added the support for the used lines source's DWARF structure -- Mostly used to handle missing subprogram's lines information, and missing CU's low/high PC 36) Added the Rx version's contact in the help text +37) Added search paths in case of missing DWARF directories information +-- Used to look for the file(s) Release 3 (13th November 2017) ------------------------------ diff --git a/src/debugger/DBGManager.cpp b/src/debugger/DBGManager.cpp index e3d5956..720fefc 100644 --- a/src/debugger/DBGManager.cpp +++ b/src/debugger/DBGManager.cpp @@ -11,7 +11,7 @@ // JPM Various efforts to set the ELF format support // JPM Various efforts to set the DWARF format support // JPM 09/15/2018 Support the unsigned char -// JPM 10/06/2018 Cosmetic changes +// JPM Oct./2018 Cosmetic changes, and added source file search paths // // To Do @@ -50,16 +50,109 @@ struct Value }S_Value; +// +void DBGManager_SourceFileSearchPathsInit(void); +void DBGManager_SourceFileSearchPathsReset(void); +void DBGManager_SourceFileSearchPathsClose(void); + + // Common debugger variables size_t DBGType; char value[1000]; +size_t NbSFSearchPaths; +char **SourceFileSearchPaths; + + +// Init the source file search paths +void DBGManager_SourceFileSearchPathsInit(void) +{ + NbSFSearchPaths = 0; + SourceFileSearchPaths = NULL; +} + + +// Set the source file search paths +// Create individual path for each one provided in the list (separate with ';') +void DBGManager_SourceFileSearchPathsSet(char *ListPaths) +{ + // Check presence of a previous list + if (NbSFSearchPaths) + { + // Reset previous list + DBGManager_SourceFileSearchPathsReset(); + } + + // Check if there is a paths list + if (strlen(ListPaths)) + { + // Get number of paths + char *Ptr = ListPaths; + while(*Ptr) + { + while (*Ptr && (*Ptr++ != ';')); + { + NbSFSearchPaths++; + } + } + + // Isolate each search path + SourceFileSearchPaths = (char **)calloc(NbSFSearchPaths, sizeof(char *)); + size_t i = 0; + Ptr = ListPaths; + + while (*Ptr) + { + // Search the path separator (';') + char *Ptr1 = Ptr; + while (*Ptr && (*Ptr++ != ';')); + + // Copy the inidividual search path + SourceFileSearchPaths[i] = (char *)calloc(1, (Ptr - Ptr1) + 1); + strncpy(SourceFileSearchPaths[i], Ptr1, (Ptr - Ptr1)); + if (SourceFileSearchPaths[i][strlen(SourceFileSearchPaths[i]) - 1] == ';') + { + SourceFileSearchPaths[i][strlen(SourceFileSearchPaths[i]) - 1] = 0; + } + i++; + } + } + + DWARFManager_Set(NbSFSearchPaths, SourceFileSearchPaths); +} + + +// Reset the source file search paths +void DBGManager_SourceFileSearchPathsReset(void) +{ + // Free each path + while (NbSFSearchPaths) + { + free(SourceFileSearchPaths[--NbSFSearchPaths]); + } + + // Free the pointers list + free(SourceFileSearchPaths); + SourceFileSearchPaths = NULL; +} + + +// Close the source file search paths +void DBGManager_SourceFileSearchPathsClose(void) +{ + DBGManager_SourceFileSearchPathsReset(); +} // Common debugger initialisation void DBGManager_Init(void) { + // DBG initialisations DBGType = DBG_NO_TYPE; + DBGManager_SourceFileSearchPathsInit(); + + // ELF initialisation ELFManager_Init(); + // DWARF initialisation DWARFManager_Init(); } @@ -82,20 +175,6 @@ void DBGManager_Reset(void) } -// Get debugger type -size_t DBGManager_GetType(void) -{ - return DBGType; -} - - -// Common debugger set -void DBGManager_SetType(size_t DBGTypeSet) -{ - DBGType |= DBGTypeSet; -} - - // Common debugger close void DBGManager_Close(void) { @@ -108,6 +187,23 @@ void DBGManager_Close(void) { ELFManager_Close(); } + + DBGManager_SourceFileSearchPathsClose(); + DBGType = DBG_NO_TYPE; +} + + +// Common debugger set +void DBGManager_SetType(size_t DBGTypeSet) +{ + DBGType |= DBGTypeSet; +} + + +// Get debugger type +size_t DBGManager_GetType(void) +{ + return DBGType; } diff --git a/src/debugger/DBGManager.h b/src/debugger/DBGManager.h index fd9a159..bf0181b 100644 --- a/src/debugger/DBGManager.h +++ b/src/debugger/DBGManager.h @@ -226,6 +226,7 @@ extern void DBGManager_SetType(size_t DBGTypeSet); extern size_t DBGManager_GetType(void); extern void DBGManager_Reset(void); extern void DBGManager_Close(void); +extern void DBGManager_SourceFileSearchPathsSet(char *ListPaths); // Source text lines manager extern size_t DBGManager_GetNumLineFromAdr(size_t Adr, size_t Tag); diff --git a/src/debugger/DWARFManager.cpp b/src/debugger/DWARFManager.cpp index bd6507b..9c497f4 100644 --- a/src/debugger/DWARFManager.cpp +++ b/src/debugger/DWARFManager.cpp @@ -9,7 +9,7 @@ // --- ---------- ------------------------------------------------------------ // JPM Dec./2016 Created this file, and added the DWARF format support // JPM Sept./2018 Added LEB128 decoding features, and improve the DWARF parsing information -// JPM Oct./2018 Improve the DWARF parsing information, the source file text reading, and Support the used lines source DWARF structure +// JPM Oct./2018 Improve the DWARF parsing information, and the source file text reading; support the used source lines from DWARF structure, and the search paths for the files // // To Do @@ -152,6 +152,8 @@ Dwarf_Ptr errarg; Dwarf_Error error; Dwarf_Debug dbg; CUStruct *PtrCU; +char **ListSearchPaths; +size_t NbSearchPaths; // @@ -161,6 +163,9 @@ void DWARFManager_CloseDMI(void); bool DWARFManager_ElfClose(void); char *DWARFManager_GetLineSrcFromNumLine(char *PtrSrcFile, size_t NumLine); void DWARFManager_InitInfosVariable(VariablesStruct *PtrVariables); +void DWARFManager_SourceFileSearchPathsInit(void); +void DWARFManager_SourceFileSearchPathsReset(void); +void DWARFManager_SourceFileSearchPathsClose(void); // @@ -170,16 +175,50 @@ Dwarf_Handler DWARFManager_ErrorHandler(Dwarf_Ptr perrarg) } +// Dwarf manager list search paths init +void DWARFManager_SourceFileSearchPathsInit(void) +{ + ListSearchPaths = NULL; + NbSearchPaths = 0; +} + + +// Dwarf manager list search paths reset +void DWARFManager_SourceFileSearchPathsReset(void) +{ + ListSearchPaths = NULL; + NbSearchPaths = 0; +} + + +// Dwarf manager list search paths close +void DWARFManager_SourceFileSearchPathsClose(void) +{ + DWARFManager_SourceFileSearchPathsReset(); +} + + // Dwarf manager init void DWARFManager_Init(void) { + DWARFManager_SourceFileSearchPathsInit(); LibDwarf = DW_DLV_NO_ENTRY; } +// Dwarf manager settings +void DWARFManager_Set(size_t NbPathsInList, char **PtrListPaths) +{ + // Search paths init + ListSearchPaths = PtrListPaths; + NbSearchPaths = NbPathsInList; +} + + // Dwarf manager Reset bool DWARFManager_Reset(void) { + DWARFManager_SourceFileSearchPathsReset(); return DWARFManager_ElfClose(); } @@ -187,6 +226,7 @@ bool DWARFManager_Reset(void) // Dwarf manager Close bool DWARFManager_Close(void) { + DWARFManager_SourceFileSearchPathsClose(); return(DWARFManager_Reset()); } @@ -394,23 +434,46 @@ void DWARFManager_InitDMI(void) dwarf_dealloc(dbg, atlist, DW_DLA_LIST); } - // Check filename validity + // Check filename presence if (!PtrCU[NbCU].PtrSourceFilename) { PtrCU[NbCU].PtrSourceFilename = (char *)calloc(1, 1); } - // Check directory validity + // Check directory presence if (!PtrCU[NbCU].PtrSourceFileDirectory) { - PtrCU[NbCU].PtrSourceFileDirectory = (char *)calloc(2, 1); - PtrCU[NbCU].PtrSourceFileDirectory[0] = '.'; + // Check if file exists in the search paths + for (size_t i = 0; i < NbSearchPaths; i++) + { + PtrCU[NbCU].PtrFullFilename = (char *)realloc(PtrCU[NbCU].PtrFullFilename, strlen(PtrCU[NbCU].PtrSourceFilename) + strlen((const char *)ListSearchPaths[i]) + 2); +#if defined(_WIN32) + sprintf(PtrCU[NbCU].PtrFullFilename, "%s\\%s", ListSearchPaths[i], PtrCU[NbCU].PtrSourceFilename); +#else + sprintf(PtrCU[NbCU].PtrFullFilename, "%s/%s", ListSearchPaths[i], PtrCU[NbCU].PtrSourceFilename); +#endif + if (!fopen_s(&SrcFile, PtrCU[NbCU].PtrFullFilename, "rb")) + { + PtrCU[NbCU].PtrSourceFileDirectory = (char *)realloc(PtrCU[NbCU].PtrSourceFileDirectory, strlen(ListSearchPaths[i]) + 1); + strcpy(PtrCU[NbCU].PtrSourceFileDirectory, ListSearchPaths[i]); + } + } + + // File directory doesn't exits + if (!PtrCU[NbCU].PtrSourceFileDirectory) + { + PtrCU[NbCU].PtrSourceFileDirectory = (char *)realloc(PtrCU[NbCU].PtrSourceFileDirectory, 2); + strcpy(PtrCU[NbCU].PtrSourceFileDirectory, "."); + } } // Create full filename Ptr = PtrCU[NbCU].PtrFullFilename = (char *)realloc(PtrCU[NbCU].PtrFullFilename, strlen(PtrCU[NbCU].PtrSourceFilename) + strlen(PtrCU[NbCU].PtrSourceFileDirectory) + 2); +#if defined(_WIN32) sprintf(PtrCU[NbCU].PtrFullFilename, "%s\\%s", PtrCU[NbCU].PtrSourceFileDirectory, PtrCU[NbCU].PtrSourceFilename); - +#else + sprintf(PtrCU[NbCU].PtrFullFilename, "%s/%s", PtrCU[NbCU].PtrSourceFileDirectory, PtrCU[NbCU].PtrSourceFilename); +#endif // Conform slashes and backslashes while (*Ptr) { @@ -1064,14 +1127,6 @@ void DWARFManager_InitDMI(void) PtrCU[NbCU].PtrLinesSrc[i].PtrLineSrc = PtrCU[NbCU].PtrLinesLoadSrc[PtrCU[NbCU].PtrLinesSrc[i].NumLineSrc - 1]; } } - - // Setup memory range for the code if CU doesn't have already this information - // It is taken from the used lines structure - if (!PtrCU[NbCU].LowPC && !PtrCU[NbCU].HighPC) - { - PtrCU[NbCU].LowPC = PtrCU[NbCU].PtrLinesSrc[0].StartPC; - PtrCU[NbCU].HighPC = PtrCU[NbCU].PtrLinesSrc[PtrCU[NbCU].NbLinesSrc - 1].StartPC; - } } // Init global variables information based on types information @@ -1243,13 +1298,11 @@ void DWARFManager_InitInfosVariable(VariablesStruct *PtrVariables) // Return NULL if no symbol name exists char *DWARFManager_GetSymbolnameFromAdr(size_t Adr) { - size_t i, j; - - for (i = 0; i < NbCU; i++) + for (size_t i = 0; i < NbCU; i++) { if ((Adr >= PtrCU[i].LowPC) && (Adr < PtrCU[i].HighPC)) { - for (j = 0; (j < PtrCU[i].NbSubProgs); j++) + for (size_t j = 0; j < PtrCU[i].NbSubProgs; j++) { if ((PtrCU[i].PtrSubProgs[j].StartPC == Adr)) { @@ -1268,9 +1321,7 @@ char *DWARFManager_GetSymbolnameFromAdr(size_t Adr) // Return the existence status (true or false) in Error char *DWARFManager_GetFullSourceFilenameFromAdr(size_t Adr, bool *Error) { - size_t i; - - for (i = 0; i < NbCU; i++) + for (size_t i = 0; i < NbCU; i++) { if ((Adr >= PtrCU[i].LowPC) && (Adr < PtrCU[i].HighPC)) { @@ -1283,7 +1334,7 @@ char *DWARFManager_GetFullSourceFilenameFromAdr(size_t Adr, bool *Error) } -// Get text line source based on line number (starting by 1) +// Get text line source based on line number (starting from 1) // Return NULL if no text line exists or if line number is 0 char *DWARFManager_GetLineSrcFromNumLine(char *PtrSrcFile, size_t NumLine) { @@ -1307,13 +1358,11 @@ char *DWARFManager_GetLineSrcFromNumLine(char *PtrSrcFile, size_t NumLine) // Get number of variables referenced by the function range address size_t DWARFManager_GetNbLocalVariables(size_t Adr) { - size_t i, j; - - for (i = 0; i < NbCU; i++) + for (size_t i = 0; i < NbCU; i++) { if ((Adr >= PtrCU[i].LowPC) && (Adr < PtrCU[i].HighPC)) { - for (j = 0; j < PtrCU[i].NbSubProgs; j++) + for (size_t j = 0; j < PtrCU[i].NbSubProgs; j++) { if ((Adr >= PtrCU[i].PtrSubProgs[j].LowPC) && (Adr < PtrCU[i].PtrSubProgs[j].HighPC)) { @@ -1327,18 +1376,16 @@ size_t DWARFManager_GetNbLocalVariables(size_t Adr) } -// Get local variable name based on his index (starting by 1) +// Get local variable name based on his index (starting from 1) // Return name's pointer text found // Return NULL if not found char *DWARFManager_GetLocalVariableName(size_t Adr, size_t Index) { - size_t i, j; - - for (i = 0; i < NbCU; i++) + for (size_t i = 0; i < NbCU; i++) { if ((Adr >= PtrCU[i].LowPC) && (Adr < PtrCU[i].HighPC)) { - for (j = 0; j < PtrCU[i].NbSubProgs; j++) + for (size_t j = 0; j < PtrCU[i].NbSubProgs; j++) { if ((Adr >= PtrCU[i].PtrSubProgs[j].LowPC) && (Adr < PtrCU[i].PtrSubProgs[j].HighPC)) { @@ -1352,17 +1399,15 @@ char *DWARFManager_GetLocalVariableName(size_t Adr, size_t Index) } -// Get local variable's type tag based on his index (starting by 1) +// Get local variable's type tag based on his index (starting from 1) // Return 0 if not found size_t DWARFManager_GetLocalVariableTypeTag(size_t Adr, size_t Index) { - size_t i, j; - - for (i = 0; i < NbCU; i++) + for (size_t i = 0; i < NbCU; i++) { if ((Adr >= PtrCU[i].LowPC) && (Adr < PtrCU[i].HighPC)) { - for (j = 0; j < PtrCU[i].NbSubProgs; j++) + for (size_t j = 0; j < PtrCU[i].NbSubProgs; j++) { if ((Adr >= PtrCU[i].PtrSubProgs[j].LowPC) && (Adr < PtrCU[i].PtrSubProgs[j].HighPC)) { @@ -1376,16 +1421,15 @@ size_t DWARFManager_GetLocalVariableTypeTag(size_t Adr, size_t Index) } -// +// Get the local variable's offset based on a index (starting from 1) +// Return 0 if no offset has been found int DWARFManager_GetLocalVariableOffset(size_t Adr, size_t Index) { - size_t i, j; - - for (i = 0; i < NbCU; i++) + for (size_t i = 0; i < NbCU; i++) { if ((Adr >= PtrCU[i].LowPC) && (Adr < PtrCU[i].HighPC)) { - for (j = 0; j < PtrCU[i].NbSubProgs; j++) + for (size_t j = 0; j < PtrCU[i].NbSubProgs; j++) { if ((Adr >= PtrCU[i].PtrSubProgs[j].LowPC) && (Adr < PtrCU[i].PtrSubProgs[j].HighPC)) { @@ -1399,18 +1443,16 @@ int DWARFManager_GetLocalVariableOffset(size_t Adr, size_t Index) } -// Get local variable Type Byte Size based on his address and index (starting by 1) +// Get local variable Type Byte Size based on his address and index (starting from 1) // Return 0 if not found // May return 0 if there is no Type Byte Size linked to the variable's address and index size_t DWARFManager_GetLocalVariableTypeByteSize(size_t Adr, size_t Index) { - size_t i, j; - - for (i = 0; i < NbCU; i++) + for (size_t i = 0; i < NbCU; i++) { if ((Adr >= PtrCU[i].LowPC) && (Adr < PtrCU[i].HighPC)) { - for (j = 0; j < PtrCU[i].NbSubProgs; j++) + for (size_t j = 0; j < PtrCU[i].NbSubProgs; j++) { if ((Adr >= PtrCU[i].PtrSubProgs[j].LowPC) && (Adr < PtrCU[i].PtrSubProgs[j].HighPC)) { @@ -1424,18 +1466,16 @@ size_t DWARFManager_GetLocalVariableTypeByteSize(size_t Adr, size_t Index) } -// Get local variable Type Encoding based on his address and index (starting by 1) +// Get local variable Type Encoding based on his address and index (starting from 1) // Return 0 if not found // May return 0 if there is no Type Encoding linked to the variable's address and index size_t DWARFManager_GetLocalVariableTypeEncoding(size_t Adr, size_t Index) { - size_t i, j; - - for (i = 0; i < NbCU; i++) + for (size_t i = 0; i < NbCU; i++) { if ((Adr >= PtrCU[i].LowPC) && (Adr < PtrCU[i].HighPC)) { - for (j = 0; j < PtrCU[i].NbSubProgs; j++) + for (size_t j = 0; j < PtrCU[i].NbSubProgs; j++) { if ((Adr >= PtrCU[i].PtrSubProgs[j].LowPC) && (Adr < PtrCU[i].PtrSubProgs[j].HighPC)) { @@ -1449,17 +1489,15 @@ size_t DWARFManager_GetLocalVariableTypeEncoding(size_t Adr, size_t Index) } -// Get local variable Op based on his address and index (starting by 1) +// Get local variable Op based on his address and index (starting from 1) // Return 0 if not found, may return 0 if there isn't Op linked to the variable's index size_t DWARFManager_GetLocalVariableOp(size_t Adr, size_t Index) { - size_t i, j; - - for (i = 0; i < NbCU; i++) + for (size_t i = 0; i < NbCU; i++) { if ((Adr >= PtrCU[i].LowPC) && (Adr < PtrCU[i].HighPC)) { - for (j = 0; j < PtrCU[i].NbSubProgs; j++) + for (size_t j = 0; j < PtrCU[i].NbSubProgs; j++) { if ((Adr >= PtrCU[i].PtrSubProgs[j].LowPC) && (Adr < PtrCU[i].PtrSubProgs[j].HighPC)) { @@ -1473,17 +1511,15 @@ size_t DWARFManager_GetLocalVariableOp(size_t Adr, size_t Index) } -// Get local variable type name based on his index (starting by 1) and an address +// Get local variable type name based on his index (starting from 1) and an address // Return NULL if not found, may also return NULL if there is no type linked to the variable's index char *DWARFManager_GetLocalVariableTypeName(size_t Adr, size_t Index) { - size_t i, j; - - for (i = 0; i < NbCU; i++) + for (size_t i = 0; i < NbCU; i++) { if ((Adr >= PtrCU[i].LowPC) && (Adr < PtrCU[i].HighPC)) { - for (j = 0; j < PtrCU[i].NbSubProgs; j++) + for (size_t j = 0; j < PtrCU[i].NbSubProgs; j++) { if ((Adr >= PtrCU[i].PtrSubProgs[j].LowPC) && (Adr < PtrCU[i].PtrSubProgs[j].HighPC)) { @@ -1501,9 +1537,9 @@ char *DWARFManager_GetLocalVariableTypeName(size_t Adr, size_t Index) // Return number of variables size_t DWARFManager_GetNbGlobalVariables(void) { - size_t NbVariables = 0, i; + size_t NbVariables = 0; - for (i = 0; i < NbCU; i++) + for (size_t i = 0; i < NbCU; i++) { NbVariables += PtrCU[i].NbVariables; } @@ -1512,14 +1548,12 @@ size_t DWARFManager_GetNbGlobalVariables(void) } -// Get global variable type name based on his index (starting by 1) +// Get global variable type name based on his index (starting from 1) // Return NULL if not found // May return NULL if there is not type linked to the variable's index char *DWARFManager_GetGlobalVariableTypeName(size_t Index) { - size_t i; - - for (i = 0; i < NbCU; i++) + for (size_t i = 0; i < NbCU; i++) { if (PtrCU[i].NbVariables) { @@ -1538,13 +1572,11 @@ char *DWARFManager_GetGlobalVariableTypeName(size_t Index) } -// Get global variable's type tag based on his index (starting by 1) +// Get global variable's type tag based on his index (starting from 1) // Return 0 if not found size_t DWARFManager_GetGlobalVariableTypeTag(size_t Index) { - size_t i; - - for (i = 0; i < NbCU; i++) + for (size_t i = 0; i < NbCU; i++) { if (PtrCU[i].NbVariables) { @@ -1563,13 +1595,11 @@ size_t DWARFManager_GetGlobalVariableTypeTag(size_t Index) } -// Get global variable byte size based on his index (starting by 1) +// Get global variable byte size based on his index (starting from 1) // Return 0 if not found size_t DWARFManager_GetGlobalVariableTypeByteSize(size_t Index) { - size_t i; - - for (i = 0; i < NbCU; i++) + for (size_t i = 0; i < NbCU; i++) { if (PtrCU[i].NbVariables) { @@ -1588,13 +1618,11 @@ size_t DWARFManager_GetGlobalVariableTypeByteSize(size_t Index) } -// Get global variable encoding based on his index (starting by 1) +// Get global variable encoding based on his index (starting from 1) // Return 0 if not found size_t DWARFManager_GetGlobalVariableTypeEncoding(size_t Index) { - size_t i; - - for (i = 0; i < NbCU; i++) + for (size_t i = 0; i < NbCU; i++) { if (PtrCU[i].NbVariables) { @@ -1613,13 +1641,11 @@ size_t DWARFManager_GetGlobalVariableTypeEncoding(size_t Index) } -// Get global variable address based on his index (starting by 1) +// Get global variable memory address based on his index (starting from 1) // Return 0 if not found size_t DWARFManager_GetGlobalVariableAdr(size_t Index) { - size_t i; - - for (i = 0; i < NbCU; i++) + for (size_t i = 0; i < NbCU; i++) { if (PtrCU[i].NbVariables) { @@ -1642,13 +1668,11 @@ size_t DWARFManager_GetGlobalVariableAdr(size_t Index) // Return 0 if not found, or will return the first occurence found size_t DWARFManager_GetGlobalVariableAdrFromName(char *VariableName) { - size_t i, j; - - for (i = 0; i < NbCU; i++) + for (size_t i = 0; i < NbCU; i++) { if (PtrCU[i].NbVariables) { - for (j = 0; j < PtrCU[i].NbVariables; j++) + for (size_t j = 0; j < PtrCU[i].NbVariables; j++) { if (!strcmp(PtrCU[i].PtrVariables[j].PtrName,VariableName)) { @@ -1662,13 +1686,11 @@ size_t DWARFManager_GetGlobalVariableAdrFromName(char *VariableName) } -// Get global variable name based on his index (starting by 1) +// Get global variable name based on his index (starting from 1) // Return name's pointer text found, or will return NULL if no variable can be found char *DWARFManager_GetGlobalVariableName(size_t Index) { - size_t i; - - for (i = 0; i < NbCU; i++) + for (size_t i = 0; i < NbCU; i++) { if (PtrCU[i].NbVariables) { @@ -1693,13 +1715,11 @@ char *DWARFManager_GetGlobalVariableName(size_t Index) // Return NULL if no text line has been found char *DWARFManager_GetLineSrcFromAdr(size_t Adr, size_t Tag) { - size_t i, j, k; - - for (i = 0; i < NbCU; i++) + for (size_t i = 0; i < NbCU; i++) { if ((Adr >= PtrCU[i].LowPC) && (Adr < PtrCU[i].HighPC)) { - for (j = 0; j < PtrCU[i].NbSubProgs; j++) + for (size_t j = 0; j < PtrCU[i].NbSubProgs; j++) { if ((Adr >= PtrCU[i].PtrSubProgs[j].LowPC) && (Adr < PtrCU[i].PtrSubProgs[j].HighPC)) { @@ -1709,7 +1729,7 @@ char *DWARFManager_GetLineSrcFromAdr(size_t Adr, size_t Tag) } else { - for (k = 0; k < PtrCU[i].PtrSubProgs[j].NbLinesSrc; k++) + for (size_t k = 0; k < PtrCU[i].PtrSubProgs[j].NbLinesSrc; k++) { if (PtrCU[i].PtrSubProgs[j].PtrLinesSrc[k].StartPC <= Adr) { @@ -1739,13 +1759,11 @@ char *DWARFManager_GetLineSrcFromAdr(size_t Adr, size_t Tag) // Return 0 if no line number has been found size_t DWARFManager_GetNumLineFromAdr(size_t Adr, size_t Tag) { - size_t i, j, k; - - for (i = 0; i < NbCU; i++) + for (size_t i = 0; i < NbCU; i++) { if ((Adr >= PtrCU[i].LowPC) && (Adr < PtrCU[i].HighPC)) { - for (j = 0; (j < PtrCU[i].NbSubProgs); j++) + for (size_t j = 0; j < PtrCU[i].NbSubProgs; j++) { if ((Adr >= PtrCU[i].PtrSubProgs[j].LowPC) && (Adr < PtrCU[i].PtrSubProgs[j].HighPC)) { @@ -1755,7 +1773,7 @@ size_t DWARFManager_GetNumLineFromAdr(size_t Adr, size_t Tag) } else { - for (k = 0; (k < PtrCU[i].PtrSubProgs[j].NbLinesSrc); k++) + for (size_t k = 0; k < PtrCU[i].PtrSubProgs[j].NbLinesSrc; k++) { if ((PtrCU[i].PtrSubProgs[j].PtrLinesSrc[k].StartPC == Adr) && (!Tag || (PtrCU[i].PtrSubProgs[j].PtrLinesSrc[k].Tag == Tag))) { @@ -1782,13 +1800,11 @@ size_t DWARFManager_GetNumLineFromAdr(size_t Adr, size_t Tag) // Return NULL if no function name has been found, otherwise will return the function name in the range of the provided address char *DWARFManager_GetFunctionName(size_t Adr) { - size_t i, j; - - for (i = 0; i < NbCU; i++) + for (size_t i = 0; i < NbCU; i++) { if ((Adr >= PtrCU[i].LowPC) && (Adr < PtrCU[i].HighPC)) { - for (j = 0; j < PtrCU[i].NbSubProgs; j++) + for (size_t j = 0; j < PtrCU[i].NbSubProgs; j++) { if ((Adr >= PtrCU[i].PtrSubProgs[j].LowPC) && (Adr < PtrCU[i].PtrSubProgs[j].HighPC)) { @@ -1802,17 +1818,15 @@ char *DWARFManager_GetFunctionName(size_t Adr) } -// Get text line from source based on address and num line (starting by 1) +// Get text line from source based on address and num line (starting from 1) // Return NULL if no text line has been found char *DWARFManager_GetLineSrcFromAdrNumLine(size_t Adr, size_t NumLine) { - size_t i, j, k; - - for (i = 0; i < NbCU; i++) + for (size_t i = 0; i < NbCU; i++) { if ((Adr >= PtrCU[i].LowPC) && (Adr < PtrCU[i].HighPC)) { - for (j = 0; j < PtrCU[i].NbSubProgs; j++) + for (size_t j = 0; j < PtrCU[i].NbSubProgs; j++) { if ((Adr >= PtrCU[i].PtrSubProgs[j].LowPC) && (Adr < PtrCU[i].PtrSubProgs[j].HighPC)) { @@ -1822,7 +1836,7 @@ char *DWARFManager_GetLineSrcFromAdrNumLine(size_t Adr, size_t NumLine) } else { - for (k = 0; k < PtrCU[i].PtrSubProgs[j].NbLinesSrc; k++) + for (size_t k = 0; k < PtrCU[i].PtrSubProgs[j].NbLinesSrc; k++) { if (PtrCU[i].PtrSubProgs[j].PtrLinesSrc[k].NumLineSrc == NumLine) { @@ -1839,13 +1853,11 @@ char *DWARFManager_GetLineSrcFromAdrNumLine(size_t Adr, size_t NumLine) } -// Get text line pointer from source, based on address and line number (starting by 1) +// Get text line pointer from source, based on address and line number (starting from 1) // Return NULL if no text line has been found, or if requested number line is above the source total number of lines char *DWARFManager_GetLineSrcFromNumLineBaseAdr(size_t Adr, size_t NumLine) { - size_t i; - - for (i = 0; i < NbCU; i++) + for (size_t i = 0; i < NbCU; i++) { if ((Adr >= PtrCU[i].LowPC) && (Adr < PtrCU[i].HighPC)) { diff --git a/src/debugger/DWARFManager.h b/src/debugger/DWARFManager.h index 7b66a74..d05e4ee 100644 --- a/src/debugger/DWARFManager.h +++ b/src/debugger/DWARFManager.h @@ -4,22 +4,29 @@ #define __DWARFMANAGER_H__ -// +// Internal manager extern bool DWARFManager_Reset(void); extern bool DWARFManager_Close(void); extern void DWARFManager_Init(void); extern int DWARFManager_ElfInit(Elf *ElfPtr); +extern void DWARFManager_Set(size_t NbPathsInList, char **PtrListPaths); -// +// General manager +extern char *DWARFManager_GetFunctionName(size_t Adr); + +// Source text files manager extern char *DWARFManager_GetFullSourceFilenameFromAdr(size_t Adr, bool *Error); -extern size_t DWARFManager_GetNumLineFromAdr(size_t Adr, size_t Tag); +extern size_t DWARFManager_GetNbFullSourceFilename(void); +extern char *DWARFManager_GetNumFullSourceFilename(size_t Index); + +// Symbols manager extern char *DWARFManager_GetSymbolnameFromAdr(size_t Adr); + +// Source text lines manager +extern size_t DWARFManager_GetNumLineFromAdr(size_t Adr, size_t Tag); extern char *DWARFManager_GetLineSrcFromAdr(size_t Adr, size_t Tag); extern char *DWARFManager_GetLineSrcFromAdrNumLine(size_t Adr, size_t NumLine); extern char *DWARFManager_GetLineSrcFromNumLineBaseAdr(size_t Adr, size_t NumLine); -extern char *DWARFManager_GetFunctionName(size_t Adr); -extern size_t DWARFManager_GetNbFullSourceFilename(void); -extern char *DWARFManager_GetNumFullSourceFilename(size_t Index); // Global variables manager extern size_t DWARFManager_GetNbGlobalVariables(void); diff --git a/src/debugger/debuggertab.cpp b/src/debugger/debuggertab.cpp index 07a6629..d6135e8 100644 --- a/src/debugger/debuggertab.cpp +++ b/src/debugger/debuggertab.cpp @@ -7,33 +7,48 @@ // // WHO WHEN WHAT // --- ---------- ------------------------------------------------------------ -// JPM 06/19/2016 Created this file -// JPM 06/19/2016 Soft debugger support +// JPM Sept./2016 Created this file, and added Soft debugger support +// JPM 10/09/2018 Added source file search paths // #include "debuggertab.h" #include "settings.h" +// DebuggerTab::DebuggerTab(QWidget * parent/*= 0*/): QWidget(parent) { - QLabel * label3 = new QLabel("Disassembly lines:"); - edit3 = new QLineEdit(""); - edit3->setPlaceholderText("Number of disassembly lines"); - QVBoxLayout * layout1 = new QVBoxLayout; + // Number of disassembly lines + QLabel *label3 = new QLabel("Disassembly lines:"); + QVBoxLayout *layout1 = new QVBoxLayout; layout1->addWidget(label3); - - QVBoxLayout * layout2 = new QVBoxLayout; - layout2->addWidget(edit3); - - QHBoxLayout * layout3 = new QHBoxLayout; + QVBoxLayout *layout2 = new QVBoxLayout; + nbrdisasmlines = new QLineEdit(""); + nbrdisasmlines->setPlaceholderText("Number of disassembly lines"); + layout2->addWidget(nbrdisasmlines); + + // Sources code paths + QLabel *label4 = new QLabel("Source file search paths:"); + QVBoxLayout *layout5 = new QVBoxLayout; + layout5->addWidget(label4); + QVBoxLayout *layout6 = new QVBoxLayout; + sourcefilesearchpaths = new QLineEdit(""); + sourcefilesearchpaths->setMaxLength(sizeof(vjs.sourcefilesearchPaths)); + sourcefilesearchpaths->setPlaceholderText("Each path must be separate by a ';', search is recursive and based on each path"); + layout6->addWidget(sourcefilesearchpaths); + + QHBoxLayout *layout3 = new QHBoxLayout; layout3->addLayout(layout1); layout3->addLayout(layout2); + QHBoxLayout *layout7 = new QHBoxLayout; + layout7->addLayout(layout5); + layout7->addLayout(layout6); - QVBoxLayout * layout4 = new QVBoxLayout; + QVBoxLayout *layout4 = new QVBoxLayout; layout4->addLayout(layout3); + layout4->addLayout(layout7); - // Checkboxes... + // Checkboxes displayHWlabels = new QCheckBox(tr("Display HW labels")); disasmopcodes = new QCheckBox(tr("Display M68000 opcodes")); displayFullSourceFilename = new QCheckBox(tr("Display source filename")); @@ -49,6 +64,7 @@ DebuggerTab::DebuggerTab(QWidget * parent/*= 0*/): QWidget(parent) } +// DebuggerTab::~DebuggerTab() { } @@ -59,11 +75,9 @@ void DebuggerTab::SetSettings(void) { bool ok; - //strcpy(vjs.debuggerROMPath, debuggerTab->edit1->text().toUtf8().data()); strcpy(vjs.debuggerROMPath, vjs.alpineROMPath); - //strcpy(vjs.absROMPath, debuggerTab->edit2->text().toUtf8().data()); - vjs.nbrdisasmlines = edit3->text().toUInt(&ok, 10); - //vjs.allowWritesToROM = debuggerTab->writeROM->isChecked(); + strcpy(vjs.sourcefilesearchPaths, CheckForTrailingSlash(sourcefilesearchpaths->text()).toUtf8().data()); + vjs.nbrdisasmlines = nbrdisasmlines->text().toUInt(&ok, 10); vjs.displayHWlabels = displayHWlabels->isChecked(); vjs.disasmopcodes = disasmopcodes->isChecked(); vjs.displayFullSourceFilename = displayFullSourceFilename->isChecked(); @@ -74,12 +88,28 @@ void DebuggerTab::SetSettings(void) void DebuggerTab::GetSettings(void) { QVariant v(vjs.nbrdisasmlines); - //debuggerTab->edit1->setText(vjs.debuggerROMPath); - //debuggerTab->edit2->setText(vjs.absROMPath); - edit3->setText(v.toString()); - //debuggerTab->writeROM->setChecked(vjs.allowWritesToROM + nbrdisasmlines->setText(v.toString()); + sourcefilesearchpaths->setText(vjs.sourcefilesearchPaths); displayHWlabels->setChecked(vjs.displayHWlabels); disasmopcodes->setChecked(vjs.disasmopcodes); displayFullSourceFilename->setChecked(vjs.displayFullSourceFilename); } + +// Remove the last character if slash or backslash at the end of each string +// Depend the platform transform slashes or backslashes +QString DebuggerTab::CheckForTrailingSlash(QString s) +{ + if (s.endsWith('/') || s.endsWith('\\')) + { + s.remove(s.length() - 1, 1); + } +#ifdef _WIN32 + s.replace(QString("/"), QString("\\")); + s.replace(QString("\\;"), QString(";")); +#else + s.replace(QString("\\"), QString("/")); + s.replace(QString("/;"), QString(";")); +#endif + return s; +} diff --git a/src/debugger/debuggertab.h b/src/debugger/debuggertab.h index fecee84..f9e1b8a 100644 --- a/src/debugger/debuggertab.h +++ b/src/debugger/debuggertab.h @@ -3,8 +3,8 @@ // // Who When What // --- ---------- ------------------------------------------------------------ -// JPM 06/19/2016 Created this file -// JPM 06/19/2016 Soft debugger support +// JPM Sept./2016 Created this file, and added Soft debugger support +// JPM 10/09/2018 Added the source file search paths // #ifndef __DEBUGGERTAB_H__ @@ -22,9 +22,12 @@ class DebuggerTab: public QWidget void SetSettings(void); void GetSettings(void); - public: - QLineEdit *edit3; + private: + QString CheckForTrailingSlash(QString s); + public: + QLineEdit *nbrdisasmlines; + QLineEdit *sourcefilesearchpaths; QCheckBox *displayHWlabels; QCheckBox *disasmopcodes; QCheckBox *displayFullSourceFilename; diff --git a/src/gui/mainwin.cpp b/src/gui/mainwin.cpp index ff0e195..9b03922 100644 --- a/src/gui/mainwin.cpp +++ b/src/gui/mainwin.cpp @@ -20,6 +20,7 @@ // JPM 11/04/2017 Added the local window // JPM 08/31/2018 Added the call stack window // JPM Sept./2018 Added the new Models and BIOS handler, a screenshot feature and source code files browsing +// JPM 10/10/2018 Added search paths in the settings // // FIXED: @@ -83,6 +84,7 @@ #include "joystick.h" #include "m68000/m68kinterface.h" +#include "debugger/DBGManager.h" //#include "debugger/VideoWin.h" //#include "debugger/DasmWin.h" #include "debugger/m68KDasmWin.h" @@ -1763,6 +1765,7 @@ void MainWin::ReadSettings(void) // Read settings from the Debugger mode settings.beginGroup("debugger"); strcpy(vjs.debuggerROMPath, settings.value("DefaultROM", "").toString().toUtf8().data()); + strcpy(vjs.sourcefilesearchPaths, settings.value("SourceFileSearchPaths", "").toString().toUtf8().data()); vjs.nbrdisasmlines = settings.value("NbrDisasmLines", 32).toUInt(); vjs.disasmopcodes = settings.value("DisasmOpcodes", true).toBool(); vjs.displayHWlabels = settings.value("DisplayHWLabels", true).toBool(); @@ -1788,13 +1791,15 @@ void MainWin::ReadSettings(void) // Write important settings to the log file WriteLog("MainWin: Paths\n"); - WriteLog(" EEPROMPath = \"%s\"\n", vjs.EEPROMPath); - WriteLog(" ROMPath = \"%s\"\n", vjs.ROMPath); - WriteLog(" AlpineROMPath = \"%s\"\n", vjs.alpineROMPath); - WriteLog("DebuggerROMPath = \"%s\"\n", vjs.debuggerROMPath); - WriteLog(" absROMPath = \"%s\"\n", vjs.absROMPath); - WriteLog("ScreenshotsPath = \"%s\"\n", vjs.screenshotPath); - WriteLog(" Pipelined DSP = %s\n", (vjs.usePipelinedDSP ? "ON" : "off")); + WriteLog(" EEPROMPath = \"%s\"\n", vjs.EEPROMPath); + WriteLog(" ROMPath = \"%s\"\n", vjs.ROMPath); + WriteLog(" AlpineROMPath = \"%s\"\n", vjs.alpineROMPath); + WriteLog(" DebuggerROMPath = \"%s\"\n", vjs.debuggerROMPath); + WriteLog(" absROMPath = \"%s\"\n", vjs.absROMPath); + WriteLog(" ScreenshotsPath = \"%s\"\n", vjs.screenshotPath); + WriteLog("SourceFileSearchPaths = \"%s\"\n", vjs.sourcefilesearchPaths); + WriteLog("MainWin: Misc.\n"); + WriteLog(" Pipelined DSP = %s\n", (vjs.usePipelinedDSP ? "ON" : "off")); #if 0 // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, * @@ -1846,6 +1851,7 @@ void MainWin::ReadSettings(void) WriteLog("Read setting = Done\n"); ReadProfiles(&settings); + DBGManager_SourceFileSearchPathsSet(vjs.sourcefilesearchPaths); } @@ -2049,6 +2055,7 @@ void MainWin::WriteSettings(void) settings.setValue("displayFullSourceFilename", vjs.displayFullSourceFilename); settings.setValue("NbrMemory1BrowserWindow", (unsigned int)vjs.nbrmemory1browserwindow); settings.setValue("DefaultROM", vjs.debuggerROMPath); + settings.setValue("SourceFileSearchPaths", vjs.sourcefilesearchPaths); settings.endGroup(); // Write settings from the Keybindings @@ -2106,6 +2113,7 @@ void MainWin::WriteSettings(void) #endif WriteProfiles(&settings); + DBGManager_SourceFileSearchPathsSet(vjs.sourcefilesearchPaths); } diff --git a/src/settings.h b/src/settings.h index 56615bc..e81d57d 100644 --- a/src/settings.h +++ b/src/settings.h @@ -6,7 +6,8 @@ // Who When What // --- ---------- ------------------------------------------------------------ // JPM 06/19/2016 Soft debugger support -// JPM Sept. / 2018 Added the new Models and BIOS handler, and a screenshot settings +// JPM Sept./2018 Added the new Models and BIOS handler, and a screenshot settings +// JPM 10/10/2018 Added search paths in settings // #ifndef __SETTINGS_H__ @@ -101,6 +102,7 @@ struct VJSettings char debuggerROMPath[MAX_PATH]; char absROMPath[MAX_PATH]; char screenshotPath[MAX_PATH]; + char sourcefilesearchPaths[4096]; }; // Render types