ddd fixes
authorkbongers <kbongers@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 24 Apr 2003 15:28:37 +0000 (15:28 +0000)
committerkbongers <kbongers@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 24 Apr 2003 15:28:37 +0000 (15:28 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2562 4a8a32a2-be11-0410-ad9d-d568d2c75423

debugger/README
debugger/mcs51/break.c
debugger/mcs51/sdcdb.c
debugger/mcs51/sdcdb.h
debugger/mcs51/simi.c
debugger/mcs51/symtab.c

index 34d9c8b9dc7e17088440833eeecbe3f758ffe361..86b02612b8d2ac9882e54391cef127b144015e6d 100644 (file)
@@ -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.
index 534723479df933c09f01685567b4125128cd8590..93a00909b4c03395f6cd5a460415d5435bab34b6 100644 (file)
@@ -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)
index a5b77d5df18bd829d45a4d41649ed7427dc3f74a..260a744df6f1dfb0a41c9f136baafe493709233e 100644 (file)
 #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";
index 586aa2cfa093d2be31b1fc7d734c33dc68b4aa55..b5afc122162031399e77c5bb00da52ae1b47c4bc 100644 (file)
 #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
index 8da959c34a0c48a6e5911e1c0d73a81844d82750..7fec50f0c7a836c8d2c413e819c1d26fa11489c7 100644 (file)
@@ -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);
 }
index 75fac2345b4dfe145ec340b5e12aa80da4472045..2e2e5008d2110ea3c5defc275b75726728837bed 100644 (file)
@@ -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;