2 # gdb helper commands and functions for Linux kernel debugging
6 # Copyright (c) Siemens AG, 2011-2013
9 # Jan Kiszka <jan.kiszka@siemens.com>
11 # This work is licensed under the terms of the GNU GPL version 2.
16 from linux
import utils
19 task_type
= utils
.CachedType("struct task_struct")
23 task_ptr_type
= task_type
.get_type().pointer()
24 init_task
= gdb
.parse_and_eval("init_task").address
31 t
= utils
.container_of(t
['thread_group']['next'],
32 task_ptr_type
, "thread_group")
36 t
= g
= utils
.container_of(g
['tasks']['next'],
37 task_ptr_type
, "tasks")
41 def get_task_by_pid(pid
):
42 for task
in task_lists():
43 if int(task
['pid']) == pid
:
48 class LxTaskByPidFunc(gdb
.Function
):
49 """Find Linux task by PID and return the task_struct variable.
51 $lx_task_by_pid(PID): Given PID, iterate over all tasks of the target and
52 return that task_struct variable which PID matches."""
55 super(LxTaskByPidFunc
, self
).__init
__("lx_task_by_pid")
57 def invoke(self
, pid
):
58 task
= get_task_by_pid(pid
)
60 return task
.dereference()
62 raise gdb
.GdbError("No task of PID " + str(pid
))
68 thread_info_type
= utils
.CachedType("struct thread_info")
73 def get_thread_info(task
):
74 global thread_info_type
75 thread_info_ptr_type
= thread_info_type
.get_type().pointer()
76 if utils
.is_target_arch("ia64"):
78 if ia64_task_size
is None:
79 ia64_task_size
= gdb
.parse_and_eval("sizeof(struct task_struct)")
80 thread_info_addr
= task
.address
+ ia64_task_size
81 thread_info
= thread_info_addr
.cast(thread_info_ptr_type
)
83 thread_info
= task
['stack'].cast(thread_info_ptr_type
)
84 return thread_info
.dereference()
87 class LxThreadInfoFunc (gdb
.Function
):
88 """Calculate Linux thread_info from task variable.
90 $lx_thread_info(TASK): Given TASK, return the corresponding thread_info
94 super(LxThreadInfoFunc
, self
).__init
__("lx_thread_info")
96 def invoke(self
, task
):
97 return get_thread_info(task
)
This page took 0.040924 seconds and 5 git commands to generate.