This commit is contained in:
T0b1
2023-06-25 02:57:11 +02:00
parent 28dbf374e8
commit 10826ff2d5
9 changed files with 271 additions and 16 deletions

View File

@@ -2146,6 +2146,100 @@ std::optional<std::pair<uint16_t, size_t>>
return std::make_pair(cache_idx, node.id);
}
}
case read_cstr:
{
using namespace lldb;
uint16_t cache_idx = 0;
if (auto found_idx = find_node_for_src_id(node.id); found_idx)
{
cache_idx = *found_idx;
} else
{
cache_idx = get_free_res_slot();
}
size_t addr_id = std::get<data::source::ReadAsCStr>(node.data).src_id;
uint16_t addr_idx = *find_node_for_src_id(addr_id);
if (!_data_res[addr_idx] || !_data_res[addr_idx]->node.success)
{
return check_single_res_changed(data::result::Node{
.idx = cache_idx,
.type_id = data::type_info::TypeID::none(),
.success = false,
});
}
if (_data_res[addr_idx]->node.type_id.type != data::type_info::Type::ptr)
{
return check_single_res_changed(data::result::Node{
.idx = cache_idx,
.type_id = data::type_info::TypeID::none(),
.success = false,
});
}
auto addr = std::get<uint64_t>(_data_res[addr_idx]->node.data);
std::vector<uint8_t> buf{};
char tmp_buf[256];
auto success = true;
while (true)
{
auto lldb_addr = _target.ResolveLoadAddress(addr);
auto err = SBError{};
err.Clear();
auto bytes_read =
_target.ReadMemory(lldb_addr, tmp_buf, sizeof(tmp_buf), err);
if (bytes_read == 0)
{
success = false;
break;
}
auto null_pos = std::find(tmp_buf, tmp_buf + bytes_read, '\0');
if (null_pos != tmp_buf + bytes_read)
{
size_t len = null_pos - tmp_buf;
auto old_size = buf.size();
buf.resize(old_size + len + 1);
std::copy(tmp_buf, null_pos + 1, buf.data() + old_size);
break;
}
if (bytes_read != sizeof(tmp_buf))
{
if (err.Fail())
{
printf("ReadAsCStr failed: %s\n", err.GetCString());
success = false;
break;
}
}
auto old_size = buf.size();
buf.resize(old_size + bytes_read);
std::copy(tmp_buf, tmp_buf + bytes_read, buf.data() + old_size);
addr += bytes_read;
}
if (!success)
{
return check_single_res_changed(data::result::Node{
.idx = cache_idx,
.type_id = data::type_info::TypeID::none(),
.success = false,
});
}
// TODO: embed the array size into the TypeID and then make this
// an i8 array type?
return check_single_res_changed(
data::result::Node{.idx = cache_idx,
.type_id = data::type_info::TypeID::custom(),
.success = true,
.data = std::move(buf)});
}
}
printf("Unhandled data type\n");
@@ -3045,7 +3139,7 @@ dbgui::data::result::NodeIdx LLDBBackend::build_nodes_for_var_uncached(
// TODO: always get child info for first level
// TODO: depending on what is previewed?
res_node.success = true;
res_node.success = err.Success();
to_send.push_back(res_node);
_data_res[res_idx] =
CachedDataRes{.node = std::move(res_node),
@@ -3132,7 +3226,7 @@ void LLDBBackend::build_nodes_for_var_cached(
// TODO: always get child info for first level
// TODO: depending on what is previewed?
res_node.success = true;
res_node.success = err.Success();
if (!_data_res[cache_idx]->node.success
|| _data_res[cache_idx]->node.data != res_node.data)
{