"FEXIT", "TMPUSER", ""};
#endif
+static long bpnum = 0;
+
+long getLastBreakptNumber()
+{
+ return bpnum;
+}
+
/*-----------------------------------------------------------------*/
/* setBreakPoint - creates an entry in the break point table */
/*-----------------------------------------------------------------*/
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",
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 */
/*-----------------------------------------------------------------*/
}
/* 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) {
fprintf(stdout,"%d\t%s",ctxt->asmline+1,
ctxt->func->mod->asmLines[ctxt->asmline]->src);
}
+
if ( bpType == TMPUSER && bpnum > 0 )
deleteUSERbp (bpnum);
return 1;
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;
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();
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 */
/*-----------------------------------------------------------------*/
return 0;
}
-
/*-----------------------------------------------------------------*/
/* cmdSimulator - send command to simulator */
/*-----------------------------------------------------------------*/
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 *);
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
{
{ "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" },
/*-----------------------------------------------------------------*/
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;
}
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;
- }
}
/*-----------------------------------------------------------------*/
setsignals();
parseCmdLine(argc,argv);
- commandLoop();
+ commandLoop(stdin);
return 0;
}
extern int srcMode;
extern char contsim;
char *searchDirsFname (char *);
-
+char *getNextCmdLine(void );
+void setCmdLine( char * );
#endif