This commit is contained in:
T0b1
2023-06-29 02:13:07 +02:00
parent 83fb234d5c
commit 6f0b3b9e99
4 changed files with 65 additions and 17 deletions

View File

@@ -1487,6 +1487,17 @@ void LLDBBackend::add_data_node(const data::source::Node &node)
_data_dag.add_edge(node.id, src_id); _data_dag.add_edge(node.id, src_id);
break; break;
} }
case read_cstr:
{
auto src_id = std::get<data::source::ReadAsCStr>(node.data).src_id;
if (!_data_dag.nodes.contains(src_id))
{
printf("Invalid add sequence\n");
exit(1);
}
_data_dag.add_edge(node.id, src_id);
break;
}
} }
_dag_linear_valid = false; _dag_linear_valid = false;
@@ -2159,9 +2170,11 @@ std::optional<std::pair<uint16_t, size_t>>
cache_idx = get_free_res_slot(); cache_idx = get_free_res_slot();
} }
size_t addr_id = std::get<data::source::ReadAsCStr>(node.data).src_id; size_t addr_id = std::get<data::source::ReadAsCStr>(node.data).src_id;
uint16_t addr_idx = *find_node_for_src_id(addr_id); uint16_t addr_parent_idx = *find_node_for_src_id(addr_id);
if (!_data_res[addr_idx] || !_data_res[addr_idx]->node.success) if (!_data_res[addr_parent_idx]
|| !_data_res[addr_parent_idx]->node.success
|| _data_res[addr_parent_idx]->node.children.size() != 1)
{ {
return check_single_res_changed(data::result::Node{ return check_single_res_changed(data::result::Node{
.idx = cache_idx, .idx = cache_idx,
@@ -2170,7 +2183,11 @@ std::optional<std::pair<uint16_t, size_t>>
}); });
} }
if (_data_res[addr_idx]->node.type_id.type != data::type_info::Type::ptr) uint16_t addr_idx = _data_res[addr_parent_idx]->node.children[0];
if (!_data_res[addr_idx] || !_data_res[addr_idx]->node.success
|| _data_res[addr_idx]->node.type_id.type
!= data::type_info::Type::ptr)
{ {
return check_single_res_changed(data::result::Node{ return check_single_res_changed(data::result::Node{
.idx = cache_idx, .idx = cache_idx,
@@ -2179,7 +2196,7 @@ std::optional<std::pair<uint16_t, size_t>>
}); });
} }
auto addr = std::get<uint64_t>(_data_res[addr_idx]->node.data); auto addr = _data_res[addr_idx]->node.get_primitive<uint64_t>(0);
std::vector<uint8_t> buf{}; std::vector<uint8_t> buf{};
char tmp_buf[256]; char tmp_buf[256];

View File

@@ -101,6 +101,10 @@ void Frontend::run_frame()
auto &entry = this->target->expr_cache[i]; auto &entry = this->target->expr_cache[i];
if (!entry.used_this_frame) if (!entry.used_this_frame)
{ {
if (entry.is_cstr)
{
this->target->backend->remove_data_node(entry.id2);
}
this->target->backend->remove_data_node(entry.id); this->target->backend->remove_data_node(entry.id);
this->target->expr_cache.erase(this->target->expr_cache.begin() + i); this->target->expr_cache.erase(this->target->expr_cache.begin() + i);
} else } else

View File

