Skip to content

Commit

Permalink
Add test for _search_for_realpath.
Browse files Browse the repository at this point in the history
  • Loading branch information
gordonmessmer committed Jun 15, 2024
1 parent 5fd1ab7 commit ee8b8ba
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/api/gef_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,33 @@ def test_func_parse_maps_remote_qemu(self):
gdb.execute(cmd)
sections = gef.memory.maps
assert len(sections) > 0

def test_func_parse_maps_realpath(self):
gef, gdb = self._gef, self._gdb
# When in a gef-remote session `parse_gdb_info_proc_maps` should work to
# query the memory maps
while True:
port = random.randint(1025, 65535)
if port != self._port:
break

with gdbserver_session(port=port) as _:
gdb.execute(f"gef-remote {GDBSERVER_DEFAULT_HOST} {port}")
gdb.execute("b main")
gdb.execute("continue")
sections = gef.memory.maps
assert len(sections) > 0
#
# Iterate over each of the maps, checking each path. If the path from
# the /proc/pid/maps file indicates a path that starts with /usr, but
# realpath does not include "/usr", then _search_for_realpath has
# probably corrected the path to account for gdb bug #23764
#
found_lib_in_usr = False
for section in sections:
if(section.is_executable() and section.path.startswith("/usr") and
"/usr" not in section.realpath):
found_lib_in_usr = True
assert pathlib.Path(section.realpath).is_file() is True
break
assert found_lib_in_usr is True

0 comments on commit ee8b8ba

Please sign in to comment.