diff --git a/gef.py b/gef.py index 8e9e4d2f3..e8fef99b0 100644 --- a/gef.py +++ b/gef.py @@ -2010,11 +2010,13 @@ def gdb_get_location_from_symbol(address: int) -> Optional[Tuple[str, int]]: if sym.startswith("No symbol matches"): return None + # 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], 0 - if len(sym) == 3 and sym[2].isdigit(): - offset = int(sym[2]) + sym = sym[:i].split("+") + name, offset = sym[0].strip(), 0 + if len(sym) == 2 and sym[1].isdigit(): + offset = int(sym[1]) return name, offset diff --git a/tests/binaries/Makefile b/tests/binaries/Makefile index d0fd53ac2..0a8acc58f 100644 --- a/tests/binaries/Makefile +++ b/tests/binaries/Makefile @@ -2,7 +2,9 @@ CC = gcc DEBUG = 1 CFLAGS += -Wall SOURCES = $(wildcard *.c) +SOURCES += $(wildcard *.cpp) LINKED = $(SOURCES:.c=.out) +LINKED := $(LINKED:.cpp=.out) LDFLAGS = EXTRA_FLAGS = TMPDIR ?= /tmp @@ -27,6 +29,10 @@ all: $(LINKED) @echo "[+] Building '$(TMPDIR)/$@'" @$(CC) $(CFLAGS) $(EXTRA_FLAGS) -o $(TMPDIR)/$@ $? $(LDFLAGS) +%.out : %.cpp + @echo "[+] Building '$(TMPDIR)/$@'" + @$(CC) $(CFLAGS) $(EXTRA_FLAGS) -o $(TMPDIR)/$@ $? $(LDFLAGS) -lstdc++ + clean : @echo "[+] Cleaning stuff" @cd $(TMPDIR) && rm -f $(LINKED) diff --git a/tests/binaries/class.cpp b/tests/binaries/class.cpp new file mode 100644 index 000000000..acc427c48 --- /dev/null +++ b/tests/binaries/class.cpp @@ -0,0 +1,29 @@ +#include + +class TraitA {}; +class TraitB {}; + +class A { +private: + int _a; + +public: + virtual ~A() {} + virtual void Run() { printf("I am A\n"); } +}; + +template +class B : public A { +private: + int _b; + +public: + virtual void Run() { printf("I am B\n"); } +}; + +int main() { + A* a = new B(); + a->Run(); + delete a; + return 0; +} diff --git a/tests/commands/xinfo.py b/tests/commands/xinfo.py index 662e2c38f..7c5b299b6 100644 --- a/tests/commands/xinfo.py +++ b/tests/commands/xinfo.py @@ -3,7 +3,7 @@ """ -from tests.utils import GefUnitTestGeneric, gdb_run_cmd, gdb_start_silent_cmd +from tests.utils import GefUnitTestGeneric, gdb_run_cmd, gdb_start_silent_cmd, gdb_run_silent_cmd, _target class XinfoCommand(GefUnitTestGeneric): @@ -18,3 +18,10 @@ def test_cmd_xinfo(self): res = gdb_start_silent_cmd("xinfo $sp") self.assertNoException(res) self.assertTrue(len(res.splitlines()) >= 7) + + def test_cmd_xinfo_on_class(self): + cmd = "xinfo $pc" + target = _target("class") + res = gdb_run_silent_cmd(cmd, target=target, before=["b B::Run()"]) + self.assertNoException(res) + self.assertIn("Symbol: B::Run", res)