Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [rfc] Recognize GCC pointer to member function DWARF2 descriptions
@ 2006-08-07  2:57 Daniel Jacobowitz
  2006-08-18  9:21 ` Daniel Jacobowitz
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Jacobowitz @ 2006-08-07  2:57 UTC (permalink / raw)
  To: gdb-patches

GCC emits DW_TAG_ptr_to_member_type for pointers to member data, but not
for pointers to member functions.  I plan to fix this in GCC eventually,
but in the mean time, this does some pattern recognition on the GCC
output to convert it into a pointer to member.  It recognizes structures
of the form:

struct {
  void (*__pfn) (args, ...);
  ptrdiff_t __delta;
};

Comments?  This isn't beautiful, but I don't think it's unbearably
ugly, either.

-- 
Daniel Jacobowitz
CodeSourcery

2006-08-06  Daniel Jacobowitz  <dan@codesourcery.com>

	* dwarf2read.c (quirk_gcc_member_function_pointer): New.
	(read_structure_type): Call it.

Index: src/gdb/dwarf2read.c
===================================================================
--- src.orig/gdb/dwarf2read.c	2006-08-05 10:10:11.000000000 -0400
+++ src/gdb/dwarf2read.c	2006-08-06 22:52:02.000000000 -0400
@@ -3708,6 +3708,69 @@ is_vtable_name (const char *name, struct
   return 0;
 }
 
+/* GCC outputs unnamed structures that are really pointers to member
+   functions, with the ABI-specified layout.  If DIE (from CU) describes
+   such a structure, set its type, and return nonzero.  Otherwise return
+   zero.  */
+
+static int
+quirk_gcc_member_function_pointer (struct die_info *die, struct dwarf2_cu *cu)
+{
+  struct objfile *objfile = cu->objfile;
+  struct type *type;
+  struct die_info *pfn_die, *delta_die;
+  struct attribute *pfn_name, *delta_name;
+  struct type *pfn_type, *domain_type;
+
+  /* Check for a structure with no name and two children.  */
+  if (die->tag != DW_TAG_structure_type
+      || dwarf2_attr (die, DW_AT_name, cu) != NULL
+      || die->child == NULL
+      || die->child->sibling == NULL
+      || (die->child->sibling->sibling != NULL
+	  && die->child->sibling->sibling->tag != DW_TAG_padding))
+    return 0;
+
+  /* Check for __pfn and __delta members.  */
+  pfn_die = die->child;
+  pfn_name = dwarf2_attr (pfn_die, DW_AT_name, cu);
+  if (pfn_die->tag != DW_TAG_member
+      || pfn_name == NULL
+      || DW_STRING (pfn_name) == NULL
+      || strcmp ("__pfn", DW_STRING (pfn_name)) != 0)
+    return 0;
+
+  delta_die = pfn_die->sibling;
+  delta_name = dwarf2_attr (delta_die, DW_AT_name, cu);
+  if (delta_die->tag != DW_TAG_member
+      || delta_name == NULL
+      || DW_STRING (delta_name) == NULL
+      || strcmp ("__delta", DW_STRING (delta_name)) != 0)
+    return 0;
+
+  /* Find the type of the method.  */
+  pfn_type = die_type (pfn_die, cu);
+  if (pfn_type == NULL
+      || TYPE_CODE (pfn_type) != TYPE_CODE_PTR
+      || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC)
+    return 0;
+
+  /* Look for the "this" argument.  */
+  pfn_type = TYPE_TARGET_TYPE (pfn_type);
+  if (TYPE_NFIELDS (pfn_type) == 0
+      || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR)
+    return 0;
+
+  domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0));
+  type = alloc_type (objfile);
+  smash_to_method_type (type, domain_type, TYPE_TARGET_TYPE (pfn_type),
+			TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type),
+			TYPE_VARARGS (pfn_type));
+  type = lookup_methodptr_type (type);
+  set_die_type (die, type, cu);
+
+  return 1;
+}
 
 /* Called when we find the DIE that starts a structure or union scope
    (definition) to process all dies that define the members of the
@@ -3737,8 +3800,10 @@ read_structure_type (struct die_info *di
   if (die->type)
     return;
 
-  type = alloc_type (objfile);
+  if (quirk_gcc_member_function_pointer (die, cu))
+    return;
 
+  type = alloc_type (objfile);
   INIT_CPLUS_SPECIFIC (type);
   attr = dwarf2_attr (die, DW_AT_name, cu);
   if (attr && DW_STRING (attr))


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [rfc] Recognize GCC pointer to member function DWARF2 descriptions
  2006-08-07  2:57 [rfc] Recognize GCC pointer to member function DWARF2 descriptions Daniel Jacobowitz
@ 2006-08-18  9:21 ` Daniel Jacobowitz
  2006-08-18 13:26   ` Mark Kettenis
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Jacobowitz @ 2006-08-18  9:21 UTC (permalink / raw)
  To: gdb-patches

On Sun, Aug 06, 2006 at 10:57:40PM -0400, Daniel Jacobowitz wrote:
> GCC emits DW_TAG_ptr_to_member_type for pointers to member data, but not
> for pointers to member functions.  I plan to fix this in GCC eventually,
> but in the mean time, this does some pattern recognition on the GCC
> output to convert it into a pointer to member.  It recognizes structures
> of the form:
> 
> struct {
>   void (*__pfn) (args, ...);
>   ptrdiff_t __delta;
> };

I checked this in as attached, with a typo fix.  The underlying issue
being worked around here is GCC PR debug/28767.

-- 
Daniel Jacobowitz
CodeSourcery

2006-08-18  Daniel Jacobowitz  <dan@codesourcery.com>

	* dwarf2read.c (quirk_gcc_member_function_pointer): New.
	(read_structure_type): Call it.

Index: src/gdb/dwarf2read.c
===================================================================
--- src.orig/gdb/dwarf2read.c	2006-08-05 10:10:11.000000000 -0400
+++ src/gdb/dwarf2read.c	2006-08-06 22:52:02.000000000 -0400
@@ -3708,6 +3708,69 @@ is_vtable_name (const char *name, struct
   return 0;
 }
 
+/* GCC outputs unnamed structures that are really pointers to member
+   functions, with the ABI-specified layout.  If DIE (from CU) describes
+   such a structure, set its type, and return nonzero.  Otherwise return
+   zero.  */
+
+static int
+quirk_gcc_member_function_pointer (struct die_info *die, struct dwarf2_cu *cu)
+{
+  struct objfile *objfile = cu->objfile;
+  struct type *type;
+  struct die_info *pfn_die, *delta_die;
+  struct attribute *pfn_name, *delta_name;
+  struct type *pfn_type, *domain_type;
+
+  /* Check for a structure with no name and two children.  */
+  if (die->tag != DW_TAG_structure_type
+      || dwarf2_attr (die, DW_AT_name, cu) != NULL
+      || die->child == NULL
+      || die->child->sibling == NULL
+      || (die->child->sibling->sibling != NULL
+	  && die->child->sibling->sibling->tag != DW_TAG_padding))
+    return 0;
+
+  /* Check for __pfn and __delta members.  */
+  pfn_die = die->child;
+  pfn_name = dwarf2_attr (pfn_die, DW_AT_name, cu);
+  if (pfn_die->tag != DW_TAG_member
+      || pfn_name == NULL
+      || DW_STRING (pfn_name) == NULL
+      || strcmp ("__pfn", DW_STRING (pfn_name)) != 0)
+    return 0;
+
+  delta_die = pfn_die->sibling;
+  delta_name = dwarf2_attr (delta_die, DW_AT_name, cu);
+  if (delta_die->tag != DW_TAG_member
+      || delta_name == NULL
+      || DW_STRING (delta_name) == NULL
+      || strcmp ("__delta", DW_STRING (delta_name)) != 0)
+    return 0;
+
+  /* Find the type of the method.  */
+  pfn_type = die_type (pfn_die, cu);
+  if (pfn_type == NULL
+      || TYPE_CODE (pfn_type) != TYPE_CODE_PTR
+      || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC)
+    return 0;
+
+  /* Look for the "this" argument.  */
+  pfn_type = TYPE_TARGET_TYPE (pfn_type);
+  if (TYPE_NFIELDS (pfn_type) == 0
+      || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR)
+    return 0;
+
+  domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0));
+  type = alloc_type (objfile);
+  smash_to_method_type (type, domain_type, TYPE_TARGET_TYPE (pfn_type),
+			TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type),
+			TYPE_VARARGS (pfn_type));
+  type = lookup_pointer_type (type);
+  set_die_type (die, type, cu);
+
+  return 1;
+}
 
 /* Called when we find the DIE that starts a structure or union scope
    (definition) to process all dies that define the members of the
@@ -3737,8 +3800,10 @@ read_structure_type (struct die_info *di
   if (die->type)
     return;
 
-  type = alloc_type (objfile);
+  if (quirk_gcc_member_function_pointer (die, cu))
+    return;
 
+  type = alloc_type (objfile);
   INIT_CPLUS_SPECIFIC (type);
   attr = dwarf2_attr (die, DW_AT_name, cu);
   if (attr && DW_STRING (attr))


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [rfc] Recognize GCC pointer to member function DWARF2 descriptions
  2006-08-18  9:21 ` Daniel Jacobowitz
