diff options
author | Mihails Strasuns <mihails.strasuns@intel.com> | 2020-03-27 11:21:01 +0100 |
---|---|---|
committer | Mihails Strasuns <mihails.strasuns@intel.com> | 2020-05-12 09:52:46 +0200 |
commit | aff4e759b8ad54df367e38ceaf16c92f680695a1 (patch) | |
tree | 26d94167f17636e273c7853fcb76cdaf3700d99c | |
parent | 80ad340c90234f7294ee71468c984e7f853d9bb6 (diff) | |
download | gdb-aff4e759b8ad54df367e38ceaf16c92f680695a1.zip gdb-aff4e759b8ad54df367e38ceaf16c92f680695a1.tar.gz gdb-aff4e759b8ad54df367e38ceaf16c92f680695a1.tar.bz2 |
[gdb/testsuite] define jit function name via macro
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.
-rw-r--r-- | gdb/testsuite/gdb.base/jit-elf-main.c | 31 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/jit-elf-solib.c | 10 | ||||
-rw-r--r-- | gdb/testsuite/lib/jit-elf-helpers.exp | 1 |
3 files changed, 8 insertions, 34 deletions
diff --git a/gdb/testsuite/gdb.base/jit-elf-main.c b/gdb/testsuite/gdb.base/jit-elf-main.c index be7185e..2d65489 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 @@ -152,8 +123,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 3bdebe9..66d6a2b 100644 --- a/gdb/testsuite/gdb.base/jit-elf-solib.c +++ b/gdb/testsuite/gdb.base/jit-elf-solib.c @@ -15,7 +15,11 @@ 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; } +#ifndef FUNCTION_NAME +#error "Must define the FUNCTION_NAME macro to set a jited function name" +#endif + +int FUNCTION_NAME() { return 42; } diff --git a/gdb/testsuite/lib/jit-elf-helpers.exp b/gdb/testsuite/lib/jit-elf-helpers.exp index 032417b..ab647ab 100644 --- a/gdb/testsuite/lib/jit-elf-helpers.exp +++ b/gdb/testsuite/lib/jit-elf-helpers.exp @@ -91,6 +91,7 @@ proc compile_and_download_n_jit_so {jit_solib_basename jit_solib_srcfile count} # with mapping the resulting binary to the same fixed base it allows # to dynamically execute functions from it without any further adjustments. set options [list \ + additional_flags=-DFUNCTION_NAME=[format "jit_function_%04d" $i] \ additional_flags=-Xlinker \ additional_flags=-Ttext-segment=$addr] if { [gdb_compile_shlib ${jit_solib_srcfile} ${binfile} $options] != "" } { |