[patch] Fix internal error on canonicalization of clang types [Re: why in cplus_demangle_operators operation sizeof is expected to be followed with space]

Jan Kratochvil jan.kratochvil@redhat.com
Mon Sep 17 06:27:00 GMT 2012


On Mon, 17 Sep 2012 07:49:16 +0200, Vasyl Vavrychuk wrote:
> This looks to be not a symbol but type name.

OK, reproduced [attached], patched DWARF of "int" in C++: void f(int i) {}


> But I have found it directly in the binary. Line containing this text looks like

readelf -wi
 <1><59>: Abbrev Number: 4 (DW_TAG_base_type)
    <5c>   DW_AT_name        : exact_unsigned_base_helper<sizeof(unsigned int) * 8>	


> Do you think the problem is in clang? Could you point out some
> specification, so I can reference it while contacting clang people.

Itanium C++ ABI does not say anything about spacing:
	http://www.swag.uwaterloo.ca/acd/docs/ItaniumC++ABI.htm
	(the original URL is 404 now)

I guess so far it is only agreed upon between GCC and GDB, it is true GDB
should accept any valid spacing of the language, this is also what
cp_canonicalize_string is there for.

Your patch would belons to the GCC mailing lists where libiberty/ is
maintained.

But I find more correct patch the one below.

For a testcase could you provide a minimal C++ code to produce such type?

No regressions on {x86_64,x86_64-m32,i686}-fedora18-linux-gnu.


Thanks,
Jan


gdb/
2012-09-17  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Fix internal error on canonicalization of clang types.
	* cp-name-parser.y (exp): Use "sizeof ".

diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y
index 6767fa5..c57ce64 100644
--- a/gdb/cp-name-parser.y
+++ b/gdb/cp-name-parser.y
@@ -1183,7 +1183,7 @@ exp	:	FLOAT
 	;
 
 exp	:	SIZEOF '(' type ')'	%prec UNARY
-		{ $$ = d_unary ("sizeof", $3); }
+		{ $$ = d_unary ("sizeof ", $3); }
 	;
 
 /* C++.  */
-------------- next part --------------
	.file	"type.C"
	.text
.Ltext0:
	.globl	_Z1fi
	.type	_Z1fi, @function
_Z1fi:
.LFB0:
	.file 1 "type.C"
	# type.C:1
	.loc 1 1 0
	.cfi_startproc
# BLOCK 2 seq:0
# PRED: ENTRY (fallthru)
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -4(%rbp)
	# type.C:1
	.loc 1 1 0
	popq	%rbp
	.cfi_def_cfa 7, 8
# SUCC: EXIT [100.0%] 
	ret
	.cfi_endproc
.LFE0:
	.size	_Z1fi, .-_Z1fi
.Letext0:
	.section	.debug_info,"",@progbits
.Ldebug_info0:
	.long	1f-2f	# Length of Compilation Unit Info
2:
	.value	0x4	# DWARF version number
	.long	.Ldebug_abbrev0	# Offset Into Abbrev. Section
	.byte	0x8	# Pointer Size (in bytes)
	.uleb128 0x1	# (DIE (0xb) DW_TAG_compile_unit)
	.long	.LASF0	# DW_AT_producer: "GNU C++ 4.7.1 20120720 (Red Hat 4.7.1-5) -mtune=generic -march=x86-64 -g"
	.byte	0x4	# DW_AT_language
	.long	.LASF1	# DW_AT_name: "type.C"
	.long	.LASF2	# DW_AT_comp_dir: "/home/jkratoch/t"
	.quad	.Ltext0	# DW_AT_low_pc
	.quad	.Letext0	# DW_AT_high_pc
	.long	.Ldebug_line0	# DW_AT_stmt_list
	.uleb128 0x2	# (DIE (0x2d) DW_TAG_subprogram)
			# DW_AT_external
	.ascii "f\0"	# DW_AT_name
	.byte	0x1	# DW_AT_decl_file (type.C)
	.byte	0x1	# DW_AT_decl_line
	.long	.LASF3	# DW_AT_linkage_name: "_Z1fi"
	.quad	.LFB0	# DW_AT_low_pc
	.quad	.LFE0	# DW_AT_high_pc
	.uleb128 0x1	# DW_AT_frame_base
	.byte	0x9c	# DW_OP_call_frame_cfa
			# DW_AT_GNU_all_call_sites
	.long	0x59	# DW_AT_sibling
	.uleb128 0x3	# (DIE (0x4c) DW_TAG_formal_parameter)
	.ascii "i\0"	# DW_AT_name
	.byte	0x1	# DW_AT_decl_file (type.C)
	.byte	0x1	# DW_AT_decl_line
	.long	0x59	# DW_AT_type
	.uleb128 0x2	# DW_AT_location
	.byte	0x91	# DW_OP_fbreg
	.sleb128 -20
	.byte	0	# end of children of DIE 0x2d
	.uleb128 0x4	# (DIE (0x59) DW_TAG_base_type)
	.byte	0x4	# DW_AT_byte_size
	.byte	0x5	# DW_AT_encoding
#if 0
	.ascii "int\0"	# DW_AT_name
#else
	.ascii "exact_unsigned_base_helper<sizeof(unsigned int) * 8>\0"	# DW_AT_name
