Add a header to the vmmap table (#1311)

* Add a header to the vmmap table

A simple header has been added to the output of vmmap which helps new users identify the columns.

* fix: lint

* fix: failing test

Adjust the length of expected vmmaps

* fix: tests again
This commit is contained in:
alufers 2022-10-21 02:58:21 +02:00 committed by GitHub
parent c74a551a6d
commit e8a8e737c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 5 deletions

View File

@ -30,6 +30,15 @@ def pages_filter(gdbval_or_str):
raise argparse.ArgumentTypeError("Unknown vmmap argument type.")
def print_vmmap_table_header():
"""
Prints the table header for the vmmap command.
"""
width = 2 + 2 * pwndbg.gdblib.arch.ptrsize
fmt_string = "%#{}s %#{}s %#4s %#8s %#6s %s".format(width, width)
print(fmt_string % ("Start", "End", "Perm", "Size", "Offset", "File"))
parser = argparse.ArgumentParser()
parser.description = """Print virtual memory map pages. Results can be filtered by providing address/module name.
@ -72,7 +81,7 @@ def vmmap(gdbval_or_str=None, writable=False, executable=False):
return
print(M.legend())
print_vmmap_table_header()
if len(pages) == 1 and isinstance(gdbval_or_str, integer_types):
page = pages[0]
print(M.get(page.vaddr, text=str(page) + " +0x%x" % (int(gdbval_or_str) - page.vaddr)))

View File

@ -69,11 +69,11 @@ def test_command_vmmap_on_coredump_on_crash_simple_binary(start_binary):
vmmaps = gdb.execute("vmmap", to_string=True).splitlines()
# Basic asserts
assert len(vmmaps) == len(expected_maps) + 1
assert len(vmmaps) == len(expected_maps) + 2 # +2 for header and legend
assert vmmaps[0] == "LEGEND: STACK | HEAP | CODE | DATA | RWX | RODATA"
# Split vmmaps
vmmaps = [i.split() for i in vmmaps[1:]]
vmmaps = [i.split() for i in vmmaps[2:]]
# Assert that vmmap output matches expected one
assert vmmaps == expected_maps
@ -91,7 +91,7 @@ def test_command_vmmap_on_coredump_on_crash_simple_binary(start_binary):
# Note: we will now see one less vmmap page as [vvar] will be missing
assert vmmaps[0] == "LEGEND: STACK | HEAP | CODE | DATA | RWX | RODATA"
vmmaps = [i.split() for i in vmmaps[1:]]
vmmaps = [i.split() for i in vmmaps[2:]]
assert len(vmmaps) == old_len_vmmaps - 1
# Fix up expected maps
@ -134,6 +134,6 @@ def test_command_vmmap_on_coredump_on_crash_simple_binary(start_binary):
gdb.execute("file")
vmmaps = gdb.execute("vmmap", to_string=True).splitlines()
vmmaps = [i.split() for i in vmmaps[1:]]
vmmaps = [i.split() for i in vmmaps[2:]]
assert_maps()