Re: pr 11067 patch

Chris Moller
2010-02-12T15:48:25Z

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

Herewith, if anyone is interested, is what I expect is the final version
of this patch, incorporating Joel's comments. Absent any objections, I
expect I'll commit it Monday (just to give people time to object :-) ).

[Joel, thanks for the link to the GDBTestcaseCookbook--extracting
coherence from lots of oral tradition and examples dating from the mists
of the distant past wasn't working well.]

On 02/11/10 23:11, Joel Brobecker wrote:
>> If you disagree strongly, then we could just close the PR and drop it, I
>> suppose. I am not very intent on this, I just thought it would be a
>> nice, if minor, enhancement. I didn't see a real downside.
>>
>
> Not at all, I cannot say I like the idea, but if it's useful to others,
> this is all that really matters. Let's go ahead, then.
>
> Regarding GNU indent - I know. But I try to keep formatting the code
> the way GNU indent would do it in sane situations, as it helps keeping
> some uniformity to our code. There are some rules I don't like (ahem,
> ask me about spaces and tabs), but I think that uniformity is more
> important...
>
> I'm happy I contributed just a little bit towards this patch - I really
> felt bad reacting to it so so late in the game.
>
>

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

Index: gdb/ChangeLog
===================================================================
RCS file: /cvs/src/src/gdb/ChangeLog,v
retrieving revision 1.11340
diff -u -r1.11340 ChangeLog
--- gdb/ChangeLog 9 Feb 2010 15:52:57 -0000 1.11340
+++ gdb/ChangeLog 12 Feb 2010 15:37:46 -0000
@@ -1,3 +1,10 @@
+Wed Feb 10 17:13:44 2010 Chris Moller <moller@mollerware.com>
+
+ PR gdb/11067
+ * c-valprint.c (c_val_print): In case TYPE_CODE_ENUM, add code to
+ print the numeric value of the enum and the enum tag for
+ top-level, non-summary "print enum"s.
+
2010-02-09 Tristan Gingold <gingold@adacore.com>

