public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v3 1/9] [gdb/testsuite] allow more registers in reader test
       [not found] <166773>
@ 2020-03-31 17:13 ` Mihails Strasuns
  2020-03-31 17:13   ` [PATCH v3 2/9] [gdb/testsuite] structured rename of jit test files Mihails Strasuns
                     ` (9 more replies)
  0 siblings, 10 replies; 17+ messages in thread
From: Mihails Strasuns @ 2020-03-31 17:13 UTC (permalink / raw)
  To: gdb-patches

Fixes jit-reader test failures on systems that have more registers than
expected by the current condition.

On Intel i9-7920X the following extra registers are printed:

k0             0x0                 0
k1             0x0                 0
k2             0x0                 0
k3             0x0                 0
k4             0x0                 0
k5             0x0                 0
k6             0x0                 0
k7             0x0                 0

gdb/testsuite/ChangeLog:

2020-02-18  Mihails Strasuns  <mihails.strasuns@intel.com>

	* gdb.base/jit-reader.exp: relax register output check

Signed-off-by: Mihails Strasuns <mihails.strasuns@intel.com>
Change-Id: I227ab8691b2363d626f7100216477ab637f619fa
---
 gdb/testsuite/gdb.base/jit-reader.exp | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/gdb/testsuite/gdb.base/jit-reader.exp b/gdb/testsuite/gdb.base/jit-reader.exp
index 7852a5b550..8663f0021d 100644
--- a/gdb/testsuite/gdb.base/jit-reader.exp
+++ b/gdb/testsuite/gdb.base/jit-reader.exp
@@ -66,7 +66,8 @@ proc info_registers_current_frame {sp} {
     set any "\[^\r\n\]*"
 
     set neg_decimal "-?$decimal"
-    gdb_test "info registers" \
+
+    set expected \
 	[multi_line \
 	     "rax            $hex +$neg_decimal" \
 	     "rbx            $hex +$neg_decimal" \
@@ -93,6 +94,11 @@ proc info_registers_current_frame {sp} {
 	     "fs             $hex +$neg_decimal" \
 	     "gs             $hex +$neg_decimal" \
 	    ]
+
+    # There may be more registers.
+    append expected ".*"
+
+    gdb_test "info registers" $expected
 }
 
 proc jit_reader_test {} {
@@ -170,7 +176,8 @@ proc jit_reader_test {} {
 
 		# Since the JIT unwinder only provides RIP/RSP/RBP,
 		# all other registers should show as "<not saved>".
-		gdb_test "info registers" \
+
+		set expected \
 		    [multi_line \
 			 "rax            <not saved>" \
 			 "rbx            <not saved>" \
@@ -198,6 +205,11 @@ proc jit_reader_test {} {
 			 "gs             <not saved>" \
 			]
 
+		# There may be more registers.
+		append expected ".*"
+
+		gdb_test "info registers" $expected
+
 		# Make sure that "info frame" doesn't crash.
 		gdb_test "info frame" "Stack level 1, .*in main.*"
 
-- 
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


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v3 2/9] [gdb/testsuite] structured rename of jit test files
  2020-03-31 17:13 ` [PATCH v3 1/9] [gdb/testsuite] allow more registers in reader test Mihails Strasuns
@ 2020-03-31 17:13   ` Mihails Strasuns
  2020-04-18  2:35     ` Simon Marchi
  2020-03-31 17:13   ` [PATCH v3 3/9] [gdb/testsuite] share jit-protocol.h by all jit tests Mihails Strasuns
                     ` (8 subsequent siblings)
  9 siblings, 1 reply; 17+ messages in thread
From: Mihails Strasuns @ 2020-03-31 17:13 UTC (permalink / raw)
  To: gdb-patches

Reorganizes how JIT related test files to be more clear what are related
to JIT reader system tests and what use JIT from ELF objfiles. Those two
approaches are quite different in GDB implementation and require very
different test setup. Keeping distinction clear at the file name level
makes it easier to maintain the testsuite.

gdb/testsuite/ChangeLog:

2020-02-18  Mihails Strasuns  <mihails.strasuns@intel.com>

	* gdb.base: rename all jit related test and source files

Signed-off-by: Mihails Strasuns <mihails.strasuns@intel.com>
Change-Id: I51524c2791744ebad4ea7cb45185ee4e2cd97993
---
 gdb/testsuite/gdb.base/{jit-dlmain.c => jit-elf-dlmain.c}   | 0
 gdb/testsuite/gdb.base/{jit-main.c => jit-elf-main.c}       | 0
 gdb/testsuite/gdb.base/{jit-so.exp => jit-elf-so.exp}       | 6 +++---
 gdb/testsuite/gdb.base/{jit-solib.c => jit-elf-solib.c}     | 0
 gdb/testsuite/gdb.base/{jit.exp => jit-elf.exp}             | 4 ++--
 gdb/testsuite/gdb.base/{jit-exec.c => jit-reader-exec.c}    | 2 +-
 .../gdb.base/{jit-exec.exp => jit-reader-exec.exp}          | 4 ++--
 gdb/testsuite/gdb.base/{jit-execd.c => jit-reader-execd.c}  | 0
 gdb/testsuite/gdb.base/{jithost.c => jit-reader-host.c}     | 2 +-
 gdb/testsuite/gdb.base/{jithost.h => jit-reader-host.h}     | 0
 .../gdb.base/{jit-simple-dl.c => jit-reader-simple-dl.c}    | 0
 .../gdb.base/{jit-simple-jit.c => jit-reader-simple-jit.c}  | 0
 .../gdb.base/{jit-simple.c => jit-reader-simple.c}          | 2 +-
 .../gdb.base/{jit-simple.exp => jit-reader-simple.exp}      | 0
 gdb/testsuite/gdb.base/{jitreader.c => jit-reader.c}        | 2 +-
 gdb/testsuite/gdb.base/jit-reader.exp                       | 4 ++--
 16 files changed, 13 insertions(+), 13 deletions(-)
 rename gdb/testsuite/gdb.base/{jit-dlmain.c => jit-elf-dlmain.c} (100%)
 rename gdb/testsuite/gdb.base/{jit-main.c => jit-elf-main.c} (100%)
 rename gdb/testsuite/gdb.base/{jit-so.exp => jit-elf-so.exp} (97%)
 rename gdb/testsuite/gdb.base/{jit-solib.c => jit-elf-solib.c} (100%)
 rename gdb/testsuite/gdb.base/{jit.exp => jit-elf.exp} (98%)
 rename gdb/testsuite/gdb.base/{jit-exec.c => jit-reader-exec.c} (96%)
 rename gdb/testsuite/gdb.base/{jit-exec.exp => jit-reader-exec.exp} (95%)
 rename gdb/testsuite/gdb.base/{jit-execd.c => jit-reader-execd.c} (100%)
 rename gdb/testsuite/gdb.base/{jithost.c => jit-reader-host.c} (99%)
 rename gdb/testsuite/gdb.base/{jithost.h => jit-reader-host.h} (100%)
 rename gdb/testsuite/gdb.base/{jit-simple-dl.c => jit-reader-simple-dl.c} (100%)
 rename gdb/testsuite/gdb.base/{jit-simple-jit.c => jit-reader-simple-jit.c} (100%)
 rename gdb/testsuite/gdb.base/{jit-simple.c => jit-reader-simple.c} (96%)
 rename gdb/testsuite/gdb.base/{jit-simple.exp => jit-reader-simple.exp} (100%)
 rename gdb/testsuite/gdb.base/{jitreader.c => jit-reader.c} (99%)

