Files
TheRock/debug-tools/rocgdb/source/gdb/testsuite/gdb.base/jit-reader-host.c
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

99 lines
3.3 KiB
C

/* Copyright (C) 2009-2024 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 <assert.h>
#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"
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;
assert (code != MAP_FAILED);
/* "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;
}