Added detection for the unsigned/signed short type
[clinton/Virtual-Jaguar-Rx.git] / src / debugger / DBGManager.cpp
index e79c257..1d024e3 100644 (file)
 // JPM  12/21/2016  Created this file\r
 // JPM              Various efforts to set the ELF format support\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  Sept./2019  Support the unsigned/signed short type\r
+//\r
+\r
+// To Do\r
+// To think about unique format to handle variations from ELF, DWARF, etc.\r
+//\r
+\r
 \r
 #include <stdlib.h>\r
 #include <string.h>\r
@@ -30,27 +39,124 @@ struct Value
 {\r
        union\r
        {\r
-               char C[10];\r
+               char Ct[10];\r
+               char C;\r
+               bool B;\r
                double D;\r
                float F;\r
+               int16_t SS;\r
                int32_t SI;\r
                int64_t SL;\r
+               uint16_t US;\r
                uint32_t UI;\r
                uint64_t UL;\r
        };\r
 }S_Value;\r
 \r
 \r
+//\r
+void DBGManager_SourceFileSearchPathsInit(void);\r
+void DBGManager_SourceFileSearchPathsReset(void);\r
+void DBGManager_SourceFileSearchPathsClose(void);\r
+\r
+\r
 // Common debugger variables\r
 size_t DBGType;\r
 char value[1000];\r
+size_t NbSFSearchPaths;\r
+char **SourceFileSearchPaths;\r
+\r
+\r
+// Init the source file search paths\r
+void DBGManager_SourceFileSearchPathsInit(void)\r
+{\r
+       NbSFSearchPaths = 0;\r
+       SourceFileSearchPaths = NULL;\r
+}\r
+\r
+\r
+// Set the source file search paths\r
+// Create individual path for each one provided in the list (separate with ';')\r
+void DBGManager_SourceFileSearchPathsSet(char *ListPaths)\r
+{\r
+       // Check presence of a previous list\r
+       if (NbSFSearchPaths)\r
+       {\r
+               // Reset previous list\r
+               DBGManager_SourceFileSearchPathsReset();\r
+       }\r
+\r
+       // Check if there is a paths list\r
+       if (strlen(ListPaths))\r
+       {\r
+               // Get number of paths\r
+               char *Ptr = ListPaths;\r
+               while(*Ptr)\r
+               {\r
+                       while (*Ptr && (*Ptr++ != ';'));\r
+                       {\r
+                               NbSFSearchPaths++;\r
+                       }\r
+               }\r
+\r
+               // Isolate each search path\r
+               SourceFileSearchPaths = (char **)calloc(NbSFSearchPaths, sizeof(char *));\r
+               size_t i = 0;\r
+               Ptr = ListPaths;\r
+\r
+               while (*Ptr)\r
+               {\r
+                       // Search the path separator (';')\r
+                       char *Ptr1 = Ptr;\r
+                       while (*Ptr && (*Ptr++ != ';'));\r
+\r
+                       // Copy the inidividual search path\r
+                       SourceFileSearchPaths[i] = (char *)calloc(1, (Ptr - Ptr1) + 1);\r
+                       strncpy(SourceFileSearchPaths[i], Ptr1, (Ptr - Ptr1));\r
+                       if (SourceFileSearchPaths[i][strlen(SourceFileSearchPaths[i]) - 1] == ';')\r
+                       {\r
+                               SourceFileSearchPaths[i][strlen(SourceFileSearchPaths[i]) - 1] = 0;\r
+                       }\r
+                       i++;\r
+               }\r
+       }\r
+\r
+       DWARFManager_Set(NbSFSearchPaths, SourceFileSearchPaths);\r
+}\r
+\r
+\r
+// Reset the source file search paths\r
+void DBGManager_SourceFileSearchPathsReset(void)\r
+{\r
+       // Free each path\r
+       while (NbSFSearchPaths)\r
+       {\r
+               free(SourceFileSearchPaths[--NbSFSearchPaths]);\r
+       }\r
+\r
+       // Free the pointers list\r
+       free(SourceFileSearchPaths);\r
+       SourceFileSearchPaths = NULL;\r
+}\r
+\r
+\r
+// Close the source file search paths\r
+void DBGManager_SourceFileSearchPathsClose(void)\r
+{\r
+       DBGManager_SourceFileSearchPathsReset();\r
+}\r
 \r
 \r
 // Common debugger initialisation\r
 void DBGManager_Init(void)\r
 {\r
+       // DBG initialisations\r
        DBGType = DBG_NO_TYPE;\r
+       DBGManager_SourceFileSearchPathsInit();\r
+\r
+       // ELF initialisation \r
        ELFManager_Init();\r
+       // DWARF initialisation\r
        DWARFManager_Init();\r
 }\r
 \r
