From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3928 invoked by alias); 25 May 2012 21:01:24 -0000 Mailing-List: contact archer-commits-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: Received: (qmail 3894 invoked by uid 9813); 25 May 2012 21:01:21 -0000 Date: Fri, 25 May 2012 21:01:00 -0000 Message-ID: <20120525210121.3879.qmail@sourceware.org> From: sergiodj@sourceware.org To: archer-commits@sourceware.org Subject: [SCM] archer-sergiodj-cpp-template-lookup: [C++-template-lookup] Import of the second patch. X-Git-Refname: refs/heads/archer-sergiodj-cpp-template-lookup X-Git-Reftype: branch X-Git-Oldrev: 6436c52bbd3d7ccd54e67138dd7cee92cb371966 X-Git-Newrev: a3b0f75e14c85acaa29401987b6348075d7ecff3 X-SW-Source: 2012-q2/txt/msg00034.txt.bz2 List-Id: The branch, archer-sergiodj-cpp-template-lookup has been updated via a3b0f75e14c85acaa29401987b6348075d7ecff3 (commit) from 6436c52bbd3d7ccd54e67138dd7cee92cb371966 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit a3b0f75e14c85acaa29401987b6348075d7ecff3 Author: Sergio Durigan Junior Date: Fri May 25 17:58:39 2012 -0300 [C++-template-lookup] Import of the second patch. URL: http://sourceware.org/ml/gdb-patches/2010-07/msg00285.html ----------------------------------------------------------------------- Summary of changes: gdb/c-typeprint.c | 6 ++ gdb/dwarf2read.c | 96 ++++++++++++++++++++++++++++-------- gdb/findvar.c | 4 ++ gdb/gdbtypes.h | 7 ++- gdb/symtab.h | 4 ++ gdb/testsuite/gdb.cp/temp-op.cc | 28 ++++++++-- gdb/testsuite/gdb.cp/temp-op.exp | 18 +++++-- gdb/testsuite/gdb.cp/templates.exp | 15 ++++++ gdb/valops.c | 9 ++-- 9 files changed, 151 insertions(+), 36 deletions(-) First 500 lines of diff: diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c index a5892b5..7db9660 100644 --- a/gdb/c-typeprint.c +++ b/gdb/c-typeprint.c @@ -326,6 +326,7 @@ c_type_print_varspec_prefix (struct type *type, case TYPE_CODE_COMPLEX: case TYPE_CODE_NAMESPACE: case TYPE_CODE_DECFLOAT: + case TYPE_CODE_TEMPLATE: /* These types need no prefix. They are listed here so that gcc -Wall will reveal any types that haven't been handled. */ break; @@ -683,6 +684,7 @@ c_type_print_varspec_suffix (struct type *type, case TYPE_CODE_COMPLEX: case TYPE_CODE_NAMESPACE: case TYPE_CODE_DECFLOAT: + case TYPE_CODE_TEMPLATE: /* These types do not need a suffix. They are listed so that gcc -Wall will report types that may not have been considered. */ @@ -1238,6 +1240,10 @@ c_type_print_base (struct type *type, struct ui_file *stream, fputs_filtered (TYPE_TAG_NAME (type), stream); break; + case TYPE_CODE_TEMPLATE: + fputs_filtered ("Template Symbol", stream); + break; + default: /* Handle types not explicitly handled by the other cases, such as fundamental types. For these, just print whatever the diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 33fea34..cce2eae 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -13253,6 +13253,72 @@ var_decode_location (struct attribute *attr, struct symbol *sym, cu->has_loclist = 1; } +static void +add_template_variable (struct symbol *symbol, struct pending **listhead, + struct objfile *objfile) +{ + const struct pending *iterator; + struct symbol *template_sym; + struct symbol *iterator_sym; + struct type *type; + const char *name = SYMBOL_NATURAL_NAME (symbol); + char *search_name; + char *tmp; + int i; + struct cleanup *all_cleanups = make_cleanup (null_cleanup, NULL); + + gdb_assert (name != NULL); + gdb_assert (listhead != NULL); + + /* Remove template parameters from the symbol's name and set its + search name. */ + tmp = cp_remove_template_params (name); + + gdb_assert (tmp != NULL); + make_cleanup(xfree, tmp); + + if (strcmp (tmp, name) == 0) + return; + + search_name = obsavestring (tmp, strlen (tmp), &objfile->objfile_obstack); + + symbol_set_cplus_search_name (&symbol->ginfo, objfile, search_name); + + /* Has a template symbol for this symbol been added already? */ + for (iterator = *(listhead); iterator != NULL; iterator = iterator->next) + { + for (i = iterator->nsyms - 1; i >= 0; --i) + { + iterator_sym = iterator->symbol[i]; + + if (TYPE_CODE (SYMBOL_TYPE (iterator_sym)) == TYPE_CODE_TEMPLATE + && strcmp (SYMBOL_SEARCH_NAME(iterator_sym), search_name) == 0) + { + do_cleanups (all_cleanups); + return; + } + } + } + + /* Add a new template symbol. */ + template_sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack, + sizeof (struct symbol)); + OBJSTAT (objfile, n_syms++); + memset (template_sym, 0, sizeof (struct symbol)); + + SYMBOL_SET_NAMES (template_sym, search_name, strlen (search_name), 0, objfile); + type = alloc_type (objfile); + TYPE_CODE (type) = TYPE_CODE_TEMPLATE; + SYMBOL_TYPE (template_sym) = type; + + SYMBOL_DOMAIN (template_sym) = VAR_DOMAIN; + SYMBOL_CLASS (template_sym) = LOC_TEMPLATE; + + add_symbol_to_list (template_sym, listhead); + + do_cleanups (all_cleanups); +} + /* Given a pointer to a DWARF information entry, figure out if we need to make a symbol table entry for it, and if so, create a new entry and return a pointer to it. @@ -13303,26 +13369,6 @@ new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu, (char *) dwarf2_full_name (name, die, cu), NULL); - /* For C++ if the name contains template parameters remove them, and set - the cleaned up name to be the search name. */ - if (cu->language == language_cplus && linkagename - && cp_name_has_template_parameters (linkagename)) - { - char *tmp = cp_remove_template_params (linkagename); - - if (tmp != NULL && strcmp (tmp, linkagename) != 0) - { - search_name = obsavestring (tmp, strlen (tmp), - &objfile->objfile_obstack); - - symbol_set_cplus_search_name (&sym->ginfo, - objfile, - search_name); - } - - xfree (tmp); - } - /* Default assumptions. Use the passed type or decode it from the die. */ SYMBOL_DOMAIN (sym) = VAR_DOMAIN; @@ -13623,7 +13669,15 @@ new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu, } if (list_to_add != NULL) - add_symbol_to_list (sym, list_to_add); + { + /* For C++ if the name contains template parameters remove them, and set + the cleaned up name to be the search name. */ + if (cu->language == language_cplus && sym->ginfo.name + && cp_name_has_template_parameters (sym->ginfo.name)) + add_template_variable (sym, list_to_add, objfile); + + add_symbol_to_list (sym, list_to_add); + } /* For the benefit of old versions of GCC, check for anonymous namespaces based on the demangled name. */ diff --git a/gdb/findvar.c b/gdb/findvar.c index ed7903c..0190a1b 100644 --- a/gdb/findvar.c +++ b/gdb/findvar.c @@ -590,6 +590,10 @@ default_read_var_value (struct symbol *var, struct frame_info *frame) case LOC_OPTIMIZED_OUT: return allocate_optimized_out_value (type); + case LOC_TEMPLATE: + error (_("Symbol represents a template and cannot be evaluated.")); + break; + default: error (_("Cannot look up value of a botched symbol `%s'."), SYMBOL_PRINT_NAME (var)); diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index 887dfdb..dee4012 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -137,7 +137,12 @@ enum type_code TYPE_CODE_MODULE, /* Fortran module. */ /* Internal function type. */ - TYPE_CODE_INTERNAL_FUNCTION + TYPE_CODE_INTERNAL_FUNCTION, + + /* Types with this code are artificial types created to + serve as the root for the instantiations of a given + template. */ + TYPE_CODE_TEMPLATE }; /* For now allow source to use TYPE_CODE_CLASS for C++ classes, as an diff --git a/gdb/symtab.h b/gdb/symtab.h index 37cfd71..ee9cd09 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -516,6 +516,10 @@ enum address_class /* The variable's address is computed by a set of location functions (see "struct symbol_computed_ops" below). */ LOC_COMPUTED, + + /* The variable is a meta variable representing a template + and has no location. */ + LOC_TEMPLATE }; /* The methods needed to implement LOC_COMPUTED. These methods can diff --git a/gdb/testsuite/gdb.cp/temp-op.cc b/gdb/testsuite/gdb.cp/temp-op.cc index 6d4b13d..b423c26 100644 --- a/gdb/testsuite/gdb.cp/temp-op.cc +++ b/gdb/testsuite/gdb.cp/temp-op.cc @@ -9,21 +9,35 @@ int foo (T, char) return 11; } +template +int foo (T, int) +{ + T t; + return 1112; +} + +template +int foo (T, float) +{ + T t; + return 1113; +} + template -int foo2 (T, T2, char) +int foo (T, T2, char) { T t; - return 11; + return 112; } namespace C { namespace D { template - int foo3 (T, T2, char) + int foo (T, T2, char) { T t; - return 11; + return 113; } } } @@ -85,8 +99,10 @@ int main () foo (a, 'a'); foo (a, 1); - foo2 (a, a, 'a'); - C::D::foo3 (a, a, 'a'); + foo (a, 1.0f); + + foo (a, a, 'a'); + C::D::foo (a, a, 'a'); a << 22; a < 22; diff --git a/gdb/testsuite/gdb.cp/temp-op.exp b/gdb/testsuite/gdb.cp/temp-op.exp index f48582f..bb4385b 100644 --- a/gdb/testsuite/gdb.cp/temp-op.exp +++ b/gdb/testsuite/gdb.cp/temp-op.exp @@ -40,8 +40,18 @@ if ![runto_main] then { } # Test that a templated function can be found -# with out specification of template arguments -gdb_test "p foo(a, 'a')" "= 11" +# with out specification of template arguments. +gdb_test "p foo(a, 'a')" "= 11" + +# Test that overload resolution is still performed +# correctly. +gdb_test "p foo(a, 1)" "= 1112" +gdb_test "p foo(a, 1.0f)" "= 1113" + +# Test that fully qualifed names names are not +# confused. +gdb_test "p foo(a, a, 'a')" "= 112" +gdb_test "p C::D::foo (a, a, 'a')" "= 113" # Test that function names with '<' in their names # are not mistaken for templates @@ -64,5 +74,5 @@ gdb_test "p b == 'a'" "= 18" # Test that printing the a template name without # template parameters does not return an arbitrary match -gdb_test "p foo" "No symbol \"foo\" in current context" -gdb_test "ptype B" "No symbol \"foo\" in current context" +gdb_test "print foo" "Symbol represents a template and cannot be evaluated." +gdb_test "ptype B" "type = Template Symbol" diff --git a/gdb/testsuite/gdb.cp/templates.exp b/gdb/testsuite/gdb.cp/templates.exp index 72b65ae..12a7336 100644 --- a/gdb/testsuite/gdb.cp/templates.exp +++ b/gdb/testsuite/gdb.cp/templates.exp @@ -323,6 +323,9 @@ gdb_test_multiple "ptype Foo" "ptype Foo" { # GCC 2.95.3, stabs+ output. pass "ptype Foo" } + -re "type = Template Symbol\r\n$gdb_prompt $" { + pass "ptype Foo" + } } # -re "type = class Foo \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*int foo(int, int);\r\n\\}\r\n$gdb_prompt $" @@ -406,6 +409,9 @@ gdb_test_multiple "ptype Bar" "ptype Bar" { # GCC 2.95.3, stabs+ output. pass "ptype Bar" } + -re "type = Template Symbol\r\n$gdb_prompt $" { + pass "ptype Bar" + } } @@ -453,6 +459,9 @@ gdb_test_multiple "ptype Baz" "ptype Baz" { # GCC 2.95.3, stabs+ output. pass "ptype Baz" } + -re "type = Template Symbol\r\n$gdb_prompt $" { + pass "ptype Baz" + } } @@ -499,6 +508,9 @@ gdb_test_multiple "ptype Qux" "ptype Qux" { # GCC 2.95.3, stabs+ output. pass "ptype Qux" } + -re "type = Template Symbol\r\n$gdb_prompt $" { + pass "ptype Qux" + } } # pt Qux @@ -537,6 +549,9 @@ gdb_test_multiple "ptype Spec" "ptype Spec" { # GCC 2.95.3, stabs+ output. pass "ptype Spec" } + -re "type = Template Symbol\r\n$gdb_prompt $" { + pass "ptype Qux" + } } # pt Spec diff --git a/gdb/valops.c b/gdb/valops.c index 563c9ea..50c6414 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -2686,15 +2686,16 @@ find_overload_match (struct value **args, int nargs, if (fsym) { + enum type_code code + = TYPE_CODE (check_typedef (SYMBOL_TYPE (fsym))); qualified_name = SYMBOL_SEARCH_NAME (fsym); /* If we have a function with a C++ name, try to extract just the function part. Do not try this for non-functions (e.g. function pointers). */ - if (qualified_name - && TYPE_CODE (check_typedef (SYMBOL_TYPE (fsym))) - == TYPE_CODE_FUNC) - { + if (qualified_name + && (code == TYPE_CODE_FUNC || code == TYPE_CODE_TEMPLATE)) + { char *temp; temp = cp_func_name (qualified_name); hooks/post-receive -- Repository for Project Archer.