6 /*************************************************************
11 *************************************************************/
13 int cdbOpenFile(char *file);
14 int cdbCloseFile(void);
15 int cdbWriteFunction(symbol *pSym);
16 int cdbWriteSymbol(symbol *pSym);
17 int cdbWriteType(structdef *sdef, int block, int inStruct, char *tag);
18 int cdbWriteModule(char *name);
19 int cdbWriteCLine(char *module, int Line, int Level, int Block);
20 int cdbWriteALine(char *module, int Line);
21 int cdbWriteBasicSymbol(symbol *sym, int isStructSym, int isFunc);
22 void cdbTypeInfo (sym_link * type);
25 DEBUGFILE cdbDebugFile =
37 FILE *cdbFilePtr = NULL;
38 char *cdbModuleName = NULL;
40 /******************************************************************
45 *****************************************************************/
47 int cdbOpenFile(char *file)
49 if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
50 fprintf (stderr, "cdbFile.c:cdbOpenFile(%s)\n", file);
52 return (cdbFilePtr = fopen(file, "w")) ? 1 : 0;
55 /******************************************************************
60 *****************************************************************/
61 int cdbCloseFile(void)
63 if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
64 fprintf (stderr, "cdbFile.c:cdbCloseFile()\n");
66 if(!cdbFilePtr) return 0;
75 /******************************************************************
80 *****************************************************************/
82 int cdbWriteFunction(symbol *pSym)
84 if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
85 fprintf (stderr, "cdbFile.c:cdbWriteFunction()\n");
88 if(!cdbFilePtr) return 0;
90 return cdbWriteBasicSymbol(pSym, FALSE, TRUE);
93 /******************************************************************
98 *****************************************************************/
100 int cdbWriteSymbol(symbol *pSym)
102 if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
103 fprintf (stderr, "cdbFile.c:cdbWriteSymbol()\n");
105 if(!cdbFilePtr) return 0;
107 return cdbWriteBasicSymbol(pSym, FALSE, FALSE);
110 /******************************************************************
115 *****************************************************************/
117 int cdbWriteType(structdef *sdef, int block, int inStruct, char *tag)
121 if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
122 fprintf (stderr, "cdbFile.c:cdbWriteType()\n");
124 if(!cdbFilePtr) return 0;
126 fprintf (cdbFilePtr, "T:");
128 /* if block # then must have function scope */
129 fprintf (cdbFilePtr, "F%s$", moduleName);
131 fprintf (cdbFilePtr, "%s[", (tag ? tag : sdef->tag));
133 for (sym = sdef->fields; sym; sym = sym->next)
135 fprintf (cdbFilePtr, "({%d}", sym->offset);
136 cdbWriteBasicSymbol(sym, TRUE, FALSE);
137 fprintf(cdbFilePtr, ")");
140 fprintf (cdbFilePtr, "]");
143 fprintf (cdbFilePtr, "\n");
148 /******************************************************************
153 *****************************************************************/
155 int cdbWriteModule(char *name)
157 if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
158 fprintf (stderr, "cdbFile.c:cdbWriteModule()\n");
160 if(!cdbFilePtr) return 0;
161 cdbModuleName = name;
163 fprintf(cdbFilePtr, "M:%s\n", cdbModuleName);
168 /******************************************************************
173 *****************************************************************/
174 int cdbWriteCLine(char *module, int Line, int Level, int Block)
176 if(!cdbFilePtr) return 0;
181 /******************************************************************
186 *****************************************************************/
188 int cdbWriteALine(char *module, int Line)
190 if(!cdbFilePtr) return 0;
195 /******************************************************************
200 *****************************************************************/
202 int cdbWriteBasicSymbol(symbol *sym, int isStructSym, int isFunc)
206 if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
207 fprintf (stderr, "cdbFile.c:cdbWriteBasicSymbol()\n");
209 if(!cdbFilePtr) return 0;
213 /* WRITE HEADER, Function or Symbol */
215 fprintf (cdbFilePtr, "F:");
217 fprintf (cdbFilePtr, "S:");
219 /* STRUCTS do not have scope info.. */
226 if (IS_STATIC (sym->etype))
227 fprintf (cdbFilePtr, "F%s$", moduleName); /* scope is file */
229 fprintf (cdbFilePtr, "G$"); /* scope is global */
232 /* symbol is local */
233 fprintf (cdbFilePtr, "L%s$", (sym->localof ? sym->localof->name : "-null-"));
236 fprintf (cdbFilePtr, "S$"); /* scope is structure */
238 /* print the name, & mangled name */
239 fprintf (cdbFilePtr, "%s$%d$%d(", sym->name,
240 sym->level, sym->block);
242 cdbTypeInfo (sym->type);
244 fprintf (cdbFilePtr, "),");
246 /* CHECK FOR REGISTER SYMBOL... */
250 symbol *TempSym = OP_SYMBOL (sym->reqv);
252 fprintf(cdbFilePtr, "R,0,0,[");
254 for(a = 0; a < 4; a++)
256 fprintf(cdbFilePtr, "%s%s", port->getRegName(TempSym->regs[a]),
257 ((a < 3) && (TempSym->regs[a+1])) ? "," : "");
259 fprintf(cdbFilePtr, "]");
263 /* print the address space */
264 map = SPEC_OCLS (sym->etype);
266 fprintf (cdbFilePtr, "%c,%d,%d",
267 (map ? map->dbName : 'Z'), sym->onStack, SPEC_STAK (sym->etype));
270 /* if assigned to registers then output register names */
271 /* if this is a function then print
272 if is it an interrupt routine & interrupt number
273 and the register bank it is using */
275 fprintf (cdbFilePtr, ",%d,%d,%d", FUNC_ISISR (sym->type),
276 FUNC_INTNO (sym->type), FUNC_REGBANK (sym->type));
279 /* alternate location to find this symbol @ : eg registers
283 fprintf (cdbFilePtr, "\n");
288 /******************************************************************
293 *****************************************************************/
295 /*-----------------------------------------------------------------*/
296 /* cdbTypeInfo - print the type information for debugger */
297 /*-----------------------------------------------------------------*/
298 void cdbTypeInfo (sym_link * type)
300 fprintf (cdbFilePtr, "{%d}", getSize (type));
306 switch (DCL_TYPE (type))
308 case FUNCTION: fprintf (cdbFilePtr, "DF,"); break;
309 case GPOINTER: fprintf (cdbFilePtr, "DG,"); break;
310 case CPOINTER: fprintf (cdbFilePtr, "DC,"); break;
311 case FPOINTER: fprintf (cdbFilePtr, "DX,"); break;
312 case POINTER: fprintf (cdbFilePtr, "DD,"); break;
313 case IPOINTER: fprintf (cdbFilePtr, "DI,"); break;
314 case PPOINTER: fprintf (cdbFilePtr, "DP,"); break;
315 case EEPPOINTER: fprintf (cdbFilePtr, "DA,"); break;
316 case ARRAY: fprintf (cdbFilePtr, "DA%d,", DCL_ELEM (type)); break;
323 switch (SPEC_NOUN (type))
327 fprintf (cdbFilePtr, "SL");
329 fprintf (cdbFilePtr, "SI");
332 case V_CHAR: fprintf (cdbFilePtr, "SC"); break;
333 case V_VOID: fprintf (cdbFilePtr, "SV"); break;
334 case V_FLOAT: fprintf (cdbFilePtr, "SF"); break;
336 fprintf (cdbFilePtr, "ST%s", SPEC_STRUCT (type)->tag);
339 case V_SBIT: fprintf (cdbFilePtr, "SX"); break;
341 fprintf (cdbFilePtr, "SB%d$%d", SPEC_BSTR (type),
348 fputs (":", cdbFilePtr);
349 if (SPEC_USIGN (type))
350 fputs ("U", cdbFilePtr);
352 fputs ("S", cdbFilePtr);