From patchwork Thu Sep 6 10:55:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Hayward X-Patchwork-Id: 29217 Received: (qmail 28052 invoked by alias); 6 Sep 2018 10:56:15 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 27934 invoked by uid 89); 6 Sep 2018 10:56:14 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=vor X-HELO: EUR03-VE1-obe.outbound.protection.outlook.com Received: from mail-eopbgr50043.outbound.protection.outlook.com (HELO EUR03-VE1-obe.outbound.protection.outlook.com) (40.107.5.43) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 06 Sep 2018 10:56:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=APvhHBA/2xd+nLLZDgk6g5v7E0njeYQsoQrxSiPpb5k=; b=X2yriboqUiVEb/JGWielRV4t5+chI5kkN7kzt2J6qODvtKzLXcGvEkWACumLC3vS0qDAZNL/IZQVvF/LP9wgZBZhdycVlc1ISb5UHaxP9m59RQvHrhOCXR6kJSlCgaKsaFDWszQmN/0aToDroYM3yZeaDjSeophB7nVI1V3sZRM= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Alan.Hayward@arm.com; Received: from C02TF0U7HF1T.manchester.arm.com (217.140.106.32) by VI1PR0802MB2142.eurprd08.prod.outlook.com (2603:10a6:800:9b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1101.17; Thu, 6 Sep 2018 10:56:01 +0000 From: Alan Hayward To: gdb-patches@sourceware.org Cc: nd@arm.com, Alan Hayward Subject: [PATCH 2/2] Testsuite: Add gdb_simple_compile Date: Thu, 6 Sep 2018 11:55:49 +0100 Message-Id: <20180906105549.4366-3-alan.hayward@arm.com> In-Reply-To: <20180906105549.4366-1-alan.hayward@arm.com> References: <20180906105549.4366-1-alan.hayward@arm.com> MIME-Version: 1.0 Return-Path: alan.hayward@arm.com Received-SPF: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-IsSubscribed: yes Simplfy gdb.exp by adding a function that will attempt to compile a piece of code, then clean up, leaving the created object. gdb/testsuite 2018-09-06 Alan Hayward * lib/gdb.exp (gdb_simple_compile): Add proc. (is_elf_target): Use gdb_simple_compile. (skip_altivec_tests): Likewise. (skip_vsx_tests): Likewise. (skip_tsx_tests): Likewise. (skip_btrace_tests): Likewise. (skip_btrace_pt_tests): Likewise. (gdb_can_simple_compile): Likewise. (gdb_has_argv0): Likewise. (gdb_target_symbol_prefix): Likewise. (target_supports_scheduler_locking): Likewise. --- gdb/testsuite/lib/gdb.exp | 253 +++++++++++++++------------------------------- 1 file changed, 84 insertions(+), 169 deletions(-) diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 43c9b03d01..c7efcecae8 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -2376,21 +2376,10 @@ proc readline_is_used { } { gdb_caching_proc is_elf_target { set me "is_elf_target" - set src [standard_temp_file is_elf_target[pid].c] - set obj [standard_temp_file is_elf_target[pid].o] - - gdb_produce_source $src { - int foo () {return 0;} - } - - verbose "$me: compiling testfile $src" 2 - set lines [gdb_compile $src $obj object {quiet}] - - file delete $src - - if ![string match "" $lines] then { - verbose "$me: testfile compilation failed, returning 0" 2 - return 0 + global obj + set src { int foo () {return 0;} } + if {![gdb_simple_compile elf_target $src]} { + return 0 } set fp_obj [open $obj "r"] @@ -2554,27 +2543,22 @@ gdb_caching_proc skip_altivec_tests { } # Make sure we have a compiler that understands altivec. - set compile_flags {debug nowarnings} if [get_compiler_info] { warning "Could not get compiler info" return 1 } if [test_compiler_info gcc*] { - set compile_flags "$compile_flags additional_flags=-maltivec" + set compile_flags "{additional_flags=-maltivec}" } elseif [test_compiler_info xlc*] { - set compile_flags "$compile_flags additional_flags=-qaltivec" + set compile_flags "{additional_flags=-qaltivec}" } else { verbose "Could not compile with altivec support, returning 1" 2 return 1 } - # Set up, compile, and execute a test program containing VMX instructions. - # Include the current process ID in the file names to prevent conflicts - # with invocations for multiple testsuites. - set src [standard_temp_file vmx[pid].c] - set exe [standard_temp_file vmx[pid].x] - - gdb_produce_source $src { + # Compile a test program containing VMX instructions. + global obj + set src { int main() { #ifdef __MACH__ asm volatile ("vor v0,v0,v0"); @@ -2584,22 +2568,16 @@ gdb_caching_proc skip_altivec_tests { return 0; } } - - verbose "$me: compiling testfile $src" 2 - set lines [gdb_compile $src $exe executable $compile_flags] - file delete $src - - if ![string match "" $lines] then { - verbose "$me: testfile compilation failed, returning 1" 2 + if {![gdb_simple_compile $me $src executable $compile_flags]} { return 1 } - # No error message, compilation succeeded so now run it via gdb. + # Compilation succeeded so now run it via gdb. gdb_exit gdb_start gdb_reinitialize_dir $srcdir/$subdir - gdb_load "$exe" + gdb_load "$obj" gdb_run_cmd gdb_expect { -re ".*Illegal instruction.*${gdb_prompt} $" { @@ -2616,7 +2594,7 @@ gdb_caching_proc skip_altivec_tests { } } gdb_exit - remote_file build delete $exe + remote_file build delete $obj verbose "$me: returning $skip_vmx_tests" 2 return $skip_vmx_tests @@ -2638,24 +2616,22 @@ gdb_caching_proc skip_vsx_tests { } # Make sure we have a compiler that understands altivec. - set compile_flags {debug nowarnings quiet} if [get_compiler_info] { warning "Could not get compiler info" return 1 } if [test_compiler_info gcc*] { - set compile_flags "$compile_flags additional_flags=-mvsx" + set compile_flags "{additional_flags=-mvsx}" } elseif [test_compiler_info xlc*] { - set compile_flags "$compile_flags additional_flags=-qasm=gcc" + set compile_flags "{additional_flags=-qasm=gcc}" } else { verbose "Could not compile with vsx support, returning 1" 2 return 1 } - set src [standard_temp_file vsx[pid].c] - set exe [standard_temp_file vsx[pid].x] - - gdb_produce_source $src { + # Compile a test program containing VSX instructions. + global obj + set src { int main() { double a[2] = { 1.0, 2.0 }; #ifdef __MACH__ @@ -2666,13 +2642,7 @@ gdb_caching_proc skip_vsx_tests { return 0; } } - - verbose "$me: compiling testfile $src" 2 - set lines [gdb_compile $src $exe executable $compile_flags] - file delete $src - - if ![string match "" $lines] then { - verbose "$me: testfile compilation failed, returning 1" 2 + if {![gdb_simple_compile $me $src executable $compile_flags]} { return 1 } @@ -2681,7 +2651,7 @@ gdb_caching_proc skip_vsx_tests { gdb_exit gdb_start gdb_reinitialize_dir $srcdir/$subdir - gdb_load "$exe" + gdb_load "$obj" gdb_run_cmd gdb_expect { -re ".*Illegal instruction.*${gdb_prompt} $" { @@ -2698,7 +2668,7 @@ gdb_caching_proc skip_vsx_tests { } } gdb_exit - remote_file build delete $exe + remote_file build delete $obj verbose "$me: returning $skip_vsx_tests" 2 return $skip_vsx_tests @@ -2712,24 +2682,17 @@ gdb_caching_proc skip_tsx_tests { set me "skip_tsx_tests" - set src [standard_temp_file tsx[pid].c] - set exe [standard_temp_file tsx[pid].x] - - gdb_produce_source $src { - int main() { - asm volatile ("xbegin .L0"); - asm volatile ("xend"); - asm volatile (".L0: nop"); - return 0; - } + # Compile a test program. + global obj + set src { + int main() { + asm volatile ("xbegin .L0"); + asm volatile ("xend"); + asm volatile (".L0: nop"); + return 0; + } } - - verbose "$me: compiling testfile $src" 2 - set lines [gdb_compile $src $exe executable {nowarnings quiet}] - file delete $src - - if ![string match "" $lines] then { - verbose "$me: testfile compilation failed." 2 + if {![gdb_simple_compile $me $src executable]} { return 1 } @@ -2738,7 +2701,7 @@ gdb_caching_proc skip_tsx_tests { gdb_exit gdb_start gdb_reinitialize_dir $srcdir/$subdir - gdb_load "$exe" + gdb_load "$obj" gdb_run_cmd gdb_expect { -re ".*Illegal instruction.*${gdb_prompt} $" { @@ -2755,7 +2718,7 @@ gdb_caching_proc skip_tsx_tests { } } gdb_exit - remote_file build delete $exe + remote_file build delete $obj verbose "$me: returning $skip_tsx_tests" 2 return $skip_tsx_tests @@ -2773,24 +2736,11 @@ gdb_caching_proc skip_btrace_tests { return 1 } - # Set up, compile, and execute a test program. - # Include the current process ID in the file names to prevent conflicts - # with invocations for multiple testsuites. - set src [standard_temp_file btrace[pid].c] - set exe [standard_temp_file btrace[pid].x] - - gdb_produce_source $src { - int main(void) { return 0; } - } - - verbose "$me: compiling testfile $src" 2 - set compile_flags {debug nowarnings quiet} - set lines [gdb_compile $src $exe executable $compile_flags] - - if ![string match "" $lines] then { - verbose "$me: testfile compilation failed, returning 1" 2 - file delete $src - return 1 + # Compile a test program. + global obj + set src { int main() { return 0; } } + if {![gdb_simple_compile $me $src executable]} { + return 0 } # No error message, compilation succeeded so now run it via gdb. @@ -2798,12 +2748,10 @@ gdb_caching_proc skip_btrace_tests { gdb_exit gdb_start gdb_reinitialize_dir $srcdir/$subdir - gdb_load $exe + gdb_load $obj if ![runto_main] { - file delete $src return 1 } - file delete $src # In case of an unexpected output, we return 2 as a fail value. set skip_btrace_tests 2 gdb_test_multiple "record btrace" "check btrace support" { @@ -2821,7 +2769,7 @@ gdb_caching_proc skip_btrace_tests { } } gdb_exit - remote_file build delete $exe + remote_file build delete $obj verbose "$me: returning $skip_btrace_tests" 2 return $skip_btrace_tests @@ -2840,24 +2788,11 @@ gdb_caching_proc skip_btrace_pt_tests { return 1 } - # Set up, compile, and execute a test program. - # Include the current process ID in the file names to prevent conflicts - # with invocations for multiple testsuites. - set src [standard_temp_file btrace[pid].c] - set exe [standard_temp_file btrace[pid].x] - - gdb_produce_source $src { - int main(void) { return 0; } - } - - verbose "$me: compiling testfile $src" 2 - set compile_flags {debug nowarnings quiet} - set lines [gdb_compile $src $exe executable $compile_flags] - - if ![string match "" $lines] then { - verbose "$me: testfile compilation failed, returning 1" 2 - file delete $src - return 1 + # Compile a test program. + global obj + set src { int main() { return 0; } } + if {![gdb_simple_compile $me $src executable]} { + return 0 } # No error message, compilation succeeded so now run it via gdb. @@ -2865,12 +2800,10 @@ gdb_caching_proc skip_btrace_pt_tests { gdb_exit gdb_start gdb_reinitialize_dir $srcdir/$subdir - gdb_load $exe + gdb_load $obj if ![runto_main] { - file delete $src return 1 } - file delete $src # In case of an unexpected output, we return 2 as a fail value. set skip_btrace_tests 2 gdb_test_multiple "record btrace pt" "check btrace pt support" { @@ -2891,7 +2824,7 @@ gdb_caching_proc skip_btrace_pt_tests { } } gdb_exit - remote_file build delete $exe + remote_file build delete $obj verbose "$me: returning $skip_btrace_tests" 2 return $skip_btrace_tests @@ -3407,9 +3340,10 @@ gdb_caching_proc universal_compile_options { # Compile the code in $code to a file based on $name. # Return 1 if code can be compiled -# Delete all created files and objects. +# Leave the file name of the resulting object in the global $obj. -proc gdb_can_simple_compile {name code {type object} {compile_flags {}}} { +proc gdb_simple_compile {name code {type object} {compile_flags {}}} { + global obj switch -regexp -- $type { "executable" { @@ -3435,7 +3369,6 @@ proc gdb_can_simple_compile {name code {type object} {compile_flags {}}} { set lines [gdb_compile $src $obj $type $compile_flags] file delete $src - file delete $obj if ![string match "" $lines] then { verbose "$name: compilation failed, returning 0" 2 @@ -3444,6 +3377,17 @@ proc gdb_can_simple_compile {name code {type object} {compile_flags {}}} { return 1 } +# Compile the code in $code to an object. +# Return 1 if code can be compiled. +# Delete all created files and objects. + +proc gdb_can_simple_compile {name code {type object} {compile_flags ""}} { + global obj + set ret [gdb_simple_compile $name $code $type $compile_flags] + file delete $obj + return $ret +} + # Some targets need to always link a special object in. Save its path here. global gdb_saved_set_unbuffered_mode_obj set gdb_saved_set_unbuffered_mode_obj "" @@ -5145,18 +5089,15 @@ gdb_caching_proc gdb_skip_xml_test { gdb_caching_proc gdb_has_argv0 { set result 0 - # Set up, compile, and execute a test program to check whether - # argv[0] is available. - set src [standard_temp_file has_argv0[pid].c] - set exe [standard_temp_file has_argv0[pid].x] + # Compile and execute a test program to check whether argv[0] is available. - gdb_produce_source $src { + global obj + gdb_simple_compile has_argv0 { int main (int argc, char **argv) { return 0; } - } + } executable - gdb_compile $src $exe executable {debug} # Helper proc. proc gdb_has_argv0_1 { exe } { @@ -5227,11 +5168,10 @@ gdb_caching_proc gdb_has_argv0 { return $retval } - set result [gdb_has_argv0_1 $exe] + set result [gdb_has_argv0_1 $obj] gdb_exit - file delete $src - file delete $exe + file delete $obj if { !$result && ([istarget *-*-linux*] @@ -5938,37 +5878,25 @@ proc core_find {binfile {deletefiles {}} {arg ""}} { # for linker symbol prefixes. gdb_caching_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; - } + # Compile a simple test program... + global obj + set src { int main() { return 0; } } + if {![gdb_simple_compile target_symbol_prefix $src executable]} { + 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 objdump_program [gdb_find_objdump] - set result [catch "exec $objdump_program --syms $exe" output] + set objdump_program [gdb_find_objdump] + set result [catch "exec $objdump_program --syms $obj" output] - if { $result == 0 \ - && ![regexp -lineanchor \ - { ([^ a-zA-Z0-9]*)main$} $output dummy prefix] } { - verbose "gdb_target_symbol_prefix: Could not find main in objdump output; returning null prefix" 2 - } + if { $result == 0 \ + && ![regexp -lineanchor \ + { ([^ a-zA-Z0-9]*)main$} $output dummy prefix] } { + verbose "gdb_target_symbol_prefix: Could not find main in objdump output; returning null prefix" 2 } - file delete $src - file delete $exe + file delete $obj return $prefix } @@ -5980,26 +5908,13 @@ gdb_caching_proc target_supports_scheduler_locking { set me "gdb_target_supports_scheduler_locking" - set src [standard_temp_file has_schedlock[pid].c] - set exe [standard_temp_file has_schedlock[pid].x] - - gdb_produce_source $src { - int main () { - return 0; - } - } - - verbose "$me: compiling testfile $src" 2 - set compile_flags {debug nowarnings} - set lines [gdb_compile $src $exe executable $compile_flags] - file delete $src - - if ![string match "" $lines] then { - verbose "$me: testfile compilation failed, returning 0" 2 + global obj + set src { int main() { return 0; } } + if {![gdb_simple_compile $me $src executable]} { return 0 } - clean_restart $exe + clean_restart $obj gdb_start_cmd set supports_schedule_locking -1 @@ -6038,7 +5953,7 @@ gdb_caching_proc target_supports_scheduler_locking { } gdb_exit - remote_file build delete $exe + remote_file build delete $obj verbose "$me: returning $supports_schedule_locking" 2 return $supports_schedule_locking }