Author: chromatic
Date: Sun Jun  3 18:56:35 2007
New Revision: 18792

Modified:
   trunk/src/debug.c

Log:
[Debug] Added comments (Klaas-Jan Stol, RT #43044).

Modified: trunk/src/debug.c
==============================================================================
--- trunk/src/debug.c   (original)
+++ trunk/src/debug.c   Sun Jun  3 18:56:35 2007
@@ -29,25 +29,14 @@
 #include "parrot/debug.h"
 #include "parrot/oplib/ops.h"
 
-
 static const char* GDB_P(Interp *interp, const char *s);
 
-/* na(c) [Next Argument (Char pointer)]
- *
- * Moves the pointer to the next argument in the user input.
- */
-#define na(c) { \
-    while (*c && !isspace((int) *c)) \
-        c++; \
-    while (*c && isspace((int) *c)) \
-        c++; }
-
 /*
 
 =item C<static char* nextarg(char *command)>
 
 Returns the position just past the current argument in the PASM instruction
-C<command>. This is not the same as C<na()>, above, which is intended for
+C<command>. This is not the same as C<skip_command()>, which is intended for
 debugger commands. This function is used for C<eval>.
 
 =cut
@@ -97,7 +86,7 @@
 =item C<static const char* skip_command(const char *str)>
 
 Returns the pointer past the current debugger command. (This is an
-alternative to the C<na()> macro above.)
+alternative to the C<skip_command()> macro above.)
 
 =cut
 
@@ -238,7 +227,7 @@
 
 /*
 
-=item C<static const char*
+=item C<static const char *
 parse_command(const char *command, unsigned long *cmdP)>
 
 Convert the command at the beginning of a string into a numeric value
@@ -248,7 +237,7 @@
 
 */
 
-static const char*
+static const char *
 parse_command(const char *command, unsigned long *cmdP)
 {
     int           i;
@@ -379,7 +368,7 @@
     command = parse_command(command, &c);
 
     if (command)
-        na(command);
+        skip_command(command);
 
     switch (c) {
         case c_disassemble:
@@ -508,8 +497,7 @@
 =item C<void
 PDB_trace(Interp *interp, const char *command)>
 
-Execute the next N operations; if no number is specified, it defaults to
-1.
+Execute the next N operations; if no number is specified, it defaults to 1.
 
 =cut
 
@@ -522,15 +510,19 @@
     PDB_t         *pdb = interp->pdb;
     Interp        *debugee;
 
+    /* if debugger is not running yet, initialize */
     if (!(pdb->state & PDB_RUNNING))
         PDB_init(interp, command);
 
+    /* if the number of ops to run is specified, convert to a long */
     if (command && isdigit((int) *command))
         n = atol(command);
 
+    /* clear the PDB_STOPPED flag, we'll be running n ops now */
     pdb->state &= ~PDB_STOPPED;
     debugee     = pdb->debugee;
 
+    /* execute n ops */
     for (; n && pdb->cur_opcode; n--) {
         trace_op(debugee,
                 debugee->code->base.data,
@@ -540,6 +532,7 @@
         DO_OP(pdb->cur_opcode, debugee);
     }
 
+    /* we just stopped */
     pdb->state |= PDB_STOPPED;
 
     /* If program ended */
@@ -604,11 +597,14 @@
      * condition. */
     command++;
 
+    /* XXX Does /this/ have to do with the fact that PASM registers used to 
have
+     * maximum of 2 digits? If so, there should be a while loop, I think.
+     */
     if (condition->reg > 9)
         command++;
 
     if (*command == ' ')
-        na(command);
+        skip_command(command);
 
     /* Now the condition */
     switch (*command) {
@@ -646,13 +642,14 @@
             return NULL;
     }
 
+    /* if there's an '=', skip it */
     if (*(command + 1) == '=')
         command += 2;
     else
-        command ++;
+        command++;
 
     if (*command == ' ')
-        na(command);
+        skip_command(command);
 
     /* return if no more arguments */
     if (!(command && *command)) {
@@ -797,7 +794,7 @@
         /* Abort if the line number provided doesn't exist */
         if (!line->next) {
             PIO_eprintf(interp,
-                        "Can't set a breakpoint at line number %li\n",ln);
+                "Can't set a breakpoint at line number %li\n", ln);
             return;
         }
     }
@@ -822,13 +819,13 @@
     /* Allocate the new break point */
     newbreak = mem_allocate_typed(PDB_breakpoint_t);
 
-    na(command);
+    skip_command(command);
     condition = NULL;
 
     /* if there is another argument to break, besides the line number,
      * it should be an 'if', so we call another handler. */
     if (command && *command) {
-        na(command);
+        skip_command(command);
         if ((condition = PDB_cond(interp, command)))
             newbreak->condition = condition;
     }
@@ -989,10 +986,9 @@
 {
     PDB_breakpoint_t *breakpoint = PDB_find_breakpoint(interp, command);
 
+    /* if the breakpoint exists, disable it. */
     if (breakpoint)
         breakpoint->skip = -1;
-
-    return;
 }
 
 /*
@@ -1012,10 +1008,9 @@
 {
     PDB_breakpoint_t *breakpoint = PDB_find_breakpoint(interp, command);
 
+    /* if the breakpoint exists, and it was disabled, enable it. */
     if (breakpoint && breakpoint->skip == -1)
         breakpoint->skip = 0;
-
-    return;
 }
 
 /*
@@ -1941,11 +1936,18 @@
 {
     char h = 0;
 
+    /* as long as c is not NULL, we're not looking at a comment (#...) or a 
'\n'... */
     while (*c && *c != '#' && *c != '\n') {
-        if (isalnum((int) *c) || *c == '"')
+        /* ... and c is alphanumeric or a quoted string then the line contains
+         * an instruction. */
+        if (isalnum((int) *c) || *c == '"') {
             h = 1;
-        else if (*c == ':')
+        }
+        else if (*c == ':') {
+            /* this is a label. XXX right? */
             h = 0;
+        }
+
         c++;
     }
 
@@ -1986,7 +1988,7 @@
         else
             pdb->file->list_line = (unsigned long) line_number;
 
-        na(command);
+        skip_command(command);
     }
     else {
         pdb->file->list_line = 0;
@@ -1995,7 +1997,7 @@
     /* set the number of lines to print */
     if (isdigit((int) *command)) {
         n = atol(command);
-        na(command);
+        skip_command(command);
     }
 
     /* if n is zero, we simply return, as we don't have to print anything */

Reply via email to