From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by sourceware.org (Postfix) with ESMTPS id 5D57D385DC26 for ; Tue, 31 Mar 2020 17:12:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5D57D385DC26 IronPort-SDR: 6+CU1fIrYHK5qUFu4WDzMEgF/mY+nOUDjq+zRzx5BIDQaeVSniHrd82lNilZQTvJy7z776LwDI bXKfMoGVp0YQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Mar 2020 10:12:24 -0700 IronPort-SDR: rBZdlwNXCwtNc68noiqFsFfEYr3M0Xy9aeKKVTJnaFyL4lwm/mms5ehAhvyLjdKRM7FgtT8Xm4 CcD7k5mCUkZQ== X-IronPort-AV: E=Sophos;i="5.72,328,1580803200"; d="scan'208";a="241971262" Received: from labpc7920x-08.iul.intel.com (HELO localhost) ([172.28.49.151]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Mar 2020 10:12:23 -0700 From: Mihails Strasuns To: gdb-patches@sourceware.org Subject: [PATCH v3 5/9] [gdb/testsuite] add lib/jit-elf-helpers.exp Date: Tue, 31 Mar 2020 19:13:52 +0200 Message-Id: <20200331171356.26126-5-mihails.strasuns@intel.com> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200331171356.26126-1-mihails.strasuns@intel.com> References: <166773> <20200331171356.26126-1-mihails.strasuns@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-25.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 Mar 2020 17:12:27 -0000 New utility library to be used by jit-elf tests responsible for compiling binary artifacts. In the next commit the compilation process will become more complicated because of extra mandatory flag - keeping it in one place will make tests less fragile. gdb/testsuite/ChangeLog: 2020-02-18 Mihails Strasuns * lib/jit-elf-helpers.exp: new file * gdb.base/jit-elf.exp: updated to use jit-elf-helpers.exp * gdb.base/jit-elf-so.exp: updated to use jit-elf-helpers.exp Change-Id: I2fda518406aeca55e82df45edd67cef149497bbe Signed-off-by: Mihails Strasuns --- gdb/testsuite/gdb.base/jit-elf-so.exp | 87 ++++++++------------------- gdb/testsuite/gdb.base/jit-elf.exp | 46 ++------------ gdb/testsuite/lib/jit-elf-helpers.exp | 78 ++++++++++++++++++++++++ 3 files changed, 108 insertions(+), 103 deletions(-) create mode 100644 gdb/testsuite/lib/jit-elf-helpers.exp diff --git a/gdb/testsuite/gdb.base/jit-elf-so.exp b/gdb/testsuite/gdb.base/jit-elf-so.exp index bcd72eb2bf..55154e9866 100644 --- a/gdb/testsuite/gdb.base/jit-elf-so.exp +++ b/gdb/testsuite/gdb.base/jit-elf-so.exp @@ -26,71 +26,32 @@ if {[get_compiler_info]} { return 1 } -# Compile the testcase program. -# OPTIONS is passed to gdb_compile when compiling the program. -proc compile_jit_main {options} { - global srcdir subdir srcfile2 binfile2 - set testfile jit-elf-main - set srcfile2 ${testfile}.c - set binfile2 [standard_output_file $testfile.so] - set options [concat \ - $options \ - debug] - if { [gdb_compile_shlib "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" \ - $options] != "" } { +load_lib jit-elf-helpers.exp + +global testfile srcfile binfile solib_binfile_targets +lassign [compile_jit_main_as_so] testfile srcfile binfile +set solib_binfile_targets [compile_n_jit_so 2] + +# Compile the test case shared library loader. +proc compile_jit_dlmain {} { + global srcdir subdir testfile_dlmain srcfile_dlmain + set testfile_dlmain jit-elf-dlmain + set srcfile_dlmain ${testfile_dlmain}.c + set binfile [standard_output_file $testfile_dlmain] + if { [gdb_compile "${srcdir}/${subdir}/${srcfile_dlmain}" "${binfile}" \ + executable {debug shlib_load}] != "" } { untested "Failure to compile jit-elf-main" } } -# Compile the testcase shared library loader. -# OPTIONS is passed to gdb_compile when compiling the library. -proc compile_jit_dlmain {options} { - global srcdir subdir testfile srcfile binfile - set testfile jit-elf-dlmain - set srcfile ${testfile}.c - set binfile [standard_output_file $testfile] - set options [concat \ - $options \ - debug] - if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \ - executable $options] != "" } { - untested "Failure to compile jit-elf-main" - } -} - -proc compile_n_jit_so {count} { - global srcdir subdir solib_binfile_targets - set solib_binfile_targets {} - set solib_testfile jit-elf-solib - - for {set i 1} {$i <= $count} {incr i} { - set solib_binfile [standard_output_file ${solib_testfile}.$i.so] - set solib_srcfile "${srcdir}/${subdir}/${solib_testfile}.c" - set solib_binfile_test_msg "SHLIBDIR/${solib_testfile}.$i.so" - - # Note: compiling without debug info by default: some test - # do symbol renaming by munging on ELF symbol table, and that - # wouldn't work for .debug sections. Also, output for "info - # function" changes when debug info is present. - if { [gdb_compile_shlib ${solib_srcfile} ${solib_binfile} {}] != "" } { - untested "Failure to compile ${solib_binfile_test_msg}" - } - - set path [gdb_remote_download target ${solib_binfile}] - lappend solib_binfile_targets $path - } -} - -compile_jit_main {additional_flags="-DMAIN=jit_dl_main"} -compile_jit_dlmain {shlib_load} -compile_n_jit_so 2 +compile_jit_dlmain proc one_jit_test {count match_str} { with_test_prefix "one_jit_test-$count" { - global verbose testfile srcfile2 binfile2 solib_binfile_targets + global verbose testfile_dlmain srcfile_dlmain srcfile binfile solib_binfile_targets - clean_restart $testfile - gdb_load_shlib $binfile2 + clean_restart $testfile_dlmain + gdb_load_shlib $binfile # This is just to help debugging when things fail if {$verbose > 0} { @@ -102,12 +63,12 @@ proc one_jit_test {count match_str} { return } - gdb_breakpoint [gdb_get_line_number "break here before-dlopen" ] + gdb_breakpoint [gdb_get_line_number "break here before-dlopen" $srcfile_dlmain] gdb_continue_to_breakpoint "break here before-dlopen" # Poke desired values directly into inferior instead of using "set args" # because "set args" does not work under gdbserver. - gdb_test_no_output "set var jit_libname = \"$binfile2\"" + gdb_test_no_output "set var jit_libname = \"$binfile\"" incr count gdb_test "set var argc=$count" gdb_test "set var argv=fake_argv" @@ -115,13 +76,13 @@ proc one_jit_test {count match_str} { gdb_test "set var argv\[$i\]=\"[lindex $solib_binfile_targets [expr $i-1]]\"" } - gdb_breakpoint [gdb_get_line_number "break here after-dlopen" ] + gdb_breakpoint [gdb_get_line_number "break here after-dlopen" $srcfile_dlmain] gdb_continue_to_breakpoint "break here after-dlopen" - gdb_breakpoint "$srcfile2:[gdb_get_line_number {break here 0} $srcfile2]" + gdb_breakpoint "$srcfile:[gdb_get_line_number {break here 0} $srcfile]" gdb_continue_to_breakpoint "break here 0" - gdb_breakpoint "$srcfile2:[gdb_get_line_number {break here 1} $srcfile2]" + gdb_breakpoint "$srcfile:[gdb_get_line_number {break here 1} $srcfile]" gdb_continue_to_breakpoint "break here 1" gdb_test "info function jit_function" "$match_str" @@ -132,7 +93,7 @@ proc one_jit_test {count match_str} { gdb_test "maintenance info break" } - gdb_breakpoint "$srcfile2:[gdb_get_line_number {break here 2} $srcfile2]" + gdb_breakpoint "$srcfile:[gdb_get_line_number {break here 2} $srcfile]" gdb_continue_to_breakpoint "break here 2" # All jit librares must have been unregistered gdb_test "info function jit_function" \ diff --git a/gdb/testsuite/gdb.base/jit-elf.exp b/gdb/testsuite/gdb.base/jit-elf.exp index afc1ac9f96..bf0e253bb9 100644 --- a/gdb/testsuite/gdb.base/jit-elf.exp +++ b/gdb/testsuite/gdb.base/jit-elf.exp @@ -23,42 +23,10 @@ if {[get_compiler_info]} { return 1 } -proc compile_jit_main {binsuffix options} { - global srcdir subdir testfile srcfile binfile - set testfile jit-elf-main - set srcfile ${testfile}.c - set binfile [standard_output_file $testfile$binsuffix] - set options [concat \ - $options \ - debug] - if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \ - executable $options] != "" } { - untested "Failure to compile jit-elf-main" - } -} +load_lib jit-elf-helpers.exp -proc compile_n_jit_so {count} { - global srcdir subdir solib_binfile_targets - set solib_binfile_targets {} - set solib_testfile jit-elf-solib - - for {set i 1} {$i <= $count} {incr i} { - set solib_binfile [standard_output_file ${solib_testfile}.$i.so] - set solib_srcfile "${srcdir}/${subdir}/${solib_testfile}.c" - set solib_binfile_test_msg "SHLIBDIR/${solib_testfile}.$i.so" - - # Note: compiling without debug info by default: some test - # do symbol renaming by munging on ELF symbol table, and that - # wouldn't work for .debug sections. Also, output for "info - # function" changes when debug info is present. - if { [gdb_compile_shlib ${solib_srcfile} ${solib_binfile} {}] != "" } { - untested "Failure to compile ${solib_binfile_test_msg}" - } - - set path [gdb_remote_download target ${solib_binfile}] - lappend solib_binfile_targets $path - } -} +global testfile srcfile binfile solib_binfile_targets +set solib_binfile_targets [compile_n_jit_so 2] # Detach, restart GDB, and re-attach to the program. @@ -149,9 +117,7 @@ proc one_jit_test {count match_str reattach} { } } -compile_jit_main "" {} -compile_n_jit_so 2 - +lassign [compile_jit_main "" {}] testfile srcfile binfile one_jit_test 1 "${hex} jit_function_0001" 0 one_jit_test 2 "${hex} jit_function_0001\[\r\n\]+${hex} jit_function_0002" 0 @@ -159,13 +125,13 @@ one_jit_test 2 "${hex} jit_function_0001\[\r\n\]+${hex} jit_function_0002" 0 # registered. We reuse the normal test, and detach/reattach at # specific interesting points. if {[can_spawn_for_attach]} { - compile_jit_main "-attach" {additional_flags=-DATTACH=1} + lassign [compile_jit_main "-attach" {additional_flags=-DATTACH=1}] testfile srcfile binfile with_test_prefix attach { one_jit_test 2 "${hex} jit_function_0001\[\r\n\]+${hex} jit_function_0002" 1 } } with_test_prefix PIE { - compile_jit_main "-pie" {additional_flags=-fPIE ldflags=-pie} + lassign [compile_jit_main "-pie" {additional_flags=-fPIE ldflags=-pie}] testfile srcfile binfile one_jit_test 1 "${hex} jit_function_0001" 0 } diff --git a/gdb/testsuite/lib/jit-elf-helpers.exp b/gdb/testsuite/lib/jit-elf-helpers.exp new file mode 100644 index 0000000000..f96dfe5ebb --- /dev/null +++ b/gdb/testsuite/lib/jit-elf-helpers.exp @@ -0,0 +1,78 @@ +# Copyright 2020 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 . + +# Compiles jit-elf-main.c as a regular executable + +# Compile the test case program as a stand-alone binary +# BINSUFFIX is appended to the resulting binary name +# OPTIONS is passed to gdb_compile when compiling the program. +proc compile_jit_main {binsuffix options} { + global srcdir subdir + set testfile jit-elf-main + set srcfile ${testfile}.c + set binfile [standard_output_file $testfile$binsuffix] + set options [concat \ + $options \ + debug] + if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \ + executable $options] != "" } { + untested "Failure to compile jit-elf-main" + } + return [list $testfile $srcfile $binfile] +} + +# Compile the test case program as a shared library +proc compile_jit_main_as_so {} { + global srcdir subdir + set testfile jit-elf-main + set srcfile ${testfile}.c + set binfile [standard_output_file $testfile] + set options [list \ + additional_flags="-DMAIN=jit_dl_main" \ + debug] + if { [gdb_compile_shlib "${srcdir}/${subdir}/${srcfile}" "${binfile}" \ + $options] != "" } { + untested "Failure to compile jit-elf-main" + } + return [list $testfile $srcfile $binfile] +} + +# Compile jit-elf-solib.c as multiple shared libraries +# distinguished by a numerical suffix. +# COUNT is amount of shared libraries to build +proc compile_n_jit_so {count} { + global srcdir subdir + set solib_binfile_targets {} + set solib_testfile jit-elf-solib + + for {set i 1} {$i <= $count} {incr i} { + set solib_binfile [standard_output_file $solib_testfile.$i.so] + set solib_srcfile "${srcdir}/${subdir}/$solib_testfile.c" + set solib_binfile_test_msg "SHLIBDIR/$solib_testfile.$i.so" + + # Note: compiling without debug info by default: some test + # do symbol renaming by munging on ELF symbol table, and that + # wouldn't work for .debug sections. Also, output for "info + # function" changes when debug info is present. + if { [gdb_compile_shlib $solib_srcfile $solib_binfile {}] != "" } { + untested "Failure to compile $solib_binfile_test_msg" + } + + set path [gdb_remote_download target $solib_binfile] + set solib_binfile_targets [concat $solib_binfile_targets $path] + } + + return $solib_binfile_targets +} -- 2.25.2 Intel Deutschland GmbH Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany Tel: +49 89 99 8853-0, www.intel.de Managing Directors: Christin Eisenschmid, Gary Kershaw Chairperson of the Supervisory Board: Nicole Lau Registered Office: Munich Commercial Register: Amtsgericht Muenchen HRB 186928