add -mz80 support
[fw/sdcc] / debugger / mcs51 / sdcdb.c
index 020814529a1f0eac5c8110ee514e4a4f96faa5b8..c40e3d8c8e45287e4ff06d93cac4a36bdd6857b8 100644 (file)
@@ -26,6 +26,7 @@
 #include "simi.h"
 #include "break.h"
 #include "cmd.h"
+#include "newalloc.h"
 
 char *currModName = NULL;
 cdbrecs *recsRoot = NULL ;
@@ -39,8 +40,9 @@ linkrec **linkrecs = NULL; /* all linkage editor records */
 context *currCtxt = NULL;
 short fullname = 0;
 char *ssdirl = SDCC_LIB_DIR ":" SDCC_LIB_DIR "/small" ;
-char *simArgs[8];
+char *simArgs[20];
 int nsimArgs = 0;
+char model_str[20];
 
 /* fake filename & lineno to make linker */
 char *filename=NULL;
@@ -85,7 +87,7 @@ struct cmdtab
     { "h"        ,  cmdHelp       , NULL },
 
     { "info"     ,  cmdInfo       ,
-      "info\n"
+      "info"
       "\t {break}\t list all break points\n"
       "\t {stack}\t information about call stack\n"
       "\t {frame}\t current frame information\n"
@@ -101,7 +103,7 @@ struct cmdtab
     },
     { "l"        ,  cmdListSrc    , NULL },
     { "show"     ,  cmdShow       ,
-      "show\n"
+      "show"
       "\t {copying}\t copying & distribution terms\n"
       "\t {warranty}\t warranty information\n"
     },
@@ -153,7 +155,7 @@ struct cmdtab
 char *gc_strdup(const char *s)
 {
     char *ret;
-    Safe_calloc(1,ret, strlen(s)+1);
+    ret = Safe_malloc(strlen(s)+1);
     strcpy(ret, s);
     return ret;
 }
@@ -168,7 +170,7 @@ char *alloccpy ( char *s, int size)
     if (!size)
   return NULL;
 
-    Safe_calloc(1,d,size+1);
+    d = Safe_malloc(size+1);
     memcpy(d,s,size);
     d[size] = '\0';
 
@@ -209,7 +211,7 @@ static int readCdb (FILE *file)
     if (!(bp = fgets(buffer,sizeof(buffer),file)))
       return 0;
 
-    Safe_calloc(1,currl,sizeof(cdbrecs));
+    currl = Safe_calloc(1,sizeof(cdbrecs));
     recsRoot = currl ;
 
     while (1) {
@@ -237,7 +239,7 @@ static int readCdb (FILE *file)
       }
 
       bp += 2;
-      Safe_calloc(1,currl->line,strlen(bp));
+      currl->line = Safe_malloc(strlen(bp));
       strncpy(currl->line,bp,strlen(bp)-1);
       currl->line[strlen(bp)-1] = '\0';
   }
@@ -248,7 +250,7 @@ static int readCdb (FILE *file)
   if (feof(file))
       break;
 
-  Safe_calloc(1,currl->next,sizeof(cdbrecs));
+  currl->next = Safe_calloc(1,sizeof(cdbrecs));
   currl = currl->next;
     }
 
@@ -351,7 +353,7 @@ srcLine **loadFile (char *name, int *nlines)
 
   slines = (srcLine **)resize((void **)slines,*nlines);
 
-  Safe_calloc(1,slines[(*nlines)-1],sizeof(srcLine));
+  slines[(*nlines)-1] = Safe_calloc(1,sizeof(srcLine));
   slines[(*nlines)-1]->src = alloccpy(bp,strlen(bp));
     }
 
@@ -429,12 +431,11 @@ static void functionPoints ()
 
   sym = func->sym;
 
