Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -59,4 +59,4 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: lldb-frontend-windows
path: lldb-frontend-windows.tar.gz
path: lldb-frontend-windows.tar.gz
2 changes: 1 addition & 1 deletion cmake/CompilerFlags.cmake
Original file line number Diff line number Diff line change
@@ -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")

Expand Down
8 changes: 5 additions & 3 deletions cmake/Install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$<TARGET_PDB_FILE:${PROJECT_NAME}>" DESTINATION bin COMPONENT Runtime)
install(FILES "$<TARGET_PDB_FILE:${PROJECT_NAME}-test>" 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 "$<TARGET_PDB_FILE:${PROJECT_NAME}>" DESTINATION bin COMPONENT Runtime)
install(FILES "$<TARGET_PDB_FILE:${PROJECT_NAME}-test>" DESTINATION bin COMPONENT Tests)
endif()
endif()
7 changes: 7 additions & 0 deletions src/Args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -24,4 +27,8 @@ namespace lldb_frontend {
void Args::ShowHelp() {
std::cout << parser.help().str() << std::endl;
}

std::vector<std::string> Args::ForwardArgs() {
return parser.get<std::vector<std::string>>("--");
}
}
1 change: 1 addition & 0 deletions src/Args.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace lldb_frontend {
static void SetupOptions();
static bool Parse(int argc, char** argv);
static void ShowHelp();
static std::vector<std::string> ForwardArgs();
public:
template<typename T>
static std::optional<T> Get(const std::string& name) {
Expand Down
44 changes: 41 additions & 3 deletions src/ImGuiLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
#define IMGUI_DEFINE_MATH_OPERATORS
#include <imgui.h>
#include <imgui_internal.h>
#include <misc/cpp/imgui_stdlib.h>
#include <backends/imgui_impl_glfw.h>
#include <backends/imgui_impl_opengl3.h>
#include <tinyfiledialogs.h>
#include <iostream>
#include <fstream>
#include "Window.hpp"
#include "Util.hpp"
#include "Args.hpp"
#include "Logger.hpp"
#include "Resources.hpp"
#include "Styling.hpp"
Expand Down Expand Up @@ -305,11 +307,47 @@ void ImGuiLayer::DrawLocalsWindow() {
ImGui::End();
}

void ImGuiLayer::DrawControlsWindow() {
ImGui::Begin("Controls");
void ImGuiLayer::DrawRunButton() {
std::array<char, 100> executable_path;
static std::vector<std::string> 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();
}
Expand Down
2 changes: 2 additions & 0 deletions src/ImGuiLayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class ImGuiLayer {

private:
bool LoadFile(FileHierarchy::TreeNode&);
void ProcessArguments(const char*, char*, int, char*[100]);

private:
void DrawDebugWindow();
Expand All @@ -47,6 +48,7 @@ class ImGuiLayer {
void DrawFileBrowser();

private:
void DrawRunButton();
void DrawCodeFile(FileHierarchy::TreeNode&);
void DrawLocal(lldb::SBValue&, const std::string& = "");

Expand Down
12 changes: 10 additions & 2 deletions src/LLDBDebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ LLDBDebugger::~LLDBDebugger() {
lldbEventThread.join();
}

void LLDBDebugger::LaunchTarget() {
void LLDBDebugger::LaunchTarget(std::optional<std::vector<std::string>> args) {
Logger::ScopedGroup g("LaunchTarget");
auto target = GetTarget();
if (!target.IsValid()) {
Expand Down Expand Up @@ -70,8 +70,16 @@ void LLDBDebugger::LaunchTarget() {
return;
}

static std::vector<const char*> 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();
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/LLDBDebugger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class LLDBDebugger {
LLDBDebugger();
~LLDBDebugger();

void LaunchTarget();
void LaunchTarget(std::optional<std::vector<std::string>> args);
lldb::SBDebugger& GetDebugger();
lldb::SBTarget GetTarget();
lldb::SBProcess GetProcess();
Expand Down
12 changes: 12 additions & 0 deletions src/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,16 @@ namespace Util {
return SystemTheme::LIGHT; // unsupported platform
#endif
}

std::vector<std::string> ConvertArgsToArgv(std::vector<std::string>& args) {
std::vector<std::string> 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;
}
}
2 changes: 2 additions & 0 deletions src/Util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace Util {
inline static std::string PathSeparator = std::string(1, char(std::filesystem::path::preferred_separator));

SystemTheme GetSystemTheme();

std::vector<std::string> ConvertArgsToArgv(std::vector<std::string>& args);
}

#endif
6 changes: 6 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down