diff --git a/gdb/testsuite/gdb.base/jit-dlmain.c b/gdb/testsuite/gdb.base/jit-elf-dlmain.c
similarity index 100%
rename from gdb/testsuite/gdb.base/jit-dlmain.c
rename to gdb/testsuite/gdb.base/jit-elf-dlmain.c
diff --git a/gdb/testsuite/gdb.base/jit-main.c b/gdb/testsuite/gdb.base/jit-elf-main.c
similarity index 100%
rename from gdb/testsuite/gdb.base/jit-main.c
rename to gdb/testsuite/gdb.base/jit-elf-main.c
diff --git a/gdb/testsuite/gdb.base/jit-so.exp b/gdb/testsuite/gdb.base/jit-elf-so.exp
similarity index 97%
rename from gdb/testsuite/gdb.base/jit-so.exp
rename to gdb/testsuite/gdb.base/jit-elf-so.exp
index 27dcdfa58e..526414f43c 100644
--- a/gdb/testsuite/gdb.base/jit-so.exp
+++ b/gdb/testsuite/gdb.base/jit-elf-so.exp
@@ -30,7 +30,7 @@ if {[get_compiler_info]} {
 # test running programs
 #
 
-set testfile jit-dlmain
+set testfile jit-elf-dlmain
 set srcfile ${testfile}.c
 set binfile [standard_output_file ${testfile}]
 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug shlib_load}] != "" } {
@@ -38,7 +38,7 @@ if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {deb
     return -1
 }
 
-set testfile2 jit-main
+set testfile2 jit-elf-main
 set srcfile2 ${testfile2}.c
 set binfile2 [standard_output_file ${testfile2}.so]
 set binfile2_dlopen [shlib_target_file ${testfile2}.so]
@@ -47,7 +47,7 @@ if { [gdb_compile_shlib "${srcdir}/${subdir}/${srcfile2}" ${binfile2} {debug add
     return -1
 }
 
-set solib_testfile "jit-solib"
+set solib_testfile "jit-elf-solib"
 set solib_srcfile "${srcdir}/${subdir}/${solib_testfile}.c"
 set solib_binfile [standard_output_file ${solib_testfile}.so]
 set solib_binfile_test_msg "SHLIBDIR/${solib_testfile}.so"
diff --git a/gdb/testsuite/gdb.base/jit-solib.c b/gdb/testsuite/gdb.base/jit-elf-solib.c
similarity index 100%
rename from gdb/testsuite/gdb.base/jit-solib.c
rename to gdb/testsuite/gdb.base/jit-elf-solib.c
diff --git a/gdb/testsuite/gdb.base/jit.exp b/gdb/testsuite/gdb.base/jit-elf.exp
similarity index 98%
rename from gdb/testsuite/gdb.base/jit.exp
rename to gdb/testsuite/gdb.base/jit-elf.exp
index 094c37fa3d..71d3e37dfb 100644
--- a/gdb/testsuite/gdb.base/jit.exp
+++ b/gdb/testsuite/gdb.base/jit-elf.exp
@@ -33,7 +33,7 @@ proc compile_jit_test {testname binsuffix options} {
     global solib_testfile solib_srcfile solib_binfile solib_binfile_test_msg
     global solib_binfile_target
 
-    set testfile jit-main
+    set testfile jit-elf-main
     set srcfile ${testfile}.c
     set binfile [standard_output_file $testfile$binsuffix]
     if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
@@ -42,7 +42,7 @@ proc compile_jit_test {testname binsuffix options} {
 	return -1
     }
 
-    set solib_testfile "jit-solib"
+    set solib_testfile "jit-elf-solib"
     set solib_srcfile "${srcdir}/${subdir}/${solib_testfile}.c"
     set solib_binfile [standard_output_file ${solib_testfile}$binsuffix.so]
     set solib_binfile_test_msg "SHLIBDIR/${solib_testfile}$binsuffix.so"
diff --git a/gdb/testsuite/gdb.base/jit-exec.c b/gdb/testsuite/gdb.base/jit-reader-exec.c
similarity index 96%
rename from gdb/testsuite/gdb.base/jit-exec.c
rename to gdb/testsuite/gdb.base/jit-reader-exec.c
index 809308fabe..f92aa5d9da 100644
--- a/gdb/testsuite/gdb.base/jit-exec.c
+++ b/gdb/testsuite/gdb.base/jit-reader-exec.c
@@ -17,7 +17,7 @@
 
 /* Simple standalone program using the JIT API.  */
 
-#include "jit-simple-jit.c"
+#include "jit-reader-simple-jit.c"
 #include <unistd.h>
 
 int
diff --git a/gdb/testsuite/gdb.base/jit-exec.exp b/gdb/testsuite/gdb.base/jit-reader-exec.exp
similarity index 95%
rename from gdb/testsuite/gdb.base/jit-exec.exp
rename to gdb/testsuite/gdb.base/jit-reader-exec.exp
index 327646bb65..4235309f77 100644
--- a/gdb/testsuite/gdb.base/jit-exec.exp
+++ b/gdb/testsuite/gdb.base/jit-reader-exec.exp
@@ -21,9 +21,9 @@ if { ![istarget "*-linux*"] } then {
     return
 }
 
-standard_testfile jit-exec.c
+standard_testfile jit-reader-exec.c
 
-set testfile2 "jit-execd"
+set testfile2 "jit-reader-execd"
 set srcfile2 ${testfile2}.c
 set binfile2 [standard_output_file ${testfile2}]
 
diff --git a/gdb/testsuite/gdb.base/jit-execd.c b/gdb/testsuite/gdb.base/jit-reader-execd.c
similarity index 100%
rename from gdb/testsuite/gdb.base/jit-execd.c
rename to gdb/testsuite/gdb.base/jit-reader-execd.c
diff --git a/gdb/testsuite/gdb.base/jithost.c b/gdb/testsuite/gdb.base/jit-reader-host.c
similarity index 99%
rename from gdb/testsuite/gdb.base/jithost.c
rename to gdb/testsuite/gdb.base/jit-reader-host.c
index 19cc3e16c0..d07acd54bb 100644
--- a/gdb/testsuite/gdb.base/jithost.c
+++ b/gdb/testsuite/gdb.base/jit-reader-host.c
@@ -23,7 +23,7 @@
 #include <sys/mman.h>
 
 #include JIT_READER_H  /* Please see jit-reader.exp for an explanation.  */
-#include "jithost.h"
+#include "jit-reader-host.h"
 #include "jit-protocol.h"
 
 void __attribute__((noinline)) __jit_debug_register_code () { }
diff --git a/gdb/testsuite/gdb.base/jithost.h b/gdb/testsuite/gdb.base/jit-reader-host.h
similarity index 100%
rename from gdb/testsuite/gdb.base/jithost.h
rename to gdb/testsuite/gdb.base/jit-reader-host.h
diff --git a/gdb/testsuite/gdb.base/jit-simple-dl.c b/gdb/testsuite/gdb.base/jit-reader-simple-dl.c
similarity index 100%
rename from gdb/testsuite/gdb.base/jit-simple-dl.c
rename to gdb/testsuite/gdb.base/jit-reader-simple-dl.c
diff --git a/gdb/testsuite/gdb.base/jit-simple-jit.c b/gdb/testsuite/gdb.base/jit-reader-simple-jit.c
similarity index 100%
rename from gdb/testsuite/gdb.base/jit-simple-jit.c
rename to gdb/testsuite/gdb.base/jit-reader-simple-jit.c
diff --git a/gdb/testsuite/gdb.base/jit-simple.c b/gdb/testsuite/gdb.base/jit-reader-simple.c
similarity index 96%
rename from gdb/testsuite/gdb.base/jit-simple.c
rename to gdb/testsuite/gdb.base/jit-reader-simple.c
index 8ea6aec1f1..bcb83f09bf 100644
--- a/gdb/testsuite/gdb.base/jit-simple.c
+++ b/gdb/testsuite/gdb.base/jit-reader-simple.c
@@ -17,7 +17,7 @@
 
 /* Simple standalone program using the JIT API.  */
 
-#include "jit-simple-jit.c"
+#include "jit-reader-simple-jit.c"
 
 int
 main (void)
diff --git a/gdb/testsuite/gdb.base/jit-simple.exp b/gdb/testsuite/gdb.base/jit-reader-simple.exp
similarity index 100%
rename from gdb/testsuite/gdb.base/jit-simple.exp
rename to gdb/testsuite/gdb.base/jit-reader-simple.exp
diff --git a/gdb/testsuite/gdb.base/jitreader.c b/gdb/testsuite/gdb.base/jit-reader.c
similarity index 99%
rename from gdb/testsuite/gdb.base/jitreader.c
rename to gdb/testsuite/gdb.base/jit-reader.c
index d0dc488fec..c5fd7a99be 100644
--- a/gdb/testsuite/gdb.base/jitreader.c
+++ b/gdb/testsuite/gdb.base/jit-reader.c
@@ -21,7 +21,7 @@
 #include <string.h>
 
 #include JIT_READER_H  /* Please see jit-reader.exp for an explanation.  */
-#include "jithost.h"
+#include "jit-reader-host.h"
 
 GDB_DECLARE_GPL_COMPATIBLE_READER;
 
diff --git a/gdb/testsuite/gdb.base/jit-reader.exp b/gdb/testsuite/gdb.base/jit-reader.exp
index 8663f0021d..c0af2fc6a1 100644
--- a/gdb/testsuite/gdb.base/jit-reader.exp
+++ b/gdb/testsuite/gdb.base/jit-reader.exp
@@ -13,7 +13,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-standard_testfile jithost.c
+standard_testfile jit-reader-host.c
 
 if { (![istarget x86_64-*-*] && ![istarget i?86-*-*]) || ![is_lp64_target] } {
     return -1;
@@ -47,7 +47,7 @@ if  { [gdb_compile "${srcdir}/${subdir}/${jit_host_src}" "${jit_host_bin}" \
     return -1
 }
 
-set jit_reader jitreader
+set jit_reader jit-reader
 set jit_reader_src ${jit_reader}.c
 set jit_reader_bin [standard_output_file ${jit_reader}.so]
 
-- 
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


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v3 3/9] [gdb/testsuite] share jit-protocol.h by all jit tests
  2020-03-31 17:13 ` [PATCH v3 1/9] [gdb/testsuite] allow more registers in reader test Mihails Strasuns
  2020-03-31 17:13   ` [PATCH v3 2/9] [gdb/testsuite] structured rename of jit test files Mihails Strasuns
@ 2020-03-31 17:13   ` Mihails Strasuns
  2020-04-18  2:38     ` Simon Marchi
  2020-03-31 17:13   ` [PATCH v3 4/9] [gdb/testsuite] use args as lib list for jit-elf tests Mihails Strasuns
                     ` (7 subsequent siblings)
  9 siblings, 1 reply; 17+ messages in thread
From: Mihails Strasuns @ 2020-03-31 17:13 UTC (permalink / raw)
  To: gdb-patches

There was an existing jit-protocol.h defining common symbols needed for
JIT-supporting application, however, it was only used by few tests.
Others redeclared the same symbols.

This unifies all tests to use jit-protocol.h

gdb/testsuite/ChangeLog:

2020-02-18  Mihails Strasuns  <mihails.strasuns@intel.com>

	* gdb.base/jit-attach-pie.c: use jit-protocol.h
	* gdb.base/jit-elf-main.c: use jit-protocol.h
	* gdb.base/jit-reader-host.c: use jit-protocol.h
	* gdb.base/jit-reader-simple-jit.c: use jit-protocol.h
	* gdb.base/jit-protocol.h: update definitions to match all usage
	  contexts

Change-Id: I0dbfa7b7dcda0ba7b5f09a2d7530dd6dce88fa1e
Signed-off-by: Mihails Strasuns <mihails.strasuns@intel.com>
---
 gdb/testsuite/gdb.base/jit-attach-pie.c       | 24 +-----------
 gdb/testsuite/gdb.base/jit-elf-main.c         | 38 ++-----------------
 gdb/testsuite/gdb.base/jit-protocol.h         |  8 +++-
 gdb/testsuite/gdb.base/jit-reader-host.c      |  3 --
 .../gdb.base/jit-reader-simple-jit.c          | 25 +-----------
 5 files changed, 13 insertions(+), 85 deletions(-)

diff --git a/gdb/testsuite/gdb.base/jit-attach-pie.c b/gdb/testsuite/gdb.base/jit-attach-pie.c
index 55a03f73ae..fd08233521 100644
--- a/gdb/testsuite/gdb.base/jit-attach-pie.c
+++ b/gdb/testsuite/gdb.base/jit-attach-pie.c
@@ -19,29 +19,7 @@
 #include <stdint.h>
 #include <pthread.h>
 
-struct jit_code_entry
-{
-  struct jit_code_entry *next_entry;
-  struct jit_code_entry *prev_entry;
-  const char *symfile_addr;
-  uint64_t symfile_size;
-};
-
-struct jit_descriptor
-{
-  uint32_t version;
-  /* This type should be jit_actions_t, but we use uint32_t
-     to be explicit about the bitwidth.  */
-  uint32_t action_flag;
-  struct jit_code_entry *relevant_entry;
-  struct jit_code_entry *first_entry;
-};
-
-struct jit_descriptor __jit_debug_descriptor = { 1, 0, 0, 0 };
-
-void __jit_debug_register_code()
-{
-}
+#include "jit-protocol.h"
 
 static void *
 thread_proc (void *arg)
diff --git a/gdb/testsuite/gdb.base/jit-elf-main.c b/gdb/testsuite/gdb.base/jit-elf-main.c
index 40958ef5b5..fe0f540d6f 100644
--- a/gdb/testsuite/gdb.base/jit-elf-main.c
+++ b/gdb/testsuite/gdb.base/jit-elf-main.c
@@ -29,6 +29,8 @@
 #include <sys/stat.h>
 #include <unistd.h>
 
+#include "jit-protocol.h"
+
 /* ElfW is coming from linux. On other platforms it does not exist.
    Let us define it here. */
 #ifndef ElfW
@@ -42,38 +44,6 @@
 #define _ElfW_1(e,w,t)  e##w##t
 #endif /* !ElfW  */
 
-typedef enum
-{
-  JIT_NOACTION = 0,
-  JIT_REGISTER_FN,
-  JIT_UNREGISTER_FN
-} jit_actions_t;
-
-struct jit_code_entry
-{
-  struct jit_code_entry *next_entry;
-  struct jit_code_entry *prev_entry;
-  const char *symfile_addr;
-  uint64_t symfile_size;
-};
-
-struct jit_descriptor
-{
-  uint32_t version;
-  /* This type should be jit_actions_t, but we use uint32_t
-     to be explicit about the bitwidth.  */
-  uint32_t action_flag;
-  struct jit_code_entry *relevant_entry;
-  struct jit_code_entry *first_entry;
-};
-
-/* GDB puts a breakpoint in this function.  */
-void __attribute__((noinline)) __jit_debug_register_code () { }
-
-/* Make sure to specify the version statically, because the
-   debugger may check the version before we can set it.  */
-struct jit_descriptor __jit_debug_descriptor = { 1, 0, 0, 0 };
-
 static void
 usage (const char *const argv0)
 {
@@ -203,7 +173,7 @@ MAIN (int argc, char *argv[])
 	__jit_debug_descriptor.first_entry = entry;
 
       /* Notify GDB.  */
-      __jit_debug_descriptor.action_flag = JIT_REGISTER_FN;
+      __jit_debug_descriptor.action_flag = JIT_REGISTER;
       __jit_debug_register_code ();
     }
 
@@ -225,7 +195,7 @@ MAIN (int argc, char *argv[])
 	__jit_debug_descriptor.first_entry = NULL;
 
       /* Notify GDB.  */
-      __jit_debug_descriptor.action_flag = JIT_UNREGISTER_FN;
+      __jit_debug_descriptor.action_flag = JIT_UNREGISTER;
       __jit_debug_register_code ();
 
       __jit_debug_descriptor.relevant_entry = prev_entry;
diff --git a/gdb/testsuite/gdb.base/jit-protocol.h b/gdb/testsuite/gdb.base/jit-protocol.h
index 458523e5ff..2b2e902fe7 100644
--- a/gdb/testsuite/gdb.base/jit-protocol.h
+++ b/gdb/testsuite/gdb.base/jit-protocol.h
@@ -38,7 +38,7 @@ struct jit_code_entry
 {
   struct jit_code_entry *next_entry;
   struct jit_code_entry *prev_entry;
-  void *symfile_addr;
+  const void *symfile_addr;
   uint64_t symfile_size;
 };
 
@@ -51,4 +51,10 @@ struct jit_descriptor
   struct jit_code_entry *first_entry;
 };
 
+struct jit_descriptor __jit_debug_descriptor = { 1, 0, 0, 0 };
+
+void __attribute__((noinline)) __jit_debug_register_code()
+{
+}
+
 #endif /* JIT_PROTOCOL_H */
diff --git a/gdb/testsuite/gdb.base/jit-reader-host.c b/gdb/testsuite/gdb.base/jit-reader-host.c
index d07acd54bb..f9c4833083 100644
--- a/gdb/testsuite/gdb.base/jit-reader-host.c
+++ b/gdb/testsuite/gdb.base/jit-reader-host.c
@@ -26,9 +26,6 @@
 #include "jit-reader-host.h"
 #include "jit-protocol.h"
 
-void __attribute__((noinline)) __jit_debug_register_code () { }
-
-struct jit_descriptor __jit_debug_descriptor = { 1, 0, 0, 0 };
 struct jit_code_entry only_entry;
 
 typedef void (jit_function_stack_mangle_t) (void);
diff --git a/gdb/testsuite/gdb.base/jit-reader-simple-jit.c b/gdb/testsuite/gdb.base/jit-reader-simple-jit.c
index 407666b98b..f446bf2d96 100644
--- a/gdb/testsuite/gdb.base/jit-reader-simple-jit.c
+++ b/gdb/testsuite/gdb.base/jit-reader-simple-jit.c
@@ -19,32 +19,9 @@
 
 #include <stdint.h>
 
-struct jit_code_entry
-{
-  struct jit_code_entry *next_entry;
-  struct jit_code_entry *prev_entry;
-  const char *symfile_addr;
-  uint64_t symfile_size;
-};
-
-struct jit_descriptor
-{
-  uint32_t version;
-  /* This type should be jit_actions_t, but we use uint32_t
-     to be explicit about the bitwidth.  */
-  uint32_t action_flag;
-  struct jit_code_entry *relevant_entry;
-  struct jit_code_entry *first_entry;
-};
-
 #ifdef SPACER
 /* This exists to change the address of __jit_debug_descriptor.  */
 int spacer = 4;
 #endif
 
-struct jit_descriptor __jit_debug_descriptor = { 1, 0, 0, 0 };
-
-void
-__jit_debug_register_code (void)
-{
-}
+#include "jit-protocol.h"
\ No newline at end of file
-- 
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


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v3 4/9] [gdb/testsuite] use args as lib list for jit-elf tests
  2020-03-31 17:13 ` [PATCH v3 1/9] [gdb/testsuite] allow more registers in reader test Mihails Strasuns
  2020-03-31 17:13   ` [PATCH v3 2/9] [gdb/testsuite] structured rename of jit test files Mihails Strasuns
  2020-03-31 17:13   ` [PATCH v3 3/9] [gdb/testsuite] share jit-protocol.h by all jit tests Mihails Strasuns
@ 2020-03-31 17:13   ` Mihails Strasuns
  2020-04-18  2:58     ` Simon Marchi
  2020-03-31 17:13   ` [PATCH v3 5/9] [gdb/testsuite] add lib/jit-elf-helpers.exp Mihails Strasuns
                     ` (6 subsequent siblings)
  9 siblings, 1 reply; 17+ messages in thread
From: Mihails Strasuns @ 2020-03-31 17:13 UTC (permalink / raw)
  To: gdb-patches

Old usage: jit-elf-main lib.so 2
New usage: jit-elf-main lib.so.1 lib.so.2

Refactoring necessary to support running tests over multiple jit
binaries rather than mapping the same binary muultiple times.

gdb/testsuite/ChangeLog:

2020-02-18  Mihails Strasuns  <mihails.strasuns@intel.com>

	* gdb.base/jit-elf-main.c: read lib list from argc/argv
	* gdb.base/jit-elf.exp: compile N jit libraries and use the list
	* gdb.base/jit-elf-so.exp: ditto

Change-Id: Ie8f85ec6358604c14557b0417d6621b2f8942033
Signed-off-by: Mihails Strasuns <mihails.strasuns@intel.com>
---
 gdb/testsuite/gdb.base/jit-elf-main.c |  55 +++++-------
 gdb/testsuite/gdb.base/jit-elf-so.exp | 115 ++++++++++++++++----------
 gdb/testsuite/gdb.base/jit-elf.exp    |  99 +++++++++++-----------
 3 files changed, 141 insertions(+), 128 deletions(-)

diff --git a/gdb/testsuite/gdb.base/jit-elf-main.c b/gdb/testsuite/gdb.base/jit-elf-main.c
index fe0f540d6f..66c6e10f24 100644
--- a/gdb/testsuite/gdb.base/jit-elf-main.c
+++ b/gdb/testsuite/gdb.base/jit-elf-main.c
@@ -45,9 +45,9 @@
 #endif /* !ElfW  */
 
 static void
-usage (const char *const argv0)
+usage (void)
 {
-  fprintf (stderr, "Usage: %s library [count]\n", argv0);
+  fprintf (stderr, "Usage: jit-elf-main libraries...\n");
   exit (1);
 }
 
@@ -106,49 +106,38 @@ int mypid;
 int
 MAIN (int argc, char *argv[])
 {
-  /* These variables are here so they can easily be set from jit.exp.  */
-  const char *libname = NULL;
-  int count = 0, i, fd;
-  struct stat st;
-
+  int i;
   alarm (300);
+  char* fake_argv[10]; // used as backing storage for GDB to populate argv
 
   mypid = getpid ();
-
-  count = count;  /* gdb break here 0  */
+  /* gdb break here 0  */
 
   if (argc < 2)
     {
-      usage (argv[0]);
+      usage ();
       exit (1);
     }
 
-  if (libname == NULL)
-    /* Only set if not already set from GDB.  */
-    libname = argv[1];
-
-  if (argc > 2 && count == 0)
-    /* Only set if not already set from GDB.  */
-    count = atoi (argv[2]);
-
-  printf ("%s:%d: libname = %s, count = %d\n", __FILE__, __LINE__,
-	  libname, count);
-
-  if ((fd = open (libname, O_RDONLY)) == -1)
+  for (i = 1; i < argc; ++i)
     {
-      fprintf (stderr, "open (\"%s\", O_RDONLY): %s\n", libname,
-	       strerror (errno));
-      exit (1);
-    }
+      struct stat st;
+      int fd;
 
-  if (fstat (fd, &st) != 0)
-    {
-      fprintf (stderr, "fstat (\"%d\"): %s\n", fd, strerror (errno));
-      exit (1);
-    }
+      printf ("%s:%d: libname = %s, i = %d\n", __FILE__, __LINE__, argv[i], i);
+      if ((fd = open (argv[i], O_RDONLY)) == -1)
+	{
+	  fprintf (stderr, "open (\"%s\", O_RDONLY): %s\n", argv[i],
+		   strerror (errno));
+	  exit (1);
+	}
+
+      if (fstat (fd, &st) != 0)
+	{
+	  fprintf (stderr, "fstat (\"%d\"): %s\n", fd, strerror (errno));
+	  exit (1);
+	}
 
-  for (i = 0; i < count; ++i)
-    {
       const void *const addr = mmap (0, st.st_size, PROT_READ|PROT_WRITE,
 				     MAP_PRIVATE, fd, 0);
       struct jit_code_entry *const entry = calloc (1, sizeof (*entry));
diff --git a/gdb/testsuite/gdb.base/jit-elf-so.exp b/gdb/testsuite/gdb.base/jit-elf-so.exp
index 526414f43c..bcd72eb2bf 100644
--- a/gdb/testsuite/gdb.base/jit-elf-so.exp
+++ b/gdb/testsuite/gdb.base/jit-elf-so.exp
@@ -26,45 +26,68 @@ if {[get_compiler_info]} {
     return 1
 }
 
-#
-# test running programs
-#
-
-set testfile jit-elf-dlmain
-set srcfile ${testfile}.c
-set binfile [standard_output_file ${testfile}]
-if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug shlib_load}] != "" } {
-    untested "failed to compile"
-    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] != "" } {
+	untested "Failure to compile jit-elf-main"
+    }
 }
 
-set testfile2 jit-elf-main
-set srcfile2 ${testfile2}.c
-set binfile2 [standard_output_file ${testfile2}.so]
-set binfile2_dlopen [shlib_target_file ${testfile2}.so]
-if { [gdb_compile_shlib "${srcdir}/${subdir}/${srcfile2}" ${binfile2} {debug additional_flags="-DMAIN=jit_dl_main"}] != "" } {
-    untested "failed to compile main shared library"
-    return -1
+# 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"
+    }
 }
 
-set solib_testfile "jit-elf-solib"
-set solib_srcfile "${srcdir}/${subdir}/${solib_testfile}.c"
-set solib_binfile [standard_output_file ${solib_testfile}.so]
-set solib_binfile_test_msg "SHLIBDIR/${solib_testfile}.so"
+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}"
+	}
 
-# Note: compiling without debug info: the library goes through symbol
-# renaming by munging on its symbol table, and that wouldn't work for .debug
-# sections.  Also, output for "info function" changes when debug info is resent.
-if { [gdb_compile_shlib ${solib_srcfile} ${solib_binfile} {}] != "" } {
-    untested "failed to compile jit shared library"
-    return -1
+	set path [gdb_remote_download target ${solib_binfile}]
+	lappend solib_binfile_targets $path
+    }
 }
 
-set solib_binfile_target [gdb_remote_download target ${solib_binfile}]
+compile_jit_main {additional_flags="-DMAIN=jit_dl_main"}
+compile_jit_dlmain {shlib_load}
+compile_n_jit_so 2
 
 proc one_jit_test {count match_str} {
     with_test_prefix "one_jit_test-$count" {
-	global verbose testfile srcfile2 binfile2 binfile2_dlopen solib_binfile_target solib_binfile_test_msg
+	global verbose testfile srcfile2 binfile2 solib_binfile_targets
 
 	clean_restart $testfile
 	gdb_load_shlib $binfile2
@@ -81,9 +104,16 @@ proc one_jit_test {count match_str} {
 
 	gdb_breakpoint [gdb_get_line_number "break here before-dlopen" ]
 	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_dlopen\""
+	gdb_test_no_output "set var jit_libname = \"$binfile2\""
+	incr count
+	gdb_test "set var argc=$count"
+	gdb_test "set var argv=fake_argv"
+	for {set i 1} {$i < $count} {incr i} {
+	    gdb_test "set var argv\[$i\]=\"[lindex $solib_binfile_targets [expr $i-1]]\""
+	}
 
 	gdb_breakpoint [gdb_get_line_number "break here after-dlopen" ]
 	gdb_continue_to_breakpoint "break here after-dlopen"
@@ -91,10 +121,6 @@ proc one_jit_test {count match_str} {
 	gdb_breakpoint "$srcfile2:[gdb_get_line_number {break here 0} $srcfile2]"
 	gdb_continue_to_breakpoint "break here 0"
 
-	gdb_test_no_output "set var argc = 2"
-	gdb_test_no_output "set var libname = \"$solib_binfile_target\"" "set var libname = \"$solib_binfile_test_msg\""
-	gdb_test_no_output "set var count = $count"
-
 	gdb_breakpoint "$srcfile2:[gdb_get_line_number {break here 1} $srcfile2]"
 	gdb_continue_to_breakpoint "break here 1"
 
@@ -114,12 +140,15 @@ proc one_jit_test {count match_str} {
     }
 }
 
-one_jit_test 1 "${hex}  jit_function_0000"
-one_jit_test 2 "${hex}  jit_function_0000\[\r\n\]+${hex}  jit_function_0001"
-
-# We don't intend to load the .so as a JIT debuginfo reader, but we
-# need some handy file name for a completion test.
-gdb_test \
-    "complete jit-reader-load [standard_output_file ${solib_testfile}.s]" \
-    "jit-reader-load $solib_binfile" \
-    "test jit-reader-load filename completion"
+one_jit_test 1 "${hex}  jit_function_0001"
+one_jit_test 2 "${hex}  jit_function_0001\[\r\n\]+${hex}  jit_function_0002"
+
+foreach solib $solib_binfile_targets {
+    # We don't intend to load the .so as a JIT debuginfo reader, but we
+    # need some handy file name for a completion test.
+    set input [string range $solib 0 [expr { [string length $solib] - 2 }]]
+    gdb_test \
+	"complete jit-reader-load [standard_output_file $input]" \
+	"jit-reader-load $solib" \
+	"test jit-reader-load filename completion"
+}
diff --git a/gdb/testsuite/gdb.base/jit-elf.exp b/gdb/testsuite/gdb.base/jit-elf.exp
index 71d3e37dfb..afc1ac9f96 100644
--- a/gdb/testsuite/gdb.base/jit-elf.exp
+++ b/gdb/testsuite/gdb.base/jit-elf.exp
@@ -23,42 +23,41 @@ if {[get_compiler_info]} {
     return 1
 }
 
-# Compile the testcase program and library.  BINSUFFIX is the suffix
-# to append to the program and library filenames, to make them unique
-# between invocations.  OPTIONS is passed to gdb_compile when
-# compiling the program.
-
-proc compile_jit_test {testname binsuffix options} {
-    global testfile srcfile binfile srcdir subdir
-    global solib_testfile solib_srcfile solib_binfile solib_binfile_test_msg
-    global solib_binfile_target
-
+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 [concat debug $options]] != "" } {
-	untested $testname
-	return -1
-    }
-
-    set solib_testfile "jit-elf-solib"
-    set solib_srcfile "${srcdir}/${subdir}/${solib_testfile}.c"
-    set solib_binfile [standard_output_file ${solib_testfile}$binsuffix.so]
-    set solib_binfile_test_msg "SHLIBDIR/${solib_testfile}$binsuffix.so"
-
-    # Note: compiling without debug info: the library goes through
-    # symbol renaming by munging on its 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} {-fPIC}] != "" } {
-	untested $testname
-	return -1
+	  executable $options] != "" } {
+	      untested "Failure to compile jit-elf-main"
     }
+}
 
-    set solib_binfile_target [gdb_remote_download target ${solib_binfile}]
+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}"
+	}
 
-    return 0
+	set path [gdb_remote_download target ${solib_binfile}]
+	lappend solib_binfile_targets $path
+    }
 }
 
 # Detach, restart GDB, and re-attach to the program.
@@ -105,7 +104,7 @@ proc continue_to_test_location {location reattach} {
 
 proc one_jit_test {count match_str reattach} {
     with_test_prefix "one_jit_test-$count" {
-	global verbose testfile solib_binfile_target solib_binfile_test_msg
+	global verbose testfile solib_binfile_targets
 
 	clean_restart $testfile
 
@@ -119,14 +118,18 @@ proc one_jit_test {count match_str reattach} {
 	    return
 	}
 
+	# Poke desired values directly into inferior instead of using "set args"
+	# because "set args" does not work under gdbserver.
+	incr count
+	gdb_test "set var argc=$count"
+	gdb_test "set var argv=fake_argv"
+	for {set i 1} {$i < $count} {incr i} {
+	    gdb_test "set var argv\[$i\]=\"[lindex $solib_binfile_targets [expr $i-1]]\""
+	}
+
 	gdb_breakpoint [gdb_get_line_number "break here 0"]
 	gdb_continue_to_breakpoint "break here 0"
 
-	# 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 argc = 2"
-	gdb_test_no_output "set var libname = \"$solib_binfile_target\"" "set var libname = \"$solib_binfile_test_msg\""
-	gdb_test_no_output "set var count = $count"
 
 	continue_to_test_location "break here 1" $reattach
 
@@ -146,31 +149,23 @@ proc one_jit_test {count match_str reattach} {
     }
 }
 
-if {[compile_jit_test jit.exp "" {}] < 0} {
-    return
-}
-one_jit_test 1 "${hex}  jit_function_0000" 0
-one_jit_test 2 "${hex}  jit_function_0000\[\r\n\]+${hex}  jit_function_0001" 0
+compile_jit_main "" {}
+compile_n_jit_so 2
+
+one_jit_test 1 "${hex}  jit_function_0001" 0
+one_jit_test 2 "${hex}  jit_function_0001\[\r\n\]+${hex}  jit_function_0002" 0
 
 # Test attaching to an inferior with some JIT libraries already
 # registered.  We reuse the normal test, and detach/reattach at
 # specific interesting points.
 if {[can_spawn_for_attach]} {
-    if {[compile_jit_test "jit.exp attach tests" \
-	     "-attach" {additional_flags=-DATTACH=1}] < 0} {
-	return
-    }
-
+    compile_jit_main "-attach" {additional_flags=-DATTACH=1}
     with_test_prefix attach {
-	one_jit_test 2 "${hex}  jit_function_0000\[\r\n\]+${hex}  jit_function_0001" 1
+	one_jit_test 2 "${hex}  jit_function_0001\[\r\n\]+${hex}  jit_function_0002" 1
     }
 }
 
 with_test_prefix PIE {
-    if {[compile_jit_test "jit.exp PIE tests" \
-	     "-pie" {additional_flags=-fPIE ldflags=-pie}] < 0} {
-	return
-    }
-
-    one_jit_test 1 "${hex}  jit_function_0000" 0
+    compile_jit_main "-pie" {additional_flags=-fPIE ldflags=-pie}
+    one_jit_test 1 "${hex}  jit_function_0001" 0
 }
-- 
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


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v3 5/9] [gdb/testsuite] add lib/jit-elf-helpers.exp
  2020-03-31 17:13 ` [PATCH v3 1/9] [gdb/testsuite] allow more registers in reader test Mihails Strasuns
                     ` (2 preceding siblings ...)
  2020-03-31 17:13   ` [PATCH v3 4/9] [gdb/testsuite] use args as lib list for jit-elf tests Mihails Strasuns
@ 2020-03-31 17:13   ` Mihails Strasuns
  2020-03-31 17:13   ` [PATCH v3 6/9] [gdb/testsuite] use -Ttext-segment for jit-elf tests Mihails Strasuns
                     ` (5 subsequent siblings)
  9 siblings, 0 replies; 17+ messages in thread
From: Mihails Strasuns @ 2020-03-31 17:13 UTC (permalink / raw)
  To: gdb-patches

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

Change-Id: I2fda518406aeca55e82df45edd67cef149497bbe
Signed-off-by: Mihails Strasuns <mihails.strasuns@intel.com>
---
 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 <http://www.gnu.org/licenses/>.
+
+# 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


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v3 6/9] [gdb/testsuite] use -Ttext-segment for jit-elf tests
  2020-03-31 17:13 ` [PATCH v3 1/9] [gdb/testsuite] allow more registers in reader test Mihails Strasuns
                     ` (3 preceding siblings ...)
  2020-03-31 17:13   ` [PATCH v3 5/9] [gdb/testsuite] add lib/jit-elf-helpers.exp Mihails Strasuns
@ 2020-03-31 17:13   ` Mihails Strasuns
  2020-03-31 17:13   ` [PATCH v3 7/9] [gdb/testsuite] define jit function name via macro Mihails Strasuns
                     ` (4 subsequent siblings)
  9 siblings, 0 replies; 17+ messages in thread
From: Mihails Strasuns @ 2020-03-31 17:13 UTC (permalink / raw)
  To: gdb-patches

Removes the need to manually relocate loaded ELF binary by using a fixed
constant as both mmap base address and as a requested first segment
address supplied to the linker.

In future will enable JIT tests with a valid DWARF debug info.  Current
tests still need to compile without a debug info though, because they do
a function name modification.

gdb/testsuite/ChangeLog:

2020-02-18  Mihails Strasuns  <mihails.strasuns@intel.com>

	* lib/jit-elf-helpers.exp: supply -Ttext-segment linker flag and
	  define LOAD_ADDRESS/LOAD_INCREMENT macros for the compiled binaries
	* gdb.base/jit-elf-main.c: use LOAD_ADDRESS/LOAD_INCREMENT to
	  calculate the mmap address

Change-Id: Ifdd70d2838d9235e5d4fb49b7cafd03cb4865751
Signed-off-by: Mihails Strasuns <mihails.strasuns@intel.com>
---
 gdb/testsuite/gdb.base/jit-elf-main.c | 27 +++++++++++++++------------
 gdb/testsuite/lib/jit-elf-helpers.exp | 20 +++++++++++++++++++-
 2 files changed, 34 insertions(+), 13 deletions(-)

diff --git a/gdb/testsuite/gdb.base/jit-elf-main.c b/gdb/testsuite/gdb.base/jit-elf-main.c
index 66c6e10f24..edf2f692f8 100644
--- a/gdb/testsuite/gdb.base/jit-elf-main.c
+++ b/gdb/testsuite/gdb.base/jit-elf-main.c
@@ -51,20 +51,16 @@ usage (void)
   exit (1);
 }
 
-/* Update .p_vaddr and .sh_addr as if the code was JITted to ADDR.  */
+/* Rename jit_function_XXXX to match idx  */
 
 static void
-update_locations (const void *const addr, int idx)
+update_name (const void *const addr, int idx)
 {
   const ElfW (Ehdr) *const ehdr = (ElfW (Ehdr) *)addr;
   ElfW (Shdr) *const shdr = (ElfW (Shdr) *)((char *)addr + ehdr->e_shoff);
   ElfW (Phdr) *const phdr = (ElfW (Phdr) *)((char *)addr + ehdr->e_phoff);
   int i;
 
-  for (i = 0; i < ehdr->e_phnum; ++i)
-    if (phdr[i].p_type == PT_LOAD)
-      phdr[i].p_vaddr += (ElfW (Addr))addr;
-
   for (i = 0; i < ehdr->e_shnum; ++i)
     {
       if (shdr[i].sh_type == SHT_STRTAB)
@@ -81,9 +77,6 @@ update_locations (const void *const addr, int idx)
             if (strcmp (p, "jit_function_XXXX") == 0)
               sprintf (p, "jit_function_%04d", idx);
         }
-
-      if (shdr[i].sh_flags & SHF_ALLOC)
-        shdr[i].sh_addr += (ElfW (Addr))addr;
     }
 }
 
@@ -96,6 +89,15 @@ update_locations (const void *const addr, int idx)
 #define MAIN main
 #endif
 
+/* Must be defined by .exp file when compiling to know
+   what address to map the ELF binary to.  */
+#ifndef LOAD_ADDRESS
+#error "Must define LOAD_ADDRESS"
+#endif
+#ifndef LOAD_INCREMENT
+#error "Must define LOAD_INCREMENT"
+#endif
+
 /* Used to spin waiting for GDB.  */
 volatile int wait_for_gdb = ATTACH;
 #define WAIT_FOR_GDB while (wait_for_gdb)
@@ -138,8 +140,9 @@ MAIN (int argc, char *argv[])
 	  exit (1);
 	}
 
-      const void *const addr = mmap (0, st.st_size, PROT_READ|PROT_WRITE,
-				     MAP_PRIVATE, fd, 0);
+      void* load_addr = (void*) (size_t) (LOAD_ADDRESS + (i - 1) * LOAD_INCREMENT);
+      const void *const addr = mmap (load_addr, st.st_size, PROT_READ|PROT_WRITE,
+				     MAP_PRIVATE | MAP_FIXED, fd, 0);
       struct jit_code_entry *const entry = calloc (1, sizeof (*entry));
 
       if (addr == MAP_FAILED)
@@ -148,7 +151,7 @@ MAIN (int argc, char *argv[])
 	  exit (1);
 	}
 
-      update_locations (addr, i);
+      update_name (addr, i);
 
       /* Link entry at the end of the list.  */
       entry->symfile_addr = (const char *)addr;
diff --git a/gdb/testsuite/lib/jit-elf-helpers.exp b/gdb/testsuite/lib/jit-elf-helpers.exp
index f96dfe5ebb..4d88ea3900 100644
--- a/gdb/testsuite/lib/jit-elf-helpers.exp
+++ b/gdb/testsuite/lib/jit-elf-helpers.exp
@@ -13,6 +13,13 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+# Magic constants used to calculate a starting address when linking
+# "jit" shared libraries.  When loaded, will be mapped by jit-elf-main
+# to the same address.
+
+set load_address   0x7000000
+set load_increment 0x1000000
+
 # Compiles jit-elf-main.c as a regular executable
 
 # Compile the test case program as a stand-alone binary
@@ -20,11 +27,14 @@
 # OPTIONS is passed to gdb_compile when compiling the program.
 proc compile_jit_main {binsuffix options} {
     global srcdir subdir
+    global load_address load_increment
     set testfile jit-elf-main
     set srcfile ${testfile}.c
     set binfile [standard_output_file $testfile$binsuffix]
     set options [concat \
 	$options \
+	additional_flags=-DLOAD_ADDRESS=$load_address \
+	additional_flags=-DLOAD_INCREMENT=$load_increment \
 	debug]
     if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
 	    executable $options] != "" } {
@@ -36,11 +46,14 @@ proc compile_jit_main {binsuffix options} {
 # Compile the test case program as a shared library
 proc compile_jit_main_as_so {} {
     global srcdir subdir
+    global load_address load_increment
     set testfile jit-elf-main
     set srcfile ${testfile}.c
     set binfile [standard_output_file $testfile]
     set options [list \
 	additional_flags="-DMAIN=jit_dl_main" \
+	additional_flags=-DLOAD_ADDRESS=$load_address \
+	additional_flags=-DLOAD_INCREMENT=$load_increment \
 	debug]
     if { [gdb_compile_shlib "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
 	    $options] != "" } {
@@ -54,6 +67,7 @@ proc compile_jit_main_as_so {} {
 # COUNT is amount of shared libraries to build
 proc compile_n_jit_so {count} {
     global srcdir subdir
+    global load_address load_increment
     set solib_binfile_targets {}
     set solib_testfile jit-elf-solib
 
@@ -66,7 +80,11 @@ proc compile_n_jit_so {count} {
 	# 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 {}] != "" } {
+	set addr [format 0x%x [expr $load_address + $load_increment * [expr $i-1]]]
+	set options [list \
+	    additional_flags=-Xlinker \
+	    additional_flags=-Ttext-segment=$addr]
+	if { [gdb_compile_shlib $solib_srcfile $solib_binfile $options] != "" } {
 	    untested "Failure to compile $solib_binfile_test_msg"
 	}
 
-- 
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


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v3 7/9] [gdb/testsuite] define jit function name via macro
  2020-03-31 17:13 ` [PATCH v3 1/9] [gdb/testsuite] allow more registers in reader test Mihails Strasuns
                     ` (4 preceding siblings ...)
  2020-03-31 17:13   ` [PATCH v3 6/9] [gdb/testsuite] use -Ttext-segment for jit-elf tests Mihails Strasuns
@ 2020-03-31 17:13   ` Mihails Strasuns
  2020-03-31 17:13   ` [PATCH v3 8/9] [gdb/testsuite] add jit-elf-util.h and run jit function Mihails Strasuns
                     ` (3 subsequent siblings)
  9 siblings, 0 replies; 17+ messages in thread
From: Mihails Strasuns @ 2020-03-31 17:13 UTC (permalink / raw)
  To: gdb-patches

Replaces previous approach with patching resulting ELF binary after
loading - now that each test iteration works on a separately compiled
binary it is not necessary anymore.

Tests are still being ran without debug info to preserve original test
functionality but this change opens up the possibility to enable debug
info if needed too.

gdb/testsuite/ChangeLog:

2020-03-27  Mihails Strasuns  <mihails.strasuns@intel.com>

	* lib/jit-elf-helpers.exp: supply -DFUNCTION_NAME macro
	  definition when compiling jit-elf-solib.co
	* gdb.base/jit-elf-main.c: stop patching jit function name
	* gdb.base/jit-elf-solib.c: use FUNCTION_NAME macro value as a
	  function name

Signed-off-by: Mihails Strasuns <mihails.strasuns@intel.com>
Change-Id: Ie9296dd374cd1ae11c7d1b8bbe4f0b6b1d5e21b5
---
 gdb/testsuite/gdb.base/jit-elf-main.c  | 31 --------------------------
 gdb/testsuite/gdb.base/jit-elf-solib.c |  6 ++---
 gdb/testsuite/lib/jit-elf-helpers.exp  |  1 +
 3 files changed, 4 insertions(+), 34 deletions(-)

diff --git a/gdb/testsuite/gdb.base/jit-elf-main.c b/gdb/testsuite/gdb.base/jit-elf-main.c
index edf2f692f8..e25ea3f524 100644
--- a/gdb/testsuite/gdb.base/jit-elf-main.c
+++ b/gdb/testsuite/gdb.base/jit-elf-main.c
@@ -51,35 +51,6 @@ usage (void)
   exit (1);
 }
 
-/* Rename jit_function_XXXX to match idx  */
-
-static void
-update_name (const void *const addr, int idx)
-{
-  const ElfW (Ehdr) *const ehdr = (ElfW (Ehdr) *)addr;
-  ElfW (Shdr) *const shdr = (ElfW (Shdr) *)((char *)addr + ehdr->e_shoff);
-  ElfW (Phdr) *const phdr = (ElfW (Phdr) *)((char *)addr + ehdr->e_phoff);
-  int i;
-
-  for (i = 0; i < ehdr->e_shnum; ++i)
-    {
-      if (shdr[i].sh_type == SHT_STRTAB)
-        {
-          /* Note: we update both .strtab and .dynstr.  The latter would
-             not be correct if this were a regular shared library (.hash
-             would be wrong), but this is a simulation -- the library is
-             never exposed to the dynamic loader, so it all ends up ok.  */
-          char *const strtab = (char *)((ElfW (Addr))addr + shdr[i].sh_offset);
-          char *const strtab_end = strtab + shdr[i].sh_size;
-          char *p;
-
-          for (p = strtab; p < strtab_end; p += strlen (p) + 1)
-            if (strcmp (p, "jit_function_XXXX") == 0)
-              sprintf (p, "jit_function_%04d", idx);
-        }
-    }
-}
-
 /* Defined by the .exp file if testing attach.  */
 #ifndef ATTACH
 #define ATTACH 0
@@ -151,8 +122,6 @@ MAIN (int argc, char *argv[])
 	  exit (1);
 	}
 
-      update_name (addr, i);
-
       /* Link entry at the end of the list.  */
       entry->symfile_addr = (const char *)addr;
       entry->symfile_size = st.st_size;
diff --git a/gdb/testsuite/gdb.base/jit-elf-solib.c b/gdb/testsuite/gdb.base/jit-elf-solib.c
index 3bdebe9ed0..7901c58ac9 100644
--- a/gdb/testsuite/gdb.base/jit-elf-solib.c
+++ b/gdb/testsuite/gdb.base/jit-elf-solib.c
@@ -15,7 +15,7 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-/* This simulates a JIT library.  The function is "renamed" after being
-   loaded into memory.  */
+/* This simulates a JIT library.  The function name is supplied during
+   compilation as a macro.  */
 
-int jit_function_XXXX() { return 42; }
+int FUNCTION_NAME() { return 42; }
diff --git a/gdb/testsuite/lib/jit-elf-helpers.exp b/gdb/testsuite/lib/jit-elf-helpers.exp
index 4d88ea3900..8a7a1796cc 100644
--- a/gdb/testsuite/lib/jit-elf-helpers.exp
+++ b/gdb/testsuite/lib/jit-elf-helpers.exp
@@ -82,6 +82,7 @@ proc compile_n_jit_so {count} {
 	# function" changes when debug info is present.
 	set addr [format 0x%x [expr $load_address + $load_increment * [expr $i-1]]]
 	set options [list \
+	    additional_flags=-DFUNCTION_NAME=[format "jit_function_%04d" $i] \
 	    additional_flags=-Xlinker \
 	    additional_flags=-Ttext-segment=$addr]
 	if { [gdb_compile_shlib $solib_srcfile $solib_binfile $options] != "" } {
-- 
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


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v3 8/9] [gdb/testsuite] add jit-elf-util.h and run jit function
  2020-03-31 17:13 ` [PATCH v3 1/9] [gdb/testsuite] allow more registers in reader test Mihails Strasuns
                     ` (5 preceding siblings ...)
  2020-03-31 17:13   ` [PATCH v3 7/9] [gdb/testsuite] define jit function name via macro Mihails Strasuns
@ 2020-03-31 17:13   ` Mihails Strasuns
  2020-03-31 17:13   ` [PATCH v3 9/9] [gdb/testsuite] handle compilation failures in jit-elf-helpers Mihails Strasuns
                     ` (2 subsequent siblings)
  9 siblings, 0 replies; 17+ messages in thread
From: Mihails Strasuns @ 2020-03-31 17:13 UTC (permalink / raw)
  To: gdb-patches

Splits ELF related symbols into a separate jit-elf-util.h header and
enhances it with a few more.

Intention is to make adding new JIT tests possible without repeating
most of the common boilerplate.

As a test enhancement, jit-elf-main.c now calls the renamed function
after registering the jit object and ensures it returns an expected
result.

gdb/testsuite/ChangeLog:

2020-02-18  Mihails Strasuns  <mihails.strasuns@intel.com>

	* gdb.base/jit-elf-util.h: new header file
	* gdb.base/jit-elf-main.c: use jit-elf-util.h, add a call to
	  the renamed JIT function to verify its result

Change-Id: I9ac35ff2d610a57536f8afd33794c2feb6f40e25
Signed-off-by: Mihails Strasuns <mihails.strasuns@intel.com>
---
 gdb/testsuite/gdb.base/jit-elf-main.c |  56 ++++--------
 gdb/testsuite/gdb.base/jit-elf-util.h | 117 ++++++++++++++++++++++++++
 2 files changed, 133 insertions(+), 40 deletions(-)
 create mode 100644 gdb/testsuite/gdb.base/jit-elf-util.h

diff --git a/gdb/testsuite/gdb.base/jit-elf-main.c b/gdb/testsuite/gdb.base/jit-elf-main.c
index e25ea3f524..0f68cc88a9 100644
--- a/gdb/testsuite/gdb.base/jit-elf-main.c
+++ b/gdb/testsuite/gdb.base/jit-elf-main.c
@@ -30,19 +30,7 @@
 #include <unistd.h>
 
 #include "jit-protocol.h"
-
-/* ElfW is coming from linux. On other platforms it does not exist.
-   Let us define it here. */
-#ifndef ElfW
-# if (defined  (_LP64) || defined (__LP64__)) 
-#   define WORDSIZE 64
-# else
-#   define WORDSIZE 32
-# endif /* _LP64 || __LP64__  */
-#define ElfW(type)      _ElfW (Elf, WORDSIZE, type)
-#define _ElfW(e,w,t)    _ElfW_1 (e, w, _##t)
-#define _ElfW_1(e,w,t)  e##w##t
-#endif /* !ElfW  */
+#include "jit-elf-util.h"
 
 static void
 usage (void)
@@ -94,37 +82,19 @@ MAIN (int argc, char *argv[])
 
   for (i = 1; i < argc; ++i)
     {
-      struct stat st;
-      int fd;
-
-      printf ("%s:%d: libname = %s, i = %d\n", __FILE__, __LINE__, argv[i], i);
-      if ((fd = open (argv[i], O_RDONLY)) == -1)
-	{
-	  fprintf (stderr, "open (\"%s\", O_RDONLY): %s\n", argv[i],
-		   strerror (errno));
-	  exit (1);
-	}
+      size_t obj_size;
+      ElfW (Addr) load_addr = LOAD_ADDRESS + (i-1) * LOAD_INCREMENT;
+      printf("Loading %s as JIT at %p\n", argv[i], (void*) load_addr);
+      ElfW (Addr) addr = load_elf (argv[i], &obj_size, load_addr);
 
-      if (fstat (fd, &st) != 0)
-	{
-	  fprintf (stderr, "fstat (\"%d\"): %s\n", fd, strerror (errno));
-	  exit (1);
-	}
-
-      void* load_addr = (void*) (size_t) (LOAD_ADDRESS + (i - 1) * LOAD_INCREMENT);
-      const void *const addr = mmap (load_addr, st.st_size, PROT_READ|PROT_WRITE,
-				     MAP_PRIVATE | MAP_FIXED, fd, 0);
-      struct jit_code_entry *const entry = calloc (1, sizeof (*entry));
-
-      if (addr == MAP_FAILED)
-	{
-	  fprintf (stderr, "mmap: %s\n", strerror (errno));
-	  exit (1);
-	}
+      char name[32];
+      sprintf (name, "jit_function_%04d", i);
+      int (*jit_function) () = (int (*) ()) load_symbol (addr, name);
 
       /* Link entry at the end of the list.  */
+      struct jit_code_entry *const entry = calloc (1, sizeof (*entry));
       entry->symfile_addr = (const char *)addr;
-      entry->symfile_size = st.st_size;
+      entry->symfile_size = obj_size;
       entry->prev_entry = __jit_debug_descriptor.relevant_entry;
       __jit_debug_descriptor.relevant_entry = entry;
 
@@ -136,6 +106,12 @@ MAIN (int argc, char *argv[])
       /* Notify GDB.  */
       __jit_debug_descriptor.action_flag = JIT_REGISTER;
       __jit_debug_register_code ();
+
+      if (jit_function () != 42)
+	{
+	  fprintf (stderr, "unexpected return value\n");
+	  exit (1);
+	}
     }
 
   WAIT_FOR_GDB; i = 0;  /* gdb break here 1 */
diff --git a/gdb/testsuite/gdb.base/jit-elf-util.h b/gdb/testsuite/gdb.base/jit-elf-util.h
new file mode 100644
index 0000000000..e48d99f098
--- /dev/null
+++ b/gdb/testsuite/gdb.base/jit-elf-util.h
@@ -0,0 +1,117 @@
+/* This test program is part of GDB, the GNU debugger.
+
+   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/>.  */
+
+/* Simulates loading of JIT code by memory mapping a compiled
+   shared library binary and doing minimal post-processing.  */
+
+#include <elf.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <link.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+/* ElfW is coming from linux. On other platforms it does not exist.
+   Let us define it here. */
+#ifndef ElfW
+#if (defined(_LP64) || defined(__LP64__))
+#define WORDSIZE 64
+#else
+#define WORDSIZE 32
+#endif /* _LP64 || __LP64__  */
+#define ElfW(type) _ElfW (Elf, WORDSIZE, type)
+#define _ElfW(e, w, t) _ElfW_1 (e, w, _##t)
+#define _ElfW_1(e, w, t) e##w##t
+#endif /* !ElfW  */
+
+/* Find symbol with the name `sym_name`.  */
+static ElfW (Addr)
+load_symbol (ElfW (Addr) addr, const char *sym_name)
+{
+  const ElfW (Ehdr) *const ehdr = (ElfW (Ehdr) *) addr;
+  ElfW (Shdr) *const shdr = (ElfW (Shdr) *) ((char *) addr + ehdr->e_shoff);
+
+  ElfW (Addr) sym_old_addr = 0;
+  ElfW (Addr) sym_new_addr = 0;
+
+  /* Find `func_name` in symbol_table and adjust it from the addr.  */
+
+  for (int i = 0; i < ehdr->e_shnum; ++i)
+    {
+      if (shdr[i].sh_type == SHT_SYMTAB)
+	{
+	  ElfW (Sym) *symtab = (ElfW (Sym) *) (addr + shdr[i].sh_offset);
+	  ElfW (Sym) *symtab_end
+	      = (ElfW (Sym) *) (addr + shdr[i].sh_offset + shdr[i].sh_size);
+	  char *const strtab
+	      = (char *) (addr + shdr[shdr[i].sh_link].sh_offset);
+
+	  for (ElfW (Sym) *p = symtab; p < symtab_end; ++p)
+	    {
+	      const char *s = strtab + p->st_name;
+	      if (strcmp (s, sym_name) == 0)
+	        return p->st_value;
+	    }
+	}
+    }
+
+  fprintf (stderr, "symbol '%s' not found\n", sym_name);
+  exit (1);
+  return 0;
+}
+
+/* Open an elf binary file and memory map it with execution flag enabled.  */
+static ElfW (Addr)
+load_elf (const char *libname, size_t *size, ElfW (Addr) load_addr)
+{
+  int fd;
+  struct stat st;
+
+  if ((fd = open (libname, O_RDONLY)) == -1)
+    {
+      fprintf (stderr, "open (\"%s\", O_RDONLY): %s\n", libname,
+	       strerror (errno));
+      exit (1);
+    }
+
+  if (fstat (fd, &st) != 0)
+    {
+      fprintf (stderr, "fstat (\"%d\"): %s\n", fd, strerror (errno));
+      exit (1);
+    }
+
+  void *addr = mmap ((void *) load_addr, st.st_size,
+		     PROT_READ | PROT_WRITE | PROT_EXEC,
+		     load_addr ? MAP_PRIVATE | MAP_FIXED : MAP_PRIVATE, fd, 0);
+  close (fd);
+
+  if (addr == MAP_FAILED)
+    {
+      fprintf (stderr, "mmap: %s\n", strerror (errno));
+      exit (1);
+    }
+
+  if (size != NULL)
+    *size = st.st_size;
+
+  return (ElfW (Addr)) addr;
+}
-- 
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


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v3 9/9] [gdb/testsuite] handle compilation failures in jit-elf-helpers
  2020-03-31 17:13 ` [PATCH v3 1/9] [gdb/testsuite] allow more registers in reader test Mihails Strasuns
                     ` (6 preceding siblings ...)
  2020-03-31 17:13   ` [PATCH v3 8/9] [gdb/testsuite] add jit-elf-util.h and run jit function Mihails Strasuns
@ 2020-03-31 17:13   ` Mihails Strasuns
  2020-04-14 10:08   ` [PATCH v3 1/9] [gdb/testsuite] allow more registers in reader test Strasuns, Mihails
  2020-04-18  2:30   ` Simon Marchi
  9 siblings, 0 replies; 17+ messages in thread
From: Mihails Strasuns @ 2020-03-31 17:13 UTC (permalink / raw)
  To: gdb-patches

Enhances lib/jit-elf-helpers.exp and tests using it to return failure
status code and exit tests early if necessary binaries fail to compile.

gdb/testsuite/ChangeLog:

2020-03-31  Mihails Strasuns  <mihails.strasuns@intel.com>

	* gdb.base/jit-elf-so.exp: exit early on compilation failures
	* gdb.base/jit-elf.exp: exit early on compilation failures
	* lib/jit-elf-helpers.exp: report compilation failures

Signed-off-by: Mihails Strasuns <mihails.strasuns@intel.com>
Change-Id: I3c773a4e7d8e23a92b3e7613c6db67254ec33c08
---
 gdb/testsuite/gdb.base/jit-elf-so.exp | 15 +++++++++++++--
 gdb/testsuite/gdb.base/jit-elf.exp    |  9 ++++++++-
 gdb/testsuite/lib/jit-elf-helpers.exp |  3 +++
 3 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/gdb/testsuite/gdb.base/jit-elf-so.exp b/gdb/testsuite/gdb.base/jit-elf-so.exp
index 55154e9866..206f8aa2b3 100644
--- a/gdb/testsuite/gdb.base/jit-elf-so.exp
+++ b/gdb/testsuite/gdb.base/jit-elf-so.exp
@@ -29,8 +29,15 @@ if {[get_compiler_info]} {
 load_lib jit-elf-helpers.exp
 
 global testfile srcfile binfile solib_binfile_targets
-lassign [compile_jit_main_as_so] testfile srcfile binfile
+set jit_main [compile_jit_main_as_so]
+if {![llength $jit_main]} {
+    return -1
+}
+lassign $jit_main testfile srcfile binfile
 set solib_binfile_targets [compile_n_jit_so 2]
+if {![llength $solib_binfile_targets]} {
+    return -1
+}
 
 # Compile the test case shared library loader.
 proc compile_jit_dlmain {} {
@@ -41,10 +48,14 @@ proc compile_jit_dlmain {} {
     if { [gdb_compile "${srcdir}/${subdir}/${srcfile_dlmain}" "${binfile}" \
 	    executable {debug shlib_load}] != "" } {
 	untested "Failure to compile jit-elf-main"
+	return -1
     }
+    return 0
 }
 
-compile_jit_dlmain
+if {[compile_jit_dlmain]} {
+  return -1
+}
 
 proc one_jit_test {count match_str} {
     with_test_prefix "one_jit_test-$count" {
diff --git a/gdb/testsuite/gdb.base/jit-elf.exp b/gdb/testsuite/gdb.base/jit-elf.exp
index bf0e253bb9..e731e8be66 100644
--- a/gdb/testsuite/gdb.base/jit-elf.exp
+++ b/gdb/testsuite/gdb.base/jit-elf.exp
@@ -27,6 +27,9 @@ load_lib jit-elf-helpers.exp
 
 global testfile srcfile binfile solib_binfile_targets
 set solib_binfile_targets [compile_n_jit_so 2]
+if {![llength $solib_binfile_targets]} {
+    return -1
+}
 
 # Detach, restart GDB, and re-attach to the program.
 
@@ -117,7 +120,11 @@ proc one_jit_test {count match_str reattach} {
     }
 }
 
-lassign [compile_jit_main "" {}] testfile srcfile binfile
+set jit_main [compile_jit_main "" {}]
+if {![llength $jit_main]} {
+    return -1
+}
+lassign $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
 
diff --git a/gdb/testsuite/lib/jit-elf-helpers.exp b/gdb/testsuite/lib/jit-elf-helpers.exp
index 8a7a1796cc..833c0541c6 100644
--- a/gdb/testsuite/lib/jit-elf-helpers.exp
+++ b/gdb/testsuite/lib/jit-elf-helpers.exp
@@ -39,6 +39,7 @@ proc compile_jit_main {binsuffix options} {
     if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
 	    executable $options] != "" } {
 	untested "Failure to compile jit-elf-main"
+	return {}
     }
     return [list $testfile $srcfile $binfile]
 }
@@ -58,6 +59,7 @@ proc compile_jit_main_as_so {} {
     if { [gdb_compile_shlib "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
 	    $options] != "" } {
 	untested "Failure to compile jit-elf-main"
+	return {}
     }
     return [list $testfile $srcfile $binfile]
 }
@@ -87,6 +89,7 @@ proc compile_n_jit_so {count} {
 	    additional_flags=-Ttext-segment=$addr]
 	if { [gdb_compile_shlib $solib_srcfile $solib_binfile $options] != "" } {
 	    untested "Failure to compile $solib_binfile_test_msg"
+	    return {}
 	}
 
 	set path [gdb_remote_download target $solib_binfile]
-- 
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


^ permalink raw reply	[flat|nested] 17+ messages in thread

* RE: [PATCH v3 1/9] [gdb/testsuite] allow more registers in reader test
  2020-03-31 17:13 ` [PATCH v3 1/9] [gdb/testsuite] allow more registers in reader test Mihails Strasuns
                     ` (7 preceding siblings ...)
  2020-03-31 17:13   ` [PATCH v3 9/9] [gdb/testsuite] handle compilation failures in jit-elf-helpers Mihails Strasuns
@ 2020-04-14 10:08   ` Strasuns, Mihails
  2020-04-18  2:30   ` Simon Marchi
  9 siblings, 0 replies; 17+ messages in thread
From: Strasuns, Mihails @ 2020-04-14 10:08 UTC (permalink / raw)
  To: gdb-patches

Ping for the series 😉

> -----Original Message-----
> From: Mihails Strasuns <mihails.strasuns@intel.com>
> Sent: Tuesday, March 31, 2020 7:14 PM
> To: gdb-patches@sourceware.org
> Cc: Strasuns, Mihails <mihails.strasuns@intel.com>
> Subject: [PATCH v3 1/9] [gdb/testsuite] allow more registers in reader test
> 
> Fixes jit-reader test failures on systems that have more registers than
> expected by the current condition.
> 
> On Intel i9-7920X the following extra registers are printed:
> 
> k0             0x0                 0
> k1             0x0                 0
> k2             0x0                 0
> k3             0x0                 0
> k4             0x0                 0
> k5             0x0                 0
> k6             0x0                 0
> k7             0x0                 0
> 
> gdb/testsuite/ChangeLog:
> 
> 2020-02-18  Mihails Strasuns  <mihails.strasuns@intel.com>
> 
> 	* gdb.base/jit-reader.exp: relax register output check
> 
> Signed-off-by: Mihails Strasuns <mihails.strasuns@intel.com>
> Change-Id: I227ab8691b2363d626f7100216477ab637f619fa
> ---
>  gdb/testsuite/gdb.base/jit-reader.exp | 16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/gdb/testsuite/gdb.base/jit-reader.exp
> b/gdb/testsuite/gdb.base/jit-reader.exp
> index 7852a5b550..8663f0021d 100644
> --- a/gdb/testsuite/gdb.base/jit-reader.exp
> +++ b/gdb/testsuite/gdb.base/jit-reader.exp
> @@ -66,7 +66,8 @@ proc info_registers_current_frame {sp} {
>      set any "\[^\r\n\]*"
> 
>      set neg_decimal "-?$decimal"
> -    gdb_test "info registers" \
> +
> +    set expected \
>  	[multi_line \
>  	     "rax            $hex +$neg_decimal" \
>  	     "rbx            $hex +$neg_decimal" \
> @@ -93,6 +94,11 @@ proc info_registers_current_frame {sp} {
>  	     "fs             $hex +$neg_decimal" \
>  	     "gs             $hex +$neg_decimal" \
>  	    ]
> +
> +    # There may be more registers.
> +    append expected ".*"
> +
> +    gdb_test "info registers" $expected
>  }
> 
>  proc jit_reader_test {} {
> @@ -170,7 +176,8 @@ proc jit_reader_test {} {
> 
>  		# Since the JIT unwinder only provides RIP/RSP/RBP,
>  		# all other registers should show as "<not saved>".
> -		gdb_test "info registers" \
> +
> +		set expected \
>  		    [multi_line \
>  			 "rax            <not saved>" \
>  			 "rbx            <not saved>" \
> @@ -198,6 +205,11 @@ proc jit_reader_test {} {
>  			 "gs             <not saved>" \
>  			]
> 
> +		# There may be more registers.
> +		append expected ".*"
> +
> +		gdb_test "info registers" $expected
> +
>  		# Make sure that "info frame" doesn't crash.
>  		gdb_test "info frame" "Stack level 1, .*in main.*"
> 
> --
> 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

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v3 1/9] [gdb/testsuite] allow more registers in reader test
  2020-03-31 17:13 ` [PATCH v3 1/9] [gdb/testsuite] allow more registers in reader test Mihails Strasuns
                     ` (8 preceding siblings ...)
  2020-04-14 10:08   ` [PATCH v3 1/9] [gdb/testsuite] allow more registers in reader test Strasuns, Mihails
@ 2020-04-18  2:30   ` Simon Marchi
  9 siblings, 0 replies; 17+ messages in thread
From: Simon Marchi @ 2020-04-18  2:30 UTC (permalink / raw)
  To: Mihails Strasuns, gdb-patches

On 2020-03-31 1:13 p.m., Mihails Strasuns via Gdb-patches wrote:
> Fixes jit-reader test failures on systems that have more registers than
> expected by the current condition.
> 
> On Intel i9-7920X the following extra registers are printed:
> 
> k0             0x0                 0
> k1             0x0                 0
> k2             0x0                 0
> k3             0x0                 0
> k4             0x0                 0
> k5             0x0                 0
> k6             0x0                 0
> k7             0x0                 0
> 
> gdb/testsuite/ChangeLog:
> 
> 2020-02-18  Mihails Strasuns  <mihails.strasuns@intel.com>
> 
> 	* gdb.base/jit-reader.exp: relax register output check

Please start with capital letter and end with a period.

> Signed-off-by: Mihails Strasuns <mihails.strasuns@intel.com>
> Change-Id: I227ab8691b2363d626f7100216477ab637f619fa

Update the commit title to mention jit, just saying "reader test" is vague.  Might as well
mention the test filename:

  allow more registers in gdb.bas/jit-reader.exp

This patch is ok to push by itself with those fixed.  Please remind me, do you have push
access, or do you need/want it?  If not I don't mind pushing for you.

Simon


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v3 2/9] [gdb/testsuite] structured rename of jit test files
  2020-03-31 17:13   ` [PATCH v3 2/9] [gdb/testsuite] structured rename of jit test files Mihails Strasuns
@ 2020-04-18  2:35     ` Simon Marchi
  0 siblings, 0 replies; 17+ messages in thread
From: Simon Marchi @ 2020-04-18  2:35 UTC (permalink / raw)
  To: Mihails Strasuns, gdb-patches

On 2020-03-31 1:13 p.m., Mihails Strasuns via Gdb-patches wrote:
> Reorganizes how JIT related test files to be more clear what are related
> to JIT reader system tests and what use JIT from ELF objfiles. Those two
> approaches are quite different in GDB implementation and require very
> different test setup. Keeping distinction clear at the file name level
> makes it easier to maintain the testsuite.
> 
> gdb/testsuite/ChangeLog:
> 
> 2020-02-18  Mihails Strasuns  <mihails.strasuns@intel.com>
> 
> 	* gdb.base: rename all jit related test and source files

Thanks, this is ok.

Simon


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v3 3/9] [gdb/testsuite] share jit-protocol.h by all jit tests
  2020-03-31 17:13   ` [PATCH v3 3/9] [gdb/testsuite] share jit-protocol.h by all jit tests Mihails Strasuns
@ 2020-04-18  2:38     ` Simon Marchi
  0 siblings, 0 replies; 17+ messages in thread
From: Simon Marchi @ 2020-04-18  2:38 UTC (permalink / raw)
  To: Mihails Strasuns, gdb-patches

On 2020-03-31 1:13 p.m., Mihails Strasuns via Gdb-patches wrote:
> There was an existing jit-protocol.h defining common symbols needed for
> JIT-supporting application, however, it was only used by few tests.
> Others redeclared the same symbols.
> 
> This unifies all tests to use jit-protocol.h
> 
> gdb/testsuite/ChangeLog:
> 
> 2020-02-18  Mihails Strasuns  <mihails.strasuns@intel.com>
> 
> 	* gdb.base/jit-attach-pie.c: use jit-protocol.h
> 	* gdb.base/jit-elf-main.c: use jit-protocol.h
> 	* gdb.base/jit-reader-host.c: use jit-protocol.h
> 	* gdb.base/jit-reader-simple-jit.c: use jit-protocol.h
> 	* gdb.base/jit-protocol.h: update definitions to match all usage
> 	  contexts

Same comment about capital letter and period, that applies to all patches,
I'll stop mentioning it.

Ok with that fixed.

Simon

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v3 4/9] [gdb/testsuite] use args as lib list for jit-elf tests
  2020-03-31 17:13   ` [PATCH v3 4/9] [gdb/testsuite] use args as lib list for jit-elf tests Mihails Strasuns
@ 2020-04-18  2:58     ` Simon Marchi
  2020-04-20  7:35       ` Strasuns, Mihails
  0 siblings, 1 reply; 17+ messages in thread
From: Simon Marchi @ 2020-04-18  2:58 UTC (permalink / raw)
  To: Mihails Strasuns, gdb-patches

On 2020-03-31 1:13 p.m., Mihails Strasuns via Gdb-patches wrote:
> @@ -106,49 +106,38 @@ int mypid;
>  int
>  MAIN (int argc, char *argv[])
>  {
> -  /* These variables are here so they can easily be set from jit.exp.  */
> -  const char *libname = NULL;
> -  int count = 0, i, fd;
> -  struct stat st;
> -
> +  int i;
>    alarm (300);
> +  char* fake_argv[10]; // used as backing storage for GDB to populate argv

Space goes before the start: `char *fake_argv`.  For comments, please follow the
usual style:

- Capital letter and period (two spaces after the final period).
- On the line before, not the same line.
- /* */, not //

> @@ -146,31 +149,23 @@ proc one_jit_test {count match_str reattach} {
>      }
>  }
>  
> -if {[compile_jit_test jit.exp "" {}] < 0} {
> -    return
> -}
> -one_jit_test 1 "${hex}  jit_function_0000" 0
> -one_jit_test 2 "${hex}  jit_function_0000\[\r\n\]+${hex}  jit_function_0001" 0
> +compile_jit_main "" {}
> +compile_n_jit_so 2

I mentioned ealier: if we fail to compile the test program, we don't want to execute the rest
of the test case.  That's what the previous code did.  Can you keep that?

Simon

^ permalink raw reply	[flat|nested] 17+ messages in thread

* RE: [PATCH v3 4/9] [gdb/testsuite] use args as lib list for jit-elf tests
  2020-04-18  2:58     ` Simon Marchi
@ 2020-04-20  7:35       ` Strasuns, Mihails
  2020-04-20 13:08         ` Simon Marchi
  0 siblings, 1 reply; 17+ messages in thread
From: Strasuns, Mihails @ 2020-04-20  7:35 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

> -----Original Message-----
> From: Simon Marchi <simark@simark.ca>
> Sent: Saturday, April 18, 2020 4:58 AM
> To: Strasuns, Mihails <mihails.strasuns@intel.com>; gdb-
> patches@sourceware.org
> Subject: Re: [PATCH v3 4/9] [gdb/testsuite] use args as lib list for jit-elf tests


> > @@ -146,31 +149,23 @@ proc one_jit_test {count match_str reattach} {
> >      }
> >  }
> >
> > -if {[compile_jit_test jit.exp "" {}] < 0} {
> > -    return
> > -}
> > -one_jit_test 1 "${hex}  jit_function_0000" 0 -one_jit_test 2 "${hex}
> > jit_function_0000\[\r\n\]+${hex}  jit_function_0001" 0
> > +compile_jit_main "" {}
> > +compile_n_jit_so 2
> 
> I mentioned ealier: if we fail to compile the test program, we don't want to
> execute the rest of the test case.  That's what the previous code did.  Can
> you keep that?
> 
> Simon

I have added it as a separate patch in the series (see "[PATCH v3 9/9] [gdb/testsuite] handle compilation failures in jit-elf-helpers") as it seemed more incremental / easier to read.  Is that ok?

BR,
Mihails
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

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v3 4/9] [gdb/testsuite] use args as lib list for jit-elf tests
  2020-04-20  7:35       ` Strasuns, Mihails
@ 2020-04-20 13:08         ` Simon Marchi
  2020-04-20 13:53           ` Simon Marchi
  0 siblings, 1 reply; 17+ messages in thread
From: Simon Marchi @ 2020-04-20 13:08 UTC (permalink / raw)
  To: Strasuns, Mihails, gdb-patches

On 2020-04-20 3:35 a.m., Strasuns, Mihails wrote:
>> -----Original Message-----
>> From: Simon Marchi <simark@simark.ca>
>> Sent: Saturday, April 18, 2020 4:58 AM
>> To: Strasuns, Mihails <mihails.strasuns@intel.com>; gdb-
>> patches@sourceware.org
>> Subject: Re: [PATCH v3 4/9] [gdb/testsuite] use args as lib list for jit-elf tests
> 
> 
>>> @@ -146,31 +149,23 @@ proc one_jit_test {count match_str reattach} {
>>>      }
>>>  }
>>>
>>> -if {[compile_jit_test jit.exp "" {}] < 0} {
>>> -    return
>>> -}
>>> -one_jit_test 1 "${hex}  jit_function_0000" 0 -one_jit_test 2 "${hex}
>>> jit_function_0000\[\r\n\]+${hex}  jit_function_0001" 0
>>> +compile_jit_main "" {}
>>> +compile_n_jit_so 2
>>
>> I mentioned ealier: if we fail to compile the test program, we don't want to
>> execute the rest of the test case.  That's what the previous code did.  Can
>> you keep that?
>>
>> Simon
> 
> I have added it as a separate patch in the series (see "[PATCH v3 9/9] [gdb/testsuite] handle compilation failures in jit-elf-helpers") as it seemed more incremental / easier to read.  Is that ok?

I don't know, the code before this patch does the checks already, which you remove in this
patch.  Is there some difficulty in just keeping it?

Simon

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v3 4/9] [gdb/testsuite] use args as lib list for jit-elf tests
  2020-04-20 13:08         ` Simon Marchi
@ 2020-04-20 13:53           ` Simon Marchi
  0 siblings, 0 replies; 17+ messages in thread
From: Simon Marchi @ 2020-04-20 13:53 UTC (permalink / raw)
  To: Strasuns, Mihails, gdb-patches

On 2020-04-20 9:08 a.m., Simon Marchi wrote:
> On 2020-04-20 3:35 a.m., Strasuns, Mihails wrote:
>>> -----Original Message-----
>>> From: Simon Marchi <simark@simark.ca>
>>> Sent: Saturday, April 18, 2020 4:58 AM
>>> To: Strasuns, Mihails <mihails.strasuns@intel.com>; gdb-
>>> patches@sourceware.org
>>> Subject: Re: [PATCH v3 4/9] [gdb/testsuite] use args as lib list for jit-elf tests
>>
>>
>>>> @@ -146,31 +149,23 @@ proc one_jit_test {count match_str reattach} {
>>>>      }
>>>>  }
>>>>
>>>> -if {[compile_jit_test jit.exp "" {}] < 0} {
>>>> -    return
>>>> -}
>>>> -one_jit_test 1 "${hex}  jit_function_0000" 0 -one_jit_test 2 "${hex}
>>>> jit_function_0000\[\r\n\]+${hex}  jit_function_0001" 0
>>>> +compile_jit_main "" {}
>>>> +compile_n_jit_so 2
>>>
>>> I mentioned ealier: if we fail to compile the test program, we don't want to
>>> execute the rest of the test case.  That's what the previous code did.  Can
>>> you keep that?
>>>
>>> Simon
>>
>> I have added it as a separate patch in the series (see "[PATCH v3 9/9] [gdb/testsuite] handle compilation failures in jit-elf-helpers") as it seemed more incremental / easier to read.  Is that ok?
> 
> I don't know, the code before this patch does the checks already, which you remove in this
> patch.  Is there some difficulty in just keeping it?

I gave it a shot yesterday, and this is how I think the patch could look like
(I haven't updated the commit message and ChangeLog).  Of course, the rest
of the series would need to be adapted.

From memory, the things that I changed, are:

- Check if compilation succeeded, skip corresponding portion of test if not
- The naming was a bit unclear (e.g. srcfile vs srcfile2), I tried to give clear
  consistent names to everything
- Setting globals in some procedures and reading them in other procedures is really
  hard to follow.  Things that are pretty much static can initialized at the top
  of the file and used throughout.  Otherwise, procedures should return values, which
  can then be passed to other procedures as arguments.
- Add comments to functions, specifying their parameters and what they return in case
  of success/failure.  I just realized that I haven't added a comment to one_jit_test,
  it would be a good idea to have one.

Feel free to pick and choose things from this version of the patch.

Simon


From d4afd233ba57c1700a940d3de3ba0e146eaba925 Mon Sep 17 00:00:00 2001
From: Mihails Strasuns via Gdb-patches <gdb-patches@sourceware.org>
Date: Tue, 31 Mar 2020 19:13:51 +0200
Subject: [PATCH] use args as lib list for jit-elf tests

Old usage: jit-elf-main lib.so 2
New usage: jit-elf-main lib.so.1 lib.so.2

Refactoring necessary to support running tests over multiple jit
binaries rather than mapping the same binary muultiple times.

gdb/testsuite/ChangeLog:

2020-02-18  Mihails Strasuns  <mihails.strasuns@intel.com>

	* gdb.base/jit-elf-main.c: read lib list from argc/argv
	* gdb.base/jit-elf.exp: compile N jit libraries and use the list
	* gdb.base/jit-elf-so.exp: ditto

Change-Id: Ie8f85ec6358604c14557b0417d6621b2f8942033
Signed-off-by: Mihails Strasuns <mihails.strasuns@intel.com>
---
 gdb/testsuite/gdb.base/jit-elf-main.c |  56 ++++-----
 gdb/testsuite/gdb.base/jit-elf-so.exp | 171 +++++++++++++++++++-------
 gdb/testsuite/gdb.base/jit-elf.exp    | 154 ++++++++++++++---------
 3 files changed, 240 insertions(+), 141 deletions(-)

diff --git a/gdb/testsuite/gdb.base/jit-elf-main.c b/gdb/testsuite/gdb.base/jit-elf-main.c
index fe0f540d6f40..c324b967261d 100644
--- a/gdb/testsuite/gdb.base/jit-elf-main.c
+++ b/gdb/testsuite/gdb.base/jit-elf-main.c
@@ -45,9 +45,9 @@
 #endif /* !ElfW  */

 static void
-usage (const char *const argv0)
+usage (void)
 {
-  fprintf (stderr, "Usage: %s library [count]\n", argv0);
+  fprintf (stderr, "Usage: jit-elf-main libraries...\n");
   exit (1);
 }

@@ -106,49 +106,39 @@ int mypid;
 int
 MAIN (int argc, char *argv[])
 {
-  /* These variables are here so they can easily be set from jit.exp.  */
-  const char *libname = NULL;
-  int count = 0, i, fd;
-  struct stat st;
-
+  int i;
   alarm (300);
+  /* Used as backing storage for GDB to populate argv.  */
+  char *fake_argv[10];

   mypid = getpid ();
-
-  count = count;  /* gdb break here 0  */
+  /* gdb break here 0  */

   if (argc < 2)
     {
-      usage (argv[0]);
+      usage ();
       exit (1);
     }

-  if (libname == NULL)
-    /* Only set if not already set from GDB.  */
-    libname = argv[1];
-
-  if (argc > 2 && count == 0)
-    /* Only set if not already set from GDB.  */
-    count = atoi (argv[2]);
-
-  printf ("%s:%d: libname = %s, count = %d\n", __FILE__, __LINE__,
-	  libname, count);
-
-  if ((fd = open (libname, O_RDONLY)) == -1)
+  for (i = 1; i < argc; ++i)
     {
-      fprintf (stderr, "open (\"%s\", O_RDONLY): %s\n", libname,
-	       strerror (errno));
-      exit (1);
-    }
+      struct stat st;
+      int fd;

-  if (fstat (fd, &st) != 0)
-    {
-      fprintf (stderr, "fstat (\"%d\"): %s\n", fd, strerror (errno));
-      exit (1);
-    }
+      printf ("%s:%d: libname = %s, i = %d\n", __FILE__, __LINE__, argv[i], i);
+      if ((fd = open (argv[i], O_RDONLY)) == -1)
+	{
+	  fprintf (stderr, "open (\"%s\", O_RDONLY): %s\n", argv[i],
+		   strerror (errno));
+	  exit (1);
+	}
+
+      if (fstat (fd, &st) != 0)
+	{
+	  fprintf (stderr, "fstat (\"%d\"): %s\n", fd, strerror (errno));
+	  exit (1);
+	}

-  for (i = 0; i < count; ++i)
-    {
       const void *const addr = mmap (0, st.st_size, PROT_READ|PROT_WRITE,
 				     MAP_PRIVATE, fd, 0);
       struct jit_code_entry *const entry = calloc (1, sizeof (*entry));
diff --git a/gdb/testsuite/gdb.base/jit-elf-so.exp b/gdb/testsuite/gdb.base/jit-elf-so.exp
index 526414f43cfd..3dd7bc8c8536 100644
--- a/gdb/testsuite/gdb.base/jit-elf-so.exp
+++ b/gdb/testsuite/gdb.base/jit-elf-so.exp
@@ -26,48 +26,97 @@ if {[get_compiler_info]} {
     return 1
 }

+# The "real" main of this test, which loads jit-elf-main
+# as a shared library.
+set main_loader_basename jit-elf-dlmain
+set main_loader_srcfile ${srcdir}/${subdir}/${main_loader_basename}.c
+set main_loader_binfile [standard_output_file ${main_loader_basename}]
+
+# The main code that loads and registers JIT objects.
+set main_solib_basename jit-elf-main
+set main_solib_srcfile ${srcdir}/${subdir}/${main_solib_basename}.c
+set main_solib_binfile [standard_output_file ${main_solib_basename}.so]
+
+# The shared library that gets loaded as JIT objects.
+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.
 #
-# test running programs
+# 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
+    }

-set testfile jit-elf-dlmain
-set srcfile ${testfile}.c
-set binfile [standard_output_file ${testfile}]
-if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug shlib_load}] != "" } {
-    untested "failed to compile"
-    return -1
+    return 0
 }

-set testfile2 jit-elf-main
-set srcfile2 ${testfile2}.c
-set binfile2 [standard_output_file ${testfile2}.so]
-set binfile2_dlopen [shlib_target_file ${testfile2}.so]
-if { [gdb_compile_shlib "${srcdir}/${subdir}/${srcfile2}" ${binfile2} {debug additional_flags="-DMAIN=jit_dl_main"}] != "" } {
-    untested "failed to compile main shared library"
-    return -1
+# Compile the testcase shared library loader.
+#
+# OPTIONS is passed to gdb_compile when compiling the binary.
+#
+# On success, return 0.
+# On failure, return -1.
+proc compile_jit_dlmain {options} {
+    global main_loader_srcfile main_loader_binfile
+    set options [concat $options debug]
+
+    if { [gdb_compile ${main_loader_srcfile} ${main_loader_binfile} \
+	    executable $options] != "" } {
+	untested "failed to compile ${main_loader_basename}.c as an executable"
+	return -1
+    }
+
+    return 0
 }

-set solib_testfile "jit-elf-solib"
-set solib_srcfile "${srcdir}/${subdir}/${solib_testfile}.c"
-set solib_binfile [standard_output_file ${solib_testfile}.so]
-set solib_binfile_test_msg "SHLIBDIR/${solib_testfile}.so"
+# 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
+	}

-# Note: compiling without debug info: the library goes through symbol
-# renaming by munging on its symbol table, and that wouldn't work for .debug
-# sections.  Also, output for "info function" changes when debug info is resent.
-if { [gdb_compile_shlib ${solib_srcfile} ${solib_binfile} {}] != "" } {
-    untested "failed to compile jit shared library"
-    return -1
+	set path [gdb_remote_download target ${binfile}]
+	lappend binfiles_target $path
+    }
+
+    return $binfiles_target
 }

-set solib_binfile_target [gdb_remote_download target ${solib_binfile}]
+proc one_jit_test {solib_binfiles_target match_str} {
+    set count [llength $solib_binfiles_target]

-proc one_jit_test {count match_str} {
     with_test_prefix "one_jit_test-$count" {
-	global verbose testfile srcfile2 binfile2 binfile2_dlopen solib_binfile_target solib_binfile_test_msg
+	global verbose
+	global main_loader_binfile main_loader_srcfile
+	global main_solib_binfile main_solib_srcfile

-	clean_restart $testfile
-	gdb_load_shlib $binfile2
+	clean_restart $main_loader_binfile
+	gdb_load_shlib $main_solib_binfile

 	# This is just to help debugging when things fail
 	if {$verbose > 0} {
@@ -79,23 +128,30 @@ 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" \
+			    $main_loader_srcfile]
 	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_dlopen\""
+	gdb_test_no_output "set var jit_libname = \"$main_solib_binfile\""
+	gdb_test "set var argc=[expr $count + 1]"
+	gdb_test "set var argv=fake_argv"
+	for {set i 1} {$i <= $count} {incr i} {
+	    set binfile_target [lindex $solib_binfiles_target [expr $i-1]]
+	    gdb_test "set var argv\[$i\]=\"${binfile_target}\""
+	}

-	gdb_breakpoint [gdb_get_line_number "break here after-dlopen" ]
+	gdb_breakpoint [gdb_get_line_number "break here after-dlopen" \
+			$main_loader_srcfile]
 	gdb_continue_to_breakpoint "break here after-dlopen"

-	gdb_breakpoint "$srcfile2:[gdb_get_line_number {break here 0} $srcfile2]"
+	set line [gdb_get_line_number {break here 0} $main_solib_srcfile]
+	gdb_breakpoint "$main_solib_srcfile:$line"
 	gdb_continue_to_breakpoint "break here 0"

-	gdb_test_no_output "set var argc = 2"
-	gdb_test_no_output "set var libname = \"$solib_binfile_target\"" "set var libname = \"$solib_binfile_test_msg\""
-	gdb_test_no_output "set var count = $count"
-
-	gdb_breakpoint "$srcfile2:[gdb_get_line_number {break here 1} $srcfile2]"
+	set line [gdb_get_line_number {break here 1} $main_solib_srcfile]
+	gdb_breakpoint "$main_solib_srcfile:$line"
 	gdb_continue_to_breakpoint "break here 1"

 	gdb_test "info function jit_function" "$match_str"
@@ -106,20 +162,41 @@ proc one_jit_test {count match_str} {
 	    gdb_test "maintenance info break"
 	}

-	gdb_breakpoint "$srcfile2:[gdb_get_line_number {break here 2} $srcfile2]"
+	set line [gdb_get_line_number {break here 2} $main_solib_srcfile]
+	gdb_breakpoint "$main_solib_srcfile:$line"
 	gdb_continue_to_breakpoint "break here 2"
+
 	# All jit librares must have been unregistered
 	gdb_test "info function jit_function" \
 	    "All functions matching regular expression \"jit_function\":"
     }
 }

-one_jit_test 1 "${hex}  jit_function_0000"
-one_jit_test 2 "${hex}  jit_function_0000\[\r\n\]+${hex}  jit_function_0001"
+# 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 } {
+    return
+}

-# We don't intend to load the .so as a JIT debuginfo reader, but we
-# need some handy file name for a completion test.
-gdb_test \
-    "complete jit-reader-load [standard_output_file ${solib_testfile}.s]" \
-    "jit-reader-load $solib_binfile" \
-    "test jit-reader-load filename completion"
+# Compile the "real" main for this test.
+if { [compile_jit_dlmain {shlib_load}] < 0 } {
+    return
+}
+
+# Compile two shared libraries to use as JIT objects.
+set jit_solibs_target [compile_and_download_n_jit_so 2]
+if { $jit_solibs_target == -1 } {
+    return
+}
+
+one_jit_test [lindex $jit_solibs_target 0] "${hex}  jit_function_0001"
+one_jit_test $jit_solibs_target "${hex}  jit_function_0001\[\r\n\]+${hex}  jit_function_0002"
+
+foreach solib $jit_solibs_target {
+    # We don't intend to load the .so as a JIT debuginfo reader, but we
+    # need some handy file name for a completion test.
+    set input [string range $solib 0 [expr { [string length $solib] - 2 }]]
+    gdb_test \
+	"complete jit-reader-load [standard_output_file $input]" \
+	"jit-reader-load $solib" \
+	"test jit-reader-load filename completion"
+}
diff --git a/gdb/testsuite/gdb.base/jit-elf.exp b/gdb/testsuite/gdb.base/jit-elf.exp
index 71d3e37dfb82..29638bd2c084 100644
--- a/gdb/testsuite/gdb.base/jit-elf.exp
+++ b/gdb/testsuite/gdb.base/jit-elf.exp
@@ -23,48 +23,70 @@ if {[get_compiler_info]} {
     return 1
 }

-# Compile the testcase program and library.  BINSUFFIX is the suffix
-# to append to the program and library filenames, to make them unique
-# between invocations.  OPTIONS is passed to gdb_compile when
-# compiling the program.
-
-proc compile_jit_test {testname binsuffix options} {
-    global testfile srcfile binfile srcdir subdir
-    global solib_testfile solib_srcfile solib_binfile solib_binfile_test_msg
-    global solib_binfile_target
-
-    set testfile jit-elf-main
-    set srcfile ${testfile}.c
-    set binfile [standard_output_file $testfile$binsuffix]
-    if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
-	      executable [concat debug $options]] != "" } {
-	untested $testname
-	return -1
-    }
+# The main code that loads and registers JIT objects.
+set main_basename jit-elf-main
+set main_srcfile ${srcdir}/${subdir}/${main_basename}.c
+set main_binfile [standard_output_file ${main_basename}]

-    set solib_testfile "jit-elf-solib"
-    set solib_srcfile "${srcdir}/${subdir}/${solib_testfile}.c"
-    set solib_binfile [standard_output_file ${solib_testfile}$binsuffix.so]
-    set solib_binfile_test_msg "SHLIBDIR/${solib_testfile}$binsuffix.so"
-
-    # Note: compiling without debug info: the library goes through
-    # symbol renaming by munging on its 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} {-fPIC}] != "" } {
-	untested $testname
-	return -1
-    }
+# The shared library that gets loaded as JIT objects.
+set jit_solib_basename jit-elf-solib
+set jit_solib_srcfile ${srcdir}/${subdir}/${jit_solib_basename}.c

-    set solib_binfile_target [gdb_remote_download target ${solib_binfile}]
+# 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 srcfile testfile
+    global decimal gdb_prompt
+    global main_binfile main_srcfile

     # Get PID of test program.
     set testpid -1
@@ -79,11 +101,11 @@ proc clean_reattach {} {
     gdb_test_no_output "set var wait_for_gdb = 1"
     gdb_test "detach" "Detaching from .*"

-    clean_restart $testfile
+    clean_restart ${main_binfile}

     set test "attach"
     gdb_test_multiple "attach $testpid" "$test" {
-	-re "Attaching to program.*.*main.*at .*$srcfile:.*$gdb_prompt $" {
+	-re "Attaching to program.*.*main.*at .*$main_srcfile:.*$gdb_prompt $" {
 	    pass "$test"
 	}
     }
@@ -94,7 +116,9 @@ proc clean_reattach {} {
 # Continue to LOCATION in the program.  If REATTACH, detach and
 # re-attach to the program from scratch.
 proc continue_to_test_location {location reattach} {
-    gdb_breakpoint [gdb_get_line_number $location]
+    global main_srcfile
+
+    gdb_breakpoint [gdb_get_line_number $location $main_srcfile]
     gdb_continue_to_breakpoint $location
     if {$reattach} {
 	with_test_prefix "$location" {
@@ -103,11 +127,14 @@ proc continue_to_test_location {location reattach} {
     }
 }

-proc one_jit_test {count match_str reattach} {
+proc one_jit_test {jit_solibs_target match_str reattach} {
+    set count [llength $jit_solibs_target]
+
     with_test_prefix "one_jit_test-$count" {
-	global verbose testfile solib_binfile_target solib_binfile_test_msg
+	global verbose
+	global main_binfile main_srcfile

-	clean_restart $testfile
+	clean_restart ${main_binfile}

 	# This is just to help debugging when things fail
 	if {$verbose > 0} {
@@ -119,14 +146,19 @@ proc one_jit_test {count match_str reattach} {
 	    return
 	}

-	gdb_breakpoint [gdb_get_line_number "break here 0"]
-	gdb_continue_to_breakpoint "break here 0"
-
 	# 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 argc = 2"
-	gdb_test_no_output "set var libname = \"$solib_binfile_target\"" "set var libname = \"$solib_binfile_test_msg\""
-	gdb_test_no_output "set var count = $count"
+	incr count
+	gdb_test "set var argc=$count"
+	gdb_test "set var argv=fake_argv"
+	for {set i 1} {$i < $count} {incr i} {
+	    set jit_solib_target [lindex $jit_solibs_target [expr $i-1]]
+	    gdb_test "set var argv\[$i\]=\"${jit_solib_target}\""
+	}
+
+	gdb_breakpoint [gdb_get_line_number "break here 0" $main_srcfile]
+	gdb_continue_to_breakpoint "break here 0"
+

 	continue_to_test_location "break here 1" $reattach

@@ -146,31 +178,31 @@ proc one_jit_test {count match_str reattach} {
     }
 }

-if {[compile_jit_test jit.exp "" {}] < 0} {
+# Compile two shared libraries to use as JIT objects.
+set jit_solibs_target [compile_and_download_n_jit_so 2]
+if { $jit_solibs_target == -1 } {
     return
 }
-one_jit_test 1 "${hex}  jit_function_0000" 0
-one_jit_test 2 "${hex}  jit_function_0000\[\r\n\]+${hex}  jit_function_0001" 0
+
+# Compile the main code (which loads the JIT objects).
+if { [compile_jit_main "" {}] == 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
+}

 # Test attaching to an inferior with some JIT libraries already
 # registered.  We reuse the normal test, and detach/reattach at
 # specific interesting points.
 if {[can_spawn_for_attach]} {
-    if {[compile_jit_test "jit.exp attach tests" \
-	     "-attach" {additional_flags=-DATTACH=1}] < 0} {
-	return
-    }
-
-    with_test_prefix attach {
-	one_jit_test 2 "${hex}  jit_function_0000\[\r\n\]+${hex}  jit_function_0001" 1
+    if { [compile_jit_main "-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
+	}
     }
 }

-with_test_prefix PIE {
-    if {[compile_jit_test "jit.exp PIE tests" \
-	     "-pie" {additional_flags=-fPIE ldflags=-pie}] < 0} {
-	return
+if { [compile_jit_main "-pie" {additional_flags=-fPIE ldflags=-pie}] == 0 } {
+    with_test_prefix PIE {
+	one_jit_test [lindex $jit_solibs_target 0] "${hex}  jit_function_0001" 0
     }
-
-    one_jit_test 1 "${hex}  jit_function_0000" 0
 }
-- 
2.26.1



^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2020-04-20 13:53 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <166773>
2020-03-31 17:13 ` [PATCH v3 1/9] [gdb/testsuite] allow more registers in reader test Mihails Strasuns
2020-03-31 17:13   ` [PATCH v3 2/9] [gdb/testsuite] structured rename of jit test files Mihails Strasuns
2020-04-18  2:35     ` Simon Marchi
2020-03-31 17:13   ` [PATCH v3 3/9] [gdb/testsuite] share jit-protocol.h by all jit tests Mihails Strasuns
2020-04-18  2:38     ` Simon Marchi
2020-03-31 17:13   ` [PATCH v3 4/9] [gdb/testsuite] use args as lib list for jit-elf tests Mihails Strasuns
2020-04-18  2:58     ` Simon Marchi
2020-04-20  7:35       ` Strasuns, Mihails
2020-04-20 13:08         ` Simon Marchi
2020-04-20 13:53           ` Simon Marchi
2020-03-31 17:13   ` [PATCH v3 5/9] [gdb/testsuite] add lib/jit-elf-helpers.exp Mihails Strasuns
2020-03-31 17:13   ` [PATCH v3 6/9] [gdb/testsuite] use -Ttext-segment for jit-elf tests Mihails Strasuns
2020-03-31 17:13   ` [PATCH v3 7/9] [gdb/testsuite] define jit function name via macro Mihails Strasuns
2020-03-31 17:13   ` [PATCH v3 8/9] [gdb/testsuite] add jit-elf-util.h and run jit function Mihails Strasuns
2020-03-31 17:13   ` [PATCH v3 9/9] [gdb/testsuite] handle compilation failures in jit-elf-helpers Mihails Strasuns
2020-04-14 10:08   ` [PATCH v3 1/9] [gdb/testsuite] allow more registers in reader test Strasuns, Mihails
2020-04-18  2:30   ` Simon Marchi

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).