a new function for startup (_main)
authormhelmling <mhelmling@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 27 Sep 2004 05:17:31 +0000 (05:17 +0000)
committermhelmling <mhelmling@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 27 Sep 2004 05:17:31 +0000 (05:17 +0000)
to step throu

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3510 4a8a32a2-be11-0410-ad9d-d568d2c75423

debugger/mcs51/cmd.c
debugger/mcs51/cmd.h
debugger/mcs51/sdcdb.c
debugger/mcs51/simi.c
debugger/mcs51/symtab.c

index 40d47ab8177e4a47426b671adf49069345b6b8d6..21309c2ea4672e5b44c1a1b0aedc9b132d449855 100644 (file)
@@ -678,15 +678,15 @@ context *discoverContext (unsigned addr, function *func)
                   &line,&currCtxt->block,&currCtxt->level)) 
             currCtxt->cline = func->lline = line;
         else
-            currCtxt->cline = func->exitline;
+            currCtxt->cline = -1;
     }    
     /* find the asm line number */
     line = 0;
     if (applyToSet(func->afpoints,lineAtAddr,addr,
                   &line,NULL,NULL))
-       currCtxt->asmline = line;       
+        currCtxt->asmline = line;       
     else
-       currCtxt->asmline = -1;
+        currCtxt->asmline = -1;
         
     return currCtxt ;
 }
@@ -2276,9 +2276,8 @@ int cmdListSrc (char *s, context *cctxt)
                 func ? func->sym->name : "?",
                 func ? lastaddr -func->sym->addr : 0);
         llines = pline +1;
