Martins changes
authorkbongers <kbongers@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 17 May 2003 06:18:42 +0000 (06:18 +0000)
committerkbongers <kbongers@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 17 May 2003 06:18:42 +0000 (06:18 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2623 4a8a32a2-be11-0410-ad9d-d568d2c75423

debugger/mcs51/break.c
debugger/mcs51/break.h
debugger/mcs51/cmd.c
debugger/mcs51/cmd.h
debugger/mcs51/sdcdb.c
debugger/mcs51/sdcdb.h

index c7f3fb943ab933b9da01ce8661216207ab8e13f3..8e5065e409e0a5f7e48118ba7c8417f154e9d7c2 100644 (file)
@@ -46,6 +46,13 @@ char *debug_bp_type_strings[] =
     "FEXIT", "TMPUSER", ""};
 #endif
 
+static long bpnum = 0;
+
+long getLastBreakptNumber()
+{
+    return bpnum;
+}
+
 /*-----------------------------------------------------------------*/
 /* setBreakPoint - creates an entry in the break point table       */
 /*-----------------------------------------------------------------*/
@@ -54,7 +61,6 @@ int setBreakPoint (unsigned addr, char addrType, char bpType,
         char *fileName, int lineno)
 {
     breakp *bp, *bpl;
-    static long bpnum = 0;
     char simbuf[50];
 
     Dprintf(D_break, ("setBreakPoint: addr:%x atype:%s bpType:%s [%s:%d]\n",
@@ -199,6 +205,31 @@ void deleteUSERbp (int bpnum)
   fprintf(stderr,"No breakpoint number %d.\n",bpnum);
 }
 
+/*-----------------------------------------------------------------*/
+/* setUserbpCommand - set commandstring for breakpoint             */
+/*-----------------------------------------------------------------*/
+void setUserbpCommand (int bpnum, char *cmds)
+{
+    breakp *bp;
+    int k;
+    Dprintf(D_break, ("break: setUserbpCommand %d: commands:\n%send\n",
+                      bpnum, cmds));
+
+    for ( bp = hTabFirstItem(bptable,&k); bp ;
+          bp = hTabNextItem(bptable,&k)) 
+    {
+        if ((bp->bpType == USER || bp->bpType == TMPUSER )
+            && ( bp->bpnum == bpnum )) 
+        {
+            if ( bp->commands )
+                Safe_free(bp->commands);
+            bp->commands = cmds;
+            return;
+        }
+    }
+    fprintf(stderr,"No breakpoint number %d.\n",bpnum);
+}
+
 /*-----------------------------------------------------------------*/
 /* listUSERbp - list all user break points                         */
 /*-----------------------------------------------------------------*/
@@ -294,11 +325,17 @@ int dispatchCB (unsigned addr, context *ctxt)
     }
 
     /* dispatch the call back functions */
-    for (; bp; bp = hTabNextItemWK(bptable)) {
-
-      rv += (*bp->callBack)(addr,bp->addrType,
-          bp->bpType,bp->bpnum,ctxt);
-
+    for (; bp; bp = hTabNextItemWK(bptable)) 
+    {
+        if ( bp->commands )
+        {
+            char save_ch;
+            Dprintf(D_break, ("break: dispatchCB: commands:\n%send\n", bp->commands));
+            setCmdLine(bp->commands);
+        }
+    
+        rv += (*bp->callBack)(addr,bp->addrType,
+                              bp->bpType,bp->bpnum,ctxt);
     }
 
     if (rv == 0) {
@@ -381,6 +418,7 @@ BP_CALLBACK(userBpCB)
       fprintf(stdout,"%d\t%s",ctxt->asmline+1,
         ctxt->func->mod->asmLines[ctxt->asmline]->src);
     }
+
     if ( bpType == TMPUSER && bpnum > 0 )
         deleteUSERbp (bpnum);
     return 1;
index 7256f519466a900da2a43e29ef355ab162a5a5e6..e856d0dcb24f35055292924e765b701578dfa0db 100644 (file)
@@ -47,7 +47,9 @@ typedef struct breakp
     char     *filename;      /* file name */
     int      lineno  ;       /* lineno */
     int (*callBack)
-        (unsigned,char,char,int,context *);/* address of call back function */
+          (unsigned,char,char,int,context *);/* address of call back
+                                         * function */
+    char *commands;
 } breakp;
 
 
@@ -68,9 +70,12 @@ typedef struct breakp
 extern char userBpPresent;
 extern char doingSteps;
 
+
 int setBreakPoint (unsigned , char , char, 
                    int (*callBack)(unsigned,char,char,int,context *),char *, int);
 
+extern long getLastBreakptNumber(void);
+
 void  clearUSERbp ( unsigned int  );
 void  deleteSTEPbp();
 void  deleteNEXTbp();
index 626994c6537ae9a86cb43af2f140fcf0ef2b5192..0c584c20068b2efa2ce5ec767e8fca61901eddff 100644 (file)
@@ -1301,6 +1301,40 @@ int cmdContinue (char *s, context *cctxt)
     return 0;
 }
 
