Patchwork [RFA,2/2] Set TYPE_NAME for Rust unions

login
register
mail settings
Submitter Tom Tromey
Date April 12, 2018, 7:07 p.m.
Message ID <20180412190756.16052-3-tom@tromey.com>
Download mbox | patch
Permalink /patch/26702/
State New
Headers show

Comments

Tom Tromey - April 12, 2018, 7:07 p.m.
I noticed that read_structure_type sets TYPE_NAME to TYPE_TAG_NAME for
some things, but not for unions.  For Rust, I think we want to do this
for all types, so this patch adds the needed code.

I think that TYPE_TAG_NAME is confusing and should probably be
removed.  I am working on a patch to do this, but in the meantime this
seemed like a reasonable change to apply.  I suspect this change would
be ok for C++ as well, but I do not know about D.

2018-04-12  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (read_structure_type): Set TYPE_NAME for rust
	unions.
---
 gdb/ChangeLog    | 5 +++++
 gdb/dwarf2read.c | 4 +++-
 2 files changed, 8 insertions(+), 1 deletion(-)
Joel Brobecker - April 13, 2018, 7:40 a.m.
> I think that TYPE_TAG_NAME is confusing and should probably be
> removed.  I am working on a patch to do this, but in the meantime this
> seemed like a reasonable change to apply.  I suspect this change would
> be ok for C++ as well, but I do not know about D.

I agree that TYPE_TAG_NAME is confusing, and I would welcome it being
removed.

> 2018-04-12  Tom Tromey  <tom@tromey.com>
> 
> 	* dwarf2read.c (read_structure_type): Set TYPE_NAME for rust
> 	unions.

The patch looks good to me, but I'd like to see if others have comments
about C++. I'm trying to remember if C++ enums might have different
rules compared to C enums, and I'm not remembering any... If there
weren't any difference, and things were OK with C enums, one might
think that we're OK for C++ enums as well...

No way to test this either?
Tom Tromey - April 17, 2018, 7:37 p.m.
>>>>> "Joel" == Joel Brobecker <brobecker@adacore.com> writes:

>> 2018-04-12  Tom Tromey  <tom@tromey.com>
>> 
>> * dwarf2read.c (read_structure_type): Set TYPE_NAME for rust
>> unions.

Joel> The patch looks good to me, but I'd like to see if others have comments
Joel> about C++. I'm trying to remember if C++ enums might have different
Joel> rules compared to C enums, and I'm not remembering any... If there
Joel> weren't any difference, and things were OK with C enums, one might
Joel> think that we're OK for C++ enums as well...

Joel> No way to test this either?

I am not sure.  However, my TYPE_TAG_NAME deletion patch is ready now
(I'll send it momentarily), so I think we can just drop this one,
because that patch obsoletes it.

Tom

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index ceaa5f92ab..f2bb3d0af3 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@ 
 2018-04-12  Tom Tromey  <tom@tromey.com>
 
+	* dwarf2read.c (read_structure_type): Set TYPE_NAME for rust
+	unions.
+
+2018-04-12  Tom Tromey  <tom@tromey.com>
+
 	* dwarf2read.c (quirk_rust_enum): Conditionally drop the
 	discriminant field.
 
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 4207e4c531..e3f544a6a4 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -15631,7 +15631,9 @@  read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
 
 	  TYPE_TAG_NAME (type) = full_name;
 	  if (die->tag == DW_TAG_structure_type
-	      || die->tag == DW_TAG_class_type)
+	      || die->tag == DW_TAG_class_type
+	      || (cu->language == language_rust
+		  && die->tag == DW_TAG_union_type))
 	    TYPE_NAME (type) = TYPE_TAG_NAME (type);
 	}
       else