@ 2006-08-18 13:26   ` Mark Kettenis
  2006-08-19  3:22     ` Daniel Jacobowitz
  0 siblings, 1 reply; 4+ messages in thread
From: Mark Kettenis @ 2006-08-18 13:26 UTC (permalink / raw)
  To: drow; +Cc: gdb-patches

> Date: Fri, 18 Aug 2006 00:11:12 -0400
> From: Daniel Jacobowitz <drow@false.org>
> 
> On Sun, Aug 06, 2006 at 10:57:40PM -0400, Daniel Jacobowitz wrote:
> > GCC emits DW_TAG_ptr_to_member_type for pointers to member data, but not
> > for pointers to member functions.  I plan to fix this in GCC eventually,
> > but in the mean time, this does some pattern recognition on the GCC
> > output to convert it into a pointer to member.  It recognizes structures
> > of the form:
> > 
> > struct {
> >   void (*__pfn) (args, ...);
> >   ptrdiff_t __delta;
> > };
> 
> I checked this in as attached, with a typo fix.  The underlying issue
> being worked around here is GCC PR debug/28767.

Could you add a reference to that GCC PR in a comment somewhere?  I
think it'd be useul to know exactly what GCC issue is being worked
around.

Mark


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [rfc] Recognize GCC pointer to member function DWARF2 descriptions
  2006-08-18 13:26   ` Mark Kettenis
@ 2006-08-19  3:22     ` Daniel Jacobowitz
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Jacobowitz @ 2006-08-19  3:22 UTC (permalink / raw)
  To: Mark Kettenis; +Cc: gdb-patches

