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

* [Bug fortran/26373] Printing members of parent type from an instance of an extended type
  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 ` antonio.mccarneiro at gmail dot com
  2022-04-08 14:22 ` nils-christian.kempke at intel dot com
  1 sibling, 0 replies; 3+ messages in thread
From: antonio.mccarneiro at gmail dot com @ 2020-08-11 11:29 UTC (permalink / raw)
  To: gdb-prs

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

amcc <antonio.mccarneiro at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |antonio.mccarneiro at gmail dot co
                   |                            |m

--- Comment #1 from amcc <antonio.mccarneiro at gmail dot com> ---
A similar bug has been issued here:
https://sourceware.org/bugzilla/show_bug.cgi?id=22497

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

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

* [Bug fortran/26373] Printing members of parent type from an instance of an extended type
  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
  1 sibling, 0 replies; 3+ messages in thread
From: nils-christian.kempke at intel dot com @ 2022-04-08 14:22 UTC (permalink / raw)
  To: gdb-prs

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

Kempke, Nils-Christian <nils-christian.kempke at intel dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nils-christian.kempke@intel
                   |                            |.com

--- Comment #2 from Kempke, Nils-Christian <nils-christian.kempke at intel dot com> ---
This is a duplicate of the already cited issue
https://sourceware.org/bugzilla/show_bug.cgi?id=22497

Similar to my comment there, also here the problem is that gfortran is not
emitting any inheritance information in its DWARF.

Using ifx/ifort and the latest gdb I can do the following:

=================================================================
Breakpoint 1, my_program () at ./f.f90:43
43      call child % increment
(gdb) p child%a
$1 = 1
(gdb) p child%b
$2 = 2
(gdb) p child%c
$3 = 3
(gdb) p child
$4 = ( test = ( a = 1, b = 2 ), c = 3 )
(gdb) p child%test
$5 = ( a = 1, b = 2 )
(gdb) p child%test%a
$6 = 1
(gdb) p child%test%b
$7 = 2
(gdb)
=================================================================

On GDB side this issue was fixed (as pointed out in the other issue). The
problem lies in gfortrans DWARF here.

With fortran and the missing DWARF inheritance info I can now do

=================================================================
Breakpoint 1, my_program () at ./f.f90:43
43      call child % increment
(gdb) p child
$1 = ( test = ( a = 1, b = 2 ), c = 3 )
(gdb) p child%test
$2 = ( a = 1, b = 2 )
(gdb) p child%test%a
$4 = 1
(gdb) p child%a
There is no member named a.
(gdb)
=================================================================

-- 
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).