From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19518 invoked by alias); 3 Jun 2003 01:39:09 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 19463 invoked from network); 3 Jun 2003 01:39:08 -0000 Received: from unknown (HELO mx1.redhat.com) (66.187.233.31) by sources.redhat.com with SMTP; 3 Jun 2003 01:39:08 -0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.11.6/8.11.6) with ESMTP id h531d8H14001 for ; Mon, 2 Jun 2003 21:39:08 -0400 Received: from pobox.corp.redhat.com (pobox.corp.redhat.com [172.16.52.156]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id h531d8I15796 for ; Mon, 2 Jun 2003 21:39:08 -0400 Received: from localhost.redhat.com (IDENT:78mAOptYyuqN7sUBmQPn9YpFmUNfLNsY@tooth.toronto.redhat.com [172.16.14.29]) by pobox.corp.redhat.com (8.11.6/8.11.6) with ESMTP id h531d6b08995; Mon, 2 Jun 2003 21:39:07 -0400 Received: by localhost.redhat.com (Postfix, from userid 469) id 3E64E2C43D; Mon, 2 Jun 2003 21:45:00 -0400 (EDT) From: Elena Zannoni MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <16091.64924.18200.426877@localhost.redhat.com> Date: Tue, 03 Jun 2003 01:39:00 -0000 To: David Carlton Cc: gdb-patches@sources.redhat.com, Elena Zannoni Subject: Re: [rfa] linespec.c: add_{matching_methods,constructors} In-Reply-To: References: X-SW-Source: 2003-06/txt/msg00112.txt.bz2 David Carlton writes: > After a long hiatus, here's the latest in my exciting series of > linespec.c patches. This one extracts code from find_methods into > add_matching_methods and add_constructors. > > The only subtlety is that the new functions translate sym_arr over by > i1, so the meaning of sym_arr and i1 between the two functions is > different. (But the meaning of sym_arr[i1] is the same: they're both > translated in a consistent way to preserve that invariant.) > Everything else about the change is mindless. > > Tested on GCC 3.1, DWARF 2, i686-pc-linux-gnu; no new regressions. OK > to commit? yes, thanks elena > > David Carlton > carlton@bactrian.org > > 2003-05-23 David Carlton > > * linespec.c (find_methods): Break out code into > add_matching_methods and add_constructors. > (add_matching_methods): New. > (add_constructors): Ditto. > > Index: linespec.c > =================================================================== > RCS file: /cvs/src/src/gdb/linespec.c,v > retrieving revision 1.47 > diff -u -p -r1.47 linespec.c > --- linespec.c 14 May 2003 17:43:18 -0000 1.47 > +++ linespec.c 24 May 2003 00:16:06 -0000 > @@ -82,6 +82,12 @@ static int total_number_of_methods (stru > > static int find_methods (struct type *, char *, struct symbol **); > > +static int add_matching_methods (int method_counter, struct type *t, > + struct symbol **sym_arr); > + > +static int add_constructors (int method_counter, struct type *t, > + struct symbol **sym_arr); > + > static void build_canonical_line_spec (struct symtab_and_line *, > char *, char ***); > > @@ -210,7 +216,6 @@ find_methods (struct type *t, char *name > method_counter >= 0; > --method_counter) > { > - int field_counter; > char *method_name = TYPE_FN_FIELDLIST_NAME (t, method_counter); > char dem_opname[64]; > > @@ -226,88 +231,13 @@ find_methods (struct type *t, char *name > > if (strcmp_iw (name, method_name) == 0) > /* Find all the overloaded methods with that name. */ > - for (field_counter = TYPE_FN_FIELDLIST_LENGTH (t, method_counter) - 1; > - field_counter >= 0; > - --field_counter) > - { > - struct fn_field *f; > - char *phys_name; > - > - f = TYPE_FN_FIELDLIST1 (t, method_counter); > - > - if (TYPE_FN_FIELD_STUB (f, field_counter)) > - { > - char *tmp_name; > - > - tmp_name = gdb_mangle_name (t, > - method_counter, > - field_counter); > - phys_name = alloca (strlen (tmp_name) + 1); > - strcpy (phys_name, tmp_name); > - xfree (tmp_name); > - } > - else > - phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter); > - > - /* Destructor is handled by caller, don't add it to > - the list. */ > - if (is_destructor_name (phys_name) != 0) > - continue; > - > - sym_arr[i1] = lookup_symbol (phys_name, > - NULL, VAR_DOMAIN, > - (int *) NULL, > - (struct symtab **) NULL); > - if (sym_arr[i1]) > - i1++; > - else > - { > - /* This error message gets printed, but the method > - still seems to be found > - fputs_filtered("(Cannot find method ", gdb_stdout); > - fprintf_symbol_filtered (gdb_stdout, phys_name, > - language_cplus, > - DMGL_PARAMS | DMGL_ANSI); > - fputs_filtered(" - possibly inlined.)\n", gdb_stdout); > - */ > - } > - } > + i1 += add_matching_methods (method_counter, t, > + sym_arr + i1); > else if (strncmp (class_name, name, name_len) == 0 > && (class_name[name_len] == '\0' > || class_name[name_len] == '<')) > - { > - /* For GCC 3.x and stabs, constructors and destructors > - have names like __base_ctor and __complete_dtor. > - Check the physname for now if we're looking for a > - constructor. */ > - for (field_counter > - = TYPE_FN_FIELDLIST_LENGTH (t, method_counter) - 1; > - field_counter >= 0; > - --field_counter) > - { > - struct fn_field *f; > - char *phys_name; > - > - f = TYPE_FN_FIELDLIST1 (t, method_counter); > - > - /* GCC 3.x will never produce stabs stub methods, so > - we don't need to handle this case. */ > - if (TYPE_FN_FIELD_STUB (f, field_counter)) > - continue; > - phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter); > - if (! is_constructor_name (phys_name)) > - continue; > - > - /* If this method is actually defined, include it in the > - list. */ > - sym_arr[i1] = lookup_symbol (phys_name, > - NULL, VAR_DOMAIN, > - (int *) NULL, > - (struct symtab **) NULL); > - if (sym_arr[i1]) > - i1++; > - } > - } > + i1 += add_constructors (method_counter, t, > + sym_arr + i1); > } > } > > @@ -325,6 +255,113 @@ find_methods (struct type *t, char *name > if (i1 == 0) > for (ibase = 0; ibase < TYPE_N_BASECLASSES (t); ibase++) > i1 += find_methods (TYPE_BASECLASS (t, ibase), name, sym_arr + i1); > + > + return i1; > +} > + > +/* Add the symbols associated to methods of the class whose type is T > + and whose name matches the method indexed by METHOD_COUNTER in the > + array SYM_ARR. Return the number of methods added. */ > + > +static int > +add_matching_methods (int method_counter, struct type *t, > + struct symbol **sym_arr) > +{ > + int field_counter; > + int i1 = 0; > + > + for (field_counter = TYPE_FN_FIELDLIST_LENGTH (t, method_counter) - 1; > + field_counter >= 0; > + --field_counter) > + { > + struct fn_field *f; > + char *phys_name; > + > + f = TYPE_FN_FIELDLIST1 (t, method_counter); > + > + if (TYPE_FN_FIELD_STUB (f, field_counter)) > + { > + char *tmp_name; > + > + tmp_name = gdb_mangle_name (t, > + method_counter, > + field_counter); > + phys_name = alloca (strlen (tmp_name) + 1); > + strcpy (phys_name, tmp_name); > + xfree (tmp_name); > + } > + else > + phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter); > + > + /* Destructor is handled by caller, don't add it to > + the list. */ > + if (is_destructor_name (phys_name) != 0) > + continue; > + > + sym_arr[i1] = lookup_symbol (phys_name, > + NULL, VAR_DOMAIN, > + (int *) NULL, > + (struct symtab **) NULL); > + if (sym_arr[i1]) > + i1++; > + else > + { > + /* This error message gets printed, but the method > + still seems to be found > + fputs_filtered("(Cannot find method ", gdb_stdout); > + fprintf_symbol_filtered (gdb_stdout, phys_name, > + language_cplus, > + DMGL_PARAMS | DMGL_ANSI); > + fputs_filtered(" - possibly inlined.)\n", gdb_stdout); > + */ > + } > + } > + > + return i1; > +} > + > +/* Add the symbols associated to constructors of the class whose type > + is CLASS_TYPE and which are indexed by by METHOD_COUNTER to the > + array SYM_ARR. Return the number of methods added. */ > + > +static int > +add_constructors (int method_counter, struct type *t, > + struct symbol **sym_arr) > +{ > + int field_counter; > + int i1 = 0; > + > + /* For GCC 3.x and stabs, constructors and destructors > + have names like __base_ctor and __complete_dtor. > + Check the physname for now if we're looking for a > + constructor. */ > + for (field_counter > + = TYPE_FN_FIELDLIST_LENGTH (t, method_counter) - 1; > + field_counter >= 0; > + --field_counter) > + { > + struct fn_field *f; > + char *phys_name; > + > + f = TYPE_FN_FIELDLIST1 (t, method_counter); > + > + /* GCC 3.x will never produce stabs stub methods, so > + we don't need to handle this case. */ > + if (TYPE_FN_FIELD_STUB (f, field_counter)) > + continue; > + phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter); > + if (! is_constructor_name (phys_name)) > + continue; > + > + /* If this method is actually defined, include it in the > + list. */ > + sym_arr[i1] = lookup_symbol (phys_name, > + NULL, VAR_DOMAIN, > + (int *) NULL, > + (struct symtab **) NULL); > + if (sym_arr[i1]) > + i1++; > + } > > return i1; > }