On Fri, Aug 18, 2006 at 08:08:50AM +0200, Mark Kettenis wrote:
> Could you add a reference to that GCC PR in a comment somewhere?  I
> think it'd be useul to know exactly what GCC issue is being worked
> around.

That's a good idea; done as attached.

-- 
Daniel Jacobowitz
CodeSourcery

2006-08-18  Daniel Jacobowitz  <dan@codesourcery.com>

	* dwarf2read.c (quirk_gcc_member_function_pointer): Add GCC PR
	number in a comment.

Index: dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.202
diff -u -p -r1.202 dwarf2read.c
--- dwarf2read.c	18 Aug 2006 04:10:30 -0000	1.202
+++ dwarf2read.c	18 Aug 2006 13:25:31 -0000
@@ -3711,7 +3711,10 @@ is_vtable_name (const char *name, struct
 /* GCC outputs unnamed structures that are really pointers to member
    functions, with the ABI-specified layout.  If DIE (from CU) describes
    such a structure, set its type, and return nonzero.  Otherwise return
-   zero.  */
+   zero.
+
+   GCC shouldn't do this; it should just output pointer to member DIEs.
+   This is GCC PR debug/28767.  */
 
 static int
 quirk_gcc_member_function_pointer (struct die_info *die, struct dwarf2_cu *cu)


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-08-18 13:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-07  2:57 [rfc] Recognize GCC pointer to member function DWARF2 descriptions Daniel Jacobowitz
2006-08-18  9:21 ` Daniel Jacobowitz
2006-08-18 13:26   ` Mark Kettenis
2006-08-19  3:22     ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox