From 4e7244922cb6d5ab03e0331e4818ea0c36a16105 Mon Sep 17 00:00:00 2001 From: kbongers Date: Mon, 11 Feb 2002 04:42:08 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1918 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- debugger/mcs51/cmd.c | 2 +- debugger/mcs51/sdcdb.c | 4 +- debugger/mcs51/sdcdb.h | 6 +- debugger/mcs51/simi.c | 174 +++++++++++++++++++++-------------------- debugger/mcs51/simi.h | 2 +- 5 files changed, 96 insertions(+), 92 deletions(-) diff --git a/debugger/mcs51/cmd.c b/debugger/mcs51/cmd.c index 0a14e2b8..739fa0a3 100644 --- a/debugger/mcs51/cmd.c +++ b/debugger/mcs51/cmd.c @@ -1925,7 +1925,7 @@ int cmdSimulator (char *s, context *cctxt) strcpy(tmpstr, s); strcat(tmpstr, "\n"); sendSim(tmpstr); - waitForSim(); + waitForSim(200,NULL); fprintf(stdout,"%s",simResponse()); return 0; } diff --git a/debugger/mcs51/sdcdb.c b/debugger/mcs51/sdcdb.c index 3cb7fd59..4a406fb1 100644 --- a/debugger/mcs51/sdcdb.c +++ b/debugger/mcs51/sdcdb.c @@ -40,7 +40,7 @@ linkrec **linkrecs = NULL; /* all linkage editor records */ context *currCtxt = NULL; short fullname = 0; char *ssdirl = SDCC_LIB_DIR ":" SDCC_LIB_DIR "/small" ; -char *simArgs[20]; +char *simArgs[40]; int nsimArgs = 0; char model_str[20]; @@ -766,6 +766,8 @@ static void parseCmdLine (int argc, char **argv) char *filename = NULL; int passon_args_flag = 0; /* if true, pass on args to simulator */ + Dprintf(D_sdcdb, ("parseCmdLine\n")); + for ( i = 1; i < argc ; i++) { //fprintf(stdout,"%s\n",argv[i]); diff --git a/debugger/mcs51/sdcdb.h b/debugger/mcs51/sdcdb.h index 9593487e..9a3c1d58 100644 --- a/debugger/mcs51/sdcdb.h +++ b/debugger/mcs51/sdcdb.h @@ -24,13 +24,13 @@ #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 0 -#define D_simi 0 -#define D_sdcdb 0 +#define D_simi 1 +#define D_sdcdb 1 #define D_symtab 0 #define Dprintf(f, fs) {if (f) printf fs ; } diff --git a/debugger/mcs51/simi.c b/debugger/mcs51/simi.c index aac8f253..55836bed 100644 --- a/debugger/mcs51/simi.c +++ b/debugger/mcs51/simi.c @@ -44,40 +44,69 @@ static char regBuff[MAX_SIM_BUFF]; static char *sbp = simibuff; /* simulator buffer pointer */ extern char **environ; char simactive = 0; + + +#if 0 +#define MS_SLEEP(_ms) usleep(_ms * 1000) +#endif + /*-----------------------------------------------------------------*/ -/* readSim - reads one character into simulator buffer */ +/* waitForSim - wait till simulator is done its job */ /*-----------------------------------------------------------------*/ -void readSim(int resetp) +void waitForSim(int timeout_ms, char *expect) { - int ch ; - /* if reset required then point to beginning of buffer */ - if (resetp) - sbp = simibuff; - - Dprintf(D_simi, ("readSim: reading from sim[")); + int i=0; + int ch; - while ((ch = fgetc(simin))) { +Dprintf(D_simi, ("waitForSim start(%d)\n", timeout_ms)); + sbp = simibuff; -#ifdef SDCDB_DEBUG - if (D_simi) { - fputc(ch,stdout); - } -#endif + // MS_SLEEP(timeout_ms); dont need, in blocking mode. - *sbp++ = ch; + while ((ch = fgetc(simin))) { + *sbp++ = ch; } + *sbp = 0; + Dprintf(D_simi, ("waitForSim(%d) got[%s]\n", timeout_ms, simibuff)); - Dprintf(D_simi, ("] end readSim\n")); - - *sbp = '\0'; -} +#if 0 + hmmmm, I guess we are not running non-blocking, we may still + need this code...Im not sure how the above works, it must block + until something gets into the buffer, then fgetc() reads down the + buffer... + do { + while ((ch = fgetc(simin))) { + *sbp++ = ch; + } + *sbp = 0; +printf("got1[%s]\n", simibuff); + MS_SLEEP(20); + timeout_ms -= 20; +printf("..\n"); + + if (expect) { + if (strstr(expect, sbp)) { + timeout_ms = 0; + } + } else if (sbp != simibuff) { + timeout_ms = 0; + } + + /* pull in data one more time after delay to try and + guarentee we pull in complete responce line */ + if (timeout_ms <= 0) { +printf(",,\n"); + while ((ch = fgetc(simin))) { + *sbp++ = ch; + } + *sbp = 0; +printf("got2[%s]\n", simibuff); + } + } + while (timeout_ms > 0); +printf("...\n"); +#endif -/*-----------------------------------------------------------------*/ -/* waitForSim - wait till simulator is done its job */ -/*-----------------------------------------------------------------*/ -void waitForSim() -{ - readSim(TRUE); } /*-----------------------------------------------------------------*/ @@ -88,29 +117,18 @@ void openSimulator (char **args, int nargs) struct sockaddr_in sin; int retry = 0; int i ; - -#if 0 - char *simargs[32] = { "s51","-P","-r 9756", NULL }; - - /* create the arguments */ - for ( i = 0 ; i < nargs ;i++) { - simargs[i+3] = args[i]; - } - simargs[i+3]= NULL; -#endif + Dprintf(D_simi, ("openSimulator\n")); /* fork and start the simulator as a subprocess */ if ((simPid = fork())) { Dprintf(D_simi, ("simulator pid %d\n",(int) simPid)); } else { - - /* we are in the child process : start the simulator */ -// if (execvp("s51",simargs) < 0) { - if (execvp(args[0],args) < 0) { - perror("cannot exec simulator"); - exit(1); - } + /* we are in the child process : start the simulator */ + if (execvp(args[0],args) < 0) { + perror("cannot exec simulator"); + exit(1); + } } try_connect: @@ -145,8 +163,8 @@ void openSimulator (char **args, int nargs) exit(1); } - /* now that we have opend wait for the prompt */ - waitForSim(); + /* now that we have opened, wait for the prompt */ + waitForSim(200,NULL); simactive = 1; } /*-----------------------------------------------------------------*/ @@ -209,7 +227,7 @@ unsigned long simGetValue (unsigned int addr,char mem, int size) /* create the simulator command */ sprintf(buffer,"%s 0x%x \n",prefix,addr); sendSim(buffer); - waitForSim(); + waitForSim(100,NULL); resp = simResponse(); /* got the response we need to parse it the response @@ -266,7 +284,7 @@ void simSetBP (unsigned int addr) sprintf(buff,"break 0x%x\n",addr); sendSim(buff); - waitForSim(); + waitForSim(100,NULL); } /*-----------------------------------------------------------------*/ @@ -278,7 +296,7 @@ void simClearBP (unsigned int addr) sprintf(buff,"clear 0x%x\n",addr); sendSim(buff); - waitForSim(); + waitForSim(100,NULL); } /*-----------------------------------------------------------------*/ @@ -291,7 +309,7 @@ void simLoadFile (char *s) sprintf(buff,"l \"%s\"\n",s); printf(buff); sendSim(buff); - waitForSim(); + waitForSim(500,NULL); } /*-----------------------------------------------------------------*/ @@ -302,11 +320,12 @@ unsigned int simGoTillBp ( unsigned int gaddr) char *sr, *svr; unsigned addr ; char *sfmt; + int wait_ms = 1000; - /* kpb: new code 8-03-01 */ if (gaddr == 0) { /* initial start, start & stop from address 0 */ - char buf[20]; + char buf[20]; + // this program is setting up a bunch of breakpoints automatically // at key places. Like at startup & main() and other function // entry points. So we don't need to setup one here.. @@ -314,32 +333,17 @@ unsigned int simGoTillBp ( unsigned int gaddr) //sleep(1); //waitForSim(); - sendSim("run 0x0\n"); - sleep(1); /* do I need this? */ + sendSim("run 0x0\n"); } else if (gaddr == -1) { /* resume */ - - // try adding this(kpb) - sendSim("step\n"); - usleep(100000); - waitForSim(); - - sendSim ("run\n"); + sendSim ("run\n"); + wait_ms = 100; } else { printf("Error, simGoTillBp > 0!\n"); exit(1); } -#if 0 - if (gaddr != -1) { - char buf[20]; - sprintf(buf,"g 0x%x\n",gaddr); - sendSim(buf); - } else - sendSim ("g\n"); -#endif - - waitForSim(); + waitForSim(wait_ms, NULL); /* get the simulator response */ svr = sr = strdup(simResponse()); @@ -349,19 +353,18 @@ unsigned int simGoTillBp ( unsigned int gaddr) [... F* ] we will ignore till we get F* then parse the address */ while (*sr) { - - if (strncmp(sr,"Stop at",7) == 0) { - sr += 7; - sfmt = "%x"; - break; - } - - if (*sr == 'F' && ( *(sr+1) == '*' || *(sr+1) == ' ')) { - sr += 2; - sfmt = "%x"; - break; - } - sr++; + if (strncmp(sr,"Stop at",7) == 0) { + sr += 7; + sfmt = "%x"; + break; + } + + if (*sr == 'F' && ( *(sr+1) == '*' || *(sr+1) == ' ')) { + sr += 2; + sfmt = "%x"; + break; + } + sr++; } if (!*sr) { @@ -385,7 +388,7 @@ unsigned int simGoTillBp ( unsigned int gaddr) void simReset () { sendSim("res\n"); - waitForSim(); + waitForSim(100,NULL); } /*-----------------------------------------------------------------*/ @@ -419,10 +422,9 @@ char *simRegs() int i; sendSim("info registers\n"); - //kpb(8-5-01) sendSim("dr\n"); - waitForSim(); - /* make it some more readable */ + waitForSim(100,NULL); + resp = simResponse(); return resp; diff --git a/debugger/mcs51/simi.h b/debugger/mcs51/simi.h index b52e0b7a..a8c6751d 100644 --- a/debugger/mcs51/simi.h +++ b/debugger/mcs51/simi.h @@ -29,7 +29,7 @@ //#define SIMNAME "s51" extern char simactive; void openSimulator (char **,int); -void waitForSim (); +void waitForSim(int timeout_ms, char *expect); void closeSimulator (); void sendSim(char *); char *simResponse(); -- 2.30.2