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
17 #include "libelf/libelf.h"
18 #include "libelf/gelf.h"
20 #include "ELFManager.h"
21 #include "DwarfManager.h"
22 #include "DBGManager.h"
23 #include "HWLABELManager.h"
44 // Common debugger variables
49 // Common debugger initialisation
50 void DBGManager_Init(void)
52 DBGType
= DBG_NO_TYPE
;
58 // Common debugger reset
59 void DBGManager_Reset(void)
61 if ((DBGType
& DBG_DWARF
))
66 if ((DBGType
& DBG_ELF
))
71 //DBGType = vjs.displayHWlabels ? DBG_HWLABEL : DBG_NO_TYPE;
72 DBGType
= DBG_NO_TYPE
;
76 // Common debugger set
77 void DBGManager_SetType(size_t DBGTypeSet
)
79 DBGType
|= DBGTypeSet
;
83 // Common debugger close
84 void DBGManager_Close(void)
86 if ((DBGType
& DBG_DWARF
))
91 if ((DBGType
& DBG_ELF
))
98 // Get source filename based on the memeory address
99 // return NULL if no source filename
100 char *DBGManager_GetFullSourceFilenameFromAdr(size_t Adr
, bool *Error
)
102 if ((DBGType
& DBG_ELFDWARF
))
104 return DWARFManager_GetFullSourceFilenameFromAdr(Adr
, Error
);
113 // Get number of local variables
114 // Return 0 if none has been found
115 size_t DBGManager_GetNbLocalVariables(size_t Adr
)
117 if ((DBGType
& DBG_ELFDWARF
))
119 return DWARFManager_GetNbLocalVariables(Adr
);
128 // Get number of global variables
129 // Return 0 if none has been found
130 size_t DBGManager_GetNbGlobalVariables(void)
132 if ((DBGType
& DBG_ELFDWARF
))
134 return DWARFManager_GetNbGlobalVariables();
144 size_t DBGManager_GetAdrFromSymbolName(char *SymbolName
)
146 if ((DBGType
& DBG_ELF
))
148 return ELFManager_GetAdrFromSymbolName(SymbolName
);
157 // Get global variable's Address based on his Name
158 // Return found Address
159 // Return NULL if no Address has been found
160 size_t DBGManager_GetGlobalVariableAdrFromName(char *VariableName
)
162 if ((DBGType
& DBG_ELFDWARF
))
164 return DWARFManager_GetGlobalVariableAdrFromName(VariableName
);
173 // Get local variable's type encoding based on his address and Index
174 // Return the type encoding found
175 // Return 0 if no type encoding has been found
176 size_t DBGManager_GetLocalVariableTypeEncoding(size_t Adr
, size_t Index
)
178 if ((DBGType
& DBG_ELFDWARF
))
180 return DWARFManager_GetLocalVariableTypeEncoding(Adr
, Index
);
190 int DBGManager_GetLocalVariableOffset(size_t Adr
, size_t Index
)
192 if ((DBGType
& DBG_ELFDWARF
))
194 return DWARFManager_GetLocalVariableOffset(Adr
, Index
);
203 // Get local variable's type byte size based on his address and Index
204 // Return the type's byte size found
205 // Return 0 if no type's byte size has been found
206 size_t DBGManager_GetLocalVariableTypeByteSize(size_t Adr
, size_t Index
)
208 if ((DBGType
& DBG_ELFDWARF
))
210 return DWARFManager_GetLocalVariableTypeByteSize(Adr
, Index
);
220 size_t DBGManager_GetLocalVariableTypeTag(size_t Adr
, size_t Index
)
222 if ((DBGType
& DBG_ELFDWARF
))
224 return DWARFManager_GetLocalVariableTypeTag(Adr
, Index
);
234 size_t DBGManager_GetGlobalVariableTypeTag(size_t Index
)
236 if ((DBGType
& DBG_ELFDWARF
))
238 return DWARFManager_GetGlobalVariableTypeTag(Index
);
247 // Get global variable's type name based on his Index
248 // Return type name's text pointer found
249 // Return NULL if no type name has been found
250 char *DBGManager_GetGlobalVariableTypeName(size_t Index
)
252 if ((DBGType
& DBG_ELFDWARF
))
254 return DWARFManager_GetGlobalVariableTypeName(Index
);
263 // Get global variable's Address based on his Index
264 // Return the Address found
265 // Return 0 if no Address has been found
266 size_t DBGManager_GetGlobalVariableAdr(size_t Index
)
268 if ((DBGType
& DBG_ELFDWARF
))
270 return DWARFManager_GetGlobalVariableAdr(Index
);
279 // Get global variable's type byte size based on his Index
280 // Return the type's byte size found
281 // Return 0 if no type's byte size has been found
282 size_t DBGManager_GetGlobalVariableTypeByteSize(size_t Index
)
284 if ((DBGType
& DBG_ELFDWARF
))
286 return DWARFManager_GetGlobalVariableTypeByteSize(Index
);
295 // Get global variable's type encoding based on his Index
296 // Return the type encoding found
297 // Return 0 if no type encoding has been found
298 size_t DBGManager_GetGlobalVariableTypeEncoding(size_t Index
)
300 if ((DBGType
& DBG_ELFDWARF
))
302 return DWARFManager_GetGlobalVariableTypeEncoding(Index
);
311 // Get global variable value based on his Index
312 // Return value as a text pointer
313 // Note: Pointer may point on a 0 lenght text
314 char *DBGManager_GetGlobalVariableValue(size_t Index
)
317 size_t TypeEncoding
= DBG_NO_TYPEENCODING
;
318 size_t TypeByteSize
= 0;
320 if ((DBGType
& DBG_ELFDWARF
))
322 Adr
= DWARFManager_GetGlobalVariableAdr(Index
);
323 TypeEncoding
= DWARFManager_GetGlobalVariableTypeEncoding(Index
);
324 TypeByteSize
= DWARFManager_GetGlobalVariableTypeByteSize(Index
);
327 return DBGManager_GetVariableValueFromAdr(Adr
, TypeEncoding
, TypeByteSize
);
331 // Get variable value based on his Adresse, Encoding Type and Size
332 // Return value as a text pointer
333 // Note: Pointer may point on a 0 lenght text if Adress is NULL
334 char *DBGManager_GetVariableValueFromAdr(size_t Adr
, size_t TypeEncoding
, size_t TypeByteSize
)
337 char *Ptrvalue
= value
;
343 memset(&V
, 0, sizeof(Value
));
345 for (uint32_t i
= 0; i
< TypeByteSize
; i
++)
346 jaguarMainRAM
[Adr
+ i
] = 0;
347 //jaguarMainRAM[Adr + i] = rand();
348 jaguarMainRAM
[Adr
+ TypeByteSize
- 1] = 0x10;
351 for (size_t i
= 0, j
= TypeByteSize
; i
< TypeByteSize
; i
++, j
--)
353 V
.C
[i
] = jaguarMainRAM
[Adr
+ j
- 1];
357 switch (TypeEncoding
)
359 case DBG_ATE_address
:
362 case DBG_ATE_boolean
:
365 case DBG_ATE_complex_float
:
369 switch (TypeByteSize
)
372 sprintf(value
, "%F", V
.F
);
376 //V.D = (double)jaguarMainRAM[Adr];
377 //sprintf(value, "%10.10F", V.D);
378 sprintf(value
, "%F", V
.D
);
387 switch (TypeByteSize
)
390 sprintf(value
, "%i", V
.SI
);
394 sprintf(value
, "%i", V
.SL
);
402 case DBG_ATE_signed_char
:
405 case DBG_ATE_unsigned
:
406 switch (TypeByteSize
)
409 sprintf(value
, "%u", V
.UI
);
413 sprintf(value
, "%u", V
.UL
);
421 case DBG_ATE_unsigned_char
:
425 switch (TypeByteSize
)
428 sprintf(value
, "0x%06x", V
.UI
);
444 // Get local variable's type name based on his Index
445 // Return type name's text pointer found
446 // Return NULL if no type name has been found
447 char *DBGManager_GetLocalVariableTypeName(size_t Adr
, size_t Index
)
449 if ((DBGType
& DBG_ELFDWARF
))
451 return DWARFManager_GetLocalVariableTypeName(Adr
, Index
);
460 // Get local variable Op based on his Index
461 // Return variable Op's found
462 // Return 0 if no variable Op has been found
463 size_t DBGManager_GetLocalVariableOp(size_t Adr
, size_t Index
)
465 if ((DBGType
& DBG_ELFDWARF
))
467 return DWARFManager_GetLocalVariableOp(Adr
, Index
);
476 // Get local variable name based on his Index
477 // Return variable name's text pointer found
478 // Return NULL if no variable name has been found
479 char *DBGManager_GetLocalVariableName(size_t Adr
, size_t Index
)
481 if ((DBGType
& DBG_ELFDWARF
))
483 return DWARFManager_GetLocalVariableName(Adr
, Index
);
492 // Get global variable name based on his Index
493 // Return variable name's text pointer found
494 // Return NULL if no variable name has been found
495 char *DBGManager_GetGlobalVariableName(size_t Index
)
497 if ((DBGType
& DBG_ELFDWARF
))
499 return DWARFManager_GetGlobalVariableName(Index
);
508 // Get function name from address
509 // Return function name found
510 // Return NULL if no function name has been found
511 char *DBGManager_GetFunctionName(size_t Adr
)
513 if ((DBGType
& DBG_ELFDWARF
))
515 return DWARFManager_GetFunctionName(Adr
);
524 // Get line number from address and his tag
525 // Return line number on the symbol name found
526 // Return 0 if no symbol name has been found
527 size_t DBGManager_GetNumLineFromAdr(size_t Adr
, size_t Tag
)
529 if ((DBGType
& DBG_ELFDWARF
))
531 return DWARFManager_GetNumLineFromAdr(Adr
, Tag
);
540 // Get symbol name from address
541 // Return text pointer on the symbol name found
542 // Return NULL if no symbol name has been found
543 char *DBGManager_GetSymbolNameFromAdr(size_t Adr
)
547 //if ((DBGType & DBG_HWLABEL) || vjs.displayHWlabels)
548 if (vjs
.displayHWlabels
)
550 Symbolname
= HWLABELManager_GetSymbolnameFromAdr(Adr
);
557 #pragma message("Warning: !!! Need to set the DBG_HWLABEL in DBGType instead to use the setting value !!!")
559 #warning "!!! Need to set the DBG_HWLABEL in DBGType instead to use the setting value !!!"
562 if (Symbolname
== NULL
)
564 if ((DBGType
& DBG_ELFDWARF
))
566 Symbolname
= DWARFManager_GetSymbolnameFromAdr(Adr
);
569 if ((DBGType
& DBG_ELF
) && (Symbolname
== NULL
))
571 Symbolname
= ELFManager_GetSymbolnameFromAdr(Adr
);
579 // Get source line based on the Address and his Tag
580 // Return text pointer on the source line found
581 // Return NULL if no source line has been found
582 char *DBGManager_GetLineSrcFromAdr(size_t Adr
, size_t Tag
)
584 char *Symbolname
= NULL
;
586 if ((DBGType
& DBG_ELFDWARF
))
588 Symbolname
= DWARFManager_GetLineSrcFromAdr(Adr
, Tag
);
595 // Get text line from source based on address and num line (starting by 1)
596 // Return NULL if no text line has been found
597 char *DBGManager_GetLineSrcFromAdrNumLine(size_t Adr
, size_t NumLine
)
599 char *Symbolname
= NULL
;
601 if ((DBGType
& DBG_ELFDWARF
))
603 Symbolname
= DWARFManager_GetLineSrcFromAdrNumLine(Adr
, NumLine
);
610 // Get text line from source based on address and num line (starting by 1)
611 // Return NULL if no text line has been found
612 char *DBGManager_GetLineSrcFromNumLineBaseAdr(size_t Adr
, size_t NumLine
)
614 char *Symbolname
= NULL
;
616 if ((DBGType
& DBG_ELFDWARF
))
618 Symbolname
= DWARFManager_GetLineSrcFromNumLineBaseAdr(Adr
, NumLine
);