diff options
| author | ruki <[email protected]> | 2025-12-09 00:32:47 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-12-09 00:32:47 +0800 |
| commit | acd4bfbcf3b73349f6b56197f3c0f27f204cc135 (patch) | |
| tree | 9ffcdd48359e77a4dc6f62938b0e8f164c1af3e9 /xmake/modules/utils/binary | |
| parent | 7b24dfe374f14c8682d8ea2b66d8892b104c7a12 (diff) | |
improve dump
Diffstat (limited to 'xmake/modules/utils/binary')
| -rw-r--r-- | xmake/modules/utils/binary/readsyms.lua | 68 |
1 files changed, 52 insertions, 16 deletions
diff --git a/xmake/modules/utils/binary/readsyms.lua b/xmake/modules/utils/binary/readsyms.lua index 212c99401..899b43f71 100644 --- a/xmake/modules/utils/binary/readsyms.lua +++ b/xmake/modules/utils/binary/readsyms.lua @@ -40,30 +40,66 @@ end function dump(binaryfile) local symbols = _get_symbols(binaryfile) if symbols and #symbols > 0 then - print("") - print("Symbols:") + -- calculate column widths for alignment + local max_value_len = 0 + local max_name_len = 0 + local max_type_len = 0 + local max_bind_len = 0 + local max_section_len = 0 + local max_size_len = 0 + for i, sym in ipairs(symbols) do - local value_str = "" if sym.value then - value_str = string.format("0x%x", sym.value) - end - local size_str = "" - if sym.size then - size_str = string.format(" size=%d", sym.size) + local value_str = string.format("0x%x", sym.value) + max_value_len = math.max(max_value_len, #value_str) end - local section_str = "" - if sym.section and sym.section > 0 then - section_str = string.format(" section=%d", sym.section) + if sym.name then + max_name_len = math.max(max_name_len, #sym.name) end - local type_str = "" if sym.type then - type_str = string.format(" type=%s", sym.type) + max_type_len = math.max(max_type_len, #sym.type) end - local bind_str = "" if sym.bind then - bind_str = string.format(" bind=%s", sym.bind) + max_bind_len = math.max(max_bind_len, #sym.bind) + end + if sym.section then + local section_str = tostring(sym.section) + max_section_len = math.max(max_section_len, #section_str) + end + if sym.size then + local size_str = tostring(sym.size) + max_size_len = math.max(max_size_len, #size_str) end - print(string.format(" %s %s%s%s%s%s", sym.name or "", value_str, size_str, section_str, type_str, bind_str)) + end + + -- calculate column widths + local value_width = math.max(max_value_len, 10) + local type_width = math.max(max_type_len, 4) + local bind_width = math.max(max_bind_len, 4) + local section_width = math.max(max_section_len, 7) + local size_width = math.max(max_size_len, 4) + + -- print header + print("") + print("Symbols:") + local header_format = string.format(" %%-%ds %%-%ds %%-%ds %%-%ds %%-%ds %%s", + value_width, type_width, bind_width, section_width, size_width) + print(string.format(header_format, "VALUE", "TYPE", "BIND", "SECTION", "SIZE", "NAME")) + print(string.rep("-", 80)) + + -- print symbols + local format_str = string.format(" %%-%ds %%-%ds %%-%ds %%-%ds %%-%ds %%s", + value_width, type_width, bind_width, section_width, size_width) + + for i, sym in ipairs(symbols) do + local value_str = sym.value and string.format("0x%x", sym.value) or "" + local type_str = sym.type or "" + local bind_str = sym.bind or "" + local section_str = sym.section and sym.section > 0 and tostring(sym.section) or "" + local size_str = sym.size and tostring(sym.size) or "" + local name_str = sym.name or "" + + print(string.format(format_str, value_str, type_str, bind_str, section_str, size_str, name_str)) end print("") cprint("${bright}%d symbols found!", #symbols) |
