feat(furdb): add break command

This commit is contained in:
2026-08-16 20:01:52 +02:00
parent b3ce4fa0ed
commit a4966a057c
6 changed files with 48 additions and 4 deletions
+5
View File
@@ -36,4 +36,9 @@ public:
void execute(context& ctx, const command_info& info) override;
};
class break_command final : public command {
public:
void execute(context& ctx, const command_info& info) override;
};
#endif // COMMAND_HPP
+1
View File
@@ -13,6 +13,7 @@ struct context {
furvm::function_h mainFunction;
bool running = true;
bool halt = false;
void run();
};
+32 -1
View File
@@ -1,5 +1,10 @@
#include "command.hpp"
#include "furvm/executor.hpp"
#include "furvm/function.hpp"
#include "furvm/module.hpp"
#include "furvm/thing.hpp"
#include <cctype>
#include <cstddef>
#include <iostream>
@@ -51,5 +56,31 @@ void quit_command::execute(context& ctx, const command_info& info) {
void run_command::execute(context& ctx, const command_info& info) {
ctx.run();
std::cout << "Execution finished\n";
}
static void breakpoint_hit(furvm::executor& executor, void* data) {
std::cout << "Breakpoint hit\n";
context* ctx = reinterpret_cast<context*>(data);
ctx->halt = true;
}
void break_command::execute(context& ctx, const command_info& info) {
if (info.args.empty()) {
std::cerr << "Usage: " << info.commandName << " <function name>\n";
return;
}
std::size_t count = 0;
for (const auto& [id, sigPair] : ctx.mod->function_map()) {
if (sigPair.first != info.args[0]) continue;
const auto& func = ctx.mod->function_at(id);
if (func->type() != furvm::function_t::Normal) continue;
count += 1;
ctx.mod->set_breakpoint(func->position(), furvm::breakpoint{ breakpoint_hit, &ctx });
}
if (count == 0) {
std::cerr << "No function \"" << info.args[0] << "\" found!\n";
return;
}
std::cout << "Breakpoint set in " << count << " places\n";
}
+7 -1
View File
@@ -1,9 +1,15 @@
#include "context.hpp"
#include <furvm/executor.hpp>
#include <iostream>
void context::run() {
if ((executor->flags() & furvm::executor_flags::Done) != furvm::executor_flags::Done)
executor->push_frame(mod, *mainFunction);
while ((executor->flags() & furvm::executor_flags::Done) != furvm::executor_flags::Done) {
while ((executor->flags() & furvm::executor_flags::Done) != furvm::executor_flags::Done && !halt) {
executor->step();
}
if ((executor->flags() & furvm::executor_flags::Done) == furvm::executor_flags::Done) {
std::cout << "Execution finished\n";
}
}
+2 -1
View File
@@ -43,8 +43,9 @@ int main(int argc, char** argv) {
}
static std::unordered_map<std::string_view, command*> s_commands;
s_commands["quit"] = s_commands["q"] = new quit_command();
s_commands["exit"] = s_commands["quit"] = s_commands["q"] = new quit_command();
s_commands["run"] = s_commands["r"] = new run_command();
s_commands["break"] = s_commands["b"] = new break_command();
try {
std::ifstream file(argv[1], std::ios::binary | std::ios::in);