#endif
	.byte	0	# end of children of DIE 0xb
1:
	.section	.debug_abbrev,"",@progbits
.Ldebug_abbrev0:
	.uleb128 0x1	# (abbrev code)
	.uleb128 0x11	# (TAG: DW_TAG_compile_unit)
	.byte	0x1	# DW_children_yes
	.uleb128 0x25	# (DW_AT_producer)
	.uleb128 0xe	# (DW_FORM_strp)
	.uleb128 0x13	# (DW_AT_language)
	.uleb128 0xb	# (DW_FORM_data1)
	.uleb128 0x3	# (DW_AT_name)
	.uleb128 0xe	# (DW_FORM_strp)
	.uleb128 0x1b	# (DW_AT_comp_dir)
	.uleb128 0xe	# (DW_FORM_strp)
	.uleb128 0x11	# (DW_AT_low_pc)
	.uleb128 0x1	# (DW_FORM_addr)
	.uleb128 0x12	# (DW_AT_high_pc)
	.uleb128 0x1	# (DW_FORM_addr)
	.uleb128 0x10	# (DW_AT_stmt_list)
	.uleb128 0x17	# (DW_FORM_sec_offset)
	.byte	0
	.byte	0
	.uleb128 0x2	# (abbrev code)
	.uleb128 0x2e	# (TAG: DW_TAG_subprogram)
	.byte	0x1	# DW_children_yes
	.uleb128 0x3f	# (DW_AT_external)
	.uleb128 0x19	# (DW_FORM_flag_present)
	.uleb128 0x3	# (DW_AT_name)
	.uleb128 0x8	# (DW_FORM_string)
	.uleb128 0x3a	# (DW_AT_decl_file)
	.uleb128 0xb	# (DW_FORM_data1)
	.uleb128 0x3b	# (DW_AT_decl_line)
	.uleb128 0xb	# (DW_FORM_data1)
	.uleb128 0x6e	# (DW_AT_linkage_name)
	.uleb128 0xe	# (DW_FORM_strp)
	.uleb128 0x11	# (DW_AT_low_pc)
	.uleb128 0x1	# (DW_FORM_addr)
	.uleb128 0x12	# (DW_AT_high_pc)
	.uleb128 0x1	# (DW_FORM_addr)
	.uleb128 0x40	# (DW_AT_frame_base)
	.uleb128 0x18	# (DW_FORM_exprloc)
	.uleb128 0x2117	# (DW_AT_GNU_all_call_sites)
	.uleb128 0x19	# (DW_FORM_flag_present)
	.uleb128 0x1	# (DW_AT_sibling)
	.uleb128 0x13	# (DW_FORM_ref4)
	.byte	0
	.byte	0
	.uleb128 0x3	# (abbrev code)
	.uleb128 0x5	# (TAG: DW_TAG_formal_parameter)
	.byte	0	# DW_children_no
	.uleb128 0x3	# (DW_AT_name)
	.uleb128 0x8	# (DW_FORM_string)
	.uleb128 0x3a	# (DW_AT_decl_file)
	.uleb128 0xb	# (DW_FORM_data1)
	.uleb128 0x3b	# (DW_AT_decl_line)
	.uleb128 0xb	# (DW_FORM_data1)
	.uleb128 0x49	# (DW_AT_type)
	.uleb128 0x13	# (DW_FORM_ref4)
	.uleb128 0x2	# (DW_AT_location)
	.uleb128 0x18	# (DW_FORM_exprloc)
	.byte	0
	.byte	0
	.uleb128 0x4	# (abbrev code)
	.uleb128 0x24	# (TAG: DW_TAG_base_type)
	.byte	0	# DW_children_no
	.uleb128 0xb	# (DW_AT_byte_size)
	.uleb128 0xb	# (DW_FORM_data1)
	.uleb128 0x3e	# (DW_AT_encoding)
	.uleb128 0xb	# (DW_FORM_data1)
	.uleb128 0x3	# (DW_AT_name)
	.uleb128 0x8	# (DW_FORM_string)
	.byte	0
	.byte	0
	.byte	0
	.section	.debug_aranges,"",@progbits
	.long	0x2c	# Length of Address Ranges Info
	.value	0x2	# DWARF Version
	.long	.Ldebug_info0	# Offset of Compilation Unit Info
	.byte	0x8	# Size of Address
	.byte	0	# Size of Segment Descriptor
	.value	0	# Pad to 16 byte boundary
	.value	0
	.quad	.Ltext0	# Address
	.quad	.Letext0-.Ltext0	# Length
	.quad	0
	.quad	0
	.section	.debug_line,"",@progbits
.Ldebug_line0:
	.section	.debug_str,"MS",@progbits,1
.LASF1:
	.string	"type.C"
.LASF2:
	.string	"/home/jkratoch/t"
.LASF0:
	.string	"GNU C++ 4.7.1 20120720 (Red Hat 4.7.1-5) -mtune=generic -march=x86-64 -g"
.LASF3:
	.string	"_Z1fi"
	.ident	"GCC: (GNU) 4.7.1 20120720 (Red Hat 4.7.1-5)"
	.section	.note.GNU-stack,"",@progbits


More information about the Gdb-patches mailing list