Merge branch 'develop'
[clinton/Virtual-Jaguar-Rx.git] / src / debugger / DBGManager.cpp
index 3dcb138..edbc766 100644 (file)
@@ -4,6 +4,7 @@
 // by Jean-Paul Mari\r
 //\r
 // JPM = Jean-Paul Mari <djipi.mari@gmail.com>\r
 // by Jean-Paul Mari\r
 //\r
 // JPM = Jean-Paul Mari <djipi.mari@gmail.com>\r
+//  RG = Richard Goedeken\r
 //\r
 // WHO  WHEN        WHAT\r
 // ---  ----------  ------------------------------------------------------------\r
 //\r
 // WHO  WHEN        WHAT\r
 // ---  ----------  ------------------------------------------------------------\r
 // JPM              Various efforts to set the DWARF format support\r
 // JPM  09/15/2018  Support the unsigned char\r
 // JPM   Oct./2018  Cosmetic changes, added source file search paths, and ELF function name\r
 // JPM              Various efforts to set the DWARF format support\r
 // JPM  09/15/2018  Support the unsigned char\r
 // JPM   Oct./2018  Cosmetic changes, added source file search paths, and ELF function name\r
+// JPM   Aug./2019  Added new functions mainly for source text lines\r
+// JPM  Sept./2019  Support the unsigned/signed short type\r
+//  RG   Jan./2021  Linux build fixes\r
+// JPM    May/2021  Code refactoring for the variables\r
 //\r
 \r
 // To Do\r
 //\r
 \r
 // To Do\r
 #include <stdlib.h>\r
 #include <string.h>\r
 #include <stdint.h>\r
 #include <stdlib.h>\r
 #include <string.h>\r
 #include <stdint.h>\r
-#include "libelf/libelf.h"\r
-#include "libelf/gelf.h"\r
+#include "libelf.h"\r
+#include "gelf.h"\r
 #include "log.h"\r
 #include "ELFManager.h"\r
 #include "log.h"\r
 #include "ELFManager.h"\r
-#include "DwarfManager.h"\r
+#include "DWARFManager.h"\r
 #include "DBGManager.h"\r
 #include "HWLABELManager.h"\r
 #include "settings.h"\r
 #include "DBGManager.h"\r
 #include "HWLABELManager.h"\r
 #include "settings.h"\r
@@ -43,8 +48,10 @@ struct Value
                bool B;\r
                double D;\r
                float F;\r
                bool B;\r
                double D;\r
                float F;\r
+               int16_t SS;\r
                int32_t SI;\r
                int64_t SL;\r
                int32_t SI;\r
                int64_t SL;\r
+               uint16_t US;\r
                uint32_t UI;\r
                uint64_t UL;\r
        };\r
                uint32_t UI;\r
                uint64_t UL;\r
        };\r
@@ -210,11 +217,11 @@ size_t DBGManager_GetType(void)
 \r
 // Get source filename based on the memeory address\r
 // return NULL if no source filename\r
 \r
 // Get source filename based on the memeory address\r
 // return NULL if no source filename\r
