5f9251a1336c643fe0998ebe10c20a8e144224c4
2 // DBGManager.cpp: Debugger information manager
6 // JPM = Jean-Paul Mari <djipi.mari@gmail.com>
9 // --- ---------- ------------------------------------------------------------
10 // JPM 12/21/2016 Created this file
11 // JPM Various efforts to set the ELF format support
12 // JPM Various efforts to set the DWARF format support
13 // JPM 09/15/2018 Support the unsigned char
22 #include "libelf/libelf.h"
23 #include "libelf/gelf.h"
25 #include "ELFManager.h"
26 #include "DwarfManager.h"
27 #include "DBGManager.h"
28 #include "HWLABELManager.h"
51 // Common debugger variables
56 // Common debugger initialisation
57 void DBGManager_Init(void)
59 DBGType
= DBG_NO_TYPE
;
65 // Common debugger reset
66 void DBGManager_Reset(void)
68 if ((DBGType
& DBG_DWARF
))
73 if ((DBGType
& DBG_ELF
))
78 //DBGType = vjs.displayHWlabels ? DBG_HWLABEL : DBG_NO_TYPE;
79 DBGType
= DBG_NO_TYPE
;
84 size_t DBGManager_GetType(void)
90 // Common debugger set
91 void DBGManager_SetType(size_t DBGTypeSet
)
93 DBGType
|= DBGTypeSet
;
97 // Common debugger close
98 void DBGManager_Close(void)
100 if ((DBGType
& DBG_DWARF
))
102 DWARFManager_Close();
105 if ((DBGType
& DBG_ELF
))
112 // Get source filename based on the memeory address
113 // return NULL if no source filename
114 char *DBGManager_GetFullSourceFilenameFromAdr(size_t Adr
, bool *Error
)
116 if ((DBGType
& DBG_ELFDWARF
))
118 return DWARFManager_GetFullSourceFilenameFromAdr(Adr
, Error
);
127 // Get number of local variables
128 // Return 0 if none has been found
129 size_t DBGManager_GetNbLocalVariables(size_t Adr
)
131 if ((DBGType
& DBG_ELFDWARF
))
133 return DWARFManager_GetNbLocalVariables(Adr
);
142 // Get number of global variables
143 // Return 0 if none has been found
144 size_t DBGManager_GetNbGlobalVariables(void)
146 if ((DBGType
& DBG_ELFDWARF
))
148 return DWARFManager_GetNbGlobalVariables();
157 // Get address from symbol name
158 // Return found address
159 // Return NULL if no symbol has been found
160 size_t DBGManager_GetAdrFromSymbolName(char *SymbolName
)
164 if ((DBGType
& DBG_ELF
))
166 return ELFManager_GetAdrFromSymbolName(SymbolName
);
174 // Get global variable's Address based on his Name
175 // Return found Address
176 // Return NULL if no Address has been found
177 size_t DBGManager_GetGlobalVariableAdrFromName(char *VariableName
)
179 if ((DBGType
& DBG_ELFDWARF
))
181 return DWARFManager_GetGlobalVariableAdrFromName(VariableName
);
190 // Get local variable's type encoding based on his address and Index
191 // Return the type encoding found
192 // Return 0 if no type encoding has been found
193 size_t DBGManager_GetLocalVariableTypeEncoding(size_t Adr
, size_t Index
)
195 if ((DBGType
& DBG_ELFDWARF
))
197 return DWARFManager_GetLocalVariableTypeEncoding(Adr
, Index
);
207 int DBGManager_GetLocalVariableOffset(size_t Adr
, size_t Index
)
209 if ((DBGType
& DBG_ELFDWARF
))
211 return DWARFManager_GetLocalVariableOffset(Adr
, Index
);
220 // Get local variable's type byte size based on his address and Index
221 // Return the type's byte size found
222 // Return 0 if no type's byte size has been found
223 size_t DBGManager_GetLocalVariableTypeByteSize(size_t Adr
, size_t Index
)
225 if ((DBGType
& DBG_ELFDWARF
))
227 return DWARFManager_GetLocalVariableTypeByteSize(Adr
, Index
);
237 size_t DBGManager_GetLocalVariableTypeTag(size_t Adr
, size_t Index
)
239 if ((DBGType
& DBG_ELFDWARF
))
241 return DWARFManager_GetLocalVariableTypeTag(Adr
, Index
);
251 size_t DBGManager_GetGlobalVariableTypeTag(size_t Index
)
253 if ((DBGType
& DBG_ELFDWARF
))
255 return DWARFManager_GetGlobalVariableTypeTag(Index
);
264 // Get global variable's type name based on his Index
265 // Return type name's text pointer found
266 // Return NULL if no type name has been found
267 char *DBGManager_GetGlobalVariableTypeName(size_t Index
)
269 if ((DBGType
& DBG_ELFDWARF
))
271 return DWARFManager_GetGlobalVariableTypeName(Index
);
280 // Get global variable's Address based on his Index
281 // Return the Address found
282 // Return 0 if no Address has been found
283 size_t DBGManager_GetGlobalVariableAdr(size_t Index
)
285 if ((DBGType
& DBG_ELFDWARF
))
287 return DWARFManager_GetGlobalVariableAdr(Index
);
296 // Get global variable's type byte size based on his Index
297 // Return the type's byte size found
298 // Return 0 if no type's byte size has been found
299 size_t DBGManager_GetGlobalVariableTypeByteSize(size_t Index
)
301 if ((DBGType
& DBG_ELFDWARF
))
303 return DWARFManager_GetGlobalVariableTypeByteSize(Index
);
312 // Get global variable's type encoding based on his Index
313 // Return the type encoding found
314 // Return 0 if no type encoding has been found
315 size_t DBGManager_GetGlobalVariableTypeEncoding(size_t Index
)
317 if ((DBGType
& DBG_ELFDWARF
))
319 return DWARFManager_GetGlobalVariableTypeEncoding(Index
);
328 // Get global variable value based on his Index
329 // Return value as a text pointer
330 // Note: Pointer may point on a 0 lenght text
331 char *DBGManager_GetGlobalVariableValue(size_t Index
)
334 size_t TypeEncoding
= DBG_NO_TYPEENCODING
;
335 size_t TypeByteSize
= 0;
337 if ((DBGType
& DBG_ELFDWARF
))
339 Adr
= DWARFManager_GetGlobalVariableAdr(Index
);
340 TypeEncoding
= DWARFManager_GetGlobalVariableTypeEncoding(Index
);
341 TypeByteSize
= DWARFManager_GetGlobalVariableTypeByteSize(Index
);
344 return DBGManager_GetVariableValueFromAdr(Adr
, TypeEncoding
, TypeByteSize
);
348 // Get variable value based on his Adresse, Encoding Type and Size
349 // Return value as a text pointer
350 // Note: Pointer may point on a 0 length text
351 char *DBGManager_GetVariableValueFromAdr(size_t Adr
, size_t TypeEncoding
, size_t TypeByteSize
)
354 char *Ptrvalue
= value
;
362 memset(&V
, 0, sizeof(Value
));
364 for (uint32_t i
= 0; i
< TypeByteSize
; i
++)
365 jaguarMainRAM
[Adr
+ i
] = 0;
366 //jaguarMainRAM[Adr + i] = rand();
367 jaguarMainRAM
[Adr
+ TypeByteSize
- 1] = 0x10;
369 for (size_t i
= 0, j
= TypeByteSize
; i
< TypeByteSize
; i
++, j
--)
371 V
.Ct
[i
] = jaguarMainRAM
[Adr
+ j
- 1];
374 switch (TypeEncoding
)
376 case DBG_ATE_address
:
379 case DBG_ATE_boolean
:
380 sprintf(value
, "%s", V
.B
? "true" : "false");
383 case DBG_ATE_complex_float
:
387 switch (TypeByteSize
)
390 sprintf(value
, "%F", V
.F
);
394 //V.D = (double)jaguarMainRAM[Adr];
395 //sprintf(value, "%10.10F", V.D);
396 sprintf(value
, "%F", V
.D
);
405 switch (TypeByteSize
)
408 sprintf(value
, "%i", V
.SI
);
412 sprintf(value
, "%i", V
.SL
);
420 case DBG_ATE_signed_char
:
423 case DBG_ATE_unsigned
:
424 switch (TypeByteSize
)
427 sprintf(value
, "%u", V
.UI
);
431 sprintf(value
, "%u", V
.UL
);
439 case DBG_ATE_unsigned_char
:
440 sprintf(value
, "%u", (unsigned int(V
.C
)));
444 switch (TypeByteSize
)
447 sprintf(value
, "0x%06x", V
.UI
);
463 // Get local variable's type name based on his Index
464 // Return type name's text pointer found
465 // Return NULL if no type name has been found
466 char *DBGManager_GetLocalVariableTypeName(size_t Adr
, size_t Index
)
468 if ((DBGType
& DBG_ELFDWARF
))
470 return DWARFManager_GetLocalVariableTypeName(Adr
, Index
);
479 // Get local variable Op based on his Index
480 // Return variable Op's found
481 // Return 0 if no variable Op has been found
482 size_t DBGManager_GetLocalVariableOp(size_t Adr
, size_t Index
)
484 if ((DBGType
& DBG_ELFDWARF
))
486 return DWARFManager_GetLocalVariableOp(Adr
, Index
);
495 // Get local variable name based on his Index
496 // Return variable name's text pointer found
497 // Return NULL if no variable name has been found
498 char *DBGManager_GetLocalVariableName(size_t Adr
, size_t Index
)
500 if ((DBGType
& DBG_ELFDWARF
))
502 return DWARFManager_GetLocalVariableName(Adr
, Index
);
511 // Get global variable name based on his Index
512 // Return variable name's text pointer found
513 // Return NULL if no variable name has been found
514 char *DBGManager_GetGlobalVariableName(size_t Index
)
516 if ((DBGType
& DBG_ELFDWARF
))
518 return DWARFManager_GetGlobalVariableName(Index
);
527 // Get function name from address
528 // Return function name found
529 // Return NULL if no function name has been found
530 char *DBGManager_GetFunctionName(size_t Adr
)
532 if ((DBGType
& DBG_ELFDWARF
))
534 return DWARFManager_GetFunctionName(Adr
);
543 // Get line number from address and his tag
544 // Return line number on the symbol name found
545 // Return 0 if no symbol name has been found
546 size_t DBGManager_GetNumLineFromAdr(size_t Adr
, size_t Tag
)
548 if ((DBGType
& DBG_ELFDWARF
))
550 return DWARFManager_GetNumLineFromAdr(Adr
, Tag
);
559 // Get symbol name from address
560 // Return text pointer on the symbol name found
561 // Return NULL if no symbol name has been found
562 char *DBGManager_GetSymbolNameFromAdr(size_t Adr
)
566 //if ((DBGType & DBG_HWLABEL) || vjs.displayHWlabels)
567 if (vjs
.displayHWlabels
)
569 Symbolname
= HWLABELManager_GetSymbolnameFromAdr(Adr
);
576 #pragma message("Warning: !!! Need to set the DBG_HWLABEL in DBGType instead to use the setting value !!!")
578 #warning "!!! Need to set the DBG_HWLABEL in DBGType instead to use the setting value !!!"
581 if (Symbolname
== NULL
)
583 if ((DBGType
& DBG_ELFDWARF
))
585 Symbolname
= DWARFManager_GetSymbolnameFromAdr(Adr
);
588 if ((DBGType
& DBG_ELF
) && (Symbolname
== NULL
))
590 Symbolname
= ELFManager_GetSymbolnameFromAdr(Adr
);
598 // Get source line based on the Address and his Tag
599 // Return text pointer on the source line found
600 // Return NULL if no source line has been found
601 char *DBGManager_GetLineSrcFromAdr(size_t Adr
, size_t Tag
)
603 char *Symbolname
= NULL
;
605 if ((DBGType
& DBG_ELFDWARF
))
607 Symbolname
= DWARFManager_GetLineSrcFromAdr(Adr
, Tag
);
614 // Get text line from source based on address and num line (starting by 1)
615 // Return NULL if no text line has been found
616 char *DBGManager_GetLineSrcFromAdrNumLine(size_t Adr
, size_t NumLine
)
618 char *Symbolname
= NULL
;
620 if ((DBGType
& DBG_ELFDWARF
))
622 Symbolname
= DWARFManager_GetLineSrcFromAdrNumLine(Adr
, NumLine
);
629 // Get text line from source based on address and num line (starting by 1)
630 // Return NULL if no text line has been found
631 char *DBGManager_GetLineSrcFromNumLineBaseAdr(size_t Adr
, size_t NumLine
)
633 char *Symbolname
= NULL
;
635 if ((DBGType
& DBG_ELFDWARF
))
637 Symbolname
= DWARFManager_GetLineSrcFromNumLineBaseAdr(Adr
, NumLine
);
644 // Get number of source code filenames
645 size_t DBGManager_GetNbFullSourceFilename(void)
649 if ((DBGType
& DBG_ELFDWARF
))
651 Nbr
= DWARFManager_GetNbFullSourceFilename();
658 // Get source code filename based on index
659 char *DBGManager_GetNumFullSourceFilename(size_t Index
)
661 char *FullSourceFilename
= NULL
;
663 if ((DBGType
& DBG_ELFDWARF
))
665 FullSourceFilename
= DWARFManager_GetNumFullSourceFilename(Index
);
668 return FullSourceFilename
;