public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Mihails Strasuns <mihails.strasuns@intel.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v3 7/9] [gdb/testsuite] define jit function name via macro
Date: Tue, 31 Mar 2020 19:13:54 +0200	[thread overview]
Message-ID: <20200331171356.26126-7-mihails.strasuns@intel.com> (raw)
In-Reply-To: <20200331171356.26126-1-mihails.strasuns@intel.com>

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


  parent reply	other threads:[~2020-03-31 17:12 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [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   ` Mihails Strasuns [this message]
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

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=20200331171356.26126-7-mihails.strasuns@intel.com \
    --to=mihails.strasuns@intel.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

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

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