[Bug gdb/34349] New: gdb prints wrong values for C compound literals
"eggert at cs dot ucla.edu via Gdb-prs" <[email protected]>
| Newsgroups | gmane.comp.gdb.bugs.discuss |
|---|---|
| Message-ID | <[email protected]/bugzilla/> |
https://sourceware.org/bugzilla/show_bug.cgi?id=34349
Bug ID: 34349
Summary: gdb prints wrong values for C compound literals
Product: gdb
Version: 17.2
Status: NEW
Severity: normal
Priority: P2
Component: gdb
Assignee: unassigned at sourceware dot org
Reporter: eggert at cs dot ucla.edu
Target Milestone: ---
GDB can't handle compound literals, when they're used as an approximation to
C++ static_casts. I discovered this problem when debugging a program that uses
that style (now used in Gnulib, Coreutils, Emacs, and some other GNU programs).
This feature was introduced in C99 and so is suitable now even for very
portable programs.
To reproduce the GDB bug, compile and debug a trivial program, like this:
$ cat >t.c <<'EOF'
int main(){}
EOF
$ gcc -g t.c
$ gdb a.out
...
(gdb) start main
...
Temporary breakpoint 1, main () at t.c:1
1 int main(){}
(gdb) p (char){'x'}
$6 = -112 '\220' <--- Incorrect; the correct value is 88 'X'
(gdb) p (long){1}
$1 = 4210704 <--- Incorrect; the correct value is 1.
(gdb) p *(long){1}
$3 = 1 <--- Incorrect; should be "Cannot access memory".
(gdb) p &(long){1}
Attempt to take address of value not located in memory. <--- Incorrect.
I marked incorrect output with "<---" comments.
Ideally GDB should be able to handle compound literals. If that's not possible
yet, it should output a diagnostic saying "not implemented" instead of silently
outputting the wrong value.
--
You are receiving this mail because:
You are on the CC list for the bug.