*** empty log message ***
[arla.git] / doc / debugging.texi
blobe62d3ecbed5871b51a78169c4d510c633769ed4d
1 @c Copyright (c) 1998 - 2000 Kungliga Tekniska Högskolan
2 @c (Royal Institute of Technology, Stockholm, Sweden).
3 @c All rights reserved.
5 @c $Id$
7 @node Debugging, Arlad, Parts of Arla, Top
8 @chapter Debugging
10 @cindex Debugging
12 This chapter of the manual includes tips that are useful when debugging
13 arla. 
15 Arla and nnpfs contains logging facilities that is quite useful when
16 debugging when something goes wrong. This and some kernel debugging tips
17 are described.
19 @menu
20 * Arlad::  
21 * Debugging LWP with GDB::
22 * nnpfs::
23 * nnpfs on linux::
24 * Debugging techniques::
25 * Kernel debuggers::
26 * Darwin/MacOS X::
27 @end menu
29 @node Arlad, Debugging LWP with GDB, Debugging, Debugging
30 @comment  node-name,  next,  previous,  up
31 @section Arlad
33 @cindex Arlad debugging
34 @cindex Debugging arlad
36 If arlad is run without any arguments arlad will fork(2) and log to
37 syslog(3). To disable forking use the --no-fork (-n) switch. In the
38 current state of the code, arlad is allways to be started with
39 the recover (-z) switch. This will invalidate your cache at startup.
40 This restriction may be dropped in the future.
42 To enable more debuggning run arla with the switch --debug=module1,module2,...
43 One useful combination is 
44 @example 
45    --debug=all,-cleaner 
46 @end example 
47 The cleaner output is usully not that intresting and can be ignored.
49 A convenient way to debug arlad is to start it inside gdb.
50 @example
51 datan:~# gdb /usr/arla/libexec/arlad
52 (gdb) run -z -n
53 @end example
54 This gives you the opportunity to examine a crashed arlad.
55 @example
56 (gdb) bt
57 @end example
58 The arla team appreciates cut and paste information from
59 the beginning to the end of the bt output from such a gdb run.
61 To set the debugging with a running arlad use @code{fs arladeb} as root.
63 @example
64 datan:~# fs arladeb
65 arladebug is: none
66 datan:~# fs arladeb almost-all
67 datan:~#
68 @end example
70 By default, arlad logs through syslog if running as a daemon and to
71 stderr when running in the foreground (with @kbd{--no-fork}).
73 @node Debugging LWP with GDB, nnpfs, Arlad, Debugging
74 @comment  node-name,  next,  previous,  up
75 @section Debugging LWP with GDB
77 @cindex Gdb
79 For easy tracing of threads we have patch
80 (@url{http://www.stacken.kth.se/projekt/arla/gdb-4.18-backfrom.diff})
81 for gdb 4.18 (a new command) and a gdb sequence (think script).
83 The sequence only works for i386, but its just matter of choosing
84 different offset in topstack to find $fp and $pc in the lwp_ps_internal
85 part of the sequence.
87 You should copy the @file{.gdbinit} (that you can find in the arlad
88 directory in the source-code) to your home-directory, the directory from
89 where you startat the patched gdb or use flag -x to gdb.
91 Your debugging session might look like this:
93 @example
94 (gdb) lwp_ps
95 Runnable[0]
96  name: IO MANAGER
97   eventlist:
98   fp: 0x806aac4
99   pc: 0x806aac4
100  name: producer
101   eventlist: 8048b00
102   fp: 0x8083b40
103   pc: 0x8083b40
104 Runnable[1]
105 [...]
106 (gdb) help backfrom
107 Print backtrace of FRAMEPOINTER and PROGRAMCOUNTER.
109 (gdb) backfrom 0x8083b40 0x8083b40
110 #0  0x8083b40 in ?? ()
111 #1  0x8049e2f in LWP_MwaitProcess (wcount=1, evlist=0x8083b70)
112     at /afs/e.kth.se/home/staff/lha/src/cvs/arla-foo/lwp/lwp.c:567
113 #2  0x8049eaf in LWP_WaitProcess (event=0x8048b00)
114     at /afs/e.kth.se/home/staff/lha/src/cvs/arla-foo/lwp/lwp.c:585
115 #3  0x8048b12 in Producer (foo=0x0)
116     at /afs/e.kth.se/home/staff/lha/src/cvs/arla-foo/lwp/testlwp.c:76
117 #4  0x804a00c in Create_Process_Part2 ()
118     at /afs/e.kth.se/home/staff/lha/src/cvs/arla-foo/lwp/lwp.c:629
119 #5  0xfffefdfc in ?? ()
120 #6  0x8051980 in ?? ()
121 @end example
123 There also the possibility to run arla with pthreads (run configure with
124 --with-pthreads).
126 @node nnpfs, nnpfs on linux, Debugging LWP with GDB, Debugging
127 @comment  node-name,  next,  previous,  up
128 @section nnpfs
130 @cindex Debugging NNPFS
131 @cindex NNPFS debugging
133 NNPFS debugging does almost look the same on all platforms. They
134 all share same debugging flags, but not all are enabled on all
135 platforms.
137 Change the debugging with the @kbd{fs nnpfsdebug} command.
139 @example
140 datan:~# fs nnpfsdebug
141 nnpfsdebug is: none
142 datan:~# fs nnpfsdebug almost-all
143 datan:~#
144 @end example
146 If it crashes before you have an opportunity to set the debug level, you
147 will have to edit @file{nnpfs/@var{your-os}/nnpfs_deb.c} and recompile.
149 The logging of nnpfs ends up in your syslog. Syslog usully logs to /var/log
150 or /var/adm (look in /etc/syslog.conf).
152 @node nnpfs on linux, Debugging techniques, nnpfs, Debugging
153 @comment  node-name,  next,  previous,  up
154 @section nnpfs on linux
156 There is a problem with klogd, it's too slow. Cat the @file{/proc/kmsg}
157 file instead.  Remember to kill klogd, since the reader will delete the
158 text from the ring-bufer, and you will only get some of the message in
159 your cat.
162 @node Debugging techniques, Kernel debuggers, nnpfs on linux, Debugging
163 @comment  node-name,  next,  previous,  up
164 @section Debugging techniques
166 @cindex Debugging techniques
168 Kernel debugging can sometimes force you to exercise your
169 imagination. We have learned some different techniques that can be
170 useful.
172 @subsection Signals
174 On operatingsystems with kernel debugger that you can use probably find
175 where in the kernel a user-program live, and thus deadlocks or trigger
176 the bad event, that later will result in a bug. This is a problem, how
177 do you some a process to find where it did the intresting thing when you
178 can't set a kernel breakpoint ?
180 One way to be notified is to send a signal from the kernel module
181 (psignal() on a BSD and force_sig() on linux). SIGABRT() is quite useful
182 if you want to force a coredump. If you want to continue debugging,
183 use SIGSTOP.
185 @subsection Recreateable testcases
187 Make sure bugs don't get reintroduced.
189 @node Kernel debuggers, Darwin/MacOS X, Debugging techniques, Debugging
190 @comment  node-name,  next,  previous,  up
191 @section Kernel debuggers
193 @cindex Kernel debugging
195 Kernel debuggers are the most useful tool when you are trying to figure
196 out what's wrong with nnpfs. Unfortunately they also seem to have their
197 own life and do not always behave as expected.
199 @subsection Using GDB
201 Kernel debugging on NetBSD, OpenBSD, FreeBSD and Darwin are almost the
202 same.  You get the idea from the NetBSD example below:
204 @example
205   (gdb) file netbsd.N
206   (gdb) target kcore netbsd.N.core
207   (gdb) symbol-file /sys/arch/i386/compile/NUTCRACKER/netbsd.gdb
208 @end example
210 This example loads the kernel symbols into gdb. But this doesn't show
211 the nnpfs symbols, and that makes your life harder.
213 @subsection Getting all symbols loaded at the same time
215 If you want to use the symbols of nnpfs, there is a gdb command called
216 @samp{add-symbol-file} that is useful. The symbol file is obtained by
217 loading the kernel module nnpfs with @samp{kmodload -o /tmp/nnpfs-sym}
218 (Darwin) or @samp{modload} (NetBSD and OpenBSD).  FreeBSD has a linker
219 in the kernel that does the linking instead of relying on @samp{ld}. The
220 symbol address where the module is loaded get be gotten from
221 @samp{modstat}, @samp{kldstat} or @samp{kmodstat} (it's in the
222 @code{area} field).
224 If you forgot the to run modstat/kldstat/kmodstat, you can extract the
225 information from the kernel. In Darwin you look at the variable kmod
226 (you might have to case it to a (kmod_info_t *). We have seen gdb lose
227 the debugging info). kmod is the start of a linked list. Other BSDs have
228 some variant of this.
230 You should also source the commands in /sys/gdbscripts (NetBSD), or
231 System/xnu/osfmk/.gdbinit (Darwin) to get commands like ps inside gdb.
233 @example
234   datan:~# modstat Type Id Off Loadaddr Size Info Rev Module
235   Name DEV 0 29 ce37f000 002c ce388fc0 1 nnpfs_mod [...]
236   [...]
237   (gdb) add-symbol-table nnpfs.sym ce37f000
238 @end example
240 @subsection Debugging processes, examine their stack, etc
242 One of differences between the BSD's are the @code{proc}, a command that
243 enables you do to a backtrace on all processes. On FreeBSD you give the
244 @code{proc} command a @samp{pid}, but on NetBSD and OpenBSD you give a
245 pointer to a @code{struct proc}.
247 After you have ran @code{proc} to set the current process, you can
248 examine the backtrace with the regular @code{backtrace} command.
250 Darwin does't have a @code{proc} command. Instead you are supposed to
251 use gdb sequences (System/xnu/osfmk/.gdbinit) to print process stacks,
252 threads, activations, and other information.
254 @subsection Debugging Linux
256 @cindex Kernel debuging on linux
257 @cindex Linux kernel debugging 
259 You can't get a crashdump for linux with patching the kernel. There are
260 two projects have support for this. Mission Critical Linux
261 @url{http://www.missioncritiallinux.com} and SGI
262 @url{http://oss.sgi.com/}.
264 Remember save the context of /proc/ksyms before you crash, since this is
265 needed to figure out where the nnpfs symbols are located in the kernel.
267 But you can still use the debugger (or objdump) to figure out where in
268 the binary that you crashed.
270 @cindex Ksymoops
272 @code{ksymoops} can be used to create a backtrace. 
274 @subsection Using adb
276 @cindex adb
278 Adb is not a symbolic debugger, this means that you have to read the
279 disassembled object-code to figure out where it made the wrong turn and
280 died. You might be able to use GNU objdump to list the assembler and
281 source-code intertwined (@samp{objdump -S -d mod_nnpfs.o}). Remember that
282 GNU binutils for sparc-v9 isn't that good yet.
284 You can find the script that use use for the adb command @samp{$<} in
285 @file{/usr/lib/adb} and @file{/usr/platform/PLATFORNAME/adb}.
287 @subsection Debugging a live kernel
289 @cindex Live kernel
291 An important thing to know is that you can debug a live kernel too, this
292 can be useful to find dead-locks. To attach to a kernel you use a
293 command like this on a BSD  system (that is using gdb):
295 @example
296   (gdb) file /netbsd
297   (gdb) target kcore /dev/mem
298   (gdb) symbol-file /sys/arch/i386/compile/NUTCRACKER/netbsd.gdb
299 @end example
301 And on Solaris:
303 @example
304   # adb -k /dev/ksyms /dev/mem
305 @end example
308 @subsection Other useful debugging tools
310 Most diagnosics tools like ps, dmesg, and pstat on BSD systems used to
311 look in kernel memory to extract information (and thus earned the name
312 kmem-groovlers). On some systems they have been replaced with other
313 method of getting their data, like /proc and sysctl. 
315 But due to their heritage they can still be used in with a kernel and
316 coredump to extract information on some system.
318 @node Darwin/MacOS X, Porting, Kernel debuggers, Debugging
319 @comment  node-name,  next,  previous,  up
320 @section Darwin/MacOS X
322 You'll need two computers to debug arlad/nnpfs on darwin since the common
323 way to debug is to use a remote kernel-debugger over IP/UDP.
325 First you need to publish the arp-address of the computer that you are
326 going to crash.
328 We have not found any kernel symbols in MacOSX Public Beta, so you
329 should probably build your own kernel. Use Darwin xnu kernel source
330 with cvs-tag: Apple-103-0-1 (not xnu-103).
332 @example
333 gdb nnpfs.out
334 target remote-kdp
335 add-symbol-table ...
336 attach <host>
337 @end example