diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index abf4731..2e3d06f 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -37,17 +37,17 @@ jobs: - name: Configure CMake run: | - cmake -G Ninja -B build -D CMAKE_BUILD_TYPE=Debug -D CMAKE_C_COMPILER=clang -D CMAKE_CXX_COMPILER=clang++ "-DLLVM_DIR=C:/llvm/lib/cmake/llvm" -DCMAKE_VERBOSE_MAKEFILE=ON + cmake -G Ninja -B build -D CMAKE_BUILD_TYPE=Release -D CMAKE_C_COMPILER=clang -D CMAKE_CXX_COMPILER=clang++ "-DLLVM_DIR=C:/llvm/lib/cmake/llvm" -DCMAKE_VERBOSE_MAKEFILE=ON shell: cmd - name: Build Target run: | - cmake --build build --config Debug + cmake --build build --config Release shell: cmd - name: Install Build run: | - cmake --install build --config Debug + cmake --install build --config Release shell: cmd - name: Package Artifacts @@ -59,4 +59,4 @@ jobs: uses: actions/upload-artifact@v4 with: name: lldb-frontend-windows - path: lldb-frontend-windows.tar.gz \ No newline at end of file + path: lldb-frontend-windows.tar.gz diff --git a/cmake/CompilerFlags.cmake b/cmake/CompilerFlags.cmake index 717e28a..9af82f2 100644 --- a/cmake/CompilerFlags.cmake +++ b/cmake/CompilerFlags.cmake @@ -1,5 +1,5 @@ if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Debug") - message(FATAL_ERROR "Build must be set to Debug") + message(WARNING "Build is not set to Debug") else() message(STATUS "CMAKE_BUILD_TYPE is Debug") diff --git a/cmake/Install.cmake b/cmake/Install.cmake index 6a0e268..204ad77 100644 --- a/cmake/Install.cmake +++ b/cmake/Install.cmake @@ -6,7 +6,9 @@ install(FILES ${CMAKE_BINARY_DIR}/imgui.ini DESTINATION bin COMPONENT Runtime) install(TARGETS ${PROJECT_NAME}-test RUNTIME DESTINATION bin COMPONENT Tests) -if(WIN32 AND (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "MSVC")) - install(FILES "$" DESTINATION bin COMPONENT Runtime) - install(FILES "$" DESTINATION bin COMPONENT Tests) +if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") + if(WIN32 AND (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "MSVC")) + install(FILES "$" DESTINATION bin COMPONENT Runtime) + install(FILES "$" DESTINATION bin COMPONENT Tests) + endif() endif() \ No newline at end of file diff --git a/src/Args.cpp b/src/Args.cpp index 5b9a505..466ebe8 100644 --- a/src/Args.cpp +++ b/src/Args.cpp @@ -8,6 +8,9 @@ namespace lldb_frontend { .help("The program you wish to debug"); parser.add_argument("--autoexec") .help("Script file containing autoexec instructions"); + parser.add_argument("--") + .remaining() + .help("Arguments to forward"); } bool Args::Parse(int argc, char **argv) { @@ -24,4 +27,8 @@ namespace lldb_frontend { void Args::ShowHelp() { std::cout << parser.help().str() << std::endl; } + + std::vector Args::ForwardArgs() { + return parser.get>("--"); + } } diff --git a/src/Args.hpp b/src/Args.hpp index c5e706b..2c75c37 100644 --- a/src/Args.hpp +++ b/src/Args.hpp @@ -10,6 +10,7 @@ namespace lldb_frontend { static void SetupOptions(); static bool Parse(int argc, char** argv); static void ShowHelp(); + static std::vector ForwardArgs(); public: template static std::optional Get(const std::string& name) { diff --git a/src/ImGuiLayer.cpp b/src/ImGuiLayer.cpp index 3e69703..8fc800b 100644 --- a/src/ImGuiLayer.cpp +++ b/src/ImGuiLayer.cpp @@ -4,6 +4,7 @@ #define IMGUI_DEFINE_MATH_OPERATORS #include #include +#include #include #include #include @@ -11,6 +12,7 @@ #include #include "Window.hpp" #include "Util.hpp" +#include "Args.hpp" #include "Logger.hpp" #include "Resources.hpp" #include "Styling.hpp" @@ -305,11 +307,47 @@ void ImGuiLayer::DrawLocalsWindow() { ImGui::End(); } -void ImGuiLayer::DrawControlsWindow() { - ImGui::Begin("Controls"); +void ImGuiLayer::DrawRunButton() { + std::array executable_path; + static std::vector args = lldb_frontend::Args::ForwardArgs(); + static int delete_index = -1; if (ImGui::Button("Run")) { - window_ref->GetDebuggerCtx().LaunchTarget(); + auto argsConverted = Util::ConvertArgsToArgv(args); + for (const auto& s : argsConverted) { + Logger::Info("{}", s.data()); + } + window_ref->GetDebuggerCtx().LaunchTarget(args); + } + if (ImGui::IsItemHovered()) { + ImGui::SetTooltip("Right click for args"); + if (ImGui::IsMouseClicked(ImGuiMouseButton_Right)) { + ImGui::OpenPopup("Run Args"); + } + } + if (ImGui::BeginPopup("Run Args")) { + ImGui::InputText("executable", executable_path.data(), executable_path.size()); + for (int i = 0; i < args.size(); i++) { + ImGui::PushID(i); + ImGui::InputText("", &args.at(i)); + ImGui::SameLine(); + if (ImGui::Button("-")) { + delete_index = i; + } + ImGui::PopID(); + } + if (delete_index != -1) { + args.erase(args.begin() + delete_index); + delete_index = -1; + } + + if (ImGui::Button("+")) args.push_back(std::string()); + ImGui::EndPopup(); } +} + +void ImGuiLayer::DrawControlsWindow() { + ImGui::Begin("Controls"); + DrawRunButton(); if (ImGui::Button("Continue")) { window_ref->GetDebuggerCtx().Continue(); } diff --git a/src/ImGuiLayer.hpp b/src/ImGuiLayer.hpp index 479662e..559313a 100644 --- a/src/ImGuiLayer.hpp +++ b/src/ImGuiLayer.hpp @@ -31,6 +31,7 @@ class ImGuiLayer { private: bool LoadFile(FileHierarchy::TreeNode&); + void ProcessArguments(const char*, char*, int, char*[100]); private: void DrawDebugWindow(); @@ -47,6 +48,7 @@ class ImGuiLayer { void DrawFileBrowser(); private: + void DrawRunButton(); void DrawCodeFile(FileHierarchy::TreeNode&); void DrawLocal(lldb::SBValue&, const std::string& = ""); diff --git a/src/LLDBDebugger.cpp b/src/LLDBDebugger.cpp index 83b404b..9395681 100644 --- a/src/LLDBDebugger.cpp +++ b/src/LLDBDebugger.cpp @@ -32,7 +32,7 @@ LLDBDebugger::~LLDBDebugger() { lldbEventThread.join(); } -void LLDBDebugger::LaunchTarget() { +void LLDBDebugger::LaunchTarget(std::optional> args) { Logger::ScopedGroup g("LaunchTarget"); auto target = GetTarget(); if (!target.IsValid()) { @@ -70,8 +70,16 @@ void LLDBDebugger::LaunchTarget() { return; } + static std::vector argv_intermediate; const char **argv = nullptr; // or fill if you need const char **envp = nullptr; + if (args.has_value()) { + for (const auto& a : *args) { + argv_intermediate.push_back(a.c_str()); + } + argv_intermediate.push_back(nullptr); + argv = argv_intermediate.data(); + } auto in_string = in_redirect.path.string(); auto err_string = err_redirect.path.string(); @@ -346,7 +354,7 @@ LLDBDebugger::ExecResult LLDBDebugger::ExecCommand(const std::string& command, F } case LLDB_CommandParser::ParsedCommandType::RUN: { - LaunchTarget(); + LaunchTarget(std::nullopt); break; } case LLDB_CommandParser::ParsedCommandType::STEP: diff --git a/src/LLDBDebugger.hpp b/src/LLDBDebugger.hpp index ef75cea..adc1e42 100644 --- a/src/LLDBDebugger.hpp +++ b/src/LLDBDebugger.hpp @@ -44,7 +44,7 @@ class LLDBDebugger { LLDBDebugger(); ~LLDBDebugger(); - void LaunchTarget(); + void LaunchTarget(std::optional> args); lldb::SBDebugger& GetDebugger(); lldb::SBTarget GetTarget(); lldb::SBProcess GetProcess(); diff --git a/src/Util.cpp b/src/Util.cpp index 295df34..e002737 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -240,4 +240,16 @@ namespace Util { return SystemTheme::LIGHT; // unsupported platform #endif } + + std::vector ConvertArgsToArgv(std::vector& args) { + std::vector converted; + for (auto& arg : args) { + size_t loc = arg.find(' '); + if (loc != std::string::npos) { + converted.push_back(arg.substr(0, loc)); + converted.push_back(arg.substr(loc + 1)); + } + } + return converted; + } } diff --git a/src/Util.hpp b/src/Util.hpp index 069ef67..d4bfff7 100644 --- a/src/Util.hpp +++ b/src/Util.hpp @@ -22,6 +22,8 @@ namespace Util { inline static std::string PathSeparator = std::string(1, char(std::filesystem::path::preferred_separator)); SystemTheme GetSystemTheme(); + + std::vector ConvertArgsToArgv(std::vector& args); } #endif diff --git a/src/main.cpp b/src/main.cpp index 87289e7..b30d416 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -48,6 +48,12 @@ int main(int argc, char** argv) { std::cout << "Provided executable: " << *value << std::endl; } + auto remaining = lldb_frontend::Args::ForwardArgs(); + std::cout << "Remaining" << std::endl; + for (auto& a : remaining) { + std::cout << a << std::endl; + } + lldb_frontend::Init::InitGlfw(); auto [width, height] = lldb_frontend::Init::GetImGuiIniDimensions(); diff --git a/test/test.cpp b/test/test.cpp index fd85a41..1fb6f3e 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -7,6 +7,10 @@ void testFunction() { } int main(int argc, const char **argv) { + for (int i = 0; i < argc; i++) { + std::cout << argv[i] << std::endl; + } + std::cout << "argv[0]: " << argv[0] << std::endl; std::cout << "Hello world from test" << std::endl; std::cout << "Hello world from test" << std::endl;