This is the mail archive of the
gdb@sources.redhat.com
mailing list for the GDB project.
[GDB & Fortran]: common block's DWARF representation and "infocommon" output
- From: Wu Zhou <woodzltc at cn dot ibm dot com>
- To: gdb at sources dot redhat dot com, fortran at gcc dot gnu dot org
- Date: Wed, 20 Jul 2005 17:39:38 +0800 (CST)
- Subject: [GDB & Fortran]: common block's DWARF representation and "infocommon" output
Hello all,
I am investigating how GDB work with Fortran and found an odd question:
GDB's "info common" command won't work with either G77 (I tested with
3.3.3 and 3.4.3) or Gfortran (I tested with gfortran-4.0).
In section 12.4.3 of GDB manual, it says that
info common [common-name]
This command prints the values contained in the Fortran COMMON block
whose name is common-name. With no argument, the names of all COMMON
blocks visible at current program location are printed.
So I use a short fortran program (source code is attached below)to verify
whether it works or not. I found: whenever I issue "info common" command,
it always reports empty like this:
(gdb) info common
All COMMON blocks visible at this level:
(gdb)
source code of common.f:
===========================
program info_common
implicit none
integer :: a,b
common /group1/ a,b
a=1
b=2
call ShowCommon()
stop
end
subroutine ShowCommon()
implicit none
integer :: num1, num2
common /group1/ num1, num2
write(*,*) num1, num2
return
end
Did anybody ever have success experience with this? Maybe this works well
with an ancient g77, such as 2.95?
I try using "readelf -wi common" to see the DWARF information the
compilers generated. It seems that g77 treats common block group1 as an
8-bytes string and gfortran treats it as a two-members structure. Neither
conform to DWARF standard, which use DW_TAG_common_block to represent a
common block. So the error might due to the fact g77 and gfortran generate
error debuginfo for common block. Any objection on this?
Maybe I can open a PR for this. Please comment. Thanks in advance!
P.S: I attach the debuginfo the compilers generated and the relative
section of DWARF standards below for your reference.
The DWARF information generated by g77:
=======================================
<1><12b>: Abbrev Number: 6 (DW_TAG_base_type)
DW_AT_name : (indirect string, offset: 0x3b): char
DW_AT_byte_size : 1
DW_AT_encoding : 8 (unsigned char)
<1><132>: Abbrev Number: 15 (DW_TAG_array_type)
DW_AT_sibling : <143>
DW_AT_type : <12b>
<2><13b>: Abbrev Number: 16 (DW_TAG_subrange_type)
DW_AT_type : <70>
DW_AT_lower_bound : 0
DW_AT_upper_bound : 7
<1><143>: Abbrev Number: 17 (DW_TAG_variable)
DW_AT_name : (indirect string, offset: 0xbb): group1_
DW_AT_decl_file : 1
DW_AT_decl_line : 3
DW_AT_type : <132>
DW_AT_external : 1
DW_AT_location : 5 byte block: 3 a0 99 4 8 (DW_OP_addr: 80499a0)
The DWARF information generated by gfortran:
=============================================
<2><9e>: Abbrev Number: 3 (DW_TAG_variable)
DW_AT_name : group1
DW_AT_decl_file : 1
DW_AT_decl_line : 4
DW_AT_MIPS_linkage_name: group1_
DW_AT_type : <e1>
DW_AT_external : 1
DW_AT_location : 5 byte block: 3 d0 99 4 8 (DW_OP_addr: 80499d0)
<1><e1>: Abbrev Number: 5 (DW_TAG_structure_type)
DW_AT_sibling : <100>
DW_AT_byte_size : 8
<2><e7>: Abbrev Number: 6 (DW_TAG_member)
DW_AT_name : a
DW_AT_decl_file : 1
DW_AT_decl_line : 3
DW_AT_type : <100>
DW_AT_data_member_location: 2 byte block: 23 0 (DW_OP_plus_uconst: 0)
<2><f3>: Abbrev Number: 6 (DW_TAG_member)
DW_AT_name : b
DW_AT_decl_file : 1
DW_AT_decl_line : 3
DW_AT_type : <100>
DW_AT_data_member_location: 2 byte block: 23 4 (DW_OP_plus_uconst: 4)
What DWARF standard said about common block:
=============================================
A Fortran common block may be described by a debugging information entry
with the tag DW_TAG_common_block. The common block entry has a DW_AT_name
attribute whose value is a null-terminated string containing the common
block name as it appears in the source program. It also has a
DW_AT_location attribute whose value describes the location of the
beginning of the common block. The common block entry owns debugging
information entries describing the variables contained within the common
block.
Regards
- Wu Zhou