X-Git-Url: http://git.hcoop.net/clinton/Virtual-Jaguar-Rx.git/blobdiff_plain/6564336c1aab410c2f67c4a2accb948080211201..c13e54167b8d5637f7a4502117ea2594959f160a:/src/debugger/DBGManager.cpp diff --git a/src/debugger/DBGManager.cpp b/src/debugger/DBGManager.cpp index 5f9251a..edbc766 100644 --- a/src/debugger/DBGManager.cpp +++ b/src/debugger/DBGManager.cpp @@ -4,26 +4,34 @@ // by Jean-Paul Mari // // JPM = Jean-Paul Mari +// RG = Richard Goedeken // // WHO WHEN WHAT // --- ---------- ------------------------------------------------------------ // 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 09/15/2018 Support the unsigned char +// JPM Oct./2018 Cosmetic changes, added source file search paths, and ELF function name +// JPM Aug./2019 Added new functions mainly for source text lines +// JPM Sept./2019 Support the unsigned/signed short type +// RG Jan./2021 Linux build fixes +// JPM May/2021 Code refactoring for the variables +// // To Do +// To think about unique format to handle variations from ELF, DWARF, etc. // #include #include #include -#include "libelf/libelf.h" -#include "libelf/gelf.h" +#include "libelf.h" +#include "gelf.h" #include "log.h" #include "ELFManager.h" -#include "DwarfManager.h" +#include "DWARFManager.h" #include "DBGManager.h" #include "HWLABELManager.h" #include "settings.h" @@ -40,24 +48,119 @@ struct Value 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(); } @@ -80,10 +183,21 @@ void DBGManager_Reset(void) } -// Get debugger type -size_t DBGManager_GetType(void) +// Common debugger close +void DBGManager_Close(void) { - return DBGType; + if ((DBGType & DBG_DWARF)) + { + DWARFManager_Close(); + } + + if ((DBGType & DBG_ELF)) + { + ELFManager_Close(); + } + + DBGManager_SourceFileSearchPathsClose(); + DBGType = DBG_NO_TYPE; } @@ -94,28 +208,50 @@ void DBGManager_SetType(size_t DBGTypeSet) } -// Common debugger close -void DBGManager_Close(void) +// Get debugger type +size_t DBGManager_GetType(void) { - if ((DBGType & DBG_DWARF)) + return DBGType; +} + + +// Get source filename based on the memeory address +// return NULL if no source filename +char *DBGManager_GetFullSourceFilenameFromAdr(size_t Adr, DBGstatus *Status) +{ + if ((DBGType & DBG_ELFDWARF)) { - DWARFManager_Close(); + return DWARFManager_GetFullSourceFilenameFromAdr(Adr, (DWARFstatus *)Status); } + else + { + return NULL; + } +} - if ((DBGType & DBG_ELF)) + +// Get number of variables +// A NULL address will return the numbre of global variables, otherwise it will return the number of local variables +size_t DBGManager_GetNbVariables(size_t Adr) +{ + if ((DBGType & DBG_ELFDWARF)) { - ELFManager_Close(); + return DWARFManager_GetNbVariables(Adr); + } + else + { + return 0; } } -// Get source filename based on the memeory address -// return NULL if no source filename -char *DBGManager_GetFullSourceFilenameFromAdr(size_t Adr, bool *Error) +// Get variable's information +// A NULL address will return the pointer to the global variable structure, otherwise it will return the local's one +S_VariablesStruct* DBGManager_GetInfosVariable(size_t Adr, size_t Index) { if ((DBGType & DBG_ELFDWARF)) { - return DWARFManager_GetFullSourceFilenameFromAdr(Adr, Error); + return (S_VariablesStruct*)DWARFManager_GetInfosVariable(Adr, Index); } else { @@ -124,6 +260,23 @@ char *DBGManager_GetFullSourceFilenameFromAdr(size_t Adr, bool *Error) } +// Get global variable's Address based on his Name +// Return found Address +// Return NULL if no Address has been found +size_t DBGManager_GetGlobalVariableAdrFromName(char *VariableName) +{ + if ((DBGType & DBG_ELFDWARF)) + { + return DWARFManager_GetGlobalVariableAdrFromName(VariableName); + } + else + { + return 0; + } +} + + +#if 0 // Get number of local variables // Return 0 if none has been found size_t DBGManager_GetNbLocalVariables(size_t Adr) @@ -152,6 +305,7 @@ size_t DBGManager_GetNbGlobalVariables(void) return 0; } } +#endif // Get address from symbol name @@ -171,22 +325,7 @@ size_t DBGManager_GetAdrFromSymbolName(char *SymbolName) } -// Get global variable's Address based on his Name -// Return found Address -// Return NULL if no Address has been found -size_t DBGManager_GetGlobalVariableAdrFromName(char *VariableName) -{ - if ((DBGType & DBG_ELFDWARF)) - { - return DWARFManager_GetGlobalVariableAdrFromName(VariableName); - } - else - { - return 0; - } -} - - +#if 0 // Get local variable's type encoding based on his address and Index // Return the type encoding found // Return 0 if no type encoding has been found @@ -345,6 +484,71 @@ char *DBGManager_GetGlobalVariableValue(size_t Index) } +// Get local variable's type name based on his Index +// Return type name's text pointer found +// Return NULL if no type name has been found +char *DBGManager_GetLocalVariableTypeName(size_t Adr, size_t Index) +{ + if ((DBGType & DBG_ELFDWARF)) + { + return DWARFManager_GetLocalVariableTypeName(Adr, Index); + } + else + { + return NULL; + } +} + + +// Get local variable Op based on his Index +// Return variable Op's found +// Return 0 if no variable Op has been found +size_t DBGManager_GetLocalVariableOp(size_t Adr, size_t Index) +{ + if ((DBGType & DBG_ELFDWARF)) + { + return DWARFManager_GetLocalVariableOp(Adr, Index); + } + else + { + return 0; + } +} + + +// Get local variable name based on his Index +// Return variable name's text pointer found +// Return NULL if no variable name has been found +char *DBGManager_GetLocalVariableName(size_t Adr, size_t Index) +{ + if ((DBGType & DBG_ELFDWARF)) + { + return DWARFManager_GetLocalVariableName(Adr, Index); + } + else + { + return NULL; + } +} + + +// Get global variable name based on his Index +// Return variable name's text pointer found +// Return NULL if no variable name has been found +char *DBGManager_GetGlobalVariableName(size_t Index) +{ + if ((DBGType & DBG_ELFDWARF)) + { + return DWARFManager_GetGlobalVariableName(Index); + } + else + { + return NULL; + } +} +#endif + + // Get variable value based on his Adresse, Encoding Type and Size // Return value as a text pointer // Note: Pointer may point on a 0 length text @@ -404,6 +608,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; @@ -423,6 +631,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; @@ -437,7 +649,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))); + sprintf(value, "%u", (unsigned int) V.C); break; case DBG_ATE_ptr: @@ -460,83 +672,24 @@ char *DBGManager_GetVariableValueFromAdr(size_t Adr, size_t TypeEncoding, size_t } -// Get local variable's type name based on his Index -// Return type name's text pointer found -// Return NULL if no type name has been found -char *DBGManager_GetLocalVariableTypeName(size_t Adr, size_t Index) -{ - if ((DBGType & DBG_ELFDWARF)) - { - return DWARFManager_GetLocalVariableTypeName(Adr, Index); - } - else - { - return NULL; - } -} - - -// Get local variable Op based on his Index -// Return variable Op's found -// Return 0 if no variable Op has been found -size_t DBGManager_GetLocalVariableOp(size_t Adr, size_t Index) -{ - if ((DBGType & DBG_ELFDWARF)) - { - return DWARFManager_GetLocalVariableOp(Adr, Index); - } - else - { - return 0; - } -} - - -// Get local variable name based on his Index -// Return variable name's text pointer found -// Return NULL if no variable name has been found -char *DBGManager_GetLocalVariableName(size_t Adr, size_t Index) -{ - if ((DBGType & DBG_ELFDWARF)) - { - return DWARFManager_GetLocalVariableName(Adr, Index); - } - else - { - return NULL; - } -} - - -// Get global variable name based on his Index -// Return variable name's text pointer found -// Return NULL if no variable name has been found -char *DBGManager_GetGlobalVariableName(size_t Index) -{ - if ((DBGType & DBG_ELFDWARF)) - { - return DWARFManager_GetGlobalVariableName(Index); - } - else - { - return NULL; - } -} - - // Get function name from address // Return function name found // 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; } @@ -600,61 +753,75 @@ 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 DBGManager_GetNbSources(void) { size_t Nbr = 0; if ((DBGType & DBG_ELFDWARF)) { - Nbr = DWARFManager_GetNbFullSourceFilename(); + Nbr = DWARFManager_GetNbSources(); } return Nbr; } +// Get source code filename based on index +char *DBGManager_GetNumSourceFilename(size_t Index) +{ + char *SourceFilename = NULL; + + if ((DBGType & DBG_ELFDWARF)) + { + SourceFilename = DWARFManager_GetNumSourceFilename(Index); + } + + return SourceFilename; +} + + // Get source code filename based on index char *DBGManager_GetNumFullSourceFilename(size_t Index) { @@ -667,3 +834,60 @@ char *DBGManager_GetNumFullSourceFilename(size_t Index) return FullSourceFilename; } + + +// Get number of lines of texts source list from source index +size_t DBGManager_GetSrcNbListPtrFromIndex(size_t Index, bool Used) +{ + size_t NbListPtr = 0; + + if ((DBGType & DBG_ELFDWARF)) + { + NbListPtr = DWARFManager_GetSrcNbListPtrFromIndex(Index, Used); + } + + return NbListPtr; +} + + +// Get pointer to the lines number list from source index +size_t *DBGManager_GetSrcNumLinesPtrFromIndex(size_t Index, bool Used) +{ + size_t *PtrNumLines = NULL; + + if ((DBGType & DBG_ELFDWARF)) + { + PtrNumLines = DWARFManager_GetSrcNumLinesPtrFromIndex(Index, Used); + } + + return PtrNumLines; +} + + +// Get text source list pointers from source index +char **DBGManager_GetSrcListPtrFromIndex(size_t Index, bool Used) +{ + char **PtrSource = NULL; + + if ((DBGType & DBG_ELFDWARF)) + { + PtrSource = DWARFManager_GetSrcListPtrFromIndex(Index, Used); + } + + return PtrSource; +} + + +// Get source language +size_t DBGManager_GetSrcLanguageFromIndex(size_t Index) +{ + size_t Language = 0; + + if ((DBGType & DBG_ELFDWARF)) + { + Language = DWARFManager_GetSrcLanguageFromIndex(Index); + } + + return Language; +} +