Ant*_*iro 5 linux debugging fortran gdb gfortran
场景(见下面的代码):考虑一些 Fortran 模块my_module,它包含两个派生类型的定义:test(parent) 和sub_test(extends test, subclass)。除了两个构件a和b父类的,sub_test定义了一个新成员c。最终,该模块my_module将用于某些程序中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
Run Code Online (Sandbox Code Playgroud)
目标:在调试时,使用gdb,我们要打印父成员a和b子(扩展)类型的某些变量的值sub_test。总而言之,我们正在寻找诸如以下内容的成功完成:
(gdb) print child % a
Run Code Online (Sandbox Code Playgroud)
然而,显然,这并不是那么简单。
尝试打印前的设置:
test.f90用-gflag编译程序(这里称为),方便gdbwith的应用gfortran -g test.f90 -o a.out
运行可执行文件 gdb ./a.out
write(*, *)在程序的最后一条语句和write(*, *)子程序的唯一语句中插入断点increment并运行程序
(gdb) break test.f90:41
Breakpoint 1 at 0xb12: file test.f90, line 41.
(gdb) break test.f90:24
Breakpoint 2 at 0x955: file test.f90, line 24.
(gdb) run
Run Code Online (Sandbox Code Playgroud)
到目前为止我所尝试的(未成功):
child变量中的成员(成员c打印完美无缺)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
Run Code Online (Sandbox Code Playgroud)
test(父)成员child,gdb显示它存在test成员中打印如此想要的成员childBreakpoint 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'.
Run Code Online (Sandbox Code Playgroud)
this。在这种情况下,gdb显然改变了关于可变螺距和,例如,c只能通过隐藏的成员进行访问_dat,但a并b继续不可达。Breakpoint 2, my_module::increment (this=...) at test.f90:24
24 write(*, *) "Incrementation complete!"
(gdb) p this
$3 = ( _data = 0x555555756018 <child>, _vptr = 0x555555755d20 <__my_module_MOD___vtab_my_module_Sub_test> )
(gdb) p this%_data
$4 = (PTR TO -> ( Type sub_test )) 0x555555756018 <child>
(gdb) p this%_data%a
There is no member named a.
(gdb) p this%_data%b
There is no member named b.
(gdb) p this%_data%c
$5 = 3
(gdb) p this%_data%test%a
A syntax error in expression, near `test%a'.
(gdb) p this%_data%test%b
A syntax error in expression, near `test%b'.
Run Code Online (Sandbox Code Playgroud)
感谢您的阅读:这方面我感觉自己走到了尽头,非常希望有人能帮我一把。gdb似乎令人难以置信,但是,由于无法检查这些信息,我很遗憾地担心它不能正确满足我的需求。
更多信息:我正在使用gdb-9.2和gfortran 7.5.0。
| 归档时间: |
|
| 查看次数: |
120 次 |
| 最近记录: |