e79c257950e5c138f1cf6c1b482dba30eb45f28e
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
;
77 size_t DBGManager_GetType(void)
83 // Common debugger set
84 void DBGManager_SetType(size_t DBGTypeSet
)
86 DBGType
|= DBGTypeSet
;
90 // Common debugger close
91 void DBGManager_Close(void)
93 if ((DBGType
& DBG_DWARF
))
98 if ((DBGType
& DBG_ELF
))
105 // Get source filename based on the memeory address
106 // return NULL if no source filename
107 char *DBGManager_GetFullSourceFilenameFromAdr(size_t Adr
, bool *Error
)
109 if ((DBGType
& DBG_ELFDWARF
))
111 return DWARFManager_GetFullSourceFilenameFromAdr(Adr
, Error
);
120 // Get number of local variables
121 // Return 0 if none has been found
122 size_t DBGManager_GetNbLocalVariables(size_t Adr
)
124 if ((DBGType
& DBG_ELFDWARF
))
126 return DWARFManager_GetNbLocalVariables(Adr
);
135 // Get number of global variables
136 // Return 0 if none has been found
137 size_t DBGManager_GetNbGlobalVariables(void)
139 if ((DBGType
& DBG_ELFDWARF
))
141 return DWARFManager_GetNbGlobalVariables();
150 // Get address from symbol name
151 // Return found address
152 // Return NULL if no symbol has been found
153 size_t DBGManager_GetAdrFromSymbolName(char *SymbolName
)
157 if ((DBGType
& DBG_ELF
))
159 return ELFManager_GetAdrFromSymbolName(SymbolName
);
167 // Get global variable's Address based on his Name
168 // Return found Address
169 // Return NULL if no Address has been found
170 size_t DBGManager_GetGlobalVariableAdrFromName(char *VariableName
)
172 if ((DBGType
& DBG_ELFDWARF
))
174 return DWARFManager_GetGlobalVariableAdrFromName(VariableName
);
183 // Get local variable's type encoding based on his address and Index
184 // Return the type encoding found
185 // Return 0 if no type encoding has been found
186 size_t DBGManager_GetLocalVariableTypeEncoding(size_t Adr
, size_t Index
)
188 if ((DBGType
& DBG_ELFDWARF
))
190 return DWARFManager_GetLocalVariableTypeEncoding(Adr
, Index
);
200 int DBGManager_GetLocalVariableOffset(size_t Adr
, size_t Index
)
202 if ((DBGType
& DBG_ELFDWARF
))
204 return DWARFManager_GetLocalVariableOffset(Adr
, Index
);
213 // Get local variable's type byte size based on his address and Index
214 // Return the type's byte size found
215 // Return 0 if no type's byte size has been found
216 size_t DBGManager_GetLocalVariableTypeByteSize(size_t Adr
, size_t Index
)
218 if ((DBGType
& DBG_ELFDWARF
))
220 return DWARFManager_GetLocalVariableTypeByteSize(Adr
, Index
);
230 size_t DBGManager_GetLocalVariableTypeTag(size_t Adr
, size_t Index
)
232 if ((DBGType
& DBG_ELFDWARF
))
234 return DWARFManager_GetLocalVariableTypeTag(Adr
, Index
);
244 size_t DBGManager_GetGlobalVariableTypeTag(size_t Index
)
246 if ((DBGType
& DBG_ELFDWARF
))
248 return DWARFManager_GetGlobalVariableTypeTag(Index
);
257 // Get global variable's type name based on his Index
258 // Return type name's text pointer found
259 // Return NULL if no type name has been found
260 char *DBGManager_GetGlobalVariableTypeName(size_t Index
)
262 if ((DBGType
& DBG_ELFDWARF
))
264 return DWARFManager_GetGlobalVariableTypeName(Index
);
273 // Get global variable's Address based on his Index
274 // Return the Address found
275 // Return 0 if no Address has been found
276 size_t DBGManager_GetGlobalVariableAdr(size_t Index
)
278 if ((DBGType
& DBG_ELFDWARF
))
280 return DWARFManager_GetGlobalVariableAdr(Index
);
289 // Get global variable's type byte size based on his Index
290 // Return the type's byte size found
291 // Return 0 if no type's byte size has been found
292 size_t DBGManager_GetGlobalVariableTypeByteSize(size_t Index
)
294 if ((DBGType
& DBG_ELFDWARF
))
296 return DWARFManager_GetGlobalVariableTypeByteSize(Index
);
305 // Get global variable's type encoding based on his Index
306 // Return the type encoding found
307 // Return 0 if no type encoding has been found
308 size_t DBGManager_GetGlobalVariableTypeEncoding(size_t Index
)
310 if ((DBGType
& DBG_ELFDWARF
))
312 return DWARFManager_GetGlobalVariableTypeEncoding(Index
);
321 // Get global variable value based on his Index
322 // Return value as a text pointer
323 // Note: Pointer may point on a 0 lenght text
324 char *DBGManager_GetGlobalVariableValue(size_t Index
)
327 size_t TypeEncoding
= DBG_NO_TYPEENCODING
;
328 size_t TypeByteSize
= 0;
330 if ((DBGType
& DBG_ELFDWARF
))
332 Adr
= DWARFManager_GetGlobalVariableAdr(Index
);
333 TypeEncoding
= DWARFManager_GetGlobalVariableTypeEncoding(Index
);
334 TypeByteSize
= DWARFManager_GetGlobalVariableTypeByteSize(Index
);
337 return DBGManager_GetVariableValueFromAdr(Adr
, TypeEncoding
, TypeByteSize
);
341 // Get variable value based on his Adresse, Encoding Type and Size
342 // Return value as a text pointer
343 // Note: Pointer may point on a 0 lenght text if Adress is NULL
344 char *DBGManager_GetVariableValueFromAdr(size_t Adr
, size_t TypeEncoding
, size_t TypeByteSize
)
347 char *Ptrvalue
= value
;
353 memset(&V
, 0, sizeof(Value
));
355 for (uint32_t i
= 0; i
< TypeByteSize
; i
++)
356 jaguarMainRAM
[Adr
+ i
] = 0;
357 //jaguarMainRAM[Adr + i] = rand();
358 jaguarMainRAM
[Adr
+ TypeByteSize
- 1] = 0x10;
361 for (size_t i
= 0, j
= TypeByteSize
; i
< TypeByteSize
; i
++, j
--)
363 V
.C
[i
] = jaguarMainRAM
[Adr
+ j
- 1];
367 switch (TypeEncoding
)
369 case DBG_ATE_address
:
372 case DBG_ATE_boolean
:
375 case DBG_ATE_complex_float
:
379 switch (TypeByteSize
)
382 sprintf(value
, "%F", V
.F
);
386 //V.D = (double)jaguarMainRAM[Adr];
387 //sprintf(value, "%10.10F", V.D);
388 sprintf(value
, "%F", V
.D
);
397 switch (TypeByteSize
)
400 sprintf(value
, "%i", V
.SI
);
404 sprintf(value
, "%i", V
.SL
);
412 case DBG_ATE_signed_char
:
415 case DBG_ATE_unsigned
:
416 switch (TypeByteSize
)
419 sprintf(value
, "%u", V
.UI
);
423 sprintf(value
, "%u", V
.UL
);
431 case DBG_ATE_unsigned_char
:
435 switch (TypeByteSize
)
438 sprintf(value
, "0x%06x", V
.UI
);
454 // Get local variable's type name based on his Index
455 // Return type name's text pointer found
456 // Return NULL if no type name has been found
457 char *DBGManager_GetLocalVariableTypeName(size_t Adr
, size_t Index
)
459 if ((DBGType
& DBG_ELFDWARF
))
461 return DWARFManager_GetLocalVariableTypeName(Adr
, Index
);
470 // Get local variable Op based on his Index
471 // Return variable Op's found
472 // Return 0 if no variable Op has been found
473 size_t DBGManager_GetLocalVariableOp(size_t Adr
, size_t Index
)
475 if ((DBGType
& DBG_ELFDWARF
))
477 return DWARFManager_GetLocalVariableOp(Adr
, Index
);
486 // Get local variable name based on his Index
487 // Return variable name's text pointer found
488 // Return NULL if no variable name has been found
489 char *DBGManager_GetLocalVariableName(size_t Adr
, size_t Index
)
491 if ((DBGType
& DBG_ELFDWARF
))
493 return DWARFManager_GetLocalVariableName(Adr
, Index
);
502 // Get global variable name based on his Index
503 // Return variable name's text pointer found
504 // Return NULL if no variable name has been found
505 char *DBGManager_GetGlobalVariableName(size_t Index
)
507 if ((DBGType
& DBG_ELFDWARF
))
509 return DWARFManager_GetGlobalVariableName(Index
);
518 // Get function name from address
519 // Return function name found
520 // Return NULL if no function name has been found
521 char *DBGManager_GetFunctionName(size_t Adr
)
523 if ((DBGType
& DBG_ELFDWARF
))
525 return DWARFManager_GetFunctionName(Adr
);
534 // Get line number from address and his tag
535 // Return line number on the symbol name found
536 // Return 0 if no symbol name has been found
537 size_t DBGManager_GetNumLineFromAdr(size_t Adr
, size_t Tag
)
539 if ((DBGType
& DBG_ELFDWARF
))
541 return DWARFManager_GetNumLineFromAdr(Adr
, Tag
);
550 // Get symbol name from address
551 // Return text pointer on the symbol name found
552 // Return NULL if no symbol name has been found
553 char *DBGManager_GetSymbolNameFromAdr(size_t Adr
)
557 //if ((DBGType & DBG_HWLABEL) || vjs.displayHWlabels)
558 if (vjs
.displayHWlabels
)
560 Symbolname
= HWLABELManager_GetSymbolnameFromAdr(Adr
);
567 #pragma message("Warning: !!! Need to set the DBG_HWLABEL in DBGType instead to use the setting value !!!")
569 #warning "!!! Need to set the DBG_HWLABEL in DBGType instead to use the setting value !!!"
572 if (Symbolname
== NULL
)
574 if ((DBGType
& DBG_ELFDWARF
))
576 Symbolname
= DWARFManager_GetSymbolnameFromAdr(Adr
);
579 if ((DBGType
& DBG_ELF
) && (Symbolname
== NULL
))
581 Symbolname
= ELFManager_GetSymbolnameFromAdr(Adr
);
589 // Get source line based on the Address and his Tag
590 // Return text pointer on the source line found
591 // Return NULL if no source line has been found
592 char *DBGManager_GetLineSrcFromAdr(size_t Adr
, size_t Tag
)
594 char *Symbolname
= NULL
;
596 if ((DBGType
& DBG_ELFDWARF
))
598 Symbolname
= DWARFManager_GetLineSrcFromAdr(Adr
, Tag
);
605 // Get text line from source based on address and num line (starting by 1)
606 // Return NULL if no text line has been found
607 char *DBGManager_GetLineSrcFromAdrNumLine(size_t Adr
, size_t NumLine
)
609 char *Symbolname
= NULL
;
611 if ((DBGType
& DBG_ELFDWARF
))
613 Symbolname
= DWARFManager_GetLineSrcFromAdrNumLine(Adr
, NumLine
);
620 // Get text line from source based on address and num line (starting by 1)
621 // Return NULL if no text line has been found
622 char *DBGManager_GetLineSrcFromNumLineBaseAdr(size_t Adr
, size_t NumLine
)
624 char *Symbolname
= NULL
;
626 if ((DBGType
& DBG_ELFDWARF
))
628 Symbolname
= DWARFManager_GetLineSrcFromNumLineBaseAdr(Adr
, NumLine
);