From 2f18d948f7f1bfc8551f926c1a903fc0b31de1ed Mon Sep 17 00:00:00 2001 From: kbongers Date: Thu, 24 Apr 2003 15:28:37 +0000 Subject: [PATCH] ddd fixes git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2562 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- debugger/README | 32 +++++++++++++++++++++-- debugger/mcs51/break.c | 22 ++++++++-------- debugger/mcs51/sdcdb.c | 32 ++++++++++++++++------- debugger/mcs51/sdcdb.h | 14 +++++----- debugger/mcs51/simi.c | 58 +++++++---------------------------------- debugger/mcs51/symtab.c | 23 +++++++++++----- 6 files changed, 97 insertions(+), 84 deletions(-) diff --git a/debugger/README b/debugger/README index 34d9c8b9..86b02612 100644 --- a/debugger/README +++ b/debugger/README @@ -1,9 +1,11 @@ sdcc/debugger -SDCDB debugger +SDCDB debugger - Development notes. ====================== -Notes April 23, 2003 + +Notes April 23, 2003 +======================== Martin Helmling added support for ddd GUI debugger. Code added to display assembly, set variables, and other commands to interface to ddd. @@ -40,9 +42,35 @@ Is this a known bug in sdcc ? Also sometimes not the correct breakpoints for stepping found in sdcdb. I try to fix this tomorrow. +Additional patches and notes from Martin(4-24-03): +in the attachment you found three patches: +debugpatch: Only for debugging, you can switch on and off the 4 different + debug and you can grep the debug by the prefix. +signalpatch:Now the simulator stops if the user sends an interrupt + ( or 'ddd' ) and also the simulator does not die by another + user signal. + +sympatch: This is not a feature, THIS is the fix of a BUG !!! + In some circumstances in the *.cdb file the Symbol record + comes before the function record. So the symbol was + generated TWO TIMES in the symbol list. The L:G and L:XG + + records then insert entry and exit address to the wrong + symbol. So before a new symbol is generated for the + function, a lookup in the symboltable is done. + +Example of a *.cdb: + +S:G$ZpuInitialize$0$0({2}DF,SV:S),C,0,0 +S:G$ZpuInitialize$0$0({2}DF,SV:S),C,0,0 +F:G$ZpuInitialize$0$0({2}DF,SV:S),Z,0,0,0,0,0 +S:LZpuInitialize$i$1$1({2}SI:S),R,0,0,[] +L:G$ZpuInitialize$0$0:ADF +L:XG$ZpuInitialize$0$0:BBB Notes Feb 10, 2002 - Karl Bongers +======================== SDCDB is a debugger for SDCC compiler. It works as a front end to the ucSim simulator/disassembler program. diff --git a/debugger/mcs51/break.c b/debugger/mcs51/break.c index 53472347..93a00909 100644 --- a/debugger/mcs51/break.c +++ b/debugger/mcs51/break.c @@ -110,7 +110,7 @@ void deleteSTEPbp () breakp *bp; int k; - Dprintf(D_break, ("Deleting all STEP BPs\n")); + Dprintf(D_break, ("break: Deleting all STEP BPs\n")); /* for break points delete if they are STEP */ for ( bp = hTabFirstItem(bptable,&k); bp ; bp = hTabNextItem(bptable,&k)) { @@ -139,7 +139,7 @@ void deleteNEXTbp () int k; char simcmd[50]; - Dprintf(D_break, ("Deleting all NEXT BPs\n")); + Dprintf(D_break, ("break: Deleting all NEXT BPs\n")); /* for break points delete if they are NEXT */ for ( bp = hTabFirstItem(bptable,&k); bp ; @@ -171,7 +171,7 @@ void deleteUSERbp (int bpnum) int k; char simcmd[50]; - Dprintf(D_break, ("deleteUSERbp %d\n", bpnum)); + Dprintf(D_break, ("break: deleteUSERbp %d\n", bpnum)); /* for break points delete if they are STEP */ for ( bp = hTabFirstItem(bptable,&k); bp ; @@ -187,7 +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)); + Dprintf(D_break, ("break: deleteUSERbp:simClearBP 0x%x\n", bp->addr)); } fprintf(stdout,"Deleted breakpoint %d\n", @@ -281,7 +281,7 @@ int dispatchCB (unsigned addr, context *ctxt) breakp *bp; int rv =0; - Dprintf(D_break, ("dispatchCB: addr:0x%x \n", addr)); + Dprintf(D_break, ("break: dispatchCB: addr:0x%x \n", addr)); /* if no break points set for this address then use a simulator stop break point */ @@ -298,7 +298,7 @@ int dispatchCB (unsigned addr, context *ctxt) } if (rv == 0) { - Dprintf(D_break, ("dispatchCB: WARNING rv==0\n", rv)); + Dprintf(D_break, ("break: dispatchCB: WARNING rv==0\n", rv)); } return rv; @@ -309,7 +309,7 @@ int dispatchCB (unsigned addr, context *ctxt) /*-----------------------------------------------------------------*/ BP_CALLBACK(fentryCB) { - Dprintf(D_break, ("fentryCB: BP_CALLBACK entry\n")); + Dprintf(D_break, ("break: fentryCB: BP_CALLBACK entry\n")); /* add the current function into the call stack */ STACK_PUSH(callStack,ctxt->func); @@ -326,7 +326,7 @@ BP_CALLBACK(fentryCB) /*-----------------------------------------------------------------*/ BP_CALLBACK(fexitCB) { - Dprintf(D_break, ("fexitCB: BP_CALLBACK entry\n")); + Dprintf(D_break, ("break: fexitCB: BP_CALLBACK entry\n")); /* pop the top most from the call stack */ STACK_POP(callStack); @@ -337,7 +337,7 @@ BP_CALLBACK(fexitCB) /*-----------------------------------------------------------------*/ BP_CALLBACK(userBpCB) { - Dprintf(D_break, ("userBpCB: BP_CALLBACK entry\n")); + Dprintf(D_break, ("break: userBpCB: BP_CALLBACK entry\n")); if (srcMode == SRC_CMODE) { fprintf(stdout,"Breakpoint %d, %s() at %s:%d\n", @@ -369,7 +369,7 @@ BP_CALLBACK(stepBpCB) { static function *lfunc = NULL; - Dprintf(D_break, ("stepBpCB: BP_CALLBACK entry\n")); + Dprintf(D_break, ("break: stepBpCB: BP_CALLBACK entry\n")); if (srcMode == SRC_CMODE) { if ((lfunc && lfunc != ctxt->func) || !lfunc) @@ -407,7 +407,7 @@ BP_CALLBACK(nextBpCB) { static function *lfunc = NULL; - Dprintf(D_break, ("nextBpCB: BP_CALLBACK entry\n")); + Dprintf(D_break, ("break: nextBpCB: BP_CALLBACK entry\n")); if (srcMode == SRC_CMODE) { if ((lfunc && lfunc != ctxt->func) || !lfunc) diff --git a/debugger/mcs51/sdcdb.c b/debugger/mcs51/sdcdb.c index a5b77d5d..260a744d 100644 --- a/debugger/mcs51/sdcdb.c +++ b/debugger/mcs51/sdcdb.c @@ -28,6 +28,10 @@ #include "cmd.h" #include "newalloc.h" +#ifdef SDCDB_DEBUG +int sdcdbDebug = 0; +#endif + char *currModName = NULL; cdbrecs *recsRoot = NULL ; set *modules = NULL; /* set of all modules */ @@ -447,7 +451,7 @@ static void functionPoints () sym = func->sym; - Dprintf(D_sdcdb, ("func '%s' has entry '%x' exit '%x'\n", + Dprintf(D_sdcdb, ("sdcdb: func '%s' has entry '0x%x' exit '0x%x'\n", func->sym->name, func->sym->addr, func->sym->eaddr)); @@ -512,20 +516,23 @@ static void functionPoints () } #ifdef SDCDB_DEBUG - Dprintf(D_sdcdb, ("function '%s' has the following C exePoints\n", + if (!( D_sdcdb & sdcdbDebug)) + return; + + Dprintf(D_sdcdb, ("sdcdb: function '%s' has the following C exePoints\n", func->sym->name)); { exePoint *ep; for (ep = setFirstItem(func->cfpoints); ep; ep = setNextItem(func->cfpoints)) - Dprintf(D_sdcdb, ("{%x,%d} %s", + Dprintf(D_sdcdb, ("sdcdb: {0x%x,%d} %s", ep->addr,ep->line,mod->cLines[ep->line]->src)); - Dprintf(D_sdcdb, (" and the following ASM exePoints\n")); + Dprintf(D_sdcdb, ("sdcdb: and the following ASM exePoints\n")); for (ep = setFirstItem(func->afpoints); ep; ep = setNextItem(func->afpoints)) - Dprintf (D_sdcdb, ("{%x,%d} %s", + Dprintf (D_sdcdb, ("sdcdb: {0x%x,%d} %s", ep->addr,ep->line,mod->asmLines[ep->line]->src)); } #endif @@ -794,7 +801,7 @@ 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")); + Dprintf(D_sdcdb, ("sdcdb: parseCmdLine\n")); for ( i = 1; i < argc ; i++) { //fprintf(stdout,"%s\n",argv[i]); @@ -835,6 +842,13 @@ static void parseCmdLine (int argc, char **argv) continue; } +#ifdef SDCDB_DEBUG + if (strncmp(argv[i],"-d=",3) == 0) { + sdcdbDebug = strtol(&argv[i][3],0,0); + continue; + } +#endif + /* model string */ if (strncmp(argv[i],"-m",2) == 0) { strncpy(model_str, &argv[i][2], 15); @@ -915,8 +929,9 @@ bad_signal(int sig) static void sigintr(int sig) { - /* may be interrupt from user: stop debugger ( also simulator ??) */ + /* may be interrupt from user: stop debugger and also simulator */ userinterrupt = 1; + sendSim("\n"); } /* the only child can be the simulator */ @@ -937,7 +952,6 @@ setsignals() signal(SIGTERM, bad_signal); signal(SIGCHLD, sigchld ); - signal(SIGPIPE, SIG_IGN); signal(SIGABRT, bad_signal); signal(SIGALRM, bad_signal); signal(SIGFPE, bad_signal); @@ -954,7 +968,7 @@ setsignals() int main ( int argc, char **argv) { printVersionInfo(); - printf("WARNING: SDCDB is EXPERIMENTAL and NOT A FULLY FUNCTIONING TOOL.\n"); + printf("WARNING: SDCDB is EXPERIMENTAL.\n"); simArgs[nsimArgs++] = "s51"; simArgs[nsimArgs++] = "-P"; diff --git a/debugger/mcs51/sdcdb.h b/debugger/mcs51/sdcdb.h index 586aa2cf..b5afc122 100644 --- a/debugger/mcs51/sdcdb.h +++ b/debugger/mcs51/sdcdb.h @@ -24,16 +24,18 @@ #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 1 -#define D_sdcdb 1 -#define D_symtab 0 +#define D_break 0x01 +#define D_simi 0x02 +#define D_sdcdb 0x04 +#define D_symtab 0x08 -#define Dprintf(f, fs) {if (f) printf fs ; } +extern int sdcdbDebug; + +#define Dprintf(f, fs) {if (f & sdcdbDebug) printf fs ; } #else #define Dprintf(f, fs) { } #endif diff --git a/debugger/mcs51/simi.c b/debugger/mcs51/simi.c index 8da959c3..7fec50f0 100644 --- a/debugger/mcs51/simi.c +++ b/debugger/mcs51/simi.c @@ -45,11 +45,6 @@ static char *sbp = simibuff; /* simulator buffer pointer */ extern char **environ; char simactive = 0; - -#if 0 -#define MS_SLEEP(_ms) usleep(_ms * 1000) -#endif - /*-----------------------------------------------------------------*/ /* waitForSim - wait till simulator is done its job */ /*-----------------------------------------------------------------*/ @@ -58,55 +53,15 @@ void waitForSim(int timeout_ms, char *expect) int i=0; int ch; -Dprintf(D_simi, ("waitForSim start(%d)\n", timeout_ms)); +Dprintf(D_simi, ("simi: waitForSim start(%d)\n", timeout_ms)); sbp = simibuff; - // MS_SLEEP(timeout_ms); dont need, in blocking mode. - while ((ch = fgetc(simin)) > 0 ) { *sbp++ = ch; } *sbp = 0; Dprintf(D_simi, ("waitForSim(%d) got[%s]\n", timeout_ms, simibuff)); -#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 - } /*-----------------------------------------------------------------*/ @@ -117,14 +72,19 @@ void openSimulator (char **args, int nargs) struct sockaddr_in sin; int retry = 0; int i ; - Dprintf(D_simi, ("openSimulator\n")); + Dprintf(D_simi, ("simi: openSimulator\n")); /* fork and start the simulator as a subprocess */ if ((simPid = fork())) { - Dprintf(D_simi, ("simulator pid %d\n",(int) simPid)); + Dprintf(D_simi, ("simi: simulator pid %d\n",(int) simPid)); } else { /* we are in the child process : start the simulator */ + signal(SIGHUP , SIG_IGN ); + signal(SIGINT , SIG_IGN ); + signal(SIGABRT, SIG_IGN ); + signal(SIGCHLD, SIG_IGN ); + if (execvp(args[0],args) < 0) { perror("cannot exec simulator"); exit(1); @@ -183,7 +143,7 @@ void sendSim(char *s) if ( ! simout ) return; - Dprintf(D_simi, ("sendSim-->%s", s)); // s has LF at end already + Dprintf(D_simi, ("simi: sendSim-->%s", s)); // s has LF at end already fputs(s,simout); fflush(simout); } diff --git a/debugger/mcs51/symtab.c b/debugger/mcs51/symtab.c index 75fac234..2e2e5008 100644 --- a/debugger/mcs51/symtab.c +++ b/debugger/mcs51/symtab.c @@ -26,6 +26,7 @@ #include "newalloc.h" structdef *structWithName (char *); +DEFSETFUNC(symWithRName); /*------------------------------------------------------------------*/ /* getSize - returns size of a type chain in bits */ @@ -88,13 +89,21 @@ unsigned int getSize ( link *p ) void parseFunc (char *line) { function *func ; - char *rs; + char *rs = line ; int i; + + while (*rs && *rs != '(') rs++ ; + *--rs = '\0'; + func = Safe_calloc(1,sizeof(function)); - func->sym = parseSymbol(line,&rs); + func->sym = NULL; + applyToSet(symbols,symWithRName,line,&func->sym); + *rs++ = '0'; + if (! func->sym) + func->sym = parseSymbol(line,&rs); func->sym->isfunc = 1; func->modName = currModName ; - while(*rs != ',') rs++; + while(*rs && *rs != ',') rs++; rs++; sscanf(rs,"%d,%d,%d",&i, &(SPEC_INTN(func->sym->etype)), @@ -608,7 +617,7 @@ static void lnkFuncEnd (char *s) s++; sscanf(s,"%x",&func->sym->eaddr); - Dprintf(D_symtab, ("%s(eaddr%x)\n",func->sym->name,func->sym->eaddr)); + Dprintf(D_symtab, ("symtab: %s(eaddr 0x%x)\n",func->sym->name,func->sym->eaddr)); } /*-----------------------------------------------------------------*/ @@ -633,7 +642,7 @@ static void lnkSymRec (char *s) s++; sscanf(s,"%x",&sym->addr); - Dprintf(D_symtab, ("%s(%x)\n",sym->name,sym->addr)); + Dprintf(D_symtab, ("symtab: %s(0x%x)\n",sym->name,sym->addr)); } /*-----------------------------------------------------------------*/ @@ -663,7 +672,7 @@ static void lnkAsmSrc (char *s) line--; if (line < mod->nasmLines) { mod->asmLines[line]->addr = addr; - Dprintf(D_symtab, ("%s(%d:%x) %s",mod->asm_name,line,addr,mod->asmLines[line]->src)); + Dprintf(D_symtab, ("symtab: %s(%d:0x%x) %s",mod->asm_name,line,addr,mod->asmLines[line]->src)); } } @@ -703,7 +712,7 @@ static void lnkCSrc (char *s) mod->cLines[line]->addr = addr; mod->cLines[line]->block = block; mod->cLines[line]->level = level; - Dprintf(D_symtab, ("%s(%d:%x) %s",mod->c_name, + Dprintf(D_symtab, ("symtab: %s(%d:0x%x) %s",mod->c_name, line+1,addr,mod->cLines[line]->src)); } return; -- 2.30.2