[PATCH v5 2/5] [gdb/testsuite] add lib/jit-elf-helpers.exp

Simon Marchi simark@simark.ca
Tue May 12 00:23:14 GMT 2020


Just some small nits, otherwise the patch LGTM.

On 2020-05-11 6:28 a.m., Mihails Strasuns via Gdb-patches wrote:
> diff --git a/gdb/testsuite/gdb.base/jit-elf-so.exp b/gdb/testsuite/gdb.base/jit-elf-so.exp
> index 59ca1ac8cf..23e5a451b4 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
> @@ -181,7 +135,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
>  }
>  
> @@ -191,7 +146,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]

Align the second line on the square bracket like this, a bit like we do in the C code:

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 29638bd2c0..642653ac6a 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
> @@ -179,13 +130,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]

Same comment about alignment.

> diff --git a/gdb/testsuite/lib/jit-elf-helpers.exp b/gdb/testsuite/lib/jit-elf-helpers.exp
> new file mode 100644
> index 0000000000..de6ac46f05
> --- /dev/null
> +++ b/gdb/testsuite/lib/jit-elf-helpers.exp
> @@ -0,0 +1,80 @@
> +# 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/>.
> +
> +# Compiles jit-elf-main.c as a regular executable
> +
> +# Compile jit-elf-main.c as an executable.

The first of these two comments could be removed, I think.

> +#
> +# 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} {

Update the documentation to match the parameters.

Simon


More information about the Gdb-patches mailing list