Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Ilya Leoshkevich via Gdb-patches <gdb-patches@sourceware.org>
To: Tom Tromey <tromey@adacore.com>, Andrew Burgess <aburgess@redhat.com>
Cc: Ulrich Weigand <ulrich.weigand@de.ibm.com>,
	Andreas Arnez <arnez@linux.ibm.com>,
	gdb-patches@sourceware.org, Pedro Alves <pedro@palves.net>,
	Ilya Leoshkevich <iii@linux.ibm.com>
Subject: [PATCH v2 6/7] gdb.base/: Introduce n_jit_so_address
Date: Tue, 31 May 2022 00:11:46 +0200	[thread overview]
Message-ID: <20220530221147.1991835-7-iii@linux.ibm.com> (raw)
In-Reply-To: <20220530221147.1991835-1-iii@linux.ibm.com>

Move computing shared library load addresses into a separate function
(both in TCL and C).  This eliminates repetition and is useful for
sharing with performance tests.
---
 gdb/testsuite/gdb.base/jit-elf-fork-main.c | 11 +----------
 gdb/testsuite/gdb.base/jit-elf-main.c      | 11 +----------
 gdb/testsuite/gdb.base/jit-elf-util.h      | 17 +++++++++++++++++
 gdb/testsuite/lib/jit-elf-helpers.exp      |  9 +++++++--
 4 files changed, 26 insertions(+), 22 deletions(-)

diff --git a/gdb/testsuite/gdb.base/jit-elf-fork-main.c b/gdb/testsuite/gdb.base/jit-elf-fork-main.c
index 96fadaa57b7..6e1b3db3d5a 100644
--- a/gdb/testsuite/gdb.base/jit-elf-fork-main.c
+++ b/gdb/testsuite/gdb.base/jit-elf-fork-main.c
@@ -39,15 +39,6 @@ usage (void)
   exit (1);
 }
 
-/* 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
-
 int
 main (int argc, char *argv[])
 {
@@ -65,7 +56,7 @@ main (int argc, char *argv[])
   for (i = 1; i < argc; ++i)
     {
       size_t obj_size;
-      void *load_addr = (void *) (size_t) (LOAD_ADDRESS + (i - 1) * LOAD_INCREMENT);
+      void *load_addr = n_jit_so_address (i);
       printf ("Loading %s as JIT at %p\n", argv[i], load_addr);
       void *addr = load_elf (argv[i], &obj_size, load_addr);
 
diff --git a/gdb/testsuite/gdb.base/jit-elf-main.c b/gdb/testsuite/gdb.base/jit-elf-main.c
index 8f482748ee5..604fb07aa8a 100644
--- a/gdb/testsuite/gdb.base/jit-elf-main.c
+++ b/gdb/testsuite/gdb.base/jit-elf-main.c
@@ -48,15 +48,6 @@ usage (void)
 #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 do {} while (wait_for_gdb)
@@ -84,7 +75,7 @@ MAIN (int argc, char *argv[])
   for (i = 1; i < argc; ++i)
     {
       size_t obj_size;
-      void *load_addr = (void *) (size_t) (LOAD_ADDRESS + (i - 1) * LOAD_INCREMENT);
+      void *load_addr = n_jit_so_address (i);
       printf ("Loading %s as JIT at %p\n", argv[i], load_addr);
       void *addr = load_elf (argv[i], &obj_size, load_addr);
 
diff --git a/gdb/testsuite/gdb.base/jit-elf-util.h b/gdb/testsuite/gdb.base/jit-elf-util.h
index 419a781f865..faa1a21204a 100644
--- a/gdb/testsuite/gdb.base/jit-elf-util.h
+++ b/gdb/testsuite/gdb.base/jit-elf-util.h
@@ -117,3 +117,20 @@ load_elf (const char *libname, size_t *size, void *load_addr)
 
   return addr;
 }
+
+/* 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
+
+/* Return the address of the SO_NRth shared library.  The first shared
+   library's SO_NR is 1.  */
+static void *
+n_jit_so_address (int so_nr)
+{
+  return (void *) (size_t) (LOAD_ADDRESS + (so_nr - 1) * LOAD_INCREMENT);
+}
diff --git a/gdb/testsuite/lib/jit-elf-helpers.exp b/gdb/testsuite/lib/jit-elf-helpers.exp
index 7c17178f800..57513de0927 100644
--- a/gdb/testsuite/lib/jit-elf-helpers.exp
+++ b/gdb/testsuite/lib/jit-elf-helpers.exp
@@ -72,13 +72,18 @@ proc compile_jit_elf_main_as_so {main_solib_srcfile main_solib_binfile options}
     return 0
 }
 
