Author: julianalbo
Date: Wed Aug 13 01:28:49 2008
New Revision: 30203

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

Log:
change the handling of command line buffers in parrot_debugger

Modified: trunk/include/parrot/debugger.h
==============================================================================
--- trunk/include/parrot/debugger.h     (original)
+++ trunk/include/parrot/debugger.h     Wed Aug 13 01:28:49 2008
@@ -175,6 +175,15 @@
 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will 
be lost. */
 
 PARROT_API
+void Parrot_debugger_break(PARROT_INTERP, ARGIN(opcode_t * cur_opcode))
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(2);
+
+PARROT_API
+void Parrot_debugger_destroy(PARROT_INTERP)
+        __attribute__nonnull__(1);
+
+PARROT_API
 void Parrot_debugger_init(PARROT_INTERP)
         __attribute__nonnull__(1);
 
@@ -188,11 +197,6 @@
         __attribute__nonnull__(2);
 
 PARROT_API
-void Parrot_debugger_break(PARROT_INTERP, ARGIN(opcode_t * cur_opcode))
-        __attribute__nonnull__(1)
-        __attribute__nonnull__(2);
-
-PARROT_API
 void PDB_load_source(PARROT_INTERP, ARGIN(const char *command))
         __attribute__nonnull__(1)
         __attribute__nonnull__(2);

Modified: trunk/src/debug.c
==============================================================================
--- trunk/src/debug.c   (original)
+++ trunk/src/debug.c   Wed Aug 13 01:28:49 2008
@@ -31,6 +31,8 @@
 #include "parrot/oplib/ops.h"
 #include "debug.str"
 
+/* Length of command line buffers */
+#define DEBUG_CMD_BUFFER_LENGTH 255
 
 /* Not sure how we want to handle this sort of cross-project header */
 PARROT_API
@@ -393,6 +395,10 @@
         interp->pdb     = pdb;
         debugger->pdb   = pdb;
         pdb->debugee    = interp;
+
+       /* Allocate space for command line buffers, NUL terminated c strings */
+        pdb->cur_command = (char *)mem_sys_allocate(DEBUG_CMD_BUFFER_LENGTH + 
1);
+        pdb->last_command = (char *)mem_sys_allocate(DEBUG_CMD_BUFFER_LENGTH + 
1);
     }
 
     /* PDB_disassemble(interp, NULL); */
@@ -403,6 +409,34 @@
 
 /*
 
+=item C<void Parrot_debugger_destroy>
+
+Destroy the current Parrot debugger instance.
+
+=cut
+
+*/
+
+PARROT_API
+void
+Parrot_debugger_destroy(PARROT_INTERP)
+{
+    /* Unfinished.
+       Free all debugger allocated resources.
+     */
+    PDB_t *pdb = interp->pdb;
+    PARROT_ASSERT(pdb);
+    PARROT_ASSERT(pdb->debugee == interp);
+ 
+    mem_sys_free(pdb->last_command);
+    mem_sys_free(pdb->cur_command);
+
+    mem_sys_free(pdb);
+    interp->pdb = NULL;
+}
+
+/*
+
 =item C<void Parrot_debugger_load>
 
 Loads a Parrot source file for the current program.
@@ -541,8 +575,6 @@
 
 */
 
-#define DEBUG_CMD_BUFFER_LENGTH 255
-
 void
 PDB_get_command(PARROT_INTERP)
 {
@@ -554,15 +586,8 @@
     /* flush the buffered data */
     fflush(stdout);
 
-    /* not used any more */
-    if (pdb->last_command && *pdb->cur_command) {
-        mem_sys_free(pdb->last_command);
-        pdb->last_command = NULL;
-    }
-
     /* update the last command */
-    if (pdb->cur_command && *pdb->cur_command)
-        pdb->last_command = pdb->cur_command;
+    strcpy(pdb->last_command, pdb->cur_command);
 
     #if 0
     /* if the program is stopped and running show the next line to run */
@@ -585,9 +610,7 @@
 
     i = 0;
 
-    /* RT #46109 who frees that */
-    /* need to allocate one more char as string is null-terminated */
-    c = (char *)mem_sys_allocate(DEBUG_CMD_BUFFER_LENGTH + 1);
+    c = pdb->cur_command;
 
     PIO_eprintf(interp, "\n(pdb) ");
 
@@ -606,8 +629,6 @@
 
     if (ch == -1)
         strcpy(c, "quit");
-
-    pdb->cur_command = c;
 }
 
 /*

Reply via email to