Diff for /freem/src/mdebug.c between versions 1.11 and 1.13

version 1.11, 2025/05/01 17:02:30 version 1.13, 2025/05/20 18:07:41
Line 24 Line 24
  *   along with FreeM.  If not, see <https://www.gnu.org/licenses/>.   *   along with FreeM.  If not, see <https://www.gnu.org/licenses/>.
  *   *
  *   $Log$   *   $Log$
    *   Revision 1.13  2025/05/20 18:07:41  snw
    *   Add completion to debugger
    *
    *   Revision 1.12  2025/05/01 21:02:31  snw
    *   Documentation updates
    *
  *   Revision 1.11  2025/05/01 17:02:30  snw   *   Revision 1.11  2025/05/01 17:02:30  snw
  *   Further debugging improvements   *   Further debugging improvements
  *   *
Line 95  extern int read_history (); Line 101  extern int read_history ();
 #include "freem.h"  #include "freem.h"
 #include "mref.h"  #include "mref.h"
   
   #ifdef HAVE_LIBREADLINE
   char *dbg_commands[] = {
       "backtrace",
       "continue",
       "examine",
       "exit",
       "halt",
       "next",
       "quit",
       "step",
       "trace",
       "watch",
       NULL
   };
   
   char **dbg_completion(const char *, int, int);
   char *dbg_generator(const char *, int);
   
   char **dbg_completion(const char *text, int start, int end)
   {
       if (start > 0) return NULL;
       rl_attempted_completion_over = 1;
       return rl_completion_matches (text, dbg_generator);
   }
   
   char *dbg_generator(const char *text, int state)
   {
       static int list_index, len;
       char *name;
   
       if (!state) {
           list_index = 0;
           len = strlen(text);
       }
   
       while ((name = dbg_commands[list_index++])) {
           if (strncmp (name, text, len) == 0) {
               return strdup (name);
           }
       }
   
       return NULL;
   }
   #endif
   
 dbg_watch dbg_watchlist[MAXWATCH];    /* list of watchpoints */  dbg_watch dbg_watchlist[MAXWATCH];    /* list of watchpoints */
 short dbg_enable_watch;               /* 0 = watches disabled, 1 = watches enabled */  short dbg_enable_watch;               /* 0 = watches disabled, 1 = watches enabled */
 int dbg_pending_watches;  int dbg_pending_watches;
Line 139  int debugger (int entry_mode, char *entr Line 190  int debugger (int entry_mode, char *entr
     char tbuf2[512];      char tbuf2[512];
     register int i;      register int i;
     register int j;      register int j;
       
       rl_attempted_completion_function = dbg_completion;
     set_io (UNIX);      set_io (UNIX);
           
     if (first_entry) {      if (first_entry) {
Line 206  int debugger (int entry_mode, char *entr Line 258  int debugger (int entry_mode, char *entr
         }          }
                   
         snprintf (dbg_prompt, sizeof (dbg_prompt) - 1, "%s $STACK=%d [DEBUG]> ", rouname_buf, nstx);          snprintf (dbg_prompt, sizeof (dbg_prompt) - 1, "%s $STACK=%d [DEBUG]> ", rouname_buf, nstx);
           if (dbg_enable_watch && dbg_pending_watches) dbg_dump_watchlist ();
         dbg_buf = readline (dbg_prompt);          dbg_buf = readline (dbg_prompt);
                   
         if (!dbg_buf) continue;          if (!dbg_buf) continue;
Line 347  int debugger (int entry_mode, char *entr Line 399  int debugger (int entry_mode, char *entr
             printf ("ZTRAP:\t%s\n", ecbuf);              printf ("ZTRAP:\t%s\n", ecbuf);
                           
         }          }
           else if ((strcmp (dbg_cmd, "halt") == 0) || (strcmp (dbg_cmd, "h") == 0)) {
               printf ("debug:  forcing halt\n");          
               exit (0);
           }
           else if ((strcmp (dbg_cmd, "watch") == 0) || (strcmp (dbg_cmd, "w") == 0)) {
               char watchmode;
               char *glvn;
               
               if (dbg_argc == 1) {
                   switch (dbg_enable_watch) {
                       case 0:
                           dbg_enable_watch = 1;
                           printf ("debug:  watchpoints enabled\n");
                           break;
                       case 1:
                           dbg_enable_watch = 0;
                           printf ("debug:  watchpoints disabled\n");
                           break;
                   }
               }
               else {
                   watchmode = dbarg[0];
                   glvn = &(dbarg[1]);
                   
                   switch (watchmode) {
                       case '+':
                           dbg_add_watch (glvn);
                           break;
                       case '-':
                           dbg_remove_watch (glvn);
                           break;
                       case '?':
                           dbg_dump_watch (glvn);
                           break;
                       default:
                           printf ("debug:  watch mode must be +, -, or ?\n");
                           break;
                   }
   
                   set_io (UNIX);
               }               
           }
         else {          else {
             printf ("DEBUG:  invalid command\r\n");              printf ("DEBUG:  invalid command\r\n");
         }          }
Line 390  dbg_watch *dbg_add_watch (char *varnam) Line 484  dbg_watch *dbg_add_watch (char *varnam)
         return NULL;          return NULL;
     }      }
   
     if ((dbg_watchlist[index].varnam = (char *) malloc (256 * sizeof (char))) == NULL) {      if ((dbg_watchlist[index].varnam = (char *) calloc (256, sizeof (char))) == NULL) {
         set_io (UNIX);          set_io (UNIX);
         fprintf (stderr, "Could not allocate memory for the new watchlist entry.\n");          fprintf (stderr, "Could not allocate memory for the new watchlist entry.\n");
         set_io (MUMPS);          set_io (MUMPS);
Line 402  dbg_watch *dbg_add_watch (char *varnam) Line 496  dbg_watch *dbg_add_watch (char *varnam)
     dbg_watchlist[index].chgct = 0;      dbg_watchlist[index].chgct = 0;
   
     set_io (UNIX);      set_io (UNIX);
     fprintf (stderr, "Added '%s' to the watchlist.\n", dbg_get_watch_name (varnam));      fprintf (stderr, "Added '%s' to the watchlist.\n", varnam);
     set_io (MUMPS);      set_io (MUMPS);
   
     return NULL;      return NULL;

Removed from v.1.11  
changed lines
  Added in v.1.13


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>