Add a test case for the jit-reader interface
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / jithost.c
CommitLineData
2838cc1d
SD
1/* Copyright (C) 2009-2016 Free Software Foundation, Inc.
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
36int main (int argc, char **argv)
37{
38 char *code = mmap (NULL, getpagesize (), PROT_WRITE | PROT_EXEC,
39 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
40 jit_function_t *function = (jit_function_t *) code;
41
42 code[0] = 0xcc; /* SIGTRAP */
43 code[1] = 0xc3; /* RET */
44
45 struct jithost_abi *symfile = malloc (sizeof (struct jithost_abi));
46 symfile->begin = code;
47 symfile->end = code + 2;
48
49 only_entry.symfile_addr = symfile;
50 only_entry.symfile_size = sizeof (struct jithost_abi);
51
52 __jit_debug_descriptor.first_entry = &only_entry;
53 __jit_debug_descriptor.relevant_entry = &only_entry;
54 __jit_debug_descriptor.action_flag = JIT_REGISTER;
55 __jit_debug_descriptor.version = 1;
56 __jit_debug_register_code ();
57
58 function ();
59
60 return 0;
61}
This page took 0.027312 seconds and 4 git commands to generate.