cvsuser 02/07/13 15:41:26
Modified: . debug.c trace.c
Log:
Fixed debugger and opcode tracing code to avoid assuming that constant
strings in the bytecode are zero terminated as they aren't.
Revision Changes Path
1.14 +12 -5 parrot/debug.c
Index: debug.c
===================================================================
RCS file: /cvs/public/parrot/debug.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -w -r1.13 -r1.14
--- debug.c 4 Jul 2002 20:39:44 -0000 1.13
+++ debug.c 13 Jul 2002 22:41:25 -0000 1.14
@@ -2,7 +2,7 @@
* debug.c
*
* CVS Info
- * $Id: debug.c,v 1.13 2002/07/04 20:39:44 mrjoltcola Exp $
+ * $Id: debug.c,v 1.14 2002/07/13 22:41:25 tom Exp $
* Overview:
* Parrot debugger
* History:
@@ -501,18 +501,23 @@
* escapes " \r \n \t \a and \\
*/
char *
-PDB_escape(const char *string)
+PDB_escape(const char *string, INTVAL length)
{
+ const char *end = string + length;
char *new,*fill;
/* Return if there is no string to escape*/
if (!string || !*string)
return NULL;
- fill = new = (char *)mem_sys_allocate(strlen(string) * 2);
+ fill = new = (char *)mem_sys_allocate(length * 2 + 1);
- for ( ; *string; string++) {
+ for ( ; string < end; string++) {
switch (*string) {
+ case '\0':
+ *(fill++) = '\\';
+ *(fill++) = '0';
+ break;
case '\n':
*(fill++) = '\\';
*(fill++) = 'n';
@@ -692,7 +697,9 @@
constants[pc[j]]->string->strlen)
{
escaped = PDB_escape(interpreter->code->const_table->
- constants[pc[j]]->string->bufstart);
+ constants[pc[j]]->string->bufstart,
+ interpreter->code->const_table->
+ constants[pc[j]]->string->strlen);
if (escaped)
{
strcpy(&pfile->source[pfile->size],escaped);
1.17 +7 -3 parrot/trace.c
Index: trace.c
===================================================================
RCS file: /cvs/public/parrot/trace.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -w -r1.16 -r1.17
--- trace.c 4 Jul 2002 20:39:44 -0000 1.16
+++ trace.c 13 Jul 2002 22:41:26 -0000 1.17
@@ -1,7 +1,7 @@
/* trace.c
* Copyright: (When this is determined...it will go here)
* CVS Info
- * $Id: trace.c,v 1.16 2002/07/04 20:39:44 mrjoltcola Exp $
+ * $Id: trace.c,v 1.17 2002/07/13 22:41:26 tom Exp $
* Overview:
* Tracing support for runops_cores.c.
* Data Structure and Algorithms:
@@ -48,7 +48,9 @@
break;
case PARROT_ARG_SC:
escaped = PDB_escape(interpreter->code->const_table->
- constants[*(pc + i)]->string->bufstart);
+ constants[*(pc + i)]->string->bufstart,
+ interpreter->code->const_table->
+ constants[*(pc + i)]->string->strlen);
fprintf(stderr, "\"%s\"", escaped);
break;
case PARROT_ARG_KC:
@@ -71,7 +73,9 @@
case PARROT_ARG_S:
if (interpreter->ctx.string_reg.registers[*(pc + i)]) {
escaped = PDB_escape(interpreter->ctx.string_reg.
- registers[*(pc + i)]->bufstart);
+ registers[*(pc + i)]->bufstart,
+ interpreter->ctx.string_reg.
+ registers[*(pc + i)]->strlen);
fprintf(stderr, "S%ld=\"%s\"", (long)*(pc + i),
escaped);
}