2005-06-25 14:58:15 -07:00
|
|
|
#
|
|
|
|
# This file contains a few gdb macros (user defined commands) to extract
|
|
|
|
# useful information from kernel crashdump (kdump) like stack traces of
|
|
|
|
# all the processes or a particular process and trapinfo.
|
|
|
|
#
|
|
|
|
# These macros can be used by copying this file in .gdbinit (put in home
|
|
|
|
# directory or current directory) or by invoking gdb command with
|
|
|
|
# --command=<command-file-name> option
|
|
|
|
#
|
|
|
|
# Credits:
|
|
|
|
# Alexander Nyberg <alexn@telia.com>
|
|
|
|
# V Srivatsa <vatsa@in.ibm.com>
|
|
|
|
# Maneesh Soni <maneesh@in.ibm.com>
|
|
|
|
#
|
|
|
|
|
|
|
|
define bttnobp
|
|
|
|
set $tasks_off=((size_t)&((struct task_struct *)0)->tasks)
|
2016-05-23 16:24:25 -07:00
|
|
|
set $pid_off=((size_t)&((struct task_struct *)0)->thread_group.next)
|
2005-06-25 14:58:15 -07:00
|
|
|
set $init_t=&init_task
|
|
|
|
set $next_t=(((char *)($init_t->tasks).next) - $tasks_off)
|
2016-05-23 16:24:25 -07:00
|
|
|
set var $stacksize = sizeof(union thread_union)
|
2005-06-25 14:58:15 -07:00
|
|
|
while ($next_t != $init_t)
|
|
|
|
set $next_t=(struct task_struct *)$next_t
|
|
|
|
printf "\npid %d; comm %s:\n", $next_t.pid, $next_t.comm
|
|
|
|
printf "===================\n"
|
2016-05-23 16:24:25 -07:00
|
|
|
set var $stackp = $next_t.thread.sp
|
|
|
|
set var $stack_top = ($stackp & ~($stacksize - 1)) + $stacksize
|
2005-06-25 14:58:15 -07:00
|
|
|
|
|
|
|
while ($stackp < $stack_top)
|
|
|
|
if (*($stackp) > _stext && *($stackp) < _sinittext)
|
|
|
|
info symbol *($stackp)
|
|
|
|
end
|
|
|
|
set $stackp += 4
|
|
|
|
end
|
2016-05-23 16:24:25 -07:00
|
|
|
set $next_th=(((char *)$next_t->thread_group.next) - $pid_off)
|
2005-06-25 14:58:15 -07:00
|
|
|
while ($next_th != $next_t)
|
|
|
|
set $next_th=(struct task_struct *)$next_th
|
|
|
|
printf "\npid %d; comm %s:\n", $next_t.pid, $next_t.comm
|
|
|
|
printf "===================\n"
|
2016-05-23 16:24:25 -07:00
|
|
|
set var $stackp = $next_t.thread.sp
|
|
|
|
set var $stack_top = ($stackp & ~($stacksize - 1)) + stacksize
|
2005-06-25 14:58:15 -07:00
|
|
|
|
|
|
|
while ($stackp < $stack_top)
|
|
|
|
if (*($stackp) > _stext && *($stackp) < _sinittext)
|
|
|
|
info symbol *($stackp)
|
|
|
|
end
|
|
|
|
set $stackp += 4
|
|
|
|
end
|
2016-05-23 16:24:25 -07:00
|
|
|
set $next_th=(((char *)$next_th->thread_group.next) - $pid_off)
|
2005-06-25 14:58:15 -07:00
|
|
|
end
|
|
|
|
set $next_t=(char *)($next_t->tasks.next) - $tasks_off
|
|
|
|
end
|
|
|
|
end
|
|
|
|
document bttnobp
|
|
|
|
dump all thread stack traces on a kernel compiled with !CONFIG_FRAME_POINTER
|
|
|
|
end
|
|
|
|
|
2016-05-23 16:24:25 -07:00
|
|
|
define btthreadstack
|
|
|
|
set var $pid_task = $arg0
|
|
|
|
|
|
|
|
printf "\npid %d; comm %s:\n", $pid_task.pid, $pid_task.comm
|
|
|
|
printf "task struct: "
|
|
|
|
print $pid_task
|
|
|
|
printf "===================\n"
|
|
|
|
set var $stackp = $pid_task.thread.sp
|
|
|
|
set var $stacksize = sizeof(union thread_union)
|
|
|
|
set var $stack_top = ($stackp & ~($stacksize - 1)) + $stacksize
|
|
|
|
set var $stack_bot = ($stackp & ~($stacksize - 1))
|
|
|
|
|
|
|
|
set $stackp = *((unsigned long *) $stackp)
|
|
|
|
while (($stackp < $stack_top) && ($stackp > $stack_bot))
|
|
|
|
set var $addr = *(((unsigned long *) $stackp) + 1)
|
|
|
|
info symbol $addr
|
|
|
|
set $stackp = *((unsigned long *) $stackp)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
document btthreadstack
|
|
|
|
dump a thread stack using the given task structure pointer
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2005-06-25 14:58:15 -07:00
|
|
|
define btt
|
|
|
|
set $tasks_off=((size_t)&((struct task_struct *)0)->tasks)
|
2016-05-23 16:24:25 -07:00
|
|
|
set $pid_off=((size_t)&((struct task_struct *)0)->thread_group.next)
|
2005-06-25 14:58:15 -07:00
|
|
|
set $init_t=&init_task
|
|
|
|
set $next_t=(((char *)($init_t->tasks).next) - $tasks_off)
|
|
|
|
while ($next_t != $init_t)
|
|
|
|
set $next_t=(struct task_struct *)$next_t
|
2016-05-23 16:24:25 -07:00
|
|
|
btthreadstack $next_t
|
2005-06-25 14:58:15 -07:00
|
|
|
|
2016-05-23 16:24:25 -07:00
|
|
|
set $next_th=(((char *)$next_t->thread_group.next) - $pid_off)
|
2005-06-25 14:58:15 -07:00
|
|
|
while ($next_th != $next_t)
|
|
|
|
set $next_th=(struct task_struct *)$next_th
|
2016-05-23 16:24:25 -07:00
|
|
|
btthreadstack $next_th
|
|
|
|
set $next_th=(((char *)$next_th->thread_group.next) - $pid_off)
|
2005-06-25 14:58:15 -07:00
|
|
|
end
|
|
|
|
set $next_t=(char *)($next_t->tasks.next) - $tasks_off
|
|
|
|
end
|
|
|
|
end
|
|
|
|
document btt
|
|
|
|
dump all thread stack traces on a kernel compiled with CONFIG_FRAME_POINTER
|
|
|
|
end
|
|
|
|
|
|
|
|
define btpid
|
|
|
|
set var $pid = $arg0
|
|
|
|
set $tasks_off=((size_t)&((struct task_struct *)0)->tasks)
|
2016-05-23 16:24:25 -07:00
|
|
|
set $pid_off=((size_t)&((struct task_struct *)0)->thread_group.next)
|
2005-06-25 14:58:15 -07:00
|
|
|
set $init_t=&init_task
|
|
|
|
set $next_t=(((char *)($init_t->tasks).next) - $tasks_off)
|
|
|
|
set var $pid_task = 0
|
|
|
|
|
|
|
|
while ($next_t != $init_t)
|
|
|
|
set $next_t=(struct task_struct *)$next_t
|
|
|
|
|
|
|
|
if ($next_t.pid == $pid)
|
|
|
|
set $pid_task = $next_t
|
|
|
|
end
|
|
|
|
|
2016-05-23 16:24:25 -07:00
|
|
|
set $next_th=(((char *)$next_t->thread_group.next) - $pid_off)
|
2005-06-25 14:58:15 -07:00
|
|
|
while ($next_th != $next_t)
|
|
|
|
set $next_th=(struct task_struct *)$next_th
|
|
|
|
if ($next_th.pid == $pid)
|
|
|
|
set $pid_task = $next_th
|
|
|
|
end
|
2016-05-23 16:24:25 -07:00
|
|
|
set $next_th=(((char *)$next_th->thread_group.next) - $pid_off)
|
2005-06-25 14:58:15 -07:00
|
|
|
end
|
|
|
|
set $next_t=(char *)($next_t->tasks.next) - $tasks_off
|
|
|
|
end
|
|
|
|
|
2016-05-23 16:24:25 -07:00
|
|
|
btthreadstack $pid_task
|
2005-06-25 14:58:15 -07:00
|
|
|
end
|
|
|
|
document btpid
|
|
|
|
backtrace of pid
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
define trapinfo
|
|
|
|
set var $pid = $arg0
|
|
|
|
set $tasks_off=((size_t)&((struct task_struct *)0)->tasks)
|
2016-05-23 16:24:25 -07:00
|
|
|
set $pid_off=((size_t)&((struct task_struct *)0)->thread_group.next)
|
2005-06-25 14:58:15 -07:00
|
|
|
set $init_t=&init_task
|
|
|
|
set $next_t=(((char *)($init_t->tasks).next) - $tasks_off)
|
|
|
|
set var $pid_task = 0
|
|
|
|
|
|
|
|
while ($next_t != $init_t)
|
|
|
|
set $next_t=(struct task_struct *)$next_t
|
|
|
|
|
|
|
|
if ($next_t.pid == $pid)
|
|
|
|
set $pid_task = $next_t
|
|
|
|
end
|
|
|
|
|
2016-05-23 16:24:25 -07:00
|
|
|
set $next_th=(((char *)$next_t->thread_group.next) - $pid_off)
|
2005-06-25 14:58:15 -07:00
|
|
|
while ($next_th != $next_t)
|
|
|
|
set $next_th=(struct task_struct *)$next_th
|
|
|
|
if ($next_th.pid == $pid)
|
|
|
|
set $pid_task = $next_th
|
|
|
|
end
|
2016-05-23 16:24:25 -07:00
|
|
|
set $next_th=(((char *)$next_th->thread_group.next) - $pid_off)
|
2005-06-25 14:58:15 -07:00
|
|
|
end
|
|
|
|
set $next_t=(char *)($next_t->tasks.next) - $tasks_off
|
|
|
|
end
|
|
|
|
|
|
|
|
printf "Trapno %ld, cr2 0x%lx, error_code %ld\n", $pid_task.thread.trap_no, \
|
|
|
|
$pid_task.thread.cr2, $pid_task.thread.error_code
|
|
|
|
|
|
|
|
end
|
|
|
|
document trapinfo
|
|
|
|
Run info threads and lookup pid of thread #1
|
|
|
|
'trapinfo <pid>' will tell you by which trap & possibly
|
2006-06-26 09:30:00 -07:00
|
|
|
address the kernel panicked.
|
2005-06-25 14:58:15 -07:00
|
|
|
end
|
2006-01-11 13:17:30 -07:00
|
|
|
|
2020-08-14 14:25:25 -07:00
|
|
|
define dump_record
|
|
|
|
set var $desc = $arg0
|
2020-09-21 04:18:45 -07:00
|
|
|
set var $info = $arg1
|
|
|
|
if ($argc > 2)
|
|
|
|
set var $prev_flags = $arg2
|
2016-06-03 14:55:36 -07:00
|
|
|
else
|
2020-08-14 14:25:25 -07:00
|
|
|
set var $prev_flags = 0
|
2016-06-03 14:55:36 -07:00
|
|
|
end
|
2020-08-14 14:25:25 -07:00
|
|
|
|
|
|
|
set var $prefix = 1
|
|
|
|
set var $newline = 1
|
|
|
|
|
|
|
|
set var $begin = $desc->text_blk_lpos.begin % (1U << prb->text_data_ring.size_bits)
|
|
|
|
set var $next = $desc->text_blk_lpos.next % (1U << prb->text_data_ring.size_bits)
|
|
|
|
|
|
|
|
# handle data-less record
|
|
|
|
if ($begin & 1)
|
|
|
|
set var $text_len = 0
|
|
|
|
set var $log = ""
|
|
|
|
else
|
|
|
|
# handle wrapping data block
|
|
|
|
if ($begin > $next)
|
|
|
|
set var $begin = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
# skip over descriptor id
|
|
|
|
set var $begin = $begin + sizeof(long)
|
|
|
|
|
|
|
|
# handle truncated message
|
|
|
|
if ($next - $begin < $info->text_len)
|
|
|
|
set var $text_len = $next - $begin
|
|
|
|
else
|
|
|
|
set var $text_len = $info->text_len
|
|
|
|
end
|
|
|
|
|
|
|
|
set var $log = &prb->text_data_ring.data[$begin]
|
|
|
|
end
|
|
|
|
|
|
|
|
# prev & LOG_CONT && !(info->flags & LOG_PREIX)
|
|
|
|
if (($prev_flags & 8) && !($info->flags & 4))
|
|
|
|
set var $prefix = 0
|
2016-06-03 14:55:36 -07:00
|
|
|
end
|
|
|
|
|
2020-08-14 14:25:25 -07:00
|
|
|
# info->flags & LOG_CONT
|
|
|
|
if ($info->flags & 8)
|
2016-06-03 14:55:36 -07:00
|
|
|
# (prev & LOG_CONT && !(prev & LOG_NEWLINE))
|
|
|
|
if (($prev_flags & 8) && !($prev_flags & 2))
|
2020-08-14 14:25:25 -07:00
|
|
|
set var $prefix = 0
|
2016-06-03 14:55:36 -07:00
|
|
|
end
|
2020-08-14 14:25:25 -07:00
|
|
|
# (!(info->flags & LOG_NEWLINE))
|
|
|
|
if (!($info->flags & 2))
|
|
|
|
set var $newline = 0
|
2016-06-03 14:55:36 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if ($prefix)
|
2020-08-14 14:25:25 -07:00
|
|
|
printf "[%5lu.%06lu] ", $info->ts_nsec / 1000000000, $info->ts_nsec % 1000000000
|
2016-06-03 14:55:36 -07:00
|
|
|
end
|
2020-08-14 14:25:25 -07:00
|
|
|
if ($text_len)
|
|
|
|
eval "printf \"%%%d.%ds\", $log", $text_len, $text_len
|
2016-06-03 14:55:36 -07:00
|
|
|
end
|
|
|
|
if ($newline)
|
|
|
|
printf "\n"
|
|
|
|
end
|
2020-08-14 14:25:25 -07:00
|
|
|
|
|
|
|
# handle dictionary data
|
|
|
|
|
2020-09-21 04:18:45 -07:00
|
|
|
set var $dict = &$info->dev_info.subsystem[0]
|
|
|
|
set var $dict_len = sizeof($info->dev_info.subsystem)
|
|
|
|
if ($dict[0] != '\0')
|
|
|
|
printf " SUBSYSTEM="
|
|
|
|
set var $idx = 0
|
|
|
|
while ($idx < $dict_len)
|
|
|
|
set var $c = $dict[$idx]
|
|
|
|
if ($c == '\0')
|
|
|
|
loop_break
|
|
|
|
else
|
|
|
|
if ($c < ' ' || $c >= 127 || $c == '\\')
|
|
|
|
printf "\\x%02x", $c
|
|
|
|
else
|
|
|
|
printf "%c", $c
|
|
|
|
end
|
|
|
|
end
|
|
|
|
set var $idx = $idx + 1
|
2020-08-14 14:25:25 -07:00
|
|
|
end
|
2020-09-21 04:18:45 -07:00
|
|
|
printf "\n"
|
2020-08-14 14:25:25 -07:00
|
|
|
end
|
|
|
|
|
2020-09-21 04:18:45 -07:00
|
|
|
set var $dict = &$info->dev_info.device[0]
|
|
|
|
set var $dict_len = sizeof($info->dev_info.device)
|
|
|
|
if ($dict[0] != '\0')
|
|
|
|
printf " DEVICE="
|
2020-08-14 14:25:25 -07:00
|
|
|
set var $idx = 0
|
|
|
|
while ($idx < $dict_len)
|
|
|
|
set var $c = $dict[$idx]
|
2016-06-03 14:55:36 -07:00
|
|
|
if ($c == '\0')
|
2020-09-21 04:18:45 -07:00
|
|
|
loop_break
|
2016-06-03 14:55:36 -07:00
|
|
|
else
|
|
|
|
if ($c < ' ' || $c >= 127 || $c == '\\')
|
|
|
|
printf "\\x%02x", $c
|
|
|
|
else
|
|
|
|
printf "%c", $c
|
|
|
|
end
|
|
|
|
end
|
2020-08-14 14:25:25 -07:00
|
|
|
set var $idx = $idx + 1
|
2016-06-03 14:55:36 -07:00
|
|
|
end
|
|
|
|
printf "\n"
|
|
|
|
end
|
|
|
|
end
|
2020-08-14 14:25:25 -07:00
|
|
|
document dump_record
|
2020-09-21 04:18:45 -07:00
|
|
|
Dump a single record. The first parameter is the descriptor,
|
|
|
|
the second parameter is the info, the third parameter is
|
|
|
|
optional and specifies the previous record's flags, used for
|
|
|
|
properly formatting continued lines.
|
2016-06-03 14:55:36 -07:00
|
|
|
end
|
2006-01-11 13:17:30 -07:00
|
|
|
|
2016-06-03 14:55:36 -07:00
|
|
|
define dmesg
|
2020-09-14 05:33:52 -07:00
|
|
|
# definitions from kernel/printk/printk_ringbuffer.h
|
|
|
|
set var $desc_committed = 1
|
2020-09-14 05:33:53 -07:00
|
|
|
set var $desc_finalized = 2
|
2020-09-14 05:33:52 -07:00
|
|
|
set var $desc_sv_bits = sizeof(long) * 8
|
|
|
|
set var $desc_flags_shift = $desc_sv_bits - 2
|
|
|
|
set var $desc_flags_mask = 3 << $desc_flags_shift
|
|
|
|
set var $id_mask = ~$desc_flags_mask
|
2020-08-14 14:25:25 -07:00
|
|
|
|
|
|
|
set var $desc_count = 1U << prb->desc_ring.count_bits
|
|
|
|
set var $prev_flags = 0
|
|
|
|
|
|
|
|
set var $id = prb->desc_ring.tail_id.counter
|
|
|
|
set var $end_id = prb->desc_ring.head_id.counter
|
2006-01-11 13:17:30 -07:00
|
|
|
|
2016-06-03 14:55:36 -07:00
|
|
|
while (1)
|
2020-08-14 14:25:25 -07:00
|
|
|
set var $desc = &prb->desc_ring.descs[$id % $desc_count]
|
2020-09-21 04:18:45 -07:00
|
|
|
set var $info = &prb->desc_ring.infos[$id % $desc_count]
|
2020-08-14 14:25:25 -07:00
|
|
|
|
|
|
|
# skip non-committed record
|
2020-09-14 05:33:52 -07:00
|
|
|
set var $state = 3 & ($desc->state_var.counter >> $desc_flags_shift)
|
2020-09-14 05:33:53 -07:00
|
|
|
if ($state == $desc_committed || $state == $desc_finalized)
|
2020-09-21 04:18:45 -07:00
|
|
|
dump_record $desc $info $prev_flags
|
|
|
|
set var $prev_flags = $info->flags
|
2016-06-03 14:55:36 -07:00
|
|
|
end
|
2020-08-14 14:25:25 -07:00
|
|
|
|
|
|
|
if ($id == $end_id)
|
2016-06-03 14:55:36 -07:00
|
|
|
loop_break
|
2006-01-11 13:17:30 -07:00
|
|
|
end
|
2022-12-29 06:43:39 -07:00
|
|
|
set var $id = ($id + 1) & $id_mask
|
2006-01-11 13:17:30 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
document dmesg
|
|
|
|
print the kernel ring buffer
|
|
|
|
end
|