scripts/gdb/linux/symbols.py

Source file repositories/reference/linux-study-clean/scripts/gdb/linux/symbols.py

File Facts

System
Linux kernel
Corpus path
scripts/gdb/linux/symbols.py
Extension
.py
Size
12935 bytes
Lines
339
Domain
Support Tooling And Documentation
Bucket
scripts
Inferred role
Support Tooling And Documentation: scripts
Status
atlas-only

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

#
# gdb helper commands and functions for Linux kernel debugging
#
#  load kernel and module symbols
#
# 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 atexit
import gdb
import os
import re
import struct

from itertools import count
from linux import bpf, constants, modules, utils


if hasattr(gdb, 'Breakpoint'):
    class LoadModuleBreakpoint(gdb.Breakpoint):
        def __init__(self, spec, gdb_command):
            super(LoadModuleBreakpoint, self).__init__(spec, internal=True)
            self.silent = True
            self.gdb_command = gdb_command

        def stop(self):
            module = gdb.parse_and_eval("mod")
            module_name = module['name'].string()
            cmd = self.gdb_command

            # enforce update if object file is not found
            cmd.module_files_updated = False

            # Disable pagination while reporting symbol (re-)loading.
            # The console input is blocked in this context so that we would
            # get stuck waiting for the user to acknowledge paged output.
            with utils.pagination_off():
                if module_name in cmd.loaded_modules:
                    gdb.write("refreshing all symbols to reload module "
                              "'{0}'\n".format(module_name))
                    cmd.load_all_symbols()
                else:
                    cmd.load_module_symbols(module)

            return False


def get_vmcore_s390():
    with utils.qemu_phy_mem_mode():
        vmcore_info = 0x0e0c
        paddr_vmcoreinfo_note = gdb.parse_and_eval("*(unsigned long long *)" +
                                                   hex(vmcore_info))
        if paddr_vmcoreinfo_note == 0 or paddr_vmcoreinfo_note & 1:
            # In the early boot case, extract vm_layout.kaslr_offset from the
            # vmlinux image in physical memory.
            if paddr_vmcoreinfo_note == 0:
                kaslr_offset_phys = 0
            else:
                kaslr_offset_phys = paddr_vmcoreinfo_note - 1
            with utils.pagination_off():
                gdb.execute("symbol-file {0} -o {1}".format(
                    utils.get_vmlinux(), hex(kaslr_offset_phys)))
            kaslr_offset = gdb.parse_and_eval("vm_layout.kaslr_offset")
            return "KERNELOFFSET=" + hex(kaslr_offset)[2:]
        inferior = gdb.selected_inferior()

Annotation

Implementation Notes