Use 'ao-dbg' instead of 's51' to communicate with TeleMetrum
[fw/sdcc] / debugger / mcs51 / sdcdb.c
index eb598461192868e79ea9384ac5b9f77ffd4a9c78..8df52526574ae2c77fc29e30d94becfd3d10f9d0 100644 (file)
    what you give them.   Help stamp out software-hoarding!
 -------------------------------------------------------------------------*/
 
+#define link unix_link
+#define _GNU_SOURCE
+#include <unistd.h>
+#undef link
 #include "sdcdb.h"
 #include "symtab.h"
 #include "simi.h"
 #include "break.h"
 #include "cmd.h"
 #include "newalloc.h"
+#if defined HAVE_LIBREADLINE && HAVE_LIBREADLINE != -1
+#define HAVE_READLINE_COMPLETITION  1
+#endif
 #ifdef HAVE_LIBREADLINE
 #include <readline/readline.h>
 #include <readline/history.h>
@@ -52,17 +59,18 @@ short showfull = 0;
 char userinterrupt = 0;
 char nointerrupt = 0;
 char contsim = 0;
-char *ssdirl = DATADIR LIB_DIR_SUFFIX ":" DATADIR LIB_DIR_SUFFIX "/small" ;
+char *ssdirl = DATADIR LIB_DIR_SUFFIX ":" DATADIR LIB_DIR_SUFFIX DIR_SEPARATOR_STRING "small" ;
 char *simArgs[40];
 int nsimArgs = 0;
 char model_str[20];
 /* fake filename & lineno to make linker */
 char *filename=NULL;
+char *current_directory;
 int lineno = 0;
 int fatalError = 0;
 
 static void commandLoop(FILE *cmdfile);
-#ifdef HAVE_LIBREADLINE
+#ifdef HAVE_READLINE_COMPLETITION
 char *completionCmdSource(const char *text, int state);
 char *completionCmdFile(const char *text, int state);
 char *completionCmdInfo(const char *text, int state);
@@ -86,18 +94,18 @@ char *completionCmdSetOption(const char *text, int state);
 #define completionCmdUnDisplay NULL
 #define completionCmdSetUserBp NULL
 #define completionCmdSetOption NULL
