^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) # This file contains a few gdb macros (user defined commands) to extract
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) # useful information from kernel crashdump (kdump) like stack traces of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) # all the processes or a particular process and trapinfo.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) # These macros can be used by copying this file in .gdbinit (put in home
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) # directory or current directory) or by invoking gdb command with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) # --command=<command-file-name> option
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) # Credits:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) # Alexander Nyberg <alexn@telia.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) # V Srivatsa <vatsa@in.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) # Maneesh Soni <maneesh@in.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) define bttnobp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) set $tasks_off=((size_t)&((struct task_struct *)0)->tasks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) set $pid_off=((size_t)&((struct task_struct *)0)->thread_group.next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) set $init_t=&init_task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) set $next_t=(((char *)($init_t->tasks).next) - $tasks_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) set var $stacksize = sizeof(union thread_union)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) while ($next_t != $init_t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) set $next_t=(struct task_struct *)$next_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) printf "\npid %d; comm %s:\n", $next_t.pid, $next_t.comm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) printf "===================\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) set var $stackp = $next_t.thread.sp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) set var $stack_top = ($stackp & ~($stacksize - 1)) + $stacksize
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) while ($stackp < $stack_top)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) if (*($stackp) > _stext && *($stackp) < _sinittext)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) info symbol *($stackp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) set $stackp += 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) set $next_th=(((char *)$next_t->thread_group.next) - $pid_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) while ($next_th != $next_t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) set $next_th=(struct task_struct *)$next_th
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) printf "\npid %d; comm %s:\n", $next_t.pid, $next_t.comm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) printf "===================\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) set var $stackp = $next_t.thread.sp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) set var $stack_top = ($stackp & ~($stacksize - 1)) + stacksize
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) while ($stackp < $stack_top)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) if (*($stackp) > _stext && *($stackp) < _sinittext)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) info symbol *($stackp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) set $stackp += 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) set $next_th=(((char *)$next_th->thread_group.next) - $pid_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) set $next_t=(char *)($next_t->tasks.next) - $tasks_off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) document bttnobp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) dump all thread stack traces on a kernel compiled with !CONFIG_FRAME_POINTER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) define btthreadstack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) set var $pid_task = $arg0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) printf "\npid %d; comm %s:\n", $pid_task.pid, $pid_task.comm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) printf "task struct: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) print $pid_task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) printf "===================\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) set var $stackp = $pid_task.thread.sp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) set var $stacksize = sizeof(union thread_union)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) set var $stack_top = ($stackp & ~($stacksize - 1)) + $stacksize
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) set var $stack_bot = ($stackp & ~($stacksize - 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) set $stackp = *((unsigned long *) $stackp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) while (($stackp < $stack_top) && ($stackp > $stack_bot))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) set var $addr = *(((unsigned long *) $stackp) + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) info symbol $addr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) set $stackp = *((unsigned long *) $stackp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) document btthreadstack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) dump a thread stack using the given task structure pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) define btt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) set $tasks_off=((size_t)&((struct task_struct *)0)->tasks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) set $pid_off=((size_t)&((struct task_struct *)0)->thread_group.next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) set $init_t=&init_task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) set $next_t=(((char *)($init_t->tasks).next) - $tasks_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) while ($next_t != $init_t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) set $next_t=(struct task_struct *)$next_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) btthreadstack $next_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) set $next_th=(((char *)$next_t->thread_group.next) - $pid_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) while ($next_th != $next_t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) set $next_th=(struct task_struct *)$next_th
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) btthreadstack $next_th
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) set $next_th=(((char *)$next_th->thread_group.next) - $pid_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) set $next_t=(char *)($next_t->tasks.next) - $tasks_off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) document btt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) dump all thread stack traces on a kernel compiled with CONFIG_FRAME_POINTER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) define btpid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) set var $pid = $arg0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) set $tasks_off=((size_t)&((struct task_struct *)0)->tasks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) set $pid_off=((size_t)&((struct task_struct *)0)->thread_group.next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) set $init_t=&init_task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) set $next_t=(((char *)($init_t->tasks).next) - $tasks_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) set var $pid_task = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) while ($next_t != $init_t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) set $next_t=(struct task_struct *)$next_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) if ($next_t.pid == $pid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) set $pid_task = $next_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) set $next_th=(((char *)$next_t->thread_group.next) - $pid_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) while ($next_th != $next_t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) set $next_th=(struct task_struct *)$next_th
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) if ($next_th.pid == $pid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) set $pid_task = $next_th
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) set $next_th=(((char *)$next_th->thread_group.next) - $pid_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) set $next_t=(char *)($next_t->tasks.next) - $tasks_off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) btthreadstack $pid_task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) document btpid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) backtrace of pid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) define trapinfo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) set var $pid = $arg0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) set $tasks_off=((size_t)&((struct task_struct *)0)->tasks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) set $pid_off=((size_t)&((struct task_struct *)0)->thread_group.next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) set $init_t=&init_task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) set $next_t=(((char *)($init_t->tasks).next) - $tasks_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) set var $pid_task = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) while ($next_t != $init_t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) set $next_t=(struct task_struct *)$next_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if ($next_t.pid == $pid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) set $pid_task = $next_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) set $next_th=(((char *)$next_t->thread_group.next) - $pid_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) while ($next_th != $next_t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) set $next_th=(struct task_struct *)$next_th
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if ($next_th.pid == $pid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) set $pid_task = $next_th
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) set $next_th=(((char *)$next_th->thread_group.next) - $pid_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) set $next_t=(char *)($next_t->tasks.next) - $tasks_off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) printf "Trapno %ld, cr2 0x%lx, error_code %ld\n", $pid_task.thread.trap_no, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) $pid_task.thread.cr2, $pid_task.thread.error_code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) document trapinfo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) Run info threads and lookup pid of thread #1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 'trapinfo <pid>' will tell you by which trap & possibly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) address the kernel panicked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) define dump_record
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) set var $desc = $arg0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) set var $info = $arg1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) if ($argc > 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) set var $prev_flags = $arg2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) set var $prev_flags = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) set var $prefix = 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) set var $newline = 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) set var $begin = $desc->text_blk_lpos.begin % (1U << prb->text_data_ring.size_bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) set var $next = $desc->text_blk_lpos.next % (1U << prb->text_data_ring.size_bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) # handle data-less record
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if ($begin & 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) set var $text_len = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) set var $log = ""
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) # handle wrapping data block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) if ($begin > $next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) set var $begin = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) # skip over descriptor id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) set var $begin = $begin + sizeof(long)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) # handle truncated message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) if ($next - $begin < $info->text_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) set var $text_len = $next - $begin
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) set var $text_len = $info->text_len
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) set var $log = &prb->text_data_ring.data[$begin]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) # prev & LOG_CONT && !(info->flags & LOG_PREIX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) if (($prev_flags & 8) && !($info->flags & 4))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) set var $prefix = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) # info->flags & LOG_CONT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) if ($info->flags & 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) # (prev & LOG_CONT && !(prev & LOG_NEWLINE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (($prev_flags & 8) && !($prev_flags & 2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) set var $prefix = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) # (!(info->flags & LOG_NEWLINE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) if (!($info->flags & 2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) set var $newline = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) if ($prefix)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) printf "[%5lu.%06lu] ", $info->ts_nsec / 1000000000, $info->ts_nsec % 1000000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if ($text_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) eval "printf \"%%%d.%ds\", $log", $text_len, $text_len
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) if ($newline)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) printf "\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) # handle dictionary data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) set var $dict = &$info->dev_info.subsystem[0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) set var $dict_len = sizeof($info->dev_info.subsystem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) if ($dict[0] != '\0')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) printf " SUBSYSTEM="
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) set var $idx = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) while ($idx < $dict_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) set var $c = $dict[$idx]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) if ($c == '\0')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) loop_break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) if ($c < ' ' || $c >= 127 || $c == '\\')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) printf "\\x%02x", $c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) printf "%c", $c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) set var $idx = $idx + 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) printf "\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) set var $dict = &$info->dev_info.device[0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) set var $dict_len = sizeof($info->dev_info.device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) if ($dict[0] != '\0')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) printf " DEVICE="
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) set var $idx = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) while ($idx < $dict_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) set var $c = $dict[$idx]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) if ($c == '\0')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) loop_break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) if ($c < ' ' || $c >= 127 || $c == '\\')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) printf "\\x%02x", $c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) printf "%c", $c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) set var $idx = $idx + 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) printf "\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) document dump_record
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) Dump a single record. The first parameter is the descriptor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) the second parameter is the info, the third parameter is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) optional and specifies the previous record's flags, used for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) properly formatting continued lines.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) define dmesg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) # definitions from kernel/printk/printk_ringbuffer.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) set var $desc_committed = 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) set var $desc_finalized = 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) set var $desc_sv_bits = sizeof(long) * 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) set var $desc_flags_shift = $desc_sv_bits - 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) set var $desc_flags_mask = 3 << $desc_flags_shift
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) set var $id_mask = ~$desc_flags_mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) set var $desc_count = 1U << prb->desc_ring.count_bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) set var $prev_flags = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) set var $id = prb->desc_ring.tail_id.counter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) set var $end_id = prb->desc_ring.head_id.counter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) while (1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) set var $desc = &prb->desc_ring.descs[$id % $desc_count]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) set var $info = &prb->desc_ring.infos[$id % $desc_count]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) # skip non-committed record
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) set var $state = 3 & ($desc->state_var.counter >> $desc_flags_shift)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) if ($state == $desc_committed || $state == $desc_finalized)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) dump_record $desc $info $prev_flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) set var $prev_flags = $info->flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) set var $id = ($id + 1) & $id_mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) if ($id == $end_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) loop_break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) document dmesg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) print the kernel ring buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) end