This commit is contained in:
T0b1
2023-06-15 02:25:57 +02:00
parent b393f3dd28
commit 9ab08de243
15 changed files with 1294 additions and 166 deletions

View File

@@ -348,10 +348,37 @@ void Frontend::handle_msgs()
case data_result:
{
const auto &result = std::get<BackToFront::DataResult>(msg->data);
printf("Result ID: %lu\n", result.result.id);
for (auto &window : _windows)
for (size_t i = 0; i < result.nodes.size(); ++i)
{
window.handle_data_res(result);
uint16_t idx = result.nodes[i].idx;
if (this->target->data_res_nodes.size() <= idx)
{
this->target->data_res_nodes.resize(idx + 1);
}
this->target->data_res_nodes[idx] = std::move(result.nodes[i]);
}
if (result.src_node_id)
{
auto id = result.src_node_id->second;
auto found = false;
for (auto &entry : this->target->src_id_to_data_idx)
{
if (entry.first == id)
{
entry.second = result.src_node_id->first;
found = true;
break;
}
}
if (!found)
{
this->target->src_id_to_data_idx.push_back(
std::make_pair(id, result.src_node_id->first));
}
for (auto &window : _windows)
{
window.handle_source_updated(*this->target, id);
}
}
break;
}

View File

@@ -80,6 +80,34 @@ namespace dbgui::frontend
Target(std::string filename);
std::optional<uint16_t> data_idx_for_src_id(size_t id)
{
for (auto &[entry_id, idx] : this->src_id_to_data_idx)
{
if (entry_id == id)
{
return idx;
}
}
return {};
}
data::result::Node *data_node_for_src_id(size_t id)
{
auto idx = this->data_idx_for_src_id(id);
if (!idx)
{
return nullptr;
}
if (*idx >= data_res_nodes.size() || !data_res_nodes[*idx])
{
return nullptr;
}
return &*data_res_nodes[*idx];
}
TargetState state = TargetState::stopped;
std::string filename;
uint64_t id;
@@ -93,6 +121,8 @@ namespace dbgui::frontend
std::vector<std::optional<Thread>> threads;
std::vector<std::optional<Frame>> frames;
std::vector<Breakpoint> breakpoints;
std::vector<std::pair<size_t, uint16_t>> src_id_to_data_idx;
std::vector<std::optional<data::result::Node>> data_res_nodes;
std::shared_ptr<backend::Backend> backend = nullptr;
};

View File

