--- freem/src/mdebug.c 2025/03/09 19:50:47 1.3
+++ freem/src/mdebug.c 2025/04/29 18:46:17 1.5
@@ -1,5 +1,5 @@
/*
- * $Id: mdebug.c,v 1.3 2025/03/09 19:50:47 snw Exp $
+ * $Id: mdebug.c,v 1.5 2025/04/29 18:46:17 snw Exp $
* debugger enhancements
*
*
@@ -24,6 +24,12 @@
* along with FreeM. If not, see .
*
* $Log: mdebug.c,v $
+ * Revision 1.5 2025/04/29 18:46:17 snw
+ * Begin work on interactive debugger
+ *
+ * Revision 1.4 2025/04/28 19:38:55 snw
+ * Add trace mode
+ *
* Revision 1.3 2025/03/09 19:50:47 snw
* Second phase of REUSE compliance and header reformat
*
@@ -35,6 +41,36 @@
#include
#include
#include
+#include
+
+#include "config.h"
+
+#ifdef HAVE_LIBREADLINE
+# if defined(HAVE_READLINE_READLINE_H)
+# include
+# elif defined(HAVE_READLINE_H)
+# include
+# else /* !defined(HAVE_READLINE_H) */
+extern char *readline ();
+# endif /* !defined(HAVE_READLINE_H) */
+/*char *cmdline = NULL;*/
+#else /* !defined(HAVE_READLINE_READLINE_H) */
+ /* no readline */
+#endif /* HAVE_LIBREADLINE */
+
+#ifdef HAVE_READLINE_HISTORY
+# if defined(HAVE_READLINE_HISTORY_H)
+# include
+# elif defined(HAVE_HISTORY_H)
+# include
+# else /* !defined(HAVE_HISTORY_H) */
+extern void add_history ();
+extern int write_history ();
+extern int read_history ();
+# endif /* defined(HAVE_READLINE_HISTORY_H) */
+ /* no history */
+#endif /* HAVE_READLINE_HISTORY */
+
#include "mpsdef.h"
#include "mdebug.h"
@@ -62,6 +98,56 @@ void dbg_init (void)
}
+int debugger (void)
+{
+
+#if defined(HAVE_LIBREADLINE)
+ static int first_entry = TRUE;
+ char *dbg_buf;
+ char dbg_prompt[256];
+ HIST_ENTRY **dbg_hist;
+ int dbg_hist_idx;
+ HIST_ENTRY *dbg_hist_ent;
+ char rouname_buf[256];
+
+ set_io (UNIX);
+
+ if (first_entry) {
+ first_entry = FALSE;
+
+ printf ("\nEntering debug mode; M commands unavailable.\n");
+ printf ("Type 'exit' to return to direct mode; 'help' for help.\n\n");
+ }
+
+ while (1) {
+ stcpy (rouname_buf, rou_name);
+ stcnv_m2c (rouname_buf);
+
+ snprintf (dbg_prompt, sizeof (dbg_prompt) - 1, "%s $STACK=%d [DEBUG]> ", rouname_buf, nstx);
+
+ dbg_buf = readline (dbg_prompt);
+
+ if (!dbg_buf) continue;
+
+ if (strcmp (dbg_buf, "exit") == 0) {
+ first_entry = TRUE;
+ printf ("\n\nExiting debug mode.\n\n");
+ set_io (MUMPS);
+ return FALSE;
+ }
+ else {
+ printf ("DEBUG: invalid command\r\n");
+ }
+
+ }
+
+ return TRUE;
+#else
+ return FALSE;
+#endif
+
+}
+
dbg_watch *dbg_add_watch (char *varnam)
{
register int i;
@@ -238,5 +324,5 @@ void dbg_fire_watch (char *varnam) {
w->chgct++;
w->firect++;
dbg_pending_watches++;
-
+
}