Bug 11067 - p <enum constant> should print the constant's value
Summary: p <enum constant> should print the constant's value
Status: RESOLVED WONTFIX
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: 7.0
: P2 enhancement
Target Milestone: 7.1
Assignee: Chris Moller
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-12-08 21:48 UTC by Jeffrey Yasskin
Modified: 2023-04-13 20:47 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jeffrey Yasskin 2009-12-08 21:48:41 UTC
$ cat test.c
enum E {
Val1,
Val2
};
int main() {
    enum E e = Val1;
    return e;
}

...
Temporary breakpoint 1, main () at test.c:6
6           enum E e = Val1;
(gdb) n
7           return e;
(gdb) p e
$1 = Val1
(gdb) p Val1
$2 = Val1
(gdb) p (int)Val1
$3 = 0


When I print a variable, printing the symbolic name for its value is right, but 
when I print the symbolic name, gdb should print its numeric value instead (or 
in addition).

There's an easy workaround, of course, but gdb should DTRT in the first place.
Comment 1 Chris Moller 2010-02-16 02:49:52 UTC
Lacking any consensus on the utility, implementation, or display format for this
enhancement, and the evolving mutually exclusive requirements, there's no way to
make this enhancement work.
Comment 2 Paul Pluzhnikov 2010-02-16 03:58:23 UTC
For those not following the discussion, Chris attempted two
separate patches:
http://sourceware.org/ml/gdb-patches/2010-02/msg00179.html
http://sourceware.org/ml/gdb-patches/2010-02/msg00279.html
Comment 3 Jeffrey Yasskin 2010-02-16 05:17:00 UTC
Thanks, Chris, for your work on this. I guess such a simple change was just asking 
to be bikeshedded into oblivion.
Comment 4 Kamaraju Kusumanchi 2013-08-06 20:38:58 UTC
You can also use "p /d" as a work around. It is less typing than "p (int)"

(gdb) p /d Val1
$4 = 0
Comment 5 Pedro Alves 2013-08-08 09:52:37 UTC
Or:

 (gdb) p Val1+0

Which I find even easier to type, as what I actually usually do is:

 (gdb) p Val1
 $1 = Val1
 <up>+0<enter>
 $2 = 0
Comment 6 Andreas Schwab 2013-08-08 20:57:29 UTC
Or use the fact that the expression defaults to $.

(gdb) p Val1
$1 = Val1
(gdb) p/d
$2 = 0