* doc/cdbfile.html: removed, replaced by cdbfileformat.lyx
authorbernhardheld <bernhardheld@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 23 Mar 2003 20:23:48 +0000 (20:23 +0000)
committerbernhardheld <bernhardheld@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 23 Mar 2003 20:23:48 +0000 (20:23 +0000)
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

19 files changed:
ChangeLog
src/Makefile.bcc
src/Makefile.in
src/SDCCast.c
src/SDCCdebug.c [new file with mode: 0644]
src/SDCCdebug.h [new file with mode: 0644]
src/SDCCglue.c
src/SDCCmain.c
src/SDCCmem.c
src/SDCCsymt.c
src/SDCCsymt.h
src/avr/gen.c
src/cdbFile.c [new file with mode: 0644]
src/common.h
src/ds390/gen.c
src/mcs51/gen.c
src/pic/gen.c
src/pic/glue.c
src/xa51/gen.c

index 3b7c1f2908ebb084b5ea5961804c85807b8c7137..dcdad14854098b18d44c166a5dbb517bd7e6f36a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,25 @@
 2003-03-23  Bernhard Held <bernhard@bernhardheld.de>
 
        * 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 <Frieder.Ferlemann@web.de>
 
index b97901fd4bcad3da72d33281e83d92a1715d3815..b4256b4e4d4ac4d1b48d97716f5181209ac5fd06 100644 (file)
@@ -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
 
index 12ff3f101ad18341823a0b6a321e0cde5e1c16df..67828f675ebaec0bbeaef6802cdfada7c49513dd 100644 (file)
@@ -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)
index eda105435db363953242a4018de200a03431387b..2c096d017dcc76bf836cbdd7bb3212cc8125e7fe 100644 (file)
@@ -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 (file)
index 0000000..ee9c211
--- /dev/null
@@ -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 (file)
index 0000000..cd4b5bf
--- /dev/null
@@ -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
index 1bd7060c5d674aee73594303c09f1c9df57cb9e7..5e1d084d98ccddca5d4fd5a8514aa787eaa36977 100644 (file)
@@ -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 */
 
index 308175e216eb28a4500b6d638e7e0b7e29ae43a6..b7132c0c2b9b2766f6b4e71d4a5f73d8d38e7a6d 100644 (file)
@@ -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 &&
index 40d422b12d38b430da755a18f82340f36930d57b..17a8859834d2ecc191d484da92da04eb583d0be0 100644 (file)
@@ -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);
-    }
 }
 
 /*-----------------------------------------------------------------*/
index 2c8926c20a591b1fd93fa66516bee5a0ae717b7c..2b7824644c61c79ece879999ea9da461ca92333b 100644 (file)
@@ -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 */
index 6511a8cab7043eb48c20178b623696d6a5ac5c39..cc96b76deba524bc9b948a1d37e9fe60343ffbfa 100644 (file)
@@ -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);
index 62329c5086a1f303d9cc3375205f852cfd50d8d6..6a0e9a9e6a4f7755b525a65777cfd77039fe873e 100644 (file)
@@ -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 (file)
index 0000000..d4a3452
--- /dev/null
@@ -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;
+    }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
index 8a8ad4fe1c418cfd21b79bad174ec9edff8121f5..d12867b26de3a16a8a4ca61f75d61899d9c1fd7e 100644 (file)
@@ -29,6 +29,7 @@
 #include "SDCCopt.h"
 #include "SDCCglue.h"
 #include "SDCCpeeph.h"
+#include "SDCCdebug.h"
 #include "SDCCutil.h"
 
 #include "asm.h"
index f7c49806e57bc5124f4bd6ba68f07ff8f50377c0..aba719c5b22627fee810ec1d9d4a0b8392bd16c5 100644 (file)
@@ -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);
index 8ca017531c986572fa111b5bcbf7bbd5d05702cc..5c7693f79505116e985aa7b5f67e03e909bf1ded 100644 (file)
@@ -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);
index 44f440f804fefd3343d2a1309caec93660e22577..ba4a10fc546dbaed67ef800a171c48da71902850 100644 (file)
@@ -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__);
index 76cf38149683fcdf955b3a8b395438498ab06856..3afb569211505d0744539b104ce2e0ef0484368f 100644 (file)
@@ -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 */
index 3313b880c03e75822f70ebb091911ecd00ae46ec..ecc91197ccd4368c688f9f6e3d0e5660aeca5e37 100755 (executable)
@@ -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);