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
14 // JPM 10/06/2018 Cosmetic changes
24 #include "libelf/libelf.h"
25 #include "libelf/gelf.h"
27 #include "ELFManager.h"
28 #include "DwarfManager.h"
29 #include "DBGManager.h"
30 #include "HWLABELManager.h"
53 // Common debugger variables
58 // Common debugger initialisation
59 void DBGManager_Init(void)
61 DBGType
= DBG_NO_TYPE
;
67 // Common debugger reset
68 void DBGManager_Reset(void)
70 if ((DBGType
& DBG_DWARF
))
75 if ((DBGType
& DBG_ELF
))
80 //DBGType = vjs.displayHWlabels ? DBG_HWLABEL : DBG_NO_TYPE;
81 DBGType
= DBG_NO_TYPE
;
86 size_t DBGManager_GetType(void)
92 // Common debugger set
93 void DBGManager_SetType(size_t DBGTypeSet
)
95 DBGType
|= DBGTypeSet
;
99 // Common debugger close
100 void DBGManager_Close(void)
102 if ((DBGType
& DBG_DWARF
))
104 DWARFManager_Close();
107 if ((DBGType
& DBG_ELF
))
114 // Get source filename based on the memeory address
115 // return NULL if no source filename
116 char *DBGManager_GetFullSourceFilenameFromAdr(size_t Adr
, bool *Error
)
118 if ((DBGType
& DBG_ELFDWARF
))
120 return DWARFManager_GetFullSourceFilenameFromAdr(Adr
, Error
);
129 // Get number of local variables
130 // Return 0 if none has been found
131 size_t DBGManager_GetNbLocalVariables(size_t Adr
)
133 if ((DBGType
& DBG_ELFDWARF
))
135 return DWARFManager_GetNbLocalVariables(Adr
);
144 // Get number of global variables
145 // Return 0 if none has been found
146 size_t DBGManager_GetNbGlobalVariables(void)
148 if ((DBGType
& DBG_ELFDWARF
))
150 return DWARFManager_GetNbGlobalVariables();
159 // Get address from symbol name
160 // Return found address
161 // Return NULL if no symbol has been found
162 size_t DBGManager_GetAdrFromSymbolName(char *SymbolName
)
166 if ((DBGType
& DBG_ELF
))
168 return ELFManager_GetAdrFromSymbolName(SymbolName
);
176 // Get global variable's Address based on his Name
177 // Return found Address
178 // Return NULL if no Address has been found
179 size_t DBGManager_GetGlobalVariableAdrFromName(char *VariableName
)
181 if ((DBGType
& DBG_ELFDWARF
))
183 return DWARFManager_GetGlobalVariableAdrFromName(VariableName
);
192 // Get local variable's type encoding based on his address and Index
193 // Return the type encoding found
194 // Return 0 if no type encoding has been found
195 size_t DBGManager_GetLocalVariableTypeEncoding(size_t Adr
, size_t Index
)
197 if ((DBGType
& DBG_ELFDWARF
))
199 return DWARFManager_GetLocalVariableTypeEncoding(Adr
, Index
);
209 int DBGManager_GetLocalVariableOffset(size_t Adr
, size_t Index
)
211 if ((DBGType
& DBG_ELFDWARF
))
213 return DWARFManager_GetLocalVariableOffset(Adr
, Index
);
222 // Get local variable's type byte size based on his address and Index
223 // Return the type's byte size found
224 // Return 0 if no type's byte size has been found
225 size_t DBGManager_GetLocalVariableTypeByteSize(size_t Adr
, size_t Index
)
227 if ((DBGType
& DBG_ELFDWARF
))
229 return DWARFManager_GetLocalVariableTypeByteSize(Adr
, Index
);
239 size_t DBGManager_GetLocalVariableTypeTag(size_t Adr
, size_t Index
)
241 if ((DBGType
& DBG_ELFDWARF
))
243 return DWARFManager_GetLocalVariableTypeTag(Adr
, Index
);
253 size_t DBGManager_GetGlobalVariableTypeTag(size_t Index
)
255 if ((DBGType
& DBG_ELFDWARF
))
257 return DWARFManager_GetGlobalVariableTypeTag(Index
);
266 // Get global variable's type name based on his Index
267 // Return type name's text pointer found
268 // Return NULL if no type name has been found
269 char *DBGManager_GetGlobalVariableTypeName(size_t Index
)
271 if ((DBGType
& DBG_ELFDWARF
))
273 return DWARFManager_GetGlobalVariableTypeName(Index
);
282 // Get global variable's Address based on his Index
283 // Return the Address found
284 // Return 0 if no Address has been found
285 size_t DBGManager_GetGlobalVariableAdr(size_t Index
)
287 if ((DBGType
& DBG_ELFDWARF
))
289 return DWARFManager_GetGlobalVariableAdr(Index
);
298 // Get global variable's type byte size based on his Index
299 // Return the type's byte size found
300 // Return 0 if no type's byte size has been found
301 size_t DBGManager_GetGlobalVariableTypeByteSize(size_t Index
)
303 if ((DBGType
& DBG_ELFDWARF
))
305 return DWARFManager_GetGlobalVariableTypeByteSize(Index
);
314 // Get global variable's type encoding based on his Index
315 // Return the type encoding found
316 // Return 0 if no type encoding has been found
317 size_t DBGManager_GetGlobalVariableTypeEncoding(size_t Index
)
319 if ((DBGType
& DBG_ELFDWARF
))
321 return DWARFManager_GetGlobalVariableTypeEncoding(Index
);
330 // Get global variable value based on his Index
331 // Return value as a text pointer
332 // Note: Pointer may point on a 0 lenght text
333 char *DBGManager_GetGlobalVariableValue(size_t Index
)
336 size_t TypeEncoding
= DBG_NO_TYPEENCODING
;
337 size_t TypeByteSize
= 0;
339 if ((DBGType
& DBG_ELFDWARF
))
341 Adr
= DWARFManager_GetGlobalVariableAdr(Index
);
342 TypeEncoding
= DWARFManager_GetGlobalVariableTypeEncoding(Index
);
343 TypeByteSize
= DWARFManager_GetGlobalVariableTypeByteSize(Index
);
346 return DBGManager_GetVariableValueFromAdr(Adr
, TypeEncoding
, TypeByteSize
);
350 // Get variable value based on his Adresse, Encoding Type and Size
351 // Return value as a text pointer
352 // Note: Pointer may point on a 0 length text
353 char *DBGManager_GetVariableValueFromAdr(size_t Adr
, size_t TypeEncoding
, size_t TypeByteSize
)
356 char *Ptrvalue
= value
;
364 memset(&V
, 0, sizeof(Value
));
366 for (uint32_t i
= 0; i
< TypeByteSize
; i
++)
367 jaguarMainRAM
[Adr
+ i
] = 0;
368 //jaguarMainRAM[Adr + i] = rand();
369 jaguarMainRAM
[Adr
+ TypeByteSize
- 1] = 0x10;
371 for (size_t i
= 0, j
= TypeByteSize
; i
< TypeByteSize
; i
++, j
--)
373 V
.Ct
[i
] = jaguarMainRAM
[Adr
+ j
- 1];
376 switch (TypeEncoding
)
378 case DBG_ATE_address
:
381 case DBG_ATE_boolean
:
382 sprintf(value
, "%s", V
.B
? "true" : "false");
385 case DBG_ATE_complex_float
:
389 switch (TypeByteSize
)
392 sprintf(value
, "%F", V
.F
);
396 //V.D = (double)jaguarMainRAM[Adr];
397 //sprintf(value, "%10.10F", V.D);
398 sprintf(value
, "%F", V
.D
);
407 switch (TypeByteSize
)
410 sprintf(value
, "%i", V
.SI
);
414 sprintf(value
, "%i", V
.SL
);
422 case DBG_ATE_signed_char
:
425 case DBG_ATE_unsigned
:
426 switch (TypeByteSize
)
429 sprintf(value
, "%u", V
.UI
);
433 sprintf(value
, "%u", V
.UL
);
441 case DBG_ATE_unsigned_char
:
442 sprintf(value
, "%u", (unsigned int(V
.C
)));
446 switch (TypeByteSize
)
449 sprintf(value
, "0x%06x", V
.UI
);
465 // Get local variable's type name based on his Index
466 // Return type name's text pointer found
467 // Return NULL if no type name has been found
468 char *DBGManager_GetLocalVariableTypeName(size_t Adr
, size_t Index
)
470 if ((DBGType
& DBG_ELFDWARF
))
472 return DWARFManager_GetLocalVariableTypeName(Adr
, Index
);
481 // Get local variable Op based on his Index
482 // Return variable Op's found
483 // Return 0 if no variable Op has been found
484 size_t DBGManager_GetLocalVariableOp(size_t Adr
, size_t Index
)
486 if ((DBGType
& DBG_ELFDWARF
))
488 return DWARFManager_GetLocalVariableOp(Adr
, Index
);
497 // Get local variable name based on his Index
498 // Return variable name's text pointer found
499 // Return NULL if no variable name has been found
500 char *DBGManager_GetLocalVariableName(size_t Adr
, size_t Index
)
502 if ((DBGType
& DBG_ELFDWARF
))
504 return DWARFManager_GetLocalVariableName(Adr
, Index
);
513 // Get global variable name based on his Index
514 // Return variable name's text pointer found
515 // Return NULL if no variable name has been found
516 char *DBGManager_GetGlobalVariableName(size_t Index
)
518 if ((DBGType
& DBG_ELFDWARF
))
520 return DWARFManager_GetGlobalVariableName(Index
);
529 // Get function name from address
530 // Return function name found
531 // Return NULL if no function name has been found
532 char *DBGManager_GetFunctionName(size_t Adr
)
534 if ((DBGType
& DBG_ELFDWARF
))
536 return DWARFManager_GetFunctionName(Adr
);
545 // Get line number from address and his tag
546 // Return line number on the symbol name found
547 // Return 0 if no symbol name has been found
548 size_t DBGManager_GetNumLineFromAdr(size_t Adr
, size_t Tag
)
550 if ((DBGType
& DBG_ELFDWARF
))
552 return DWARFManager_GetNumLineFromAdr(Adr
, Tag
);
561 // Get symbol name from address
562 // Return text pointer on the symbol name found
563 // Return NULL if no symbol name has been found
564 char *DBGManager_GetSymbolNameFromAdr(size_t Adr
)
568 //if ((DBGType & DBG_HWLABEL) || vjs.displayHWlabels)
569 if (vjs
.displayHWlabels
)
571 Symbolname
= HWLABELManager_GetSymbolnameFromAdr(Adr
);
578 #pragma message("Warning: !!! Need to set the DBG_HWLABEL in DBGType instead to use the setting value !!!")
580 #warning "!!! Need to set the DBG_HWLABEL in DBGType instead to use the setting value !!!"
583 if (Symbolname
== NULL
)
585 if ((DBGType
& DBG_ELFDWARF
))
587 Symbolname
= DWARFManager_GetSymbolnameFromAdr(Adr
);
590 if ((DBGType
& DBG_ELF
) && (Symbolname
== NULL
))
592 Symbolname
= ELFManager_GetSymbolnameFromAdr(Adr
);
600 // Get source line based on the Address and his Tag
601 // Return text pointer on the source line found
602 // Return NULL if no source line has been found
603 char *DBGManager_GetLineSrcFromAdr(size_t Adr
, size_t Tag
)
605 char *TextLine
= NULL
;
607 if ((DBGType
& DBG_ELFDWARF
))
609 TextLine
= DWARFManager_GetLineSrcFromAdr(Adr
, Tag
);
616 // Get text line from source based on address and num line (starting from 1)
617 // Return NULL if no text line has been found
618 char *DBGManager_GetLineSrcFromAdrNumLine(size_t Adr
, size_t NumLine
)
620 char *TextLine
= NULL
;
622 if ((DBGType
& DBG_ELFDWARF
))
624 TextLine
= DWARFManager_GetLineSrcFromAdrNumLine(Adr
, NumLine
);
631 // Get text line from source based on address and num line (starting from 1)
632 // Return NULL if no text line has been found
633 char *DBGManager_GetLineSrcFromNumLineBaseAdr(size_t Adr
, size_t NumLine
)
635 char *TextLine
= NULL
;
637 if ((DBGType
& DBG_ELFDWARF
))
639 TextLine
= DWARFManager_GetLineSrcFromNumLineBaseAdr(Adr
, NumLine
);
646 // Get number of source code filenames
647 size_t DBGManager_GetNbFullSourceFilename(void)
651 if ((DBGType
& DBG_ELFDWARF
))
653 Nbr
= DWARFManager_GetNbFullSourceFilename();
660 // Get source code filename based on index
661 char *DBGManager_GetNumFullSourceFilename(size_t Index
)
663 char *FullSourceFilename
= NULL
;
665 if ((DBGType
& DBG_ELFDWARF
))
667 FullSourceFilename
= DWARFManager_GetNumFullSourceFilename(Index
);
670 return FullSourceFilename
;