From 412d4b5859358565f766960414786e0b173ad77e Mon Sep 17 00:00:00 2001 From: kbongers Date: Sat, 17 May 2003 06:18:42 +0000 Subject: [PATCH] Martins changes git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2623 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- debugger/mcs51/break.c | 50 ++++++++++++++++--- debugger/mcs51/break.h | 7 ++- debugger/mcs51/cmd.c | 35 ++++++++++++- debugger/mcs51/cmd.h | 2 +- debugger/mcs51/sdcdb.c | 109 +++++++++++++++++++++++++++++++---------- debugger/mcs51/sdcdb.h | 3 +- 6 files changed, 170 insertions(+), 36 deletions(-) diff --git a/debugger/mcs51/break.c b/debugger/mcs51/break.c index c7f3fb94..8e5065e4 100644 --- a/debugger/mcs51/break.c +++ b/debugger/mcs51/break.c @@ -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; diff --git a/debugger/mcs51/break.h b/debugger/mcs51/break.h index 7256f519..e856d0dc 100644 --- a/debugger/mcs51/break.h +++ b/debugger/mcs51/break.h @@ -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(); diff --git a/debugger/mcs51/cmd.c b/debugger/mcs51/cmd.c index 626994c6..0c584c20 100644 --- a/debugger/mcs51/cmd.c +++ b/debugger/mcs51/cmd.c @@ -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 */ /*-----------------------------------------------------------------*/ diff --git a/debugger/mcs51/cmd.h b/debugger/mcs51/cmd.h index 42e3cbf7..ce0d165e 100644 --- a/debugger/mcs51/cmd.h +++ b/debugger/mcs51/cmd.h @@ -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 *); diff --git a/debugger/mcs51/sdcdb.c b/debugger/mcs51/sdcdb.c index c9f6d40e..d5c7a44b 100644 --- a/debugger/mcs51/sdcdb.c +++ b/debugger/mcs51/sdcdb.c @@ -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 ' 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; } diff --git a/debugger/mcs51/sdcdb.h b/debugger/mcs51/sdcdb.h index 5f8af678..3cf43b8c 100644 --- a/debugger/mcs51/sdcdb.h +++ b/debugger/mcs51/sdcdb.h @@ -267,5 +267,6 @@ extern short fullname; extern int srcMode; extern char contsim; char *searchDirsFname (char *); - +char *getNextCmdLine(void ); +void setCmdLine( char * ); #endif -- 2.30.2