From: kbongers Date: Mon, 6 Aug 2001 00:16:49 +0000 (+0000) Subject: Get debugger working X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=b225ad4b7481128235e8868007618cf111985ade;p=fw%2Fsdcc Get debugger working git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1130 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/debugger/mcs51/break.c b/debugger/mcs51/break.c index 4e5c263c..75f5b72a 100644 --- a/debugger/mcs51/break.c +++ b/debugger/mcs51/break.c @@ -31,6 +31,19 @@ char userBpPresent = 0; /* call stack can be 1024 deep */ STACK_DCL(callStack,function *,1024); +#ifdef SDCDB_DEBUG +char *debug_bp_type_strings[] = + {"ERR-0", + "DATA", + "CODE" , + "A_CODE" , + "USER" , + "STEP" , + "NEXT" , + "FENTRY" , + "FEXIT", "", ""}; +#endif + /*-----------------------------------------------------------------*/ /* setBreakPoint - creates an entry in the break point table */ /*-----------------------------------------------------------------*/ @@ -42,6 +55,12 @@ int setBreakPoint (unsigned addr, char addrType, char bpType, static long bpnum = 0; char simbuf[50]; + Dprintf(D_break, ("setBreakPoint: addr:%x atype:%s bpType:%s [%s:%d]\n", + addr, + debug_bp_type_strings[addrType], + debug_bp_type_strings[bpType], + fileName, lineno)); + /* allocate & init a new bp */ bp = Safe_calloc(1,sizeof(breakp)); bp->addr = addr; @@ -91,6 +110,7 @@ void deleteSTEPbp () breakp *bp; int k; + Dprintf(D_break, ("Deleting all STEP BPs\n")); /* for break points delete if they are STEP */ for ( bp = hTabFirstItem(bptable,&k); bp ; bp = hTabNextItem(bptable,&k)) { @@ -119,6 +139,8 @@ void deleteNEXTbp () int k; char simcmd[50]; + Dprintf(D_break, ("Deleting all NEXT BPs\n")); + /* for break points delete if they are NEXT */ for ( bp = hTabFirstItem(bptable,&k); bp ; bp = hTabNextItem(bptable,&k)) { @@ -149,6 +171,8 @@ void deleteUSERbp (int bpnum) int k; char simcmd[50]; + Dprintf(D_break, ("deleteUSERbp %d\n", bpnum)); + /* for break points delete if they are STEP */ for ( bp = hTabFirstItem(bptable,&k); bp ; bp = hTabNextItem(bptable,&k)) { @@ -163,6 +187,7 @@ void deleteUSERbp (int bpnum) send command to simulator to delete bp from this addr */ if (hTabSearch(bptable,bp->addr) == NULL) { simClearBP (bp->addr); + Dprintf(D_break, ("deleteUSERbp:simClearBP 0x%x\n", bp->addr)); } fprintf(stdout,"Deleted breakpoint %d\n", @@ -256,6 +281,8 @@ int dispatchCB (unsigned addr, context *ctxt) breakp *bp; int rv =0; + Dprintf(D_break, ("dispatchCB: addr:0x%x \n", addr)); + /* if no break points set for this address then use a simulator stop break point */ if ((bp = hTabFirstItemWK(bptable,addr)) == NULL) { @@ -270,6 +297,10 @@ int dispatchCB (unsigned addr, context *ctxt) } + if (rv == 0) { + Dprintf(D_break, ("dispatchCB: WARNING rv==0\n", rv)); + } + return rv; } @@ -278,6 +309,8 @@ int dispatchCB (unsigned addr, context *ctxt) /*-----------------------------------------------------------------*/ BP_CALLBACK(fentryCB) { + Dprintf(D_break, ("fentryCB: BP_CALLBACK entry\n")); + /* add the current function into the call stack */ STACK_PUSH(callStack,ctxt->func); @@ -293,6 +326,8 @@ BP_CALLBACK(fentryCB) /*-----------------------------------------------------------------*/ BP_CALLBACK(fexitCB) { + Dprintf(D_break, ("fexitCB: BP_CALLBACK entry\n")); + /* pop the top most from the call stack */ STACK_POP(callStack); return 0; @@ -302,6 +337,8 @@ BP_CALLBACK(fexitCB) /*-----------------------------------------------------------------*/ BP_CALLBACK(userBpCB) { + Dprintf(D_break, ("userBpCB: BP_CALLBACK entry\n")); + if (srcMode == SRC_CMODE) { fprintf(stdout,"Breakpoint %d, %s() at %s:%d\n", bpnum, @@ -332,6 +369,8 @@ BP_CALLBACK(stepBpCB) { static function *lfunc = NULL; + Dprintf(D_break, ("stepBpCB: BP_CALLBACK entry\n")); + if (srcMode == SRC_CMODE) { if ((lfunc && lfunc != ctxt->func) || !lfunc) fprintf(stdout,"%s () at %s:%d\n", @@ -368,6 +407,8 @@ BP_CALLBACK(nextBpCB) { static function *lfunc = NULL; + Dprintf(D_break, ("nextBpCB: BP_CALLBACK entry\n")); + if (srcMode == SRC_CMODE) { if ((lfunc && lfunc != ctxt->func) || !lfunc) fprintf(stdout,"%s () at %s:%d\n", diff --git a/debugger/mcs51/break.h b/debugger/mcs51/break.h index 7b6d9893..e5985022 100644 --- a/debugger/mcs51/break.h +++ b/debugger/mcs51/break.h @@ -37,7 +37,6 @@ enum { FENTRY , FEXIT}; - typedef struct breakp { unsigned addr; /* address of break point */ diff --git a/debugger/mcs51/cmd.c b/debugger/mcs51/cmd.c index 89dfe6a5..7c0b474b 100644 --- a/debugger/mcs51/cmd.c +++ b/debugger/mcs51/cmd.c @@ -540,8 +540,10 @@ context *discoverContext (unsigned addr) int line = 0; /* find the function we are in */ - if (!applyToSet(functions,funcInAddr,addr,&func)) - return NULL; + if (!applyToSet(functions,funcInAddr,addr,&func)) { + fprintf(stderr, "Error?:discoverContext: cannot apply to set!\n"); + return NULL; + } currCtxt->func = func; currCtxt->addr = func->laddr = addr; @@ -592,8 +594,30 @@ void simGo (unsigned int gaddr) if not then we continue with the execution of the program */ if (!rv) { + fprintf(stdout, "Stopping at non-user breakpoint\n"); + +// notes: kpb +// I took this out, after running "run" it would just keep re-running +// even after a lot of break points hit. For some reason above code +// not triggering(dispatchCB). This seems to be by design, startup adds +// a bunch of breakpoints-but they are not USER breakpoints. Perhaps the +// debugger changed with its implementation of "go"("run"). It seems we +// need to add a "next" or "step" followed by a "run"... +// I added a "step" in simi.c when we want a resume function, this seems +// to work. + +// still there is question of how do we stop it initially, since +// it must be started before it can get a context. If so, we would +// want it to just run up to an initial entry point you'd think... +// I don't see why we can't set breakpoints before an initial run, +// this does not seem right to me. + +// line #'s are a bit off too. + +#if 0 gaddr = -1; goto top ; +#endif } } @@ -1574,8 +1598,15 @@ int cmdClrUserBp (char *s, context *cctxt) /*-----------------------------------------------------------------*/ int cmdSimulator (char *s, context *cctxt) { - sendSim(s); - sendSim("\n"); + char tmpstr[82]; + + if (strlen(s) > 80) { + printf("error 3A\n"); + exit(1); + } + strcpy(tmpstr, s); + strcat(tmpstr, "\n"); + sendSim(tmpstr); waitForSim(); fprintf(stdout,"%s",simResponse()); return 0; diff --git a/debugger/mcs51/sdcdb.c b/debugger/mcs51/sdcdb.c index f23dba38..a416625a 100644 --- a/debugger/mcs51/sdcdb.c +++ b/debugger/mcs51/sdcdb.c @@ -430,12 +430,11 @@ static void functionPoints () sym = func->sym; -#ifdef SDCDB_DEBUG - printf("func '%s' has entry '%x' exit '%x'\n", + Dprintf(D_sdcdb, ("func '%s' has entry '%x' exit '%x'\n", func->sym->name, func->sym->addr, - func->sym->eaddr); -#endif + func->sym->eaddr)); + if (!func->sym->addr && !func->sym->eaddr) continue ; @@ -496,20 +495,21 @@ static void functionPoints () } #ifdef SDCDB_DEBUG - printf("function '%s' has the following C exePoints\n", - func->sym->name); + Dprintf(D_sdcdb, ("function '%s' has the following C exePoints\n", + func->sym->name)); { exePoint *ep; for (ep = setFirstItem(func->cfpoints); ep; ep = setNextItem(func->cfpoints)) - fprintf (stdout,"{%x,%d} %s",ep->addr,ep->line,mod->cLines[ep->line]->src); + Dprintf(D_sdcdb, ("{%x,%d} %s", + ep->addr,ep->line,mod->cLines[ep->line]->src)); - fprintf(stdout," and the following ASM exePoints\n"); + Dprintf(D_sdcdb, (" and the following ASM exePoints\n")); for (ep = setFirstItem(func->afpoints); ep; - ep = setNextItem(func->afpoints)) - fprintf (stdout,"{%x,%d} %s",ep->addr,ep->line,mod->asmLines[ep->line]->src); - + ep = setNextItem(func->afpoints)) + Dprintf (D_sdcdb, ("{%x,%d} %s", + ep->addr,ep->line,mod->asmLines[ep->line]->src)); } #endif } diff --git a/debugger/mcs51/sdcdb.h b/debugger/mcs51/sdcdb.h index b91ae279..0021fd69 100644 --- a/debugger/mcs51/sdcdb.h +++ b/debugger/mcs51/sdcdb.h @@ -26,6 +26,18 @@ /* #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 Dprintf(f, fs) {if (f) printf fs ; } +#else +#define Dprintf(f, fs) { } +#endif + #include #include #include diff --git a/debugger/mcs51/simi.c b/debugger/mcs51/simi.c index 16e25b7e..12430d1e 100644 --- a/debugger/mcs51/simi.c +++ b/debugger/mcs51/simi.c @@ -54,19 +54,20 @@ void readSim(int resetp) if (resetp) sbp = simibuff; -#ifdef SDCDB_DEBUG - fprintf(stderr,"stderr--> reading from sim\n"); -#endif + Dprintf(D_simi, ("readSim: reading from sim[")); while ((ch = fgetc(simin))) { + #ifdef SDCDB_DEBUG - fputc(ch,stdout); + if (D_simi) { + fputc(ch,stdout); + } #endif + *sbp++ = ch; } -#ifdef SDCDB_DEBUG - fprintf(stderr,"stderr--> reading from sim done\n"); -#endif + + Dprintf(D_simi, ("] end readSim\n")); *sbp = '\0'; } @@ -97,9 +98,7 @@ void openSimulator (char **args, int nargs) /* fork and start the simulator as a subprocess */ if ((simPid = fork())) { -#ifdef SDCDB_DEBUG - printf("simulator pid %d\n",(int) simPid); -#endif + Dprintf(D_simi, ("simulator pid %d\n",(int) simPid)); } else { @@ -159,6 +158,7 @@ char *simResponse() /*-----------------------------------------------------------------*/ void sendSim(char *s) { + Dprintf(D_simi, ("sendSim-->%s", s)); // s has LF at end already fputs(s,simout); fflush(simout); } @@ -280,7 +280,7 @@ void simLoadFile (char *s) { char buff[128]; - sprintf(buff,"l %s\n",s); + sprintf(buff,"l \"%s\"\n",s); printf(buff); sendSim(buff); waitForSim(); @@ -295,12 +295,41 @@ unsigned int simGoTillBp ( unsigned int gaddr) unsigned addr ; char *sfmt; + /* kpb: new code 8-03-01 */ + if (gaddr == 0) { + /* initial start, start & stop from address 0 */ + 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.. + //sendSim("break 0x0\n"); + //sleep(1); + //waitForSim(); + + sendSim("run 0x0\n"); + sleep(1); /* do I need this? */ + } else if (gaddr == -1) { /* resume */ + + // try adding this(kpb) + sendSim("step\n"); + usleep(100000); + waitForSim(); + + sendSim ("run\n"); + } + 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(); @@ -327,15 +356,18 @@ unsigned int simGoTillBp ( unsigned int gaddr) sr++; } - if (!*sr) return 0; + if (!*sr) { + fprintf(stderr, "Error?, simGoTillBp failed to Stop\n"); + return 0; + } while (isspace(*sr)) sr++ ; - if (sscanf(sr,sfmt,&addr) != 1) - return 0; - else + if (sscanf(sr,sfmt,&addr) != 1) { + fprintf(stderr, "Error?, simGoTillBp failed to get Addr\n"); + return 0; + } return addr; - } @@ -378,7 +410,9 @@ char *simRegs() char *rb = regBuff; int i; - sendSim("dr\n"); + sendSim("info registers\n"); + //kpb(8-5-01) sendSim("dr\n"); + waitForSim(); /* make it some more readable */ resp = simResponse(); @@ -386,10 +420,24 @@ char *simRegs() /* 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 - XXXXXX XX . PSW= 0xxx CY=[1|0] AC=[0|1] OV=[0|1] P=[1|0] */ + XXXXXX XX . PSW= 0xxx CY=[1|0] AC=[0|1] OV=[0|1] P=[1|0] + +Format as of 8-4-01: + 0x00 00 00 00 00 00 00 00 00 ........ + 000000 00 . ACC= 0x00 0 . B= 0x00 DPTR= 0x0000 @DPTR= 0x00 0 . + 000000 00 . PSW= 0x00 CY=0 AC=0 OV=0 P=0 +F 0x006d 75 87 80 MOV PCON,#80 +*/ + memset(regBuff,0,sizeof(regBuff)); /* skip the first numerics */ while (*resp && !isxdigit(*resp)) resp++; + + if (strncmp(resp, "0x", 2)) { + fprintf(stderr, "Error: Format1A\n"); + return regBuff; + } + resp += 2; while (*resp && isxdigit(*resp)) resp++; /* now get the eight registers */ diff --git a/debugger/mcs51/symtab.c b/debugger/mcs51/symtab.c index 0e5b8c6a..5a1c1bb7 100644 --- a/debugger/mcs51/symtab.c +++ b/debugger/mcs51/symtab.c @@ -590,9 +590,8 @@ static void lnkFuncEnd (char *s) s++; sscanf(s,"%x",&func->sym->eaddr); -#ifdef SDCDB_DEBUG - printf("%s(eaddr%x)\n",func->sym->name,func->sym->eaddr); -#endif + + Dprintf(D_symtab, ("%s(eaddr%x)\n",func->sym->name,func->sym->eaddr)); } /*-----------------------------------------------------------------*/ @@ -616,9 +615,8 @@ static void lnkSymRec (char *s) s++; sscanf(s,"%x",&sym->addr); -#ifdef SDCDB_DEBUG - printf("%s(%x)\n",sym->name,sym->addr); -#endif + + Dprintf(D_symtab, ("%s(%x)\n",sym->name,sym->addr)); } /*-----------------------------------------------------------------*/ @@ -648,9 +646,7 @@ static void lnkAsmSrc (char *s) line--; if (line < mod->nasmLines) { mod->asmLines[line]->addr = addr; -#ifdef SDCDB_DEBUG - printf("%s(%d:%x) %s",mod->asm_name,line,addr,mod->asmLines[line]->src); -#endif + Dprintf(D_symtab, ("%s(%d:%x) %s",mod->asm_name,line,addr,mod->asmLines[line]->src)); } } @@ -690,10 +686,8 @@ static void lnkCSrc (char *s) mod->cLines[line]->addr = addr; mod->cLines[line]->block = block; mod->cLines[line]->level = level; -#ifdef SDCDB_DEBUG - printf("%s(%d:%x) %s",mod->c_name, - line+1,addr,mod->cLines[line]->src); -#endif + Dprintf(D_symtab, ("%s(%d:%x) %s",mod->c_name, + line+1,addr,mod->cLines[line]->src)); } return;