* machoread.c (macho_symfile_relocate): New function.
Index: gdb/c-valprint.c
===================================================================
RCS file: /cvs/src/src/gdb/c-valprint.c,v
retrieving revision 1.67
diff -u -r1.67 c-valprint.c
--- gdb/c-valprint.c 2 Feb 2010 16:45:16 -0000 1.67
+++ gdb/c-valprint.c 12 Feb 2010 15:37:47 -0000
@@ -412,9 +412,30 @@
}
}
if (i < len)
- {
+ /*
+ When printing a simple enum value, the following code includes, in
+ addition to the symbolic value, the numeric value and the enum tag.
+ Under other-than-simple circumstances--in structs, arrays, etc.--
+ it does what's always done and prints just the symbolic value.
+ */
+ if (options->summary || recurse != 0)
fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
- }
+ else
+ {
+ 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
{
print_longest (stream, 'd', 0, val);
Index: gdb/testsuite/ChangeLog
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/ChangeLog,v
retrieving revision 1.2128
diff -u -r1.2128 ChangeLog
--- gdb/testsuite/ChangeLog 9 Feb 2010 13:16:33 -0000 1.2128
+++ gdb/testsuite/ChangeLog 12 Feb 2010 15:38:04 -0000
@@ -1,3 +1,19 @@
+Wed Feb 10 17:18:17 2010 Chris Moller <moller@mollerware.com>
+
+ PR gdb/11067
+ * gdb.base/pr11067.c: New file.
+ * gdb.base/pr11067.exp: New file.
+ * gdb.base/Makefile.in (EXECUTABLES): Added pr11067
+ * gdb.cp/classes.exp:
+ * gdb.cp/m-data.exp:
+ * gdb.cp/m-static.exp:
+ * gdb.cp/namespace.exp:
+ * gdb.mi/mi-var-display.exp:
+ * gdb.mi/mi2-var-display.exp:
+ * gdb.python/py-value.exp:
+ * gdb.base/setvar.exp: Updated expects to the new enum format.
+
+
2010-02-09 Joel Brobecker <brobecker@adacore.com>

* gdb.ada/ptype_tagged_param: New testcase.
Index: gdb/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
--- gdb/testsuite/gdb.base/Makefile.in 15 Sep 2009 03:30:08 -0000 1.5
+++ gdb/testsuite/gdb.base/Makefile.in 12 Feb 2010 15:38:04 -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: gdb/testsuite/gdb.base/pr11067.c
===================================================================
RCS file: gdb/testsuite/gdb.base/pr11067.c
diff -N gdb/testsuite/gdb.base/pr11067.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gdb/testsuite/gdb.base/pr11067.c 12 Feb 2010 15:38:05 -0000
@@ -0,0 +1,48 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ 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/>. */
+
+enum E {
+ Val1 = 56,
+ Val2
+};
+
+struct Es {
+ int v;
+ enum E e;
+};
+
+enum E e = Val1;
+
+enum E ea[] = { Val1, Val2, Val1 };
+
+struct Es es = { 5, Val2 };
+
+int main() {
+ /*
+ The following is a fake-out for linkers (such as, apparently, the AIX
+ linker) that optimises out unreference variables.
+ */
+
+ e = Val2;
+
+ ea[0] = Val2;
+
+ es.v = 99;
+
+ return 0;
+}
+
Index: gdb/testsuite/gdb.base/pr11067.exp
===================================================================
RCS file: gdb/testsuite/gdb.base/pr11067.exp
diff -N gdb/testsuite/gdb.base/pr11067.exp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gdb/testsuite/gdb.base/pr11067.exp 12 Feb 2010 15:38:05 -0000
@@ -0,0 +1,31 @@
+# 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}] } {
+ return -1
+}
+
+if ![runto_main] {
+ return -1
+}
+
+gdb_test "print e" "Val1 = \\(enum E\\)56"
+
+gdb_test "print ea" "{Val1, Val2, Val1}"
+
+gdb_test "print es" "v = 5, e = Val2}"
Index: gdb/testsuite/gdb.base/setvar.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/setvar.exp,v
retrieving revision 1.19
diff -u -r1.19 setvar.exp
--- gdb/testsuite/gdb.base/setvar.exp 29 Jan 2010 15:38:37 -0000 1.19
+++ gdb/testsuite/gdb.base/setvar.exp 12 Feb 2010 15:38:05 -0000
@@ -399,18 +399,22 @@
# GNU C supports them, some other compilers don't.

if {$gcc_compiled} then {
- gdb_test "print sef.field=sm1" ".*.\[0-9\]* = sm1"
- gdb_test "print sef.field" ".*.\[0-9\]* = sm1" "print sef.field (sm1)"
- gdb_test "print sef.field=s1" ".*.\[0-9\]* = s1"
- gdb_test "print sef.field" ".*.\[0-9\]* = s1" "print sef.field (s1)"
- gdb_test "print uef.field=u2" ".*.\[0-9\]* = u2"
- gdb_test "print uef.field" ".*.\[0-9\]* = u2" "print uef.field (u2)"
- gdb_test "print uef.field=u1" ".*.\[0-9\]* = u1"
- gdb_test "print uef.field" ".*.\[0-9\]* = u1" "print uef.field (u1)"
+ gdb_test "print sef.field=sm1" ".*.\[0-9\]* = sm1 = \\(enum senum\\)-1"
+ gdb_test "print sef.field" ".*.\[0-9\]* = sm1 = \\(enum senum\\)-1" \
+ "print sef.field (sm1)"
+ gdb_test "print sef.field=s1" ".*.\[0-9\]* = s1 = \\(enum senum\\)1"
+ gdb_test "print sef.field" ".*.\[0-9\]* = s1 = \\(enum senum\\)1" \
+ "print sef.field (s1)"
+ gdb_test "print uef.field=u2" ".*.\[0-9\]* = u2 = \\(enum uenum\\)2"
+ gdb_test "print uef.field" ".*.\[0-9\]* = u2 = \\(enum uenum\\)2" \
+ "print uef.field (u2)"
+ gdb_test "print uef.field=u1" ".*.\[0-9\]* = u1 = \\(enum uenum\\)1"
+ gdb_test "print uef.field" ".*.\[0-9\]* = u1 = \\(enum uenum\\)1" \
+ "print uef.field (u1)"

# Test for truncation when assigning invalid values to bitfields.
gdb_test "print sef.field=7" \
- ".*warning: Value does not fit in 2 bits.*\[0-9\]* = sm1"
+ ".*warning: Value does not fit in 2 bits.*\[0-9\]* = sm1 = \\(enum senum\\)-1"
gdb_test "print uef.field=6" \
- ".*warning: Value does not fit in 2 bits.*\[0-9\]* = u2"
+ ".*warning: Value does not fit in 2 bits.*\[0-9\]* = u2 = \\(enum uenum\\)2"
}
Index: gdb/testsuite/gdb.cp/classes.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.cp/classes.exp,v
retrieving revision 1.24
diff -u -r1.24 classes.exp
--- gdb/testsuite/gdb.cp/classes.exp 1 Jan 2010 07:32:01 -0000 1.24
+++ gdb/testsuite/gdb.cp/classes.exp 12 Feb 2010 15:38:06 -0000
@@ -413,7 +413,7 @@

# print the enum member

- gdb_test "print obj_with_enum.priv_enum" "\\$\[0-9\]+ = (ClassWithEnum::)?green"
+ gdb_test "print obj_with_enum.priv_enum" "\\$\[0-9\]+ = (ClassWithEnum::)?green = \\(enum ClassWithEnum::PrivEnum\\)1"

# ptype on the enum member

@@ -482,7 +482,7 @@
}

gdb_test_multiple "print ('ClassWithEnum::PrivEnum') 42" "print ('ClassWithEnum::PrivEnum') 42" {
- -re "\\$\[0-9\]+ = (ClassWithEnum::)?yellow$nl$gdb_prompt $" {
+ -re "\\$\[0-9\]+ = (ClassWithEnum::)?yellow = \\(enum ClassWithEnum::PrivEnum\\)42$nl$gdb_prompt $" {
# gcc 3.3.2 -gstabs+
# gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
pass "print ('ClassWithEnum::PrivEnum') 42"
Index: gdb/testsuite/gdb.cp/m-data.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.cp/m-data.exp,v
retrieving revision 1.7
diff -u -r1.7 m-data.exp
--- gdb/testsuite/gdb.cp/m-data.exp 1 Jan 2010 07:32:01 -0000 1.7
+++ gdb/testsuite/gdb.cp/m-data.exp 12 Feb 2010 15:38:06 -0000
@@ -71,7 +71,7 @@
gdb_test "print test1.key2" "\\$\[0-9\]* = 4589" "simple object, long"

# simple object, enum
-gdb_test "print test1.value" "\\$\[0-9\]* = egyptian" "simple object, enum"
+gdb_test "print test1.value" "\\$\[0-9\]* = egyptian = \\(enum region\\)1" "simple object, enum"

# Two.

@@ -85,10 +85,10 @@
gdb_test "print test2.key2" "\\$\[0-9\]* = 7" "derived template object, base long"

# derived template object, base enum
-gdb_test "print test2.value" "\\$\[0-9\]* = oriental" "derived template object, base enum"
+gdb_test "print test2.value" "\\$\[0-9\]* = oriental = \\(enum region\\)0" "derived template object, base enum"

# derived template object, enum
-gdb_test "print test2.value_derived" "\\$\[0-9\]* = roman" "derived template object, derived enum"
+gdb_test "print test2.value_derived" "\\$\[0-9\]* = roman = \\(enum region\\)4" "derived template object, derived enum"

# Three.

@@ -102,10 +102,10 @@
gdb_test "print test3.data.key2" "\\$\[0-9\]* = 7" "template object, long"

# template object, derived template data member's base enum
-gdb_test "print test3.data.value" "\\$\[0-9\]* = oriental" "template object, base enum"
+gdb_test "print test3.data.value" "\\$\[0-9\]* = oriental = \\(enum region\\)0" "template object, base enum"

# template object, derived template data member's enum
-gdb_test "print test3.data.value_derived" "\\$\[0-9]\* = etruscan" "template object, derived enum"
+gdb_test "print test3.data.value_derived" "\\$\[0-9]\* = etruscan = \\(enum region\\)3" "template object, derived enum"

# Now some tests for shadowing (see PR gdb/804):

Index: gdb/testsuite/gdb.cp/m-static.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.cp/m-static.exp,v
retrieving revision 1.9
diff -u -r1.9 m-static.exp
--- gdb/testsuite/gdb.cp/m-static.exp 1 Jan 2010 07:32:01 -0000 1.9
+++ gdb/testsuite/gdb.cp/m-static.exp 12 Feb 2010 15:38:06 -0000
@@ -82,7 +82,7 @@
gdb_test "print test1.key2" "\\$\[0-9\]* = 77" "simple object, static long"

# simple object, static enum
-gdb_test "print test1.value" "\\$\[0-9\]* = oriental" "simple object, static enum"
+gdb_test "print test1.value" "\\$\[0-9\]* = oriental = \\(enum region\\)0" "simple object, static enum"

# Two.

@@ -96,10 +96,10 @@
gdb_test "print test2.key2" "\\$\[0-9\]* = 77" "derived template object, base static long"

# derived template object, base static enum
-gdb_test "print test2.value" "\\$\[0-9\].* = oriental" "derived template object, base static enum"
+gdb_test "print test2.value" "\\$\[0-9\].* = oriental = \\(enum region\\)0" "derived template object, base static enum"

# derived template object, static enum
-gdb_test "print test2.value_derived" "\\$\[0-9\].* = etruscan" "derived template object, static enum"
+gdb_test "print test2.value_derived" "\\$\[0-9\].* = etruscan = \\(enum region\\)3" "derived template object, static enum"

# Three.

@@ -113,10 +113,10 @@
gdb_test "print test3.data.key2" "\\$\[0-9\].* = 77" "template object, static long"

# template object, static derived template data member's base static enum
-gdb_test "print test3.data.value" "\\$\[0-9\].* = oriental" "template object, static enum"
+gdb_test "print test3.data.value" "\\$\[0-9\].* = oriental = \\(enum region\\)0" "template object, static enum"

# template object, static derived template data member's static enum
-gdb_test "print test3.data.value_derived" "\\$\[0-9\].* = etruscan" "template object, static derived enum"
+gdb_test "print test3.data.value_derived" "\\$\[0-9\].* = etruscan = \\(enum region\\)3" "template object, static derived enum"

# 2002-08-16
# Four.
Index: gdb/testsuite/gdb.cp/namespace.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.cp/namespace.exp,v
retrieving revision 1.16
diff -u -r1.16 namespace.exp
--- gdb/testsuite/gdb.cp/namespace.exp 19 Jan 2010 18:11:19 -0000 1.16
+++ gdb/testsuite/gdb.cp/namespace.exp 12 Feb 2010 15:38:06 -0000
@@ -273,4 +273,4 @@
gdb_test "print XOtherFile" "No symbol \"XOtherFile\" in current context."

# Enum tests.
-gdb_test "print AAA::ALPHA" "\\$\[0-9\].* = AAA::ALPHA"
+gdb_test "print AAA::ALPHA" "\\$\[0-9\].* = AAA::ALPHA = \\(enum AAA::SomeEnum\\)0"
Index: gdb/testsuite/gdb.mi/mi-var-display.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.mi/mi-var-display.exp,v
retrieving revision 1.34
diff -u -r1.34 mi-var-display.exp
--- gdb/testsuite/gdb.mi/mi-var-display.exp 1 Jan 2010 07:32:03 -0000 1.34
+++ gdb/testsuite/gdb.mi/mi-var-display.exp 12 Feb 2010 15:38:07 -0000
@@ -568,7 +568,7 @@
# Test: c_variable-7.61
# Desc: value of anone
mi_gdb_test "-var-evaluate-expression anone" \
- "\\^done,value=\"A\"" \
+ "\\^done,value=\"A = \\(enum <anonymous>\\)0\"" \
"eval variable anone"

# Test: c_variable-7.70
Index: gdb/testsuite/gdb.mi/mi2-var-display.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.mi/mi2-var-display.exp,v
retrieving revision 1.27
diff -u -r1.27 mi2-var-display.exp
--- gdb/testsuite/gdb.mi/mi2-var-display.exp 1 Jan 2010 07:32:03 -0000 1.27
+++ gdb/testsuite/gdb.mi/mi2-var-display.exp 12 Feb 2010 15:38:08 -0000
@@ -567,7 +567,7 @@
# Test: c_variable-7.61
# Desc: value of anone
mi_gdb_test "-var-evaluate-expression anone" \
- "\\^done,value=\"A\"" \
+ "\\^done,value=\"A = \\(enum <anonymous>\\)0\"" \
"eval variable anone"

# Test: c_variable-7.70
Index: gdb/testsuite/gdb.python/py-value.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.python/py-value.exp,v
retrieving revision 1.5
diff -u -r1.5 py-value.exp
--- gdb/testsuite/gdb.python/py-value.exp 14 Jan 2010 08:03:37 -0000 1.5
+++ gdb/testsuite/gdb.python/py-value.exp 12 Feb 2010 15:38:08 -0000
@@ -115,7 +115,7 @@
gdb_test "python print 'result = ' + str(1.5+f)" " = 2.75" "add python float with double value"

# Conversion test.
- gdb_test "print evalue" " = TWO"
+ gdb_test "print evalue" " = TWO = \\(enum e\\)2"
gdb_test "python evalue = gdb.history (0)" ""
gdb_test "python print int (evalue)" "2"

[-- Attachment #3: pr11067-check.diff --]
[-- Type: text/plain, Size: 1917 bytes --]

--- gdb-virgin.sum 2010-02-10 08:57:04.980039916 -0500
+++ gdb-patched.sum 2010-02-12 10:36:03.075165127 -0500
@@ -1,4 +1,4 @@
-Test Run By moller on Wed Feb 10 08:49:14 2010
+Test Run By moller on Fri Feb 12 10:27:31 2010
Native configuration is i686-pc-linux-gnu

=== gdb tests ===
@@ -5646,6 +5646,10 @@
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: print e
+PASS: gdb.base/pr11067.exp: print ea
+PASS: gdb.base/pr11067.exp: print es
Running ../../../src/gdb/testsuite/gdb.base/prelink.exp ...
PASS: gdb.base/prelink.exp: prelink
Running ../../../src/gdb/testsuite/gdb.base/printcmds.exp ...
@@ -12669,6 +12673,7 @@
PASS: gdb.mi/mi-simplerun.exp: step at main
PASS: gdb.mi/mi-simplerun.exp: step to callee4
PASS: gdb.mi/mi-simplerun.exp: exec-finish
+FAIL: gdb.mi/mi-simplerun.exp: continue to end (failed to resume)
PASS: gdb.mi/mi-simplerun.exp: continue to end
Running ../../../src/gdb/testsuite/gdb.mi/mi-stack.exp ...
PASS: gdb.mi/mi-stack.exp: breakpoint at callee4
@@ -15509,7 +15514,7 @@
PASS: gdb.threads/watchthreads.exp: successfully compiled posix threads test case
PASS: gdb.threads/watchthreads.exp: watch args[0]
PASS: gdb.threads/watchthreads.exp: watch args[1]
-PASS: gdb.threads/watchthreads.exp: disable 3
+PASS: gdb.threads/watchthreads.exp: disable 2
PASS: gdb.threads/watchthreads.exp: threaded watch loop
PASS: gdb.threads/watchthreads.exp: first watchpoint on args[0] hit
PASS: gdb.threads/watchthreads.exp: first watchpoint on args[1] hit
@@ -15713,8 +15718,8 @@

=== gdb Summary ===

-# of expected passes 14910
-# of unexpected failures 22
+# of expected passes 14913
+# of unexpected failures 23
# of expected failures 41
# of untested testcases 3
# of unsupported tests 64