Calling functions of derived types from gdb


I want to call a function that takes as an argument a derived type from within the Gnu Debugger (gdb).

Say I have this code:

module modSimpleClass
    type Person
        character(len=20) :: Name
            procedure PrintName
    end type
        subroutine PrintName(a)
            class(Person) :: a
            print *, a%Name
        end subroutine
        subroutine Print42()
            print *, "42"
        end subroutine
        subroutine Outsider(a)
            class(Person) :: a
            print *, a%Name
        end subroutine
end module
program testgdb
    use modSimpleClass
    implicit none
    type(Person) :: JoeJohnson

    JoeJohnson%Name = "Joe Johnson"
    call JoeJohnson%PrintName
end program testgdb

I run it from gdb and stop it before its end.
The following things work:

call Print42()
print JoeJohnson%Name

The following things don’t work:

call JoeJohnson%PrintName()!There is no member named PrintName.
call PrintName(JoeJohnson)!Error then segfault
call Outsider(JoeJohnson)!Error then segfault

The error is as follows:

The program being debugged was signaled while in a function called from GDB.
GDB remains in the frame where the signal was received.
To change this behavior use “set unwindonsignal on”.
Evaluation of the expression containing the function
(modsimpleclass::printname) will be abandoned.
When the function is done executing, GDB will silently stop.

Thank you in advance

1 Like

@hohoho yes I was able to replicate the issue in my computer but I can’t say if this is a bug or not, I noticed that there are known issues with Fortran derived types in GDB:

1 Like