From: bernhardheld Date: Sun, 23 Mar 2003 20:23:48 +0000 (+0000) Subject: * doc/cdbfile.html: removed, replaced by cdbfileformat.lyx X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=c7f4a6fa7318f4495c4c68870600eede23249868;p=fw%2Fsdcc * doc/cdbfile.html: removed, replaced by cdbfileformat.lyx Added Lenny Story's debug infrastructure changes: * src/Makefile.in: added new files cdbFile.c and SDCCdebug.c * src/Makefile.bcc: added new files cdbFile.c and SDCCdebug.c * src/cdbFile.c: added * src/SDCCdebug.c: added * src/SDCCdebug.h: added * src/SDCCast.c (createFunction) * src/SDCCglue.c (emitRegularMap, emitStaticSeg, emitOverlay, glue) * src/SDCCmain.c (parseCmdLine, main) * src/SDCCmem.c (redoStackOffsets) * src/SDCCsymt.c (cdbStructBlock, cdbTypeInfo, cdbSymbol, cdbStruct, cdbStructBlock) * src/SDCCsymt.h * src/common.h * src/avr/gen.c (genAVRCode) * src/ds390/gen.c (gen390Code) * src/mcs51/gen.c (gen51Code) * src/pic/gen.c (genpic14Code) * src/pic/glue.c (pic14emitRegularMap, pic14emitStaticSeg, pic14emitOverlay, picglue) * src/xa51/gen.c (genXA51Code) git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2412 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 3b7c1f29..dcdad148 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,25 @@ 2003-03-23 Bernhard Held * doc/cdbfile.html: removed, replaced by cdbfileformat.lyx + Added Lenny Story's debug infrastructure changes: + * src/Makefile.in: added new files cdbFile.c and SDCCdebug.c + * src/Makefile.bcc: added new files cdbFile.c and SDCCdebug.c + * src/cdbFile.c: added + * src/SDCCdebug.c: added + * src/SDCCdebug.h: added + * src/SDCCast.c (createFunction) + * src/SDCCglue.c (emitRegularMap, emitStaticSeg, emitOverlay, glue) + * src/SDCCmain.c (parseCmdLine, main) + * src/SDCCmem.c (redoStackOffsets) + * src/SDCCsymt.c (cdbStructBlock, cdbTypeInfo, cdbSymbol, cdbStruct, cdbStructBlock) + * src/SDCCsymt.h + * src/common.h + * src/avr/gen.c (genAVRCode) + * src/ds390/gen.c (gen390Code) + * src/mcs51/gen.c (gen51Code) + * src/pic/gen.c (genpic14Code) + * src/pic/glue.c (pic14emitRegularMap, pic14emitStaticSeg, pic14emitOverlay, picglue) + * src/xa51/gen.c (genXA51Code) 2003-03-22 Frieder Ferlemann diff --git a/src/Makefile.bcc b/src/Makefile.bcc index b97901fd..b4256b4e 100644 --- a/src/Makefile.bcc +++ b/src/Makefile.bcc @@ -13,7 +13,7 @@ OBJECTS = SDCCy.obj SDCClex.obj SDCChasht.obj SDCCmain.obj \ SDCCicode.obj SDCCbitv.obj SDCCset.obj SDCClabel.obj \ SDCCBBlock.obj SDCCloop.obj SDCCcse.obj SDCCcflow.obj SDCCdflow.obj \ SDCClrange.obj SDCCptropt.obj SDCCpeeph.obj SDCCglue.obj \ - asm.obj SDCCutil.obj SDCCmacro.obj + asm.obj SDCCutil.obj SDCCmacro.obj SDCCdebug.obj cdbFile.obj SLIBOBJS = $(SLIB)/SDCCerr.obj $(SLIB)/NewAlloc.obj $(SLIB)/MySystem.obj $(SLIB)/BuildCmd.obj diff --git a/src/Makefile.in b/src/Makefile.in index 12ff3f10..67828f67 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -27,7 +27,7 @@ OBJECTS = SDCCy.o SDCChasht.o SDCCmain.o \ SDCCicode.o SDCCbitv.o SDCCset.o SDCClabel.o \ SDCCBBlock.o SDCCloop.o SDCCcse.o SDCCcflow.o SDCCdflow.o \ SDCClrange.o SDCCptropt.o SDCCpeeph.o SDCCglue.o \ - asm.o SDCCmacro.o SDCCutil.o + asm.o SDCCmacro.o SDCCutil.o SDCCdebug.o cdbFile.o SPECIAL = SDCCy.h ifeq ($(USE_ALT_LEX), 1) diff --git a/src/SDCCast.c b/src/SDCCast.c index eda10543..2c096d01 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -1211,14 +1211,14 @@ processBlockVars (ast * tree, int *stack, int action) ast *autoInit; if (action == ALLOCATE) - { + { *stack += allocVariables (tree->values.sym); autoInit = gatherAutoInit (tree->values.sym); - + /* if there are auto inits then do them */ if (autoInit) tree->left = newNode (NULLOP, autoInit, tree->left); - } + } else /* action is deallocate */ deallocLocal (tree->values.sym); } @@ -3545,7 +3545,7 @@ createBlock (symbol * decl, ast * body) ex = newNode (BLOCK, NULL, body); ex->values.sym = decl; - + ex->right = ex->right; ex->level++; ex->lineno = 0; @@ -4397,6 +4397,7 @@ skipall: /* dealloc the block variables */ processBlockVars (body, &stack, DEALLOCATE); + outputDebugStackSymbols(); /* deallocate paramaters */ deallocParms (FUNC_ARGS(name->type)); @@ -4411,8 +4412,8 @@ skipall: addSet (&operKeyReset, name); applyToSet (operKeyReset, resetParmKey); - if (options.debug) - cdbStructBlock (1, cdbFile); + if (options.debug) + cdbStructBlock(1); cleanUpLevel (LabelTab, 0); cleanUpBlock (StructTab, 1); diff --git a/src/SDCCdebug.c b/src/SDCCdebug.c new file mode 100644 index 00000000..ee9c2115 --- /dev/null +++ b/src/SDCCdebug.c @@ -0,0 +1,128 @@ + +#include "common.h" + +extern DEBUGFILE cdbDebugFile; + +DEBUGFILE *debugFile = &cdbDebugFile; + +void outputDebugStackSymbols(void) +{ + if(getenv("SDCC_DEBUG_VAR_STORAGE")) + { + dumpSymInfo("XStack", xstack); + dumpSymInfo("IStack", istack); + } + + if(options.debug && debugFile) + { + symbol *sym; + + for (sym = setFirstItem (xstack->syms); sym; sym = setNextItem (xstack->syms)) + debugFile->writeSymbol(sym); + + for (sym = setFirstItem (istack->syms); sym; sym = setNextItem (istack->syms)) + debugFile->writeSymbol(sym); + } + +} + + +void outputDebugSymbols(void) +{ + if(getenv("SDCC_DEBUG_VAR_STORAGE")) + { + dumpSymInfo("Code", code); + dumpSymInfo("Data", data); + dumpSymInfo("XData", xdata); + dumpSymInfo("XIData", xidata); + dumpSymInfo("XInit", xinit); + dumpSymInfo("IData", idata); + dumpSymInfo("Bit", bit); + dumpSymInfo("Statics", statsg); + dumpSymInfo("SFR", sfr); + dumpSymInfo("SFRBits", sfrbit); + dumpSymInfo("Reg", reg); + dumpSymInfo("Generic", generic); + dumpSymInfo("Overlay", overlay); + dumpSymInfo("EEProm", eeprom); + dumpSymInfo("Home", home); + } + + if(options.debug && debugFile) + { + symbol *sym; + + for (sym = setFirstItem (data->syms); sym; sym = setNextItem (data->syms)) + debugFile->writeSymbol(sym); + + for (sym = setFirstItem (idata->syms); sym; sym = setNextItem (idata->syms)) + debugFile->writeSymbol(sym); + + for (sym = setFirstItem (bit->syms); sym; sym = setNextItem (bit->syms)) + debugFile->writeSymbol(sym); + + for (sym = setFirstItem (xdata->syms); sym; sym = setNextItem (xdata->syms)) + debugFile->writeSymbol(sym); + + if(port->genXINIT) { + for (sym = setFirstItem (xidata->syms); sym; sym = setNextItem (xidata->syms)) + debugFile->writeSymbol(sym); + } + + for (sym = setFirstItem (sfr->syms); sym; sym = setNextItem (sfr->syms)) + debugFile->writeSymbol(sym); + + for (sym = setFirstItem (sfrbit->syms); sym; sym = setNextItem (sfrbit->syms)) + debugFile->writeSymbol(sym); + + for (sym = setFirstItem (home->syms); sym; sym = setNextItem (home->syms)) + debugFile->writeSymbol(sym); + + for (sym = setFirstItem (code->syms); sym; sym = setNextItem (code->syms)) + debugFile->writeSymbol(sym); + + for (sym = setFirstItem (statsg->syms); sym; sym = setNextItem (statsg->syms)) + debugFile->writeSymbol(sym); + + if(port->genXINIT) { + for (sym = setFirstItem (xinit->syms); sym; sym = setNextItem (xinit->syms)) + debugFile->writeSymbol(sym); + } + } + + return; +} + + +void dumpSymInfo(char *pcName, memmap *memItem) +{ + symbol *sym; + + printf("--------------------------------------------\n"); + printf(" %s\n", pcName); + + for(sym = setFirstItem(memItem->syms); + sym; sym = setNextItem(memItem->syms)) + { + printf(" %s, isReqv:%d, reqv:0x%p, onStack:%d, Stack:%d, nRegs:%d, [", + sym->rname, sym->isreqv, sym->reqv, sym->onStack, sym->stack, sym->nRegs); + + if(sym->reqv) + { + int i; + symbol *TempSym = OP_SYMBOL (sym->reqv); + + for (i = 0; i < 4; i++) + if(TempSym->regs[i]) + printf("%s,", port->getRegName(TempSym->regs[i])); + } + + printf("]\n"); + } + + printf("\n"); +} + + + + diff --git a/src/SDCCdebug.h b/src/SDCCdebug.h new file mode 100644 index 00000000..cd4b5bf9 --- /dev/null +++ b/src/SDCCdebug.h @@ -0,0 +1,24 @@ + +#ifndef _DEBUG_INCLUDE_ +#define _DEBUG_INCLUDE_ + +typedef struct DebugFile +{ + int (*openFile)(char *file); + int (*closeFile)(void); + int (*writeModule)(char *name); + int (*writeFunction)(symbol *pSym); + int (*writeSymbol)(symbol *pSym); + int (*writeType)(structdef *sdef, int block, int inStruct, char *tag); + int (*writeCLine)(char *module, int Line, int Level, int Block); + int (*writeALine)(char *module, int Line); + +}DEBUGFILE; + +extern DEBUGFILE *debugFile; + +void outputDebugStackSymbols(void); +void outputDebugSymbols(void); +void dumpSymInfo(char *pcName, memmap *memItem); + +#endif diff --git a/src/SDCCglue.c b/src/SDCCglue.c index 1bd7060c..5e1d084d 100644 --- a/src/SDCCglue.c +++ b/src/SDCCglue.c @@ -263,18 +263,22 @@ emitRegularMap (memmap * map, bool addPublics, bool arFlag) continue; /* print extra debug info if required */ - if (options.debug) { - cdbSymbol (sym, cdbFile, FALSE, FALSE); - if (!sym->level) /* global */ - if (IS_STATIC (sym->etype)) - fprintf (map->oFile, "F%s$", moduleName); /* scope is file */ + if (options.debug) + { + if (!sym->level) /* global */ + { + if (IS_STATIC (sym->etype)) + fprintf (map->oFile, "F%s$", moduleName); /* scope is file */ + else + fprintf (map->oFile, "G$"); /* scope is global */ + } else - fprintf (map->oFile, "G$"); /* scope is global */ - else - /* symbol is local */ - fprintf (map->oFile, "L%s$", (sym->localof ? sym->localof->name : "-null-")); - fprintf (map->oFile, "%s$%d$%d", sym->name, sym->level, sym->block); - } + { + /* symbol is local */ + fprintf (map->oFile, "L%s$", (sym->localof ? sym->localof->name : "-null-")); + } + fprintf (map->oFile, "%s$%d$%d", sym->name, sym->level, sym->block); + } /* if it has an initial value then do it only if it is a global variable */ @@ -1150,7 +1154,7 @@ emitStaticSeg (memmap * map, FILE * out) /* print extra debug info if required */ if (options.debug) { - cdbSymbol (sym, cdbFile, FALSE, FALSE); + if (!sym->level) { /* global */ if (IS_STATIC (sym->etype)) @@ -1420,8 +1424,6 @@ emitOverlay (FILE * afile) /* print extra debug info if required */ if (options.debug) { - cdbSymbol (sym, cdbFile, FALSE, FALSE); - if (!sym->level) { /* global */ if (IS_STATIC (sym->etype)) @@ -1479,7 +1481,7 @@ glue (void) addSetHead (&tmpfileSet, ovrFile); /* print the global struct definitions */ if (options.debug) - cdbStructBlock (0, cdbFile); + cdbStructBlock (0); vFile = tempfile (); /* PENDING: this isnt the best place but it will do */ @@ -1496,6 +1498,8 @@ glue (void) /* do the overlay segments */ emitOverlay (ovrFile); + outputDebugSymbols(); + /* now put it all together into the assembler file */ /* create the assembler file name */ diff --git a/src/SDCCmain.c b/src/SDCCmain.c index 308175e2..b7132c0c 100644 --- a/src/SDCCmain.c +++ b/src/SDCCmain.c @@ -31,6 +31,7 @@ #include "MySystem.h" #include "SDCCmacro.h" #include "SDCCutil.h" +#include "SDCCdebug.h" #include "SDCCargs.h" #if NATIVE_WIN32 @@ -49,7 +50,6 @@ extern int yyparse (); FILE *srcFile; /* source file */ -FILE *cdbFile = NULL; /* debugger information output file */ char *fullSrcFileName; /* full name for the source file; */ /* can be NULL while c1mode or linking without compiling */ char *fullDstFileName; /* full name for the output file; */ @@ -1115,6 +1115,7 @@ parseCmdLine (int argc, char **argv) addToList (preArgv, "-C"); break; } + case 'd': case 'D': case 'I': @@ -1244,18 +1245,15 @@ parseCmdLine (int argc, char **argv) if (!options.xstack_loc) options.xstack_loc = options.xdata_loc; - /* if debug option is set the open the cdbFile */ + /* if debug option is set then open the cdbFile */ if (options.debug && fullSrcFileName) { SNPRINTF (scratchFileName, sizeof(scratchFileName), "%s.adb", dstFileName); //JCF: Nov 30, 2002 - if ((cdbFile = fopen (scratchFileName, "w")) == NULL) - werror (E_FILE_OPEN_ERR, scratchFileName); + if(debugFile->openFile(scratchFileName)) + debugFile->writeModule(moduleName); else - { - /* add a module record */ - fprintf (cdbFile, "M:%s\n", moduleName); - } + werror (E_FILE_OPEN_ERR, scratchFileName); } return 0; } @@ -1955,8 +1953,8 @@ main (int argc, char **argv, char **envp) } closeDumpFiles(); - if (cdbFile) - fclose (cdbFile); + if (options.debug && debugFile) + debugFile->closeFile(); if (!options.cc_only && !fatalError && diff --git a/src/SDCCmem.c b/src/SDCCmem.c index 40d422b1..17a88598 100644 --- a/src/SDCCmem.c +++ b/src/SDCCmem.c @@ -709,11 +709,11 @@ allocLocal (symbol * sym) will remove and put into the 'data' segment if required after overlay analysis has been done */ if (options.model == MODEL_SMALL) { - SPEC_OCLS (sym->etype) = - (options.noOverlay ? port->mem.default_local_map - : overlay); + SPEC_OCLS (sym->etype) = + (options.noOverlay ? port->mem.default_local_map + : overlay); } else { - SPEC_OCLS (sym->etype) = port->mem.default_local_map; + SPEC_OCLS (sym->etype) = port->mem.default_local_map; } allocIntoSeg (sym); } @@ -960,18 +960,6 @@ redoStackOffsets (void) xsPtr += size; } - /* if the debug option is set then output the - symbols to the map file */ - if (options.debug) - { - for (sym = setFirstItem (istack->syms); sym; - sym = setNextItem (istack->syms)) - cdbSymbol (sym, cdbFile, FALSE, FALSE); - - for (sym = setFirstItem (xstack->syms); sym; - sym = setNextItem (xstack->syms)) - cdbSymbol (sym, cdbFile, FALSE, FALSE); - } } /*-----------------------------------------------------------------*/ diff --git a/src/SDCCsymt.c b/src/SDCCsymt.c index 2c8926c2..2b782464 100644 --- a/src/SDCCsymt.c +++ b/src/SDCCsymt.c @@ -1770,6 +1770,29 @@ checkFunction (symbol * sym, symbol *csym) return 1; } +/*------------------------------------------------------------------*/ +/* cdbStructBlock - calls struct printing for a blcks */ +/*------------------------------------------------------------------*/ +void cdbStructBlock (int block) +{ + int i; + bucket **table = StructTab; + bucket *chain; + + /* go thru the entire table */ + for (i = 0; i < 256; i++) + { + for (chain = table[i]; chain; chain = chain->next) + { + if (chain->block >= block) + { + if(debugFile) + debugFile->writeType((structdef *)chain->sym, chain->block, 0, NULL); + } + } + } +} + /*-----------------------------------------------------------------*/ /* processFuncArgs - does some processing with function args */ /*-----------------------------------------------------------------*/ @@ -2080,206 +2103,6 @@ printTypeChain (sym_link * start, FILE * of) fprintf (of, "\n"); } -/*-----------------------------------------------------------------*/ -/* cdbTypeInfo - print the type information for debugger */ -/*-----------------------------------------------------------------*/ -void -cdbTypeInfo (sym_link * type, FILE * of) -{ - fprintf (of, "{%d}", getSize (type)); - while (type) - { - if (IS_DECL (type)) - { - switch (DCL_TYPE (type)) - { - case FUNCTION: - fprintf (of, "DF,"); - break; - case GPOINTER: - fprintf (of, "DG,"); - break; - case CPOINTER: - fprintf (of, "DC,"); - break; - case FPOINTER: - fprintf (of, "DX,"); - break; - case POINTER: - fprintf (of, "DD,"); - break; - case IPOINTER: - fprintf (of, "DI,"); - break; - case PPOINTER: - fprintf (of, "DP,"); - break; - case EEPPOINTER: - fprintf (of, "DA,"); - break; - case ARRAY: - fprintf (of, "DA%d,", DCL_ELEM (type)); - break; - default: - break; - } - } - else - { - switch (SPEC_NOUN (type)) - { - case V_INT: - if (IS_LONG (type)) - fprintf (of, "SL"); - else - fprintf (of, "SI"); - break; - - case V_CHAR: - fprintf (of, "SC"); - break; - - case V_VOID: - fprintf (of, "SV"); - break; - - case V_FLOAT: - fprintf (of, "SF"); - break; - - case V_STRUCT: - fprintf (of, "ST%s", SPEC_STRUCT (type)->tag); - break; - - case V_SBIT: - fprintf (of, "SX"); - break; - - case V_BIT: - fprintf (of, "SB%d$%d", SPEC_BSTR (type), SPEC_BLEN (type)); - break; - - default: - break; - } - fputs (":", of); - if (SPEC_USIGN (type)) - fputs ("U", of); - else - fputs ("S", of); - } - type = type->next; - } -} -/*-----------------------------------------------------------------*/ -/* cdbSymbol - prints a symbol & its type information for debugger */ -/*-----------------------------------------------------------------*/ -void -cdbSymbol (symbol * sym, FILE * of, int isStructSym, int isFunc) -{ - memmap *map; - - if (!sym) - return; - if (!of) - of = stdout; - - if (isFunc) - fprintf (of, "F:"); - else - fprintf (of, "S:"); /* symbol record */ - /* if this is not a structure symbol then - we need to figure out the scope information */ - if (!isStructSym) - { - if (!sym->level) - { - /* global */ - if (IS_STATIC (sym->etype)) - fprintf (of, "F%s$", moduleName); /* scope is file */ - else - fprintf (of, "G$"); /* scope is global */ - } - else - /* symbol is local */ - fprintf (of, "L%s$", (sym->localof ? sym->localof->name : "-null-")); - } - else - fprintf (of, "S$"); /* scope is structure */ - - /* print the name, & mangled name */ - fprintf (of, "%s$%d$%d(", sym->name, - sym->level, sym->block); - - cdbTypeInfo (sym->type, of); - fprintf (of, "),"); - - /* print the address space */ - map = SPEC_OCLS (sym->etype); - fprintf (of, "%c,%d,%d", - (map ? map->dbName : 'Z'), sym->onStack, SPEC_STAK (sym->etype)); - - /* if assigned to registers then output register names */ - /* if this is a function then print - if is it an interrupt routine & interrupt number - and the register bank it is using */ - if (isFunc) - fprintf (of, ",%d,%d,%d", FUNC_ISISR (sym->type), - FUNC_INTNO (sym->type), FUNC_REGBANK (sym->type)); - /* alternate location to find this symbol @ : eg registers - or spillication */ - - if (!isStructSym) - fprintf (of, "\n"); -} - -/*-----------------------------------------------------------------*/ -/* cdbStruct - print a structure for debugger */ -/*-----------------------------------------------------------------*/ -void -cdbStruct (structdef * sdef, int block, FILE * of, - int inStruct, char *tag) -{ - symbol *sym; - - fprintf (of, "T:"); - /* if block # then must have function scope */ - fprintf (of, "F%s$", moduleName); - fprintf (of, "%s[", (tag ? tag : sdef->tag)); - for (sym = sdef->fields; sym; sym = sym->next) - { - fprintf (of, "({%d}", sym->offset); - cdbSymbol (sym, of, TRUE, FALSE); - fprintf (of, ")"); - } - fprintf (of, "]"); - if (!inStruct) - fprintf (of, "\n"); -} - -/*------------------------------------------------------------------*/ -/* cdbStructBlock - calls struct printing for a blcks */ -/*------------------------------------------------------------------*/ -void -cdbStructBlock (int block, FILE * of) -{ - int i; - bucket **table = StructTab; - bucket *chain; - wassert (of); - - /* go thru the entire table */ - for (i = 0; i < 256; i++) - { - for (chain = table[i]; chain; chain = chain->next) - { - if (chain->block >= block) - { - cdbStruct ((structdef *) chain->sym, chain->block, of, 0, NULL); - } - } - } -} /*-----------------------------------------------------------------*/ /* powof2 - returns power of two for the number if number is pow 2 */ diff --git a/src/SDCCsymt.h b/src/SDCCsymt.h index 6511a8ca..cc96b76d 100644 --- a/src/SDCCsymt.h +++ b/src/SDCCsymt.h @@ -535,9 +535,7 @@ void printTypeChain (sym_link *, FILE *); void initCSupport (); void initBuiltIns (); void pointerTypes (sym_link *, sym_link *); -void cdbTypeInfo (sym_link *, FILE *); -void cdbSymbol (symbol *, FILE *, int, int); -void cdbStructBlock (int, FILE *); +void cdbStructBlock (int); void initHashT (); bucket *newBucket (); void addSym (bucket **, void *, char *, int, int, int checkType); diff --git a/src/avr/gen.c b/src/avr/gen.c index 62329c50..6a0e9a9e 100644 --- a/src/avr/gen.c +++ b/src/avr/gen.c @@ -5103,7 +5103,7 @@ genAVRCode (iCode * lic) /* if debug information required */ /* if (options.debug && currFunc) { */ if (currFunc) { - cdbSymbol (currFunc, cdbFile, FALSE, TRUE); + debugFile->writeFunction(currFunc); _G.debugLine = 1; /* emitcode ("", ".type %s,@function", currFunc->name); */ _G.debugLine = 0; diff --git a/src/cdbFile.c b/src/cdbFile.c new file mode 100644 index 00000000..d4a34520 --- /dev/null +++ b/src/cdbFile.c @@ -0,0 +1,375 @@ + + +#include "common.h" + + +/************************************************************* + * + * + * + * + *************************************************************/ + +int cdbOpenFile(char *file); +int cdbCloseFile(void); +int cdbWriteFunction(symbol *pSym); +int cdbWriteSymbol(symbol *pSym); +int cdbWriteType(structdef *sdef, int block, int inStruct, char *tag); +int cdbWriteModule(char *name); +int cdbWriteCLine(char *module, int Line, int Level, int Block); +int cdbWriteALine(char *module, int Line); +int cdbWriteBasicSymbol(symbol *sym, int isStructSym, int isFunc); +void cdbTypeInfo (sym_link * type); + + +DEBUGFILE cdbDebugFile = + { + &cdbOpenFile, + &cdbCloseFile, + &cdbWriteModule, + &cdbWriteFunction, + &cdbWriteSymbol, + &cdbWriteType, + &cdbWriteCLine, + &cdbWriteALine + }; + +FILE *cdbFilePtr = NULL; +char *cdbModuleName = NULL; + +/****************************************************************** + * + * + * + * + *****************************************************************/ + +int cdbOpenFile(char *file) +{ + if (getenv("SDCC_DEBUG_FUNCTION_POINTERS")) + fprintf (stderr, "cdbFile.c:cdbOpenFile(%s)\n", file); + + return (cdbFilePtr = fopen(file, "w")) ? 1 : 0; +} + +/****************************************************************** + * + * + * + * + *****************************************************************/ +int cdbCloseFile(void) +{ + if (getenv("SDCC_DEBUG_FUNCTION_POINTERS")) + fprintf (stderr, "cdbFile.c:cdbCloseFile()\n"); + + if(!cdbFilePtr) return 0; + + fclose(cdbFilePtr); + cdbFilePtr = NULL; + cdbModuleName = NULL; + + return 1; +} + +/****************************************************************** + * + * + * + * + *****************************************************************/ + +int cdbWriteFunction(symbol *pSym) +{ + if (getenv("SDCC_DEBUG_FUNCTION_POINTERS")) + fprintf (stderr, "cdbFile.c:cdbWriteFunction()\n"); + + + if(!cdbFilePtr) return 0; + + return cdbWriteBasicSymbol(pSym, FALSE, TRUE); +} + +/****************************************************************** + * + * + * + * + *****************************************************************/ + +int cdbWriteSymbol(symbol *pSym) +{ + if (getenv("SDCC_DEBUG_FUNCTION_POINTERS")) + fprintf (stderr, "cdbFile.c:cdbWriteSymbol()\n"); + + if(!cdbFilePtr) return 0; + + return cdbWriteBasicSymbol(pSym, FALSE, FALSE); +} + +/****************************************************************** + * + * + * + * + *****************************************************************/ + +int cdbWriteType(structdef *sdef, int block, int inStruct, char *tag) +{ + symbol *sym; + + if (getenv("SDCC_DEBUG_FUNCTION_POINTERS")) + fprintf (stderr, "cdbFile.c:cdbWriteType()\n"); + + if(!cdbFilePtr) return 0; + + fprintf (cdbFilePtr, "T:"); + + /* if block # then must have function scope */ + fprintf (cdbFilePtr, "F%s$", moduleName); + + fprintf (cdbFilePtr, "%s[", (tag ? tag : sdef->tag)); + + for (sym = sdef->fields; sym; sym = sym->next) + { + fprintf (cdbFilePtr, "({%d}", sym->offset); + cdbWriteBasicSymbol(sym, TRUE, FALSE); + fprintf(cdbFilePtr, ")"); + } + + fprintf (cdbFilePtr, "]"); + + if (!inStruct) + fprintf (cdbFilePtr, "\n"); + + return 1; +} + +/****************************************************************** + * + * + * + * + *****************************************************************/ + +int cdbWriteModule(char *name) +{ + if (getenv("SDCC_DEBUG_FUNCTION_POINTERS")) + fprintf (stderr, "cdbFile.c:cdbWriteModule()\n"); + + if(!cdbFilePtr) return 0; + cdbModuleName = name; + + fprintf(cdbFilePtr, "M:%s\n", cdbModuleName); + + return 1; +} + +/****************************************************************** + * + * + * + * + *****************************************************************/ +int cdbWriteCLine(char *module, int Line, int Level, int Block) +{ + if(!cdbFilePtr) return 0; + + return 1; +} + +/****************************************************************** + * + * + * + * + *****************************************************************/ + +int cdbWriteALine(char *module, int Line) +{ + if(!cdbFilePtr) return 0; + + return 1; +} + +/****************************************************************** + * + * + * + * + *****************************************************************/ + +int cdbWriteBasicSymbol(symbol *sym, int isStructSym, int isFunc) +{ + memmap *map; + + if (getenv("SDCC_DEBUG_FUNCTION_POINTERS")) + fprintf (stderr, "cdbFile.c:cdbWriteBasicSymbol()\n"); + + if(!cdbFilePtr) return 0; + + if (!sym) return 0; + + /* WRITE HEADER, Function or Symbol */ + if (isFunc) + fprintf (cdbFilePtr, "F:"); + else + fprintf (cdbFilePtr, "S:"); + + /* STRUCTS do not have scope info.. */ + + if (!isStructSym) + { + if (!sym->level) + { + /* global */ + if (IS_STATIC (sym->etype)) + fprintf (cdbFilePtr, "F%s$", moduleName); /* scope is file */ + else + fprintf (cdbFilePtr, "G$"); /* scope is global */ + } + else + /* symbol is local */ + fprintf (cdbFilePtr, "L%s$", (sym->localof ? sym->localof->name : "-null-")); + } + else + fprintf (cdbFilePtr, "S$"); /* scope is structure */ + + /* print the name, & mangled name */ + fprintf (cdbFilePtr, "%s$%d$%d(", sym->name, + sym->level, sym->block); + + cdbTypeInfo (sym->type); + + fprintf (cdbFilePtr, "),"); + + /* CHECK FOR REGISTER SYMBOL... */ + if(sym->reqv) + { + int a; + symbol *TempSym = OP_SYMBOL (sym->reqv); + + fprintf(cdbFilePtr, "R,0,0,["); + + for(a = 0; a < 4; a++) + if(TempSym->regs[a]) + fprintf(cdbFilePtr, "%s%s", port->getRegName(TempSym->regs[a]), + ((a < 3) && (TempSym->regs[a+1])) ? "," : ""); + + fprintf(cdbFilePtr, "]"); + } + else + { + /* print the address space */ + map = SPEC_OCLS (sym->etype); + + fprintf (cdbFilePtr, "%c,%d,%d", + (map ? map->dbName : 'Z'), sym->onStack, SPEC_STAK (sym->etype)); + } + + /* if assigned to registers then output register names */ + /* if this is a function then print + if is it an interrupt routine & interrupt number + and the register bank it is using */ + if (isFunc) + fprintf (cdbFilePtr, ",%d,%d,%d", FUNC_ISISR (sym->type), + FUNC_INTNO (sym->type), FUNC_REGBANK (sym->type)); + + +/* alternate location to find this symbol @ : eg registers + or spillication */ + + if (!isStructSym) + fprintf (cdbFilePtr, "\n"); + + return 1; +} + +/****************************************************************** + * + * + * + * + *****************************************************************/ + +/*-----------------------------------------------------------------*/ +/* cdbTypeInfo - print the type information for debugger */ +/*-----------------------------------------------------------------*/ +void cdbTypeInfo (sym_link * type) +{ + fprintf (cdbFilePtr, "{%d}", getSize (type)); + + while (type) + { + if (IS_DECL (type)) + { + switch (DCL_TYPE (type)) + { + case FUNCTION: fprintf (cdbFilePtr, "DF,"); break; + case GPOINTER: fprintf (cdbFilePtr, "DG,"); break; + case CPOINTER: fprintf (cdbFilePtr, "DC,"); break; + case FPOINTER: fprintf (cdbFilePtr, "DX,"); break; + case POINTER: fprintf (cdbFilePtr, "DD,"); break; + case IPOINTER: fprintf (cdbFilePtr, "DI,"); break; + case PPOINTER: fprintf (cdbFilePtr, "DP,"); break; + case EEPPOINTER: fprintf (cdbFilePtr, "DA,"); break; + case ARRAY: fprintf (cdbFilePtr, "DA%d,", DCL_ELEM (type)); break; + default: + break; + } + } + else + { + switch (SPEC_NOUN (type)) + { + case V_INT: + if (IS_LONG (type)) + fprintf (cdbFilePtr, "SL"); + else + fprintf (cdbFilePtr, "SI"); + break; + + case V_CHAR: fprintf (cdbFilePtr, "SC"); break; + case V_VOID: fprintf (cdbFilePtr, "SV"); break; + case V_FLOAT: fprintf (cdbFilePtr, "SF"); break; + case V_STRUCT: + fprintf (cdbFilePtr, "ST%s", SPEC_STRUCT (type)->tag); + break; + + case V_SBIT: fprintf (cdbFilePtr, "SX"); break; + case V_BIT: + fprintf (cdbFilePtr, "SB%d$%d", SPEC_BSTR (type), + SPEC_BLEN (type)); + break; + + default: + break; + } + fputs (":", cdbFilePtr); + if (SPEC_USIGN (type)) + fputs ("U", cdbFilePtr); + else + fputs ("S", cdbFilePtr); + } + type = type->next; + } +} + + + + + + + + + + + + + + + + + + + diff --git a/src/common.h b/src/common.h index 8a8ad4fe..d12867b2 100644 --- a/src/common.h +++ b/src/common.h @@ -29,6 +29,7 @@ #include "SDCCopt.h" #include "SDCCglue.h" #include "SDCCpeeph.h" +#include "SDCCdebug.h" #include "SDCCutil.h" #include "asm.h" diff --git a/src/ds390/gen.c b/src/ds390/gen.c index f7c49806..aba719c5 100644 --- a/src/ds390/gen.c +++ b/src/ds390/gen.c @@ -12700,7 +12700,7 @@ gen390Code (iCode * lic) /* if debug information required */ if (options.debug && currFunc) { - cdbSymbol (currFunc, cdbFile, FALSE, TRUE); + debugFile->writeFunction(currFunc); _G.debugLine = 1; if (IS_STATIC (currFunc->etype)) emitcode ("", "F%s$%s$0$0 ==.", moduleName, currFunc->name); diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index 8ca01753..5c7693f7 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -8881,7 +8881,7 @@ gen51Code (iCode * lic) /* if debug information required */ if (options.debug && currFunc) { - cdbSymbol (currFunc, cdbFile, FALSE, TRUE); + debugFile->writeFunction(currFunc); _G.debugLine = 1; if (IS_STATIC (currFunc->etype)) emitcode ("", "F%s$%s$0$0 ==.", moduleName, currFunc->name); diff --git a/src/pic/gen.c b/src/pic/gen.c index 44f440f8..ba4a10fc 100644 --- a/src/pic/gen.c +++ b/src/pic/gen.c @@ -9907,7 +9907,7 @@ void genpic14Code (iCode *lic) /* if debug information required */ if (options.debug && currFunc) { if (currFunc) { - cdbSymbol(currFunc,cdbFile,FALSE,TRUE); + debugFile->writeFunction(currFunc); _G.debugLine = 1; if (IS_STATIC(currFunc->etype)) { pic14_emitcode("",";F%s$%s$0$0 %d",moduleName,currFunc->name,__LINE__); diff --git a/src/pic/glue.c b/src/pic/glue.c index 76cf3814..3afb5692 100644 --- a/src/pic/glue.c +++ b/src/pic/glue.c @@ -140,9 +140,6 @@ pic14emitRegularMap (memmap * map, bool addPublics, bool arFlag) /* print extra debug info if required */ if (options.debug || sym->level == 0) { - - cdbSymbol (sym, cdbFile, FALSE, FALSE); - if (!sym->level) /* global */ if (IS_STATIC (sym->etype)) fprintf (map->oFile, "F%s_", moduleName); /* scope is file */ @@ -447,11 +444,6 @@ pic14emitStaticSeg (memmap * map) /* print extra debug info if required */ if (options.debug || sym->level == 0) { - /* NOTE to me - cdbFile may be null in which case, - * the sym name will be printed to stdout. oh well */ - if(cdbFile) - cdbSymbol (sym, cdbFile, FALSE, FALSE); - if (!sym->level) { /* global */ if (IS_STATIC (sym->etype)) @@ -680,9 +672,6 @@ pic14emitOverlay (FILE * afile) /* print extra debug info if required */ if (options.debug || sym->level == 0) { - - cdbSymbol (sym, cdbFile, FALSE, FALSE); - if (!sym->level) { /* global */ if (IS_STATIC (sym->etype)) @@ -774,7 +763,7 @@ picglue () /* print the global struct definitions */ if (options.debug) - cdbStructBlock (0,cdbFile); + cdbStructBlock (0); vFile = tempfile(); /* PENDING: this isnt the best place but it will do */ diff --git a/src/xa51/gen.c b/src/xa51/gen.c index 3313b880..ecc91197 100755 --- a/src/xa51/gen.c +++ b/src/xa51/gen.c @@ -1901,7 +1901,7 @@ void genXA51Code (iCode * lic) { /* if debug information required */ if (options.debug && currFunc) { - cdbSymbol (currFunc, cdbFile, FALSE, TRUE); + debugFile->writeFunction(currFunc); _G.debugLine = 1; if (IS_STATIC (currFunc->etype)) emitcode ("", "F%s$%s$0$0 ==.", moduleName, currFunc->name);