我注意到gdb指向未实际执行的行的步骤:怪异的步骤导致某些(不是全部)else
块中未执行的最后一条语句以及未执行的{{ 1}}块。我将这些行标记为“未触发”,因为未按预期执行(请参见下面的gdb日志)。
我还注意到,它以可分配数组的声明为基础,而不是其他变量的声明,并且不遵循行号顺序(尽管此示例只有1个可分配变量)。
一个最小的工作示例如下:
(main.f90)
case default
我使用-g和-O0如下编译它
PROGRAM main
implicit none
! two variables, we will test i and modify j
integer i
integer j
! i is 1
i=1
! j is zero for default
j=0
! let the tests begin
if ((i .ne. 2) .and. (i .ne. 3)) then
j=1 ! if #1a triggered
if (i .eq. 1) then
j=1 ! if #1a1a triggered
else !i .ne. 1
j=2 ! if #1a1b not triggered
endif
else !i .eq. 2 .or. i .eq. 3 .or. isnan(i)
j=3 !if #1b not triggered
endif
select case(i)
case(1)
j=1 !case #1 triggered
case default !i .ne. 1
j=4 !case #2 not triggered
end select
call sub1()
contains
subroutine sub1()
!lets also see an issue with allocatables
integer, allocatable, dimension(:) :: k !why does gdb step in this line?
allocate(k(9))
end subroutine
end program
我有以下gfortran版本
gfortran -g -O0 -ffree-line-length-none -Jobj -c -o run/main.o src/main.f90
gfortran -g -O0 -ffree-line-length-none -Jobj -o run/main.elf obj/main.o
这是gdb(不包括版本)中步骤的输出
GNU Fortran (Ubuntu 7.3.0-16ubuntu3) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
我将此测试代码上传到https://github.com/iurisegtovich/gdb_gfortran
现在,我只是在使用g95编译的同一程序上测试了步骤,输出对我来说更有意义。我仍然想知道gfortran的行为是错误还是“就是这样”。
建立配方:
GNU gdb (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-git
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from run/main.elf...done.
(gdb) start
Temporary breakpoint 1 at 0x942: file ./src/main.f90, line 1.
Starting program: /home/atoms/Desktop/testa-gdb/run/main.elf
Temporary breakpoint 1, MAIN__ () at ./src/main.f90:1
1 PROGRAM main
(gdb) n
8 i=1
(gdb) n
10 j=0
(gdb) n
13 if ((i .ne. 2) .and. (i .ne. 3)) then
(gdb) n
14 j=1 ! if #1a triggered
(gdb) n
15 if (i .eq. 1) then
(gdb) n
16 j=1 ! if #1a1a triggered
(gdb) n
18 j=2 ! if #1a1b not triggered
(gdb) n
30 j=4 !case #2 not triggered
(gdb) n
28 j=1 !case #1 triggered
(gdb) n
33 call sub1()
(gdb) s
sub1 () at ./src/main.f90:39
39 integer, allocatable, dimension(:) :: k !why does gdb step in this line?
(gdb) n
40 allocate(k(9))
(gdb) n
41 end subroutine
(gdb) n
__libc_start_main (main=0x5555555549b0 <main>, argc=1, argv=0x7fffffffe048,
init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>,
stack_end=0x7fffffffe038) at ../csu/libc-start.c:344
(gdb) n
[Inferior 1 (process 27842) exited normally]
(gdb) q
版本信息:
x86_64-unknown-linux-gnu-g95 -g -O0 ~/Desktop/testa-gdb/src/main.f90
gdb日志:
x86_64-unknown-linux-gnu-g95 --version
G95 (GCC 4.0.3 (g95 0.94!) Jan 17 2013)
Copyright (C) 2002-2008 Free Software Foundation, Inc.
G95 comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of G95
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING