diff --git a/page/public/emulator-worker.js b/page/public/emulator-worker.js index feeee17d..c3804f53 100644 --- a/page/public/emulator-worker.js +++ b/page/public/emulator-worker.js @@ -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"); } diff --git a/src/analyzer/CMakeLists.txt b/src/analyzer/CMakeLists.txt index 0cfffb61..036e614e 100644 --- a/src/analyzer/CMakeLists.txt +++ b/src/analyzer/CMakeLists.txt @@ -16,6 +16,7 @@ endif() target_link_libraries(analyzer PRIVATE reflect + debugger windows-emulator windows-gdb-stub ) diff --git a/src/analyzer/main.cpp b/src/analyzer/main.cpp index ec943fa0..b95bd429 100644 --- a/src/analyzer/main.cpp +++ b/src/analyzer/main.cpp @@ -6,6 +6,10 @@ #include "object_watching.hpp" #include "snapshot.hpp" +#ifdef OS_EMSCRIPTEN +#include +#endif + #include #include @@ -249,6 +253,14 @@ namespace bool run(const analysis_options& options, const std::span 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; diff --git a/src/debugger/CMakeLists.txt b/src/debugger/CMakeLists.txt index a0cf3db5..6fb70a5a 100644 --- a/src/debugger/CMakeLists.txt +++ b/src/debugger/CMakeLists.txt @@ -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 "$" --gen-mutable --gen-object-api --filename-ext hxx --cpp -o "${CMAKE_CURRENT_LIST_DIR}" "${CMAKE_CURRENT_LIST_DIR}/events.fbs" COMMAND "$" --gen-mutable --gen-object-api --ts -o "${PROJECT_SOURCE_DIR}/page/src/fb" "${CMAKE_CURRENT_LIST_DIR}/events.fbs" diff --git a/src/debugger/main.cpp b/src/debugger/main.cpp deleted file mode 100644 index b234f088..00000000 --- a/src/debugger/main.cpp +++ /dev/null @@ -1,97 +0,0 @@ -#include "std_include.hpp" - -#include -#include -#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 diff --git a/src/debugger/resource.rc b/src/debugger/resource.rc deleted file mode 100644 index 8da94cc0..00000000 --- a/src/debugger/resource.rc +++ /dev/null @@ -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 - diff --git a/src/debugger/resources/icon.ico b/src/debugger/resources/icon.ico deleted file mode 100644 index b4afb19b..00000000 Binary files a/src/debugger/resources/icon.ico and /dev/null differ diff --git a/src/debugger/std_include.hpp b/src/debugger/std_include.hpp deleted file mode 100644 index 9719ff6b..00000000 --- a/src/debugger/std_include.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -// NOLINTNEXTLINE(google-global-names-in-headers) -using namespace std::literals;