diff options
author | Mihails Strasuns <mihails.strasuns@intel.com> | 2020-02-17 11:24:14 +0100 |
---|---|---|
committer | Mihails Strasuns <mihails.strasuns@intel.com> | 2020-05-12 09:52:46 +0200 |
commit | f80120719777e671e871434d727716355d6ab57d (patch) | |
tree | e0328391d206d1885114ccaa0945a9b3fa8ddf53 | |
parent | 9a94694506c636f573b9194d9820fd4842b8fe51 (diff) | |
download | gdb-f80120719777e671e871434d727716355d6ab57d.zip gdb-f80120719777e671e871434d727716355d6ab57d.tar.gz gdb-f80120719777e671e871434d727716355d6ab57d.tar.bz2 |
[gdb/testsuite] add lib/jit-elf-helpers.exp
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 <mihails.strasuns@intel.com>
* 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.
-rw-r--r-- | gdb/testsuite/gdb.base/jit-elf-so.exp | 56 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/jit-elf.exp | 65 | ||||
-rw-r--r-- | gdb/testsuite/lib/jit-elf-helpers.exp | 78 |
3 files changed, 93 insertions, 106 deletions
diff --git a/gdb/testsuite/gdb.base/jit-elf-so.exp b/gdb/testsuite/gdb.base/jit-elf-so.exp index 4f50c44..51c1d33 100644 --- a/gdb/testsuite/gdb.base/jit-elf-so.exp +++ b/gdb/testsuite/gdb.base/jit-elf-so.exp @@ -26,6 +26,8 @@ if {[get_compiler_info]} { return 1 } +load_lib jit-elf-helpers.exp + # The "real" main of this test, which loads jit-elf-main # as a shared library. set main_loader_basename jit-elf-dlmain @@ -41,25 +43,6 @@ set main_solib_binfile [standard_output_file ${main_solib_basename}.so] set jit_solib_basename jit-elf-solib set jit_solib_srcfile ${srcdir}/${subdir}/${jit_solib_basename}.c -# Compile jit-elf-main.c as a shared library. -# -# OPTIONS is passed to gdb_compile when compiling the program. -# -# On success, return 0. -# On failure, return -1. -proc compile_jit_elf_main_as_so {options} { - global main_solib_srcfile main_solib_binfile - set options [concat $options debug] - - if { [gdb_compile_shlib ${main_solib_srcfile} ${main_solib_binfile} \ - $options] != "" } { - untested "failed to compile ${main_solib_basename}.c as a shared library" - return -1 - } - - return 0 -} - # Compile the testcase shared library loader. # # OPTIONS is passed to gdb_compile when compiling the binary. @@ -79,34 +62,6 @@ proc compile_jit_dlmain {options} { return 0 } -# Compile jit-elf-solib.c as a shared library in multiple copies and -# upload them to the target. -# -# On success, return a list of target path to the shared libraries. -# On failure, return -1. -proc compile_and_download_n_jit_so {count} { - global jit_solib_basename jit_solib_srcfile - set binfiles_target {} - - for {set i 1} {$i <= $count} {incr i} { - set binfile [standard_output_file ${jit_solib_basename}.$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 ${jit_solib_srcfile} ${binfile} {}] != "" } { - untested "failed to compile ${jit_solib_basename}.c as a shared library" - return -1 - } - - set path [gdb_remote_download target ${binfile}] - lappend binfiles_target $path - } - - return $binfiles_target -} - # Run $main_loader_binfile and load $main_solib_binfile in # GDB. Check jit-related debug output and matches `info function` # output for a jit loaded function using MATCH_STR. @@ -117,7 +72,6 @@ proc compile_and_download_n_jit_so {count} { # must match. proc one_jit_test {solib_binfiles_target match_str} { set count [llength $solib_binfiles_target] - with_test_prefix "one_jit_test-$count" { global verbose global main_loader_binfile main_loader_srcfile @@ -184,7 +138,8 @@ proc one_jit_test {solib_binfiles_target match_str} { } # Compile the main code (which loads the JIT objects) as a shared library. -if { [compile_jit_elf_main_as_so {additional_flags="-DMAIN=jit_dl_main"}] < 0 } { +if { [compile_jit_elf_main_as_so $main_solib_srcfile $main_solib_binfile \ + {additional_flags="-DMAIN=jit_dl_main"}] < 0 } { return } @@ -194,7 +149,8 @@ if { [compile_jit_dlmain {shlib_load}] < 0 } { } # Compile two shared libraries to use as JIT objects. -set jit_solibs_target [compile_and_download_n_jit_so 2] +set jit_solibs_target [compile_and_download_n_jit_so \ + $jit_solib_basename $jit_solib_srcfile 2] if { $jit_solibs_target == -1 } { return } diff --git a/gdb/testsuite/gdb.base/jit-elf.exp b/gdb/testsuite/gdb.base/jit-elf.exp index 98da57b..68196a0 100644 --- a/gdb/testsuite/gdb.base/jit-elf.exp +++ b/gdb/testsuite/gdb.base/jit-elf.exp @@ -23,8 +23,10 @@ if {[get_compiler_info]} { return 1 } +load_lib jit-elf-helpers.exp + # The main code that loads and registers JIT objects. -set main_basename jit-elf-main +set main_basename "jit-elf-main" set main_srcfile ${srcdir}/${subdir}/${main_basename}.c set main_binfile [standard_output_file ${main_basename}] @@ -32,58 +34,7 @@ set main_binfile [standard_output_file ${main_basename}] set jit_solib_basename jit-elf-solib set jit_solib_srcfile ${srcdir}/${subdir}/${jit_solib_basename}.c -# Compile jit-elf-main.c as an executable. -# -# BINSUFFIX is appended to the binary name. -# OPTIONS is passed to gdb_compile when compiling the program. -# -# On success, return 0. -# On failure, return -1. -proc compile_jit_main {binsuffix options} { - global main_binfile main_srcfile main_basename - - set binfile ${main_binfile}${binsuffix} - set options [concat $options debug] - - if { [gdb_compile ${main_srcfile} ${binfile} \ - executable $options] != "" } { - untested "failed to compile ${main_basename}.c" - return -1 - } - - return 0 -} - -# Compile jit-elf-solib.c as a shared library in multiple copies and -# upload them to the target. -# -# On success, return a list of target paths to the shared libraries. -# On failure, return -1. -proc compile_and_download_n_jit_so {count} { - global jit_solib_basename jit_solib_srcfile - set binfiles_target {} - - for {set i 1} {$i <= $count} {incr i} { - set binfile [standard_output_file ${jit_solib_basename}.$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 ${jit_solib_srcfile} ${binfile} {}] != "" } { - untested "failed to compile ${jit_solib_basename}.c as a shared library" - return -1 - } - - set path [gdb_remote_download target ${binfile}] - lappend binfiles_target $path - } - - return $binfiles_target -} - # Detach, restart GDB, and re-attach to the program. - proc clean_reattach {} { global decimal gdb_prompt global main_binfile main_srcfile @@ -180,13 +131,14 @@ proc one_jit_test {jit_solibs_target match_str reattach} { } # Compile two shared libraries to use as JIT objects. -set jit_solibs_target [compile_and_download_n_jit_so 2] +set jit_solibs_target [compile_and_download_n_jit_so \ + $jit_solib_basename $jit_solib_srcfile 2] if { $jit_solibs_target == -1 } { return } # Compile the main code (which loads the JIT objects). -if { [compile_jit_main "" {}] == 0 } { +if { [compile_jit_main ${main_srcfile} ${main_binfile} {}] == 0 } { one_jit_test [lindex $jit_solibs_target 0] "${hex} jit_function_0001" 0 one_jit_test $jit_solibs_target "${hex} jit_function_0001\[\r\n\]+${hex} jit_function_0002" 0 } @@ -195,14 +147,15 @@ if { [compile_jit_main "" {}] == 0 } { # registered. We reuse the normal test, and detach/reattach at # specific interesting points. if {[can_spawn_for_attach]} { - if { [compile_jit_main "-attach" {additional_flags=-DATTACH=1}] == 0 } { + if { [compile_jit_main ${main_srcfile} ${main_binfile}"-attach" \ + {additional_flags=-DATTACH=1}] == 0 } { with_test_prefix attach { one_jit_test $jit_solibs_target "${hex} jit_function_0001\[\r\n\]+${hex} jit_function_0002" 1 } } } -if { [compile_jit_main "-pie" {additional_flags=-fPIE ldflags=-pie}] == 0 } { +if { [compile_jit_main ${main_srcfile} ${main_binfile}"-pie" {additional_flags=-fPIE ldflags=-pie}] == 0 } { with_test_prefix PIE { one_jit_test [lindex $jit_solibs_target 0] "${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 0000000..91b64f2 --- /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 <http://www.gnu.org/licenses/>. + +# Compile jit-elf-main.c as an executable. +# +# BINSUFFIX is appended to the binary name. +# OPTIONS is passed to gdb_compile when compiling the program. +# +# On success, return 0. +# On failure, return -1. +proc compile_jit_main {main_srcfile main_binfile options} { + set options [concat $options debug] + + if { [gdb_compile ${main_srcfile} ${main_binfile} \ + executable $options] != "" } { + untested "failed to compile ${main_basename}.c" + return -1 + } + + return 0 +} + +# Compile jit-elf-main.c as a shared library. +# +# OPTIONS is passed to gdb_compile when compiling the program. +# +# On success, return 0. +# On failure, return -1. +proc compile_jit_elf_main_as_so {main_solib_srcfile main_solib_binfile options} { + set options [concat $options debug] + + if { [gdb_compile_shlib ${main_solib_srcfile} ${main_solib_binfile} \ + $options] != "" } { + untested "failed to compile ${main_solib_basename}.c as a shared library" + return -1 + } + + return 0 +} + +# Compile jit-elf-solib.c as a shared library in multiple copies and +# upload them to the target. +# +# On success, return a list of target path to the shared libraries. +# On failure, return -1. +proc compile_and_download_n_jit_so {jit_solib_basename jit_solib_srcfile count} { + set binfiles_target {} + + for {set i 1} {$i <= $count} {incr i} { + set binfile [standard_output_file ${jit_solib_basename}.$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 ${jit_solib_srcfile} ${binfile} {}] != "" } { + untested "failed to compile ${jit_solib_basename}.c as a shared library" + return -1 + } + + set path [gdb_remote_download target ${binfile}] + lappend binfiles_target $path + } + + return $binfiles_target +}
\ No newline at end of file |