* src/*.c, src/pic16/{gen.c,glue.c,main.c}: applied Vangelis
[fw/sdcc] / src / cdbFile.c
1
2
3 #include "common.h"
4
5
6 /*************************************************************
7  *
8  *
9  *
10  *
11  *************************************************************/
12
13 int cdbOpenFile(char *file);
14 int cdbCloseFile(void);
15 int cdbWriteFunction(symbol *pSym, iCode *ic);
16 int cdbWriteEndFunction(symbol *pSym, iCode *ic, int offset);
17 int cdbWriteLabel(symbol *pSym, iCode *ic);
18 int cdbWriteScope(iCode *ic);
19 int cdbWriteSymbol(symbol *pSym);
20 int cdbWriteType(structdef *sdef, int block, int inStruct, char *tag);
21 int cdbWriteModule(char *name);
22 int cdbWriteCLine(iCode *ic);
23 int cdbWriteALine(char *module, int Line);
24 int cdbWriteFrameAddress(char *variable, struct regs *reg, int offset);
25 int cdbWriteBasicSymbol(symbol *sym, int isStructSym, int isFunc);
26 void cdbTypeInfo (sym_link * type);
27      
28
29 DEBUGFILE cdbDebugFile = 
30   {
31     &cdbOpenFile,
32     &cdbCloseFile,
33     &cdbWriteModule,
34     &cdbWriteFunction,
35     &cdbWriteEndFunction,
36     &cdbWriteLabel,
37     &cdbWriteScope,
38     &cdbWriteSymbol,
39     &cdbWriteType,
40     &cdbWriteCLine,
41     &cdbWriteALine,
42     &cdbWriteFrameAddress
43   };
44
45 FILE *cdbFilePtr = NULL;
46 char *cdbModuleName = NULL;
47
48 /******************************************************************
49  *
50  *
51  *
52  *
53  *****************************************************************/
54
55 int cdbOpenFile(char *file)
56 {
57   if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
58     fprintf (stderr, "cdbFile.c:cdbOpenFile(%s)\n", file);
59
60   return (cdbFilePtr = fopen(file, "w")) ? 1 : 0; 
61 }
62
63 /******************************************************************
64  *
65  *
66  *
67  *
68  *****************************************************************/
69 int cdbCloseFile(void)
70 {
71   if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
72     fprintf (stderr, "cdbFile.c:cdbCloseFile()\n");
73
74   if(!cdbFilePtr) return 0;
75  
76   fclose(cdbFilePtr);
77   cdbFilePtr = NULL;
78   cdbModuleName = NULL;
79
80   return 1;
81 }
82
83 /******************************************************************
84  *
85  *
86  *
87  *
88  *****************************************************************/
89
90 int cdbWriteFunction(symbol *pSym, iCode *ic)
91 {
92   char debugSym[INITIAL_INLINEASM];
93   
94   if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
95     fprintf (stderr, "cdbFile.c:cdbWriteFunction()\n");
96
97
98   if(!cdbFilePtr) return 0;
99
100   if (IS_STATIC (pSym->etype))
101     sprintf (debugSym, "F%s$%s$0$0", moduleName, pSym->name);
102   else
103     sprintf (debugSym, "G$%s$0$0", pSym->name);
104   emitDebuggerSymbol (debugSym);
105     
106   return cdbWriteBasicSymbol(pSym, FALSE, TRUE);
107 }
108
109 /******************************************************************
110  *
111  *
112  *
113  *
114  *****************************************************************/
115
116 int cdbWriteEndFunction(symbol *pSym, iCode *ic, int offset)
117 {
118   char debugSym[INITIAL_INLINEASM];
119   
120   if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
121     fprintf (stderr, "cdbFile.c:cdbWriteEndFunction()\n");
122
123   if(!cdbFilePtr) return 0;
124           
125   if (ic)
126     {
127       sprintf (debugSym, "C$%s$%d$%d$%d",
128                FileBaseName (ic->filename), pSym->lastLine,
129                ic->level, ic->block);
130       emitDebuggerSymbol (debugSym);
131     }
132
133   if (IS_STATIC (pSym->etype))
134     sprintf (debugSym, "XF%s$%s$0$0", moduleName, pSym->name);
135   else
136     sprintf (debugSym, "XG$%s$0$0", pSym->name);
137   emitDebuggerSymbol (debugSym);
138     
139   return 1;
140 }
141
142 /******************************************************************
143  *
144  *
145  *
146  *
147  *****************************************************************/
148
149 int cdbWriteLabel(symbol *pSym, iCode *ic)
150 {
151   if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
152     fprintf (stderr, "cdbFile.c:cdbWriteLabel()\n");
153
154   if(!cdbFilePtr) return 0;
155           
156   return 1;
157 }
158
159 /******************************************************************
160  *
161  *
162  *
163  *
164  *****************************************************************/
165
166 int cdbWriteScope(iCode *ic)
167 {
168   if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
169     fprintf (stderr, "cdbFile.c:cdbWriteScope()\n");
170
171   if(!cdbFilePtr) return 0;
172           
173   return 1;
174 }
175
176 /******************************************************************
177  *
178  *
179  *
180  *
181  *****************************************************************/
182
183 int cdbWriteSymbol(symbol *pSym)
184 {
185   if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
186     fprintf (stderr, "cdbFile.c:cdbWriteSymbol()\n");
187
188   if(!cdbFilePtr) return 0;
189
190   return cdbWriteBasicSymbol(pSym, FALSE, FALSE);
191 }
192
193 /******************************************************************
194  *
195  *
196  *
197  *
198  *****************************************************************/
199
200 int cdbWriteType(structdef *sdef, int block, int inStruct, char *tag)
201 {
202   symbol *sym;
203
204   if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
205     fprintf (stderr, "cdbFile.c:cdbWriteType()\n");
206
207   if(!cdbFilePtr) return 0;
208
209   fprintf (cdbFilePtr, "T:");
210
211   /* if block # then must have function scope */
212   fprintf (cdbFilePtr, "F%s$", moduleName);
213
214   fprintf (cdbFilePtr, "%s[", (tag ? tag : sdef->tag));
215
216   for (sym = sdef->fields; sym; sym = sym->next)
217     {
218       fprintf (cdbFilePtr, "({%d}", sym->offset);
219       cdbWriteBasicSymbol(sym, TRUE, FALSE);
220       fprintf(cdbFilePtr, ")");
221     }
222
223   fprintf (cdbFilePtr, "]");
224
225   if (!inStruct)
226     fprintf (cdbFilePtr, "\n");
227
228   return 1;
229 }
230
231 /******************************************************************
232  *
233  *
234  *
235  *
236  *****************************************************************/
237
238 int cdbWriteModule(char *name)
239 {
240   if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
241     fprintf (stderr, "cdbFile.c:cdbWriteModule()\n");
242
243   if(!cdbFilePtr) return 0;
244   cdbModuleName = name;
245
246   fprintf(cdbFilePtr, "M:%s\n", cdbModuleName);
247
248   return 1;
249 }
250
251 /******************************************************************
252  *
253  *
254  *
255  *
256  *****************************************************************/
257 int cdbWriteCLine(iCode *ic)
258 {
259   char debugSym[INITIAL_INLINEASM];
260   
261   if(!cdbFilePtr) return 0;
262               
263   sprintf (debugSym, "C$%s$%d$%d$%d", 
264            FileBaseName (ic->filename), ic->lineno,
265            ic->level, ic->block);
266   emitDebuggerSymbol (debugSym);
267
268   return 1;
269 }
270
271 /******************************************************************
272  *
273  *
274  *
275  *
276  *****************************************************************/
277
278 int cdbWriteALine(char *module, int Line)
279 {
280   if(!cdbFilePtr) return 0;
281
282   return 1;
283 }
284
285 /******************************************************************
286  *
287  *
288  *
289  *
290  *****************************************************************/
291
292 int cdbWriteFrameAddress(char *variable, struct regs *reg, int offset)
293 {
294   if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
295     fprintf (stderr, "cdbFile.c:cdbWriteFrameAddress()\n");
296
297   if(!cdbFilePtr) return 0;
298           
299   return 1;
300 }
301
302 /******************************************************************
303  *
304  *
305  *
306  *
307  *****************************************************************/
308
309 int cdbWriteBasicSymbol(symbol *sym, int isStructSym, int isFunc)
310 {
311   memmap *map;
312
313   if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
314     fprintf (stderr, "cdbFile.c:cdbWriteBasicSymbol()\n");
315
316   if(!cdbFilePtr) return 0;
317
318   if (!sym) return 0;
319
320   /* WRITE HEADER, Function or Symbol */
321   if (isFunc)
322     fprintf (cdbFilePtr, "F:");   
323   else
324     fprintf (cdbFilePtr, "S:");
325
326   /* STRUCTS do not have scope info.. */
327
328   if (!isStructSym)
329     {
330       if (!sym->level)
331         {
332           /* global */
333           if (IS_STATIC (sym->etype))
334             fprintf (cdbFilePtr, "F%s$", moduleName);   /* scope is file */
335           else
336             fprintf (cdbFilePtr, "G$"); /* scope is global */
337         }
338       else
339         /* symbol is local */
340         fprintf (cdbFilePtr, "L%s$", (sym->localof ? sym->localof->name : "-null-"));
341     }
342   else
343     fprintf (cdbFilePtr, "S$");         /* scope is structure */
344
345   /* print the name, & mangled name */
346   fprintf (cdbFilePtr, "%s$%d$%d(", sym->name,
347            sym->level, sym->block);
348
349   cdbTypeInfo (sym->type);
350
351   fprintf (cdbFilePtr, "),");
352
353   /* CHECK FOR REGISTER SYMBOL... */ 
354   if(sym->reqv)
355   {
356     int a;
357     symbol *TempSym = OP_SYMBOL (sym->reqv);
358
359     fprintf(cdbFilePtr, "R,0,0,[");
360
361     for(a = 0; a < 4; a++)
362       if(TempSym->regs[a])     
363         fprintf(cdbFilePtr, "%s%s", port->getRegName(TempSym->regs[a]),
364                 ((a < 3) && (TempSym->regs[a+1])) ? "," : "");
365
366     fprintf(cdbFilePtr, "]");
367   }
368   else
369   {
370     /* print the address space */
371     map = SPEC_OCLS (sym->etype);
372
373     fprintf (cdbFilePtr, "%c,%d,%d",
374              (map ? map->dbName : 'Z'), sym->onStack, SPEC_STAK (sym->etype));
375   }
376
377   /* if assigned to registers then output register names */
378   /* if this is a function then print
379      if is it an interrupt routine & interrupt number
380      and the register bank it is using */
381   if (isFunc)
382     fprintf (cdbFilePtr, ",%d,%d,%d", FUNC_ISISR (sym->type),
383              FUNC_INTNO (sym->type), FUNC_REGBANK (sym->type));
384   
385
386 /* alternate location to find this symbol @ : eg registers
387      or spillication */
388
389   if (!isStructSym)
390     fprintf (cdbFilePtr, "\n");
391
392   return 1;
393 }
394
395 /******************************************************************
396  *
397  *
398  *
399  *
400  *****************************************************************/
401
402 /*-----------------------------------------------------------------*/
403 /* cdbTypeInfo - print the type information for debugger           */
404 /*-----------------------------------------------------------------*/
405 void cdbTypeInfo (sym_link * type)
406 {
407   fprintf (cdbFilePtr, "{%d}", getSize (type));
408
409   while (type)
410     {
411       if (IS_DECL (type))
412         {
413           switch (DCL_TYPE (type))
414             {
415             case FUNCTION: fprintf (cdbFilePtr, "DF,"); break;
416             case GPOINTER: fprintf (cdbFilePtr, "DG,"); break;
417             case CPOINTER: fprintf (cdbFilePtr, "DC,"); break;
418             case FPOINTER: fprintf (cdbFilePtr, "DX,"); break;
419             case POINTER:  fprintf (cdbFilePtr, "DD,"); break;
420             case IPOINTER: fprintf (cdbFilePtr, "DI,"); break;
421             case PPOINTER: fprintf (cdbFilePtr, "DP,"); break;
422             case EEPPOINTER: fprintf (cdbFilePtr, "DA,"); break;
423             case ARRAY: fprintf (cdbFilePtr, "DA%d,", DCL_ELEM (type)); break;
424             default:
425               break;
426             }
427         }
428       else
429         {
430           switch (SPEC_NOUN (type))
431             {
432             case V_INT:
433               if (IS_LONG (type))
434                 fprintf (cdbFilePtr, "SL");
435               else
436                 fprintf (cdbFilePtr, "SI");
437               break;
438
439             case V_CHAR: fprintf (cdbFilePtr, "SC"); break;
440             case V_VOID: fprintf (cdbFilePtr, "SV"); break;
441             case V_FLOAT: fprintf (cdbFilePtr, "SF"); break;
442             case V_FIXED16X16: fprintf(cdbFilePtr, "SQ"); break;
443             case V_STRUCT: 
444               fprintf (cdbFilePtr, "ST%s", SPEC_STRUCT (type)->tag); 
445               break;
446             
447             case V_SBIT: fprintf (cdbFilePtr, "SX"); break;
448             case V_BIT: 
449             case V_BITFIELD: 
450               fprintf (cdbFilePtr, "SB%d$%d", SPEC_BSTR (type), 
451                        SPEC_BLEN (type));
452               break;
453
454             default:
455               break;
456             }
457           fputs (":", cdbFilePtr);
458           if (SPEC_USIGN (type))
459             fputs ("U", cdbFilePtr);
460           else
461             fputs ("S", cdbFilePtr);
462         }
463       type = type->next;
464     }
465 }
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484