1# $DragonFly: src/sys/dev/raid/vinum/.gdbinit.kernel,v 1.3 2006/02/17 19:18:06 dillon Exp $ 2set remotebaud 38400 3set remotetimeout 1 4set complaints 1 5set print pretty 6define xi 7x/10i $eip 8end 9define xs 10x/12x $esp 11end 12define xb 13x/12x $ebp 14end 15define z 16ni 17x/1i $eip 18end 19define zs 20si 21x/1i $eip 22end 23define xp 24printf " esp: " 25output/x $esp 26echo ( 27output (((int)$ebp)-(int)$esp)/4-4 28printf " words on stack)\n ebp: " 29output/x $ebp 30printf "\n eip: " 31x/1i $eip 32printf "Saved ebp: " 33output/x *(int*)$ebp 34printf " (maximum of " 35output ((*(int*)$ebp)-(int)$ebp)/4-4 36printf " parameters possible)\nSaved eip: " 37x/1i *(int*)($ebp+4) 38printf "\nParm 1 at " 39output/x (int) ($ebp+8) 40printf ": " 41output (char*) *(int*)($ebp+8) 42printf "\nParm 2 at " 43output/x (int) ($ebp+12) 44printf ": " 45output (char*) *(int*)($ebp+12) 46printf "\nParm 3 at " 47output/x (int) ($ebp+16) 48printf ": " 49output (char*) *(int*)($ebp+16) 50printf "\nParm 4 at " 51output/x (int) ($ebp+20) 52printf ": " 53output (char*) *(int*)($ebp+20) 54echo \n 55end 56document xp 57Show the register contents and the first four parameter 58words of the current frame. 59end 60define xxp 61printf " esp: " 62output/x $esp 63printf "\n ebp: " 64output/x $ebp 65printf "\n eip: " 66x/1i $eip 67printf "Saved ebp: " 68output/x *(int*)$ebp 69printf " (maximum of " 70output ((*(int*)$ebp)-(int)$ebp)/4-4 71printf " parameters possible)\nSaved eip: " 72x/1i *(int*)($ebp+4) 73printf "\nParm 1 at " 74output/x (int) ($ebp+8) 75printf ": " 76output (char*) *(int*)($ebp+8) 77printf "\nParm 2 at " 78output/x (int) ($ebp+12) 79printf ": " 80output (char*) *(int*)($ebp+12) 81printf "\nParm 3 at " 82output/x (int) ($ebp+16) 83printf ": " 84output (char*) *(int*)($ebp+16) 85printf "\nParm 4 at " 86output/x (int) ($ebp+20) 87printf ": " 88output (char*) *(int*)($ebp+20) 89printf "\nParm 5 at " 90output/x (int) ($ebp+24) 91printf ": " 92output (char*) *(int*)($ebp+24) 93printf "\nParm 6 at " 94output/x (int) ($ebp+28) 95printf ": " 96output (char*) *(int*)($ebp+28) 97printf "\nParm 7 at " 98output/x (int) ($ebp+32) 99printf ": " 100output (char*) *(int*)($ebp+32) 101printf "\nParm 8 at " 102output/x (int) ($ebp+36) 103printf ": " 104output (char*) *(int*)($ebp+36) 105printf "\nParm 9 at " 106output/x (int) ($ebp+40) 107printf ": " 108output (char*) *(int*)($ebp+40) 109printf "\nParm 10 at " 110output/x (int) ($ebp+44) 111printf ": " 112output (char*) *(int*)($ebp+44) 113echo \n 114end 115document xxp 116Show the register contents and the first ten parameter 117words of the current frame. 118end 119define xp0 120x/12x *(int*)$esp 121p *(int*)$esp 122p (char*)*$esp 123end 124define xp1 125x/12x *(int*)($ebp+4) 126p *(int*)($ebp+4) 127p (char**)($ebp+4) 128end 129define xp2 130x/12x *(int*)($ebp+8) 131p *(int*)($ebp+8) 132p *(char**)($ebp+8) 133end 134define xp3 135x/12x *(int*)($ebp+12) 136p *(int*)($ebp+12) 137p (char**)($ebp+12) 138end 139define xp4 140x/12x *(int*)($ebp+16) 141p *(int*)($ebp+16) 142p (char**)($ebp+16) 143end 144document xp0 145Show the first parameter of current stack frame in various formats 146end 147document xp1 148Show the second parameter of current stack frame in various formats 149end 150document xp2 151Show the third parameter of current stack frame in various formats 152end 153document xp3 154Show the fourth parameter of current stack frame in various formats 155end 156document xp4 157Show the fifth parameter of current stack frame in various formats 158end 159define f0 160f 0 161xp 162end 163define f1 164f 1 165xp 166end 167define f2 168f 2 169xp 170end 171define f3 172f 3 173xp 174end 175define f4 176f 4 177xp 178end 179define f5 180f 5 181xp 182end 183document f0 184Select stack frame 0 and show assembler-level details 185end 186document f1 187Select stack frame 1 and show assembler-level details 188end 189document f2 190Select stack frame 2 and show assembler-level details 191end 192document f3 193Select stack frame 3 and show assembler-level details 194end 195document f4 196Select stack frame 4 and show assembler-level details 197end 198document f5 199Select stack frame 5 and show assembler-level details 200end 201document z 202Single step 1 instruction (over calls) and show next instruction. 203end 204document zs 205Single step 1 instruction (through calls) and show next instruction. 206end 207document xi 208List the next 10 instructions from the current IP value 209end 210document xs 211Show the last 12 words on stack in hex 212end 213document xb 214Show 12 words starting at current BP value in hex 215end 216define tr 217target remote /dev/cuaa1 218end 219document tr 220Attach to a remote kernel via /dev/cuaa0 221end 222set output-radix 16 223define pname 224p (char *)curproc->p_comm 225end 226document pname 227Print the command name of the current process 228end 229define bpp 230set $bp = (struct buf *) $arg0 231 if $bp->b_dev 232 printf " Buffer at 0x%x: dev 0x%x data 0x%x bcount 0x%x blkno 0x%x resid 0x%x\n", \ 233 $bp, \ 234 $bp->b_dev->si_udev, \ 235 $bp->b_data, \ 236 $bp->b_bcount, \ 237 $bp->b_bio->bio_blkno, \ 238 $bp->b_resid 239 else 240 printf " Buffer at 0x%x: dev (none) data 0x%x bcount 0x%x blkno 0x%x resid 0x%x\n", \ 241 $bp, \ 242 $bp->b_data, \ 243 $bp->b_bcount, \ 244 $bp->b_bio->bio_blkno, \ 245 $bp->b_resid 246 end 247 printf " flags 0x%x: ", $bp->b_flags 248 if $bp->b_flags & 0x10 249 printf "busy " 250 end 251 if $bp->b_flags & 0x40 252 printf "call " 253 end 254 if $bp->b_flags & 0x200 255 printf "done " 256 end 257 if $bp->b_flags & 0x800 258 printf "error " 259 end 260 if $bp->b_flags & 0x40000 261 printf "phys " 262 end 263 if $bp->b_flags & 0x100000 264 printf "read " 265 end 266 printf "\n" 267end 268define bpl 269set $bp = (struct buf *) $arg0 270printf "b_proc: " 271output $bp->b_proc 272printf "\nb_flags: " 273output $bp->b_flags 274printf "\nb_qindex: " 275output $bp->b_qindex 276printf "\nb_usecount: " 277output $bp->b_usecount 278printf "\nb_error: " 279output $bp->b_error 280printf "\nb_bufsize: " 281output $bp->b_bufsize 282printf "\nb_bcount: " 283output $bp->b_bcount 284printf "\nb_resid: " 285output $bp->b_resid 286printf "\nb_dev: " 287output $bp->b_dev 288printf "\nb_data: " 289output $bp->b_data 290printf "\nb_kvasize: " 291output $bp->b_kvasize 292printf "\nb_lblkno: " 293output $bp->b_lblkno 294printf "\nb_blkno: " 295output $bp->b_bio->bio_blkno 296printf "\nb_iodone: " 297output $bp->b_bio->bio_done 298printf "\nb_vp: " 299output $bp->b_vp 300printf "\nb_dirtyoff: " 301output $bp->b_dirtyoff 302printf "\nb_dirtyend: " 303output $bp->b_dirtyend 304printf "\nb_generation: " 305output $bp->b_generation 306printf "\nb_validoff: " 307output $bp->b_validoff 308printf "\nb_validend: " 309output $bp->b_validend 310printf "\nb_pblkno: " 311output $bp->b_pblkno 312printf "\nb_saveaddr: " 313output $bp->b_saveaddr 314printf "\nb_savekva: " 315output $bp->b_savekva 316printf "\nb_driver1: " 317output $bp->b_driver1 318printf "\nb_driver2: " 319output $bp->b_driver2 320printf "\nb_spc: " 321output $bp->b_spc 322printf "\nb_npages: " 323output $bp->b_npages 324printf "\n" 325end 326define bp 327bpp bp 328end 329define bpd 330 printf "Buffer data:\n%s", (char *) bp->b_data 331end 332document bpd 333Show the contents (char*) of bp->data in the current frame. 334end 335document bp 336Show information about the buffer header pointed to by the 337variable bp in the current frame. 338end 339document bpp 340Show summary information about the buffer header (struct bp) pointed 341at by the parameter. 342end 343document bpl 344Show detailled information about the buffer header (struct bp) pointed 345at by the parameter. 346end 347document bpl 348Show detailled information about the buffer header (struct bp) pointed 349at by the local variable bp. 350end 351define bx 352printf "\n b_vnbufs " 353output/x bp->b_vnbufs 354printf "\n b_freelist " 355output/x bp->b_freelist 356printf "\n b_act " 357output/x bp->b_act 358printf "\n b_flags " 359output/x bp->b_flags 360printf "\n b_qindex " 361output/x bp->b_qindex 362printf "\n b_usecount " 363output/x bp->b_usecount 364printf "\n b_error " 365output/x bp->b_error 366printf "\n b_bufsize " 367output/x bp->b_bufsize 368printf "\n b_bcount " 369output/x bp->b_bcount 370printf "\n b_resid " 371output/x bp->b_resid 372printf "\n b_dev " 373output/x bp->b_dev 374printf "\n b_data " 375output/x bp->b_data 376printf "\n b_kvasize " 377output/x bp->b_kvasize 378printf "\n b_blkno " 379output/x bp->b_bio->bio_blkno 380printf "\n b_vp " 381output/x bp->b_vp 382printf "\n b_dirtyoff " 383output/x bp->b_dirtyoff 384printf "\n b_validoff " 385output/x bp->b_validoff 386echo \n 387end 388define ddb 389set boothowto=0x80000000 390s 391end 392document ddb 393Switch back to ddb. 394end 395define ps 396 set $nproc = nprocs 397 set $aproc = allproc.lh_first 398 set $proc = allproc.lh_first 399 printf " pid proc addr uid ppid pgrp flag stat comm wchan\n" 400 while (--$nproc >= 0) 401 set $pptr = $proc.p_pptr 402 if ($pptr == 0) 403 set $pptr = $proc 404 end 405 if ($proc.p_stat) 406 printf "%5d %08x %08x %4d %5d %5d %06x %d %-10s ", \ 407 $proc.p_pid, $aproc, \ 408 $proc.p_addr, $proc.p_cred->p_ruid, $pptr->p_pid, \ 409 $proc.p_pgrp->pg_id, $proc.p_flag, $proc.p_stat, \ 410 &$proc.p_comm[0] 411 if ($proc.p_wchan) 412 if ($proc.p_wmesg) 413 printf "%s ", $proc.p_wmesg 414 end 415 printf "%x", $proc.p_wchan 416 end 417 printf "\n" 418 end 419 set $aproc = $proc.p_list.le_next 420 if ($aproc == 0 && $nproc > 0) 421 set $aproc = zombproc 422 end 423 set $proc = $aproc 424 end 425end 426document ps 427"ps" -- when kernel debugging, type out a ps-like listing of active processes. 428end 429define pcb 430 set $nproc = nprocs 431 set $aproc = allproc.lh_first 432 set $proc = allproc.lh_first 433 while (--$nproc >= 0) 434 set $pptr = $proc.p_pptr 435 if ($proc->p_pid == $arg0) 436 set $pcba = $pptr->p_addr->u_pcb 437 printf "ip: %08x sp: %08x bp: %08x bx: %08x\n", $pcba->pcb_eip, $pcba->pcb_esp, $pcba->pcb_ebp, $pcba->pcb_ebx 438 x/1i $pcba->pcb_eip 439 set $nproc = 0 440 end 441 set $aproc = $proc.p_list.le_next 442 if ($aproc == 0 && $nproc > 0) 443 set $aproc = zombproc 444 end 445 set $proc = $aproc 446 end 447end 448document pcb 449Show some pcb contents of process whose pid is specified. 450end 451define btr 452set $frame = $arg0 453set $fno = 0 454while (*(int *) $frame > 0xc0000000) 455 set $myebp = *(int *) $frame 456 set $myeip = *(int *) ($frame + 4) 457 printf " frame %d at %p: ebp %8x, eip ", $fno, $frame, $myebp 458 x/1i $myeip 459 set $frame = $myebp 460 set $fno = $fno + 1 461end 462end 463document btr 464Show a backtrace from the ebp address specified. This can be used to 465get a backtrace from any stack resident in memory. 466end 467define btp 468 set $nproc = nprocs 469 set $aproc = allproc.lh_first 470 set $proc = allproc.lh_first 471 while (--$nproc >= 0) 472 if ($proc->p_pid == $arg0) 473 btr $proc->p_addr->u_pcb->pcb_ebp 474 set $nproc = 0 475 else 476 set $aproc = $proc.p_list.le_next 477 if ($aproc == 0 && $nproc > 0) 478 set $aproc = zombproc 479 end 480 set $proc = $aproc 481 end 482 end 483end 484document btp 485Show a backtrace for the process whose pid is specified as a parameter. 486end 487define btpa 488 set $nproc = nprocs 489 set $aproc = allproc.lh_first 490 set $proc = allproc.lh_first 491 printf " pid proc addr uid ppid pgrp flag stat comm wchan\n" 492 while (--$nproc >= 0) 493 set $pptr = $proc.p_pptr 494 if ($pptr == 0) 495 set $pptr = $proc 496 end 497 if ($proc.p_stat) 498 printf "%5d %08x %08x %4d %5d %5d %06x %d %-10s ", \ 499 $proc.p_pid, $aproc, \ 500 $proc.p_addr, $proc.p_cred->p_ruid, $pptr->p_pid, \ 501 $proc.p_pgrp->pg_id, $proc.p_flag, $proc.p_stat, \ 502 &$proc.p_comm[0] 503 if ($proc.p_wchan) 504 if ($proc.p_wmesg) 505 printf "%s ", $proc.p_wmesg 506 end 507 printf "%x", $proc.p_wchan 508 end 509 printf "\n" 510 if ($proc->p_flag & 4) 511 btr $proc->p_addr->u_pcb->pcb_ebp 512 else 513 echo (not loaded)\n 514 end 515 end 516 set $aproc = $proc.p_list.le_next 517 if ($aproc == 0 && $nproc > 0) 518 set $aproc = zombproc 519 end 520 set $proc = $aproc 521 end 522end 523document btpa 524Show backtraces for all processes in the system. 525end 526define btpp 527 if ($myvectorproc->p_flag & 4) 528 btr $myvectorproc->p_addr->u_pcb->pcb_ebp 529 else 530 echo (not loaded)\n 531 end 532end 533document btpp 534Show a backtrace for the process previously selected with 'defproc'. 535end 536define defproc 537 set $nproc = nprocs 538 set $aproc = allproc.lh_first 539 set $proc = allproc.lh_first 540 while (--$nproc >= 0) 541 if ($proc->p_pid == $arg0) 542 set $pptr = $proc.p_pptr 543 if ($pptr == 0) 544 set $pptr = $proc 545 end 546 set $myvectorproc = $proc 547 if ($proc.p_stat) 548 printf "%5d %08x %08x %4d %5d %5d %06x %d %-10s ", \ 549 $proc.p_pid, $aproc, \ 550 $proc.p_addr, $proc.p_cred->p_ruid, $pptr->p_pid, \ 551 $proc.p_pgrp->pg_id, $proc.p_flag, $proc.p_stat, \ 552 &$proc.p_comm[0] 553 if ($proc.p_wchan) 554 if ($proc.p_wmesg) 555 printf "%s ", $proc.p_wmesg 556 end 557 printf "%x", $proc.p_wchan 558 end 559 printf "\n" 560 end 561 btpp 562 set $nproc = 0 563 else 564 set $proc = $proc.p_list.le_next 565 end 566 end 567end 568document defproc 569Specify a process for btpp and fr commands. 570end 571define fr 572set $fno = 0 573set $searching = 1 574if ($myvectorproc->p_flag & 4) 575 set $frame = $myvectorproc->p_addr->u_pcb->pcb_ebp 576 while (($searching == 1) && (*(int *) $frame > 0xc0000000)) 577 set $myebp = *(int *) $frame 578 set $myeip = *(int *) ($frame + 4) 579 if ($fno == $arg0) 580 printf " frame %d at %p: ebp %8x, eip ", $fno, $frame, $myebp 581 x/1i $myeip 582 printf "Called from %8x, stack frame at %8x\n", *(int *) ($myebp+4), *(int *) $myebp 583 printf "last 20 local variables:\n" 584 x/20x ($myebp-80) 585 printf "call parameters:\n" 586 x/8x ($myebp+8) 587 set $searching = 0 588 else 589 set $frame = $myebp 590 set $fno = $fno + 1 591 end 592 end 593 if ($searching == 1) 594 echo frame not found\n 595 end 596else 597 printf "process %d is not loaded in memory\n", $myvectorproc->p_pid 598end 599end 600document fr 601Show the frame of the stack of the process previously selected with 'defproc'. 602end 603set height 70 604set width 120 605define vdev 606if (vp->v_type == VBLK) 607 p *vp->v_un.vu_spec.vu_specinfo 608 printf "numoutput: %d\n", vp->v_numoutput 609else 610 echo "Not a block device" 611end 612end 613document vdev 614Show some information of the vnode pointed to by the local variable vp. 615end 616define y 617echo Check your .gdbinit, it contains a y command\n 618end 619define kldstat 620 set $file = files.tqh_first 621 printf "Id Refs Address Size Name\n" 622 while ($file != 0) 623 printf "%2d %4d 0x%8x %8x %s\n", \ 624 $file->id, \ 625 $file->refs, \ 626 $file->address, \ 627 $file->size, \ 628 $file->filename 629 set $file = $file->link.tqe_next 630 end 631end 632document kldstat 633Equivalent of the kldstat(9) command, without options. 634end 635define msgbuf 636printf "%s", msgbufp->msg_ptr 637end 638document msgbuf 639Print the system message buffer (dmesg). This can take a long time due to the time it takes to transmit the data across a serial line. 640end 641