This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] PR symtab/13277: Resolving opaque structures in ICC generated binaries.


[ Cc to gdb-patches has been lost.  ]
On Fri, 18 May 2012 16:46:42 +0200, Jan Kratochvil wrote:
Hi John,

On Mon, 14 May 2012 15:51:20 +0200, John Steele Scott wrote:
> Are the existing tests already known to work with ICC?

I do not remember trying it.  I assume many tests will FAIL.  But we do not
want to diff gcc results vs. icc results but only icc results before the patch
vs. icc results after the patch.


> I have added a check for "Intel(R) C Compiler XE" which is what the 32-bit
> version emits. If you know the Fortran producer string I can add that, or if
> you really prefer we can just scan for "Intel(R)" like you said before.

OK, I am fine with that 32-bit C compiler DW_AT_producer.

Also check for C++ DW_AT_producer - C++ has the same problem for stub structs;
just for the real definition of 'struct {} var' type C++ has DW_AT_byte_size==1.

FYI I was unable to create stub struct with ifort.


> I can merge this die_is_incomplete_type logic into
> die_is_declaration, but then it means there is no way to distinguish between
> a "declaration", and an "incomplete type". It seems okay (dwarf2 tests pass
> at least), as long as there no obscure corner of dwarf where this
> distinction matters to us.

With my icc test there is difference between the types for v and w:
	struct s;
	extern struct s v;
	struct w {} w;

DW_AT_producer    : Intel(R) C Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 12.1.4.319 Build 20120410 Fixes SameLinkageName MemberPointers

 <1><ed>: Abbrev Number: 4 (DW_TAG_variable)
    <f2>   DW_AT_name        : v
    <f4>   DW_AT_type        : <0xfa>
[shortened]
 <1><fa>: Abbrev Number: 5 (DW_TAG_structure_type)
    <fb>   DW_AT_decl_line   : 1
    <fc>   DW_AT_decl_column : 8
    <fd>   DW_AT_decl_file   : 1
    <fe>   DW_AT_accessibility: 1       (public)
    <ff>   DW_AT_byte_size   : 0
    <100>   DW_AT_name        : s
 <1><102>: Abbrev Number: 6 (DW_TAG_variable)
    <107>   DW_AT_name        : w
    <109>   DW_AT_type        : <0x118>
[shortened]
 <1><118>: Abbrev Number: 5 (DW_TAG_structure_type)
    <119>   DW_AT_decl_line   : 4
    <11a>   DW_AT_decl_column : 8
    <11b>   DW_AT_decl_file   : 1
    <11c>   DW_AT_accessibility: 1      (public)
    <11d>   DW_AT_byte_size   : 0
    <11e>   DW_AT_name        : w

This means icc does must not use TYPE_STUB_SUPPORTED.  Just one needs to fix
producer_is_icc so that it gets processed only once and cached via
'checked_producer' as otherwise it may needlessly slow down reading DWARF.



> >> +    return 1;
> >> +  else if (producer_is_icc (cu->producer)
> >> +	   && attr != NULL && DW_UNSND (attr) == 0 && die->child == NULL
> >> +	   && (die->tag == DW_TAG_structure_type
> >> +	       || die->tag == DW_TAG_class_type
> >> +	       || die->tag == DW_TAG_union_type))
> >> +    /* ICC does not output the required DW_AT_declaration on incomplete
> >> +       structure, union and class types, but gives them a size of zero.  */
> >> +    return 1;
> > 
> > braces:
> >     {
> >       /* ICC does not output the required DW_AT_declaration on incomplete
> > 	 structure, union and class types, but gives them a size of zero.  */
> >       return 1;
> >     }
> 
> In this case, should I also add braces to the "else if" block just above,
> while I'm there? Or do you prefer to avoid the churn?

There is only single line of code so the braces should not be at the block
above.  (I am sorry as the rule comes from me.)

