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 /******************************************************************
49 * spacesToUnderscores - replace all non alpha-numerics with
53 *****************************************************************/
56 spacesToUnderscores (char *dest, const char *src, size_t len)
66 for (p = dest, i = 0; *src != '\0' && i < len; ++src, ++i) {
67 *p++ = (isspace((unsigned char)*src) || (*src == '-')) ? '_' : *src;
75 /******************************************************************
80 *****************************************************************/
82 int cdbOpenFile(char *file)
84 if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
85 fprintf (stderr, "cdbFile.c:cdbOpenFile(%s)\n", file);
87 return (cdbFilePtr = fopen(file, "w")) ? 1 : 0;
90 /******************************************************************
95 *****************************************************************/
96 int cdbCloseFile(void)
98 if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
99 fprintf (stderr, "cdbFile.c:cdbCloseFile()\n");
101 if(!cdbFilePtr) return 0;
105 cdbModuleName = NULL;
110 /******************************************************************
115 *****************************************************************/
117 int cdbWriteFunction(symbol *pSym, iCode *ic)
119 char debugSym[INITIAL_INLINEASM];
121 if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
122 fprintf (stderr, "cdbFile.c:cdbWriteFunction()\n");
125 if(!cdbFilePtr) return 0;
127 if (IS_STATIC (pSym->etype))
128 sprintf (debugSym, "F%s$%s$0$0", moduleName, pSym->name);
130 sprintf (debugSym, "G$%s$0$0", pSym->name);
131 emitDebuggerSymbol (debugSym);
133 return cdbWriteBasicSymbol(pSym, FALSE, TRUE);
136 /******************************************************************
141 *****************************************************************/
143 int cdbWriteEndFunction(symbol *pSym, iCode *ic, int offset)
145 char debugSym[INITIAL_INLINEASM];
147 if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
148 fprintf (stderr, "cdbFile.c:cdbWriteEndFunction()\n");
150 if(!cdbFilePtr) return 0;
154 sprintf (debugSym, "C$%s$%d$%d$%d",
155 FileBaseName (ic->filename), pSym->lastLine,
156 ic->level, ic->block);
157 spacesToUnderscores (debugSym, debugSym, sizeof (debugSym));
158 emitDebuggerSymbol (debugSym);
161 if (IS_STATIC (pSym->etype))
162 sprintf (debugSym, "XF%s$%s$0$0", moduleName, pSym->name);
164 sprintf (debugSym, "XG$%s$0$0", pSym->name);
165 emitDebuggerSymbol (debugSym);
170 /******************************************************************
175 *****************************************************************/
177 int cdbWriteLabel(symbol *pSym, iCode *ic)
179 if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
180 fprintf (stderr, "cdbFile.c:cdbWriteLabel()\n");
182 if(!cdbFilePtr) return 0;
187 /******************************************************************
192 *****************************************************************/
194 int cdbWriteScope(iCode *ic)
196 if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
197 fprintf (stderr, "cdbFile.c:cdbWriteScope()\n");
199 if(!cdbFilePtr) return 0;
204 /******************************************************************
209 *****************************************************************/
211 int cdbWriteSymbol(symbol *pSym)
213 if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
214 fprintf (stderr, "cdbFile.c:cdbWriteSymbol()\n");
216 if(!cdbFilePtr) return 0;
218 return cdbWriteBasicSymbol(pSym, FALSE, FALSE);
221 /******************************************************************
226 *****************************************************************/
228 int cdbWriteType(structdef *sdef, int block, int inStruct, char *tag)
232 if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
233 fprintf (stderr, "cdbFile.c:cdbWriteType()\n");
235 if(!cdbFilePtr) return 0;
237 fprintf (cdbFilePtr, "T:");
239 /* if block # then must have function scope */
240 fprintf (cdbFilePtr, "F%s$", moduleName);
242 fprintf (cdbFilePtr, "%s[", (tag ? tag : sdef->tag));
244 for (sym = sdef->fields; sym; sym = sym->next)
246 fprintf (cdbFilePtr, "({%d}", sym->offset);
247 cdbWriteBasicSymbol(sym, TRUE, FALSE);
248 fprintf(cdbFilePtr, ")");
251 fprintf (cdbFilePtr, "]");
254 fprintf (cdbFilePtr, "\n");
259 /******************************************************************
264 *****************************************************************/
266 int cdbWriteModule(char *name)
268 if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
269 fprintf (stderr, "cdbFile.c:cdbWriteModule()\n");
271 if(!cdbFilePtr) return 0;
272 cdbModuleName = name;
274 fprintf(cdbFilePtr, "M:%s\n", cdbModuleName);
279 /******************************************************************
284 *****************************************************************/
285 int cdbWriteCLine(iCode *ic)
287 char debugSym[INITIAL_INLINEASM];
289 if(!cdbFilePtr) return 0;
291 sprintf (debugSym, "C$%s$%d$%d$%d",
292 FileBaseName (ic->filename), ic->lineno,
293 ic->level, ic->block);
294 spacesToUnderscores (debugSym, debugSym, sizeof (debugSym));
295 emitDebuggerSymbol (debugSym);
300 /******************************************************************
305 *****************************************************************/
307 int cdbWriteALine(char *module, int Line)
309 if(!cdbFilePtr) return 0;
314 /******************************************************************
319 *****************************************************************/
321 int cdbWriteFrameAddress(char *variable, struct regs *reg, int offset)
323 if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
324 fprintf (stderr, "cdbFile.c:cdbWriteFrameAddress()\n");
326 if(!cdbFilePtr) return 0;
331 /******************************************************************
336 *****************************************************************/
338 int cdbWriteBasicSymbol(symbol *sym, int isStructSym, int isFunc)
342 if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
343 fprintf (stderr, "cdbFile.c:cdbWriteBasicSymbol()\n");
345 if(!cdbFilePtr) return 0;
349 /* WRITE HEADER, Function or Symbol */
351 fprintf (cdbFilePtr, "F:");
353 fprintf (cdbFilePtr, "S:");
355 /* STRUCTS do not have scope info.. */
362 if (IS_STATIC (sym->etype))
363 fprintf (cdbFilePtr, "F%s$", moduleName); /* scope is file */
365 fprintf (cdbFilePtr, "G$"); /* scope is global */
368 /* symbol is local */
369 fprintf (cdbFilePtr, "L%s$", (sym->localof ? sym->localof->name : "-null-"));
372 fprintf (cdbFilePtr, "S$"); /* scope is structure */
374 /* print the name, & mangled name */
375 fprintf (cdbFilePtr, "%s$%d$%d(", sym->name,
376 sym->level, sym->block);
378 cdbTypeInfo (sym->type);
380 fprintf (cdbFilePtr, "),");
382 /* CHECK FOR REGISTER SYMBOL... */
386 symbol *TempSym = OP_SYMBOL (sym->reqv);
388 fprintf(cdbFilePtr, "R,0,0,[");
390 for(a = 0; a < 4; a++)
392 fprintf(cdbFilePtr, "%s%s", port->getRegName(TempSym->regs[a]),
393 ((a < 3) && (TempSym->regs[a+1])) ? "," : "");
395 fprintf(cdbFilePtr, "]");
399 /* print the address space */
400 map = SPEC_OCLS (sym->etype);
402 fprintf (cdbFilePtr, "%c,%d,%d",
403 (map ? map->dbName : 'Z'), sym->onStack, SPEC_STAK (sym->etype));
406 /* if assigned to registers then output register names */
407 /* if this is a function then print
408 if is it an interrupt routine & interrupt number
409 and the register bank it is using */
411 fprintf (cdbFilePtr, ",%d,%d,%d", FUNC_ISISR (sym->type),
412 FUNC_INTNO (sym->type), FUNC_REGBANK (sym->type));
415 /* alternate location to find this symbol @ : eg registers
419 fprintf (cdbFilePtr, "\n");
424 /******************************************************************
429 *****************************************************************/
431 /*-----------------------------------------------------------------*/
432 /* cdbTypeInfo - print the type information for debugger */
433 /*-----------------------------------------------------------------*/
434 void cdbTypeInfo (sym_link * type)
436 fprintf (cdbFilePtr, "{%d}", getSize (type));
442 switch (DCL_TYPE (type))
444 case FUNCTION: fprintf (cdbFilePtr, "DF,"); break;
445 case GPOINTER: fprintf (cdbFilePtr, "DG,"); break;
446 case CPOINTER: fprintf (cdbFilePtr, "DC,"); break;
447 case FPOINTER: fprintf (cdbFilePtr, "DX,"); break;
448 case POINTER: fprintf (cdbFilePtr, "DD,"); break;
449 case IPOINTER: fprintf (cdbFilePtr, "DI,"); break;
450 case PPOINTER: fprintf (cdbFilePtr, "DP,"); break;
451 case EEPPOINTER: fprintf (cdbFilePtr, "DA,"); break;
452 case ARRAY: fprintf (cdbFilePtr, "DA%d,", DCL_ELEM (type)); break;
459 switch (SPEC_NOUN (type))
463 fprintf (cdbFilePtr, "SL");
465 fprintf (cdbFilePtr, "SI");
468 case V_CHAR: fprintf (cdbFilePtr, "SC"); break;
469 case V_VOID: fprintf (cdbFilePtr, "SV"); break;
470 case V_FLOAT: fprintf (cdbFilePtr, "SF"); break;
471 case V_FIXED16X16: fprintf(cdbFilePtr, "SQ"); break;
473 fprintf (cdbFilePtr, "ST%s", SPEC_STRUCT (type)->tag);
476 case V_SBIT: fprintf (cdbFilePtr, "SX"); break;
479 fprintf (cdbFilePtr, "SB%d$%d", SPEC_BSTR (type),
486 fputs (":", cdbFilePtr);
487 if (SPEC_USIGN (type))
488 fputs ("U", cdbFilePtr);
490 fputs ("S", cdbFilePtr);