fix some things
authorkbongers <kbongers@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 11 Feb 2002 00:09:03 +0000 (00:09 +0000)
committerkbongers <kbongers@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 11 Feb 2002 00:09:03 +0000 (00:09 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1915 4a8a32a2-be11-0410-ad9d-d568d2c75423

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

index ea71bff0de0c8eef587fc9d908fba274a90e1517..0a14e2b8f0c65c69beb198364314a720a529182c 100644 (file)
 #include "break.h"
 #include "cmd.h"
 
-int listLines = 10;
+/* default number of lines to list out */
+int listLines = 16;
+
+/* mainly used to retain a reference to the active module being
+   listed.  May be used as a general context for other commands if
+   no better context is available */
+static module *list_mod = NULL;
+
 EXTERN_STACK_DCL(callStack,function *,1024);
 
 #if defined(__APPLE__) && defined(__MACH__)
@@ -350,6 +357,8 @@ DEFSETFUNC(funcWithName)
 /*-----------------------------------------------------------------*/
 static void setBPatModLine (module *mod, int line)
 {
+  int next_line;
+
     /* look for the first executable line after the line
        specified & get the break point there */    
     if (srcMode == SRC_CMODE && line > mod->ncLines) {
@@ -364,24 +373,30 @@ static void setBPatModLine (module *mod, int line)
        return ;
     }
 
-    for ( ; line < (srcMode == SRC_CMODE ? mod->ncLines : mod->nasmLines ) ; 
-         line++ ) {
+    next_line = line;
+    for ( ; next_line < (srcMode == SRC_CMODE ? mod->ncLines : mod->nasmLines ) ; 
+         next_line++ ) {
        if (srcMode == SRC_CMODE) {
-           if (mod->cLines[line]->addr) {
-               setBreakPoint (mod->cLines[line]->addr, CODE, USER, 
-                              userBpCB, mod->c_name, line);
-               break;
+           if (mod->cLines[next_line]->addr) {
+               setBreakPoint (mod->cLines[next_line]->addr, CODE, USER, 
+                              userBpCB, mod->c_name, next_line);
+               return;
+//             break;
            }
        }
        else {
-          if (mod->asmLines[line]->addr) {
-              setBreakPoint (mod->asmLines[line]->addr, CODE, USER, 
-                             userBpCB, mod->asm_name, line);
-              break;
+          if (mod->asmLines[next_line]->addr) {
+              setBreakPoint (mod->asmLines[next_line]->addr, CODE, USER, 
+                             userBpCB, mod->asm_name, next_line);
+               return;
+//            break;
           } 
        }
     }
 
+       fprintf(stderr,"No line %d or after in file \"%s\"..\n",
+                       line,mod->c_name);
+
     return;
 }
 
@@ -707,9 +722,13 @@ int cmdSetUserBp (char *s, context *cctxt)
                else 
                    setBPatModLine(func->mod,line);
            } else 
-               setBPatModLine(cctxt->func->mod,line);                  
+               setBPatModLine(cctxt->func->mod,line);
        } else {
-               fprintf(stdout,"No symbol information currently\n");
+               if (list_mod) {
+                       setBPatModLine(list_mod,line);
+               } else {
+                 fprintf(stdout,"Sdcdb fails to have module symbol context at %d\n", __LINE__);
+               }
        }
        
        goto ret;
@@ -1012,6 +1031,276 @@ int cmdRun (char *s, context *cctxt)
     return 0;
 }
 
+/*-----------------------------------------------------------------
+ cmdListSymbols - list symbols
+|-----------------------------------------------------------------*/
+int cmdListSymbols (char *s, context *cctxt)
+{
+    int our_verbose = 0;
+    symbol *sy;
+    int i;
+
+    if (strstr(s, "v1")) {
+      our_verbose = 1;
+    } else if (strstr(s, "v2")) {
+      our_verbose = 2;
+    }
+
+    printf("[symbols]\n");
+    sy = setFirstItem(symbols);
+    i = 0;
+    for (;;) {
+      if (sy == NULL)
+        break;
+      if (our_verbose <= 1)
+        printf("<%s>", sy->name);
+
+      if (our_verbose > 1) {
+        printf("  %d) name:%s, size:%d, level:%d block:%d\n", i,
+          sy->name, sy->size, sy->level, sy->block);
+        printf("    isonstack:%d, isfunc:%d, offset:%d addr:%d\n",
+          sy->isonstack, sy->isfunc, sy->offset, sy->addr);
+        printf("    eaddr:%d, addr_type:%c, type:%x etype:%x\n",
+          sy->eaddr, sy->addr_type, sy->type, sy->etype);
+        printf("    scopetype:%c, sname:%s, rname:%s addrspace:%c\n",
+          sy->scopetype, sy->sname, sy->rname, sy->addrspace);
+        printf("    next:%x\n", sy->next);
+      }
+      ++i;
+      sy = setNextItem(symbols);
+    }
+    printf("   %d symbols\n", i);
+    return 0;
+}
+
+/*-----------------------------------------------------------------
+ cmdListFunctions - list functions.
+|-----------------------------------------------------------------*/
+int cmdListFunctions (char *s, context *cctxt)
+{
+    function *f;
+    int i;
+    int our_verbose = 0;
+
+    if (strstr(s, "v1")) {
+      our_verbose = 1;
+    } else if (strstr(s, "v2")) {
+      our_verbose = 2;
+    }
+
+    printf("[functions]\n");
+    f = setFirstItem(functions);
+    i = 0;
+    for (;;) {
+      if (f == NULL)
+        break;
+      if (our_verbose) {
+        printf("  %d) sym:%x, modName:%s, mod:%x\n", i,
+          f->sym, f->modName, f->mod);
+        printf("    entryline:%d, aentryline:%d, exitline:%d, aexitline:%d\n",
+                f->entryline, f->aentryline, f->exitline, f->aexitline);
+        printf("    cfpoints:%x, afpoints:%x, laddr:%x, lline:%d\n",
+                f->cfpoints, f->afpoints, f->laddr, f->lline);
+      }
+      else {
+        printf("<%s>", f->modName);
+      }
+      ++i;
+      f = setNextItem(functions);
+    }
+    printf("   %d functions\n", i);
+    return 0;
+}
+
+/*-----------------------------------------------------------------
+ cmdListModules - list functions.
+|-----------------------------------------------------------------*/
+int cmdListModules (char *s, context *cctxt)
+{
+    module *m;
+    srcLine *cs, *as;
+    int i, mi;
+    int our_verbose = 0;
+
+    if (strstr(s, "v1")) {
+      our_verbose = 1;
+    } else if (strstr(s, "v2")) {
+      our_verbose = 2;
+    }
+
+    printf("[modules]\n");
+    m = setFirstItem(modules);
+    mi = 0;
+    for (;;) {
+      if (m == NULL)
+        break;
+
+      if (our_verbose >= 0) {
+      printf("  %d) cfullname:%s, afullname:%s, name:%s\n", ++mi,
+        m->cfullname, m->afullname, m->name);
+      printf("    c_name:%s, asm_name:%s, ncLines:%d, nasmLines:%d\n",
+              m->c_name, m->asm_name, m->ncLines, m->nasmLines);
+      printf("    cLines:%x, asmLines:%x\n",
+              m->cLines, m->asmLines);
+      }
+      if (our_verbose > 2) {
+        i = 0;
+        if (m->cLines) {
+          cs = m->cLines[i++];
+          printf("    [cLines] ");
+          while (cs) {
+            if (our_verbose)
+              printf("   (%d) addr:%x, block:%d, level:%d, src:%s\n",
+                 i, cs->addr, cs->block, cs->level, cs->src);
+            cs = m->cLines[i++];
+          }
+          if (!our_verbose)
+              printf("%d records", i);
+        }
+        i = 0;
+        if (m->asmLines) {
+          as = m->asmLines[i++];
+          printf("    [asmLines] ");
+          while (as) {
+            if (our_verbose)
+              printf("   (%d) addr:%x, block:%d, level:%d, src:%s\n",
+                 i, as->addr, as->block, as->level, as->src);
+            as = m->asmLines[i++];
+          }
+          if (!our_verbose)
+              printf("%d records", i);
+        }
+        printf("\n");
+      }
+
+      m = setNextItem(modules);
+    }
+    return 0;
+}
+
+/*-----------------------------------------------------------------
+ infoSymbols - This is really just a tool to dump all these
+   huge program structures out into human readable form.
+|-----------------------------------------------------------------*/
+static void infoSymbols(context *ctxt)
+{
+  int our_verbose = 0;
+
+  printf("[context:%x] func:%x modName:%s addr:%x\n",
+    ctxt, ctxt->func, ctxt->modName, ctxt->addr);
+
+  printf("  cline:%d asmline:%d block:%d level:%d\n",
+    ctxt->cline, ctxt->asmline, ctxt->level);
+
+  printf("[globals] currCtxt:%x, modules:%x, functions:%x symbols:%x\n",
+    currCtxt, modules, functions, symbols);
+  printf("  nStructs:%d, structs:%x, ssdirl:%s\n",
+    nStructs, structs, ssdirl);
+
+  /**************** modules *******************/
+  {
+    module *m;
+    srcLine *cs, *as;
+    int i, mi;
+    printf("[modules]\n");
+    m = setFirstItem(modules);
+    mi = 0;
+    for (;;) {
+      if (m == NULL)
+        break;
+      printf("  %d) cfullname:%s, afullname:%s, name:%s\n", ++mi,
+        m->cfullname, m->afullname, m->name);
+      printf("    c_name:%s, asm_name:%s, ncLines:%d, nasmLines:%d\n",
+              m->c_name, m->asm_name, m->ncLines, m->nasmLines);
+      printf("    cLines:%x, asmLines:%x\n",
+              m->cLines, m->asmLines);
+      i = 0;
+      if (m->cLines) {
+        cs = m->cLines[i++];
+        printf("    [cLines] ");
+        while (cs) {
+          if (our_verbose)
+            printf("   (%d) addr:%x, block:%d, level:%d, src:%s\n",
+               i, cs->addr, cs->block, cs->level, cs->src);
+          cs = m->cLines[i++];
+        }
+        if (!our_verbose)
+            printf("%d records", i);
+      }
+      i = 0;
+      if (m->asmLines) {
+        as = m->asmLines[i++];
+        printf("    [asmLines] ");
+        while (as) {
+          if (our_verbose)
+            printf("   (%d) addr:%x, block:%d, level:%d, src:%s\n",
+               i, as->addr, as->block, as->level, as->src);
+          as = m->asmLines[i++];
+        }
+        if (!our_verbose)
+            printf("%d records", i);
+      }
+      printf("\n");
+
+      m = setNextItem(modules);
+    }
+  }
+
+  /**************** functions *******************/
+  {
+    function *f;
+    int i;
+    printf("[functions]\n");
+    f = setFirstItem(functions);
+    i = 0;
+    for (;;) {
+      if (f == NULL)
+        break;
+      if (our_verbose) {
+        printf("  %d) sym:%x, modName:%s, mod:%x\n", i,
+          f->sym, f->modName, f->mod);
+        printf("    entryline:%d, aentryline:%d, exitline:%d, aexitline:%d\n",
+                f->entryline, f->aentryline, f->exitline, f->aexitline);
+        printf("    cfpoints:%x, afpoints:%x, laddr:%x, lline:%d\n",
+                f->cfpoints, f->afpoints, f->laddr, f->lline);
+      }
+      ++i;
+      f = setNextItem(functions);
+    }
+    if (!our_verbose)
+      printf("   %d functions\n", i);
+  }
+
+  /**************** symbols *******************/
+  {
+    symbol *s;
+    int i;
+    printf("[symbols]\n");
+    s = setFirstItem(symbols);
+    i = 0;
+    for (;;) {
+      if (s == NULL)
+        break;
+      if (our_verbose) {
+        printf("  %d) name:%s, size:%d, level:%d block:%d\n", i,
+          s->name, s->size, s->level, s->block);
+        printf("    isonstack:%d, isfunc:%d, offset:%d addr:%d\n",
+          s->isonstack, s->isfunc, s->offset, s->addr);
+        printf("    eaddr:%d, addr_type:%c, type:%x etype:%x\n",
+          s->eaddr, s->addr_type, s->type, s->etype);
+        printf("    scopetype:%c, sname:%s, rname:%s addrspace:%c\n",
+          s->scopetype, s->sname, s->rname, s->addrspace);
+        printf("    next:%x\n", s->next);
+      }
+      ++i;
+      s = setNextItem(symbols);
+    }
+    if (!our_verbose)
+      printf("   %d symbols\n", i);
+  }
+
+}
+
 /*-----------------------------------------------------------------*/
 /* infoStack - print call stack information                        */
 /*-----------------------------------------------------------------*/
@@ -1061,6 +1350,14 @@ int cmdInfo (char *s, context *cctxt)
        return 0;
     }
 
