add decimal printing of addresses
This commit is contained in:
parent
9c3a8a1474
commit
7d04a0b1ad
3 changed files with 33 additions and 6 deletions
|
@ -6,6 +6,7 @@ void print_help(const char *argv0)
|
|||
"\n"
|
||||
"\nUsage: %s [-ehknRtv] [-s START] [-l LEN] [-w WIDTH] <ntuple_file.root> [ntuple_name[;cycle]]"
|
||||
"\n\t-R: disable highlighting of non-RNTuple ROOT objects"
|
||||
"\n\t-d: display addresses in decimal rather than hexadecimal"
|
||||
"\n\t-e: display some extended info(*) (may slow down the startup)"
|
||||
"\n\t-h: display this help and exit"
|
||||
"\n\t-l: display LEN bytes (only in terminal mode)"
|
||||
|
@ -66,6 +67,11 @@ void print_version_and_copyright()
|
|||
);
|
||||
}
|
||||
|
||||
enum Print_Fmt {
|
||||
PrintFmt_Hexadecimal,
|
||||
PrintFmt_Decimal,
|
||||
};
|
||||
|
||||
struct Cmdline_Args {
|
||||
b8 print_to_terminal;
|
||||
b8 show_help_and_exit;
|
||||
|
@ -76,6 +82,7 @@ struct Cmdline_Args {
|
|||
b8 extended_info;
|
||||
b8 only_print_rntuple_names;
|
||||
b8 print_keys_info;
|
||||
Print_Fmt print_addr_fmt;
|
||||
b8 dont_collect_other_root_objs;
|
||||
|
||||
String8 ntpl_name;
|
||||
|
@ -157,6 +164,8 @@ Cmdline_Args parse_args(i32 argc, char **argv)
|
|||
if (arg.size == 2) {
|
||||
if (arg[1] == 't')
|
||||
args.print_to_terminal = true;
|
||||
else if (arg[1] == 'd')
|
||||
args.print_addr_fmt = PrintFmt_Decimal;
|
||||
else if (arg[1] == 'e')
|
||||
args.extended_info = true;
|
||||
else if (arg[1] == 's')
|
||||
|
|
|
@ -162,6 +162,8 @@ int main(int argc, char **argv)
|
|||
u32 walk_tkeys_flags = WTK_NONE;
|
||||
if (args.print_keys_info)
|
||||
walk_tkeys_flags |= WTK_PRINT_KEYS_INFO;
|
||||
if (args.print_addr_fmt)
|
||||
walk_tkeys_flags |= WTK_PRINT_DECIMAL;
|
||||
if (!args.dont_collect_other_root_objs)
|
||||
walk_tkeys_flags |= WTK_COLLECT_OTHER_ROOT_OBJS;
|
||||
app.walk_tkeys_flags = walk_tkeys_flags;
|
||||
|
@ -172,7 +174,10 @@ int main(int argc, char **argv)
|
|||
if (args.only_print_rntuple_names) {
|
||||
for (Section *sec = app.fdata.tfile_data.sections[Sec_RNTuple_Anchor].head; sec; sec = sec->next) {
|
||||
const RNTuple_Anchor_Info *info = (const RNTuple_Anchor_Info *)sec->info;
|
||||
printf("%s at 0x%" PRIX64 "\n", info->name.c(), info->offset_in_file);
|
||||
if (args.print_addr_fmt == PrintFmt_Decimal)
|
||||
printf("%s at %" PRIu64 "\n", info->name.c(), info->offset_in_file);
|
||||
else
|
||||
printf("%s at 0x%" PRIX64 "\n", info->name.c(), info->offset_in_file);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -74,6 +74,7 @@ enum {
|
|||
WTK_NONE = 0,
|
||||
WTK_PRINT_KEYS_INFO = 1,
|
||||
WTK_COLLECT_OTHER_ROOT_OBJS = 2,
|
||||
WTK_PRINT_DECIMAL = 4,
|
||||
};
|
||||
|
||||
// Examines the innards of a TFile to get byte range info about the TKeys.
|
||||
|
@ -214,13 +215,19 @@ b8 walk_tkeys(Arena *arena, const u8 *data, u64 data_len, u32 flags, TFile_Data
|
|||
n_bytes = abs(n_bytes);
|
||||
|
||||
if (!n_bytes) {
|
||||
fprintf(stderr, "Error: found key or obj with len 0 at 0x%" PRIX64 ". Bailing out...\n", cur);
|
||||
if (flags & WTK_PRINT_DECIMAL)
|
||||
fprintf(stderr, "Error: found key with size 0 at %" PRIu64 ". Bailing out...\n", cur);
|
||||
else
|
||||
fprintf(stderr, "Error: found key with size 0 at 0x%" PRIX64 ". Bailing out...\n", cur);
|
||||
break;
|
||||
}
|
||||
|
||||
if (is_free_slot) {
|
||||
if (flags & WTK_PRINT_KEYS_INFO) {
|
||||
printf("Free Slot at 0x%lX, len: %d (%s)\n", cur, n_bytes, to_pretty_size(scratch.arena, n_bytes).c());
|
||||
if (flags & WTK_PRINT_DECIMAL)
|
||||
printf("Free Slot at %" PRIu64 ", len: %d (%s)\n", cur, n_bytes, to_pretty_size(scratch.arena, n_bytes).c());
|
||||
else
|
||||
printf("Free Slot at 0x%" PRIX64 ", len: %d (%s)\n", cur, n_bytes, to_pretty_size(scratch.arena, n_bytes).c());
|
||||
}
|
||||
// don't try to read the rest of the data
|
||||
cur += n_bytes;
|
||||
|
@ -230,8 +237,11 @@ b8 walk_tkeys(Arena *arena, const u8 *data, u64 data_len, u32 flags, TFile_Data
|
|||
u16 key_version = read_be<u16>(data + cur + key_version_off);
|
||||
u32 objlen = read_be<u32>(data + cur + objlen_off);
|
||||
u16 keylen = read_be<u16>(data + cur + keylen_off);
|
||||
if (!keylen) {
|
||||
fprintf(stderr, "Error: found key or obj with len 0 at 0x%" PRIX64 ". Bailing out...\n", cur);
|
||||
if (!keylen || !objlen) {
|
||||
if (flags & WTK_PRINT_DECIMAL)
|
||||
fprintf(stderr, "Error: found key or obj with keylen 0 at %" PRIu64 ". Bailing out...\n", cur);
|
||||
else
|
||||
fprintf(stderr, "Error: found key or obj with keylen 0 at 0x%" PRIX64 ". Bailing out...\n", cur);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -242,7 +252,10 @@ b8 walk_tkeys(Arena *arena, const u8 *data, u64 data_len, u32 flags, TFile_Data
|
|||
char cname[256];
|
||||
cname[cname_len] = 0;
|
||||
memcpy(cname, data + cname_off + 1, cname_len);
|
||||
printf("TKey '%s' at 0x%lX, len: %d (%s)\n", cname, cur, n_bytes, to_pretty_size(scratch.arena, n_bytes).c());
|
||||
if (flags & WTK_PRINT_DECIMAL)
|
||||
printf("TKey '%s' at %" PRIu64 ", len: %d (%s)\n", cname, cur, n_bytes, to_pretty_size(scratch.arena, n_bytes).c());
|
||||
else
|
||||
printf("TKey '%s' at 0x%" PRIX64 ", len: %d (%s)\n", cname, cur, n_bytes, to_pretty_size(scratch.arena, n_bytes).c());
|
||||
++n_keys;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue