Re: pr 11067 patch resurrected from the dead

Chris Moller
2010-03-11T15:44:20Z

[-- Attachment #1: Type: text/plain, Size: 1520 bytes --]

On 02/23/10 18:54, Tom Tromey wrote:
>>>>>> "Jan" == Jan Kratochvil<jan.kratochvil@redhat.com> writes:
>>>>>>
>
> Finally catching up on this thread...
>
> Jan> I would prefer the value_print_options way but rather:
>

Okay, folks, I dusted this off and spun another simple patch using
value_print_options. Given an enum:

enum tt {
T0,
T1,
T2
};

enum tt tf = T1;

If you do

p /f tf

you'll get

$1 = T1 = (enum tt)1

of instead of the

$2 = T1

you'd get without the /f flag. (It's "/f" because 'f' isn't otherwise
used for enums--'f' for "fancy" or something like that.)

It also doesn't differentiate between printing single enums and enums in
more complex things like arrays. Given

enum tt ta[] = { T1, T0, T2 };

The result would be:

p /f ta
$3 = {T1 = (enum tt)1, T0 = (enum tt)0, T2 = (enum tt)2}

As an alternative, maybe it could print something like

$2 = (enum tt)1 <T1>

which kind looks like the result of printing a character.

As you can see in the attached check summary diff, this patch doesn't do
a thing to MI or anything else.

If people like this, great. Otherwise, I'll leave it dead and buried.

> Yes, I think value_print_options is preferable to checking
> ui_out_is_mi_like_p. My reason is that getting the ui-out object
> involves looking at some global state, whereas value_print_options is
> local to the call hierarchy. This means that it is simpler to reason
> about and modify.
>
> Tom
>

[-- Attachment #2: pr11067.patch --]
[-- Type: text/x-patch, Size: 3815 bytes --]

Index: printcmd.c
===================================================================
RCS file: /cvs/src/src/gdb/printcmd.c,v
retrieving revision 1.173
diff -u -r1.173 printcmd.c
--- printcmd.c 5 Mar 2010 20:18:14 -0000 1.173
+++ printcmd.c 11 Mar 2010 15:20:44 -0000
@@ -373,6 +373,46 @@
current_language);
return;
}
+
+ if (TYPE_CODE (type) == TYPE_CODE_ENUM
+ && options->format == 'f')
+ {
+ unsigned flen, i;
+ LONGEST val;
+
+ flen = TYPE_NFIELDS (type);
+ val = unpack_long (type, valaddr);
+
+ for (i = 0; i < flen; i++)
+ {
+ if (val == TYPE_FIELD_BITPOS (type, i))
+ {
+ break;
+ }
+ }
+ if (i < flen)
+ {
+ char *enum_name;
+
+ if (TYPE_NAME (type))
+ enum_name = TYPE_NAME (type);
+ else if (TYPE_TAG_NAME(type))
+ enum_name = TYPE_TAG_NAME(type);
+ else
+ enum_name = "<anonymous>";
+
+ fprintf_filtered (stream, "%s = (enum %s)%s",
+ TYPE_FIELD_NAME (type, i),
+ enum_name,
+ plongest (val));
+ }
+ else
+ {
+ warning (_("Enum fancy formatting failed, using simple format."));
+ print_longest (stream, 'd', 0, val);
+ }
+ return;
+ }

if (len > sizeof(LONGEST) &&
(TYPE_CODE (type) == TYPE_CODE_INT
Index: testsuite/gdb.base/Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/Makefile.in,v
retrieving revision 1.5
diff -u -r1.5 Makefile.in
--- testsuite/gdb.base/Makefile.in 15 Sep 2009 03:30:08 -0000 1.5
+++ testsuite/gdb.base/Makefile.in 11 Mar 2010 15:20:45 -0000
@@ -12,7 +12,8 @@
scope section_command setshow setvar shmain sigall signals \
solib solib_sl so-impl-ld so-indr-cl \
step-line step-test structs structs2 \
- twice-tmp varargs vforked-prog watchpoint whatis catch-syscall
+ twice-tmp varargs vforked-prog watchpoint whatis catch-syscall \
+ pr11067

MISCELLANEOUS = coremmap.data ../foobar.baz \
shr1.sl shr2.sl solib_sl.sl solib1.sl solib2.sl
Index: testsuite/gdb.base/pr11067.c
===================================================================
RCS file: testsuite/gdb.base/pr11067.c
diff -N testsuite/gdb.base/pr11067.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/gdb.base/pr11067.c 11 Mar 2010 15:20:45 -0000
@@ -0,0 +1,18 @@
+#include <stdio.h>
+
+typedef enum { E0, E1, E2 } ex_e;
+ex_e ef = E2;
+
+enum tt {
+ T0,
+ T1,
+ T2
+};
+
+enum tt tf = T1;
+
+int
+main()
+{
+ return 0;
+}
Index: testsuite/gdb.base/pr11067.exp
===================================================================
RCS file: testsuite/gdb.base/pr11067.exp
diff -N testsuite/gdb.base/pr11067.exp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/gdb.base/pr11067.exp 11 Mar 2010 15:20:45 -0000
@@ -0,0 +1,28 @@
+# Copyright 2010 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+set testfile pr11067
+set srcfile ${testfile}.c
+if [prepare_for_testing $testfile.exp $testfile $srcfile {debug}] {
+ return -1
+}
+
+if ![runto_main] then {
+ fail "Can't run to main"
+ return
+}
+
+gdb_test "p /f tf" "T1 = \\(enum tt\\)1.*"
+gdb_test "p /f ef" "E2 = \\(enum <anonymous>\\)2.*"

[-- Attachment #3: pr11067-check.diff --]
[-- Type: text/x-patch, Size: 1475 bytes --]

--- ../../../gdb-virgin.sum 2010-03-09 21:36:05.994326240 -0500
+++ gdb.sum 2010-03-11 10:26:51.188200869 -0500
@@ -1,4 +1,4 @@
-Test Run By moller on Tue Mar 9 19:14:09 2010
+Test Run By moller on Thu Mar 11 10:18:45 2010
Native configuration is i686-pc-linux-gnu

=== gdb tests ===
@@ -5703,6 +5703,9 @@
PASS: gdb.base/pr11022.exp: breakpoint hit 2
PASS: gdb.base/pr11022.exp: set var x = 1
PASS: gdb.base/pr11022.exp: watchpoint hit 2
+Running ../../../src/gdb/testsuite/gdb.base/pr11067.exp ...
+PASS: gdb.base/pr11067.exp: p /f tf
+PASS: gdb.base/pr11067.exp: p /f ef
Running ../../../src/gdb/testsuite/gdb.base/prelink.exp ...
PASS: gdb.base/prelink.exp: set verbose on
PASS: gdb.base/prelink.exp: prelink
@@ -16058,7 +16061,7 @@
PASS: gdb.threads/watchthreads2.exp: all threads started
PASS: gdb.threads/watchthreads2.exp: watch x
PASS: gdb.threads/watchthreads2.exp: set var test_ready = 1
-PASS: gdb.threads/watchthreads2.exp: all threads incremented x
+KFAIL: gdb.threads/watchthreads2.exp: gdb can drop watchpoints in multithreaded app (PRMS: gdb/10116)
Running ../../../src/gdb/testsuite/gdb.trace/actions.exp ...
PASS: gdb.trace/actions.exp: 5.1a: set three tracepoints, no actions
PASS: gdb.trace/actions.exp: 5.1b: set actions for first tracepoint
@@ -16259,7 +16262,7 @@

=== gdb Summary ===

-# of expected passes 15452
+# of expected passes 15453
# of unexpected failures 16
# of expected failures 43
# of untested testcases 3