vmmap: Prefer shortest paths in relpath config (#2835)

* vmmap: Prefer shortest paths in relpath config

* Update pwndbg/lib/memory.py

* Fix wrong hint on vmmap

---------

Co-authored-by: Disconnect3d <dominik.b.czarnota@gmail.com>
pull/2838/head
tesuji 8 months ago committed by GitHub
parent 107a8f1bac
commit 8ffba2ebce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -50,7 +50,7 @@ def print_vmmap_table_header() -> None:
width = 2 + 2 * pwndbg.aglib.arch.ptrsize
print(
f"{'Start':>{width}} {'End':>{width}} {'Perm'} {'Size':>8} {'Offset':>6} "
f"{'File'} (set vmmap_prefer_relpaths {prefer_relpaths})"
f"{'File'} (set vmmap-prefer-relpaths {prefer_relpaths})"
)

@ -143,9 +143,8 @@ class Page:
def __str__(self) -> str:
if pwndbg.config.vmmap_prefer_relpaths:
rel = relpath(self.objfile)
# Prefer absolute paths for system files (for example libc) since
# `os.path.relpath` returns longer relative paths with no clear benefits.
objfile = self.objfile if rel.startswith("../../") else rel
# Keep the origin path when relative paths are longer than absolute ones.
objfile = self.objfile if len(rel) > len(self.objfile) else rel
else:
objfile = self.objfile
width = 2 + 2 * pwndbg.aglib.arch.ptrsize

Loading…
Cancel
Save