[rfa] search for fields of this correctly, PR gdb/804

David Carlton carlton@math.stanford.edu
Thu Dec 5 12:23:00 GMT 2002


On Wed, 4 Dec 2002 22:20:37 -0500, Elena Zannoni <ezannoni@redhat.com> said:
> David Carlton writes:

>> In lookup_symbol_aux, the 'field_of_this' search happens at the
>> wrong time: it happens after all of the superblocks of 'block' have
>> been searched, whereas fields of this should shadow file-level
>> static and global variables.

> I see, the search stops as soon as you find something, so doing it
> in that order would find the 'outer' first.

Right.

>> * Pull out the code from lookup_symbol_aux_local that sets 'symtab'
>> correctly and that does the fixup_symbol stuff into a new function,
>> lookup_symbol_aux_block.

> Since this bit is just moving code around, would you mind it
> checking it in first, by itself? Then check in the rest.

Sure, that's fine.

>> * In lookup_symbol_aux, after doing the field_of_this stuff, call
>> lookup_symbol_aux_block to search in the static block.
>> 
>> I waffled a bit as to whether or not we should preserve the current
>> behavior of searching the current file's global block before searching
>> all of the global blocks; I decided that doing so was redundant and a
>> bit messy, so I omitted that but left in a comment mentioning the
>> issue.

> The only thing I wonder is if there's going to be a performance
> penalty for this. Can you mention in the comment that there was old
> code that was looking for symbols in the current file's global
> block?

Absolutely.  Yeah, I thought about the performance penalty issues,
too: searching the current file's global block first is a win if the
symbol you're looking for is in that file, and it's a loss if the
symbol isn't in that file.  The former case seems likely to be common,
but not so common as to be a clear win.  But I don't think that
optimizing this issue is important at this stage: there are other
performance issues with lookup_symbol that are much more important
than this one.  (E.g. the fact that a failed lookup ends up searching
through every psymtab twice (once for globals and once for statics).)
Still, I should add a comment addressing the issue.

> It would be really nice if that 'goto' would disappear....hint,
> hint.

:-) I dislike gotos as much as the next person, but actually this one
isn't so bad: it's just being used to break out of the ALL_SYMTABS
loop, which expands to a pair of nested loops so a simple break won't
work.  So, while it wouldn't be hard to get rid of it, I don't think
it's necessary here.

Okay, then I'll commit this in three stages: first, I'll commit a
patch that just creates the lookup_symbol_aux_block function, and then
I'll commit a patch that moves the field_of_this check to the correct
spot.  Those two together will give exactly the symtab.c patch that I
posted, except that I'll expand on the comment.  Then, next week, when
I'm a C++ testsuite co-maintainer, I'll commit the testsuite stuff
(unless somebody else complains about it for some reason).

David Carlton
carlton@math.stanford.edu



More information about the Gdb-patches mailing list