8#include "../macros.hpp"
9#include "../win32/win32.hpp"
10#include "console_win32.hpp"
11#include "exception.hpp"
12#include "debugger_intf.hpp"
13#include "debugger_utils.hpp"
24hi_export_module(hikogui.utility.debugger : impl);
29hi_warning_ignore_msvc(6320);
31hi_export
namespace hi {
38 DWORD dwProcessorArchitecture;
58hi_inline
bool launch_jit_debugger()
noexcept
60 using namespace std::literals;
63 HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug",
"Auto");
70 HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug",
"Debugger");
95 if (
auto handle = win32_CreateEvent()) {
96 jit_debug_handle = *handle;
99 set_debug_message(
"Could not create event object for JIT debugger.");
114 set_debug_message(
"JIT debugger accepts an invalid number of arguments.");
138 set_debug_message(
"Could not executed JIT debugger.");
143 auto end_time = std::chrono::utc_clock::time_point::max();
144 while (std::chrono::utc_clock::now() <
end_time) {
151 if (
end_time == std::chrono::utc_clock::time_point::max()) {
156 end_time = std::chrono::utc_clock::now() + 60s;
162 }
else if (
exit_code.error() != win32_error::status_pending) {
164 set_debug_message(
"GetExitCodeProcess() return unknown error");
172 set_debug_message(
"Debugger did not attach within 60s after being selected.");
188 switch (
ep.ExceptionRecord->ExceptionCode) {
210 default: r +=
"Unknown Operating System Exception";
break;
220 switch (
ep.ExceptionRecord->ExceptionCode) {
242 default:
return false;
249 if (
not is_debugable_exception(*p)) {
254 jit_debug_info.dwSize =
sizeof(JIT_DEBUG_INFO);
255#if HI_PROCESSOR == HI_CPU_X86
257#elif HI_PROCESSOR == HI_CPU_X86_64
259#elif HI_PROCESSOR == HI_CPU_ARM
261#elif HI_PROCESSOR == HI_CPU_ARM64
264#error "Not implemented."
267 jit_debug_info.dwReserved0 = 0;
268 jit_debug_info.lpExceptionAddress = std::bit_cast<ULONG64>(p->ExceptionRecord->ExceptionAddress);
269 jit_debug_info.lpExceptionRecord = std::bit_cast<ULONG64>(&p->ExceptionRecord);
270 jit_debug_info.lpContextRecord = std::bit_cast<ULONG64>(p->ContextRecord);
277 }
else if (launch_jit_debugger()) {
282 ::hi::set_debug_message(
nullptr);
288#if HI_PROCESSOR == HI_CPU_X86_64
290 p->ContextRecord->Rip++;
291#elif HI_PROCESSOR == HI_CPU_X86
293 p->ContextRecord->Eip++;
295#error "Not implemented."
Rules for working with win32 headers.
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
The HikoGUI namespace.
Definition recursive_iterator.hpp:15
hi_inline uint32_t win32_HANDLE_to_int(HANDLE handle) noexcept
Convert a HANDLE to a 32-bit unsigned integer.
Definition base.hpp:226
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:378
hi_inline void enable_debugger() noexcept
Enable the JIT debugger to be attached.
Definition debugger_generic_impl.hpp:17
Definition debugger_win32_impl.hpp:36