This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
RFC: [3/4] partial fix for PR 14160
- From: Tom Tromey <tromey at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Tue, 27 Nov 2012 07:17:15 -0700
- Subject: RFC: [3/4] partial fix for PR 14160
I've sent this patch before, as part of my still-on-hold "operator new"
series.
In that series I had accidentally let some unrelated hunks into the
patch. This refresh simply removes those but is otherwise unchanged.
The old note to the list is still relevant:
This is a partial fix for PR 14160.
The bug here is that there is some fundamental confusion in gdb about
what the physname is, so things like is_constructor_name are
unreliable.
This patch works around the immediate bug by noting constructors when
reading the DWARF and marking the function fields appropriately. I
think this is a better approach than checking physnames anyhow.
Built and regtested on x86-64 Fedora 16.
Tom
Partial fix for PR c++/14160:
* c-typeprint.c (c_type_print_base): Use TYPE_FN_FIELD_CONSTRUCTOR.
* dwarf2read.c (dwarf2_is_constructor): New function.
(dwarf2_add_member_fn): Use it.
* gnu-v3-abi.c (gnuv3_pass_by_reference): Use
TYPE_FN_FIELD_CONSTRUCTOR.
* jv-typeprint.c (java_type_print_base): Use
TYPE_FN_FIELD_CONSTRUCTOR.
* gdbtypes.h (struct fn_field) <is_constructor>: New field.
<dummy>: Shrink.
(TYPE_FN_FIELD_CONSTRUCTOR): New macro.
* gdb.cp/templates.exp (test_ptype_of_templates): Update kfails.
---
gdb/c-typeprint.c | 3 ++-
gdb/dwarf2read.c | 30 ++++++++++++++++++++++++++++++
gdb/gdbtypes.h | 7 ++++++-
gdb/gnu-v3-abi.c | 3 ++-
gdb/jv-typeprint.c | 3 ++-
gdb/testsuite/gdb.cp/templates.exp | 16 ++++++++++++++++
6 files changed, 58 insertions(+), 4 deletions(-)
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index 161b3fe..d3ab4a7 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -1143,7 +1143,8 @@ c_type_print_base (struct type *type, struct ui_file *stream,
struct cleanup *inner_cleanup;
const char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
int is_full_physname_constructor =
- is_constructor_name (physname)
+ TYPE_FN_FIELD_CONSTRUCTOR (f, j)
+ || is_constructor_name (physname)
|| is_destructor_name (physname)
|| method_name[0] == '~';
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index f4bd7a9..dd41418 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -10769,6 +10769,34 @@ dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
}
}
+/* Return true if this member function is a constructor, false
+ otherwise. */
+
+static int
+dwarf2_is_constructor (struct die_info *die, struct dwarf2_cu *cu)
+{
+ const char *fieldname;
+ const char *typename;
+ int len;
+
+ if (die->parent == NULL)
+ return 0;
+
+ if (die->parent->tag != DW_TAG_structure_type
+ && die->parent->tag != DW_TAG_union_type
+ && die->parent->tag != DW_TAG_class_type)
+ return 0;
+
+ fieldname = dwarf2_name (die, cu);
+ typename = dwarf2_name (die->parent, cu);
+ if (fieldname == NULL || typename == NULL)
+ return 0;
+
+ len = strlen (fieldname);
+ return (strncmp (fieldname, typename, len) == 0
+ && (typename[len] == '\0' || typename[len] == '<'));
+}
+
/* Add a member function to the proper fieldlist. */
static void
@@ -10900,6 +10928,8 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
if (attr && DW_UNSND (attr) != 0)
fnp->is_artificial = 1;
+ fnp->is_constructor = dwarf2_is_constructor (die, cu);
+
/* Get index in virtual function table if it is a virtual member
function. For older versions of GCC, this is an offset in the
appropriate virtual table, as specified by DW_AT_containing_type.
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index b23df9a..e20c1f8 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -837,8 +837,12 @@ struct cplus_struct_type
to reconstruct the rest of the fields). */
unsigned int is_stub:1;
+ /* True if this function is a constructor, false
+ otherwise. */
+ unsigned int is_constructor : 1;
+
/* Unused. */
- unsigned int dummy:4;
+ unsigned int dummy:3;
/* Index into that baseclass's virtual function table,
minus 2; else if static: VOFFSET_STATIC; else: 0. */
@@ -1212,6 +1216,7 @@ extern void allocate_gnat_aux_type (struct type *);
#define TYPE_FN_FIELD_ARTIFICIAL(thisfn, n) ((thisfn)[n].is_artificial)
#define TYPE_FN_FIELD_ABSTRACT(thisfn, n) ((thisfn)[n].is_abstract)
#define TYPE_FN_FIELD_STUB(thisfn, n) ((thisfn)[n].is_stub)
+#define TYPE_FN_FIELD_CONSTRUCTOR(thisfn, n) ((thisfn)[n].is_constructor)
#define TYPE_FN_FIELD_FCONTEXT(thisfn, n) ((thisfn)[n].fcontext)
#define TYPE_FN_FIELD_VOFFSET(thisfn, n) ((thisfn)[n].voffset-2)
#define TYPE_FN_FIELD_VIRTUAL_P(thisfn, n) ((thisfn)[n].voffset > 1)
diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c
index c025a7b..83ee196 100644
--- a/gdb/gnu-v3-abi.c
+++ b/gdb/gnu-v3-abi.c
@@ -1071,7 +1071,8 @@ gnuv3_pass_by_reference (struct type *type)
with the mangled name. We don't have a convenient function
to strip off both leading scope qualifiers and trailing
template arguments yet. */
- if (!is_constructor_name (TYPE_FN_FIELD_PHYSNAME (fn, fieldelem)))
+ if (!is_constructor_name (TYPE_FN_FIELD_PHYSNAME (fn, fieldelem))
+ && !TYPE_FN_FIELD_CONSTRUCTOR (fn, fieldelem))
continue;
/* If this method takes two arguments, and the second argument is
diff --git a/gdb/jv-typeprint.c b/gdb/jv-typeprint.c
index f0d3448..95b1758 100644
--- a/gdb/jv-typeprint.c
+++ b/gdb/jv-typeprint.c
@@ -239,7 +239,8 @@ java_type_print_base (struct type *type, struct ui_file *stream, int show,
physname[p - real_physname] = '\0';
is_full_physname_constructor
- = (is_constructor_name (physname)
+ = (TYPE_FN_FIELD_CONSTRUCTOR (f, j)
+ || is_constructor_name (physname)
|| is_destructor_name (physname));
QUIT;
diff --git a/gdb/testsuite/gdb.cp/templates.exp b/gdb/testsuite/gdb.cp/templates.exp
index 9ebb3bd..45b67e1 100644
--- a/gdb/testsuite/gdb.cp/templates.exp
+++ b/gdb/testsuite/gdb.cp/templates.exp
@@ -60,6 +60,14 @@ proc test_ptype_of_templates {} {
# This also triggers gdb/1113...
kfail "gdb/1111" "ptype T5<int>"
# Add here a PASS case when PR gdb/1111 gets fixed.
+ # These are really:
+ # http://sourceware.org/bugzilla/show_bug.cgi?id=8216
+ # http://sourceware.org/bugzilla/show_bug.cgi?id=8218
+ }
+ -re "type = class T5<int> \{${ws}public:${ws}static int X;${ws}int x;${ws}int val;${ws}T5\\(int\\);${ws}T5\\((T5<int> const|const T5<int>) ?&\\);${ws}~T5\\(int\\);${ws}static void \\* operator new\\((size_t|unsigned( int| long|))\\);${ws}static void operator delete\\(void ?\\*\\);${ws}int value\\((void|)\\);${ws}\}\r\n$gdb_prompt $" {
+ # http://sourceware.org/bugzilla/show_bug.cgi?id=8218
+ # The destructor has an argument type.
+ kfail "gdb/8218" "ptype T5<int>"
}
}
@@ -89,6 +97,14 @@ proc test_ptype_of_templates {} {
# This also triggers gdb/1113...
kfail "gdb/1111" "ptype T5<int>"
# Add here a PASS case when PR gdb/1111 gets fixed.
+ # These are really:
+ # http://sourceware.org/bugzilla/show_bug.cgi?id=8216
+ # http://sourceware.org/bugzilla/show_bug.cgi?id=8218
+ }
+ -re "type = class T5<int> \{${ws}public:${ws}static int X;${ws}int x;${ws}int val;${ws}T5\\(int\\);${ws}T5\\((T5<int> const|const T5<int>) ?&\\);${ws}~T5\\(int\\);${ws}static void \\* operator new\\((size_t|unsigned( int| long|))\\);${ws}static void operator delete\\(void ?\\*\\);${ws}int value\\((void|)\\);${ws}\}\r\n$gdb_prompt $" {
+ # http://sourceware.org/bugzilla/show_bug.cgi?id=8218
+ # The destructor has an argument type.
+ kfail "gdb/8218" "ptype T5<int>"
}
}
}
--
1.7.7.6