ladybird/Userland/Libraries/LibJIT/GDB.h
Jesús "gsus" Lapastora 149e382735 LibJIT: Integrate GDB JIT Interface with ELF builders
Provide a function to create an ELF image in a format GDB expects.
Outside of ELF platforms this image doesn't make much sense, and in
MacOS a Mach-O memory image is required: see
https://chromium.googlesource.com/v8/v8.git/+/refs/heads/main/src/diagnostics/gdb-jit.cc#1802

Since GDB requires active runtime addresses for the code, copying the
generated code into the image will not help. Instead, `build_gdb_image`
writes the runtime addresses of the code into a NOBITS `.text` section.
2023-12-07 15:34:38 -07:00

29 lines
1011 B
C++

/*
* Copyright (c) 2023, Jesús Lapastora <cyber.gsuscode@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/FixedArray.h>
#include <AK/Span.h>
#include <AK/StringView.h>
namespace JIT::GDB {
void register_into_gdb(ReadonlyBytes data);
void unregister_from_gdb(ReadonlyBytes data);
// Build a GDB compatible image to register with the GDB JIT Interface.
// Returns Optional since the platform may not be supported.
// The `code` must be the region of memory that will be executed, since the
// image will hold direct references to addresses within the code. This way GDB
// will be able to identify the code region and insert breakpoints into it.
// Both `file_symbol_name` and `code_symbol_name` will end up in the symbol
// table of the image. They represent a file name for the image and a name for
// the region of code that is being executed.
Optional<FixedArray<u8>> build_gdb_image(ReadonlyBytes code, StringView file_symbol_name, StringView code_symbol_name);
}