scripts/gdb/linux/utils.py
Source file repositories/reference/linux-study-clean/scripts/gdb/linux/utils.py
File Facts
- System
- Linux kernel
- Corpus path
scripts/gdb/linux/utils.py- Extension
.py- Size
- 7491 bytes
- Lines
- 274
- 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.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
#
# 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
def _new_objfile_handler(self, event):
self._type = None
gdb.events.new_objfile.disconnect(self._new_objfile_handler)
def get_type(self):
if self._type is None:
self._type = gdb.lookup_type(self._name)
if self._type is None:
raise gdb.GdbError(
"cannot resolve type '{0}'".format(self._name))
if hasattr(gdb, 'events') and hasattr(gdb.events, 'new_objfile'):
gdb.events.new_objfile.connect(self._new_objfile_handler)
return self._type
long_type = CachedType("long")
ulong_type = CachedType("unsigned long")
uint_type = CachedType("unsigned int")
atomic_long_type = CachedType("atomic_long_t")
size_t_type = CachedType("size_t")
struct_page_type = CachedType("struct page")
def get_uint_type():
global uint_type
return uint_type.get_type()
def get_page_type():
global struct_page_type
return struct_page_type.get_type()
def get_long_type():
global long_type
return long_type.get_type()
def get_ulong_type():
global ulong_type
return ulong_type.get_type()
def get_size_t_type():
global size_t_type
return size_t_type.get_type()
def offset_of(typeobj, field):
element = gdb.Value(0).cast(typeobj)
Annotation
- Atlas domain: Support Tooling And Documentation / scripts.
- Implementation status: atlas-only.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.