Skip to content

Commit 79447be

Browse files
committed
fixed gef-remote from tests, using only target remote
1 parent 771a598 commit 79447be

File tree

3 files changed

+17
-32
lines changed

3 files changed

+17
-32
lines changed

tests/api/gef_memory.py

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
ARCH,
1313
debug_target,
1414
gdbserver_session,
15+
get_random_port,
1516
qemuuser_session,
1617
GDBSERVER_DEFAULT_HOST,
1718
)
@@ -121,48 +122,35 @@ def test_func_parse_maps_local_procfs(self):
121122
@pytest.mark.slow
122123
def test_func_parse_maps_remote_gdbserver(self):
123124
gef, gdb = self._gef, self._gdb
124-
# When in a gef-remote session `parse_gdb_info_proc_maps` should work to
125+
# When in a remote session `parse_gdb_info_proc_maps` should work to
125126
# query the memory maps
126-
while True:
127-
port = random.randint(1025, 65535)
128-
if port != self._port:
129-
break
127+
port = get_random_port()
130128

131129
with pytest.raises(Exception):
132-
gdb.execute(f"gef-remote {GDBSERVER_DEFAULT_HOST} {port}")
130+
gdb.execute(f"target remote :{port}")
133131

134132
with gdbserver_session(port=port) as _:
135-
gdb.execute(f"gef-remote {GDBSERVER_DEFAULT_HOST} {port}")
133+
gdb.execute(f"target remote :{port}")
136134
sections = gef.memory.maps
137135
assert len(sections) > 0
138136

139137
@pytest.mark.skipif(ARCH not in ("x86_64",), reason=f"Skipped for {ARCH}")
140138
def test_func_parse_maps_remote_qemu(self):
141139
gdb, gef = self._gdb, self._gef
142-
# When in a gef-remote qemu-user session `parse_gdb_info_proc_maps`
143-
# should work to query the memory maps
144-
while True:
145-
port = random.randint(1025, 65535)
146-
if port != self._port:
147-
break
140+
port = get_random_port()
148141

149142
with qemuuser_session(port=port) as _:
150-
cmd = f"gef-remote --qemu-user --qemu-binary {self._target} {GDBSERVER_DEFAULT_HOST} {port}"
143+
cmd = f"target remote :{port}"
151144
gdb.execute(cmd)
152145
sections = gef.memory.maps
153146
assert len(sections) > 0
154147

155148
def test_func_parse_maps_realpath(self):
156149
gef, gdb = self._gef, self._gdb
157-
# When in a gef-remote session `parse_gdb_info_proc_maps` should work to
158-
# query the memory maps
159-
while True:
160-
port = random.randint(1025, 65535)
161-
if port != self._port:
162-
break
150+
port = get_random_port()
163151

164152
with gdbserver_session(port=port) as _:
165-
gdb.execute(f"gef-remote {GDBSERVER_DEFAULT_HOST} {port}")
153+
gdb.execute(f"target remote :{port}")
166154
gdb.execute("b main")
167155
gdb.execute("continue")
168156
sections = gef.memory.maps

tests/api/gef_session.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
ARCH,
1515
debug_target,
1616
gdbserver_session,
17+
get_random_port,
1718
qemuuser_session,
1819
GDBSERVER_DEFAULT_HOST,
1920
)
@@ -63,12 +64,11 @@ def test_root_dir_local(self):
6364
def test_root_dir_remote(self):
6465
gdb = self._gdb
6566
gdb.execute("start")
66-
6767
expected = os.stat("/")
68-
host = GDBSERVER_DEFAULT_HOST
69-
port = random.randint(1025, 65535)
68+
port = get_random_port()
69+
7070
with gdbserver_session(port=port):
71-
gdb.execute(f"gef-remote {host} {port}")
71+
gdb.execute(f"target remote :{port}")
7272
result = self._conn.root.eval("os.stat(gef.session.root)")
7373
assert (expected.st_dev == result.st_dev) and (
7474
expected.st_ino == result.st_ino
@@ -77,11 +77,8 @@ def test_root_dir_remote(self):
7777
@pytest.mark.skipif(ARCH not in ("x86_64",), reason=f"Skipped for {ARCH}")
7878
def test_root_dir_qemu(self):
7979
gdb, gef = self._gdb, self._gef
80+
port = get_random_port()
8081

81-
host = GDBSERVER_DEFAULT_HOST
82-
port = random.randint(1025, 65535)
8382
with qemuuser_session(port=port):
84-
gdb.execute(
85-
f"gef-remote --qemu-user --qemu-binary {self._target} {host} {port}"
86-
)
83+
gdb.execute(f"target remote :{port}")
8784
assert re.search(r"\/proc\/[0-9]+/root", str(gef.session.root))

tests/regressions/gdbserver_connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ def test_can_establish_connection_to_gdbserver_again_after_disconnect(self):
1010
gdb = self._gdb
1111

1212
with gdbserver_session(port=5001) as _, gdbserver_session(port=5002) as _:
13-
gdb.execute("gef-remote 127.0.0.1 5001")
13+
gdb.execute("target remote :5001")
1414
gdb.execute("detach")
1515

16-
gdb.execute("gef-remote 127.0.0.1 5002")
16+
gdb.execute("target remote :5002")
1717
gdb.execute("continue")

0 commit comments

Comments
 (0)