Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Mihails Strasuns <mihails.strasuns@intel.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 7/8] [gdb/testsuite] define jit function name via macro
Date: Fri, 27 Mar 2020 11:39:31 +0100	[thread overview]
Message-ID: <20200327103932.17765-7-mihails.strasuns@intel.com> (raw)
In-Reply-To: <20200327103932.17765-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 5bd8a05926..ce94fe3875 100644
--- a/gdb/testsuite/gdb.base/jit-elf-main.c
+++ b/gdb/testsuite/gdb.base/jit-elf-main.c
@@ -51,35 +51,6 @@ usage ()
   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
@@ -150,8 +121,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 8f17c2f972..2273333b60 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 binsuffix options} {
 	set addr [format 0x%x [expr $load_address + $load_increment * [expr $i-1]]]
 	set comp_options [concat \
 	    $options \
+	    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 $comp_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-27 10:38 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <165972>
2020-03-27 10:39 ` [PATCH v2 1/8] [gdb/testsuite] allow more registers in reader test Mihails Strasuns
2020-03-27 10:39   ` [PATCH v2 2/8] [gdb/testsuite] structured rename of jit test files Mihails Strasuns
2020-03-27 10:39   ` [PATCH v2 3/8] [gdb/testsuite] share jit-protocol.h by all jit tests Mihails Strasuns
2020-03-27 10:39   ` [PATCH v2 4/8] [gdb/testsuite] use args as lib list for jit-elf tests Mihails Strasuns
2020-03-30  3:00     ` Simon Marchi
2020-03-31 15:13       ` Strasuns, Mihails
2020-03-31 16:08         ` Simon Marchi
2020-03-27 10:39   ` [PATCH v2 5/8] [gdb/testsuite] add lib/jit-elf-helpers.exp Mihails Strasuns
2020-03-27 10:39   ` [PATCH v2 6/8] [gdb/testsuite] use -Ttext-segment for jit-elf tests Mihails Strasuns
2020-03-27 10:39   ` Mihails Strasuns [this message]
2020-03-27 10:39   ` [PATCH v2 8/8] [gdb/testsuite] add jit-elf-util.h and run jit function Mihails Strasuns
2020-03-30  2:55   ` [PATCH v2 1/8] [gdb/testsuite] allow more registers in reader test 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=20200327103932.17765-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