diff --git a/Userland/Libraries/LibJS/JIT/Compiler.cpp b/Userland/Libraries/LibJS/JIT/Compiler.cpp index 2c27fb3918..d1d8b31e84 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.cpp +++ b/Userland/Libraries/LibJS/JIT/Compiler.cpp @@ -1,12 +1,14 @@ /* * Copyright (c) 2023, Andreas Kling * Copyright (c) 2023, Simon Wanner + * Copyright (c) 2023, Jesús Lapastora * * SPDX-License-Identifier: BSD-2-Clause */ #include #include +#include #include #include #include @@ -3757,7 +3759,14 @@ OwnPtr Compiler::compile(Bytecode::Executable& bytecode_execut dbgln("\033[32;1mJIT compilation succeeded!\033[0m {}", bytecode_executable.name); } - auto executable = make(executable_memory, compiler.m_output.size(), mapping); + auto const code = ReadonlyBytes { + executable_memory, + compiler.m_output.size(), + }; + + auto gdb_object = ::JIT::GDB::build_gdb_image(code, "LibJS JIT"sv, "LibJS JITted code"sv); + + auto executable = make(executable_memory, compiler.m_output.size(), mapping, move(gdb_object)); if constexpr (DUMP_JIT_DISASSEMBLY) executable->dump_disassembly(bytecode_executable); return executable; diff --git a/Userland/Libraries/LibJS/JIT/NativeExecutable.cpp b/Userland/Libraries/LibJS/JIT/NativeExecutable.cpp index 277ab6c7a6..ec3706c780 100644 --- a/Userland/Libraries/LibJS/JIT/NativeExecutable.cpp +++ b/Userland/Libraries/LibJS/JIT/NativeExecutable.cpp @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -14,10 +15,11 @@ namespace JS::JIT { -NativeExecutable::NativeExecutable(void* code, size_t size, Vector mapping) +NativeExecutable::NativeExecutable(void* code, size_t size, Vector mapping, Optional> gdb_object) : m_code(code) , m_size(size) , m_mapping(move(mapping)) + , m_gdb_object(move(gdb_object)) { // Translate block index to instruction address, so the native code can just jump to it. for (auto const& entry : m_mapping) { @@ -28,10 +30,14 @@ NativeExecutable::NativeExecutable(void* code, size_t size, Vector(m_code) + entry.native_offset); } } + if (m_gdb_object.has_value()) + ::JIT::GDB::register_into_gdb(m_gdb_object.value().span()); } NativeExecutable::~NativeExecutable() { + if (m_gdb_object.has_value()) + ::JIT::GDB::unregister_from_gdb(m_gdb_object.value().span()); munmap(m_code, m_size); } diff --git a/Userland/Libraries/LibJS/JIT/NativeExecutable.h b/Userland/Libraries/LibJS/JIT/NativeExecutable.h index 9111934fd4..f40a897991 100644 --- a/Userland/Libraries/LibJS/JIT/NativeExecutable.h +++ b/Userland/Libraries/LibJS/JIT/NativeExecutable.h @@ -6,6 +6,7 @@ #pragma once +#include #include #include #include @@ -28,7 +29,7 @@ class NativeExecutable { AK_MAKE_NONMOVABLE(NativeExecutable); public: - NativeExecutable(void* code, size_t size, Vector); + NativeExecutable(void* code, size_t size, Vector, Optional> gdb_object = {}); ~NativeExecutable(); void run(VM&, size_t entry_point) const; @@ -44,6 +45,7 @@ private: Vector m_mapping; Vector m_block_entry_points; mutable OwnPtr m_instruction_stream_iterator; + Optional> m_gdb_object; }; }