Author: julianalbo
Date: Thu Aug 21 01:13:28 2008
New Revision: 30421

Modified:
   trunk/include/parrot/debugger.h
   trunk/src/debug.c

Log:
add 'echo' command to debugger, and some cleaning and fixing on it

Modified: trunk/include/parrot/debugger.h
==============================================================================
--- trunk/include/parrot/debugger.h     (original)
+++ trunk/include/parrot/debugger.h     Thu Aug 21 01:13:28 2008
@@ -27,7 +27,8 @@
     PDB_EXIT        = 1 << 5,
     PDB_ENTER       = 1 << 6,
     PDB_GCDEBUG     = 1 << 7,
-    PDB_TRACING     = 1 << 8
+    PDB_TRACING     = 1 << 8,
+    PDB_ECHO        = 1 << 9
 };
 
 enum {

Modified: trunk/src/debug.c
==============================================================================
--- trunk/src/debug.c   (original)
+++ trunk/src/debug.c   Thu Aug 21 01:13:28 2008
@@ -31,10 +31,13 @@
 #include "parrot/oplib/ops.h"
 #include "debug.str"
 
-/* Hand switched debugger tracing */
-/*#define TRACE_DEBUGGER 1*/
+/* Hand switched debugger tracing
+ * Set to 1 to enable tracing to stderr
+ * Set to 0 to disable
+ */
+#define TRACE_DEBUGGER 0
 
-#ifdef TRACE_DEBUGGER
+#if TRACE_DEBUGGER
 #  define TRACEDEB_MSG(msg) fprintf(stderr, "%s\n", (msg))
 #else
 #  define TRACEDEB_MSG(msg)
@@ -93,7 +96,8 @@
     debug_cmd_disable     = 772140,
     debug_cmd_continue    = 1053405,
     debug_cmd_disassemble = 1903830,
-    debug_cmd_gcdebug     = 779790
+    debug_cmd_gcdebug     = 779790,
+    debug_cmd_echo        = 276675
 };
 
 /* HEADERIZER HFILE: include/parrot/debugger.h */
@@ -101,6 +105,10 @@
 /* HEADERIZER BEGIN: static */
 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will 
be lost. */
 
+static void chop_newline(ARGMOD(char * buf))
+        __attribute__nonnull__(1)
+        FUNC_MODIFIES(* buf);
+
 static void close_script_file(PARROT_INTERP)
         __attribute__nonnull__(1);
 
@@ -171,6 +179,24 @@
 
 /*
 
+=item C<static void chop_newline>
+
+If the C string argument end with a newline, delete it.
+
+=cut
+
+*/
+
+static void
+chop_newline(ARGMOD(char * buf))
+{
+    int l = strlen(buf);
+    if (l > 0 && buf [l - 1] == '\n')
+        buf [l - 1] = '\0';
+}
+
+/*
+
 =item C<static const char * nextarg>
 
 Returns the position just past the current argument in the PASM instruction
@@ -676,20 +702,23 @@
                 return;
             }
 
+            chop_newline (buf);
+
             /* skip spaces */
-            for (ptr = (char *)&buf; *ptr && isspace((unsigned char)*ptr); 
ptr++);
+            for (ptr = buf; *ptr && isspace((unsigned char)*ptr); ptr++);
+
+            /* skip blank and commented lines */
+       } while (*ptr == '\0' || *ptr == '#');
 
-            /* avoid null blank and commented lines */
-            if (*buf == '\0' || *buf == '#')
-                continue;
-        } while (0);
+        if (pdb->state & PDB_ECHO)
+            fprintf(stderr, "[%s]\n", buf);
 
         /* RT #46117: handle command error and print out script line
          *       PDB_run_command should return non-void value?
          *       stop execution of script if fails
          * RT #46115: avoid this verbose output? add -v flag? */
 
-#ifdef TRACE_DEBUGGER
+#if TRACE_DEBUGGER
         fprintf(stderr, "(script) %s\n", buf);
 #endif
 
@@ -872,6 +901,16 @@
                 pdb->state |= PDB_GCDEBUG;
             }
             break;
+        case debug_cmd_echo:
+            if (pdb->state & PDB_ECHO) {
+                TRACEDEB_MSG("Disabling echo");
+                pdb->state &= ~PDB_ECHO;
+            }
+            else {
+                TRACEDEB_MSG("Enabling echo");
+                pdb->state |= PDB_ECHO;
+            }
+            break;
         case debug_cmd_h:
         case debug_cmd_help:
             PDB_help(interp, command);
@@ -894,7 +933,7 @@
         default:
             PIO_eprintf(interp,
                         "Undefined command: \"%s\".  Try \"help\".", 
original_command);
-#ifdef TRACE_DEBUGGER
+#if TRACE_DEBUGGER
             fprintf(stderr, " (parse_command result: %li)", c);
 #endif
             return 1;
@@ -2892,6 +2931,11 @@
 In gcdebug mode a garbage collection cycle is run before each opcocde,\n\
 same as using the gcdebug core.\n");
             break;
+        case debug_cmd_echo:
+            PIO_eprintf(interp,
+"Toggle echo mode.\n\n\
+In echo mode the script commands are written to stderr before executing.\n");
+            break;
         case debug_cmd_quit:
             PIO_eprintf(interp, "Exit the debugger.\n");
             break;
@@ -2908,6 +2952,7 @@
     run      (r) -- run the program\n\
     break    (b) -- add a breakpoint\n\
     script   (f) -- interprets a file as user commands\n\
+    echo         -- toggle echo of script commands\n\
     watch    (w) -- add a watchpoint\n\
     delete   (d) -- delete a breakpoint\n\
     disable      -- disable a breakpoint\n\

Reply via email to