-#endif /* HAVE_LIBREADLINE */
+#endif /* HAVE_READLINE_COMPLETITION */
 
 /* command table */
 struct cmdtab
 {
     char      *cmd ;  /* command the user will enter */
     int (*cmdfunc)(char *,context *);   /* function to execute when command is entered */
-#ifdef HAVE_LIBREADLINE
+#ifdef HAVE_READLINE_COMPLETITION
     rl_compentry_func_t *completion_func;
 #else
     void *dummy;
-#endif  /* HAVE_LIBREADLINE */
+#endif  /* HAVE_READLINE_COMPLETITION */
     char *htxt ;    /* short help text */
 
 } cmdTab[] = {
@@ -379,7 +387,7 @@ char *searchDirsFname (char *fname)
 {
     char *dirs , *sdirs;
     FILE *rfile = NULL;
-    char buffer[128];
+    char buffer[1024];
 
     /* first try the current directory */
     if ((rfile = fopen(fname,"r"))) {
@@ -421,7 +429,7 @@ FILE *searchDirsFopen(char *fname)
 {
     char *dirs , *sdirs;
     FILE *rfile = NULL;
-    char buffer[128];
+    char buffer[1024];
 
     /* first try the current directory */
     if ((rfile = fopen(fname,"r")))
@@ -685,35 +693,13 @@ static void functionPoints (void)
     }
 }
 
-
-/*-----------------------------------------------------------------*/
-/* setEntryExitBP - set the entry & exit Break Points for functions*/
-/*-----------------------------------------------------------------*/
-DEFSETFUNC(setEntryExitBP)
-{
-    function *func = item;
-
-    if (func->sym && func->sym->addr && func->sym->eaddr) {
-
-        /* set the entry break point */
-        setBreakPoint (func->sym->addr , CODE , FENTRY ,
-            fentryCB ,func->mod->c_name , func->entryline);
-
-        /* set the exit break point */
-        setBreakPoint (func->sym->eaddr , CODE , FEXIT  ,
-            fexitCB  ,func->mod->c_name , func->exitline );
-    }
-
-    return 0;
-}
-
 /*-----------------------------------------------------------------*/
 /* cmdFile - load file into the debugger                           */
 /*-----------------------------------------------------------------*/
 int cmdFile (char *s,context *cctxt)
 {
     FILE *cdbFile;
-    char buffer[128];
+    char buffer[1024];
     char *bp;
 
     s = trim_left(s);
@@ -768,7 +754,7 @@ int cmdFile (char *s,context *cctxt)
     /*set the break points
        required by the debugger . i.e. the function entry
        and function exit break points */
-    applyToSet(functions,setEntryExitBP);
+//    applyToSet(functions,setEntryExitBP);
 
     setMainContext();
     return 0;
@@ -844,6 +830,16 @@ int cmdHelp (char *s, context *cctxt)
 static char cmdbuff[MAX_CMD_LEN];
 static int sim_cmd_mode = 0;
 
+char *
+canonname(char *file)
+{
+    static char        buffer[1024];
+    if (*file == '/')
+       return file;
+    sprintf(buffer,"%s/%s", current_directory, file);
+    return buffer;
+}
+
 /*-----------------------------------------------------------------
  interpretCmd - interpret and do the command.  Return 0 to continue,
    return 1 to exit program.
@@ -856,7 +852,7 @@ int interpretCmd (char *s)
 
     /* if nothing & previous command exists then
        execute the previous command again */
-    if (*s == '\n' && pcmd)
+    if ((*s == '\n' || *s == '\0') && pcmd)
         strcpy(s,pcmd);
 
     /* if previous command exists & is different
@@ -909,11 +905,11 @@ int interpretCmd (char *s)
                 showfull = 0;
                 if (srcMode == SRC_CMODE)
                     fprintf(stdout,"\032\032%s:%d:1:beg:0x%08x\n",
-                        currCtxt->func->mod->cfullname,
+                        canonname(currCtxt->func->mod->cfullname),
                         currCtxt->cline+1,currCtxt->addr);
                 else
                     fprintf(stdout,"\032\032%s:%d:1:beg:0x%08x\n",
-                        currCtxt->func->mod->afullname,
+                        canonname(currCtxt->func->mod->afullname),
                         currCtxt->asmline,currCtxt->addr);
                 displayAll(currCtxt);
             }
@@ -958,7 +954,7 @@ void stopCommandList()
     stopcmdlist = 1;
 }
 
-#ifdef HAVE_LIBREADLINE
+#ifdef HAVE_READLINE_COMPLETITION
 // helper function for doing readline completion.
 // input: toknum=index of token to find (0=first token)
 // output: *start=first character index of the token,
@@ -1419,7 +1415,7 @@ char *completionMain(const char *text, int state)
 
     return (*compl_func)(text,state);
 }
-#endif  /* HAVE_LIBREADLINE */
+#endif  /* HAVE_READLINE_COMPLETITION */
 
 /*-----------------------------------------------------------------*/
 /* commandLoop - the main command loop or loop over command file   */
@@ -1433,7 +1429,9 @@ static void commandLoop(FILE *cmdfile)
     FILE *old_rl_instream, *old_rl_outstream;
     actualcmdfile = cmdfile;
 
+#ifdef HAVE_READLINE_COMPLETITION
     rl_completion_entry_function = completionMain;
+#endif  /* HAVE_READLINE_COMPLETITION */
     rl_readline_name = "sdcdb"; // Allow conditional parsing of the ~/.inputrc file.
 
     // save readline's input/output streams
@@ -1453,9 +1451,9 @@ static void commandLoop(FILE *cmdfile)
           if ( cmdfile == stdin )
           {
               if (sim_cmd_mode)
-                  line_read = (char*)readline ("(sim)");
+                  line_read = (char*)readline ("(sim) ");
               else
-                  line_read = (char*)readline ("(sdcdb)");
+                  line_read = (char*)readline ("(sdcdb) ");
           }
           else
               line_read = (char*)readline ("");
@@ -1598,7 +1596,7 @@ static void parseCmdLine (int argc, char **argv)
             }
 
             if (strncmp(argv[i],"-cd=",4) == 0) {
-                chdir(argv[i][4]);
+                chdir(argv[i]+4);
                 continue;
             }
 
@@ -1655,8 +1653,10 @@ static void parseCmdLine (int argc, char **argv)
 
             /* serial port */
             if ( (strcmp(argv[i],"-S") == 0) ||
-                (strcmp(argv[i],"-s") == 0)) {
-                simArgs[nsimArgs++] = strdup(argv[i]);
+                (strcmp(argv[i],"-s") == 0) ||
+                (strcmp(argv[i],"-T") == 0) ||
+                (strcmp(argv[i],"--tty") == 0)) {
+               simArgs[nsimArgs++] = "--tty";
                 simArgs[nsimArgs++] = strdup(argv[++i]);
                 continue ;
             }
@@ -1759,7 +1759,8 @@ int main ( int argc, char **argv)
     printVersionInfo();
     printf("WARNING: SDCDB is EXPERIMENTAL.\n");
 
-    simArgs[nsimArgs++] = "s51";
+    current_directory = get_current_dir_name();
+    simArgs[nsimArgs++] = "ao-dbg";
     simArgs[nsimArgs++] = "-P";
     simArgs[nsimArgs++] = "-r 9756";
     /* parse command line */