• Save
Lecture 6 Kernel Debugging + Ports Development
Upcoming SlideShare
Loading in...5
×
 

Lecture 6 Kernel Debugging + Ports Development

on

  • 3,411 views

[ArabBSD] .. Lecture 6 Kernel Debugging + Ports Development

[ArabBSD] .. Lecture 6 Kernel Debugging + Ports Development

Statistics

Views

Total Views
3,411
Views on SlideShare
3,339
Embed Views
72

Actions

Likes
0
Downloads
24
Comments
0

2 Embeds 72

http://mj89sp3sau2k7lj1eg3k40hkeppguj6j-a-sites-opensocial.googleusercontent.com 71
http://127.0.0.1:800 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Lecture 6 Kernel Debugging + Ports Development Lecture 6 Kernel Debugging + Ports Development Presentation Transcript

  •  FreeBSD Kernel Debugging Port Development
  • gdb KdgbDTrace Valgrind ktrace ktr Kernel Userland Space
  • KernelDebugging Tracking
  •  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.
  • CommonStrategies Kernel Crash Kernel Hang
  • ● dumpon(8) and savecore(8) – /etc/rc.conf● [syrinx@tweety]/(76)% cat /etc/rc.conf | grep dump● dumpdev="/dev/ad4s4b"● dumpdir="/var/crash/"● Remote systems● options DDB_UNATTENDED● Virtual machines - Pros and cons – Qemu – VirtualBox
  • ● Kernel configurationmakeoptions DEBUG=-g #memguard(9) and redzone(9) options DEBUG_MEMGUARD#ktrace(1) options DEBUG_REDZONEoptions KTRACE #ktr(4)options KDB options KTRoptions KDB_TRACE options ALQoptions DDB options ALQ_KTRoptions GBD options KTR_ENTRIES=4096 options KTR_COMPILE=KTR_INEToptions INVARIANTS options KTR_MASK=KTR_INEToptions INVARIANT_SUPPORT options KTR_CPUMASK=0x3options WITNESSoptions WITNESS_SKIPSPINoptions LOCK_PROFILING
  • ● 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
  • ddb(8) kgmon(8)kgdb(1) pmcstat(1)ktr(4) hwpmc(4)ktr(9) addr2line(1)ktrdump(8) kldstat(8)ktrace(1) fstat(1)kdump(1) iostat(8)dmesg(8) ipcs(1)objdump(1) ipmi(9)size(1) netstat(1)savecore(8) ps(1)dumpon(8) vmstat(8)textdump(8) redzone(9)hexdump(1) memguard(9) truss(1)
  • ● 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) ...
  •  ktrace -d -i -p 0 kdump –f ktrace.out >>myfile.txt
  • 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
  •  http://www.FreeBSD.org/doc/en_US.ISO8859 -1/articles/contributing/contrib- how.html#CONTRIB-GENERAL http://www.FreeBSD.org/cgi/query-pr- summary.cgi?category=ports