From patchwork Thu Sep 6 10:55:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Hayward X-Patchwork-Id: 29216 Received: (qmail 27495 invoked by alias); 6 Sep 2018 10:56:10 -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 27386 invoked by uid 89); 6 Sep 2018 10:56:09 -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=sk:alan.ha, alanhaywardarmcom, alan.hayward@arm.com, U*alan.hayward 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:07 +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=BHqI4793ReFu0e7M4Muc35re+6lCU2S1FxcCmKa6mNQ=; b=gFcP9bR05Zh0nEAL+vBbdGNBQIREZah8qmrReq8e2bzir0yvKoPYfBw0y6HxG3QCx1iSNW595JbHp1cLhimgrrNzMgTOaHqgx7ExwIQN3ktJPoKFn1bJOza2DHDCAalpCpBZoUJBCNkw+t3JwqApQuGvNS93NpuTaaQEXzhAf8s= 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:00 +0000 From: Alan Hayward To: gdb-patches@sourceware.org Cc: nd@arm.com, Alan Hayward Subject: [PATCH 1/2] Testsuite: Add gdb_can_simple_compile Date: Thu, 6 Sep 2018 11:55:48 +0100 Message-Id: <20180906105549.4366-2-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. gdb/testsuite 2018-09-06 Alan Hayward * lib/gdb.exp (gdb_can_simple_compile): Add proc. (support_complex_tests): Use gdb_can_simple_compile. (is_ilp32_target): Likewise. (is_lp64_target): Likewise. (is_64_target): Likewise. (is_amd64_regs_target): Likewise. (is_aarch32_target): Likewise. (gdb_int128_helper): Likewise. --- gdb/testsuite/lib/gdb.exp | 184 +++++++++++++--------------------------------- 1 file changed, 52 insertions(+), 132 deletions(-) diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index dd2c57cbc2..43c9b03d01 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -2272,35 +2272,16 @@ gdb_caching_proc support_complex_tests { return 0 } - # Set up, compile, and execute a test program containing _Complex types. - # Include the current process ID in the file names to prevent conflicts - # with invocations for multiple testsuites. - set src [standard_temp_file complex[pid].c] - set exe [standard_temp_file complex[pid].x] + # Compile a test program containing _Complex types. - gdb_produce_source $src { + return [gdb_can_simple_compile complex { int main() { _Complex float cf; _Complex double cd; _Complex long double cld; return 0; } - } - - verbose "compiling testfile $src" 2 - set compile_flags {debug nowarnings quiet} - set lines [gdb_compile $src $exe executable $compile_flags] - file delete $src - file delete $exe - - if ![string match "" $lines] then { - verbose "testfile compilation failed, returning 0" 2 - set result 0 - } else { - set result 1 - } - - return $result + } executable] } # Return 1 if GDB can get a type for siginfo from the target, otherwise @@ -2462,86 +2443,32 @@ proc gdb_produce_source { name sources } { # This cannot be decided simply from looking at the target string, # as it might depend on externally passed compiler options like -m64. gdb_caching_proc is_ilp32_target { - set me "is_ilp32_target" - - set src [standard_temp_file ilp32[pid].c] - set obj [standard_temp_file ilp32[pid].o] - - gdb_produce_source $src { + return [gdb_can_simple_compile is_ilp32_target { int dummy[sizeof (int) == 4 && sizeof (void *) == 4 && sizeof (long) == 4 ? 1 : -1]; - } - - verbose "$me: compiling testfile $src" 2 - set lines [gdb_compile $src $obj object {quiet}] - file delete $src - file delete $obj - - if ![string match "" $lines] then { - verbose "$me: testfile compilation failed, returning 0" 2 - return 0 - } - - verbose "$me: returning 1" 2 - return 1 + }] } # Return 1 if target is LP64. # This cannot be decided simply from looking at the target string, # as it might depend on externally passed compiler options like -m64. gdb_caching_proc is_lp64_target { - set me "is_lp64_target" - - set src [standard_temp_file lp64[pid].c] - set obj [standard_temp_file lp64[pid].o] - - gdb_produce_source $src { + return [gdb_can_simple_compile is_lp64_target { int dummy[sizeof (int) == 4 && sizeof (void *) == 8 && sizeof (long) == 8 ? 1 : -1]; - } - - verbose "$me: compiling testfile $src" 2 - set lines [gdb_compile $src $obj object {quiet}] - file delete $src - file delete $obj - - if ![string match "" $lines] then { - verbose "$me: testfile compilation failed, returning 0" 2 - return 0 - } - - verbose "$me: returning 1" 2 - return 1 + }] } # Return 1 if target has 64 bit addresses. # This cannot be decided simply from looking at the target string, # as it might depend on externally passed compiler options like -m64. gdb_caching_proc is_64_target { - set me "is_64_target" - - set src [standard_temp_file is64[pid].c] - set obj [standard_temp_file is64[pid].o] - - gdb_produce_source $src { + return [gdb_can_simple_compile is_64_target { int function(void) { return 3; } int dummy[sizeof (&function) == 8 ? 1 : -1]; - } - - verbose "$me: compiling testfile $src" 2 - set lines [gdb_compile $src $obj object {quiet}] - file delete $src - file delete $obj - - if ![string match "" $lines] then { - verbose "$me: testfile compilation failed, returning 0" 2 - return 0 - } - - verbose "$me: returning 1" 2 - return 1 + }] } # Return 1 if target has x86_64 registers - either amd64 or x32. @@ -2552,30 +2479,13 @@ gdb_caching_proc is_amd64_regs_target { return 0 } - set me "is_amd64_regs_target" - - set src [standard_temp_file reg64[pid].s] - set obj [standard_temp_file reg64[pid].o] - set list {} foreach reg \ {rax rbx rcx rdx rsi rdi rbp rsp r8 r9 r10 r11 r12 r13 r14 r15} { lappend list "\tincq %$reg" } - gdb_produce_source $src [join $list \n] - - verbose "$me: compiling testfile $src" 2 - set lines [gdb_compile $src $obj object {quiet}] - file delete $src - file delete $obj - if ![string match "" $lines] then { - verbose "$me: testfile compilation failed, returning 0" 2 - return 0 - } - - verbose "$me: returning 1" 2 - return 1 + return [gdb_can_simple_compile is_amd64_regs_target [join $list \n]] } # Return 1 if this target is an x86 or x86-64 with -m32. @@ -2597,30 +2507,13 @@ gdb_caching_proc is_aarch32_target { return 0 } - set me "is_aarch32_target" - - set src [standard_temp_file aarch32[pid].s] - set obj [standard_temp_file aarch32[pid].o] - set list {} foreach reg \ {r0 r1 r2 r3} { lappend list "\tmov $reg, $reg" } - gdb_produce_source $src [join $list \n] - - verbose "$me: compiling testfile $src" 2 - set lines [gdb_compile $src $obj object {quiet}] - file delete $src - file delete $obj - - if ![string match "" $lines] then { - verbose "$me: testfile compilation failed, returning 0" 2 - return 0 - } - verbose "$me: returning 1" 2 - return 1 + return [gdb_can_simple_compile aarch32 [join $list \n]] } # Return 1 if this target is an aarch64, either lp64 or ilp32. @@ -3006,22 +2899,10 @@ gdb_caching_proc skip_btrace_pt_tests { # A helper that compiles a test case to see if __int128 is supported. proc gdb_int128_helper {lang} { - set src [standard_temp_file i128[pid].c] - set obj [standard_temp_file i128[pid].o] - - verbose -log "checking $lang for __int128" - gdb_produce_source $src { + return [gdb_can_simple_compile "i128-for-$lang" { __int128 x; int main() { return 0; } - } - - set lines [gdb_compile $src $obj object [list nowarnings quiet $lang]] - file delete $src - file delete $obj - - set result [expr {!![string match "" $lines]}] - verbose -log "__int128 for $lang result = $result" - return $result + } executable {$lang}] } # Return true if the C compiler understands the __int128 type. @@ -3524,6 +3405,45 @@ gdb_caching_proc universal_compile_options { return $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. + +proc gdb_can_simple_compile {name code {type object} {compile_flags {}}} { + + switch -regexp -- $type { + "executable" { + set postfix "x" + } + "object" { + set postfix "o" + } + "preprocess" { + set postfix "i" + } + "assembly" { + set postfix "s" + } + } + set src [standard_temp_file $name-[pid].c] + set obj [standard_temp_file $name-[pid].$postfix] + set compile_flags [concat $compile_flags {debug nowarnings quiet}] + + gdb_produce_source $src $code + + verbose "$name: compiling testfile $src" 2 + 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 + return 0 + } + return 1 +} + # 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 ""