+    /* info stack display call stack */
+    if (strcmp(s,"symbols") == 0) {
+      /* dump out symbols we have read in */
+      fprintf(stdout,"Dumping symbols...\n");
+      infoSymbols(cctxt);
+      return 0;
+    }
+
     fprintf(stdout,"Undefined info command: \"%s\".  Try \"help\n",s);
     return 0;
 
@@ -1084,7 +1381,6 @@ int cmdListSrc (char *s, context *cctxt)
     static int currline = 0;
     int i =0 ;
     int pline = 0;
-    static module *mod = NULL;
     int llines = listLines;
 
     while (*s && isspace(*s)) s++;
@@ -1095,15 +1391,19 @@ int cmdListSrc (char *s, context *cctxt)
        FILE:LINE     - filename line number
        FUNCTION      - list a function
        FILE:FUNCTION - function in file */
-    if (!cctxt || !cctxt->func || !cctxt->func->mod) {
-       fprintf(stdout,"No symbol table is loaded.  Use the \"file\" command.\n");
-       return 0;
-    }
+
     if (*s) {
        /* case a) LINE */
        if (isdigit(*s)) {
            sscanf(s,"%d",&pline);
-           mod = cctxt->func->mod;
+           if (!cctxt || !cctxt->func || !cctxt->func->mod) {
+             if (!list_mod) {
+               fprintf(stdout,"Sdcdb fails to have a proper context at %d.\n", __LINE__);
+               return 0;
+             }
+           }
+           else
+             list_mod = cctxt->func->mod;
        }
        else {
            char *bp;
@@ -1115,25 +1415,26 @@ int cmdListSrc (char *s, context *cctxt)
                bp ++;
                if (isdigit(*bp)) {
                    /* FILE:LINE */
+                   list_mod=NULL;  /* bug fix 2-09-02, moduleWithCName expects mod to be null */
                    if (srcMode == SRC_CMODE) {
-                       if (!applyToSet(modules,moduleWithCName,s,&mod)) {
-                           fprintf (stderr,"No source file named %s.\n",s);
+                       if (!applyToSet(modules,moduleWithCName,s,&list_mod)) {
+                           fprintf (stderr,"No source file named %s.\n",s);
                            return 0;
                        }
                    } else {
-                       if (!applyToSet(modules,moduleWithAsmName,s,&mod)) {
+                       if (!applyToSet(modules,moduleWithAsmName,s,&list_mod)) {
                            fprintf (stderr,"No source file named %s.\n",s);
                            return 0;
                        }
                    }
-                   sscanf(bp,"%d",&pline);                         
+                   sscanf(bp,"%d",&pline);
                } else {
                    /* FILE:FUCTION */
                    if (!applyToSet(functions,funcWithNameModule,bp,s,&func)) {
                        fprintf(stdout,"Function \"%s\" not defined.\n",bp);
                        return 0;
                    }
-                   mod = func->mod;
+                   list_mod = func->mod;
                    if (srcMode == SRC_CMODE) {
                        pline = func->entryline;
                        llines = func->exitline - func->entryline + 1;
@@ -1150,7 +1451,7 @@ int cmdListSrc (char *s, context *cctxt)
                    return 0;
                }
                else {
-                   mod = func->mod;
+                   list_mod = func->mod;
                    if (srcMode == SRC_CMODE) {
                        pline = func->entryline;
                        llines = func->exitline - func->entryline + 1; 
@@ -1159,7 +1460,7 @@ int cmdListSrc (char *s, context *cctxt)
                        llines = func->aexitline - func->aentryline + 1; 
                    }
                }
-           }               
+           }
        }
     } else {
        /* if no line specified & we had listed
@@ -1167,25 +1468,36 @@ int cmdListSrc (char *s, context *cctxt)
        if (currline)
            pline = currline ;
        else {
-           mod = cctxt->func->mod;
+           if (!cctxt || !cctxt->func || !cctxt->func->mod) {
+             fprintf(stdout,"Missing context at %d. Try list filename:lineno\n", __LINE__);
+             return 0;
+           }
+           list_mod = cctxt->func->mod;
            if (srcMode == SRC_CMODE)
                pline = cctxt->cline;
            else
                pline = cctxt->asmline;
        }
     }
+
+    if (!list_mod) {
+      fprintf(stdout,"Sdcdb fails to have a valid module context at %d.\n", __LINE__);
+      return 0;
+    }
     
+    if (llines > listLines) llines = listLines;
+
     for ( i = 0 ; i < llines ; i++ ) {
        if (srcMode == SRC_CMODE) {
-           if ( (pline + i) >= mod->ncLines )
+           if ( (pline + i) >= list_mod->ncLines )
                break;
            fprintf(stdout,"%d\t%s",pline + i,
-                   mod->cLines[pline +i]->src);
+                   list_mod->cLines[pline +i]->src);
        } else {
-           if ( (pline + i) >= mod->nasmLines )
+           if ( (pline + i) >= list_mod->nasmLines )
                break;
            fprintf(stdout,"%d\t%s",pline + i,
-                   mod->asmLines[pline +i]->src);
+                   list_mod->asmLines[pline +i]->src);
        }
     }
     currline = pline + i ;
@@ -1340,6 +1652,7 @@ static void printSymValue (symbol *sym, context *cctxt)
        else {
            printValBasic(sym,sym->addr,sym->addrspace,sym->size);
            fprintf(stdout,"\n");
+           //fprintf(stdout,"(BASIC %x,%c,%d)\n",sym->addr,sym->addrspace,sym->size);
        }
 }
 
@@ -1457,11 +1770,6 @@ int cmdPrint (char *s, context *cctxt)
     bp++ ;
     *bp = '\0';
 
-    if (!cctxt || !cctxt->func) {
-       fprintf(stdout,"No symbol \"%s\" in current context.\n",
-               s);
-       return 0;
-    }
     if ((sym = symLookup(s,cctxt))) {
        printSymValue(sym,cctxt);
     } else {
@@ -1486,18 +1794,12 @@ int cmdPrintType (char *s, context *cctxt)
     bp++ ;
     *bp = '\0';
 
-    if (!cctxt || !cctxt->func) {
-       fprintf(stdout,"No symbol \"%s\" in current context.\n",
-               s);
-       return 0;
-    }
-
     if ((sym = symLookup(s,cctxt))) {
        printTypeInfo(sym->type);
        fprintf(stdout,"\n");
     } else {
        fprintf(stdout,
-               "No symbol \"%s\" in current context.\n",              
+               "No symbol \"%s\" in current context.\n",
                s);
     }
     return 0;   
index ad53cd1621d887783b9a0685866f5e278f9b5c88..9d4c7602ebd1ef4d942004e9f499e714315a3069 100644 (file)
@@ -44,4 +44,9 @@ extern int cmdFile      (char *, context *);
 extern int cmdInfo      (char *, context *);
 extern int cmdShow      (char *, context *);
 extern int cmdFinish    (char *, context *);
+
+extern int cmdListModules (char *s, context *cctxt);
+extern int cmdListFunctions (char *s, context *cctxt);
+extern int cmdListSymbols (char *s, context *cctxt);
+
 #endif
index c40e3d8c8e45287e4ff06d93cac4a36bdd6857b8..3cb7fd5932dabcd59627f96b198347cf1eacdb5b 100644 (file)
@@ -61,7 +61,7 @@ struct cmdtab
        precede the synonym "b" */
     /* break point */
     { "break"    ,  cmdSetUserBp  ,
-      "{b}reak\t\t\t [LINE |  FILE:LINE | FILE:FUNCTION | FUNCTION]\n",
+      "{b}reak\t\t\t [LINE | FILE:LINE | FILE:FUNCTION | FUNCTION]\n",
     },
     { "b"        ,  cmdSetUserBp  , NULL },
 
@@ -87,27 +87,26 @@ struct cmdtab
     { "h"        ,  cmdHelp       , NULL },
 
     { "info"     ,  cmdInfo       ,
-      "info"
-      "\t {break}\t list all break points\n"
-      "\t {stack}\t information about call stack\n"
-      "\t {frame}\t current frame information\n"
-      "\t {registers}\t display value of all registers\n"
+      "info <break stack frame registers>\n"
+      "\t list all break points, call-stack, frame or register information\n"
     },
 
     { "listasm"  ,  cmdListAsm    ,
       "listasm {la}\t\t list assembler code for the current C line\n"
     },
     { "la"       ,  cmdListAsm    , NULL },
+    { "ls"       ,  cmdListSymbols  , "ls,lf,lm\t\t list symbols,functions,modules\n" },
+    { "lf"       ,  cmdListFunctions, NULL },
+    { "lm"       ,  cmdListModules  , NULL },
     { "list"     ,  cmdListSrc    ,
       "{l}ist\t\t\t [LINE | FILE:LINE | FILE:FUNCTION | FUNCTION]\n"
     },
     { "l"        ,  cmdListSrc    , NULL },
     { "show"     ,  cmdShow       ,
       "show"
-      "\t {copying}\t copying & distribution terms\n"
-      "\t {warranty}\t warranty information\n"
+      " <copying warranty>\t copying & distribution terms, warranty\n"
     },
-    { "set"      ,  cmdSetOption  , NULL },
+    { "set"      ,  cmdSetOption  , "set <srcmode>\t\t toggle between c/asm.\n" },
     { "step"     ,  cmdStep       ,
       "{s}tep\t\t\t Step program until it reaches a different source line.\n"
     },
@@ -143,6 +142,9 @@ struct cmdtab
     { "!"        ,  cmdSimulator  ,
       "!<simulator command>\t send a command directly to the simulator\n"
     },
+    { "."        ,  cmdSimulator  ,
+      ".{cmd}\t switch from simulator or debugger command mode\n"
+    },
     { "quit"     ,  cmdQuit       ,
       "{q}uit\t\t\t \"Watch me now. Iam going Down. My name is Bobby Brown\"\n"
     },
@@ -600,67 +602,107 @@ int cmdFile (char *s,context *cctxt)
 int cmdHelp (char *s, context *cctxt)
 {
     int i ;
+    int endline = 999;
+    int startline = 0;
+
+    while (isspace(*s))
+      ++s;
+    if (isdigit(*s)) {
+      endline = ((*s - '0') * 20) + 20;
+      if (endline > 0)
+        startline = endline - 20;
+    }
 
     for (i = 0 ; i < (sizeof(cmdTab)/sizeof(struct cmdtab)) ; i++) {
 
-  /* command string matches */
-  if (cmdTab[i].htxt)
-      fprintf(stdout,"%s",cmdTab[i].htxt);
+      /* command string matches */
+      
+      if ((cmdTab[i].htxt) && (i >= startline))
+        fprintf(stdout,"%s",cmdTab[i].htxt);
+      if (i == endline)
+        break;
     }
 
     return 0;
 }
 
 #define MAX_CMD_LEN 512
-char *prompt = "(sdcdb) ";
-char cmdbuff[MAX_CMD_LEN];
+static char cmdbuff[MAX_CMD_LEN];
+static int sim_cmd_mode = 0;
 
-/*-----------------------------------------------------------------*/
-/* interpretCmd - interpret and do the command                     */
-/*-----------------------------------------------------------------*/
+/*-----------------------------------------------------------------
+ interpretCmd - interpret and do the command.  Return 0 to continue,
+   return 1 to exit program.
+|-----------------------------------------------------------------*/
 int interpretCmd (char *s)
 {
     static char *pcmd = NULL;
     int i ;
     int rv = 0 ;
+
     /* if nothing & previous command exists then
        execute the previous command again */
     if (*s == '\n' && pcmd)
-  strcpy(s,pcmd);
+      strcpy(s,pcmd);
+
     /* if previous command exists & is different
        from the current command then copy it */
     if (pcmd) {
-  if (strcmp(pcmd,s)) {
-      free(pcmd);
-      pcmd = strdup(s);
-  }
+      if (strcmp(pcmd,s)) {
+         free(pcmd);
+         pcmd = strdup(s);
+      }
     } else
-  pcmd = strdup(s);
-    /* lookup the command table and do the
-       task required */
+      pcmd = strdup(s);
+
+    /* lookup the command table and do the task required */
     strtok(s,"\n");
 
+    if (sim_cmd_mode) {
+      if (strcmp(s,".") == 0) {
+        sim_cmd_mode = 0;
+        return 0;
+      }
+      else if (s[0] == '.') {
+        /* kill the preceeding '.' and pass on as SDCDB command */
+        char *s1 = s+1;
+        char *s2 = s;
+        while (*s1 != 0)
+          *s2++ = *s1++;
+        *s2 = 0;
+      } else {
+        cmdSimulator (s, currCtxt);
+        return 0;
+      }
+    } else {
+      if (strcmp(s,".") ==0) {
+        sim_cmd_mode = 1;
+        return 0;
+      }
+    }
+
     for (i = 0 ; i < (sizeof(cmdTab)/sizeof(struct cmdtab)) ; i++) {
 
-  /* command string matches */
-  if (strncmp(s,cmdTab[i].cmd,strlen(cmdTab[i].cmd)) == 0) {
-      if (!cmdTab[i].cmdfunc)
-    return 1;
-      rv = (*cmdTab[i].cmdfunc)(s + strlen(cmdTab[i].cmd),currCtxt);
-
-      /* if full name then give the file name & position */
-      if (fullname && currCtxt && currCtxt->func) {
-    if (srcMode == SRC_CMODE)
-        fprintf(stdout,"\032\032%s:%d:1\n",
-          currCtxt->func->mod->cfullname,
-          currCtxt->cline+1);
-    else
-        fprintf(stdout,"\032\032%s:%d:1\n",
-          currCtxt->func->mod->afullname,
-          currCtxt->asmline+1);
+      /* command string matches */
+      if (strncmp(s,cmdTab[i].cmd,strlen(cmdTab[i].cmd)) == 0) {
+        if (!cmdTab[i].cmdfunc)
+          return 1;
+
+        rv = (*cmdTab[i].cmdfunc)(s + strlen(cmdTab[i].cmd),currCtxt);
+
+        /* if full name then give the file name & position */
+        if (fullname && currCtxt && currCtxt->func) {
+          if (srcMode == SRC_CMODE)
+            fprintf(stdout,"\032\032%s:%d:1\n",
+                    currCtxt->func->mod->cfullname,
+                    currCtxt->cline+1);
+          else
+            fprintf(stdout,"\032\032%s:%d:1\n",
+                    currCtxt->func->mod->afullname,
+                    currCtxt->asmline+1);
+        }
+        goto ret;
       }
-      goto ret;
-  }
     }
 
     fprintf(stdout,"Undefined command: \"%s\".  Try \"help\".\n",s);
@@ -673,18 +715,32 @@ int interpretCmd (char *s)
 /*-----------------------------------------------------------------*/
 void commandLoop()
 {
+ char *prompt = "(sdcdb) ";
+ char *sim_prompt = "(sim) ";
 
-    while (1) {
-  fprintf(stdout,"%s",prompt);
-  fflush(stdout);
+  while (1) {
+    if (sim_cmd_mode)
+      printf("%s",sim_prompt);
+    else
+      fprintf(stdout,"%s",prompt);
 
-  if (fgets(cmdbuff,sizeof(cmdbuff),stdin) == NULL)
-      break;
+    fflush(stdout);
 
-  if (interpretCmd(cmdbuff))
+    if (fgets(cmdbuff,sizeof(cmdbuff),stdin) == NULL)
       break;
 
+#if 0
+    /* make a way to go into "ucSim" mode */
+    if (cmdbuff[0] == '$') {
+      if (sim_cmd_mode) sim_cmd_mode = 0;
+      else sim_cmd_mode = 1;
+      continue;
     }
+#endif
+
+    if (interpretCmd(cmdbuff))
+      break;
+  }
 }
 
 /*-----------------------------------------------------------------*/
@@ -708,9 +764,15 @@ static void parseCmdLine (int argc, char **argv)
 {
     int i ;
     char *filename = NULL;
-    char buffer[100];
+    int passon_args_flag = 0;  /* if true, pass on args to simulator */
+
     for ( i = 1; i < argc ; i++) {
-  fprintf(stdout,"%s\n",argv[i]);
+  //fprintf(stdout,"%s\n",argv[i]);
+
+  if (passon_args_flag) { /* if true, pass on args to simulator */
+    simArgs[nsimArgs++] = strdup(argv[i]);
+    continue;
+  }
 
   /* if this is an option */
   if (argv[i][0] == '-') {
@@ -743,6 +805,24 @@ 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,"xa") == 0)
+          simArgs[0] = "sxa";
+        else if (strcmp(model_str,"z80") == 0)
+          simArgs[0] = "sz80";
+        continue ;
+      }
+
+      /* -z all remaining options are for simulator */
+      if (strcmp(argv[i],"-z") == 0) {
+        passon_args_flag = 1;
+        continue ;
+      }
+
       /* the simulator arguments */
 
       /* cpu */
@@ -763,34 +843,16 @@ static void parseCmdLine (int argc, char **argv)
       }
 
       /* serial port */
-      if (strcmp(argv[i],"-s") == 0) {
+      if ( (strcmp(argv[i],"-S") == 0) ||
+           (strcmp(argv[i],"-s") == 0)) {
         simArgs[nsimArgs++] = "-s";
         simArgs[nsimArgs++] = strdup(argv[++i]);
         continue ;
       }
 
-      if (strcmp(argv[i],"-S") == 0) {
-        simArgs[nsimArgs++] = "-s";
-        simArgs[nsimArgs++] = strdup(argv[++i]);
-        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 {
       /* must be file name */
       if (filename) {
@@ -815,6 +877,7 @@ static void parseCmdLine (int argc, char **argv)
 int main ( int argc, char **argv)
 {
     printVersionInfo();
+    printf("WARNING: SDCDB is EXPERIMENTAL and NOT A FULLY FUNCTIONING TOOL.\n");
 
     simArgs[nsimArgs++] = "s51";
     simArgs[nsimArgs++] = "-P";
index 0021fd69ed3524fa6bb1617d8a5b6797a608f99b..9593487ea46ba713185556a5383a0160d7b59869 100644 (file)
 #ifndef  SDCDB_H
 #define  SDCDB_H
 
-/* #define SDCDB_DEBUG */
+#define SDCDB_DEBUG
 
 #ifdef SDCDB_DEBUG
 // set D_x to 0 to turn off, 1 to turn on.
-#define D_break  1
-#define D_simi   1
-#define D_sdcdb  1
-#define D_symtab 1
+#define D_break  0
+#define D_simi   0
+#define D_sdcdb  0
+#define D_symtab 0
 
 #define Dprintf(f, fs) {if (f) printf fs ; }
 #else
index 168f02eb6e15e1fdd8496f7186e646818275c3c6..aac8f253fd5b5b92f02212708777d05b92e384ab 100644 (file)
@@ -198,7 +198,8 @@ unsigned long simGetValue (unsigned int addr,char mem, int size)
        break;
     case 'H':
     case 'J':
-       prefix = "db" ;
+//     prefix = "db" ;
+       prefix = "dump" ;
        break;
     case 'I':
        prefix = "ds" ;
@@ -219,11 +220,14 @@ unsigned long simGetValue (unsigned int addr,char mem, int size)
     /* first skip thru white space */
     while (isspace(*resp)) resp++ ;
 
+    if (strncmp(resp, "0x",2) == 0)
+      resp += 2;
+
     /* then make the branch for bit variables */
     /* skip thru the address part */
     while (isxdigit(*resp)) resp++;
     
-    if (!strcmp(prefix,"db")) {
+    if (!strcmp(prefix,"dump")) {
 
        /* skip white space */
        while (isspace(*resp)) resp++ ;
@@ -421,6 +425,11 @@ char  *simRegs()
     /* make it some more readable */
     resp  = simResponse();
 
+    return resp;
+
+#if 0
+  Take this out(2-09-02) cant see as its that useful to reformat, karl.
+  
     /* the response is of the form 
        XXXXXX R0 R1 R2 R3 R4 R5 R6 R7 ........
        XXXXXX XX . ACC=0xxx dd cc B=0xxx dd cc DPTR= 0xxxxx @DPTR= 0xxx dd cc
@@ -487,8 +496,7 @@ F  0x006d 75 87 80 MOV   PCON,#80
            getValueStr(resp,"P="));
 
     return regBuff;
-    
-    
+#endif
 
 }
 
index 9e1f8c3481b1a76e417044c9107df905c9e8f784..b52e0b7a0c4ef21998aa058214a17330808bb63b 100644 (file)
@@ -26,7 +26,7 @@
 #define  SIMI_H
 
 #define MAX_SIM_BUFF 8*1024
-#define SIMNAME "s51"
+//#define SIMNAME "s51"
 extern char simactive;
 void  openSimulator (char **,int);
 void  waitForSim ();
index 5a1c1bb7bd6fa72103ad65c469ab7a3bdadb702c..1305cc3ee8f610f8b2bbc8a5fdc982db4e98997d 100644 (file)
@@ -544,27 +544,33 @@ symbol *symLookup (char *name, context *ctxt)
 {
     symbol *sym = NULL ;
 
-    /* first try & find a local variable for the
-       given name */
-    if ( applyToSet(symbols,symLocal,
+    if ((ctxt) && (ctxt->func) &&
+        (ctxt->func->sym) && (ctxt->func->sym->name)) {
+      /* first try & find a local variable for the given name */
+      if ( applyToSet(symbols,symLocal,
         name,
         ctxt->func->sym->name,
         ctxt->block,
         ctxt->level,
         &sym))
-  return sym;
+         return sym;
+      sym = NULL;
+    }
+
+    if ((ctxt) && (ctxt->func) &&
+        (ctxt->func->mod) && (ctxt->func->mod->name)) {
+      /* then try local to this module */
+      if (applyToSet(symbols,symLocal,
+          name,
+          ctxt->func->mod->name,
+          0,0,&sym))
+             return sym;
+      sym = NULL;
+    }
 
-    sym = NULL;
-    /* then try local to this module */
-    if (applyToSet(symbols,symLocal,
-       name,
-       ctxt->func->mod->name,
-       0,0,&sym))
-  return sym;
-    sym = NULL;
     /* no:: try global */
     if ( applyToSet(symbols,symGlobal,name,&sym))
-  return sym;
+      return sym;
 
     /* cannot find return null */
     return NULL;