--- freem/src/mdebug.c 2025/03/09 15:20:18 1.2 +++ freem/src/mdebug.c 2025/04/29 18:46:17 1.5 @@ -1,23 +1,11 @@ /* - * * - * * * - * * * - * *************** - * * * * * - * * MUMPS * - * * * * * - * *************** - * * * - * * * - * * - * - * mdebug.c + * $Id: mdebug.c,v 1.5 2025/04/29 18:46:17 snw Exp $ * debugger enhancements * * * Author: Serena Willis * Copyright (C) 1998 MUG Deutschland - * Copyright (C) 2020 Coherent Logic Development LLC + * Copyright (C) 2020, 2025 Coherent Logic Development LLC * * * This file is part of FreeM. @@ -35,11 +23,54 @@ * You should have received a copy of the GNU Affero Public License * 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 + * + * + * SPDX-FileCopyrightText: (C) 2025 Coherent Logic Development LLC + * SPDX-License-Identifier: AGPL-3.0-or-later **/ #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" @@ -67,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; @@ -243,5 +324,5 @@ void dbg_fire_watch (char *varnam) { w->chgct++; w->firect++; dbg_pending_watches++; - + }