feat(furdb): add break command
This commit is contained in:
@@ -36,4 +36,9 @@ public:
|
|||||||
void execute(context& ctx, const command_info& info) override;
|
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
|
#endif // COMMAND_HPP
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ struct context {
|
|||||||
furvm::function_h mainFunction;
|
furvm::function_h mainFunction;
|
||||||
|
|
||||||
bool running = true;
|
bool running = true;
|
||||||
|
bool halt = false;
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
};
|
};
|
||||||
|
|||||||
+32
-1
@@ -1,5 +1,10 @@
|
|||||||
#include "command.hpp"
|
#include "command.hpp"
|
||||||
|
|
||||||
|
#include "furvm/executor.hpp"
|
||||||
|
#include "furvm/function.hpp"
|
||||||
|
#include "furvm/module.hpp"
|
||||||
|
#include "furvm/thing.hpp"
|
||||||
|
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <iostream>
|
#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) {
|
void run_command::execute(context& ctx, const command_info& info) {
|
||||||
ctx.run();
|
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";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,15 @@
|
|||||||
#include "context.hpp"
|
#include "context.hpp"
|
||||||
|
|
||||||
|
#include <furvm/executor.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
void context::run() {
|
void context::run() {
|
||||||
if ((executor->flags() & furvm::executor_flags::Done) != furvm::executor_flags::Done)
|
if ((executor->flags() & furvm::executor_flags::Done) != furvm::executor_flags::Done)
|
||||||
executor->push_frame(mod, *mainFunction);
|
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();
|
executor->step();
|
||||||
}
|
}
|
||||||
|
if ((executor->flags() & furvm::executor_flags::Done) == furvm::executor_flags::Done) {
|
||||||
|
std::cout << "Execution finished\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -43,8 +43,9 @@ int main(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static std::unordered_map<std::string_view, command*> s_commands;
|
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["run"] = s_commands["r"] = new run_command();
|
||||||
|
s_commands["break"] = s_commands["b"] = new break_command();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
std::ifstream file(argv[1], std::ios::binary | std::ios::in);
|
std::ifstream file(argv[1], std::ios::binary | std::ios::in);
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ struct mod_type {
|
|||||||
|
|
||||||
struct breakpoint {
|
struct breakpoint {
|
||||||
std::function<void(executor&, void*)> callback;
|
std::function<void(executor&, void*)> callback;
|
||||||
void* data;
|
void* data = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
class mod {
|
class mod {
|
||||||
|
|||||||
Reference in New Issue
Block a user