-        while ( pline < list_mod->ncLines )
+        for ( ; pline < list_mod->ncLines; pline++ )
         {
-            pline++;
             if ( list_mod->cLines[pline]->addr > lastaddr )
             {
                 lastaddr = list_mod->cLines[pline]->addr -1;
@@ -3200,12 +3199,25 @@ void setMainContext()
 {
     function *func = NULL;
     currentFrame = 0; 
-    if (!applyToSet(functions,funcWithName,"main",&func) &&
-        !applyToSet(functions,funcWithName,"_main",&func))
-        return;
+    if (!applyToSet(functions,funcWithName,"_main",&func) &&
+        !applyToSet(functions,funcWithName,"main",&func))
+            return;
 
     discoverContext (func->sym->addr, func);
 }
+
+function *needExtraMainFunction()
+{
+    function *func = NULL;
+    if (!applyToSet(functions,funcWithName,"_main",&func))
+    {
+        if (applyToSet(functions,funcWithName,"main",&func))
+        {
+            return func;
+        }
+    }
+    return NULL;
+}
     
 static void printFrame()
 {
index 25c65f4ed1f3ea7f0b8c3de5519f373f6990b4eb..5829dc564f300fd83ab08044c2ed157ef6e4a756 100644 (file)
@@ -67,6 +67,7 @@ extern int cmdListFunctions (char *s, context *cctxt);
 extern int cmdListSymbols (char *s, context *cctxt);
 
 extern void setMainContext( void);
+extern function *needExtraMainFunction(void);
 int conditionIsTrue( char *s, context *cctxt);
 
 #endif
index 1cc14082404448aece81fd3514c134efe379ed36..66c0d46832148094dc73366a347fa6d8557799b6 100644 (file)
@@ -398,18 +398,19 @@ srcLine **loadFile (char *name, int *nlines)
 
 
     if (!(mfile = searchDirsFopen(name))) {
-  fprintf(stderr,"sdcdb: cannot open module %s -- use '--directory=<source directory> option\n",name);
-  return NULL;
+        fprintf(stderr,"sdcdb: cannot open module %s -- use '--directory=<source directory> option\n",name);
+        return NULL;
     }
 
     while ((bp = fgets(buffer,sizeof(buffer),mfile))) {
-  (*nlines)++;
+        (*nlines)++;
 
-  slines = (srcLine **)resize((void **)slines,*nlines);
+        slines = (srcLine **)resize((void **)slines,*nlines);
 
-  slines[(*nlines)-1] = Safe_calloc(1,sizeof(srcLine));
-  slines[(*nlines)-1]->src = alloccpy(bp,strlen(bp));
-    }
+        slines[(*nlines)-1] = Safe_calloc(1,sizeof(srcLine));
+        slines[(*nlines)-1]->src = alloccpy(bp,strlen(bp));
+        slines[(*nlines)-1]->addr= INT_MAX;
+            }
 
     fclose(mfile);
     return slines;
@@ -495,106 +496,130 @@ static void functionPoints ()
     symbol *sym;
     exePoint *ep ;
 
+    // add _main dummy for runtime env
+    if ((func = needExtraMainFunction()))
+    {
+        function *func1;
+
+        /* alloc new _main function */
+        func1 = Safe_calloc(1,sizeof(function));
+        *func1 = *func;
+        func1->sym = Safe_calloc(1,sizeof(symbol));
+        *func1->sym =  *func->sym;
+        func1->sym->name  = alloccpy("_main",5);
+        func1->sym->rname = alloccpy("G$_main$0$",10);
+        /* TODO must be set by symbol information */
+        func1->sym->addr  = 0;
+        func1->sym->eaddr = 0x2f;
+        addSet(&functions,func1);
+    }
+
     /* for all functions do */
     for ( func = setFirstItem(functions); func;
-    func = setNextItem(functions)) {
-  int j ;
-  module *mod;
-
-  sym = func->sym;
-
-  Dprintf(D_sdcdb, ("sdcdb: func '%s' has entry '0x%x' exit '0x%x'\n",
-         func->sym->name,
-         func->sym->addr,
-         func->sym->eaddr));
-
-  if (!func->sym->addr && !func->sym->eaddr)
-      continue ;
-
-  /* for all source lines in the module find
-     the ones with address >= start and <= end
-     and put them in the point */
-  mod = NULL ;
-  if (! applyToSet(modules,moduleWithName,func->modName,&mod))
-      continue ;
-  func->mod = mod ;
-  func->entryline= INT_MAX;
-  func->exitline =  0;
-  func->aentryline = INT_MAX ;
-  func->aexitline = 0;
-
-  /* do it for the C Lines first */
-  for ( j = 0 ; j < mod->ncLines ; j++ ) {
-      if (mod->cLines[j]->addr >= sym->addr &&
-    mod->cLines[j]->addr <= sym->eaddr ) {
-
-
-    /* add it to the execution point */
-    if (func->entryline > j)
-        func->entryline = j;
-
-    if (func->exitline < j)
-        func->exitline = j;
-
-    ep = Safe_calloc(1,sizeof(exePoint));
-    ep->addr =  mod->cLines[j]->addr ;
-    ep->line = j;
-    ep->block= mod->cLines[j]->block;
-    ep->level= mod->cLines[j]->level;
-    addSet(&func->cfpoints,ep);
-      }
-  }
-  /* check double line execution points of module */
-  for (ep = setFirstItem(mod->cfpoints); ep;
-       ep = setNextItem(mod->cfpoints))
-  {
-      if (ep->addr >= sym->addr &&
-          ep->addr <= sym->eaddr ) 
-      {
-          addSet(&func->cfpoints,ep);
-      }
-  }
-  /* do the same for asm execution points */
-  for ( j = 0 ; j < mod->nasmLines ; j++ ) {
-      if (mod->asmLines[j]->addr >= sym->addr &&
-    mod->asmLines[j]->addr <= sym->eaddr ) {
-
-    exePoint *ep ;
-    /* add it to the execution point */
-    if (func->aentryline > j)
-        func->aentryline = j;
-
-    if (func->aexitline < j)
-        func->aexitline = j;
-
-    /* add it to the execution point */
-    ep = Safe_calloc(1,sizeof(exePoint));
-    ep->addr =  mod->asmLines[j]->addr ;
-    ep->line = j;
-    addSet(&func->afpoints,ep);
-      }
-  }
+          func = setNextItem(functions)) {
+        int j ;
+        module *mod;
+
+        sym = func->sym;
+
+        Dprintf(D_sdcdb, ("sdcdb: func '%s' has entry '0x%x' exit '0x%x'\n",
+                          func->sym->name,
+                          func->sym->addr,
+                          func->sym->eaddr));
+
+        if (!func->sym->addr && !func->sym->eaddr)
+            continue ;
+
+        /* for all source lines in the module find
+           the ones with address >= start and <= end
+           and put them in the point */
+        mod = NULL ;
+        if (! applyToSet(modules,moduleWithName,func->modName,&mod))
+            continue ;
+        func->mod = mod ;
+        func->entryline= INT_MAX-2;
+        func->exitline =  0;
+        func->aentryline = INT_MAX-2 ;
+        func->aexitline = 0;
+
+        /* do it for the C Lines first */
+        for ( j = 0 ; j < mod->ncLines ; j++ ) {
+            if (mod->cLines[j]->addr < INT_MAX &&
+                mod->cLines[j]->addr >= sym->addr &&
+                mod->cLines[j]->addr <= sym->eaddr ) {
+
+
+                /* add it to the execution point */
+                if (func->entryline > j)
+                    func->entryline = j;
+
+                if (func->exitline < j)
+                    func->exitline = j;
+
+                ep = Safe_calloc(1,sizeof(exePoint));
+                ep->addr =  mod->cLines[j]->addr ;
+                ep->line = j;
+                ep->block= mod->cLines[j]->block;
+                ep->level= mod->cLines[j]->level;
+                addSet(&func->cfpoints,ep);
+            }
+        }
+        /* check double line execution points of module */
+        for (ep = setFirstItem(mod->cfpoints); ep;
+             ep = setNextItem(mod->cfpoints))
+        {
+            if (ep->addr >= sym->addr &&
+                ep->addr <= sym->eaddr ) 
+            {
+                addSet(&func->cfpoints,ep);
+            }
+        }
+        /* do the same for asm execution points */
+        for ( j = 0 ; j < mod->nasmLines ; j++ ) {
+            if (mod->asmLines[j]->addr < INT_MAX &&
+                mod->asmLines[j]->addr >= sym->addr &&
+                mod->asmLines[j]->addr <= sym->eaddr ) {
+
+                exePoint *ep ;
+                /* add it to the execution point */
+                if (func->aentryline > j)
+                    func->aentryline = j;
+
+                if (func->aexitline < j)
+                    func->aexitline = j;
+
+                /* add it to the execution point */
+                ep = Safe_calloc(1,sizeof(exePoint));
+                ep->addr =  mod->asmLines[j]->addr ;
+                ep->line = j;
+                addSet(&func->afpoints,ep);
+            }
+        }
+        if ( func->entryline == INT_MAX-2 )
+            func->entryline = 0;
+        if ( func->aentryline == INT_MAX-2 )
+            func->aentryline = 0;
 
 #ifdef SDCDB_DEBUG
-  if (!( D_sdcdb & sdcdbDebug))
-      continue;
-
-  Dprintf(D_sdcdb, ("sdcdb: function '%s' has the following C exePoints\n",
-         func->sym->name));
-  {
-      exePoint *ep;
-
-      for (ep = setFirstItem(func->cfpoints); ep;
-     ep = setNextItem(func->cfpoints))
-     Dprintf(D_sdcdb, ("sdcdb: {0x%x,%d} %s",
-         ep->addr,ep->line+1,mod->cLines[ep->line]->src));
-
-      Dprintf(D_sdcdb, ("sdcdb:  and the following ASM exePoints\n"));
-      for (ep = setFirstItem(func->afpoints); ep;
-           ep = setNextItem(func->afpoints))
-        Dprintf (D_sdcdb, ("sdcdb: {0x%x,%d} %s",
-            ep->addr,ep->line+1,mod->asmLines[ep->line]->src));
-  }
+        if (!( D_sdcdb & sdcdbDebug))
+            continue;
+
+        Dprintf(D_sdcdb, ("sdcdb: function '%s' has the following C exePoints\n",
+                          func->sym->name));
+        {
+            exePoint *ep;
+
+            for (ep = setFirstItem(func->cfpoints); ep;
+                 ep = setNextItem(func->cfpoints))
+                Dprintf(D_sdcdb, ("sdcdb: {0x%x,%d} %s",
+                                  ep->addr,ep->line+1,mod->cLines[ep->line]->src));
+
+            Dprintf(D_sdcdb, ("sdcdb:  and the following ASM exePoints\n"));
+            for (ep = setFirstItem(func->afpoints); ep;
+                 ep = setNextItem(func->afpoints))
+                Dprintf (D_sdcdb, ("sdcdb: {0x%x,%d} %s",
+                                   ep->addr,ep->line+1,mod->asmLines[ep->line]->src));
+        }
 #endif
     }
 }
index 27ed92d1999016068fac50b6b8444309ac4654a1..6eb859cadf3c1ae26fdaca38edff9eb693118d5c 100644 (file)
@@ -144,7 +144,17 @@ void openSimulator (char **args, int nargs)
     int retry = 0;
     int i ;
     Dprintf(D_simi, ("simi: openSimulator\n"));
-
+#ifdef SDCDB_DEBUG
+    if (D_simi & sdcdbDebug)
+    {
+        printf("simi: openSimulator: ");
+        for (i=0; i < nargs; i++ )
+        {
+            printf("arg%d: %s ",i,args[i]);
+        }
+        printf("\n");
+    }
+#endif
     invalidateCache(XMEM_CACHE);
     invalidateCache(IMEM_CACHE);
     invalidateCache(SREG_CACHE);
index 6d12e577917c745c4f436218e2e5060975cb7574..423bf2b6ab99c185bf1cd9676540a280eaa6cd8d 100644 (file)
@@ -712,7 +712,7 @@ static void lnkCSrc (char *s)
     module *mod ;
 
     /* input will be of format
-       filename.ext$<level>$<block>$<line>:<address> */
+       filename.ext$<line>$<level>$<block>:<address> */
     /* get the module name */
     while (*s != '$' )
   *bp++ = *s++;
@@ -738,7 +738,7 @@ static void lnkCSrc (char *s)
         ( !mod->cLines[line]->addr ||
         mod->cLines[line]->level > level )*/ ) 
     {
-        if ( mod->cLines[line]->addr )
+        if ( mod->cLines[line]->addr != INT_MAX )
         {
             /* save double line information for exepoints */
             exePoint *ep ;