@@ -82,7 +82,9 @@ namespace dbgui::frontend
{ {
std::string expr_path; std::string expr_path;
size_t id; size_t id;
size_t id2;
bool used_this_frame = false; bool used_this_frame = false;
bool is_cstr = false;
}; };
Target(std::string filename); Target(std::string filename);
@@ -115,26 +117,37 @@ namespace dbgui::frontend
return &*data_res_nodes[*idx]; return &*data_res_nodes[*idx];
} }
size_t find_or_create_expr_path(std::string &&path) size_t find_or_create_expr_path(std::string &&path, bool is_cstr = false)
{ {
for (auto &entry : expr_cache) for (auto &entry : expr_cache)
{ {
if (entry.expr_path == path) if (entry.expr_path == path)
{ {
entry.used_this_frame = true; entry.used_this_frame = true;
return entry.id; return entry.is_cstr ? entry.id2 : entry.id;
} }
} }
using namespace data::source; using namespace data::source;
auto id = this->id++; auto id = this->id++;
size_t cstr_id = -1;
this->backend->add_data_node( this->backend->add_data_node(
Node{.id = id, Node{.id = id,
.type = Node::Type::source, .type = Node::Type::source,
.data = Source{.type = Source::Type::variable, .data = Source{.type = Source::Type::variable,
.data = Source::Variable{.expr_path = path}}}); .data = Source::Variable{.expr_path = path}}});
expr_cache.push_back(ExprCacheEntry{ if (is_cstr)
.expr_path = std::move(path), .id = id, .used_this_frame = true}); {
cstr_id = this->id++;
this->backend->add_data_node(Node{.id = cstr_id,
.type = Node::Type::read_cstr,
.data = ReadAsCStr{.src_id = id}});
}
expr_cache.push_back(ExprCacheEntry{.expr_path = std::move(path),
.id = id,
.id2 = cstr_id,
.used_this_frame = true,
.is_cstr = is_cstr});
return id; return id;
} }

View File

@@ -1283,9 +1283,10 @@ void WatchWindow::draw_value(Frontend &frontend,
if (!is_editing) if (!is_editing)
{ {
tree_open = tree_open = ImGui::TreeNodeEx(
ImGui::TreeNodeEx(tree_id_buf, ImGuiTreeNodeFlags_SpanFullWidth, "%.*s", tree_id_buf,
static_cast<int>(name_end - name_begin), name_begin); ImGuiTreeNodeFlags_SpanFullWidth | ImGuiTreeNodeFlags_SpanAvailWidth,
"%.*s", static_cast<int>(name_end - name_begin), name_begin);
if (name.index() == 1 if (name.index() == 1
&& ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left) && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)
&& ImGui::IsItemHovered()) && ImGui::IsItemHovered())
@@ -1542,20 +1543,33 @@ void WatchWindow::draw_value(Frontend &frontend,
{ {
// TODO: make this func be able to not print the "outer" line // TODO: make this func be able to not print the "outer" line
// and just accept a bool to only draw the containing value // and just accept a bool to only draw the containing value
std::string path{"*"}; std::string path{};
if (type_id.sub_type != Type::i8)
{
// TODO: better check if this is really a string
path = "*";
}
// why cant i just path name_begin, name_end to string_view? :[ // why cant i just path name_begin, name_end to string_view? :[
construct_expr_path( construct_expr_path(
path, expr_path, path, expr_path,
std::string_view{name_begin, std::string_view{name_begin,
static_cast<size_t>(name_end - name_begin)}); static_cast<size_t>(name_end - name_begin)});
auto src_id = auto src_id = frontend.target->find_or_create_expr_path(
frontend.target->find_or_create_expr_path(std::move(path)); std::move(path), type_id.sub_type == Type::i8);
auto res_idx = frontend.target->data_idx_for_src_id(src_id); auto res_idx = frontend.target->data_idx_for_src_id(src_id);
if (res_idx) if (res_idx)
{ {
const auto &node = *frontend.target->data_res_nodes[*res_idx]; const auto &node = *frontend.target->data_res_nodes[*res_idx];
if (node.success && node.children.size() == 1) if (type_id.sub_type == Type::i8 && node.success)
{
// TODO: make span whole row (see https://github.com/ocornut/imgui/issues/3565)
assert(node.type_id.type == Type::custom);
assert(node.vec_data().back() == '\0');
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(1);
ImGui::TextWrapped("\"%s\"", node.vec_data().data());
} else if (node.success && node.children.size() == 1)
{ {
auto data_idx = node.children[0]; auto data_idx = node.children[0];
const auto &data_node = const auto &data_node =