-char *DBGManager_GetFullSourceFilenameFromAdr(size_t Adr, bool *Error)\r
+char *DBGManager_GetFullSourceFilenameFromAdr(size_t Adr, DBGstatus *Status)\r
 {\r
        if ((DBGType & DBG_ELFDWARF))\r
        {\r
 {\r
        if ((DBGType & DBG_ELFDWARF))\r
        {\r
-               return DWARFManager_GetFullSourceFilenameFromAdr(Adr, Error);\r
+               return DWARFManager_GetFullSourceFilenameFromAdr(Adr, (DWARFstatus *)Status);\r
        }\r
        else\r
        {\r
        }\r
        else\r
        {\r
@@ -223,6 +230,53 @@ char *DBGManager_GetFullSourceFilenameFromAdr(size_t Adr, bool *Error)
 }\r
 \r
 \r
 }\r
 \r
 \r
+// Get number of variables\r
+// A NULL address will return the numbre of global variables, otherwise it will return the number of local variables\r
+size_t DBGManager_GetNbVariables(size_t Adr)\r
+{\r
+       if ((DBGType & DBG_ELFDWARF))\r
+       {\r
+               return DWARFManager_GetNbVariables(Adr);\r
+       }\r
+       else\r
+       {\r
+               return  0;\r
+       }\r
+}\r
+\r
+\r
+// Get variable's information\r
+// A NULL address will return the pointer to the global variable structure, otherwise it will return the local's one\r
+S_VariablesStruct* DBGManager_GetInfosVariable(size_t Adr, size_t Index)\r
+{\r
+       if ((DBGType & DBG_ELFDWARF))\r
+       {\r
+               return (S_VariablesStruct*)DWARFManager_GetInfosVariable(Adr, Index);\r
+       }\r
+       else\r
+       {\r
+               return  NULL;\r
+       }\r
+}\r
+\r
+\r
+// Get global variable's Address based on his Name\r
+// Return found Address\r
+// Return NULL if no Address has been found\r
+size_t DBGManager_GetGlobalVariableAdrFromName(char *VariableName)\r
+{\r
+       if ((DBGType & DBG_ELFDWARF))\r
+       {\r
+               return DWARFManager_GetGlobalVariableAdrFromName(VariableName);\r
+       }\r
+       else\r
+       {\r
+               return 0;\r
+       }\r
+}\r
+\r
+\r
+#if 0\r
 // Get number of local variables\r
 // Return 0 if none has been found\r
 size_t DBGManager_GetNbLocalVariables(size_t Adr)\r
 // Get number of local variables\r
 // Return 0 if none has been found\r
 size_t DBGManager_GetNbLocalVariables(size_t Adr)\r
@@ -251,6 +305,7 @@ size_t DBGManager_GetNbGlobalVariables(void)
                return  0;\r
        }\r
 }\r
                return  0;\r
        }\r
 }\r
+#endif\r
 \r
 \r
 // Get address from symbol name\r
 \r
 \r
 // Get address from symbol name\r
@@ -270,22 +325,7 @@ size_t DBGManager_GetAdrFromSymbolName(char *SymbolName)
 }\r
 \r
 \r
 }\r
 \r
 \r
-// Get global variable's Address based on his Name\r
-// Return found Address\r
-// Return NULL if no Address has been found\r
-size_t DBGManager_GetGlobalVariableAdrFromName(char *VariableName)\r
-{\r
-       if ((DBGType & DBG_ELFDWARF))\r
-       {\r
-               return DWARFManager_GetGlobalVariableAdrFromName(VariableName);\r
-       }\r
-       else\r
-       {\r
-               return 0;\r
-       }\r
-}\r
-\r
-\r
+#if 0\r
 // Get local variable's type encoding based on his address and Index\r
 // Return the type encoding found\r
 // Return 0 if no type encoding has been found\r
 // Get local variable's type encoding based on his address and Index\r
 // Return the type encoding found\r
 // Return 0 if no type encoding has been found\r
@@ -444,6 +484,71 @@ char *DBGManager_GetGlobalVariableValue(size_t Index)
 }\r
 \r
 \r
 }\r
 \r
 \r
+// Get local variable's type name based on his Index\r
+// Return type name's text pointer found\r
+// Return NULL if no type name has been found\r
+char *DBGManager_GetLocalVariableTypeName(size_t Adr, size_t Index)\r
+{\r
+       if ((DBGType & DBG_ELFDWARF))\r
+       {\r
+               return DWARFManager_GetLocalVariableTypeName(Adr, Index);\r
+       }\r
+       else\r
+       {\r
+               return  NULL;\r
+       }\r
+}\r
+\r
+\r
+// Get local variable Op based on his Index\r
+// Return variable Op's found\r
+// Return 0 if no variable Op has been found\r
+size_t DBGManager_GetLocalVariableOp(size_t Adr, size_t Index)\r
+{\r
+       if ((DBGType & DBG_ELFDWARF))\r
+       {\r
+               return DWARFManager_GetLocalVariableOp(Adr, Index);\r
+       }\r
+       else\r
+       {\r
+               return  0;\r
+       }\r
+}\r
+\r
+\r
+// Get local variable name based on his Index\r
+// Return variable name's text pointer found\r
+// Return NULL if no variable name has been found\r
+char *DBGManager_GetLocalVariableName(size_t Adr, size_t Index)\r
+{\r
+       if ((DBGType & DBG_ELFDWARF))\r
+       {\r
+               return DWARFManager_GetLocalVariableName(Adr, Index);\r
+       }\r
+       else\r
+       {\r
+               return  NULL;\r
+       }\r
+}\r
+\r
+\r
+// Get global variable name based on his Index\r
+// Return variable name's text pointer found\r
+// Return NULL if no variable name has been found\r
+char *DBGManager_GetGlobalVariableName(size_t Index)\r
+{\r
+       if ((DBGType & DBG_ELFDWARF))\r
+       {\r
+               return DWARFManager_GetGlobalVariableName(Index);\r
+       }\r
+       else\r
+       {\r
+               return  NULL;\r
+       }\r
+}\r
+#endif\r
+\r
+\r
 // Get variable value based on his Adresse, Encoding Type and Size\r
 // Return value as a text pointer\r
 // Note: Pointer may point on a 0 length text\r
 // Get variable value based on his Adresse, Encoding Type and Size\r
 // Return value as a text pointer\r
 // Note: Pointer may point on a 0 length text\r
