make off and cur_field_off absolute in Sec_Hover_Fn
This commit is contained in:
parent
d3786e4c6d
commit
fe924743ef
1 changed files with 26 additions and 51 deletions
|
@ -129,24 +129,19 @@ enum Hover_Section_Flags {
|
||||||
|
|
||||||
// Functor used by get_section_hover_info to describe the structure of a section and print data about it.
|
// Functor used by get_section_hover_info to describe the structure of a section and print data about it.
|
||||||
struct Sec_Hover_Fn {
|
struct Sec_Hover_Fn {
|
||||||
u64 start; // the start of the section (including the pre_size, e.g. the TKey)
|
u64 off; // the offset relative to the start of `data`
|
||||||
u64 roff; // the offset relative to the section start
|
|
||||||
const u8 *data; // the entire file data
|
const u8 *data; // the entire file data
|
||||||
const Section §ion;
|
const Section §ion;
|
||||||
Arena *arena;
|
Arena *arena;
|
||||||
Sec_Hover_Info &info;
|
Sec_Hover_Info &info;
|
||||||
u64 &cur_field_off;
|
u64 &cur_field_off; // current field offset relative to the start of `data`
|
||||||
b8 display_grouped;
|
b8 display_grouped;
|
||||||
b8 ended = false;
|
|
||||||
u8 cur_section_nesting = 0;
|
u8 cur_section_nesting = 0;
|
||||||
u8 innermost_section_highlighted = 0;
|
u8 innermost_section_highlighted = 0;
|
||||||
|
|
||||||
template <typename F>
|
template <typename F>
|
||||||
void titled_section(const char *title, F &&sec_body_fn, u64 flags = 0)
|
void titled_section(const char *title, F &&sec_body_fn, u64 flags = 0)
|
||||||
{
|
{
|
||||||
// if (ended)
|
|
||||||
// return;
|
|
||||||
|
|
||||||
++cur_section_nesting;
|
++cur_section_nesting;
|
||||||
String8_Node *prev_desc = info.desc;
|
String8_Node *prev_desc = info.desc;
|
||||||
info.desc = push_str8_node_child(arena, prev_desc, title);
|
info.desc = push_str8_node_child(arena, prev_desc, title);
|
||||||
|
@ -156,15 +151,14 @@ struct Sec_Hover_Fn {
|
||||||
sec_body_fn();
|
sec_body_fn();
|
||||||
|
|
||||||
assert(cur_field_off >= sec_start);
|
assert(cur_field_off >= sec_start);
|
||||||
b8 hovered = roff >= sec_start && roff <= cur_field_off;
|
b8 hovered = off >= sec_start && off <= cur_field_off;
|
||||||
|
|
||||||
if (!hovered & (flags & HoverSec_HideIfNotHovered)) {
|
if (!hovered & (flags & HoverSec_HideIfNotHovered)) {
|
||||||
pop_str8_node_child(prev_desc, info.desc);
|
pop_str8_node_child(prev_desc, info.desc);
|
||||||
} else if (display_grouped) {
|
} else if (display_grouped) {
|
||||||
// if we're in display_grouped mode, we want to highlight the entire range of the section;
|
// if we're in display_grouped mode, we want to highlight the entire range of the section;
|
||||||
u64 sec_len = cur_field_off - sec_start;
|
u64 sec_len = cur_field_off - sec_start;
|
||||||
info.rng = { start + sec_start, sec_len };
|
info.rng = { sec_start, sec_len };
|
||||||
// ended = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!info.highlighted_desc) {
|
if (!info.highlighted_desc) {
|
||||||
|
@ -187,14 +181,12 @@ struct Sec_Hover_Fn {
|
||||||
b8 field(const char *desc_fmt, Display_Fn<T> display_val, T *val_read = nullptr)
|
b8 field(const char *desc_fmt, Display_Fn<T> display_val, T *val_read = nullptr)
|
||||||
{
|
{
|
||||||
static_assert(!std::is_same_v<T, String8>, "use field_str8 instead.");
|
static_assert(!std::is_same_v<T, String8>, "use field_str8 instead.");
|
||||||
// if (ended)
|
|
||||||
// return false;
|
|
||||||
|
|
||||||
u64 field_len = sizeof(T);
|
u64 field_len = sizeof(T);
|
||||||
b8 hovered = cur_field_off <= roff && roff < cur_field_off + field_len;
|
b8 hovered = cur_field_off <= off && off < cur_field_off + field_len;
|
||||||
|
|
||||||
T val;
|
T val;
|
||||||
memcpy(&val, (u8 *)data + start + cur_field_off, field_len);
|
memcpy(&val, (u8 *)data + cur_field_off, field_len);
|
||||||
String8_Node *desc = display_val(arena, info.desc, desc_fmt, val);
|
String8_Node *desc = display_val(arena, info.desc, desc_fmt, val);
|
||||||
if (hovered && !display_grouped)
|
if (hovered && !display_grouped)
|
||||||
info.highlighted_desc = desc;
|
info.highlighted_desc = desc;
|
||||||
|
@ -202,9 +194,7 @@ struct Sec_Hover_Fn {
|
||||||
*val_read = val;
|
*val_read = val;
|
||||||
|
|
||||||
if (display_grouped || hovered) {
|
if (display_grouped || hovered) {
|
||||||
info.rng = { start + cur_field_off, field_len };
|
info.rng = { cur_field_off, field_len };
|
||||||
// truncate the hovered section here if we're not in display_grouped mode.
|
|
||||||
// ended = !display_grouped;
|
|
||||||
}
|
}
|
||||||
cur_field_off += field_len;
|
cur_field_off += field_len;
|
||||||
return true;
|
return true;
|
||||||
|
@ -213,23 +203,19 @@ struct Sec_Hover_Fn {
|
||||||
template <typename TStrSize>
|
template <typename TStrSize>
|
||||||
void field_str8(const char *desc_fmt, Display_Fn<String8> display_val = hover_display_val_str8)
|
void field_str8(const char *desc_fmt, Display_Fn<String8> display_val = hover_display_val_str8)
|
||||||
{
|
{
|
||||||
// if (ended)
|
|
||||||
// return;
|
|
||||||
|
|
||||||
// String size can be stored as different types, like u8 (by ROOT I/O) or u32 (by RNTuple).
|
// String size can be stored as different types, like u8 (by ROOT I/O) or u32 (by RNTuple).
|
||||||
TStrSize str_size;
|
TStrSize str_size;
|
||||||
memcpy(&str_size, data + start + cur_field_off, sizeof(TStrSize));
|
memcpy(&str_size, data + cur_field_off, sizeof(TStrSize));
|
||||||
// DEBUG
|
// DEBUG
|
||||||
if (str_size > 1000) {
|
if (str_size > 1000) {
|
||||||
printf("read str_size = %u at offset 0x%lX!\n", str_size, start + cur_field_off);
|
printf("read str_size = %u at offset 0x%lX!\n", str_size, cur_field_off);
|
||||||
// ended = true;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
u64 field_len = sizeof(TStrSize) + (u64)str_size;
|
u64 field_len = sizeof(TStrSize) + (u64)str_size;
|
||||||
b8 hovered = cur_field_off <= roff && roff < cur_field_off + field_len;
|
b8 hovered = cur_field_off <= off && off < cur_field_off + field_len;
|
||||||
|
|
||||||
u8 *buf = arena_push_array_nozero<u8>(arena, str_size + 1);
|
u8 *buf = arena_push_array_nozero<u8>(arena, str_size + 1);
|
||||||
memcpy(buf, data + start + cur_field_off + sizeof(TStrSize), str_size);
|
memcpy(buf, data + cur_field_off + sizeof(TStrSize), str_size);
|
||||||
buf[str_size] = 0;
|
buf[str_size] = 0;
|
||||||
String8 s = { buf, str_size };
|
String8 s = { buf, str_size };
|
||||||
String8_Node *desc = display_val(arena, info.desc, desc_fmt, s);
|
String8_Node *desc = display_val(arena, info.desc, desc_fmt, s);
|
||||||
|
@ -237,8 +223,7 @@ struct Sec_Hover_Fn {
|
||||||
info.highlighted_desc = desc;
|
info.highlighted_desc = desc;
|
||||||
|
|
||||||
if (display_grouped || hovered) {
|
if (display_grouped || hovered) {
|
||||||
info.rng = { start + cur_field_off, field_len };
|
info.rng = { cur_field_off, field_len };
|
||||||
// ended = !display_grouped;
|
|
||||||
}
|
}
|
||||||
cur_field_off += field_len;
|
cur_field_off += field_len;
|
||||||
}
|
}
|
||||||
|
@ -258,17 +243,13 @@ struct Sec_Hover_Fn {
|
||||||
// An unspecified range of bytes
|
// An unspecified range of bytes
|
||||||
void range(const char *desc, u64 range_len, Display_Range_Fn display_val = hover_display_generic_range)
|
void range(const char *desc, u64 range_len, Display_Range_Fn display_val = hover_display_generic_range)
|
||||||
{
|
{
|
||||||
// if (ended)
|
b8 hovered = cur_field_off <= off && off < cur_field_off + range_len;
|
||||||
// return;
|
String8_Node *dsc = display_val(arena, info.desc, desc, data + cur_field_off, range_len);
|
||||||
|
|
||||||
b8 hovered = cur_field_off <= roff && roff < cur_field_off + range_len;
|
|
||||||
String8_Node *dsc = display_val(arena, info.desc, desc, data + start + cur_field_off, range_len);
|
|
||||||
if (hovered && !display_grouped)
|
if (hovered && !display_grouped)
|
||||||
info.highlighted_desc = dsc;
|
info.highlighted_desc = dsc;
|
||||||
|
|
||||||
if (display_grouped || hovered) {
|
if (display_grouped || hovered) {
|
||||||
info.rng = { start + cur_field_off, range_len };
|
info.rng = { cur_field_off, range_len };
|
||||||
// ended = !display_grouped;
|
|
||||||
}
|
}
|
||||||
cur_field_off += range_len;
|
cur_field_off += range_len;
|
||||||
}
|
}
|
||||||
|
@ -276,20 +257,16 @@ struct Sec_Hover_Fn {
|
||||||
// Returns true if `was_zipped` was read.
|
// Returns true if `was_zipped` was read.
|
||||||
b8 maybe_rootzip(b8 *was_zipped = nullptr)
|
b8 maybe_rootzip(b8 *was_zipped = nullptr)
|
||||||
{
|
{
|
||||||
// if (ended)
|
|
||||||
// return false;
|
|
||||||
|
|
||||||
// TODO boundary checks
|
// TODO boundary checks
|
||||||
const u64 range_len = 9;
|
const u64 range_len = 9;
|
||||||
b8 hovered = cur_field_off <= roff && roff < cur_field_off + range_len;
|
b8 hovered = cur_field_off <= off && off < cur_field_off + range_len;
|
||||||
if (display_val_rootzip(arena, info.desc, "Zipped Block", data + start + cur_field_off)) {
|
if (display_val_rootzip(arena, info.desc, "Zipped Block", data + cur_field_off)) {
|
||||||
if (display_grouped || hovered) {
|
if (display_grouped || hovered) {
|
||||||
if (was_zipped)
|
if (was_zipped)
|
||||||
*was_zipped = true;
|
*was_zipped = true;
|
||||||
info.rng = { start + cur_field_off, range_len };
|
info.rng = { cur_field_off, range_len };
|
||||||
if (hovered)
|
if (hovered)
|
||||||
info.highlighted_desc = info.desc;
|
info.highlighted_desc = info.desc;
|
||||||
// ended = !display_grouped;
|
|
||||||
}
|
}
|
||||||
cur_field_off += range_len;
|
cur_field_off += range_len;
|
||||||
} else if (was_zipped) {
|
} else if (was_zipped) {
|
||||||
|
@ -303,7 +280,7 @@ struct Sec_Hover_Fn {
|
||||||
{
|
{
|
||||||
titled_section(title, [this] {
|
titled_section(title, [this] {
|
||||||
u16 version_be;
|
u16 version_be;
|
||||||
memcpy(&version_be, data + start + 4, sizeof(u16));
|
memcpy(&version_be, data + cur_field_off + 4, sizeof(u16));
|
||||||
u32 version = bswap(version_be);
|
u32 version = bswap(version_be);
|
||||||
b8 is_big = version > 1000;
|
b8 is_big = version > 1000;
|
||||||
|
|
||||||
|
@ -358,12 +335,12 @@ struct Sec_Hover_Fn {
|
||||||
Frame_Type frame_type = Frame_INVALID;
|
Frame_Type frame_type = Frame_INVALID;
|
||||||
titled_section(titlestr.c(), [this, &frame_type, &frame_size = size, n_items] {
|
titled_section(titlestr.c(), [this, &frame_type, &frame_size = size, n_items] {
|
||||||
i64 size;
|
i64 size;
|
||||||
memcpy(&size, data + start + cur_field_off, sizeof(size));
|
memcpy(&size, data + cur_field_off, sizeof(size));
|
||||||
// Sanity check
|
// Sanity check
|
||||||
if (size > 1000000) {
|
if (size > 1000000) {
|
||||||
fprintf(stderr, "Frame size read at 0x%" PRIX64 " looks bogus"
|
fprintf(stderr, "Frame size read at 0x%" PRIX64 " looks bogus"
|
||||||
" (is it really %s? Don't think so...); setting it to 0 for good measure.\n",
|
" (is it really %s? Don't think so...); setting it to 0 for good measure.\n",
|
||||||
start + cur_field_off, to_pretty_size(arena, size).c());
|
cur_field_off, to_pretty_size(arena, size).c());
|
||||||
frame_size = 0;
|
frame_size = 0;
|
||||||
frame_type = Frame_INVALID;
|
frame_type = Frame_INVALID;
|
||||||
return;
|
return;
|
||||||
|
@ -380,7 +357,7 @@ struct Sec_Hover_Fn {
|
||||||
frame_type = Frame_INVALID;
|
frame_type = Frame_INVALID;
|
||||||
} else {
|
} else {
|
||||||
frame_type = Frame_List;
|
frame_type = Frame_List;
|
||||||
memcpy(n_items, data + start + cur_field_off + sizeof(i64), sizeof(u32));
|
memcpy(n_items, data + cur_field_off + sizeof(i64), sizeof(u32));
|
||||||
field<i64>("List frame size: %" PRIi64 " B", hover_display_val_le_abs<i64>);
|
field<i64>("List frame size: %" PRIi64 " B", hover_display_val_le_abs<i64>);
|
||||||
field_le<u32>("List frame n.items: %u");
|
field_le<u32>("List frame n.items: %u");
|
||||||
}
|
}
|
||||||
|
@ -648,7 +625,7 @@ struct Sec_Hover_Fn {
|
||||||
{
|
{
|
||||||
titled_section("TFile Header", [this] {
|
titled_section("TFile Header", [this] {
|
||||||
u32 root_version_be;
|
u32 root_version_be;
|
||||||
memcpy(&root_version_be, data + start + 4, sizeof(u32));
|
memcpy(&root_version_be, data + cur_field_off + 4, sizeof(u32));
|
||||||
u32 root_version = bswap(root_version_be);
|
u32 root_version = bswap(root_version_be);
|
||||||
b8 is_big = root_version > 1000'000;
|
b8 is_big = root_version > 1000'000;
|
||||||
|
|
||||||
|
@ -744,7 +721,7 @@ struct Sec_Hover_Fn {
|
||||||
titled_section("TFile FreeList", [this] {
|
titled_section("TFile FreeList", [this] {
|
||||||
tkey();
|
tkey();
|
||||||
u16 version_be;
|
u16 version_be;
|
||||||
memcpy(&version_be, data + start + cur_field_off, sizeof(u16));
|
memcpy(&version_be, data + cur_field_off, sizeof(u16));
|
||||||
u32 version = bswap(version_be);
|
u32 version = bswap(version_be);
|
||||||
b8 is_big = version > 1000;
|
b8 is_big = version > 1000;
|
||||||
|
|
||||||
|
@ -920,10 +897,8 @@ Sec_Hover_Info get_section_hover_info(Arena *arena, Section section, u64 off, co
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 start = section.range.start - section.pre_size;
|
u64 cur_field_off = section.range.start - section.pre_size;
|
||||||
u64 roff = off - start; // offset relative to `section`
|
Sec_Hover_Fn hover { off, data, section, arena, info, cur_field_off, display_grouped };
|
||||||
u64 cur_field_off = 0;
|
|
||||||
Sec_Hover_Fn hover { start, roff, data, section, arena, info, cur_field_off, display_grouped };
|
|
||||||
|
|
||||||
switch (section.id) {
|
switch (section.id) {
|
||||||
case Sec_RNTuple_Anchor:
|
case Sec_RNTuple_Anchor:
|
||||||
|
|
Loading…
Reference in a new issue