Aldo Calpini <[EMAIL PROTECTED]> writes:

> Jürgen Bömmels wrote:
> > Hi,
> >
> > When you use pdb and hit just <ENTER> you get a segfault. Thats
> > quite anoying especially if you are used to gdbs behaviour.
> >
> > The attached patch fixes this by just ignoring empty lines.
> 
> this doesn't seem to me how pdb is supposed to work.
> docs/debugger.pod says:
> 
>      A blank line always repeat the last command entered.
> 
> and that's also perl -d behaviour.
> either fix it differently, or patch the documentation too :-)

Everything you want.
But I don't think the previous segfault was intended behaviour.

      A blank line always gets a segfault.

Ok, after some more debugging of the debugger i got it working like
documented.

bye
b.

Index: debug.c
===================================================================
RCS file: /cvs/public/parrot/debug.c,v
retrieving revision 1.38
diff -u -r1.38 debug.c
--- debug.c	14 Sep 2002 13:51:34 -0000	1.38
+++ debug.c	30 Sep 2002 21:19:08 -0000
@@ -158,8 +158,10 @@
     int i;
     unsigned long c = 0;
 
-    if (*command == '\0')
+    if (*command == '\0') {
+        *cmdP = c;
         return 0;
+    }
 
     for (i = 0; *command && isalpha((int) *command); command++, i++)
         c += (tolower((int) *command) + (i + 1)) * ((i + 1) * 255);
@@ -189,7 +191,7 @@
 void
 PDB_get_command(struct Parrot_Interp *interpreter)
 {
-    unsigned int i = 0;
+    unsigned int i;
     char *c;
     PDB_t *pdb = interpreter->pdb;
     PDB_line_t *line; 
@@ -220,18 +222,24 @@
         fprintf(stderr,"\n");
     }
 
-    i = 1;
+    i = 0;
 
     c = (char *)mem_sys_allocate(255);
 
     fprintf(stderr,"\n(pdb) ");
 
-    *c = (char)(ch = fgetc(stdin));
+    /* skip leading whitespace */
+    do {
+        ch = fgetc(stdin);
+    } while (isspace(ch) && ch != '\n');
+
+    /* generate string (no more than 255 chars) */
+     while (ch != EOF && ch != '\n' && (i < 255)) {
+        c[i++] = ch;
+        ch = fgetc(stdin);
+    }
 
-    while (ch != -1 && (c[i - 1] !=  '\n') && (i < 255))
-        c[i++] = (char)(ch = fgetc(stdin));
-    
-    c[--i] = '\0';
+    c[i] = '\0';
 
     if (ch == -1) strcpy(c, "quit");
     pdb->cur_command = c;
@@ -250,13 +258,10 @@
     int i;
     unsigned long c;
 
-    /* Skip trailing spaces */
-    command = skip_ws(command);
-
     /* get a number from what the user typed */
     command = parse_command(command, &c);
 
-    na(command);
+    if (command) na(command);
 
     switch (c) {
         case c_disassemble:

Reply via email to