regs and we can step into!

This commit is contained in:
T0b1
2023-06-02 02:06:49 +02:00
parent d4bf6731a3
commit ac3718b12b
17 changed files with 1434 additions and 344 deletions

101
src/frontend/window.cpp Normal file
View File

@@ -0,0 +1,101 @@
#include "window.h"
#include "frontend.h"
using namespace dbgui;
using namespace dbgui::frontend;
void Window::draw(const Frontend &frontend)
{
switch (this->type)
{
using enum WindowType;
case regs: std::get<RegWindow>(this->data).draw(frontend); break;
default: printf("Unhandled window draw: %u\n", this->type); exit(1);
}
}
Window Window::create_regs(size_t id)
{
auto id_str = std::string{"Registers##"};
id_str.append(std::to_string(id));
return Window{.type = WindowType::regs,
.data = RegWindow{.id = id_str, .open = true}};
}
void RegWindow::draw(const Frontend &frontend)
{
ImGui::SetNextWindowDockID(frontend.dock_id, ImGuiCond_Appearing);
if (!ImGui::Begin(this->id.c_str()))
{
return;
}
if (!frontend.target)
{
ImGui::End();
return;
}
if (ImGui::BeginTable("table", 1,
ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg))
{
const auto &sets = frontend.target->reg_sets;
for (size_t set_idx = 0; set_idx < sets.size(); ++set_idx)
{
const auto &set = sets[set_idx];
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::Text(set.name.c_str());
char buf[20];
std::snprintf(buf, sizeof(buf), "nested_%lu", set_idx);
if (ImGui::BeginTable(buf, 2,
ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg))
{
for (size_t i = 0; i < set.regs.size(); ++i)
{
const auto &reg = set.regs[i];
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::Text(reg.name.c_str());
ImGui::TableNextColumn();
if (reg.bytes.size() == 0)
{
ImGui::Text("<unk>");
continue;
}
switch (reg.bytes.size())
{
case 1: std::snprintf(buf, sizeof(buf), "%X", reg.bytes[0]); break;
case 2:
std::snprintf(
buf, sizeof(buf), "%X",
*reinterpret_cast<const uint16_t *>(reg.bytes.data()));
break;
case 4:
std::snprintf(
buf, sizeof(buf), "%X",
*reinterpret_cast<const uint32_t *>(reg.bytes.data()));
break;
case 8:
std::snprintf(
buf, sizeof(buf), "%lX",
*reinterpret_cast<const uint64_t *>(reg.bytes.data()));
break;
default: std::snprintf(buf, sizeof(buf), "<val too large>"); break;
}
ImGui::Text(buf);
}
ImGui::EndTable();
}
}
ImGui::EndTable();
}
ImGui::End();
}