# # gdb helper commands and functions for Linux kernel debugging # # common utilities # # Copyright (c) Siemens AG, 2011-2013 # # Authors: # Jan Kiszka <jan.kiszka@siemens.com> # # This work is licensed under the terms of the GNU GPL version 2. #
import contextlib import dataclasses import re import typing
import gdb
class CachedType: def __init__(self, name):
self._type = None
self._name = name
class ContainerOf(gdb.Function): """Return pointer to containing data structure.
$container_of(PTR, "TYPE", "ELEMENT"): Given PTR, return a pointer to the
data structure of the type TYPE in which PTR is the address of ELEMENT.
Note that TYPE and ELEMENT have to be quoted as strings."""
def is_target_arch(arch): if hasattr(gdb.Frame, 'architecture'): return arch in gdb.newest_frame().architecture().name() else: global target_arch if target_arch isNone:
target_arch = gdb.execute("show architecture", to_string=True) return arch in target_arch
@contextlib.contextmanager def qemu_phy_mem_mode():
connection = gdb.selected_inferior().connection
orig = connection.send_packet("qqemu.PhyMemMode") if orig notin b"01": raise gdb.error("Unexpected qemu.PhyMemMode")
orig = orig.decode() if connection.send_packet("Qqemu.PhyMemMode:1") != b"OK": raise gdb.error("Failed to set qemu.PhyMemMode") try: yield finally: if connection.send_packet("Qqemu.PhyMemMode:" + orig) != b"OK": raise gdb.error("Failed to restore qemu.PhyMemMode")
@dataclasses.dataclass class VmCore:
kerneloffset: typing.Optional[int]
def parse_vmcore(s):
match = re.search(r"KERNELOFFSET=([0-9a-f]+)", s) if match isNone:
kerneloffset = None else:
kerneloffset = int(match.group(1), 16) return VmCore(kerneloffset=kerneloffset)
def get_vmlinux():
vmlinux = 'vmlinux' for obj in gdb.objfiles(): if (obj.filename.endswith('vmlinux') or
obj.filename.endswith('vmlinux.debug')):
vmlinux = obj.filename return vmlinux
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.