@@ -73,20 +179,6 @@ void DBGManager_Reset(void)
 }\r
 \r
 \r
-// Get debugger type\r
-size_t DBGManager_GetType(void)\r
-{\r
-       return DBGType;\r
-}\r
-\r
-\r
-// Common debugger set\r
-void DBGManager_SetType(size_t DBGTypeSet)\r
-{\r
-       DBGType |= DBGTypeSet;\r
-}\r
-\r
-\r
 // Common debugger close\r
 void DBGManager_Close(void)\r
 {\r
@@ -99,6 +191,23 @@ void DBGManager_Close(void)
        {\r
                ELFManager_Close();\r
        }\r
+\r
+       DBGManager_SourceFileSearchPathsClose();\r
+       DBGType = DBG_NO_TYPE;\r
+}\r
+\r
+\r
+// Common debugger set\r
+void DBGManager_SetType(size_t DBGTypeSet)\r
+{\r
+       DBGType |= DBGTypeSet;\r
+}\r
+\r
+\r
+// Get debugger type\r
+size_t DBGManager_GetType(void)\r
+{\r
+       return DBGType;\r
 }\r
 \r
 \r
@@ -340,7 +449,7 @@ char *DBGManager_GetGlobalVariableValue(size_t Index)
 \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 lenght text if Adress is NULL\r
