public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/26373] New: Printing members of parent type from an instance of an extended type
@ 2020-08-11 11:27 antonio.mccarneiro at gmail dot com
  2020-08-11 11:29 ` [Bug fortran/26373] " antonio.mccarneiro at gmail dot com
  2022-04-08 14:22 ` nils-christian.kempke at intel dot com
  0 siblings, 2 replies; 3+ messages in thread
From: antonio.mccarneiro at gmail dot com @ 2020-08-11 11:27 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26373

            Bug ID: 26373
           Summary: Printing members of parent type from an instance of an
                    extended type
           Product: gdb
           Version: 9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: fortran
          Assignee: unassigned at sourceware dot org
          Reporter: antonio.mccarneiro at gmail dot com
  Target Milestone: ---

* Scenario (see the code below): consider some Fortran module my_module which
contains the definition of two derived types: test (parent) and sub_test
(extends test, subclass). In addition to the two members a and b of the parent
class, sub_test defines a new member c. Eventually, this module my_module is to
used in some program my_program.
================================================================================
module my_module

implicit none

private
public :: test, sub_test

type :: test
  integer :: a = 1
  integer :: b = 2
end type test

type, extends(test) :: sub_test
  integer :: c = 3
contains
  procedure, public :: increment
end type sub_test

contains

subroutine increment (this)
class(sub_test) :: this
this % a = this % a + 1
write(*, *) "Incrementation complete!"
end subroutine increment

end module my_module
!---------------------------------------
program my_program

use my_module

implicit none

type(test)  :: parent
type(sub_test) :: child

write(*, *) "Printing parent members"
write(*, *) parent % a, parent % b
write(*, *) "Printing child members"
write(*, *) child % a, child % b, child % c

call child % increment

end program my_program
================================================================================
* Objective: When debugging, using gdb, we want to print the values of the
parent members a and b of some variable of the child (extended) type sub_test.
In sum, we're looking for a successful completion of something like:
----------------------
(gdb) print child % a
----------------------
yet, apparently, it is not that trivial.
What I have (unsuccessfully) tried so far:

    1. Print directly the members from the child variable (member c prints
flawlessly)
------------------------------------------------
Breakpoint 1, my_program () at test.f90:41
41  write(*, *) child % a, child % b, child % c
(gdb) p child%a
There is no member named a.
(gdb) p child%b
There is no member named b.
(gdb) p child%c
$1 = 3
------------------------------------------------
    2. Print the test (parent) member of the child variable, as gdb shows it
exists
    3. Print the so-wanted members from the test member of child
------------------------------------------------
Breakpoint 1, my_program () at test.f90:41
41  write(*, *) child % a, child % b, child % c
(gdb) p child
$2 = ( test = ( a = 1, b = 2 ), c = 3 )
(gdb) p child%test
A syntax error in expression, near `test'.
(gdb) p child%test%a
A syntax error in expression, near `test%a'.
(gdb) p child%test%b
A syntax error in expression, near `test%b'.
------------------------------------------------

More information: I am using gdb-9.2 and gfortran 7.5.0.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-04-08 14:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-11 11:27 [Bug fortran/26373] New: Printing members of parent type from an instance of an extended type antonio.mccarneiro at gmail dot com
2020-08-11 11:29 ` [Bug fortran/26373] " antonio.mccarneiro at gmail dot com
2022-04-08 14:22 ` nils-christian.kempke at intel dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).