@@ -503,6 +608,10 @@ char *DBGManager_GetVariableValueFromAdr(size_t Adr, size_t TypeEncoding, size_t
                case DBG_ATE_signed:\r
                        switch (TypeByteSize)\r
                        {\r
                case DBG_ATE_signed:\r
                        switch (TypeByteSize)\r
                        {\r
+                       case 2:\r
+                               sprintf(value, "%i", V.SS);\r
+                               break;\r
+\r
                        case 4:\r
                                sprintf(value, "%i", V.SI);\r
                                break;\r
                        case 4:\r
                                sprintf(value, "%i", V.SI);\r
                                break;\r
@@ -522,6 +631,10 @@ char *DBGManager_GetVariableValueFromAdr(size_t Adr, size_t TypeEncoding, size_t
                case DBG_ATE_unsigned:\r
                        switch (TypeByteSize)\r
                        {\r
                case DBG_ATE_unsigned:\r
                        switch (TypeByteSize)\r
                        {\r
+                       case 2:\r
+                               sprintf(value, "%u", V.US);\r
+                               break;\r
+\r
                        case 4:\r
                                sprintf(value, "%u", V.UI);\r
                                break;\r
                        case 4:\r
                                sprintf(value, "%u", V.UI);\r
                                break;\r
@@ -536,7 +649,7 @@ char *DBGManager_GetVariableValueFromAdr(size_t Adr, size_t TypeEncoding, size_t
                        break;\r
 \r
                case DBG_ATE_unsigned_char:\r
                        break;\r
 \r
                case DBG_ATE_unsigned_char:\r
-                       sprintf(value, "%u", (unsigned int(V.C)));\r
+                       sprintf(value, "%u", (unsigned int) V.C);\r
                        break;\r
 \r
                case DBG_ATE_ptr:\r
                        break;\r
 \r
                case DBG_ATE_ptr:\r
@@ -559,70 +672,6 @@ char *DBGManager_GetVariableValueFromAdr(size_t Adr, size_t TypeEncoding, size_t
 }\r
 \r
 \r
 }\r
 \r
 \r
-// Get local variable's type name based on his Index\r
-// Return type name's text pointer found\r
-// Return NULL if no type name has been found\r
-char *DBGManager_GetLocalVariableTypeName(size_t Adr, size_t Index)\r
-{\r
-       if ((DBGType & DBG_ELFDWARF))\r
-       {\r
-               return DWARFManager_GetLocalVariableTypeName(Adr, Index);\r
-       }\r
-       else\r
-       {\r
-               return  NULL;\r
-       }\r
-}\r
-\r
-\r
-// Get local variable Op based on his Index\r
-// Return variable Op's found\r
-// Return 0 if no variable Op has been found\r
-size_t DBGManager_GetLocalVariableOp(size_t Adr, size_t Index)\r
-{\r
-       if ((DBGType & DBG_ELFDWARF))\r
-       {\r
-               return DWARFManager_GetLocalVariableOp(Adr, Index);\r
-       }\r
-       else\r
-       {\r
-               return  0;\r
-       }\r
-}\r
-\r
-\r
-// Get local variable name based on his Index\r
-// Return variable name's text pointer found\r
-// Return NULL if no variable name has been found\r
-char *DBGManager_GetLocalVariableName(size_t Adr, size_t Index)\r
-{\r
-       if ((DBGType & DBG_ELFDWARF))\r
-       {\r
-               return DWARFManager_GetLocalVariableName(Adr, Index);\r
-       }\r
-       else\r
-       {\r
-               return  NULL;\r
-       }\r
-}\r
-\r
-\r
-// Get global variable name based on his Index\r
-// Return variable name's text pointer found\r
-// Return NULL if no variable name has been found\r
-char *DBGManager_GetGlobalVariableName(size_t Index)\r
-{\r
-       if ((DBGType & DBG_ELFDWARF))\r
-       {\r
-               return DWARFManager_GetGlobalVariableName(Index);\r
-       }\r
-       else\r
-       {\r
-               return  NULL;\r
-       }\r
-}\r
-\r
-\r
 // Get function name from address\r
 // Return function name found\r
 // Return NULL if no function name has been found\r
 // Get function name from address\r
 // Return function name found\r
 // Return NULL if no function name has been found\r
@@ -746,19 +795,33 @@ char *DBGManager_GetLineSrcFromNumLineBaseAdr(size_t Adr, size_t NumLine)
 \r
 \r
 // Get number of source code filenames\r
 \r
 \r
 // Get number of source code filenames\r
-size_t DBGManager_GetNbFullSourceFilename(void)\r
+size_t DBGManager_GetNbSources(void)\r
 {\r
        size_t Nbr = 0;\r
 \r
        if ((DBGType & DBG_ELFDWARF))\r
        {\r
 {\r
        size_t Nbr = 0;\r
 \r
        if ((DBGType & DBG_ELFDWARF))\r
        {\r
-               Nbr = DWARFManager_GetNbFullSourceFilename();\r
+               Nbr = DWARFManager_GetNbSources();\r
        }\r
 \r
        return Nbr;\r
 }\r
 \r
 \r
        }\r
 \r
        return Nbr;\r
 }\r
 \r
 \r
+// Get source code filename based on index\r
+char *DBGManager_GetNumSourceFilename(size_t Index)\r
+{\r
+       char *SourceFilename = NULL;\r
+\r
+       if ((DBGType & DBG_ELFDWARF))\r
+       {\r
+               SourceFilename = DWARFManager_GetNumSourceFilename(Index);\r
+       }\r
+\r
+       return  SourceFilename;\r
+}\r
+\r
+\r
 // Get source code filename based on index\r
 char *DBGManager_GetNumFullSourceFilename(size_t Index)\r
 {\r
 // Get source code filename based on index\r
 char *DBGManager_GetNumFullSourceFilename(size_t Index)\r
 {\r
@@ -771,3 +834,60 @@ char *DBGManager_GetNumFullSourceFilename(size_t Index)
 \r
        return  FullSourceFilename;\r
 }\r
 \r
        return  FullSourceFilename;\r
 }\r
+\r
+\r
+// Get number of lines of texts source list from source index\r
+size_t DBGManager_GetSrcNbListPtrFromIndex(size_t Index, bool Used)\r
+{\r
+       size_t NbListPtr = 0;\r
+\r
+       if ((DBGType & DBG_ELFDWARF))\r
+       {\r
+               NbListPtr = DWARFManager_GetSrcNbListPtrFromIndex(Index, Used);\r
+       }\r
+\r
+       return  NbListPtr;\r
+}\r
+\r
+\r
+// Get pointer to the lines number list from source index\r
+size_t *DBGManager_GetSrcNumLinesPtrFromIndex(size_t Index, bool Used)\r
+{\r
+       size_t *PtrNumLines = NULL;\r
+\r
+       if ((DBGType & DBG_ELFDWARF))\r
+       {\r
+               PtrNumLines = DWARFManager_GetSrcNumLinesPtrFromIndex(Index, Used);\r
+       }\r
+\r
+       return  PtrNumLines;\r
+}\r
+\r
+\r
+// Get text source list pointers from source index\r
+char **DBGManager_GetSrcListPtrFromIndex(size_t Index, bool Used)\r
+{\r
+       char **PtrSource = NULL;\r
+\r
+       if ((DBGType & DBG_ELFDWARF))\r
+       {\r
+               PtrSource = DWARFManager_GetSrcListPtrFromIndex(Index, Used);\r
+       }\r
+\r
+       return  PtrSource;\r
+}\r
+\r
+\r
+// Get source language\r
+size_t DBGManager_GetSrcLanguageFromIndex(size_t Index)\r
+{\r
+       size_t Language = 0;\r
+\r
+       if ((DBGType & DBG_ELFDWARF))\r
+       {\r
+               Language = DWARFManager_GetSrcLanguageFromIndex(Index);\r
+       }\r
+\r
+       return  Language;\r
+}\r
+\r