gdb KdgbDTrace Valgrind ktrace ktr Kernel Userland Space
The process that takes a control of execution of another process and make step over of code to view the process execution, show relation between consecutive processes. Debugging mainly used to detect error or bugs.
● If kernel dies, display driver dies too● Do not panic the system while fsck (8) is running● [syrinx@tweety]/(78)% cat /etc/rc.conf | grep fsck● fsck_y_enable="YES"● background_fsck="NO"● Core dumps may contain sensitive information● # boot -s● # dumpon /dev/ad4s4b● # mount -a -art ufs● # /command-to-crash-the-kernel
● Kernel crashes usually require straighforward approach● kgdb(1) is an extention of gdb(1) that understands FreeBSD kernel corefiles● Symbol resolving● Scripting support● On-line debugging via /dev/mem● Remote debugging – via serial line – via firewire
[syrinx@tweety]/home/syrinx(92)% sudo kgdb /boot/kernel.old/kernel /var/crash/vmcore.1GNU gdb 6.1.1 [FreeBSD]Copyright 2004 Free Software Foundation, Inc.Unread portion of the kernel message buffer:rum0: could not multi read MAC register: USB_ERR_NOT_CONFIGUREDFatal trap 12: page fault while in kernel modecpuid = 1; apic id = 01fault virtual address = 0x0fault code = supervisor read, page not presentinstruction pointer = 0x20:0xc069bf24stack pointer = 0x28:0xe6b40c44frame pointer = 0x28:0xe6b40c60code segment = base 0x0, limit 0xfffff, type 0x1b = DPL 0, pres 1, def32 1, gran 1processor eflags = interrupt enabled, resume, IOPL = 0current process = 0 (rum0 taskq)panic: from debugger
● NULL Pointer Dereference● Resource leak● Bad test condition, resulting in code path never executed● Use before test (NULL/-1)● Use after free● Buffer overflow● Unsafe use of returned value● Uninitialized value read● Type and allocation size mismatch
● ddb(4) – interactive kernel ● Inspecting locks with ddb debugger ● db> show lock [lockaddr]● Poor symbol resolving ● db> show turnstile [lockaddr] compared to kgdb(1) ● # mutexes● Extensible – new commands ● db> show lockchain added at compile time - ● # six locks, sleepqueues● Sources at src/sys/ddb ● db> show sleepchain● Scripting support since FreeBSD 7.1 – ddb(8) ● More info in manual page.● Enter DDB● #sysctl debug.kdb.enter=1
Examination of CPU registers, variables, etc. Stepping over the instructions code to view the process execution.
ps shows selected fields from the process structures. With an understanding of the structures, it can give a good idea of whats going on. top is like a repetitive ps: it shows the most active processes at regular intervals. vmstat shows a number of parameters, including virtual memory. It can also be set up to run at regular intervals.
iostat is similar to vmstat, and it duplicates some fields, but it concentrates more on I/O activity. netstat show network information. It can also be set up to show transfer rates for specific interfaces. systat is a curses-based program which displays a large number of parameters, including most of the parameters displayed by vmstat, iostat and netstat.
[syrinx@tweety]/home/syrinx(71)% sysctl debug.ktrdebug.ktr.alq_enable: 0debug.ktr.alq_file: /tmp/ktr.outdebug.ktr.alq_depth: 1024debug.ktr.alq_failed: 0debug.ktr.alq_cnt: 0debug.ktr.alq_max: 0debug.ktr.clear: 0debug.ktr.version: 2debug.ktr.entries: 1024debug.ktr.compile: 270540806debug.ktr.mask: 270540806debug.ktr.cpumask: 3● KTR buffer accessible in DDBdb> show ktr [v]● read the contents of a ktr(4) file[syrinx@tweety]/(105)% sudo ktrdump -t -o /tmp/ktr.out
● Kernel process tracing● [syrinx@tweety]/home/syrinx(89)% ktrace -a -tcy -f /home/syrinx/krtace.out ifconfig● kdump(1) displays the kernel trace data● [syrinx@tweety]/home/syrinx(91)% kdump -f ~/krtace.out ... 7490 ifconfig CALL write(0x1,0x28203000,0x38) 7490 ifconfig GIO fd 1 wrote 56 bytes options=23<PERFORMNUD,ACCEPT_RTADV,AUTO_LINKLOCAL> 7490 ifconfig RET write 56/0x38 7490 ifconfig CALL ioctl(0x3,SIOCGIFMAC,0xbfbfdfac) 7490 ifconfig RET ioctl -1 errno 22 Invalid argument 7490 ifconfig CALL ioctl(0x3,SIOCGIFMEDIA,0xbfbfdfa0) ...
1. Writing the Makefile.2. Writing the description files.3. Creating the checksum file4. Testing the port5. Checking your port with portlint6. Submitting the port.
# New ports collection makefile for: oneko# Date created: 5 December 1994# Whom: asami## $FreeBSD$#PORTNAME= onekoPORTVERSION= 1.1bCATEGORIES= gamesMASTER_SITES= ftp://ftp.cs.columbia.edu/archives/X11R5/contrib/MAINTAINER= asami@FreeBSD.orgCOMMENT= A cat chasing a mouse all over the screenMAN1= oneko.1MANCOMPRESSED= yesUSE_IMAKE= yes.include <bsd.port.mk>
pkg-descr pkg-plist Refer to the pkg_create(1) manual page for details on the packing list.
This is a longer description of the port. One to a few paragraphs concisely explaining what the port does is sufficient. Example This is a port of oneko, in which a cat chases a poor mouse all over the screen. : (etc.) WWW: http://www.oneko.org/
This file lists all the files installed by the port. Also called the “packing list” because the package is generated by packing the files listed here. The pathnames are relative to the installation prefix (usually /usr/local or /usr/X11R6). If you are using the MANn variables (as you should be), do not list any manpages here. If the port creates directories during installation, make sure to add @dirrm lines to remove them when the package is deleted. Example: bin/oneko lib/X11/app-defaults/Oneko lib/X11/oneko/cat1.xpm lib/X11/oneko/cat2.xpm lib/X11/oneko/mouse.xpm @dirrm lib/X11/oneko
Type make makesum. The ports make rules will automatically generate the file distinfo.
pkg-plist does not contain anything not installed by your port pkg-plist contains everything that is installed by your port Your port can be installed multiple times using the reinstall target Your port cleans up after itself upon deinstall
1. make install2. make package3. make deinstall4. pkg_add package-name5. make deinstall6. make reinstall7. make package