diff options
author | Mihails Strasuns <mihails.strasuns@intel.com> | 2020-02-11 13:23:25 +0100 |
---|---|---|
committer | Mihails Strasuns <mihails.strasuns@intel.com> | 2020-04-21 15:22:34 +0200 |
commit | 922a7c7c5d4040f9e4ab75a059b9ca33f45ab952 (patch) | |
tree | dbd02a57618a2e920810dce51766b9d69a02b665 /gdb/testsuite/gdb.base/jit-reader-host.c | |
parent | f49c464f933172bae5685c2fb51b9e220902146c (diff) | |
download | binutils-922a7c7c5d4040f9e4ab75a059b9ca33f45ab952.zip binutils-922a7c7c5d4040f9e4ab75a059b9ca33f45ab952.tar.gz binutils-922a7c7c5d4040f9e4ab75a059b9ca33f45ab952.tar.bz2 |
[gdb/testsuite] structured rename of jit test files
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.
Diffstat (limited to 'gdb/testsuite/gdb.base/jit-reader-host.c')
-rw-r--r-- | gdb/testsuite/gdb.base/jit-reader-host.c | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.base/jit-reader-host.c b/gdb/testsuite/gdb.base/jit-reader-host.c new file mode 100644 index 0000000..d07acd5 --- /dev/null +++ b/gdb/testsuite/gdb.base/jit-reader-host.c @@ -0,0 +1,98 @@ +/* Copyright (C) 2009-2020 Free Software Foundation, Inc. + + This file is part of GDB. + + 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/>. */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include <sys/mman.h> + +#include JIT_READER_H /* Please see jit-reader.exp for an explanation. */ +#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); +typedef long (jit_function_add_t) (long a, long b); + +/* The code of the jit_function_00 function that is copied into an + mmapped buffer in the inferior at run time. + + The second instruction mangles the stack pointer, meaning that when + stopped at the third instruction, GDB needs assistance from the JIT + unwinder in order to be able to unwind successfully. */ +static const unsigned char jit_function_stack_mangle_code[] = { + 0xcc, /* int3 */ + 0x48, 0x83, 0xf4, 0xff, /* xor $0xffffffffffffffff, %rsp */ + 0x48, 0x83, 0xf4, 0xff, /* xor $0xffffffffffffffff, %rsp */ + 0xc3 /* ret */ +}; + +/* And another "JIT-ed" function, with the prototype `jit_function_add_t`. */ +static const unsigned char jit_function_add_code[] = { + 0x48, 0x01, 0xfe, /* add %rdi,%rsi */ + 0x48, 0x89, 0xf0, /* mov %rsi,%rax */ + 0xc3, /* retq */ +}; + +int +main (int argc, char **argv) +{ + struct jithost_abi *symfile = malloc (sizeof (struct jithost_abi)); + char *code = mmap (NULL, getpagesize (), PROT_WRITE | PROT_EXEC, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + char *code_end = code; + + /* "JIT" function_stack_mangle. */ + memcpy (code_end, jit_function_stack_mangle_code, + sizeof (jit_function_stack_mangle_code)); + jit_function_stack_mangle_t *function_stack_mangle + = (jit_function_stack_mangle_t *) code_end; + symfile->function_stack_mangle.begin = code_end; + code_end += sizeof (jit_function_stack_mangle_code); + symfile->function_stack_mangle.end = code_end; + + /* "JIT" function_add. */ + memcpy (code_end, jit_function_add_code, sizeof (jit_function_add_code)); + jit_function_add_t *function_add = (jit_function_add_t *) code_end; + symfile->function_add.begin = code_end; + code_end += sizeof (jit_function_add_code); + symfile->function_add.end = code_end; + + /* Bounds of the whole object. */ + symfile->object.begin = code; + symfile->object.end = code_end; + + only_entry.symfile_addr = symfile; + only_entry.symfile_size = sizeof (struct jithost_abi); + + __jit_debug_descriptor.first_entry = &only_entry; + __jit_debug_descriptor.relevant_entry = &only_entry; + __jit_debug_descriptor.action_flag = JIT_REGISTER; + __jit_debug_descriptor.version = 1; + __jit_debug_register_code (); + + function_stack_mangle (); + function_add (5, 6); + + return 0; +} |