From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 80311 invoked by alias); 30 Oct 2015 04:25:16 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 80297 invoked by uid 89); 30 Oct 2015 04:25:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL,BAYES_05,KAM_STOCKGEN,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=no version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 30 Oct 2015 04:25:13 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id AAA3EC0B2B75 for ; Fri, 30 Oct 2015 04:25:12 +0000 (UTC) Received: from pinnacle.lan (ovpn-113-191.phx2.redhat.com [10.3.113.191]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t9U4PBFl026037 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA256 bits=256 verify=NO) for ; Fri, 30 Oct 2015 00:25:12 -0400 Date: Fri, 30 Oct 2015 11:06:00 -0000 From: Kevin Buettner To: gdb-patches@sourceware.org Subject: [PATCH] gdb.dwarf2: Define and use gdb_target_symbol_prefix for symbol prefixes Message-ID: <20151029212509.438b5642@pinnacle.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2015-10/txt/msg00746.txt.bz2 Some of the tests in gdb.dwarf2 which use Dwarf::assemble refer to (minimal/linker) symbols created in the course of building a small test program. Some targets use a prefix such as underscore ("_") on these symbols. Many of the tests in gdb.dwarf2 do not take this into account. As a consequence, these tests fail to build, resulting either in failures or untested testcases. Here is an example from gdb.dwarf2/dw2-regno-invalid.exp: Dwarf::assemble $asm_file { cu {} { compile_unit { {low_pc main DW_FORM_addr} {high_pc main+0x10000 DW_FORM_addr} } { ... } For targets which require an underscore prefix on linker symbols, the two occurrences of "main" would have to have a prepended underscore, i.e. _main instead of main. gdb/testsuite/ChangeLog: * lib/gdb.exp (gdb_target_symbol_prefix): New proc. * gdb.dwarf2/atomic-type.exp (Dwarf::assemble): Fetch linker symbol prefix and prepend it to f. * gdb.dwarf2/data-loc.exp (Dwarf::assemble): Fetch linker symbol prefix and prepend it to table_1 and table_2. * gdb.dwarf2/dw2-bad-mips-linkage-name.exp (Dwarf::assemble): Fetch linker symbol prefix and prepend it to f and g. * gdb.dwarf2/dw2-ifort-parameter.exp (Dwarf::assemble): Fetch linker symbol prefix and prepend it to ptr. * gdb.dwarf2/dw2-regno-invalid.exp (Dwarf::assemble): Fetch linker symbol prefix and prepend it to main. * gdb.dwarf2/dynarr-ptr.exp (Dwarf::assemble): Fetch linker symbol prefix and prepend it to table_1_ptr and table_2_ptr. --- gdb/testsuite/gdb.dwarf2/atomic-type.exp | 4 ++- gdb/testsuite/gdb.dwarf2/data-loc.exp | 10 +++--- .../gdb.dwarf2/dw2-bad-mips-linkage-name.exp | 6 ++-- gdb/testsuite/gdb.dwarf2/dw2-ifort-parameter.exp | 3 +- gdb/testsuite/gdb.dwarf2/dw2-regno-invalid.exp | 10 +++--- gdb/testsuite/gdb.dwarf2/dynarr-ptr.exp | 10 +++--- gdb/testsuite/lib/gdb.exp | 39 ++++++++++++++++++++++ 7 files changed, 66 insertions(+), 16 deletions(-) diff --git a/gdb/testsuite/gdb.dwarf2/atomic-type.exp b/gdb/testsuite/gdb.dwarf2/atomic-type.exp index fb315e3..43e28c8 100644 --- a/gdb/testsuite/gdb.dwarf2/atomic-type.exp +++ b/gdb/testsuite/gdb.dwarf2/atomic-type.exp @@ -25,6 +25,8 @@ standard_testfile atomic.c atomic-type-dw.S set asm_file [standard_output_file $srcfile2] Dwarf::assemble $asm_file { + set prefix [gdb_target_symbol_prefix] + cu {} { DW_TAG_compile_unit { {DW_AT_language @DW_LANG_C11} @@ -68,7 +70,7 @@ Dwarf::assemble $asm_file { DW_TAG_subprogram { {name f} - {low_pc f addr} + {low_pc ${prefix}f addr} {high_pc f_end_lbl addr} {type :$i_l} } { diff --git a/gdb/testsuite/gdb.dwarf2/data-loc.exp b/gdb/testsuite/gdb.dwarf2/data-loc.exp index e9e702c..4802a0a 100644 --- a/gdb/testsuite/gdb.dwarf2/data-loc.exp +++ b/gdb/testsuite/gdb.dwarf2/data-loc.exp @@ -36,6 +36,8 @@ if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } { # Make some DWARF for the test. set asm_file [standard_output_file $srcfile2] Dwarf::assemble $asm_file { + set prefix [gdb_target_symbol_prefix] + cu {} { DW_TAG_compile_unit { {DW_AT_language @DW_LANG_Ada95} @@ -84,7 +86,7 @@ Dwarf::assemble $asm_file { {DW_AT_name foo__three} {DW_AT_type :$array_label} {DW_AT_location { - DW_OP_addr table_1 + DW_OP_addr ${prefix}table_1 } SPECIAL_expr} {external 1 flag} } @@ -92,7 +94,7 @@ Dwarf::assemble $asm_file { {DW_AT_name foo__three_tdef} {DW_AT_type :$array_ptr_label} {DW_AT_location { - DW_OP_addr table_1 + DW_OP_addr ${prefix}table_1 } SPECIAL_expr} {external 1 flag} } @@ -100,7 +102,7 @@ Dwarf::assemble $asm_file { {DW_AT_name foo__five} {DW_AT_type :$array_label} {DW_AT_location { - DW_OP_addr table_2 + DW_OP_addr ${prefix}table_2 } SPECIAL_expr} {external 1 flag} } @@ -108,7 +110,7 @@ Dwarf::assemble $asm_file { {DW_AT_name foo__five_tdef} {DW_AT_type :$array_ptr_label} {DW_AT_location { - DW_OP_addr table_2 + DW_OP_addr ${prefix}table_2 } SPECIAL_expr} {external 1 flag} } diff --git a/gdb/testsuite/gdb.dwarf2/dw2-bad-mips-linkage-name.exp b/gdb/testsuite/gdb.dwarf2/dw2-bad-mips-linkage-name.exp index 77f6175..decd531 100644 --- a/gdb/testsuite/gdb.dwarf2/dw2-bad-mips-linkage-name.exp +++ b/gdb/testsuite/gdb.dwarf2/dw2-bad-mips-linkage-name.exp @@ -26,6 +26,8 @@ standard_testfile dw2-bad-mips-linkage-name.c dw2-bad-mips-linkage-name.S set asm_file [standard_output_file $srcfile2] Dwarf::assemble $asm_file { + set prefix [gdb_target_symbol_prefix] + cu {} { DW_TAG_compile_unit { {DW_AT_language @DW_LANG_C} @@ -42,14 +44,14 @@ Dwarf::assemble $asm_file { } DW_TAG_subprogram { {name f} - {low_pc f addr} + {low_pc ${prefix}f addr} {high_pc f_end_lbl addr} {type :$b_l} {DW_AT_MIPS_linkage_name _Z1fv} } DW_TAG_subprogram { {name g} - {low_pc g addr} + {low_pc ${prefix}g addr} {high_pc g_end_lbl addr} {type :$b_l} {DW_AT_MIPS_linkage_name 42 DW_FORM_data1} diff --git a/gdb/testsuite/gdb.dwarf2/dw2-ifort-parameter.exp b/gdb/testsuite/gdb.dwarf2/dw2-ifort-parameter.exp index c71103d..d55fd43 100644 --- a/gdb/testsuite/gdb.dwarf2/dw2-ifort-parameter.exp +++ b/gdb/testsuite/gdb.dwarf2/dw2-ifort-parameter.exp @@ -27,6 +27,7 @@ standard_testfile .c dw2-ifort-parameter-dw.S # Make some DWARF for the test. set asm_file [standard_output_file $srcfile2] Dwarf::assemble $asm_file { + set prefix [gdb_target_symbol_prefix] declare_labels int_label extern func_start func_end ptr @@ -53,7 +54,7 @@ Dwarf::assemble $asm_file { {variable_parameter 1 flag} {type :$int_label} {location { - addr ptr + addr ${prefix}ptr deref } SPECIAL_expr} } diff --git a/gdb/testsuite/gdb.dwarf2/dw2-regno-invalid.exp b/gdb/testsuite/gdb.dwarf2/dw2-regno-invalid.exp index a7d77c5..620d438 100644 --- a/gdb/testsuite/gdb.dwarf2/dw2-regno-invalid.exp +++ b/gdb/testsuite/gdb.dwarf2/dw2-regno-invalid.exp @@ -27,10 +27,12 @@ standard_testfile .S main.c # Make some DWARF for the test. set asm_file [standard_output_file $srcfile] Dwarf::assemble $asm_file { + set prefix [gdb_target_symbol_prefix] + cu {} { compile_unit { - {low_pc main DW_FORM_addr} - {high_pc main+0x10000 DW_FORM_addr} + {low_pc ${prefix}main DW_FORM_addr} + {high_pc ${prefix}main+0x10000 DW_FORM_addr} } { declare_labels integer_label @@ -43,8 +45,8 @@ Dwarf::assemble $asm_file { DW_TAG_subprogram { {name main} {DW_AT_external 1 flag} - {low_pc main DW_FORM_addr} - {high_pc main+0x10000 DW_FORM_addr} + {low_pc ${prefix}main DW_FORM_addr} + {high_pc ${prefix}main+0x10000 DW_FORM_addr} } { DW_TAG_variable { {DW_AT_name bregx} diff --git a/gdb/testsuite/gdb.dwarf2/dynarr-ptr.exp b/gdb/testsuite/gdb.dwarf2/dynarr-ptr.exp index 3dcb3d7..d0a74be 100644 --- a/gdb/testsuite/gdb.dwarf2/dynarr-ptr.exp +++ b/gdb/testsuite/gdb.dwarf2/dynarr-ptr.exp @@ -36,6 +36,8 @@ if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } { # Make some DWARF for the test. set asm_file [standard_output_file $srcfile2] Dwarf::assemble $asm_file { + set prefix [gdb_target_symbol_prefix] + cu {} { DW_TAG_compile_unit { {DW_AT_language @DW_LANG_Ada95} @@ -85,7 +87,7 @@ Dwarf::assemble $asm_file { {DW_AT_name foo__three_ptr} {DW_AT_type :$array_ptr_label} {DW_AT_location { - DW_OP_addr table_1_ptr + DW_OP_addr ${prefix}table_1_ptr } SPECIAL_expr} {external 1 flag} } @@ -93,7 +95,7 @@ Dwarf::assemble $asm_file { {DW_AT_name foo__three_ptr_tdef} {DW_AT_type :$array_typedef_label} {DW_AT_location { - DW_OP_addr table_1_ptr + DW_OP_addr ${prefix}table_1_ptr } SPECIAL_expr} {external 1 flag} } @@ -101,7 +103,7 @@ Dwarf::assemble $asm_file { {DW_AT_name foo__five_ptr} {DW_AT_type :$array_ptr_label} {DW_AT_location { - DW_OP_addr table_2_ptr + DW_OP_addr ${prefix}table_2_ptr } SPECIAL_expr} {external 1 flag} } @@ -109,7 +111,7 @@ Dwarf::assemble $asm_file { {DW_AT_name foo__five_ptr_tdef} {DW_AT_type :$array_typedef_label} {DW_AT_location { - DW_OP_addr table_2_ptr + DW_OP_addr ${prefix}table_2_ptr } SPECIAL_expr} {external 1 flag} } diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 048070b..f8e35ac 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -5521,6 +5521,45 @@ proc core_find {binfile {deletefiles {}} {arg ""}} { return $destcore } +# gdb_target_symbol_prefix compiles a test program and uses readelf +# to determine the prefix (such as underscore) for linker symbol +# prefixes. + +proc gdb_target_symbol_prefix {} { + # Set up and compile a simple test program... + set src [standard_temp_file main[pid].c] + set exe [standard_temp_file main[pid].x] + + gdb_produce_source $src { + int main() { + return 0; + } + } + + verbose "compiling testfile $src" 2 + set compile_flags {debug nowarnings quiet} + set lines [gdb_compile $src $exe executable $compile_flags] + + set prefix "" + + if ![string match "" $lines] then { + verbose "gdb_target_symbol_prefix: testfile compilation failed, returning null prefix" 2 + } else { + set readelf_program [gdb_find_readelf] + set result [catch "exec $readelf_program --syms $exe" output] + + if { $result == 0 \ + && ![regexp { ([^ a-zA-Z0-9]*)main$} $output dummy prefix] } { + verbose "gdb_target_symbol_prefix: Could not find main in readelf output; returning null prefix" 2 + } + } + + file delete $src + file delete $exe + + return $prefix +} + # gdb_target_symbol_prefix_flags returns a string that can be added # to gdb_compile options to define SYMBOL_PREFIX macro value # symbol_prefix_flags returns a string that can be added