Integrate debugger into analyzer

This commit is contained in:
momo5502
2025-04-29 09:25:25 +02:00
parent fd6d4f0420
commit 5ed3036d53
8 changed files with 18 additions and 240 deletions

View File

@@ -51,7 +51,7 @@ function getMessageFromQueue() {
function runEmulation(filesystem, file, options) {
globalThis.Module = {
arguments: ["./root", file],
arguments: [...options, "-e", "./root", file],
onRuntimeInitialized: function () {
filesystem.forEach((e) => {
if (e.name.endsWith("/")) {
@@ -74,5 +74,5 @@ function runEmulation(filesystem, file, options) {
postRun: flushLines,
};
importScripts("./debugger.js");
importScripts("./analyzer.js");
}

View File

@@ -16,6 +16,7 @@ endif()
target_link_libraries(analyzer PRIVATE
reflect
debugger
windows-emulator
windows-gdb-stub
)

View File

@@ -6,6 +6,10 @@
#include "object_watching.hpp"
#include "snapshot.hpp"
#ifdef OS_EMSCRIPTEN
#include <event_handler.hpp>
#endif
#include <utils/interupt_handler.hpp>
#include <cstdio>
@@ -249,6 +253,14 @@ namespace
bool run(const analysis_options& options, const std::span<const std::string_view> args)
{
const auto win_emu = setup_emulator(options, args);
#ifdef OS_EMSCRIPTEN
win_emu->callbacks.on_thread_switch = [&] {
debugger::event_context c{.win_emu = *win_emu};
debugger::handle_events(c); //
};
#endif
win_emu->log.log("Using emulator: %s\n", win_emu->emu().get_name().c_str());
(void)&watch_system_objects;

View File

@@ -6,25 +6,19 @@ file(GLOB_RECURSE SRC_FILES CONFIGURE_DEPENDS
list(SORT SRC_FILES)
add_executable(debugger ${SRC_FILES})
add_library(debugger ${SRC_FILES})
momo_assign_source_group(${SRC_FILES})
if(NOT MOMO_ENABLE_CLANG_TIDY)
target_precompile_headers(debugger PRIVATE std_include.hpp)
endif()
target_link_libraries(debugger PRIVATE
windows-emulator
flatbuffers
base64
)
set_property(GLOBAL PROPERTY VS_STARTUP_PROJECT debugger)
target_include_directories(debugger INTERFACE "${CMAKE_CURRENT_LIST_DIR}")
momo_strip_target(debugger)
add_custom_target(gen_fbs
add_custom_target(generate-flatbuffer
DEPENDS flatc
COMMAND "$<TARGET_FILE:flatc>" --gen-mutable --gen-object-api --filename-ext hxx --cpp -o "${CMAKE_CURRENT_LIST_DIR}" "${CMAKE_CURRENT_LIST_DIR}/events.fbs"
COMMAND "$<TARGET_FILE:flatc>" --gen-mutable --gen-object-api --ts -o "${PROJECT_SOURCE_DIR}/page/src/fb" "${CMAKE_CURRENT_LIST_DIR}/events.fbs"

View File

@@ -1,97 +0,0 @@
#include "std_include.hpp"
#include <windows_emulator.hpp>
#include <cstdio>
#include "event_handler.hpp"
namespace
{
bool run_emulation(windows_emulator& win_emu)
{
try
{
win_emu.start();
}
catch (const std::exception& e)
{
win_emu.log.error("Emulation failed at: 0x%" PRIx64 " - %s\n", win_emu.emu().read_instruction_pointer(),
e.what());
throw;
}
catch (...)
{
win_emu.log.error("Emulation failed at: 0x%" PRIx64 "\n", win_emu.emu().read_instruction_pointer());
throw;
}
const auto exit_status = win_emu.process.exit_status;
if (!exit_status.has_value())
{
win_emu.log.error("Emulation terminated without status!\n");
return false;
}
const auto success = *exit_status == STATUS_SUCCESS;
win_emu.log.disable_output(false);
win_emu.log.print(success ? color::green : color::red, "Emulation terminated with status: %X\n", *exit_status);
return success;
}
bool run(const int argc, char** argv)
{
if (argc < 3)
{
return false;
}
const emulator_settings settings{
.emulation_root = argv[1],
};
application_settings app_settings{
.application = argv[2],
};
for (int i = 3; i < argc; ++i)
{
app_settings.arguments.push_back(u8_to_u16(argv[i]));
}
windows_emulator win_emu{app_settings, settings};
win_emu.callbacks.on_thread_switch = [&] {
debugger::event_context c{.win_emu = win_emu};
debugger::handle_events(c); //
};
return run_emulation(win_emu);
}
}
int main(const int argc, char** argv)
{
try
{
const auto result = run(argc, argv);
return result ? 0 : 1;
}
catch (std::exception& e)
{
puts(e.what());
#if defined(_WIN32) && 0
MessageBoxA(nullptr, e.what(), "ERROR", MB_ICONERROR);
#endif
}
return 1;
}
#ifdef _WIN32
int WINAPI WinMain(HINSTANCE, HINSTANCE, PSTR, int)
{
return main(__argc, __argv);
}
#endif

View File

@@ -1,101 +0,0 @@
// Microsoft Visual C++ generated resource script.
//
#pragma code_page(65001)
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "windows.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (United States) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"#include ""windows.h""\r\n"
"\0"
END
2 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x40004L
FILETYPE VFT_DLL
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "momo5502"
VALUE "FileDescription", "Windows Emulator"
VALUE "FileVersion", "1.0.0.0"
VALUE "InternalName", "emulator"
VALUE "LegalCopyright", "All rights reserved."
VALUE "OriginalFilename", "emulator.exe"
VALUE "ProductName", "emulator"
VALUE "ProductVersion", "1.0.0.0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
/////////////////////////////////////////////////////////////////////////////
//
// Binary Data
//
GLFW_ICON ICON "resources/icon.ico"
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

View File

@@ -1,31 +0,0 @@
#pragma once
#include <map>
#include <set>
#include <list>
#include <array>
#include <deque>
#include <queue>
#include <thread>
#include <ranges>
#include <atomic>
#include <vector>
#include <mutex>
#include <string>
#include <chrono>
#include <memory>
#include <fstream>
#include <functional>
#include <filesystem>
#include <optional>
#include <stdexcept>
#include <string_view>
#include <unordered_set>
#include <condition_variable>
#include <cassert>
#include <platform/platform.hpp>
// NOLINTNEXTLINE(google-global-names-in-headers)
using namespace std::literals;