@@ -468,17 +468,18 @@ bool DisasmWindow::draw(Frontend &frontend)
this->ip_src_id = frontend.target->data_node_id++;
this->disas_src_id = frontend.target->data_node_id++;
using namespace data::source;
frontend.target->backend->add_data_node(
data::DataNode{.id = this->ip_src_id,
.type = data::DataNode::Type::data_source,
.data = data::DataSource{
.type = data::DataSource::Type::frame_ip,
}});
Node{.id = this->ip_src_id,
.type = Node::Type::source,
.data = Source{
.type = Source::Type::frame_ip,
}});
frontend.target->backend->add_data_node(
data::DataNode{.id = this->disas_src_id,
.type = data::DataNode::Type::disassemble,
.data = data::Disassemble{.src_id = this->ip_src_id}});
Node{.id = this->disas_src_id,
.type = Node::Type::disassemble,
.data = Disassemble{.src_id = this->ip_src_id}});
first = false;
}
@@ -760,17 +761,18 @@ bool SourceWindow::draw(Frontend &frontend)
this->ip_src_id = frontend.target->data_node_id++;
this->line_entry_src_id = frontend.target->data_node_id++;
using namespace data::source;
frontend.target->backend->add_data_node(
data::DataNode{.id = this->ip_src_id,
.type = data::DataNode::Type::data_source,
.data = data::DataSource{
.type = data::DataSource::Type::frame_ip,
}});
Node{.id = this->ip_src_id,
.type = Node::Type::source,
.data = Source{
.type = Source::Type::frame_ip,
}});
frontend.target->backend->add_data_node(
data::DataNode{.id = this->line_entry_src_id,
.type = data::DataNode::Type::line_entry,
.data = data::LineEntry{.src_id = this->ip_src_id}});
Node{.id = this->line_entry_src_id,
.type = Node::Type::line_entry,
.data = LineEntry{.src_id = this->ip_src_id}});
first = false;
}
@@ -968,29 +970,29 @@ bool SourceWindow::draw(Frontend &frontend)
return false;
}
void Window::handle_data_res(const BackToFront::DataResult &result)
void Window::handle_source_updated(Target &target, size_t id)
{
switch (this->type)
{
using enum WindowType;
case disassembly:
std::get<DisasmWindow>(this->data).handle_data_res(result);
std::get<DisasmWindow>(this->data).handle_source_updated(target, id);
break;
case source:
std::get<SourceWindow>(this->data).handle_data_res(result);
std::get<SourceWindow>(this->data).handle_source_updated(target, id);
break;
default: break;
}
}
void DisasmWindow::handle_data_res(
const BackToFront::DataResult &result_wrapper)
void DisasmWindow::handle_source_updated(Target &target, size_t id)
{
const auto &result = result_wrapper.result;
if (result.id == this->ip_src_id)
if (id == this->ip_src_id)
{
if (!result.success || result.type.type != data::TypeInfo::Type::u64)
auto result = target.data_node_for_src_id(id);
if (!result || !result->success
|| result->type_id.type != data::type_info::Type::u64)
{
this->ip_unsuccessful = true;
return;
@@ -998,17 +1000,19 @@ void DisasmWindow::handle_data_res(
this->ip_unsuccessful = false;
this->ip_changed = true;
this->ip = *reinterpret_cast<const uint64_t *>(result.data.data());
this->ip = std::get<uint64_t>(result->data);
printf("IP changed to %lX\n", this->ip);
return;
}
if (result.id != this->disas_src_id)
if (id != this->disas_src_id)
{
return;
}
if (!result.success || result.type.type != data::TypeInfo::Type::custom)
auto result = target.data_node_for_src_id(id);
if (!result || !result->success
|| result->type_id.type != data::type_info::Type::custom)
{
this->disas_unsuccessful = true;
this->insts.clear();
@@ -1035,21 +1039,20 @@ void DisasmWindow::handle_data_res(
uint8_t max_mnem_len = 0;
uint8_t max_op_len = 0;
while (idx < result.data.size())
const auto &data = result->vec_data();
while (idx < data.size())
{
if (result.data.size() - idx < 12)
if (data.size() - idx < 12)
{
break;
}
uint64_t addr = *reinterpret_cast<const uint64_t *>(&result.data[idx]);
uint8_t mnem_len =
*reinterpret_cast<const uint8_t *>(&result.data[idx + 8]);
uint8_t op_len = *reinterpret_cast<const uint8_t *>(&result.data[idx + 9]);
uint8_t comment_len =
*reinterpret_cast<const uint8_t *>(&result.data[idx + 10]);
uint64_t addr = *reinterpret_cast<const uint64_t *>(&data[idx]);
uint8_t mnem_len = *reinterpret_cast<const uint8_t *>(&data[idx + 8]);
uint8_t op_len = *reinterpret_cast<const uint8_t *>(&data[idx + 9]);
uint8_t comment_len = *reinterpret_cast<const uint8_t *>(&data[idx + 10]);
// dc about inst_len rn
idx += 12;
if (result.data.size() - idx < mnem_len + op_len + comment_len)
if (data.size() - idx < mnem_len + op_len + comment_len)
{
break;
}
@@ -1057,12 +1060,12 @@ void DisasmWindow::handle_data_res(
if (comment_len)
{
std::snprintf(buf, sizeof(buf), "%.*s%%*c%.*s%%.*c ; %.*s", mnem_len,
&result.data[idx], op_len, &result.data[idx + mnem_len],
comment_len, &result.data[idx + mnem_len + op_len]);
&data[idx], op_len, &data[idx + mnem_len], comment_len,
&data[idx + mnem_len + op_len]);
} else
{
std::snprintf(buf, sizeof(buf), "%.*s%%*c%.*s%%.*c", mnem_len,
&result.data[idx], op_len, &result.data[idx + mnem_len]);
std::snprintf(buf, sizeof(buf), "%.*s%%*c%.*s%%.*c", mnem_len, &data[idx],
op_len, &data[idx + mnem_len]);
}
idx += mnem_len + op_len + comment_len;
@@ -1086,22 +1089,22 @@ void DisasmWindow::handle_data_res(
this->max_op_len = max_op_len;
}
void SourceWindow::handle_data_res(
const BackToFront::DataResult &result_wrapper)
void SourceWindow::handle_source_updated(Target &target, size_t id)
{
const auto &result = result_wrapper.result;
if (result.id == this->ip_src_id)
if (id == this->ip_src_id)
{
// should not need to care
return;
}
if (result.id != this->line_entry_src_id)
if (id != this->line_entry_src_id)
{
return;
}
if (!result.success || result.type.type != data::TypeInfo::Type::custom)
auto result = target.data_node_for_src_id(id);
if (!result || !result->success
|| result->type_id.type != data::type_info::Type::custom)
{
this->lines.clear();
this->file_data.clear();
@@ -1117,7 +1120,8 @@ void SourceWindow::handle_data_res(
// char file_name[];
// };
if (result.data.size() < 8)
const auto &data = result->vec_data();
if (data.size() < 8)
{
this->lines.clear();
this->file_data.clear();
@@ -1126,10 +1130,9 @@ void SourceWindow::handle_data_res(
return;
}
const auto line = *reinterpret_cast<const uint32_t *>(result.data.data());
const auto name_len =
*reinterpret_cast<const uint32_t *>(result.data.data() + 4);
if (result.data.size() < 8 + name_len)
const auto line = *reinterpret_cast<const uint32_t *>(data.data());
const auto name_len = *reinterpret_cast<const uint32_t *>(data.data() + 4);
if (data.size() < 8 + name_len)
{
this->lines.clear();
this->file_data.clear();
@@ -1138,8 +1141,8 @@ void SourceWindow::handle_data_res(
return;
}
const auto file_view = std::string_view{
reinterpret_cast<const char *>(result.data.data() + 8), name_len};
const auto file_view =
std::string_view{reinterpret_cast<const char *>(data.data() + 8), name_len};
printf("New LE: %.*s:%u", static_cast<int>(file_view.size()),
file_view.data(), line);

View File

@@ -84,7 +84,7 @@ namespace dbgui::frontend
bool draw(Frontend &);
void handle_data_res(const BackToFront::DataResult &result);
void handle_source_updated(Target& target, size_t id);
std::string id;
bool open;
@@ -110,7 +110,7 @@ namespace dbgui::frontend
struct SourceWindow
{
bool draw(Frontend &);
void handle_data_res(const BackToFront::DataResult &result);
void handle_source_updated(Target& target, size_t id);
std::string id;
bool open;
@@ -141,6 +141,6 @@ namespace dbgui::frontend
static Window create_bp(size_t window_id);
static Window create_source(size_t window_id);
void handle_data_res(const BackToFront::DataResult &result);
void handle_source_updated(Target& target, size_t id);
};
} // namespace dbgui::frontend