public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Mihails Strasuns <mihails.strasuns@intel.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v5 2/5] [gdb/testsuite] add lib/jit-elf-helpers.exp
Date: Mon, 11 May 2020 12:28:52 +0200	[thread overview]
Message-ID: <20200511102855.4987-2-mihails.strasuns@intel.com> (raw)
In-Reply-To: <20200511102855.4987-1-mihails.strasuns@intel.com>

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.
---
 gdb/testsuite/gdb.base/jit-elf-so.exp | 56 ++-----------------
 gdb/testsuite/gdb.base/jit-elf.exp    | 65 +++-------------------
 gdb/testsuite/lib/jit-elf-helpers.exp | 80 +++++++++++++++++++++++++++
 3 files changed, 95 insertions(+), 106 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 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]
 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]
 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
 }
@@ -194,14 +146,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 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.
+#
+# 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
-- 
2.26.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


  reply	other threads:[~2020-05-11 10:26 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <167782>
2020-05-11 10:28 ` [PATCH v5 1/5] [gdb/testsuite] use args as lib list for jit-elf tests Mihails Strasuns
2020-05-11 10:28   ` Mihails Strasuns [this message]
2020-05-12  0:23     ` [PATCH v5 2/5] [gdb/testsuite] add lib/jit-elf-helpers.exp Simon Marchi
2020-05-11 10:28   ` [PATCH v5 3/5] [gdb/testsuite] use -Ttext-segment for jit-elf tests Mihails Strasuns
2020-05-12  0:28     ` Simon Marchi
2020-05-11 10:28   ` [PATCH v5 4/5] [gdb/testsuite] define jit function name via macro Mihails Strasuns
2020-05-12  0:31     ` Simon Marchi
2020-05-11 10:28   ` [PATCH v5 5/5] [gdb/testsuite] add jit-elf-util.h and run jit function Mihails Strasuns
2020-05-12  0:37     ` Simon Marchi
2020-05-12  0:17   ` [PATCH v5 1/5] [gdb/testsuite] use args as lib list for jit-elf tests Simon Marchi
2020-05-12  7:51     ` Strasuns, Mihails
2020-05-12 14:13       ` Simon Marchi
2020-05-12 14:15         ` Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200511102855.4987-2-mihails.strasuns@intel.com \
    --to=mihails.strasuns@intel.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).