+/*-----------------------------------------------------------------*/
+/* cmdCommands - set commands for breakpoint                       */
+/*-----------------------------------------------------------------*/
+int cmdCommands (char *s, context *cctxt)
+{   
+    int bpnum ;
+    char *cmds,*line;
+    while (isspace(*s)) s++;
+    
+    if (!*s ) 
+        bpnum = getLastBreakptNumber();
+    else
+        bpnum = strtol(s,0,10);
+
+    cmds = NULL;
+    while ((line = getNextCmdLine()))
+    {
+        while (isspace(*line)) line++;
+        if (!strncmp(line,"end",3))
+            break;
+        if (! cmds )
+        {
+            cmds = Safe_strdup(line);
+        }
+        else
+        {
+            cmds = Safe_realloc( cmds, strlen(cmds) + 1 + strlen(line));
+            strcat(cmds,line);
+        }
+    }
+    setUserbpCommand(bpnum,cmds);
+    return 0;
+}
+
 /*-----------------------------------------------------------------*/
 /* cmdDelUserBp - delete user break point                          */
 /*-----------------------------------------------------------------*/
@@ -3016,7 +3050,6 @@ int cmdClrUserBp (char *s, context *cctxt)
     return 0;        
 }
 
-
 /*-----------------------------------------------------------------*/
 /* cmdSimulator - send command to simulator                        */
 /*-----------------------------------------------------------------*/
index 42e3cbf7de56382bc4a0c381b468891bd6ab645d..ce0d165e90d8770173501233cb263b23c98118ea 100644 (file)
@@ -46,7 +46,7 @@ extern int cmdFile      (char *, context *);
 extern int cmdInfo      (char *, context *);
 extern int cmdShow      (char *, context *);
 extern int cmdFinish    (char *, context *);
-
+extern int cmdCommands  (char *, context *);
 extern int cmdStepi     (char *, context *);
 extern int cmdNexti     (char *, context *);
 extern int cmdUp        (char *, context *);
index c9f6d40e8f8154879fc0cb7b03de2ba0f5de5d09..d5c7a44becc444fd2b7f0f6ce7ff4849d7a64af8 100644 (file)
@@ -52,12 +52,13 @@ char *ssdirl = DATADIR LIB_DIR_SUFFIX ":" DATADIR LIB_DIR_SUFFIX "/small" ;
 char *simArgs[40];
 int nsimArgs = 0;
 char model_str[20];
-
 /* fake filename & lineno to make linker */
 char *filename=NULL;
 int lineno = 0;
 int fatalError = 0;
 