-#ifdef SDCDB_DEBUG
-  printf("func '%s' has entry '%x' exit '%x'\n",
+  Dprintf(D_sdcdb, ("func '%s' has entry '%x' exit '%x'\n",
          func->sym->name,
          func->sym->addr,
-         func->sym->eaddr);
-#endif
+         func->sym->eaddr));
+
   if (!func->sym->addr && !func->sym->eaddr)
       continue ;
 
@@ -464,7 +465,7 @@ static void functionPoints ()
     if (func->exitline < j)
         func->exitline = j;
 
-    Safe_calloc(1,ep,sizeof(exePoint));
+    ep = Safe_calloc(1,sizeof(exePoint));
     ep->addr =  mod->cLines[j]->addr ;
     ep->line = j;
     ep->block= mod->cLines[j]->block;
@@ -487,7 +488,7 @@ static void functionPoints ()
         func->aexitline = j;
 
     /* add it to the execution point */
-    Safe_calloc(1,ep,sizeof(exePoint));
+    ep = Safe_calloc(1,sizeof(exePoint));
     ep->addr =  mod->asmLines[j]->addr ;
     ep->line = j;
     addSet(&func->afpoints,ep);
@@ -495,20 +496,21 @@ static void functionPoints ()
   }
 
 #ifdef SDCDB_DEBUG
-  printf("function '%s' has the following C exePoints\n",
-         func->sym->name);
+  Dprintf(D_sdcdb, ("function '%s' has the following C exePoints\n",
+         func->sym->name));
   {
       exePoint *ep;
 
       for (ep = setFirstItem(func->cfpoints); ep;
      ep = setNextItem(func->cfpoints))
-    fprintf (stdout,"{%x,%d} %s",ep->addr,ep->line,mod->cLines[ep->line]->src);
+     Dprintf(D_sdcdb, ("{%x,%d} %s",
+         ep->addr,ep->line,mod->cLines[ep->line]->src));
 
-      fprintf(stdout," and the following ASM exePoints\n");
+      Dprintf(D_sdcdb, (" and the following ASM exePoints\n"));
       for (ep = setFirstItem(func->afpoints); ep;
-     ep = setNextItem(func->afpoints))
-    fprintf (stdout,"{%x,%d} %s",ep->addr,ep->line,mod->asmLines[ep->line]->src);
-
+           ep = setNextItem(func->afpoints))
+        Dprintf (D_sdcdb, ("{%x,%d} %s",
+            ep->addr,ep->line,mod->asmLines[ep->line]->src));
   }
 #endif
     }
@@ -559,7 +561,7 @@ int cmdFile (char *s,context *cctxt)
     }
 
     /* allocate for context */
-    Safe_calloc(1,currCtxt ,sizeof(context));
+    currCtxt = Safe_calloc(1,sizeof(context));
 
     /* readin the debug information */
     if (!readCdb (cdbFile)) {
@@ -773,6 +775,20 @@ static void parseCmdLine (int argc, char **argv)
         continue ;
       }
 
+      /* model string */
+      if (strncmp(argv[i],"-m",2) == 0) {
+        strncpy(model_str, &argv[i][2], 15);
+        if (strcmp(model_str,"avr") == 0)
+          simArgs[0] = "savr";
+        else if (strcmp(model_str,"rrz80") == 0)
+          simArgs[0] = "rrz80";
+        else if (strcmp(model_str,"xa") == 0)
+          simArgs[0] = "sxa";
+        else if (strcmp(model_str,"z80") == 0)
+          simArgs[0] = "sz80";
+        continue ;
+      }
+
       fprintf(stderr,"unknown option %s --- ignored\n",
         argv[i]);
   } else {
@@ -799,7 +815,12 @@ static void parseCmdLine (int argc, char **argv)
 int main ( int argc, char **argv)
 {
     printVersionInfo();
+
+    simArgs[nsimArgs++] = "s51";
+    simArgs[nsimArgs++] = "-P";
+    simArgs[nsimArgs++] = "-r 9756";
     /* parse command line */
+
     parseCmdLine(argc,argv);
 
     commandLoop();