This is GCC Bugzilla
This is GCC Bugzilla Version 2.20+
View Bug Activity | Format For Printing | Clone This Bug
In section 4.2 of DWARF STD, it says that: A Fortran common block may be described by a debugging information entry with the tag DW_TAG_common_block. But it seems that both gfortran and g77 didn't conform to this. This makes trouble for debugging common block. Here is a testcase to verify this: 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 group1 is a named common block. After using gfortran to build this case, I use "readelf -wi" to get the debuginfo of the executable: <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> =====> This point to the type of group1 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) It tells us that group1 is treated as a two-members structure. g77 handles this in another way, it treats group1 as an eight-character array. And eight is exactly the size of common block group1. Here is the debuginfo for g77-generated executable: <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> =====> This point to the type of group1 DW_AT_external : 1 DW_AT_location : 5 byte block: 3 a0 99 4 8 (DW_OP_addr: 80499a0) P.S: I reported this problem some days before. But there is no response ever since. Here is the link: http://gcc.gnu.org/ml/fortran/2005-07/msg00310.html Thanks.
Confiremd, since the standard says "may", this is an enhancement.
Andrew, Do you think you might be interested in tackling the implementation of the DW_TAG_common_block tag if we could get HJ Lu and/or Jakub Jelinek to provide technical assistance? Having the ability to debug COMMON blocks in gfortran would be quite helpful for programs like xplor-nih that heavily use them. Jack
(In reply to comment #2) Jack, Actually on ppc-darwin, GCC still uses stabs so I doubt this is the bug you are hitting.
Some more COMMON problems here: http://gcc.gnu.org/ml/gcc-patches/2007-10/msg01685.html
I submitted a patch that causes debug info for identifiers in COMMON to be emitted with DW_TAG_common_block. See http://gcc.gnu.org/ml/gcc-patches/2007-11/msg00311.html
Fixed in rev 133800, 1 April 2008
Subject: Bug 23057 Author: jakub Date: Fri Aug 29 18:41:19 2008 New Revision: 139773 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=139773 Log: PR fortran/29635 PR fortran/23057 * debug.h (struct gcc_debug_hooks): Add NAME and CHILD arguments to imported_module_or_decl. (debug_nothing_tree_tree): Removed. (debug_nothing_tree_tree_tree_bool): New prototype. * debug.c (do_nothing_debug_hooks): Adjust. (debug_nothing_tree_tree): Removed. (debug_nothing_tree_tree_tree_bool): New function. * dwarf2out.c (is_symbol_die): Handle DW_TAG_module. (gen_variable_die): Put all common vars for the same COMMON block under one DW_TAG_common_block. (declare_in_namespace): Return new context_die, for Fortran return the module DIE instead of adding extra declarations into the namespace. (gen_type_die_with_usage): Adjust declare_in_namespace caller. (gen_namespace_die): If is_fortran (), generate DW_TAG_module instead of DW_TAG_namespace. If DECL_EXTERNAL is set, add DW_AT_declaration. (dwarf2out_global_decl): Don't skip Fortran global vars. (gen_decl_die): Likewise. Adjust declare_in_namespace callers. (dwarf2out_imported_module_or_decl): Add NAME and CHILD arguments. If NAME is non-NULL, add DW_AT_name. If CHILD is non-NULL, put DW_TAG_imported_declaration as child of previous DW_TAG_imported_module. * dbxout.c (dbx_debug_hooks, xcoff_debug_hooks): Adjust. * sdbout.c (sdb_debug_hooks): Likewise. * vmsdbgout.c (vmsdbg_debug_hooks): Likewise. * name-lookup.c (do_using_directive, cp_emit_debug_info_for_using): Adjust debug_hooks->imported_module_or_decl callers. * f95-lang.c (gfc_init_ts): New function. (LANG_HOOKS_INIT_TS): Define. * gfortran.h (gfc_use_rename): New type, moved from module.c. (gfc_get_use_rename): New macro, moved from module.c. (gfc_use_list): New type. (gfc_get_use_list): New macro. (gfc_namespace): Add use_stmts field. (gfc_free_use_stmts): New prototype. * Make-lang.in (fortran/trans-decl.o): Depend on debug.h. * module.c (gfc_use_rename, gfc_get_use_rename): Moved to gfortran.h. (gfc_use_module): Chain the USE statement info to ns->use_stmts. (gfc_free_use_stmts): New function. * symbol.c (gfc_free_namespace): Call gfc_free_use_stmts. * trans.h (struct module_htab_entry): New type. (gfc_find_module, gfc_module_add_decl): New functions. * trans.c (gfc_generate_module_code): Create NAMESPACE_DECL for the module, adjust DECL_CONTEXTs of module procedures and call gfc_module_add_decl for them. * trans-common.c (build_common_decl): Set DECL_IGNORED_P on the common variable. (create_common): Set DECL_IGNORED_P for use associated vars. * trans-decl.c: Include debug.h. (gfc_get_symbol_decl): Set DECL_IGNORED_P on use_assoc vars from modules. (build_function_decl): Allow current_function_decl's context to be a NAMESPACE_DECL. (module_htab, cur_module): New variables. (module_htab_do_hash, module_htab_eq, module_htab_decls_hash, module_htab_decls_eq, gfc_find_module, gfc_module_add_decl): New functions. (gfc_create_module_variable): Adjust DECL_CONTEXTs of module variables and types and call gfc_module_add_decl for them. (gfc_generate_module_vars): Temporarily set cur_module. (gfc_trans_use_stmts): New function. (gfc_generate_function_code): Call it. (gfc_generate_block_data): Set DECL_IGNORED_P on decl. * trans-types.c (gfc_get_derived_type): Adjust DECL_CONTEXT and TYPE_CONTEXT of module derived types. Modified: trunk/gcc/ChangeLog trunk/gcc/cp/ChangeLog trunk/gcc/cp/name-lookup.c trunk/gcc/dbxout.c trunk/gcc/debug.c trunk/gcc/debug.h trunk/gcc/dwarf2out.c trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/Make-lang.in trunk/gcc/fortran/f95-lang.c trunk/gcc/fortran/gfortran.h trunk/gcc/fortran/module.c trunk/gcc/fortran/symbol.c trunk/gcc/fortran/trans-common.c trunk/gcc/fortran/trans-decl.c trunk/gcc/fortran/trans-types.c trunk/gcc/fortran/trans.c trunk/gcc/fortran/trans.h trunk/gcc/sdbout.c trunk/gcc/vmsdbgout.c
Subject: Bug 23057 Author: jakub Date: Fri Aug 29 18:45:25 2008 New Revision: 139775 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=139775 Log: PR fortran/23057 * dwarf2out.c (gen_variable_die): Represent Fortran COMMON vars as DW_TAG_variable children of DW_TAG_common_block rather than DW_TAG_member children. Put DW_AT_external to individual DW_TAG_variable DIEs, not to DW_TAG_common_block. * gfortran.dg/debug/pr35154-dwarf2.f: Adjust for replacement of DW_TAG_member with DW_TAG_variable. Modified: trunk/gcc/ChangeLog trunk/gcc/dwarf2out.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gfortran.dg/debug/pr35154-dwarf2.f