This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH v13 3/4] Add support for lookup, overload resolution and invocation of C++ debug methods
- From: Doug Evans <dje at google dot com>
- To: Siva Chandra <sivachandra at google dot com>
- Cc: gdb-patches <gdb-patches at sourceware dot org>
- Date: Fri, 11 Apr 2014 17:10:19 -0700
- Subject: Re: [PATCH v13 3/4] Add support for lookup, overload resolution and invocation of C++ debug methods
- Authentication-results: sourceware.org; auth=none
- References: <CAGyQ6gzJ-yKvAuOY9guB3kS9LJ_HKAYAgMmo3y8RA26Zf1f3aQ at mail dot gmail dot com>
On Wed, Apr 9, 2014 at 11:56 AM, Siva Chandra <sivachandra@google.com> wrote:
> This version addresses all of Doug's comments on v12.
>
> v12 posting: https://sourceware.org/ml/gdb-patches/2014-04/msg00014.html
> Doug's review: https://sourceware.org/ml/gdb-patches/2014-04/msg00107.html
>
> Doug had this comment:
>
> Doug> The following code to handle dynamic types seems excessively
> Doug> complex. Plus we do a lot of work only to throw it away and start
> Doug> over (by calling find_overload_match on the dynamic type).
> Doug> Maybe instead of starting over, just look for the debug method on the
> Doug> dynamic type and use that if it exists? Thoughts?
>
> I agree that calling find_overload_match again will do repetitive
> work. But, lets say the dynamic type does have a matching debug method
> worker. In which case, it has to be compared with the matching virtual
> function. find_overload_match does this comparison for us. If we do
> not want to call find_overload_match again, then we will have to 1)
> pull out the debug method specific parts of find_overload_match and
> its helpers and make them separate functions, 2) pull out that part of
> find_overload_match which compares source methods and debug methods to
> decide who wins and make it a separate function. I took the easier
> route of calling find_overload_match again. I am not sure if splitting
> find_overload_match would reduce the complexity of this part of the
> code. Also, find_overload_match will only be called once more: not too
> bad may be?
Yeah, I'm not sure the extra work is worth it.
One worry I have is that starting the search over with the dynamic
type could get the "wrong" answer.
["wrong" is in quotes because I can imagine differing opinions]
What if we have:
class base
{
public:
virtual int foo (char x) { return x + 1; }
};
class derived : public base
{
public:
int foo (char x) { return x + 2; }
int foo (int x) { return x + 3; }
};
base* ptr = new derived;
and suppose we have a debug method for derived::foo (int) and none for
base::foo(char) or derived::foo(char).
If I do "p ptr->foo (3)" in gdb, which method (c++ or debug) should be invoked?
I don't have a strong opinion on what the right answer is, at least
not yet, but then I'm not a c++ language lawyer and am not sure
whether there's an even better example.