From 6209c5b362ffe9f53125b478d1bf6f39f03db056 Mon Sep 17 00:00:00 2001 From: Disconnect3d Date: Thu, 29 Aug 2024 00:04:52 +0200 Subject: [PATCH] Add tests for dt command (#2398) --- tests/gdb-tests/tests/test_command_dt.py | 43 ++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tests/gdb-tests/tests/test_command_dt.py diff --git a/tests/gdb-tests/tests/test_command_dt.py b/tests/gdb-tests/tests/test_command_dt.py new file mode 100644 index 000000000..fdaf340d7 --- /dev/null +++ b/tests/gdb-tests/tests/test_command_dt.py @@ -0,0 +1,43 @@ +from __future__ import annotations + +import re + +import gdb + +import tests + +HEAP_MALLOC_CHUNK = tests.binaries.get("heap_malloc_chunk.out") + + +def test_command_dt_works_with_address(start_binary): + start_binary(HEAP_MALLOC_CHUNK) + gdb.execute("break break_here") + gdb.execute("continue") + + tcache = gdb.execute("print tcache", to_string=True) + + tcache_addr = tcache.split()[-1] + + out = gdb.execute(f'dt "struct tcache_perthread_struct" {tcache_addr}', to_string=True) + + exp_regex = ( + "struct tcache_perthread_struct @ 0x[0-9a-f]+\n" + " 0x[0-9a-f]+ \\+0x0000 counts : uint16_t \\[64\\]\n" + " 0x[0-9a-f]+ \\+0x[0-9a-f]{4} entries : tcache_entry \\*\\[64\\]\n" + ) + assert re.match(exp_regex, out) + + +def test_command_dt_works_with_no_address(start_binary): + start_binary(HEAP_MALLOC_CHUNK) + gdb.execute("break break_here") + gdb.execute("continue") + + out = gdb.execute('dt "struct tcache_perthread_struct"', to_string=True) + + exp_regex = ( + "struct tcache_perthread_struct\n" + " \\+0x0000 counts : uint16_t \\[64\\]\n" + " \\+0x[0-9a-f]{4} entries : tcache_entry \\*\\[64\\]\n" + ) + assert re.match(exp_regex, out)