question about c-lang.c

Tom Tromey
2002-09-10T23:29:06Z

Today I happened to read c-lang.c:c_emit_char().

Suppose a string contains the characters \0 (nul), `0' and finally `1'.
(See appended source.)

Now print this string:

(gdb) p *c @ 4
$2 = "\001"

This output is ambiguous, as \001 has another meaning.

I believe this is a problem for programs using MI. They can't
correctly parse this output (should they want to).

I've appended one possible fix. This isn't ideal since it also
changes how char literals are printed. Perhaps that is acceptable?

Tom

#include <stdio.h>

char *c = "\00001";

int main ()
{
printf ("%s\n", c);
return 0;
}

Index: ChangeLog
from Tom Tromey <tromey@redhat.com>

* c-lang.c (c_emit_char): Don't treat \0 specially.

Index: c-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/c-lang.c,v
retrieving revision 1.13
diff -u -r1.13 c-lang.c
--- c-lang.c 11 Jul 2002 13:50:49 -0000 1.13
+++ c-lang.c 10 Sep 2002 23:26:06 -0000
@@ -78,9 +78,6 @@
case '\007':
fputs_filtered ("\\a", stream);
break;
- case '\0':
- fputs_filtered ("\\0", stream);
- break;
default:
fprintf_filtered (stream, "\\%.3o", (unsigned int) c);
break;