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