[RFA] Typedef'd method parameters [0/4]

Keith Seitz
2011-04-21T21:15:58Z

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

Hi,

I've been working on fixing c++/12266 and c++/12506 in which users are
unable to specify linespecs for class methods which have typedef'd
parameters, e.g., klass:method(my_typedef). This is an attempt to fix
this shortcoming. [This is not a dwarf2_physname regression.]

I've attempted to split this up into four different patches to help
facilitate review, but to be honest, I'm not sure how helpful this split
is going to be, but I'll leave it to maintainers to ask for whatever
would help them digest this easiest.

Back to the problem. Physnames (similar to linkage names) are used to
store symbols in the symbol tables -- this is the whole dwarf2_physname
patchset from last year. These physnames should represent the most basic
"name" of a symbol.

The inability to use typedef'd parameter types arises from the fact that
we do fairly literal lookups in the symbol table from decode_line_1 et
al. So for example, if the user types "break klass::method(my_typedef)",
decode_compound will attempt to look for a method of "klass" with the
parameter type "my_typedef". Alas, as I've already mentioned, the symbol
tables do not contain this information -- the contain whatever the
typedef resolves to (klass::method(int), for example).

The proposed solution in this patchset is to use the C++ name parser to
find these method parameter types, look them up, and if they are
typedefs, change the name in the tree to physname of the typedef.

A note on the test suite: I propose to get these all approved and commit
in one go. If done this way, no test suite regressions should occur. Or
at least they don't show up here. :-)

There are several (mechanical) problems that arise from this approach
that need to be dealt with first. First of all,
cp_demangled_name_to_comp can not be called recursively because the
storage for the resulting parse tree is rewritten with every call.

This can happen before debuginfo is read and the user attempts to
specify a linespec; when the typedef is looked up, the dwarf reader will
call cp_canonicalize_string, destroying the result. So the first of
these patches addresses this. It is pretty much orthogonal to the other
patches.

Second, c_type_print_args (and several functions in c-typeprint.c)
needed to be taught the difference between linkage names and print
names. [Reminder: Both skip artificial parameters; linkage names always
resolve typedefs.] This is addressed in the second patch.

