This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [RFA]: search_symbols(in symtab.c) -- fix off by one error




Yes, true. Approved. Now, though, there is another similar thing in
symtab.c:symtab_symbol_info(). This function also defines an array and
uses LABEL_NAMESPACE to access its elements. But it subtracts 1, so
this is in sync:

symtab_symbol_info (regexp, kind, from_tty)
     char *regexp;
     namespace_enum kind;
     int from_tty;
{
  static char *classnames[]
  =
  {"variable", "function", "type", "method"};

[....]

  printf_filtered (regexp
		   ? "All %ss matching regular expression \"%s\":\n"
		   : "All defined %ss:\n",
		   classnames[(int) (kind - LABEL_NAMESPACE - 1)], regexp);
[....]


I wonder why LABEL_NAMESPACE was used at all.
Can you fix this above occurrence as well, so it is all consistent?

Thanks
Elena


David Taylor writes:
 > [Jim Blandy or Elena Zannoni -- I believe that this one needs your
 > approval.]
 > 
 > In search_symbols, we have the 4 variables
 > 
 >     types, types2, types3, type4
 > 
 > (each an array of 4 elements of type enum minimal_symbol_type),
 > initialized with the following values:
 > 
 >     variable index
 > 	     0             1                    2       3
 >     types    mst_data      mst_text             mst_abs mst_unknown
 >     types2   mst_bss       mst_file_text        mst_abs mst_unknown
 >     types3   mst_file_data mst_solib_trampoline mst_abs mst_unknown
 >     types4   mst_file_bss  mst_text             mst_abs mst_unknown
 > 
 > And then there are the 4 variables
 > 
 >     ourtype, ourtype2, ourtype3, ourtype4
 > 
 > initialized thusly:
 > 
 >     ourtype = types[(int) (kind - LABEL_NAMESPACE)];
 >     ourtype2 = types2[(int) (kind - LABEL_NAMESPACE)];
 >     ourtype3 = types3[(int) (kind - LABEL_NAMESPACE)];
 >     ourtype4 = types4[(int) (kind - LABEL_NAMESPACE)];
 > 
 > where kind is a variable of type namespace_enum and has one of the
 > four values:
 > 
 >     VARIABLES_NAMESPACE
 >     FUNCTIONS_NAMESPACE
 >     TYPES_NAMESPACE
 >     METHODS_NAMESPACE
 > 
 > (which immediately follow the enum value LABEL_NAMESPACE in the
 > definition of namespace_enum in symtab.h).
 > 
 > Thus, "kind - LABEL_NAMESPACE" has a value of 1, 2, 3, or 4 (not 0, 1,
 > 2, or 3).  Ooops.
 > 
 > Which can result in the code within the function that starts with:
 > 
 >   if (nfiles == 0 && (kind == VARIABLES_NAMESPACE || kind == FUNCTIONS_NAMESPACE))
 >     {
 >       ALL_MSYMBOLS (objfile, msymbol)
 >       {
 > 	if (MSYMBOL_TYPE (msymbol) == ourtype ||
 > 	    MSYMBOL_TYPE (msymbol) == ourtype2 ||
 > 	    MSYMBOL_TYPE (msymbol) == ourtype3 ||
 > 	    MSYMBOL_TYPE (msymbol) == ourtype4)
 > 	  {
 > 
 > selecting the wrong set of symbols.  I have executable where the off
 > by one error resulted in "info variables" showing all the functions
 > (and none of the variables!) and "info functions" showing some of the
 > variables (and none of the functions!).
 > 
 > The following patch fixes that:
 > 
 > 	* symtab.c (search_symbols): fix off by one error in index for
 > 	initializing variables ourtype, ourtype2, ourtype3, ourtype4.
 > 
 > Index: symtab.c
 > ===================================================================
 > RCS file: /cvs/src/src/gdb/symtab.c,v
 > retrieving revision 1.12
 > diff -c -r1.12 symtab.c
 > *** symtab.c	2000/08/11 01:02:35	1.12
 > --- symtab.c	2000/08/23 20:44:05
 > ***************
 > *** 3573,3582 ****
 >     if (kind < LABEL_NAMESPACE)
 >       error ("must search on specific namespace");
 >   
 > !   ourtype = types[(int) (kind - LABEL_NAMESPACE)];
 > !   ourtype2 = types2[(int) (kind - LABEL_NAMESPACE)];
 > !   ourtype3 = types3[(int) (kind - LABEL_NAMESPACE)];
 > !   ourtype4 = types4[(int) (kind - LABEL_NAMESPACE)];
 >   
 >     sr = *matches = NULL;
 >     tail = NULL;
 > --- 3573,3582 ----
 >     if (kind < LABEL_NAMESPACE)
 >       error ("must search on specific namespace");
 >   
 > !   ourtype = types[(int) (kind - VARIABLES_NAMESPACE)];
 > !   ourtype2 = types2[(int) (kind - VARIABLES_NAMESPACE)];
 > !   ourtype3 = types3[(int) (kind - VARIABLES_NAMESPACE)];
 > !   ourtype4 = types4[(int) (kind - VARIABLES_NAMESPACE)];
 >   
 >     sr = *matches = NULL;
 >     tail = NULL;
 > 
 > 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]