6 /*************************************************************
11 *************************************************************/
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);
29 DEBUGFILE cdbDebugFile =
45 FILE *cdbFilePtr = NULL;
46 char *cdbModuleName = NULL;
48 /******************************************************************
53 *****************************************************************/
55 int cdbOpenFile(char *file)
57 if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
58 fprintf (stderr, "cdbFile.c:cdbOpenFile(%s)\n", file);
60 return (cdbFilePtr = fopen(file, "w")) ? 1 : 0;
63 /******************************************************************
68 *****************************************************************/
69 int cdbCloseFile(void)
71 if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
72 fprintf (stderr, "cdbFile.c:cdbCloseFile()\n");
74 if(!cdbFilePtr) return 0;
83 /******************************************************************
88 *****************************************************************/
90 int cdbWriteFunction(symbol *pSym, iCode *ic)
92 char debugSym[INITIAL_INLINEASM];
94 if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
95 fprintf (stderr, "cdbFile.c:cdbWriteFunction()\n");
98 if(!cdbFilePtr) return 0;
100 if (IS_STATIC (pSym->etype))
101 sprintf (debugSym, "F%s$%s$0$0", moduleName, pSym->name);
103 sprintf (debugSym, "G$%s$0$0", pSym->name);
104 emitDebuggerSymbol (debugSym);
106 return cdbWriteBasicSymbol(pSym, FALSE, TRUE);
109 /******************************************************************
114 *****************************************************************/
116 int cdbWriteEndFunction(symbol *pSym, iCode *ic, int offset)
118 char debugSym[INITIAL_INLINEASM];
120 if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
121 fprintf (stderr, "cdbFile.c:cdbWriteEndFunction()\n");
123 if(!cdbFilePtr) return 0;
127 sprintf (debugSym, "C$%s$%d$%d$%d",
128 FileBaseName (ic->filename), pSym->lastLine,
129 ic->level, ic->block);
130 emitDebuggerSymbol (debugSym);
133 if (IS_STATIC (pSym->etype))
134 sprintf (debugSym, "XF%s$%s$0$0", moduleName, pSym->name);
136 sprintf (debugSym, "XG$%s$0$0", pSym->name);
137 emitDebuggerSymbol (debugSym);
142 /******************************************************************
147 *****************************************************************/
149 int cdbWriteLabel(symbol *pSym, iCode *ic)
151 if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
152 fprintf (stderr, "cdbFile.c:cdbWriteLabel()\n");
154 if(!cdbFilePtr) return 0;
159 /******************************************************************
164 *****************************************************************/
166 int cdbWriteScope(iCode *ic)
168 if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
169 fprintf (stderr, "cdbFile.c:cdbWriteScope()\n");
171 if(!cdbFilePtr) return 0;
176 /******************************************************************
181 *****************************************************************/
183 int cdbWriteSymbol(symbol *pSym)
185 if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
186 fprintf (stderr, "cdbFile.c:cdbWriteSymbol()\n");
188 if(!cdbFilePtr) return 0;
190 return cdbWriteBasicSymbol(pSym, FALSE, FALSE);
193 /******************************************************************
198 *****************************************************************/
200 int cdbWriteType(structdef *sdef, int block, int inStruct, char *tag)
204 if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
205 fprintf (stderr, "cdbFile.c:cdbWriteType()\n");
207 if(!cdbFilePtr) return 0;
209 fprintf (cdbFilePtr, "T:");
211 /* if block # then must have function scope */
212 fprintf (cdbFilePtr, "F%s$", moduleName);
214 fprintf (cdbFilePtr, "%s[", (tag ? tag : sdef->tag));
216 for (sym = sdef->fields; sym; sym = sym->next)
218 fprintf (cdbFilePtr, "({%d}", sym->offset);
219 cdbWriteBasicSymbol(sym, TRUE, FALSE);
220 fprintf(cdbFilePtr, ")");
223 fprintf (cdbFilePtr, "]");
226 fprintf (cdbFilePtr, "\n");
231 /******************************************************************
236 *****************************************************************/
238 int cdbWriteModule(char *name)
240 if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
241 fprintf (stderr, "cdbFile.c:cdbWriteModule()\n");
243 if(!cdbFilePtr) return 0;
244 cdbModuleName = name;
246 fprintf(cdbFilePtr, "M:%s\n", cdbModuleName);
251 /******************************************************************
256 *****************************************************************/
257 int cdbWriteCLine(iCode *ic)
259 char debugSym[INITIAL_INLINEASM];
261 if(!cdbFilePtr) return 0;
263 sprintf (debugSym, "C$%s$%d$%d$%d",
264 FileBaseName (ic->filename), ic->lineno,
265 ic->level, ic->block);
266 emitDebuggerSymbol (debugSym);
271 /******************************************************************
276 *****************************************************************/
278 int cdbWriteALine(char *module, int Line)
280 if(!cdbFilePtr) return 0;
285 /******************************************************************
290 *****************************************************************/
292 int cdbWriteFrameAddress(char *variable, struct regs *reg, int offset)
294 if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
295 fprintf (stderr, "cdbFile.c:cdbWriteFrameAddress()\n");
297 if(!cdbFilePtr) return 0;
302 /******************************************************************
307 *****************************************************************/
309 int cdbWriteBasicSymbol(symbol *sym, int isStructSym, int isFunc)
313 if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
314 fprintf (stderr, "cdbFile.c:cdbWriteBasicSymbol()\n");
316 if(!cdbFilePtr) return 0;
320 /* WRITE HEADER, Function or Symbol */
322 fprintf (cdbFilePtr, "F:");
324 fprintf (cdbFilePtr, "S:");
326 /* STRUCTS do not have scope info.. */
333 if (IS_STATIC (sym->etype))
334 fprintf (cdbFilePtr, "F%s$", moduleName); /* scope is file */
336 fprintf (cdbFilePtr, "G$"); /* scope is global */
339 /* symbol is local */
340 fprintf (cdbFilePtr, "L%s$", (sym->localof ? sym->localof->name : "-null-"));
343 fprintf (cdbFilePtr, "S$"); /* scope is structure */
345 /* print the name, & mangled name */
346 fprintf (cdbFilePtr, "%s$%d$%d(", sym->name,
347 sym->level, sym->block);
349 cdbTypeInfo (sym->type);
351 fprintf (cdbFilePtr, "),");
353 /* CHECK FOR REGISTER SYMBOL... */
357 symbol *TempSym = OP_SYMBOL (sym->reqv);
359 fprintf(cdbFilePtr, "R,0,0,[");
361 for(a = 0; a < 4; a++)
363 fprintf(cdbFilePtr, "%s%s", port->getRegName(TempSym->regs[a]),
364 ((a < 3) && (TempSym->regs[a+1])) ? "," : "");
366 fprintf(cdbFilePtr, "]");
370 /* print the address space */
371 map = SPEC_OCLS (sym->etype);
373 fprintf (cdbFilePtr, "%c,%d,%d",
374 (map ? map->dbName : 'Z'), sym->onStack, SPEC_STAK (sym->etype));
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 */
382 fprintf (cdbFilePtr, ",%d,%d,%d", FUNC_ISISR (sym->type),
383 FUNC_INTNO (sym->type), FUNC_REGBANK (sym->type));
386 /* alternate location to find this symbol @ : eg registers
390 fprintf (cdbFilePtr, "\n");
395 /******************************************************************
400 *****************************************************************/
402 /*-----------------------------------------------------------------*/
403 /* cdbTypeInfo - print the type information for debugger */
404 /*-----------------------------------------------------------------*/
405 void cdbTypeInfo (sym_link * type)
407 fprintf (cdbFilePtr, "{%d}", getSize (type));
413 switch (DCL_TYPE (type))
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;
430 switch (SPEC_NOUN (type))
434 fprintf (cdbFilePtr, "SL");
436 fprintf (cdbFilePtr, "SI");
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;
444 fprintf (cdbFilePtr, "ST%s", SPEC_STRUCT (type)->tag);
447 case V_SBIT: fprintf (cdbFilePtr, "SX"); break;
450 fprintf (cdbFilePtr, "SB%d$%d", SPEC_BSTR (type),
457 fputs (":", cdbFilePtr);
458 if (SPEC_USIGN (type))
459 fputs ("U", cdbFilePtr);
461 fputs ("S", cdbFilePtr);