The third patch is actually the "guts" of the patch, which walks the
name parse tree and converts typedefs. The main function of interest
here is cp_canonicalize_string_no_typedefs, which is largely a clone of
cp_canonicalize_string, except that it resolves any typedefs found in
the name (as if you couldn't guess that).

The final/fourth patch is test cases for this. I have really tried to
hit a bunch of corner cases, but it is likely that users have thought of
some way to express something in C++ that I have not.

Just a side note for maintainers, since I know this is going to come up:
I have tried my best to consolidate name canonicalization, but there are
a bunch of problems that arise from attempting to do this. I believe the
solution proposed here is the most consistent from an API perspective --
everything still acts the way it should (and has). The alternative is to
canonicalize_no_typedefs before anyone calls lookup_symbol or
lookup_symbol_in_language. I rejected this approach.

In one specific case, we have no choice but to re-canonicalize the input
anyway, and this isn't particularly time-critical code, since it is only
called from decode_line_1, i.e., from user input. It does not get called
from dwarf2read.c.

Keith

PS. I've attached the whole patch as a single large piece for those
interested in skipping the piecemeal evaluation of the patchset. [See
ChangeLogs in subsequent messages.]

[-- Attachment #2: 12266-whole.patch --]
[-- Type: text/plain, Size: 44299 bytes --]

Index: c-typeprint.c
===================================================================
RCS file: /cvs/src/src/gdb/c-typeprint.c,v
retrieving revision 1.70
diff -u -p -r1.70 c-typeprint.c
--- c-typeprint.c 22 Mar 2011 17:35:22 -0000 1.70
+++ c-typeprint.c 21 Apr 2011 17:59:14 -0000
@@ -44,14 +44,22 @@ static void c_type_print_varspec_prefix
static void c_type_print_modifier (struct type *,
struct ui_file *,
int, int);
+
+static void c_type_print_base_internal (struct type *, struct ui_file *,
+ int, int, int);
+
\f
-/* LEVEL is the depth to indent lines by. */
+/* The real c_print_type. See c_print_type below for a description
+ of parameters and usage.

-void
-c_print_type (struct type *type,
- const char *varstring,
- struct ui_file *stream,
- int show, int level)
+ LINKAGE_NAME should be non-zero if we are printing a linkage name
+ on the stream. */
+
+static void
+c_print_type_internal (struct type *type,
+ const char *varstring,
+ struct ui_file *stream,
+ int show, int level, int linkage_name)
{
enum type_code code;
int demangled_args;
@@ -60,7 +68,7 @@ c_print_type (struct type *type,
if (show > 0)
CHECK_TYPEDEF (type);

- c_type_print_base (type, stream, show, level);
+ c_type_print_base_internal (type, stream, show, level, linkage_name);
code = TYPE_CODE (type);
if ((varstring != NULL && *varstring != '\0')
/* Need a space if going to print stars or brackets;
@@ -85,10 +93,25 @@ c_print_type (struct type *type,

demangled_args = strchr (varstring, '(') != NULL;
c_type_print_varspec_suffix (type, stream, show,
- 0, demangled_args);
+ 0, demangled_args, linkage_name);
}
}

+/* Print TYPE to the STREAM.
+ VARSTRING (optional) is the name of the field being printed.
+ If SHOW is greater than zero, print the details of the type. Otherwise
+ simply print the type name.
+ LEVEL is the depth to indent lines by. */
+
+void
+c_print_type (struct type *type,
+ const char *varstring,
+ struct ui_file *stream,
+ int show, int level)
+{
+ c_print_type_internal (type, varstring, stream, show, level, 0);
+}
+
/* Print a typedef using C syntax. TYPE is the underlying type.
NEW_SYMBOL is the symbol naming the type. STREAM is the stream on
which to print. */
@@ -166,17 +189,14 @@ cp_type_print_derivation_info (struct ui
/* Print the C++ method arguments ARGS to the file STREAM. */

static void
-cp_type_print_method_args (struct type *mtype, char *prefix,
- char *varstring, int staticp,
- struct ui_file *stream)
+cp_type_print_method_args (struct type *mtype, char *varstring,
+ int staticp, struct ui_file *stream)
{
struct field *args = TYPE_FIELDS (mtype);
int nargs = TYPE_NFIELDS (mtype);
int varargs = TYPE_VARARGS (mtype);
int i;

- fprintf_symbol_filtered (stream, prefix,
- language_cplus, DMGL_ANSI);
fprintf_symbol_filtered (stream, varstring,
language_cplus, DMGL_ANSI);
fputs_filtered ("(", stream);
@@ -386,17 +406,25 @@ c_type_print_modifier (struct type *type

/* Print out the arguments of TYPE, which should have TYPE_CODE_METHOD
- or TYPE_CODE_FUNC, to STREAM. Artificial arguments, such as "this"
- in non-static methods, are displayed if LINKAGE_NAME is zero. If
- LINKAGE_NAME is non-zero and LANGUAGE is language_cplus the topmost
- parameter types get removed their possible const and volatile qualifiers to
+ or TYPE_CODE_FUNC, to STREAM.
+
+ LINKAGE_NAME is non-zero when the SYMBOL_LINKAGE_NAME of TYPE
+ (a function or method) is printed. Artifical parameters such as "this"
+ in non-static methods are skipped and all typedefs will be removed/expanded.
+ Additionally if LANGUAGE is language_cplus, topmost parameter types
+ may have any possible const and volatile qualifiers removed to
match demangled linkage name parameters part of such function type.
+
+ PRINT_NAME is non-zero when the SYMBOL_PRINT_NAME of TYPE is
+ printed. In this case, artificial parameters are skipped, but
+ any typedef'd parameter types are left intact.
+
LANGUAGE is the language in which TYPE was defined. This is a necessary
evil since this code is used by the C, C++, and Java backends. */

void
c_type_print_args (struct type *type, struct ui_file *stream,
- int linkage_name, enum language language)
+ int linkage_name, int print_name, enum language language)
{
int i, len;
struct field *args;
@@ -410,7 +438,7 @@ c_type_print_args (struct type *type, st
{
struct type *param_type;

- if (TYPE_FIELD_ARTIFICIAL (type, i) && linkage_name)
+ if (TYPE_FIELD_ARTIFICIAL (type, i) && (linkage_name || print_name))
continue;

if (printed_any)
@@ -433,10 +461,13 @@ c_type_print_args (struct type *type, st
param_type = make_cv_type (0, 0, param_type, NULL);
}

+ if (linkage_name)
+ CHECK_TYPEDEF (param_type);
+
if (language == language_java)
java_print_type (param_type, "", stream, -1, 0);
else
- c_print_type (param_type, "", stream, -1, 0);
+ c_print_type_internal (param_type, "", stream, -1, 0, linkage_name);
printed_any = 1;
}

@@ -599,13 +630,16 @@ remove_qualifiers (char *qid)

/* Print any array sizes, function arguments or close parentheses
needed after the variable name (to describe its type).
- Args work like c_type_print_varspec_prefix. */
+ Args work like c_type_print_varspec_prefix.
+
+ LINKAGE_NAME is non-zero when printing the linkage name of a
+ function or method. */

void
c_type_print_varspec_suffix (struct type *type,
struct ui_file *stream,
int show, int passed_a_ptr,
- int demangled_args)
+ int demangled_args, int linkage_name)
{
if (type == 0)
return;
@@ -631,25 +665,25 @@ c_type_print_varspec_suffix (struct type
fprintf_filtered (stream, "]");

c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
- show, 0, 0);
+ show, 0, 0, linkage_name);
}
break;

case TYPE_CODE_MEMBERPTR:
c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
- show, 0, 0);
+ show, 0, 0, linkage_name);
break;

case TYPE_CODE_METHODPTR:
fprintf_filtered (stream, ")");
c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
- show, 0, 0);
+ show, 0, 0, linkage_name);
break;

case TYPE_CODE_PTR:
case TYPE_CODE_REF:
c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
- show, 1, 0);
+ show, 1, 0, linkage_name);
break;

case TYPE_CODE_METHOD:
@@ -657,14 +691,17 @@ c_type_print_varspec_suffix (struct type
if (passed_a_ptr)
fprintf_filtered (stream, ")");
if (!demangled_args)
- c_type_print_args (type, stream, 0, current_language->la_language);
+ {
+ c_type_print_args (type, stream, linkage_name, 0,
+ current_language->la_language);
+ }
c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
- show, passed_a_ptr, 0);
+ show, passed_a_ptr, 0, linkage_name);
break;

case TYPE_CODE_TYPEDEF:
c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
- show, passed_a_ptr, 0);
+ show, passed_a_ptr, 0, linkage_name);
break;

case TYPE_CODE_UNDEF:
@@ -694,27 +731,14 @@ c_type_print_varspec_suffix (struct type
}
}

-/* Print the name of the type (or the ultimate pointer target,
- function value or array element), or the description of a structure
- or union.
-
- SHOW positive means print details about the type (e.g. enum
- values), and print structure elements passing SHOW - 1 for show.
-
- SHOW negative means just print the type name or struct tag if there
- is one. If there is no name, print something sensible but concise
- like "struct {...}".
+/* The real c_type_print_base_internal. This function takes an
+ additional argument over the API function c_type_print_base:
+ LINKAGE_NAME, which is non-zero when the linkage name is being
+ printed to the STREAM. */

