Keep the scrollbar position in accordance of the M68K PC pointer
[clinton/Virtual-Jaguar-Rx.git] / src / debugger / DBGManager.cpp
CommitLineData
2d0121d4
JPM
1//\r
2// DBGManager.cpp: Debugger information manager\r
3//\r
4// by Jean-Paul Mari\r
5//\r
6// JPM = Jean-Paul Mari <djipi.mari@gmail.com>\r
7//\r
8// WHO WHEN WHAT\r
9// --- ---------- ------------------------------------------------------------\r
10// JPM 12/21/2016 Created this file\r
11// JPM Various efforts to set the ELF format support\r
12// JPM Various efforts to set the DWARF format support\r
13\r
14#include <stdlib.h>\r
15#include <string.h>\r
16#include <stdint.h>\r
17#include "libelf/libelf.h"\r
18#include "libelf/gelf.h"\r
19#include "log.h"\r
20#include "ELFManager.h"\r
21#include "DwarfManager.h"\r
22#include "DBGManager.h"\r
23#include "HWLABELManager.h"\r
24#include "settings.h"\r
25#include "memory.h"\r
26\r
27\r
28// \r
29char *DBGManager_GetVariableValueFromAdr(uint32_t Adr, uint32_t TypeEncoding, uint32_t TypeByteSize);\r
30\r
31\r
32//\r
33struct Value\r
34{\r
35 union\r
36 {\r
37 char C[10];\r
38 double D;\r
39 float F;\r
40 int32_t SI;\r
41 int64_t SL;\r
42 uint32_t UI;\r
43 uint64_t UL;\r
44 };\r
45}S_Value;\r
46\r
47\r
48// Common debugger variables\r
49size_t DBGType;\r
50char value[1000];\r
51\r
52\r
53// Common debugger initialisation\r
54void DBGManager_Init(void)\r
55{\r
56 DBGType = DBG_NO_TYPE;\r
57 ELFManager_Init();\r
58 DWARFManager_Init();\r
59}\r
60\r
61\r
62// Common debugger reset\r
63void DBGManager_Reset(void)\r
64{\r
65 if ((DBGType & DBG_DWARF))\r
66 {\r
67 DWARFManager_Reset();\r
68 }\r
69\r
70 if ((DBGType & DBG_ELF))\r
71 {\r
72 ELFManager_Reset();\r
73 }\r
74\r
75 //DBGType = vjs.displayHWlabels ? DBG_HWLABEL : DBG_NO_TYPE;\r
76 DBGType = DBG_NO_TYPE;\r
77}\r
78\r
79\r
80// Common debugger set\r
81void DBGManager_SetType(size_t DBGTypeSet)\r
82{\r
83 DBGType |= DBGTypeSet;\r
84}\r
85\r
86\r
87// Common debugger close\r
88void DBGManager_Close(void)\r
89{\r
90 if ((DBGType & DBG_DWARF))\r
91 {\r
92 DWARFManager_Close();\r
93 }\r
94\r
95 if ((DBGType & DBG_ELF))\r
96 {\r
97 ELFManager_Close();\r
98 }\r
99}\r
100\r
101\r
102// Get source filename based on the memeory address\r
103// return NULL if no source filename\r
104char *DBGManager_GetFullSourceFilenameFromAdr(size_t Adr, bool *Error)\r
105{\r
106 if ((DBGType & DBG_ELFDWARF))\r
107 {\r
108 return DWARFManager_GetFullSourceFilenameFromAdr(Adr, Error);\r
109 }\r
110 else\r
111 {\r
112 return NULL;\r
113 }\r
114}\r
115\r
116\r
117// Get number of external variables\r
118// Return 0 if none has been found\r
119size_t DBGManager_GetNbExternalVariables(void)\r
120{\r
121 if ((DBGType & DBG_ELFDWARF))\r
122 {\r
123 return DWARFManager_GetNbExternalVariables();\r
124 }\r
125 else\r
126 {\r
127 return 0;\r
128 }\r
129}\r
130\r
131\r
132//\r
133size_t DBGManager_GetAdrFromSymbolName(char *SymbolName)\r
134{\r
135 if ((DBGType & DBG_ELF))\r
136 {\r
137 return ELFManager_GetAdrFromSymbolName(SymbolName);\r
138 }\r
139 else\r
140 {\r
141 return 0;\r
142 }\r
143}\r
144\r
145\r
146// Get external variable's Address based on his Name\r
147// Return found Address\r
148// Return NULL if no Address has been found\r
149size_t DBGManager_GetExternalVariableAdrFromName(char *VariableName)\r
150{\r
151 if ((DBGType & DBG_ELFDWARF))\r
152 {\r
153 return DWARFManager_GetExternalVariableAdrFromName(VariableName);\r
154 }\r
155 else\r
156 {\r
157 return 0;\r
158 }\r
159}\r
160\r
161\r
162//\r
163size_t DBGManager_GetExternalVariableTypeTag(size_t Index)\r
164{\r
165 if ((DBGType & DBG_ELFDWARF))\r
166 {\r
167 return DWARFManager_GetExternalVariableTypeTag(Index);\r
168 }\r
169 else\r
170 {\r
171 return 0;\r
172 }\r
173}\r
174\r
175\r
176// Get external variable's type name based on his Index\r
177// Return type name's text pointer found\r
178// Return NULL if no type name has been found\r
179char *DBGManager_GetExternalVariableTypeName(size_t Index)\r
180{\r
181 if ((DBGType & DBG_ELFDWARF))\r
182 {\r
183 return DWARFManager_GetExternalVariableTypeName(Index);\r
184 }\r
185 else\r
186 {\r
187 return NULL;\r
188 }\r
189}\r
190\r
191\r
192// Get external variable's Address based on his Index\r
193// Return the Address found\r
194// Return 0 if no Address has been found\r
195size_t DBGManager_GetExternalVariableAdr(size_t Index)\r
196{\r
197 if ((DBGType & DBG_ELFDWARF))\r
198 {\r
199 return DWARFManager_GetExternalVariableAdr(Index);\r
200 }\r
201 else\r
202 {\r
203 return 0;\r
204 }\r
205}\r
206\r
207\r
208// Get external variable's type byte size based on his Index\r
209// Return the type's byte size found\r
210// Return 0 if no type's byte size has been found\r
211size_t DBGManager_GetExternalVariableTypeByteSize(size_t Index)\r
212{\r
213 if ((DBGType & DBG_ELFDWARF))\r
214 {\r
215 return DWARFManager_GetExternalVariableTypeByteSize(Index);\r
216 }\r
217 else\r
218 {\r
219 return 0;\r
220 }\r
221}\r
222\r
223\r
224// Get external variable's type encoding based on his Index\r
225// Return the type encoding found\r
226// Return 0 if no type encoding has been found\r
227size_t DBGManager_GetExternalVariableTypeEncoding(size_t Index)\r
228{\r
229 if ((DBGType & DBG_ELFDWARF))\r
230 {\r
231 return DWARFManager_GetExternalVariableTypeEncoding(Index);\r
232 }\r
233 else\r
234 {\r
235 return 0;\r
236 }\r
237}\r
238\r
239\r
240// Get external variable value based on his Index\r
241// Return value as a text pointer\r
242// Note: Pointer may point on a 0 lenght text\r
243char *DBGManager_GetExternalVariableValue(size_t Index)\r
244{\r
245 uint32_t Adr = 0;\r
246 uint32_t TypeEncoding = DBG_NO_TYPEENCODING;\r
247 uint32_t TypeByteSize = 0;\r
248\r
249 if ((DBGType & DBG_ELFDWARF))\r
250 {\r
251 Adr = DWARFManager_GetExternalVariableAdr(Index);\r
252 TypeEncoding = DWARFManager_GetExternalVariableTypeEncoding(Index);\r
253 TypeByteSize = DWARFManager_GetExternalVariableTypeByteSize(Index);\r
254 }\r
255\r
256 return DBGManager_GetVariableValueFromAdr(Adr, TypeEncoding, TypeByteSize);\r
257}\r
258\r
259\r
260// Get variable value based on his Adresse, Encoding Type and Size\r
261// Return value as a text pointer\r
262// Note: Pointer may point on a 0 lenght text if Adress is NULL\r
263char *DBGManager_GetVariableValueFromAdr(uint32_t Adr, uint32_t TypeEncoding, uint32_t TypeByteSize)\r
264{\r
265 Value V;\r
266 char *Ptrvalue = value;\r
267\r
268 value[0] = 0;\r
269\r
270 if (Adr)\r
271 {\r
272 memset(&V, 0, sizeof(Value));\r
273#if 0\r
274 for (uint32_t i = 0; i < TypeByteSize; i++)\r
275 jaguarMainRAM[Adr + i] = 0;\r
276 //jaguarMainRAM[Adr + i] = rand();\r
277 jaguarMainRAM[Adr + TypeByteSize - 1] = 0x10;\r
278#endif\r
279#if 1\r
280 for (uint32_t i = 0, j = TypeByteSize; i < TypeByteSize; i++, j--)\r
281 {\r
282 V.C[i] = jaguarMainRAM[Adr + j - 1];\r
283 }\r
284#endif\r
285\r
286 switch (TypeEncoding)\r
287 {\r
288 case DBG_ATE_address:\r
289 break;\r
290\r
291 case DBG_ATE_boolean:\r
292 break;\r
293\r
294 case DBG_ATE_complex_float:\r
295 break;\r
296\r
297 case DBG_ATE_float:\r
298 switch (TypeByteSize)\r
299 {\r
300 case 4:\r
301 sprintf(value, "%F", V.F);\r
302 break;\r
303\r
304 case 8:\r
305 //V.D = (double)jaguarMainRAM[Adr];\r
306 //sprintf(value, "%10.10F", V.D);\r
307 sprintf(value, "%F", V.D);\r
308 break;\r
309\r
310 default:\r
311 break;\r
312 }\r
313 break;\r
314\r
315 case DBG_ATE_signed:\r
316 switch (TypeByteSize)\r
317 {\r
318 case 4:\r
319 sprintf(value, "%i", V.SI);\r
320 break;\r
321\r
322 case 8:\r
323 sprintf(value, "%i", V.SL);\r
324 break;\r
325\r
326 default:\r
327 break;\r
328 }\r
329 break;\r
330\r
331 case DBG_ATE_signed_char:\r
332 break;\r
333\r
334 case DBG_ATE_unsigned:\r
335 switch (TypeByteSize)\r
336 {\r
337 case 4:\r
338 sprintf(value, "%u", V.UI);\r
339 break;\r
340\r
341 case 8:\r
342 sprintf(value, "%u", V.UL);\r
343 break;\r
344\r
345 default:\r
346 break;\r
347 }\r
348 break;\r
349\r
350 case DBG_ATE_unsigned_char:\r
351 break;\r
352\r
353 case DBG_ATE_ptr:\r
354 switch (TypeByteSize)\r
355 {\r
356 case 4:\r
357 sprintf(value, "0x%06x", V.UI);\r
358 break;\r
359\r
360 default:\r
361 break;\r
362 }\r
363\r
364 default:\r
365 break;\r
366 }\r
367 }\r
368\r
369 return Ptrvalue;\r
370}\r
371\r
372\r
373// Get external variable name based on his Index\r
374// Return variable name's text pointer found\r
375// Return NULL if no variable name has been found\r
376char *DBGManager_GetExternalVariableName(size_t Index)\r
377{\r
378 if ((DBGType & DBG_ELFDWARF))\r
379 {\r
380 return DWARFManager_GetExternalVariableName(Index);\r
381 }\r
382 else\r
383 {\r
384 return NULL;\r
385 }\r
386}\r
387\r
388\r
389// Get line number from address and his tag\r
390// Return line number on the symbol name found\r
391// Return 0 if no symbol name has been found\r
392size_t DBGManager_GetNumLineFromAdr(size_t Adr, size_t Tag)\r
393{\r
394 if ((DBGType & DBG_ELFDWARF))\r
395 {\r
396 return DWARFManager_GetNumLineFromAdr(Adr, Tag);\r
397 }\r
398 else\r
399 {\r
400 return 0;\r
401 }\r
402}\r
403\r
404\r
405// Get symbol name from address\r
406// Return text pointer on the symbol name found\r
407// Return NULL if no symbol name has been found\r
408char *DBGManager_GetSymbolnameFromAdr(size_t Adr)\r
409{\r
410 char *Symbolname;\r
411\r
412 //if ((DBGType & DBG_HWLABEL) || vjs.displayHWlabels)\r
413 if (vjs.displayHWlabels)\r
414 {\r
415 Symbolname = HWLABELManager_GetSymbolnameFromAdr(Adr);\r
416 }\r
417 else\r
418 {\r
419 Symbolname = NULL;\r
420 }\r
421#ifdef _MSC_VER
422#pragma message("Warning: !!! Need to set the DBG_HWLABEL in DBGType instead to use the setting value !!!")
423#else
424 #warning "!!! Need to set the DBG_HWLABEL in DBGType instead to use the setting value !!!"
425#endif // _MSC_VER\r
426\r
427 if (Symbolname == NULL)\r
428 {\r
429 if ((DBGType & DBG_ELFDWARF))\r
430 {\r
431 Symbolname = DWARFManager_GetSymbolnameFromAdr(Adr);\r
432 }\r
433\r
434 if ((DBGType & DBG_ELF) && (Symbolname == NULL))\r
435 {\r
436 Symbolname = ELFManager_GetSymbolnameFromAdr(Adr);\r
437 }\r
438 }\r
439\r
440 return Symbolname;\r
441}\r
442\r
443\r
444// Get source line based on the Address and his Tag\r
445// Return text pointer on the source line found\r
446// Return NULL if no source line has been found\r
447char *DBGManager_GetLineSrcFromAdr(size_t Adr, size_t Tag)\r
448{\r
449 char *Symbolname = NULL;\r
450\r
451 if ((DBGType & DBG_ELFDWARF))\r
452 {\r
453 Symbolname = DWARFManager_GetLineSrcFromAdr(Adr, Tag);\r
454 }\r
455\r
456 return Symbolname;\r
457}\r
458\r
459\r
460// Get text line from source based on address and num line (starting by 1)\r
461// Return NULL if no text line has been found\r
462char *DBGManager_GetLineSrcFromAdrNumLine(size_t Adr, size_t NumLine)\r
463{\r
464 char *Symbolname = NULL;\r
465\r
466 if ((DBGType & DBG_ELFDWARF))\r
467 {\r
468 Symbolname = DWARFManager_GetLineSrcFromAdrNumLine(Adr, NumLine);\r
469 }\r
470\r
471 return Symbolname;\r
472}\r
473\r
474\r
475// Get text line from source based on address and num line (starting by 1)\r
476// Return NULL if no text line has been found\r
477char *DBGManager_GetLineSrcFromNumLineBaseAdr(size_t Adr, size_t NumLine)\r
478{\r
479 char *Symbolname = NULL;\r
480\r
481 if ((DBGType & DBG_ELFDWARF))\r
482 {\r
483 Symbolname = DWARFManager_GetLineSrcFromNumLineBaseAdr(Adr, NumLine);\r
484 }\r
485\r
486 return Symbolname;\r
487}\r
488\r