+// Note: Pointer may point on a 0 length text\r
 char *DBGManager_GetVariableValueFromAdr(size_t Adr, size_t TypeEncoding, size_t TypeByteSize)\r
 {\r
        Value V;\r
@@ -348,7 +457,9 @@ char *DBGManager_GetVariableValueFromAdr(size_t Adr, size_t TypeEncoding, size_t
 \r
        value[0] = 0;\r
 \r
+#if 0\r
        if (Adr)\r
+#endif\r
        {\r
                memset(&V, 0, sizeof(Value));\r
 #if 0\r
@@ -356,20 +467,19 @@ char *DBGManager_GetVariableValueFromAdr(size_t Adr, size_t TypeEncoding, size_t
                        jaguarMainRAM[Adr + i] = 0;\r
                        //jaguarMainRAM[Adr + i] = rand();\r
                jaguarMainRAM[Adr + TypeByteSize - 1] = 0x10;\r
-#endif\r
-#if 1\r
+#else\r
                for (size_t i = 0, j = TypeByteSize; i < TypeByteSize; i++, j--)\r
                {\r
-                       V.C[i] = jaguarMainRAM[Adr + j - 1];\r
+                       V.Ct[i] = jaguarMainRAM[Adr + j - 1];\r
                }\r
 #endif\r
-\r
                switch (TypeEncoding)\r
                {\r
                case DBG_ATE_address:\r
                        break;\r
 \r
                case DBG_ATE_boolean:\r
+                       sprintf(value, "%s", V.B ? "true" : "false");\r
                        break;\r
 \r
                case DBG_ATE_complex_float:\r
@@ -396,6 +506,10 @@ char *DBGManager_GetVariableValueFromAdr(size_t Adr, size_t TypeEncoding, size_t
                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
@@ -415,6 +529,10 @@ char *DBGManager_GetVariableValueFromAdr(size_t Adr, size_t TypeEncoding, size_t
                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
@@ -429,6 +547,7 @@ char *DBGManager_GetVariableValueFromAdr(size_t Adr, size_t TypeEncoding, size_t
                        break;\r
 \r
                case DBG_ATE_unsigned_char:\r
+                       sprintf(value, "%u", (unsigned int(V.C)));\r
                        break;\r
 \r
                case DBG_ATE_ptr:\r
@@ -520,14 +639,19 @@ char *DBGManager_GetGlobalVariableName(size_t Index)
 // Return NULL if no function name has been found\r
 char *DBGManager_GetFunctionName(size_t Adr)\r
 {\r
+       char *Symbolname = NULL;\r
+\r
        if ((DBGType & DBG_ELFDWARF))\r
        {\r
-               return DWARFManager_GetFunctionName(Adr);\r
+               Symbolname = DWARFManager_GetFunctionName(Adr);\r
        }\r
-       else\r
+\r
+       if ((DBGType & DBG_ELF) && (Symbolname == NULL))\r
        {\r
-               return  NULL;\r
+               Symbolname = ELFManager_GetFunctionName(Adr);\r
        }\r
+\r
+       return  Symbolname;\r
 }\r
 \r
 \r
@@ -591,43 +715,70 @@ char *DBGManager_GetSymbolNameFromAdr(size_t Adr)
 // Return NULL if no source line has been found\r
 char *DBGManager_GetLineSrcFromAdr(size_t Adr, size_t Tag)\r
 {\r
-       char *Symbolname = NULL;\r
+       char *TextLine = NULL;\r
 \r
        if ((DBGType & DBG_ELFDWARF))\r
        {\r
-               Symbolname = DWARFManager_GetLineSrcFromAdr(Adr, Tag);\r
+               TextLine = DWARFManager_GetLineSrcFromAdr(Adr, Tag);\r
        }\r
 \r
-       return  Symbolname;\r
+       return  TextLine;\r
 }\r
 \r
 \r
-// Get text line from source based on address and num line (starting by 1)\r
+// Get text line from source based on address and num line (starting from 1)\r
 // Return NULL if no text line has been found\r
 char *DBGManager_GetLineSrcFromAdrNumLine(size_t Adr, size_t NumLine)\r
 {\r
-       char *Symbolname = NULL;\r
+       char *TextLine = NULL;\r
 \r
        if ((DBGType & DBG_ELFDWARF))\r
        {\r
-               Symbolname = DWARFManager_GetLineSrcFromAdrNumLine(Adr, NumLine);\r
+               TextLine = DWARFManager_GetLineSrcFromAdrNumLine(Adr, NumLine);\r
        }\r
 \r
-       return  Symbolname;\r
+       return  TextLine;\r
 }\r
 \r
 \r
-// Get text line from source based on address and num line (starting by 1)\r
+// Get text line from source based on address and num line (starting from 1)\r
 // Return NULL if no text line has been found\r
 char *DBGManager_GetLineSrcFromNumLineBaseAdr(size_t Adr, size_t NumLine)\r
 {\r
-       char *Symbolname = NULL;\r
+       char *TextLine = NULL;\r
 \r
        if ((DBGType & DBG_ELFDWARF))\r
        {\r
-               Symbolname = DWARFManager_GetLineSrcFromNumLineBaseAdr(Adr, NumLine);\r
+               TextLine = DWARFManager_GetLineSrcFromNumLineBaseAdr(Adr, NumLine);\r
        }\r
 \r
-       return  Symbolname;\r
+       return  TextLine;\r
+}\r
+\r
+\r
+// Get number of source code filenames\r
+size_t DBGManager_GetNbFullSourceFilename(void)\r
+{\r
+       size_t Nbr = 0;\r
+\r
+       if ((DBGType & DBG_ELFDWARF))\r
+       {\r
+               Nbr = DWARFManager_GetNbFullSourceFilename();\r
+       }\r
+\r
+       return Nbr;\r
 }\r
 \r
+\r
+// Get source code filename based on index\r
+char *DBGManager_GetNumFullSourceFilename(size_t Index)\r
+{\r
+       char *FullSourceFilename = NULL;\r
+\r
+       if ((DBGType & DBG_ELFDWARF))\r
+       {\r
+               FullSourceFilename = DWARFManager_GetNumFullSourceFilename(Index);\r
+       }\r
+\r
+       return  FullSourceFilename;\r
+}\r