Re: question about c-lang.c

Fred Viles
2002-09-13T00:17:06Z

On 12 Sep 2002 at 17:44, Andrew Cagney wrote about
"Re: question about c-lang.c":

| > 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.
|
| Isn't it simply wrong? A C parser would treat that as '\1'.

Right.

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

Looks to me like c_emit_char() is called both for char and string
cases. So char c = '\0'; would result in
(gdb) print c
$1 = '\000'
rather than
$1 = '\0'

From the change log, it looks like GDB used to work this way and was
patched last December to get the current (wrong for strings)
behavior.

Maybe making the output conditional on (quoter == '\'') would allow
for both cases.

- Fred