scripts/gdb/linux/slab.py

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

File Facts

System
Linux kernel
Corpus path
scripts/gdb/linux/slab.py
Extension
.py
Size
11566 bytes
Lines
326
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

# SPDX-License-Identifier: GPL-2.0
#
# Copyright (c) 2023 MediaTek Inc.
#
# Authors:
#  Kuan-Ying Lee <Kuan-Ying.Lee@mediatek.com>
#

import gdb
import re
import traceback
from linux import lists, utils, stackdepot, constants, mm

SLAB_RED_ZONE       = constants.LX_SLAB_RED_ZONE
SLAB_POISON         = constants.LX_SLAB_POISON
SLAB_KMALLOC        = constants.LX_SLAB_KMALLOC
SLAB_HWCACHE_ALIGN  = constants.LX_SLAB_HWCACHE_ALIGN
SLAB_CACHE_DMA      = constants.LX_SLAB_CACHE_DMA
SLAB_CACHE_DMA32    = constants.LX_SLAB_CACHE_DMA32
SLAB_STORE_USER     = constants.LX_SLAB_STORE_USER
SLAB_PANIC          = constants.LX_SLAB_PANIC

OO_SHIFT = 16
OO_MASK = (1 << OO_SHIFT) - 1

if constants.LX_CONFIG_SLUB_DEBUG:
    slab_type = utils.CachedType("struct slab")
    slab_ptr_type = slab_type.get_type().pointer()
    kmem_cache_type = utils.CachedType("struct kmem_cache")
    kmem_cache_ptr_type = kmem_cache_type.get_type().pointer()
    freeptr_t = utils.CachedType("freeptr_t")
    freeptr_t_ptr = freeptr_t.get_type().pointer()

    track_type = gdb.lookup_type('struct track')
    track_alloc = int(gdb.parse_and_eval('TRACK_ALLOC'))
    track_free = int(gdb.parse_and_eval('TRACK_FREE'))

def slab_folio(slab):
    return slab.cast(gdb.lookup_type("struct folio").pointer())

def slab_address(slab):
    p_ops = mm.page_ops().ops
    folio = slab_folio(slab)
    return p_ops.folio_address(folio)

def for_each_object(cache, addr, slab_objects):
    p = addr
    if cache['flags'] & SLAB_RED_ZONE:
        p += int(cache['red_left_pad'])
    while p < addr + (slab_objects * cache['size']):
        yield p
        p = p + int(cache['size'])

def get_info_end(cache):
    if (cache['offset'] >= cache['inuse']):
        return cache['inuse'] + gdb.lookup_type("void").pointer().sizeof
    else:
        return cache['inuse']

def get_orig_size(cache, obj):
    if cache['flags'] & SLAB_STORE_USER and cache['flags'] & SLAB_KMALLOC:
        p = mm.page_ops().ops.kasan_reset_tag(obj)
        p += get_info_end(cache)
        p += gdb.lookup_type('struct track').sizeof * 2
        p = p.cast(utils.get_uint_type().pointer())
        return p.dereference()
    else:
        return cache['object_size']

def get_track(cache, object_pointer, alloc):

Annotation

Implementation Notes