]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/jithost.c
Update copyright year range in all GDB files.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / jithost.c
CommitLineData
42a4f53d 1/* Copyright (C) 2009-2019 Free Software Foundation, Inc.
2838cc1d
SD
2
3 This file is part of GDB.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
18#include <stdio.h>
19#include <stdlib.h>
20#include <string.h>
21#include <unistd.h>
22
23#include <sys/mman.h>
24
25#include JIT_READER_H /* Please see jit-reader.exp for an explanation. */
26#include "jithost.h"
27#include "jit-protocol.h"
28
29void __attribute__((noinline)) __jit_debug_register_code () { }
30
31struct jit_descriptor __jit_debug_descriptor = { 1, 0, 0, 0 };
32struct jit_code_entry only_entry;
33
34typedef void (jit_function_t) ();
35
20aa2c60
PA
36/* The code of the jit_function_00 function that is copied into an
37 mmapped buffer in the inferior at run time.
38
39 The second instruction mangles the stack pointer, meaning that when
40 stopped at the third instruction, GDB needs assistance from the JIT
41 unwinder in order to be able to unwind successfully. */
42const unsigned char jit_function_00_code[] = {
43 0xcc, /* int3 */
44 0x48, 0x83, 0xf4, 0xff, /* xor $0xffffffffffffffff, %rsp */
45 0x48, 0x83, 0xf4, 0xff, /* xor $0xffffffffffffffff, %rsp */
46 0xc3 /* ret */
47};
48
49int
50main (int argc, char **argv)
2838cc1d 51{
20aa2c60 52 struct jithost_abi *symfile;
2838cc1d
SD
53 char *code = mmap (NULL, getpagesize (), PROT_WRITE | PROT_EXEC,
54 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
55 jit_function_t *function = (jit_function_t *) code;
56
20aa2c60 57 memcpy (code, jit_function_00_code, sizeof (jit_function_00_code));
2838cc1d 58
20aa2c60 59 symfile = malloc (sizeof (struct jithost_abi));
2838cc1d 60 symfile->begin = code;
20aa2c60 61 symfile->end = code + sizeof (jit_function_00_code);
2838cc1d
SD
62
63 only_entry.symfile_addr = symfile;
64 only_entry.symfile_size = sizeof (struct jithost_abi);
65
66 __jit_debug_descriptor.first_entry = &only_entry;
67 __jit_debug_descriptor.relevant_entry = &only_entry;
68 __jit_debug_descriptor.action_flag = JIT_REGISTER;
69 __jit_debug_descriptor.version = 1;
70 __jit_debug_register_code ();
71
72 function ();
73
74 return 0;
75}