This patch has not been regression tested (neither against icc) in any way.


Thanks,
Jan


diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index fc1a864..32f0603 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -8977,6 +8977,23 @@ quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile)
   smash_to_methodptr_type (type, new_type);
 }
 
+/* Return non-zero if the supplied PRODUCER string matches the Intel C/C++
+   compiler (icc).  */
+
+static int
+producer_is_icc (const char *producer)
+{
+  static const char *const icc_ident = "Intel(R) C Intel(R) 64 Compiler XE";
+
+  if (producer == NULL)
+    return 0;
+
+  if (strncmp (producer, icc_ident, strlen (icc_ident)) == 0)
+    return 1;
+
+  return 0;
+}
+
 /* Called when we find the DIE that starts a structure or union scope
    (definition) to create a type for the structure or union.  Fill in
    the type's name and general properties; the members will not be
@@ -9079,7 +9096,14 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
       TYPE_LENGTH (type) = 0;
     }
 
-  TYPE_STUB_SUPPORTED (type) = 1;
+  if (producer_is_icc (cu->producer))
+    {
+      /* ICC does not output the required DW_AT_declaration
+	 on incomplete types, but gives them a size of zero.  */
+    }
+  else
+    TYPE_STUB_SUPPORTED (type) = 1;
+
   if (die_is_declaration (die, cu))
     TYPE_STUB (type) = 1;
   else if (attr == NULL && die->child == NULL
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-icc-opaque.S b/gdb/testsuite/gdb.dwarf2/dw2-icc-opaque.S
new file mode 100644
index 0000000..a12c8cf
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/dw2-icc-opaque.S
@@ -0,0 +1,192 @@
+/* Copyright (C) 2011-2012 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+	.file "opaque-pointer.c"
+	.data
+	.comm p_struct,8,8
+	.global p_struct#
+
+	.section .debug_info
+	.align 1
+debug_info_seg1:
+	.4byte debug_info_seg1_end - 1f	/* Length of compilation unit info. */
+1:
+	.2byte 0x0002			/* DWARF version number. */
+	.4byte .debug_abbrev_seg1	/* Points to abbrev section for this unit. */
+	.byte 0x04			/* Target address size. */
+
+	.byte 0x01			/* DIE 1: DW_TAG_compile_unit. */
+	.byte 0x01			/* DW_AT_language = DW_LANG_C89. */
+	.ascii "Intel(R) C Intel(R) 64 Compiler XE "	/* DW_AT_producer. */
+	.ascii "for applications running on Intel(R) 64, "
+	.ascii "Version 12.0.4.191 Build 20110427\n "
+	.asciz "Fixes SameLinkageName MemberPointers"
+
+	.byte 0x02			/* DIE 2: DW_TAG_variable. */
+	.byte 0x01			/* DW_AT_accessibility. */
+	.asciz "p_struct"		/* DW_AT_name. */
+	.4byte 3f - debug_info_seg1	/* DW_AT_type. */
+	.2byte 0x0305			/* DW_AT_location: 5 bytes, DW_OP_addr */
+	.4byte p_struct			/* followed by the address of p_struct. */
+	.byte 0x01			/* DW_AT_external. */
+
+3:
+	.byte 0x03			/* DIE 3: DW_TAG_pointer_type. */
+	.4byte 4f - debug_info_seg1	/* DW_AT_type. */
+
+4:
+	.byte 0x04			/* DIE 4: DW_TAG_structure_type. */
+	.byte 0x01			/* DW_AT_accessibility. */
+	.byte 0x00			/* DW_AT_byte_size. */
+	.asciz "opaque_struct_t"	/* DW_AT_name. */
+	.byte 0x00
+	.byte 0x00
+	.byte 0x00
+	.byte 0x00
+debug_info_seg1_end:
+
+	.section .debug_abbrev
+.debug_abbrev_seg1:
+	.align 1
+	.byte 0x01	/* Abbrev 1. */
+	.byte 0x11	/* DW_TAG_compile_unit. */
+	.byte 0x01	/* DW_CHILDREN_yes. */
+	.byte 0x13	/* DW_AT_language. */
+	.byte 0x0b	/* DW_FORM_data1. */
+	.byte 0x25	/* DW_AT_producer. */
+	.byte 0x08	/* DW_AT_string. */
+	.2byte 0x0000	/* End abbrev. */
+
+	.byte 0x02	/* Abbrev 2. */
+	.byte 0x34	/* DW_TAG_variable. */
+	.byte 0x00	/* DW_CHILDREN_no. */
+	.byte 0x32	/* DW_AT_accessibility. */
+	.byte 0x0b	/* DW_FORM_data1. */
+	.byte 0x03	/* DW_AT_name. */
+	.byte 0x08	/* DW_FORM_string. */
+	.byte 0x49	/* DW_AT_type. */
+	.byte 0x13	/* DW_FORM_ref4. */
+	.byte 0x02	/* DW_AT_location. */
+	.byte 0x0a	/* DW_FORM_block1. */
+	.byte 0x3f	/* DW_AT_external. */
+	.byte 0x0c	/* DW_FORM_flag. */
+	.2byte 0x0000	/* End abbrev. */
+
+	.byte 0x03	/* Abbrev 3. */
+	.byte 0x0f	/* DW_TAG_pointer_type. */
+	.byte 0x00	/* DW_CHILDREN_no. */
+	.byte 0x49	/* DW_AT_type. */
+	.byte 0x13	/* DW_FORM_ref4. */
+	.2byte 0x0000	/* End abbrev. */
+
+	.byte 0x04	/* Abbrev 4. */
+	.byte 0x13	/* DW_TAG_structure_type. */
+	.byte 0x00	/* DW_CHILDREN_no. */
+	.byte 0x32	/* DW_AT_accessibility. */
+	.byte 0x0b	/* DW_FORM_data1. */
+	.byte 0x0b	/* DW_AT_byte_size. */
+	.byte 0x0b	/* DW_FORM_data1. */
+	.byte 0x03	/* DW_AT_name. */
+	.byte 0x08	/* DW_FORM_string. */
+	.2byte 0x0000	/* End abbrev. */
+	.byte 0x00	/* End abbrev table. */
+
+
+	.file "opaque-struct.c"
+	.section .debug_info
+	.align 1
+debug_info_seg2:
+	.4byte debug_info_seg2_end - 1f	/* Length of compilation unit info. */
+1:
+	.2byte 0x0002			/* DWARF version number. */
+	.4byte .debug_abbrev_seg2	/* Points to abbrev section for this unit. */
+	.byte 0x04			/* Target address size. */
+
+	.byte 0x01			/* DIE 1: DW_TAG_compile_unit. */
+	.byte 0x01			/* DW_AT_language = DW_LANG_C89. */
+	.ascii "Intel(R) C Intel(R) 64 Compiler XE "	/* DW_AT_producer. */
+	.ascii "for applications running on Intel(R) 64, "
+	.ascii "Version 12.0.4.191 Build 20110427\n "
+	.asciz "Fixes SameLinkageName MemberPointers"
+
+	.byte 0x02			/* DIE 2: DW_TAG_structure_type. */
+	.byte 0x01			/* DW_AT_accessibility. */
+	.byte 0x04			/* DW_AT_byte_size. */
+	.asciz "opaque_struct_t"	/* DW_AT_name. */
+
+
+	.byte 0x03			/* DIE 3: DW_TAG_member. */
+	.2byte 0x2302			/* DW_AT_data_member_location, 2 bytes, */
+	.byte 0x00			/* DW_OP_plus_uconst followed by zero. */
+	.asciz "wrapped_value"		/* DW_AT_name. */
+	.4byte 4f - debug_info_seg2	/* DW_AT_type. */
+	.byte 0x00
+
+4:
+	.byte 0x04			/* DIE 4: DW_TAG_base_type. */
+	.byte 0x04			/* DW_AT_byte_size. */
+	.byte 0x05			/* DW_AT_encoding. */
+	.asciz "int"			/* DW_AT_name. */
+	.byte 0x00
+	.byte 0x00
+	.byte 0x00
+	.byte 0x00
+debug_info_seg2_end:
+
+	.section .debug_abbrev
+.debug_abbrev_seg2:
+	.align 1
+	.byte 0x01	/* Abbrev 1. */
+	.byte 0x11	/* DW_TAG_compile_unit. */
+	.byte 0x01	/* DW_CHILDREN_yes. */
+	.byte 0x13	/* DW_AT_language. */
+	.byte 0x0b	/* DW_FORM_data1. */
+	.byte 0x25	/* DW_AT_producer. */
+	.byte 0x08	/* DW_FORM_string. */
+	.2byte 0x0000	/* End abbrev. */
+
+	.byte 0x02	/* Abbrev 2. */
+	.byte 0x13	/* DW_TAG_structure_type. */
+	.byte 0x01	/* DW_CHILDREN_yes. */
+	.byte 0x32	/* DW_AT_accessibility. */
+	.byte 0x0b	/* DW_FORM_data1. */
+	.byte 0x0b	/* DW_AT_byte_size. */
+	.byte 0x0b	/* DW_FORM_data1. */
+	.byte 0x03	/* DW_AT_name. */
+	.byte 0x08	/* DW_FORM_string. */
+	.2byte 0x0000	/* End abbrev. */
+
+	.byte 0x03	/* Abbrev 3. */
+	.byte 0x0d	/* DW_TAG_member. */
+	.byte 0x00	/* DW_CHILDREN_no. */
+	.byte 0x38	/* DW_AT_data_member_location. */
+	.byte 0x0a	/* DW_FORM_block1. */
+	.byte 0x03	/* DW_AT_name. */
+	.byte 0x08	/* DW_FORM_string. */
+	.byte 0x49	/* DW_AT_type. */
+	.byte 0x13	/* DW_FORM_ref4. */
+	.2byte 0x0000	/* End abbrev. */
+
+	.byte 0x04	/* Abbrev 4. */
+	.byte 0x24	/* DW_TAG_base_type. */
+	.byte 0x00	/* DW_CHILDREN_no. */
+	.byte 0x0b	/* DW_AT_byte_size. */
+	.byte 0x0b	/* DW_FORM_data1. */
+	.byte 0x3e	/* DW_AT_encoding. */
+	.byte 0x0b	/* DW_FORM_data1. */
+	.byte 0x03	/* DW_AT_name. */
+	.byte 0x08	/* DW_FORM_string. */
+	.2byte 0x0000	/* End abbrev. */
+	.byte 0x00	/* End abbrev table. */
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-icc-opaque.exp b/gdb/testsuite/gdb.dwarf2/dw2-icc-opaque.exp
new file mode 100644
index 0000000..53db400
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/dw2-icc-opaque.exp
@@ -0,0 +1,37 @@
+# Copyright (C) 2011-2012 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+load_lib dwarf.exp
+
+# This test can only be run on targets which support DWARF-2 and use gas.
+if {![dwarf2_support]} {
+    return 0
+}
+
+set testfile "dw2-icc-opaque"
+set srcfile ${testfile}.S
+set executable ${testfile}.x
+set binfile ${objdir}/${subdir}/${executable}
+
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {}] != "" } {
+    return -1
+}
+
+clean_restart $executable
+
+# Before PR 13277 was fixed, this would output:
+# type = struct opaque_struct_t {
+#     <no data fields>
+# } *
+gdb_test "ptype p_struct" "type = struct opaque_struct_t {\r\n *int wrapped_value;\r\n} \\*"


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]