Skip to content

Commit 0e1b240

Browse files
Kuan-Ying Leeakpm00
authored andcommitted
scripts/gdb/stackdepot: add stackdepot support
Add support for printing the backtrace of stackdepot handle. This is the preparation patch for dumping page_owner, slabtrace usage. Link: https://lkml.kernel.org/r/20230808083020.22254-6-Kuan-Ying.Lee@mediatek.com Signed-off-by: Kuan-Ying Lee <Kuan-Ying.Lee@mediatek.com> Cc: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Cc: Chinwen Chang <chinwen.chang@mediatek.com> Cc: Matthias Brugger <matthias.bgg@gmail.com> Cc: Qun-Wei Lin <qun-wei.lin@mediatek.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent eb985b5 commit 0e1b240

3 files changed

Lines changed: 57 additions & 0 deletions

File tree

scripts/gdb/linux/constants.py.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,4 @@ LX_CONFIG(CONFIG_VMAP_STACK)
128128
if IS_BUILTIN(CONFIG_NUMA):
129129
LX_VALUE(CONFIG_NODES_SHIFT)
130130
LX_CONFIG(CONFIG_DEBUG_VIRTUAL)
131+
LX_CONFIG(CONFIG_STACKDEPOT)

scripts/gdb/linux/stackdepot.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
#
3+
# Copyright (c) 2023 MediaTek Inc.
4+
#
5+
# Authors:
6+
# Kuan-Ying Lee <Kuan-Ying.Lee@mediatek.com>
7+
#
8+
9+
import gdb
10+
from linux import utils, constants
11+
12+
if constants.LX_CONFIG_STACKDEPOT:
13+
stack_record_type = utils.CachedType('struct stack_record')
14+
DEPOT_STACK_ALIGN = 4
15+
16+
def stack_depot_fetch(handle):
17+
global DEPOT_STACK_ALIGN
18+
global stack_record_type
19+
20+
stack_depot_disabled = gdb.parse_and_eval('stack_depot_disabled')
21+
22+
if stack_depot_disabled:
23+
raise gdb.GdbError("stack_depot_disabled\n")
24+
25+
handle_parts_t = gdb.lookup_type("union handle_parts")
26+
parts = handle.cast(handle_parts_t)
27+
offset = parts['offset'] << DEPOT_STACK_ALIGN
28+
pool_index_cached = gdb.parse_and_eval('pool_index')
29+
30+
if parts['pool_index'] > pool_index_cached:
31+
gdb.write("pool index %d out of bounds (%d) for stack id 0x%08x\n" % (parts['pool_index'], pool_index_cached, handle))
32+
return gdb.Value(0), 0
33+
34+
stack_pools = gdb.parse_and_eval('stack_pools')
35+
36+
try:
37+
pool = stack_pools[parts['pool_index']]
38+
stack = (pool + gdb.Value(offset).cast(utils.get_size_t_type())).cast(stack_record_type.get_type().pointer())
39+
size = int(stack['size'].cast(utils.get_ulong_type()))
40+
return stack['entries'], size
41+
except Exception as e:
42+
gdb.write("%s\n" % e)
43+
return gdb.Value(0), 0
44+
45+
def stack_depot_print(handle):
46+
if not constants.LX_CONFIG_STACKDEPOT:
47+
raise gdb.GdbError("CONFIG_STACKDEPOT is not enabled")
48+
49+
entries, nr_entries = stack_depot_fetch(handle)
50+
if nr_entries > 0:
51+
for i in range(0, nr_entries):
52+
try:
53+
gdb.execute("x /i 0x%x" % (int(entries[i])))
54+
except Exception as e:
55+
gdb.write("%s\n" % e)

scripts/gdb/vmlinux-gdb.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,4 @@
4545
import linux.radixtree
4646
import linux.interrupts
4747
import linux.mm
48+
import linux.stackdepot

0 commit comments

Comments
 (0)