# Copyright (c) 2025, Oracle and/or its affiliates. # SPDX-License-Identifier: LGPL-2.1-or-later import contextlib import io import struct from drgn import ( Architecture, FaultError, Platform, Program, Symbol, SymbolBinding, SymbolKind, ) from drgn.commands._crash._rd import _print_memory from tests import TestCase def add_fake_memory_segment(prog, start, bytes, is_phys=False): def reader(address, count, offset, physical): if physical == is_phys: return bytes[offset : offset + count] raise FaultError("unable to read memory", address) prog.add_memory_segment(start, len(bytes), reader, physical=is_phys) class TestPrintMemory(TestCase): @classmethod def setUpClass(cls): # The only reason to set a specific architecture is to have a known word # size, which does impact alignment. The rest is not # architecture-specific. cls.prog = Program(platform=Platform(Architecture.X86_64)) mem_data = bytes(range(8)) + struct.pack("