From deeab2f6f679783b25ced3ef74c0582c3e2c8095 Mon Sep 17 00:00:00 2001 From: Angelo942 <52466998+Angelo942@users.noreply.github.com> Date: Thu, 4 Jan 2024 17:42:07 +0000 Subject: [PATCH] Set correct parsing to `gdb_get_location_from_symbol` (#1037) ## Description As stated in the comments `info symbol` returns "` + `" with spaces around the `+`. The current split leaves a space in front of the offset which makes .isdigit() return False. --- gef.py | 4 ++-- tests/commands/xinfo.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gef.py b/gef.py index bc61ad4b4..5c2dbfd24 100644 --- a/gef.py +++ b/gef.py @@ -2021,8 +2021,8 @@ def gdb_get_location_from_symbol(address: int) -> Optional[Tuple[str, int]]: # gdb outputs symbols with format: " + in section of ", # here, we are only interested in symbol name and offset. i = sym.find(" in section ") - sym = sym[:i].split("+") - name, offset = sym[0].strip(), 0 + sym = sym[:i].split(" + ") + name, offset = sym[0], 0 if len(sym) == 2 and sym[1].isdigit(): offset = int(sym[1]) return name, offset diff --git a/tests/commands/xinfo.py b/tests/commands/xinfo.py index afa53b949..ea50e23b9 100644 --- a/tests/commands/xinfo.py +++ b/tests/commands/xinfo.py @@ -20,8 +20,8 @@ def test_cmd_xinfo(self): self.assertTrue(len(res.splitlines()) >= 7) def test_cmd_xinfo_on_class(self): - cmd = "xinfo $pc" + cmd = "xinfo $pc+4" target = debug_target("class") - res = gdb_run_silent_cmd(cmd, target=target, before=["b B::Run()"]) + res = gdb_run_silent_cmd(cmd, target=target, before=["b *'B::Run'"]) self.assertNoException(res) - self.assertIn("Symbol: B::Run", res) + self.assertIn("Symbol: B::Run()+4", res)