- SHOW zero means just print the type name or struct tag if there is
- one. If there is no name, print something sensible but not as
- concise like "struct {int x; int y;}".
-
- LEVEL is the number of spaces to indent by.
- We increase it for some recursive calls. */
-
-void
-c_type_print_base (struct type *type, struct ui_file *stream,
- int show, int level)
+static void
+c_type_print_base_internal (struct type *type, struct ui_file *stream,
+ int show, int level, int linkage_name)
{
int i;
int len, real_len;
@@ -773,8 +797,8 @@ c_type_print_base (struct type *type, st
case TYPE_CODE_FUNC:
case TYPE_CODE_METHOD:
case TYPE_CODE_METHODPTR:
- c_type_print_base (TYPE_TARGET_TYPE (type),
- stream, show, level);
+ c_type_print_base_internal (TYPE_TARGET_TYPE (type),
+ stream, show, level, linkage_name);
break;

case TYPE_CODE_STRUCT:
@@ -954,9 +978,10 @@ c_type_print_base (struct type *type, st
print_spaces_filtered (level + 4, stream);
if (field_is_static (&TYPE_FIELD (type, i)))
fprintf_filtered (stream, "static ");
- c_print_type (TYPE_FIELD_TYPE (type, i),
- TYPE_FIELD_NAME (type, i),
- stream, show - 1, level + 4);
+ c_print_type_internal (TYPE_FIELD_TYPE (type, i),
+ TYPE_FIELD_NAME (type, i),
+ stream, show - 1, level + 4,
+ linkage_name);
if (!field_is_static (&TYPE_FIELD (type, i))
&& TYPE_FIELD_PACKED (type, i))
{
@@ -1085,7 +1110,6 @@ c_type_print_base (struct type *type, st
struct type *mtype = TYPE_FN_FIELD_TYPE (f, j);

cp_type_print_method_args (mtype,
- "",
method_name,
staticp,
stream);
@@ -1145,8 +1169,10 @@ c_type_print_base (struct type *type, st

print_spaces_filtered (level + 4, stream);
fprintf_filtered (stream, "typedef ");
- c_print_type (target, TYPE_TYPEDEF_FIELD_NAME (type, i),
- stream, show - 1, level + 4);
+ c_print_type_internal (target,
+ TYPE_TYPEDEF_FIELD_NAME (type, i),
+ stream, show - 1, level + 4,
+ linkage_name);
fprintf_filtered (stream, ";\n");
}
}
@@ -1251,3 +1277,28 @@ c_type_print_base (struct type *type, st
break;
}
}
+
+/* Print the name of the type (or the ultimate pointer target,
+ function value or array element), or the description of a structure
+ or union.
+
+ SHOW positive means print details about the type (e.g. enum
+ values), and print structure elements passing SHOW - 1 for show.
+
+ SHOW negative means just print the type name or struct tag if there
+ is one. If there is no name, print something sensible but concise
+ like "struct {...}".
+
+ SHOW zero means just print the type name or struct tag if there is
+ one. If there is no name, print something sensible but not as
+ concise like "struct {int x; int y;}".
+
+ LEVEL is the number of spaces to indent by.
+ We increase it for some recursive calls. */
+
+void
+c_type_print_base (struct type *type, struct ui_file *stream,
+ int show, int level)
+{
+ c_type_print_base_internal (type, stream, show, level, 0);
+}
Index: cp-name-parser.y
===================================================================
RCS file: /cvs/src/src/gdb/cp-name-parser.y,v
retrieving revision 1.20
diff -u -p -r1.20 cp-name-parser.y
--- cp-name-parser.y 18 Mar 2011 13:51:41 -0000 1.20
+++ cp-name-parser.y 21 Apr 2011 17:59:14 -0000
@@ -1935,20 +1935,15 @@ yyerror (char *msg)
generally allocate too many components, but the extra memory usage
doesn't hurt because the trees are temporary and the storage is
reused. More may be allocated later, by d_grab. */
-static void
+static struct demangle_info *
allocate_info (void)
{
- if (demangle_info == NULL)
- {
- demangle_info = malloc (sizeof (struct demangle_info));
- demangle_info->prev = NULL;
- demangle_info->next = NULL;
- }
- else
- while (demangle_info->prev)
- demangle_info = demangle_info->prev;
+ struct demangle_info *info = malloc (sizeof (struct demangle_info));

- demangle_info->used = 0;
+ info->prev = NULL;
+ info->next = NULL;
+ info->used = 0;
+ return info;
}

/* Convert RESULT to a string. The return value is allocated
@@ -1966,23 +1961,46 @@ cp_comp_to_string (struct demangle_compo
&err);
}

+/* Free any memory associated with the given PARSE_INFO. */
+
+void
+cp_demangled_name_parse_free (struct demangle_parse_info *parse_info)
+{
+ struct demangle_info *info = parse_info->info;
+
+ /* Free any allocated chunks of memory for the parse. */
+ while (info != NULL)
+ {
+ struct demangle_info *next = info->next;
+ free (info);
+ info = next;
+ }
+
+ /* Free the parser info. */
+ free (parse_info);
+}
+
/* Convert a demangled name to a demangle_component tree. On success,
- the root of the new tree is returned; it is valid until the next
- call to this function and should not be freed. On error, NULL is
+ a structure containing the root of the new tree is returned; it must
+ be freed by calling cp_demangled_name_parse_free. On error, NULL is
returned, and an error message will be set in *ERRMSG (which does
not need to be freed). */

-struct demangle_component *
+struct demangle_parse_info *
cp_demangled_name_to_comp (const char *demangled_name, const char **errmsg)
{
static char errbuf[60];
- struct demangle_component *result;
+ struct demangle_parse_info *result;

prev_lexptr = lexptr = demangled_name;
error_lexptr = NULL;
global_errmsg = NULL;

- allocate_info ();
+ demangle_info = allocate_info ();
+
+ result = ((struct demangle_parse_info *)
+ malloc (sizeof (struct demangle_parse_info)));
+ result->info = demangle_info;

if (yyparse ())
{
@@ -1993,10 +2011,11 @@ cp_demangled_name_to_comp (const char *d
strcat (errbuf, "'");
*errmsg = errbuf;
}
+ cp_demangled_name_parse_free (result);
return NULL;
}

- result = global_result;
+ result->tree = global_result;
global_result = NULL;

return result;
@@ -2052,7 +2071,7 @@ main (int argc, char **argv)
char buf[65536];
int arg;
const char *errmsg;
- struct demangle_component *result;
+ struct demangle_parse_info *result;

arg = 1;
if (argv[arg] && strcmp (argv[arg], "--debug") == 0)
@@ -2086,7 +2105,8 @@ main (int argc, char **argv)
continue;
}

- cp_print (result);
+ cp_print (result->tree);
+ cp_demangled_name_parse_free (result);

free (str2);
if (c)
@@ -2105,7 +2125,8 @@ main (int argc, char **argv)
fputc ('\n', stderr);
return 0;
}
- cp_print (result);
+ cp_print (result->tree);
+ cp_demangled_name_parse_free (result);
putchar ('\n');
}
return 0;
Index: cp-support.c
===================================================================
RCS file: /cvs/src/src/gdb/cp-support.c,v
retrieving revision 1.49
diff -u -p -r1.49 cp-support.c
--- cp-support.c 26 Feb 2011 02:07:07 -0000 1.49
+++ cp-support.c 21 Apr 2011 17:59:15 -0000
@@ -117,6 +117,115 @@ cp_already_canonical (const char *string
return 0;
}

+/* Insepct the given RET_COMP for its type. If it is a typedef,
+ replace the name stored in the tree with the typedef's fully resolved
+ type. If no changes have been made to the tree, set CHANGED to 0;
+ otherwise set it to 1. FREE_LIST contains any temprorary storage
+ that was used to revise the tree. It should be freed by the caller. */
+
+static void
+inspect_type (struct demangle_component *ret_comp)
+{
+ char *name;
+ struct symbol *sym;
+
+ name = (char *) alloca (ret_comp->u.s_name.len + 1);
+ strncpy (name, ret_comp->u.s_name.s, ret_comp->u.s_name.len);
+ name[ret_comp->u.s_name.len] = '\0';
+ sym = lookup_symbol (name, 0, VAR_DOMAIN, 0);
+ if (sym != NULL)
+ {
+ struct type *type = SYMBOL_TYPE (sym);
+
+ if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
+ {
+ char *canon;
+ struct ui_file *buf = mem_fileopen ();
+
+ CHECK_TYPEDEF (type);
+ type_print (type, "", buf, -1);
+ name = ui_file_xstrdup (buf, NULL);
+ ui_file_delete (buf);
+ canon = cp_canonicalize_string_no_typedefs (name);
+ if (canon != NULL)
+ {
+ xfree (name);
+ name = canon;
+ }
+ ret_comp->u.s_name.s = name;
+ ret_comp->u.s_name.len = strlen (name);
+ }
+ }
+}
+
+/* Walk the parse tree given by RET_COMP, replacing any typedefs with
+ their basic types. CHANGED is set to indicate whether any changes
+ to the tree were made, and FREE_LIST will contain any memory used
+ for this purpose. It must be freed by the caller. */
+
+static void
+replace_typedefs (struct demangle_component *ret_comp)
+{
+ if (ret_comp)
+ {
+ switch (ret_comp->type)
+ {
+ case DEMANGLE_COMPONENT_ARGLIST:
+ replace_typedefs (d_left (ret_comp));
+ replace_typedefs (d_right (ret_comp));
+ break;
+
+ case DEMANGLE_COMPONENT_NAME:
+ inspect_type (ret_comp);
+ break;
+
+ case DEMANGLE_COMPONENT_FUNCTION_TYPE:
+ case DEMANGLE_COMPONENT_LOCAL_NAME:
+ case DEMANGLE_COMPONENT_TYPED_NAME:
+ replace_typedefs (d_right (ret_comp));
+ break;
+
+ case DEMANGLE_COMPONENT_QUAL_NAME:
+ case DEMANGLE_COMPONENT_POINTER:
+ replace_typedefs (d_left (ret_comp));
+ break;
+
+ default:
+ break;
+ }
+ }
+}
+
+/* Parse STRING and convert it to canonical form, resolving any typedefs.
+ If parsing fails, or if STRING is already canonical, return NULL.
+ Otherwise return the canonical form. The return value is allocated via
+ xmalloc. */
+
+char *
+cp_canonicalize_string_no_typedefs (const char *string)
+{
+ char *ret;
+ unsigned int estimated_len;
+ struct demangle_parse_info *info;
+
+ ret = NULL;
+ estimated_len = strlen (string) * 2;
+ info = cp_demangled_name_to_comp (string, NULL);
+ if (info != NULL)
+ {
+ replace_typedefs (info->tree);
+ ret = cp_comp_to_string (info->tree, estimated_len);
+ cp_demangled_name_parse_free (info);
+ if (strcmp (string, ret) == 0)
+ {
+ xfree (ret);
+ return NULL;
+ }
+ }
+
+ return ret;
+}
+
/* Parse STRING and convert it to canonical form. If parsing fails,
or if STRING is already canonical, return NULL. Otherwise return
the canonical form. The return value is allocated via xmalloc. */
@@ -124,20 +233,21 @@ cp_already_canonical (const char *string
char *
cp_canonicalize_string (const char *string)
{
- struct demangle_component *ret_comp;
+ struct demangle_parse_info *info;
unsigned int estimated_len;
char *ret;

if (cp_already_canonical (string))
return NULL;

- ret_comp = cp_demangled_name_to_comp (string, NULL);
- if (ret_comp == NULL)
+ info = cp_demangled_name_to_comp (string, NULL);
+ if (info == NULL)
return NULL;

estimated_len = strlen (string) * 2;
- ret = cp_comp_to_string (ret_comp, estimated_len);
-
+ ret = cp_comp_to_string (info->tree, estimated_len);
+ cp_demangled_name_parse_free (info);
+
if (strcmp (string, ret) == 0)
{
xfree (ret);
@@ -153,23 +263,28 @@ cp_canonicalize_string (const char *stri
freed when finished with the tree, or NULL if none was needed.
OPTIONS will be passed to the demangler. */

-static struct demangle_component *
+static struct demangle_parse_info *
mangled_name_to_comp (const char *mangled_name, int options,
void **memory, char **demangled_p)
{
- struct demangle_component *ret;
char *demangled_name;
+ struct demangle_parse_info *info;

/* If it looks like a v3 mangled name, then try to go directly
to trees. */
if (mangled_name[0] == '_' && mangled_name[1] == 'Z')
{
+ struct demangle_component *ret;
ret = cplus_demangle_v3_components (mangled_name,
options, memory);
if (ret)
{
+ info = ((struct demangle_parse_info *)
+ xmalloc (sizeof (struct demangle_parse_info)));
+ info->info = NULL;
+ info->tree = ret;
*demangled_p = NULL;
- return ret;
+ return info;
}
}

@@ -181,16 +296,16 @@ mangled_name_to_comp (const char *mangle

/* If we could demangle the name, parse it to build the component
tree. */
- ret = cp_demangled_name_to_comp (demangled_name, NULL);
+ info = cp_demangled_name_to_comp (demangled_name, NULL);

- if (ret == NULL)
+ if (info == NULL)
{
xfree (demangled_name);
return NULL;
}

*demangled_p = demangled_name;
- return ret;
+ return info;
}

/* Return the name of the class containing method PHYSNAME. */
@@ -201,14 +316,16 @@ cp_class_name_from_physname (const char
void *storage = NULL;
char *demangled_name = NULL, *ret;
struct demangle_component *ret_comp, *prev_comp, *cur_comp;
+ struct demangle_parse_info *info;
int done;

- ret_comp = mangled_name_to_comp (physname, DMGL_ANSI,
- &storage, &demangled_name);
- if (ret_comp == NULL)
+ info = mangled_name_to_comp (physname, DMGL_ANSI,
+ &storage, &demangled_name);
+ if (info == NULL)
return NULL;

done = 0;
+ ret_comp = info->tree;

/* First strip off any qualifiers, if we have a function or
method. */
@@ -277,8 +394,8 @@ cp_class_name_from_physname (const char
}

xfree (storage);
- if (demangled_name)
- xfree (demangled_name);
+ xfree (demangled_name);
+ cp_demangled_name_parse_free (info);
return ret;
}

@@ -348,13 +465,14 @@ method_name_from_physname (const char *p
void *storage = NULL;
char *demangled_name = NULL, *ret;
struct demangle_component *ret_comp;
+ struct demangle_parse_info *info;

- ret_comp = mangled_name_to_comp (physname, DMGL_ANSI,
- &storage, &demangled_name);
- if (ret_comp == NULL)
+ info = mangled_name_to_comp (physname, DMGL_ANSI,
+ &storage, &demangled_name);
+ if (info == NULL)
return NULL;

- ret_comp = unqualified_name_from_comp (ret_comp);
+ ret_comp = unqualified_name_from_comp (info->tree);

ret = NULL;
if (ret_comp != NULL)
@@ -363,8 +481,8 @@ method_name_from_physname (const char *p
ret = cp_comp_to_string (ret_comp, 10);

xfree (storage);
- if (demangled_name)
- xfree (demangled_name);
+ xfree (demangled_name);
+ cp_demangled_name_parse_free (info);
return ret;
}

@@ -379,17 +497,19 @@ cp_func_name (const char *full_name)
{
char *ret;
struct demangle_component *ret_comp;
+ struct demangle_parse_info *info;

- ret_comp = cp_demangled_name_to_comp (full_name, NULL);
- if (!ret_comp)
+ info = cp_demangled_name_to_comp (full_name, NULL);
+ if (!info)
return NULL;

- ret_comp = unqualified_name_from_comp (ret_comp);
+ ret_comp = unqualified_name_from_comp (info->tree);

ret = NULL;
if (ret_comp != NULL)
ret = cp_comp_to_string (ret_comp, 10);

+ cp_demangled_name_parse_free (info);
return ret;
}

@@ -402,16 +522,18 @@ cp_remove_params (const char *demangled_
{
int done = 0;
struct demangle_component *ret_comp;
+ struct demangle_parse_info *info;
char *ret = NULL;

if (demangled_name == NULL)
return NULL;

- ret_comp = cp_demangled_name_to_comp (demangled_name, NULL);
- if (ret_comp == NULL)
+ info = cp_demangled_name_to_comp (demangled_name, NULL);
+ if (info == NULL)
return NULL;

/* First strip off any qualifiers, if we have a function or method. */
+ ret_comp = info->tree;
while (!done)
switch (ret_comp->type)
{
@@ -433,6 +555,7 @@ cp_remove_params (const char *demangled_
if (ret_comp->type == DEMANGLE_COMPONENT_TYPED_NAME)
ret = cp_comp_to_string (d_left (ret_comp), 10);

+ cp_demangled_name_parse_free (info);
return ret;
}

Index: cp-support.h
===================================================================
RCS file: /cvs/src/src/gdb/cp-support.h,v
retrieving revision 1.42
diff -u -p -r1.42 cp-support.h
--- cp-support.h 4 Apr 2011 14:37:16 -0000 1.42
+++ cp-support.h 21 Apr 2011 17:59:15 -0000
@@ -36,6 +36,16 @@ struct objfile;
struct type;
struct demangle_component;

+/* The result of parsing a name. */
+struct demangle_parse_info
+{
+ /* The memory used during the parse. */
+ struct demangle_info *info;
+
+ /* The result of the parse. */
+ struct demangle_component *tree;
+};
+
/* This struct is designed to store data from using directives. It
says that names from namespace IMPORT_SRC should be visible within
namespace IMPORT_DEST. These form a linked list; NEXT is the next
@@ -100,6 +110,8 @@ struct using_direct

extern char *cp_canonicalize_string (const char *string);

+extern char *cp_canonicalize_string_no_typedefs (const char *string);
+
extern char *cp_class_name_from_physname (const char *physname);

extern char *method_name_from_physname (const char *physname);
@@ -177,12 +189,14 @@ struct type *cp_lookup_transparent_type

/* Functions from cp-name-parser.y. */

-extern struct demangle_component *cp_demangled_name_to_comp
+extern struct demangle_parse_info *cp_demangled_name_to_comp
(const char *demangled_name, const char **errmsg);

extern char *cp_comp_to_string (struct demangle_component *result,
int estimated_len);

+extern void cp_demangled_name_parse_free (struct demangle_parse_info *);
+
/* The list of "maint cplus" commands. */

extern struct cmd_list_element *maint_cplus_cmd_list;
Index: dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.524
diff -u -p -r1.524 dwarf2read.c
--- dwarf2read.c 15 Apr 2011 15:05:04 -0000 1.524
+++ dwarf2read.c 21 Apr 2011 17:59:17 -0000
@@ -307,6 +307,16 @@ struct delayed_method_info
typedef struct delayed_method_info delayed_method_info;
DEF_VEC_O (delayed_method_info);

+/* An enumeration for specifying the type of name dwarf2_compute_name
+ generates. */
+enum name_kind
+ {
+ NAME_KIND_FULL, /* The fullname (methods do not
+ contain any formal parameters). */
+ NAME_KIND_PHYS, /* The physname used to lookup symbols. */
+ NAME_KIND_PRINT /* The name used when printing the symbol. */
+ };
+
/* Internal state when decoding a particular compilation unit. */
struct dwarf2_cu
{
@@ -4835,7 +4845,7 @@ do_ui_file_peek_last (void *object, cons

static const char *
dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu,
- int physname)
+ enum name_kind kind)
{
if (name == NULL)
name = dwarf2_name (die, cu);
@@ -4843,7 +4853,7 @@ dwarf2_compute_name (char *name, struct
/* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
compute it by typename_concat inside GDB. */
if (cu->language == language_ada
- || (cu->language == language_fortran && physname))
+ || (cu->language == language_fortran && kind == NAME_KIND_PHYS))
{
/* For Ada unit, we prefer the linkage name over the name, as
the former contains the exported name, which the user expects
@@ -4875,7 +4885,8 @@ dwarf2_compute_name (char *name, struct
if (*prefix != '\0')
{
char *prefixed_name = typename_concat (NULL, prefix, name,
- physname, cu);
+ (kind == NAME_KIND_PHYS),
+ cu);

fputs_unfiltered (prefixed_name, buf);
xfree (prefixed_name);
@@ -5012,13 +5023,17 @@ dwarf2_compute_name (char *name, struct
/* For Java and C++ methods, append formal parameter type
information, if PHYSNAME. */

- if (physname && die->tag == DW_TAG_subprogram
+ if ((kind == NAME_KIND_PHYS || kind == NAME_KIND_PRINT)
+ && die->tag == DW_TAG_subprogram
&& (cu->language == language_cplus
|| cu->language == language_java))
{
struct type *type = read_type_die (die, cu);

- c_type_print_args (type, buf, 1, cu->language);
+ c_type_print_args (type, buf,
+ (kind == NAME_KIND_PHYS ? 1 : 0),
+ (kind == NAME_KIND_PRINT ? 1 : 0),
+ cu->language);

if (cu->language == language_java)
{
@@ -5074,7 +5089,7 @@ dwarf2_compute_name (char *name, struct
static const char *
dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu)
{
- return dwarf2_compute_name (name, die, cu, 0);
+ return dwarf2_compute_name (name, die, cu, NAME_KIND_FULL);
}

/* Construct a physname for the given DIE in CU. NAME may either be
@@ -5087,7 +5102,13 @@ dwarf2_full_name (char *name, struct die
static const char *
dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu)
{
- return dwarf2_compute_name (name, die, cu, 1);
+ return dwarf2_compute_name (name, die, cu, NAME_KIND_PHYS);
+}
+
+static const char *
+dwarf2_print_name (char *name, struct die_info *die, struct dwarf2_cu *cu)
+{
+ return dwarf2_compute_name (name, die, cu, NAME_KIND_PRINT);
}

/* Read the import statement specified by the given die and record it. */
@@ -11002,6 +11023,20 @@ new_symbol_full (struct die_info *die, s
linkagename = dwarf2_physname (name, die, cu);
SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile);

+ /* For C++ set the symbol's demangled name if it is different than
+ the computed physname. This can happen when the source defines
+ a method with typedef'd parameters. This is ultimately used by
+ the type printer. */
+ if (cu->language == language_cplus && die->tag == DW_TAG_subprogram)
+ {
+ const char *print_name = dwarf2_print_name (name, die, cu);
+ if (strcmp (print_name, linkagename))
+ {
+ symbol_set_demangled_name (&(sym->ginfo),
+ (char *) print_name, NULL);
+ }
+ }
+
/* Fortran does not have mangling standard and the mangling does differ
between gfortran, iFort etc. */
if (cu->language == language_fortran
Index: jv-typeprint.c
===================================================================
RCS file: /cvs/src/src/gdb/jv-typeprint.c,v
retrieving revision 1.22
diff -u -p -r1.22 jv-typeprint.c
--- jv-typeprint.c 9 Jan 2011 03:08:57 -0000 1.22
+++ jv-typeprint.c 21 Apr 2011 17:59:18 -0000
@@ -328,9 +328,6 @@ java_type_print_base (struct type *type,

/* LEVEL is the depth to indent lines by. */

-extern void c_type_print_varspec_suffix (struct type *, struct ui_file *,
- int, int, int);
-
void
java_print_type (struct type *type, const char *varstring,
struct ui_file *stream, int show, int level)
@@ -349,5 +346,5 @@ java_print_type (struct type *type, cons
so don't print an additional pair of ()'s. */

demangled_args = varstring != NULL && strchr (varstring, '(') != NULL;
- c_type_print_varspec_suffix (type, stream, show, 0, demangled_args);
+ c_type_print_varspec_suffix (type, stream, show, 0, demangled_args, 0);
}
Index: linespec.c
===================================================================
RCS file: /cvs/src/src/gdb/linespec.c,v
retrieving revision 1.118
diff -u -p -r1.118 linespec.c
--- linespec.c 4 Apr 2011 17:41:07 -0000 1.118
+++ linespec.c 21 Apr 2011 17:59:18 -0000
@@ -222,7 +222,7 @@ find_methods (struct type *t, char *name

/* NAME is typed by the user: it needs to be canonicalized before
passing to lookup_symbol. */
- canon = cp_canonicalize_string (name);
+ canon = cp_canonicalize_string_no_typedefs (name);
if (canon != NULL)
{
name = canon;
@@ -1315,7 +1315,7 @@ decode_compound (char **argptr, int funf
char *the_real_saved_arg, char *p)
{
struct symtabs_and_lines values;
- char *p2;
+ char *p2, *name, *canon;
char *saved_arg2 = *argptr;
char *temp_end;
struct symbol *sym;
@@ -1324,6 +1324,7 @@ decode_compound (char **argptr, int funf
struct type *t;
char *saved_java_argptr = NULL;
char *saved_arg;
+ struct cleanup *cleanup;

/* If the user specified any completer quote characters in the input,
strip them. They are superfluous. */
@@ -1586,7 +1587,17 @@ decode_compound (char **argptr, int funf
*argptr = (*p == '\'') ? p + 1 : p;

/* Look up entire name. */
- sym = lookup_symbol (copy, get_selected_block (0), VAR_DOMAIN, 0);
+ name = copy;
+ canon = cp_canonicalize_string_no_typedefs (copy);
+ if (canon != NULL)
+ {
+ name = canon;
+ cleanup = make_cleanup (xfree, name);
+ }
+ else
+ cleanup = make_cleanup (null_cleanup, NULL);
+ sym = lookup_symbol (name, get_selected_block (0), VAR_DOMAIN, 0);
+ do_cleanups (cleanup);
if (sym)
return symbol_found (funfirstline, canonical, copy, sym, NULL, NULL);
else
@@ -1727,7 +1738,7 @@ find_method (int funfirstline, struct li
strcpy (name, SYMBOL_NATURAL_NAME (sym_class));
strcat (name, "::");
strcat (name, copy);
- canon = cp_canonicalize_string (name);
+ canon = cp_canonicalize_string_no_typedefs (name);
if (canon != NULL)
{
xfree (name);
@@ -2069,15 +2080,27 @@ decode_variable (char *copy, int funfirs
struct linespec_result *canonical,
struct symtab *file_symtab)
{
+ char *name;
struct symbol *sym;
+ struct cleanup *cleanup;
struct minimal_symbol *msymbol;

- sym = lookup_symbol (copy,
+ name = cp_canonicalize_string_no_typedefs (copy);
+ if (name == NULL)
+ {
+ name = copy;
+ cleanup = make_cleanup (null_cleanup, NULL);
+ }
+ else
+ cleanup = make_cleanup (xfree, name);
+
+ sym = lookup_symbol (name,
(file_symtab
? BLOCKVECTOR_BLOCK (BLOCKVECTOR (file_symtab),
STATIC_BLOCK)
: get_selected_block (0)),
VAR_DOMAIN, 0);
+ do_cleanups (cleanup);

if (sym != NULL)
return symbol_found (funfirstline, canonical, copy, sym, file_symtab, NULL);
Index: symtab.c
===================================================================
RCS file: /cvs/src/src/gdb/symtab.c,v
retrieving revision 1.266
diff -u -p -r1.266 symtab.c
--- symtab.c 19 Apr 2011 18:04:07 -0000 1.266
+++ symtab.c 21 Apr 2011 17:59:19 -0000
@@ -740,17 +740,21 @@ symbol_demangled_name (const struct gene
return NULL;
}

-/* Return the search name of a symbol---generally the demangled or
- linkage name of the symbol, depending on how it will be searched for.
- If there is no distinct demangled name, then returns the same value
- (same pointer) as SYMBOL_LINKAGE_NAME. */
+/* Return the search name of a symbol. This is typically the smybol's
+ physname (SYMBOL_LINKAGE_NAME). Symbols with mangled names
+ are special: return their SYMBOL_NATURAL_NAME instead. */
char *
symbol_search_name (const struct general_symbol_info *gsymbol)
{
if (gsymbol->language == language_ada)
return gsymbol->name;
else
- return symbol_natural_name (gsymbol);
+ {
+ if (gsymbol->name && gsymbol->name[0] == '_' && gsymbol->name[1] == 'Z')
+ return symbol_natural_name (gsymbol);
+ else
+ return gsymbol->name;
+ }
}

/* Initialize the structure fields to zero values. */
@@ -2900,8 +2904,8 @@ compare_search_syms (const void *sa, con
struct symbol_search **sym_a = (struct symbol_search **) sa;
struct symbol_search **sym_b = (struct symbol_search **) sb;

- return strcmp (SYMBOL_PRINT_NAME ((*sym_a)->symbol),
- SYMBOL_PRINT_NAME ((*sym_b)->symbol));
+ return strcmp (SYMBOL_SEARCH_NAME ((*sym_a)->symbol),
+ SYMBOL_SEARCH_NAME ((*sym_b)->symbol));
}

/* Sort the ``nfound'' symbols in the list after prevtail. Leave
Index: typeprint.h
===================================================================
RCS file: /cvs/src/src/gdb/typeprint.h,v
retrieving revision 1.11
diff -u -p -r1.11 typeprint.h
--- typeprint.h 1 Jan 2011 15:33:18 -0000 1.11
+++ typeprint.h 21 Apr 2011 17:59:19 -0000
@@ -26,7 +26,9 @@ struct ui_file;
void print_type_scalar (struct type * type, LONGEST, struct ui_file *);

void c_type_print_varspec_suffix (struct type *, struct ui_file *, int,
- int, int);
+ int, int, int);
+
+void c_type_print_args (struct type *, struct ui_file *,
+ int, int, enum language);

-void c_type_print_args (struct type *, struct ui_file *, int, enum language);
#endif
Index: python/py-type.c
===================================================================
RCS file: /cvs/src/src/gdb/python/py-type.c,v
retrieving revision 1.18
diff -u -p -r1.18 py-type.c
--- python/py-type.c 26 Jan 2011 20:53:45 -0000 1.18
+++ python/py-type.c 21 Apr 2011 17:59:19 -0000
@@ -577,6 +577,7 @@ typy_legacy_template_argument (struct ty
{
int i;
struct demangle_component *demangled;
+ struct demangle_parse_info *info;
const char *err;
struct type *argtype;

@@ -587,12 +588,13 @@ typy_legacy_template_argument (struct ty
}

/* Note -- this is not thread-safe. */
- demangled = cp_demangled_name_to_comp (TYPE_NAME (type), &err);
- if (! demangled)
+ info = cp_demangled_name_to_comp (TYPE_NAME (type), &err);
+ if (! info)
{
PyErr_SetString (PyExc_RuntimeError, err);
return NULL;
}
+ demangled = info->tree;

/* Strip off component names. */
while (demangled->type == DEMANGLE_COMPONENT_QUAL_NAME
@@ -601,6 +603,7 @@ typy_legacy_template_argument (struct ty

if (demangled->type != DEMANGLE_COMPONENT_TEMPLATE)
{
+ cp_demangled_name_parse_free (info);
PyErr_SetString (PyExc_RuntimeError, _("Type is not a template."));
return NULL;
}
@@ -613,12 +616,14 @@ typy_legacy_template_argument (struct ty

if (! demangled)
{
+ cp_demangled_name_parse_free (info);
PyErr_Format (PyExc_RuntimeError, _("No argument %d in template."),
argno);
return NULL;
}

argtype = typy_lookup_type (demangled->u.s_binary.left, block);
+ cp_demangled_name_parse_free (info);
if (! argtype)
return NULL;

Index: testsuite/gdb.cp/meth-typedefs.cc
===================================================================
RCS file: testsuite/gdb.cp/meth-typedefs.cc
diff -N testsuite/gdb.cp/meth-typedefs.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/gdb.cp/meth-typedefs.cc 21 Apr 2011 17:59:19 -0000
@@ -0,0 +1,80 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2011 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/>.
+
+ Contributed by Red Hat, originally written by Keith Seitz. */
+
+#include <stdlib.h>
+
+typedef const char* const* my_type;
+typedef int my_type_2;
+typedef my_type my_other_type;
+typedef my_type_2 my_other_type_2;
+
+typedef void (*fptr1) (my_other_type);
+typedef void (*fptr2) (fptr1, my_other_type_2);
+typedef void (*fptr3) (fptr2, my_other_type);
+
+namespace A
+{
+ class foo
+ {
+ public:
+ foo (void) { }
+ foo (my_other_type a) { } // A::foo::foo(my_other_type)
+ foo (my_other_type_2 a) { } // A::foo::foo(my_other_type_2)
+ foo (my_other_type_2 a, my_other_type b) { } // A::foo::foo(my_other_type_2, my_other_type)
+ foo (fptr3) { } // A::foo::foo(fptr3)
+ void test (my_other_type a) { } // A::foo::test(my_other_type)
+ void test (my_other_type_2 a) { } // A::foo::test(my_other_type_2)
+ void test (my_other_type_2 a, my_other_type b) { } // A::foo::test(my_other_type_2, my_other_type)
+ void test (fptr3 a) { } // A::foo::test(fptr3)
+ };
+};
+
+namespace B
+{
+ void
+ test (my_other_type foo) { } // B::test(my_other_type)
+
+ void
+ test (my_other_type foo, my_other_type_2) { } // B::test(my_other_type, my_other_type_2)
+};
+
+void
+test (my_other_type foo) { } // test(my_other_type)
+
+void
+test (my_other_type foo, my_other_type_2) { } // test(my_other_type, my_other_type_2)
+
+int
+main (void)
+{
+ A::foo f, a[3];
+ f.test (static_cast<my_other_type> (NULL));
+ f.test (0);
+ f.test (0, static_cast<my_type> (NULL));
+ f.test (static_cast<fptr3> (NULL));
+ B::test (static_cast<my_other_type> (NULL));
+ B::test (static_cast<my_other_type> (NULL), 0);
+ test (static_cast<my_other_type> (NULL));
+ test (static_cast<my_other_type> (NULL), 0);
+ A::foo w (static_cast<my_other_type> (NULL));
+ A::foo x (0);
+ A::foo y (0, static_cast<my_other_type> (NULL));
+ A::foo z (static_cast<fptr3> (NULL));
+ return 0;
+}
Index: testsuite/gdb.cp/meth-typedefs.exp
===================================================================
RCS file: testsuite/gdb.cp/meth-typedefs.exp
diff -N testsuite/gdb.cp/meth-typedefs.exp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/gdb.cp/meth-typedefs.exp 21 Apr 2011 17:59:20 -0000
@@ -0,0 +1,112 @@
+# Copyright 2011 Free Software Foundation, Inc.
+#
+# Contributed by Red Hat, originally written by Keith Seitz.
+#
+# 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/>.
+
+# This file is part of the gdb testsuite.
+
+proc add {var name params expected} {
+ upvar $var result
+ set expect ".*// ${name}\\($expected\\)"
+ lappend result [list "${name}($params)" $expect]
+}
+
+if {[skip_cplus_tests]} { continue }
+
+# Tests for c++/12266 et al
+set testfile "meth-typedefs"
+set srcfile $testfile.cc
+
+if {[prepare_for_testing $testfile $testfile $srcfile {c++ debug}]} {
+ return -1
+}
+
+if {![runto_main]} {
+ perror "couldn't run to breakpoint"
+ continue
+}
+
+array set typedefs {
+ "my_other_type" {"my_other_type" "my_type" "const char* const*"}
+ "my_other_type_2" {"my_other_type_2" "my_type_2" "int"}
+}
+
+set methods {}
+
+# Add the simple, one-parameter methods
+foreach method {A::foo::test A::foo::foo} {
+ foreach type {my_other_type my_other_type_2} {
+ foreach t $typedefs($type) {
+ add methods $method $t $type
+ }
+ }
+}
+# Add two-parameter methods
+foreach method {A::foo::test A::foo::foo} {
+ set type "my_other_type_2, my_other_type"
+ foreach t1 $typedefs(my_other_type_2) {
+ foreach t2 $typedefs(my_other_type) {
+ add methods $method "$t1, $t2" $type
+ }
+ }
+}
+
+# Add the function pointer methods
+set type "fptr3"
+foreach method {A::foo::test A::foo::foo} {
+ add methods $method "fptr3" $type
+
+ foreach t1 $typedefs(my_other_type) {
+ add methods $method "void (*)(fptr2, $t1)" $type
+ foreach t2 $typedefs(my_other_type_2) {
+ add methods $method "void (*)(void (*)(fptr1, $t2), $t1)" $type
+ foreach t3 $typedefs(my_other_type) {
+ add methods $method \
+ "void (*)(void (*)(void (*) ($t3), $t2), $t1)" $type
+ }
+ }
+ }
+}
+
+# Add non-method tests
+set type1 "my_other_type"
+set type2 "my_other_type, my_other_type_2"
+foreach method {"test" "B::test"} {
+ foreach t1 $typedefs(my_other_type) {
+ add methods $method $t1 $type1
+ foreach t2 $typedefs(my_other_type_2) {
+ add methods $method "$t1, $t2" $type2
+ }
+ }
+}
+
+gdb_test_no_output "set listsize 1" ""
+
+# Finally, for each method in the list METHODS, check whether
+# the user can "list" it and "break" on it (both quoted and unquoted).
+foreach test $methods {
+ set func [lindex $test 0]
+ set result [lindex $test 1]
+ gdb_test "list $func" $result
+ if {[gdb_breakpoint $func]} {
+ pass "break $func"
+ }
+ if {[gdb_breakpoint '$func']} {
+ pass "break '$func'"
+ }
+}
+
+gdb_exit
+return 0