Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Wei-min Pan <weimin.pan@oracle.com>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH v3 PR gdb/16841] virtual inheritance via typedef cannot find base
Date: Thu, 04 Oct 2018 23:51:00 -0000	[thread overview]
Message-ID: <53170edb-bed8-1c42-2d55-93ee622d0822@oracle.com> (raw)
In-Reply-To: <877eixicc1.fsf@tromey.com>

[-- Attachment #1: Type: text/plain, Size: 205 bytes --]

On 10/4/2018 3:19 PM, Tom Tromey wrote:
> multiple inheritance case

Thank you for the clarification. I have expanded both virtbase2.cc
and virtbase2.exp (attached) to test the multiple inheritance case.


[-- Attachment #2: virtbase2.cc --]
[-- Type: text/plain, Size: 1137 bytes --]

/* This testcase is part of GDB, the GNU debugger.

   Copyright 2018 Free Software Foundation, Inc.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

struct super {
  int w;
  super () : w(17) {}
};

struct superbase {
  int x;
  superbase () : x(22) {}
};

struct base : superbase {
  int i;
  double d;
  base() : i(55), d(6.25) {}
};

typedef base tbase;
struct derived: virtual super, virtual tbase
{
  void func_d() { }
};

struct foo: virtual derived
{
  void func_f() { }
};

int main()
{
  derived().func_d();
  foo().func_f();
}

[-- Attachment #3: virtbase2.exp --]
[-- Type: text/plain, Size: 3431 bytes --]

# Copyright 2018 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Make sure printing virtual base class data member works correctly (PR16841)

if { [skip_cplus_tests] } { continue }

standard_testfile .cc

if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
    return -1
}

if {![runto_main]} then {
    perror "couldn't run to main"
    continue
}

# From a list of nested scopes, generate all possible ways of accessing something
# in those scopes.  For example, with the argument {foo bar baz}, this proc will
# return:
#  - {} (empty string)
#  - baz::
#  - bar::
#  - bar::baz::
#  - foo::
#  - foo::baz::
#  - foo::bar::
#  - foo::bar::baz::

proc make_scope_list { scopes } {
    if { [llength $scopes] == 1 } {
        return [list "" "${scopes}::"]
    }

    # Pop the first element, save the first scope.
    set this_scope [lindex $scopes 0]
    set scopes [lreplace $scopes 0 0]

    set child_result [make_scope_list $scopes]

    # Add a copy of the child's result without this scope...
    set result $child_result

    # ... and a copy of the child's result with this scope.
    foreach r $child_result {
        lappend result "${this_scope}::$r"
    }

    return $result
}

proc test_variables_in_base { scopes } {
    foreach scope [make_scope_list $scopes] {
        gdb_test "print ${scope}i" " = 55"
        gdb_test "print ${scope}d" " = 6.25"
        gdb_test "print ${scope}x" " = 22"
    }
}

proc test_variables_in_superbase { scopes } {
    foreach scope [make_scope_list $scopes] {
        gdb_test "print ${scope}x" " = 22"
    }
}

proc test_variables_in_super { scopes } {
    foreach scope [make_scope_list $scopes] {
        gdb_test "print ${scope}w" " = 17"
    }
}

with_test_prefix "derived::func_d" {
    gdb_breakpoint "derived::func_d"
    gdb_continue_to_breakpoint "continue to derived::func_d"
    test_variables_in_base {derived base}
    test_variables_in_superbase {derived base superbase}
    test_variables_in_superbase {base superbase}
    test_variables_in_superbase {derived superbase}
    test_variables_in_superbase {superbase}
    test_variables_in_superbase {base}
    test_variables_in_super {super}
    test_variables_in_super {derived super}
}

with_test_prefix "foo::func_f" {
    gdb_breakpoint "foo::func_f"
    gdb_continue_to_breakpoint "continue to foo::func_f"
    test_variables_in_base {foo derived base}
    test_variables_in_base {foo base}
    test_variables_in_base {base}
    test_variables_in_superbase {superbase}
    test_variables_in_superbase {foo superbase}
    test_variables_in_superbase {foo derived superbase}
    test_variables_in_superbase {foo derived base superbase}
    test_variables_in_super {super}
    test_variables_in_super {foo super}
    test_variables_in_super {foo derived super}
}

  reply	other threads:[~2018-10-04 23:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-13  1:39 Weimin Pan
2018-09-14 18:26 ` Simon Marchi
2018-09-14 21:49   ` Weimin Pan
2018-09-18 11:59 ` Tom Tromey
2018-09-18 23:26   ` Weimin Pan
2018-10-04 22:20     ` Tom Tromey
2018-10-04 23:51       ` Wei-min Pan [this message]
2018-10-05 14:02         ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=53170edb-bed8-1c42-2d55-93ee622d0822@oracle.com \
    --to=weimin.pan@oracle.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox