From 70cbb003f21f907548393b466c356f326d3ce527 Mon Sep 17 00:00:00 2001 From: CHatingPython Date: Mon, 17 Aug 2026 11:21:22 +0200 Subject: [PATCH] feat(furdb): introduce info command --- furdb/include/command.hpp | 5 +++ furdb/src/command.cpp | 76 +++++++++++++++++++++++++++++++++++++++ furdb/src/main.cpp | 1 + 3 files changed, 82 insertions(+) diff --git a/furdb/include/command.hpp b/furdb/include/command.hpp index 96234e6..5970bbd 100644 --- a/furdb/include/command.hpp +++ b/furdb/include/command.hpp @@ -41,4 +41,9 @@ public: void execute(context& ctx, const command_info& info) override; }; +class info_command final : public command { +public: + void execute(context& ctx, const command_info& info) override; +}; + #endif // COMMAND_HPP diff --git a/furdb/src/command.cpp b/furdb/src/command.cpp index c464d08..bc7d627 100644 --- a/furdb/src/command.cpp +++ b/furdb/src/command.cpp @@ -71,6 +71,61 @@ void run_command::execute(context& ctx, const command_info& info) { ctx.run(); } +static void print_type(const furvm::thing_type& type) { + switch (type.type) { + case furvm::thing_type::S8: std::cout << "s8"; break; + case furvm::thing_type::S16: std::cout << "s16"; break; + case furvm::thing_type::S32: std::cout << "s32"; break; + case furvm::thing_type::S64: std::cout << "s64"; break; + case furvm::thing_type::U8: std::cout << "u8"; break; + case furvm::thing_type::U16: std::cout << "u16"; break; + case furvm::thing_type::U32: std::cout << "u32"; break; + case furvm::thing_type::U64: std::cout << "u64"; break; + case furvm::thing_type::Ptr: std::cout << "ptr"; break; + case furvm::thing_type::Ref: std::cout << "ref"; break; + case furvm::thing_type::Array: + std::cout << "array("; + print_type(*type.value.array.type); + std::cout << ", "; + if (type.value.array.size == 0) + std::cout << "dynamic"; + else + std::cout << type.value.array.size; + std::cout << ")"; + break; + case furvm::thing_type::Count: break; + } +} + +static void print_thing(const furvm::thing<>& thing) { + std::cout << '('; + print_type(thing.type()); + std::cout << ") "; + switch (thing.type().type) { + case furvm::thing_type::S8: std::cout << thing.get(); break; + case furvm::thing_type::S16: std::cout << thing.get(); break; + case furvm::thing_type::S32: std::cout << thing.get(); break; + case furvm::thing_type::S64: std::cout << thing.get(); break; + case furvm::thing_type::U8: std::cout << thing.get(); break; + case furvm::thing_type::U16: std::cout << thing.get(); break; + case furvm::thing_type::U32: std::cout << thing.get(); break; + case furvm::thing_type::U64: std::cout << thing.get(); break; + case furvm::thing_type::Ptr: std::cout << thing.get(); break; + case furvm::thing_type::Array: { + if (thing.type().value.array.size == 0) std::cout << thing.length(); + std::cout << "{ "; + for (std::size_t i = 0; i < thing.length(); ++i) { + if (i > 0) std::cout << ", "; + print_thing(thing.at(i)); + } + std::cout << " }"; + } break; + case furvm::thing_type::Ref: + case furvm::thing_type::Count: break; + } + std::cout << '\n'; +} + static void breakpoint_hit(furvm::executor& executor, void* data) { std::cout << "Breakpoint hit\n"; context* ctx = reinterpret_cast(data); @@ -99,3 +154,24 @@ void break_command::execute(context& ctx, const command_info& info) { } std::cout << "Breakpoint set in " << count << " places\n"; } + +void info_command::execute(context& ctx, const command_info& info) { + if (info.args.empty()) { + std::cout << "Possible arguments:\n"; + std::cout << "- variables\n"; + } else if (info.args[0] == "variables") { + if (ctx.executor->frames().empty()) { + std::cerr << "Not running\n"; + return; + } + std::cout << "Variables:\n"; + const auto& frame = ctx.executor->top_frame(); + for (std::size_t i = 0; i < frame.variables.size(); ++i) { + // TODO: Add debug information to modules + std::cout << "- %" << i << " = "; + print_thing(frame.variables[i]); + } + } else { + std::cerr << "Unexpected argument \"" << info.args[0] << "\"\n"; + } +} diff --git a/furdb/src/main.cpp b/furdb/src/main.cpp index a707628..ba41df5 100644 --- a/furdb/src/main.cpp +++ b/furdb/src/main.cpp @@ -46,6 +46,7 @@ int main(int argc, char** argv) { 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(); + s_commands["info"] = s_commands["i"] = new info_command(); try { std::ifstream file(argv[1], std::ios::binary | std::ios::in);