Skip to content

Commit

Permalink
pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
hugsy committed Jan 19, 2024
1 parent 6759be8 commit 1a9a035
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
21 changes: 12 additions & 9 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -10533,7 +10533,17 @@ def parse_gdb_info_proc_maps() -> Generator[Section, None, None]:

lines = (gdb.execute("info proc mappings", to_string=True) or "").splitlines()

# See expected format in tests/api/gef_memory.py:test_api_gef_memory_parse_info_proc_maps*
# The function assumes the following output format (as of GDB 11+) for `info proc mappings`
# ```
# process 61789
# Mapped address spaces:
#
# Start Addr End Addr Size Offset Perms objfile
# 0x555555554000 0x555555558000 0x4000 0x0 r--p /usr/bin/ls
# 0x555555558000 0x55555556c000 0x14000 0x4000 r-xp /usr/bin/ls
# [...]
# ```

if len(lines) < 5:
raise AttributeError

Expand All @@ -10543,7 +10553,7 @@ def parse_gdb_info_proc_maps() -> Generator[Section, None, None]:
break

parts = [x.strip() for x in line.split()]
addr_start, addr_end, offset, _ = list(map(lambda x: int(x, 16), parts[0:4]))
addr_start, addr_end, offset = [int(x, 16) for x in parts[0:3]]
perm = Permission.from_process_maps(parts[4])
path = " ".join(parts[5:]) if len(parts) >= 5 else ""
yield Section(
Expand Down Expand Up @@ -11158,13 +11168,6 @@ def __setup_remote(self) -> bool:
err(f"'{fpath}' could not be fetched on the remote system.")
return False

# makeup a fake mem mapping in case we failed to retrieve it
# maps = self.root / f"proc/{self.pid}/maps"
# if not maps.exists():
# with maps.open("w") as fd:
# fname = self.file.absolute()
# mem_range = "00000000-ffffffff" if is_32bit() else "0000000000000000-ffffffffffffffff"
# fd.write(f"{mem_range} rwxp 00000000 00:00 0 {fname}\n")
return True

def remote_objfile_event_handler(self, evt: "gdb.NewObjFileEvent") -> None:
Expand Down
15 changes: 1 addition & 14 deletions tests/api/gef_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,6 @@ def test_api_gef_memory_parse_info_proc_maps_expected_format(self):
gdb, root = self._gdb, self._conn.root
gdb.execute("start")

#
# The function assumes the following output format (as of GDB 10+) for `info proc mappings`
# """"
# process 61789
# Mapped address spaces:
#
# Start Addr End Addr Size Offset Perms objfile
# 0x555555554000 0x555555558000 0x4000 0x0 r--p /usr/bin/ls
# 0x555555558000 0x55555556c000 0x14000 0x4000 r-xp /usr/bin/ls
# [...]
# """
#

# Check output format
lines = (gdb.execute("info proc mappings", to_string=True) or "").splitlines()
assert len(lines) >= 5
Expand Down Expand Up @@ -122,7 +109,7 @@ def test_func_parse_maps_local_procfs(self):
# up, and we should be able to view the maps via the `gef.memory.maps`
# property. So check the alias `gef.memory.maps`
# However, since `gef.memory.maps` has more info, use it as source of
# trust
# truth
#
assert section in gef.memory.maps

Expand Down

0 comments on commit 1a9a035

Please sign in to comment.