X-Git-Url: http://git.hcoop.net/clinton/Virtual-Jaguar-Rx.git/blobdiff_plain/0203b5fd6f49dbc4f4244417c095882eb9882d49..ef0da6debd1fc73d0f4c3914e21d9a09dd8fe7e7:/src/debugger/DBGManager.cpp diff --git a/src/debugger/DBGManager.cpp b/src/debugger/DBGManager.cpp index cf2847c..1d024e3 100644 --- a/src/debugger/DBGManager.cpp +++ b/src/debugger/DBGManager.cpp @@ -10,6 +10,15 @@ // JPM 12/21/2016 Created this file // 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 Oct./2018 Cosmetic changes, added source file search paths, and ELF function name +// JPM Sept./2019 Support the unsigned/signed short type +// + +// To Do +// To think about unique format to handle variations from ELF, DWARF, etc. +// + #include #include @@ -30,27 +39,124 @@ struct Value { union { - char C[10]; + char Ct[10]; + char C; + bool B; double D; float F; + int16_t SS; int32_t SI; int64_t SL; + uint16_t US; uint32_t UI; uint64_t UL; }; }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(); } @@ -73,13 +179,6 @@ void DBGManager_Reset(void) } -// Common debugger set -void DBGManager_SetType(size_t DBGTypeSet) -{ - DBGType |= DBGTypeSet; -} - - // Common debugger close void DBGManager_Close(void) { @@ -92,6 +191,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; } @@ -140,17 +256,20 @@ size_t DBGManager_GetNbGlobalVariables(void) } -// +// Get address from symbol name +// Return found address +// Return NULL if no symbol has been found size_t DBGManager_GetAdrFromSymbolName(char *SymbolName) { - if ((DBGType & DBG_ELF)) + if (SymbolName) { - return ELFManager_GetAdrFromSymbolName(SymbolName); - } - else - { - return 0; + if ((DBGType & DBG_ELF)) + { + return ELFManager_GetAdrFromSymbolName(SymbolName); + } } + + return 0; } @@ -330,7 +449,7 @@ char *DBGManager_GetGlobalVariableValue(size_t Index) // Get variable value based on his Adresse, Encoding Type and Size // Return value as a text pointer -// Note: Pointer may point on a 0 lenght text if Adress is NULL +// Note: Pointer may point on a 0 length text char *DBGManager_GetVariableValueFromAdr(size_t Adr, size_t TypeEncoding, size_t TypeByteSize) { Value V; @@ -338,7 +457,9 @@ char *DBGManager_GetVariableValueFromAdr(size_t Adr, size_t TypeEncoding, size_t value[0] = 0; +#if 0 if (Adr) +#endif { memset(&V, 0, sizeof(Value)); #if 0 @@ -346,20 +467,19 @@ char *DBGManager_GetVariableValueFromAdr(size_t Adr, size_t TypeEncoding, size_t jaguarMainRAM[Adr + i] = 0; //jaguarMainRAM[Adr + i] = rand(); jaguarMainRAM[Adr + TypeByteSize - 1] = 0x10; -#endif -#if 1 +#else for (size_t i = 0, j = TypeByteSize; i < TypeByteSize; i++, j--) { - V.C[i] = jaguarMainRAM[Adr + j - 1]; + V.Ct[i] = jaguarMainRAM[Adr + j - 1]; } #endif - switch (TypeEncoding) { case DBG_ATE_address: break; case DBG_ATE_boolean: + sprintf(value, "%s", V.B ? "true" : "false"); break; case DBG_ATE_complex_float: @@ -386,6 +506,10 @@ char *DBGManager_GetVariableValueFromAdr(size_t Adr, size_t TypeEncoding, size_t case DBG_ATE_signed: switch (TypeByteSize) { + case 2: + sprintf(value, "%i", V.SS); + break; + case 4: sprintf(value, "%i", V.SI); break; @@ -405,6 +529,10 @@ char *DBGManager_GetVariableValueFromAdr(size_t Adr, size_t TypeEncoding, size_t case DBG_ATE_unsigned: switch (TypeByteSize) { + case 2: + sprintf(value, "%u", V.US); + break; + case 4: sprintf(value, "%u", V.UI); break; @@ -419,6 +547,7 @@ char *DBGManager_GetVariableValueFromAdr(size_t Adr, size_t TypeEncoding, size_t break; case DBG_ATE_unsigned_char: + sprintf(value, "%u", (unsigned int(V.C))); break; case DBG_ATE_ptr: @@ -510,14 +639,19 @@ char *DBGManager_GetGlobalVariableName(size_t Index) // Return NULL if no function name has been found char *DBGManager_GetFunctionName(size_t Adr) { + char *Symbolname = NULL; + if ((DBGType & DBG_ELFDWARF)) { - return DWARFManager_GetFunctionName(Adr); + Symbolname = DWARFManager_GetFunctionName(Adr); } - else + + if ((DBGType & DBG_ELF) && (Symbolname == NULL)) { - return NULL; + Symbolname = ELFManager_GetFunctionName(Adr); } + + return Symbolname; } @@ -581,43 +715,70 @@ char *DBGManager_GetSymbolNameFromAdr(size_t Adr) // Return NULL if no source line has been found char *DBGManager_GetLineSrcFromAdr(size_t Adr, size_t Tag) { - char *Symbolname = NULL; + char *TextLine = NULL; if ((DBGType & DBG_ELFDWARF)) { - Symbolname = DWARFManager_GetLineSrcFromAdr(Adr, Tag); + TextLine = DWARFManager_GetLineSrcFromAdr(Adr, Tag); } - return Symbolname; + return TextLine; } -// 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 *DBGManager_GetLineSrcFromAdrNumLine(size_t Adr, size_t NumLine) { - char *Symbolname = NULL; + char *TextLine = NULL; if ((DBGType & DBG_ELFDWARF)) { - Symbolname = DWARFManager_GetLineSrcFromAdrNumLine(Adr, NumLine); + TextLine = DWARFManager_GetLineSrcFromAdrNumLine(Adr, NumLine); } - return Symbolname; + return TextLine; } -// 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 *DBGManager_GetLineSrcFromNumLineBaseAdr(size_t Adr, size_t NumLine) { - char *Symbolname = NULL; + char *TextLine = NULL; if ((DBGType & DBG_ELFDWARF)) { - Symbolname = DWARFManager_GetLineSrcFromNumLineBaseAdr(Adr, NumLine); + TextLine = DWARFManager_GetLineSrcFromNumLineBaseAdr(Adr, NumLine); } - return Symbolname; + return TextLine; } + +// Get number of source code filenames +size_t DBGManager_GetNbFullSourceFilename(void) +{ + size_t Nbr = 0; + + if ((DBGType & DBG_ELFDWARF)) + { + Nbr = DWARFManager_GetNbFullSourceFilename(); + } + + return Nbr; +} + + +// Get source code filename based on index +char *DBGManager_GetNumFullSourceFilename(size_t Index) +{ + char *FullSourceFilename = NULL; + + if ((DBGType & DBG_ELFDWARF)) + { + FullSourceFilename = DWARFManager_GetNumFullSourceFilename(Index); + } + + return FullSourceFilename; +}