+static void commandLoop(FILE *cmdfile);
+
 /* command table */
 struct cmdtab
 {
@@ -88,6 +89,9 @@ struct cmdtab
     { "continue" ,  cmdContinue   ,
       "{c}ontinue\t\t Continue program being debugged, after breakpoint.\n"
     },
+    { "commands" ,  cmdCommands  ,
+      "commands [brkpoint number]\t\tSetting commands for breakpoint.\n"
+    },
     { "c"        ,  cmdContinue   , NULL },
 
     { "disassemble",cmdDisasmF    , "disassemble [startaddr [endaddress]]\tdisassemble asm commands\n" },
@@ -678,7 +682,22 @@ int cmdFile (char *s,context *cctxt)
 /*-----------------------------------------------------------------*/
 int cmdSource (char *s, context *cctxt)
 {
-    fprintf(stderr,"'source <file>' command not yet implemented\n",s);
+    FILE *cmdfile;
+    char *bp = s+strlen(s) -1;
+
+    while (isspace(*s))
+      ++s;
+
+    while (isspace(*bp)) bp--;
+    *++bp = '\0';
+
+    if (!( cmdfile = searchDirsFopen(s)))
+    {
+        fprintf(stderr,"commandfile '%s' not found\n",s);
+        return 0;
+    }
+    commandLoop( cmdfile );
+    fclose( cmdfile );
     return 0;
 }
 
@@ -815,37 +834,75 @@ int interpretCmd (char *s)
     return rv;
 }
 
+static FILE *actualcmdfile=NULL ;
+static char *actualcmds=NULL;
+
 /*-----------------------------------------------------------------*/
-/* commandLoop - the main command loop                             */
+/* getNextCmdLine get additional lines used by special commands    */
 /*-----------------------------------------------------------------*/
-void commandLoop()
+char *getNextCmdLine()
+{
+    if (!actualcmdfile)
+        return NULL;
+    if (fgets(cmdbuff,sizeof(cmdbuff),actualcmdfile) == NULL)
+        return NULL;
+    return cmdbuff;
+}
+
+void setCmdLine( char *cmds )
 {
char *prompt = "(sdcdb) ";
- char *sim_prompt = "(sim) ";
   actualcmds = cmds;
+}
 
-  while (1) {
-    if (sim_cmd_mode)
-      printf("%s",sim_prompt);
-    else
-      fprintf(stdout,"%s",prompt);
+/*-----------------------------------------------------------------*/
+/* commandLoop - the main command loop or loop over command file   */
+/*-----------------------------------------------------------------*/
+static void commandLoop(FILE *cmdfile)
+{
+    char *line, save_ch, *s;
+    actualcmdfile = cmdfile;
+    while (1) 
+    {
+        if ( cmdfile == stdin )
+        {
+            if (sim_cmd_mode)
+                printf("(sim) ");
+            else
+                fprintf(stdout,"(sdcdb) ");        
+            fflush(stdout);
+        }
 
-    fflush(stdout);
+        if (fgets(cmdbuff,sizeof(cmdbuff),cmdfile) == NULL)
+            break;
 
-    if (fgets(cmdbuff,sizeof(cmdbuff),stdin) == NULL)
-      break;
+        if (interpretCmd(cmdbuff))
+            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;
+        while ( actualcmds )
+        {
+            strcpy(cmdbuff,actualcmds);
+            actualcmds = NULL;
+            for ( line = cmdbuff; *line ; line = s )
+            {
+                if ( (s=strchr(line ,'\n')))
+                {
+                    save_ch = *++s;
+                    *s = '\0';
+                }
+                else
+                {
+                    s += strlen( line );
+                    save_ch = '\0';
+                }
+                if (interpretCmd( line ))
+                {
+                    *s = save_ch;
+                    break;
+                }
+                *s = save_ch;
+            }
+        }
     }
-#endif
-
-    if (interpretCmd(cmdbuff))
-      break;
-  }
 }
 
 /*-----------------------------------------------------------------*/
@@ -1057,7 +1114,7 @@ int main ( int argc, char **argv)
     setsignals();
     parseCmdLine(argc,argv);
 
-    commandLoop();
+    commandLoop(stdin);
 
     return 0;
 }
index 5f8af6789a456d7b88d4906ccc4a6060b76eaf55..3cf43b8ce2a229c51140b96c2e1624bc82c2a869 100644 (file)
@@ -267,5 +267,6 @@ extern short fullname;
 extern int srcMode;
 extern char contsim;
 char *searchDirsFname (char *);
-
+char *getNextCmdLine(void );
+void setCmdLine( char * );
 #endif