This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
Fix for gdb.template_argument() brokenness WRT const, volatile.
- From: ppluzhnikov at google dot com (Paul Pluzhnikov)
- To: archer at sourceware dot org
- Cc: ppluzhnikov at google dot com
- Date: Thu, 6 Nov 2008 15:59:09 -0800 (PST)
- Subject: Fix for gdb.template_argument() brokenness WRT const, volatile.
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=google.com; s=beta;t=1226015952; bh=D3JgkR6N8mCDljeEvIqav9yl90M=;h=DomainKey-Signature:To:Cc:Subject:Message-Id:Date:From; b=eX93WKERL6O7Rk8Ylj0k068O4NPDJR1lkQhwCzOFrnqupaMAMppNS77Di+ZCTgJVyzM1ejGHdw/HxDKewVbf3Q==
- Domainkey-signature: a=rsa-sha1; s=beta; d=google.com; c=nofws; q=dns;h=to:cc:subject:message-id:date:from;b=DSKC2tq/98rWtRakVw1bGk00A9IDrWhsmpllpjePL6jYZvVhyvpd994yJfRG1mJTdgjGcPmnZgM6BVhbidEpRQ==
Greetings,
Consider:
--- cut --- t6.cc --
template <typename T>
struct Foo {
};
#ifndef TYPE
#define TYPE int
#endif
int main()
{
Foo<TYPE> foo;
return 0; // break here
}
--- cut --- t6.cc --
If I build this with:
# intentionally mixing pointers, qualifiers, etc.
g++ -g t6.cc -o t6 -DTYPE='const char *volatile *const'
then template_argument() breaks:
Breakpoint 1, main () at t6.cc:12
12 return 0; // break here
(gdb) p foo
$1 = {<No data fields>}
(gdb) py foo = gdb.get_value_from_history(0)
(gdb) py foo.type().template_argument(0)
Traceback (most recent call last):
File "<string>", line 1, in ?
RuntimeError: no such type named char const* volatile* const
Attached patch fixes this.
If that's acceptable, I'll write a test case and commit.
Thanks,
--
Paul Pluzhnikov
2008-11-06 Paul Pluzhnikov <ppluzhnikov@google.com>
* python/python-type.c (typy_lookup_type): New fn.
Handle const and volatile qualified types.
* python/python-type.c (typy_template_argument): Call it.
diff --git a/gdb/python/python-type.c b/gdb/python/python-type.c
index 1d27714..3058a2e 100644
--- a/gdb/python/python-type.c
+++ b/gdb/python/python-type.c
@@ -128,6 +128,45 @@ typy_lookup_typename (char *type_name, struct block *block)
return type;
}
+static struct type *
+typy_lookup_type (struct demangle_component *demangled,
+ struct block *block)
+{
+ struct type *type;
+ char *type_name;
+
+ if (demangled->type == DEMANGLE_COMPONENT_POINTER
+ || demangled->type == DEMANGLE_COMPONENT_CONST
+ || demangled->type == DEMANGLE_COMPONENT_VOLATILE)
+ {
+ type = typy_lookup_type (demangled->u.s_binary.left, block);
+ if (! type)
+ return NULL;
+ }
+ switch (demangled->type)
+ {
+ case DEMANGLE_COMPONENT_POINTER:
+ return lookup_pointer_type (type);
+ case DEMANGLE_COMPONENT_CONST:
+ return make_cv_type (1, 0, type, NULL);
+ case DEMANGLE_COMPONENT_VOLATILE:
+ return make_cv_type (0, 1, type, NULL);
+ }
+
+ type_name = cp_comp_to_string (demangled, 10);
+ type = typy_lookup_typename (type_name, block);
+ if (! type)
+ {
+ PyErr_Format (PyExc_RuntimeError, "no such type named %s",
+ type_name);
+ xfree (type_name);
+ return NULL;
+ }
+ xfree (type_name);
+
+ return type;
+}
+
static PyObject *
typy_template_argument (PyObject *self, PyObject *args)
{
@@ -135,7 +174,6 @@ typy_template_argument (PyObject *self, PyObject *args)
struct type *type = ((type_object *) self)->type;
struct demangle_component *demangled;
const char *err;
- char *type_name;
struct type *argtype;
struct block *block = NULL;
PyObject *block_obj = NULL;
@@ -196,32 +234,9 @@ typy_template_argument (PyObject *self, PyObject *args)
return NULL;
}
- /* Count pointers and apply later, because lookup_typename does not
- understand '*'. FIXME: should handle references as well. Really
- we should have a generic cp_comp_to_type. */
- demangled = demangled->u.s_binary.left;
- n_pointers = 0;
- while (demangled->type == DEMANGLE_COMPONENT_POINTER)
- {
- ++n_pointers;
- demangled = demangled->u.s_binary.left;
- }
-
- /* FIXME: if argument is a value, we should DTRT. */
- type_name = cp_comp_to_string (demangled, 10);
-
- argtype = typy_lookup_typename (type_name, block);
+ argtype = typy_lookup_type (demangled->u.s_binary.left, block);
if (! argtype)
- {
- PyErr_Format (PyExc_RuntimeError, "no such type named %s",
- type_name);
- xfree (type_name);
- return NULL;
- }
- xfree (type_name);
-
- while (n_pointers--)
- argtype = lookup_pointer_type (argtype);
+ return NULL;
return type_to_type_object (argtype);
}