gdb / gfortran在7.2 / 4.7之后破解 [英] gdb/gfortran broken after 7.2/4.7
问题描述
我有三台机器,两台运行Linux,一台运行OS X Yosemite,具有不同版本的 gfortran
和 gdb
。 gdb
(在7.2之后)和 gfortran
(4.7之后)似乎无法检查可分配变量。
我的问题是:this is an预期的行为,还是有补丁保持 gfortran
, gdb
像旧版本一样工作?
这是我测试的一个小版本代码:
$ b
整数:: x(2,3)
整数,可分配:: y(:,:)
分配(y(2,3))
x = reshape([1,2,3,4,5,6],[2,3],order = [2,1])$ b $ by = reshape([1,2,3,4,5,6] ,[2,3],order = [2,1])$ b
$ b print *,'x',转置(x)
print *,'y',转置(y)
end
结果来自三台机器
它在Fedora 17上的4.7中运行良好(不再维护)
[qlle @(none) 〜] $ gdb --version | head -n1
GNU gdb(GDB)Fedora(7.4.50.20120120-54.fc17)
[qlle @(none)〜] $ gfortran --version | head -n1
GNU Fortran(GCC)4.7.2 20120921(Red Hat 4.7.2-2)
(gdb)i lo
x =((1,4)( 2,5)(3,6))
y =((1,4)(2,5)(3,6))
(gdb)py(:2)
$ 1 =(2,5)
(gdb)py(2,:)
$ 2 =(4,5,6)
(gdb)显示语言
当前源语言是汽车;目前fortran。
然而,最新版本通过 homebrew
开启Mac机器,我得到不完整类型
。
〜/ Downloads gdb --version | head -n 1
GNU gdb(GDB)7.8.1
〜/ Downloads gfortran --version | head -n1
GNU Fortran(Homebrew gcc 4.9.2_1)4.9.2
〜/Downloads❯gdb a.out
...
(gdb)break
断点1在0x100000b41:文件alloc.f90,第9行。
run
...
(gdb)info locals
x =((1,4) (2,5)(3,6))
y =<不完整类型>
更糟糕的是,在4.8(Ubuntu 14.04)的其他Linux机器上,它似乎指向不正确部分(堆栈而不是堆):
link @ hyrule:〜$ gdb --version | head -n1
GNU gdb(Ubuntu 7.7.1-0ubuntu5〜14.04.2)7.7.1
link @ hyrule:〜$ gfortran --version | head -n1
GNU Fortran(Ubuntu 4.8.2-19ubuntu1)4.8.2
(gdb)i lo
x =((1,4)(2,5)(3,6) )
y =((0))
(gdb)p& y
$ 1 =(PTR TO - >(integer(kind = 4)(*,*)))0x7fffffffe4f0 $ (整数(种类= 4)(2,3)))0x7fffffffe540
(gdb)p *((整数* )y)@ 6
$ 6 =(1,4,2,5,3,6)
我认为最好回答这个问题。实际上Fedora上的 gdb
带有一个补丁集 http ://pkgs.fedoraproject.org/cgit/gdb.git/ ,它可以为Fortran代码调试可分配数组。
为了使可分配数组工作在其他平台上,我们需要从特定的分支重建 gdb
,比如来自Archer的archer-jankratochvil-vla gdb https://sourceware.org/gdb/wiki/ProjectArcher 。
虽然不需要修补gfortran。
I have three machine, two run Linux and one run OS X Yosemite with different version of gfortran
and gdb
. gdb
on my old box work well with allocated arrays, however, newer version of gdb
(after 7.2) and gfortran
(after 4.7) do not seem to be able to examine the allocatable variables.
My question is: is this an expected behavior or is there a patch to keep gfortran
, gdb
work like the older version?
This is a small version of code I tested:
integer :: x(2,3)
integer, allocatable :: y(:,:)
allocate(y(2,3))
x = reshape([1,2,3,4,5,6], [2,3], order=[2,1])
y = reshape([1,2,3,4,5,6], [2,3], order=[2,1])
print *, 'x', transpose(x)
print *, 'y', transpose(y)
end
And results from three machine
It works well on 4.7 on Fedora 17 (no longer maintained)
[qlle@(none) ~]$ gdb --version | head -n1
GNU gdb (GDB) Fedora (7.4.50.20120120-54.fc17)
[qlle@(none) ~]$ gfortran --version | head -n1
GNU Fortran (GCC) 4.7.2 20120921 (Red Hat 4.7.2-2)
(gdb) i lo
x = (( 1, 4) ( 2, 5) ( 3, 6) )
y = (( 1, 4) ( 2, 5) ( 3, 6) )
(gdb) p y(:,2)
$1 = (2, 5)
(gdb) p y(2,:)
$2 = (4, 5, 6)
(gdb) show language
The current source language is "auto; currently fortran".
However, with latest version through homebrew
on Mac machine, I got incomplete type
instead.
~/Downloads❯ gdb --version | head -n 1
GNU gdb (GDB) 7.8.1
~/Downloads❯ gfortran --version | head -n1
GNU Fortran (Homebrew gcc 4.9.2_1) 4.9.2
~/Downloads❯ gdb a.out
...
(gdb) break 9
Breakpoint 1 at 0x100000b41: file alloc.f90, line 9.
run
...
(gdb) info locals
x = (( 1, 4) ( 2, 5) ( 3, 6) )
y = <incomplete type>
And even worse, on other Linux box with 4.8 (Ubuntu 14.04), it seems to point to incorrect section (stack instead of heap):
link@hyrule:~$ gdb --version | head -n1
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
link@hyrule:~$ gfortran --version | head -n1
GNU Fortran (Ubuntu 4.8.2-19ubuntu1) 4.8.2
(gdb) i lo
x = (( 1, 4) ( 2, 5) ( 3, 6) )
y = (( 0) )
(gdb) p &y
$1 = (PTR TO -> ( integer(kind=4) (*,*))) 0x7fffffffe4f0
(gdb) p &x
$2 = (PTR TO -> ( integer(kind=4) (2,3))) 0x7fffffffe540
(gdb) p *((integer *) y)@6
$6 = (1, 4, 2, 5, 3, 6)
I think it's better to answer the question. Actually gdb
on Fedora come with a patchset http://pkgs.fedoraproject.org/cgit/gdb.git/ that enable debugging allocatable arrays for Fortran code.
In order to get allocatable arrays working on other platform, we need to rebuild gdb
from a specific branch like archer-jankratochvil-vla from Archer gdb https://sourceware.org/gdb/wiki/ProjectArcher.
No need to patch gfortran though.
这篇关于gdb / gfortran在7.2 / 4.7之后破解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!