+# Return the address of the SO_NRth shared library.
+proc n_jit_so_address {so_nr} {
+    global jit_load_address jit_load_increment
+    return [expr $jit_load_address + $jit_load_increment * [expr $so_nr - 1]]
+}
+
 # Compile jit-elf-solib.c as a shared library in multiple copies and
 # upload them to the target.
 #
 # On success, return a list of target path to the shared libraries.
 # On failure, return -1.
 proc compile_and_download_n_jit_so {jit_solib_basename jit_solib_srcfile count} {
-    global jit_load_address jit_load_increment
     set binfiles_target {}
 
     for {set i 1} {$i <= $count} {incr i} {
@@ -88,7 +93,7 @@ proc compile_and_download_n_jit_so {jit_solib_basename jit_solib_srcfile 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.
-	set addr [format 0x%x [expr $jit_load_address + $jit_load_increment * [expr $i-1]]]
+	set addr [format 0x%x [n_jit_so_address $i]]
 
 	# Use "text_segment=..." to ask the linker to relocate everything in the
 	# compiled shared library against a fixed base address.  Combined
-- 
2.35.3


  parent reply	other threads:[~2022-05-30 22:15 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-30 22:11 [PATCH v2 0/7] gdb.perf/: Add JIT performance test Ilya Leoshkevich via Gdb-patches
2022-05-30 22:11 ` [PATCH v2 1/7] gdb.perf/: Fix tcl_string_list_to_python_list {x} Ilya Leoshkevich via Gdb-patches
2022-05-30 22:11 ` [PATCH v2 2/7] gdb.perf/: Add binary_link_with_shlibs setting to GenPerfTest Ilya Leoshkevich via Gdb-patches
2022-05-30 22:11 ` [PATCH v2 3/7] gdb.perf/: Allow adjusting GenPerfTest compile options Ilya Leoshkevich via Gdb-patches
2022-05-30 22:11 ` [PATCH v2 4/7] gdb.base/: Introduce jit-protocol-util.h Ilya Leoshkevich via Gdb-patches
2022-05-30 22:11 ` [PATCH v2 5/7] gdb.base/: Introduce jit_compile_options Ilya Leoshkevich via Gdb-patches
2022-05-30 22:11 ` Ilya Leoshkevich via Gdb-patches [this message]
2022-05-30 22:11 ` [PATCH v2 7/7] gdb.perf/: Add JIT performance test Ilya Leoshkevich via Gdb-patches
2022-06-22  8:48 ` [PING] [PATCH v2 0/7] " Ilya Leoshkevich via Gdb-patches
2022-08-03 10:52 ` [PING^2] " Ilya Leoshkevich via Gdb-patches

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=20220530221147.1991835-7-iii@linux.ibm.com \
    --to=gdb-patches@sourceware.org \
    --cc=aburgess@redhat.com \
    --cc=arnez@linux.ibm.com \
    --cc=iii@linux.ibm.com \
    --cc=pedro@palves.net \
    --cc=tromey@adacore.com \
    --cc=ulrich.weigand@de.ibm.com \
    /path/to/YOUR_REPLY

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

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