1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type">
<title>A debugging session</title>
</head>
<body alink="#FF0000" vlink="#55188A" link="#0000EF" bgcolor="#FFFFFF" text="#000099">
<table border="0">
<tr align="left">
<td valign="top">
<table border="0">
<tr align="left"><td valign="top" >
<img width="120" height="171" src="uml-small.png">
</td></tr>
<tr align="left"><td valign="top" bgcolor="#e0e0e0">
<font size="-1"><a href="index.html">Site Home Page</a></font>
<br>
<font size="-1"><a href="uses.html">What it's good for</a></font>
<br>
<font size="-1"><a href="case-studies.html">Case Studies</a></font>
<br>
<font size="-1"><a href="kernel.html">Kernel Capabilities</a></font>
<br>
<font size="-1"><a href="dl-sf.html">Downloading it</a></font>
<br>
<font size="-1"><a href="run.html">Running it</a></font>
<br>
<font size="-1"><a href="compile.html">Compiling</a></font>
<br>
<font size="-1"><a href="install.html">Installation</a></font>
<br>
<font size="-1"><a href="fs_making.html">Building filesystems</a></font>
<br>
<font size="-1"><a href="faq.html">Troubles</a></font>
<br>
<font size="-1"><a href="contrib.html">User Contributions</a></font>
<br>
<font size="-1"><a href="links.html">Related Links</a></font>
<br>
<font size="-1"><a href="todo.html">The ToDo list</a></font>
<br>
<font size="-1"><a href="projects.html">Projects</a></font>
<br>
<font size="-1"><a href="diary.html">Diary</a></font>
<br>
<font size="-1"><a href="thanks.html">Thanks</a></font>
<br>
<font size="-1"><a href="contacts.html">Contacts</a></font>
</td></tr>
<tr align="left"><td valign="top" bgcolor="#e0e0e0">Tutorials<br>
<font size="-1"><a href="UserModeLinux-HOWTO.html">The HOWTO (html)</a></font>
<br>
<font size="-1"><a href="UserModeLinux-HOWTO.txt">The HOWTO (text)</a></font>
<br>
<font size="-1"><a href="hostfs.html">Host file access</a></font>
<br>
<font size="-1"><a href="input.html">Device inputs</a></font>
<br>
<font size="-1"><a href="shared_fs.html">Sharing filesystems</a></font>
<br>
<font size="-1"><a href="fs.html">Creating filesystems</a></font>
<br>
<font size="-1"><a href="networking.html">Virtual Networking</a></font>
<br>
<font size="-1"><a href="mconsole.html">Management Console</a></font>
<br>
<font size="-1"><a href="debugging.html">Kernel Debugging</a></font>
<br>
<font size="-1"><a href="gprof.html">gprof and gcov</a></font>
<br>
<font size="-1"><a href="xtut.html">Running X</a></font>
<br>
<font size="-1"><a href="trouble.html">Diagnosing problems</a></font>
<br>
<font size="-1"><a href="config.html">Configuration</a></font>
<br>
<font size="-1"><a href="slack_readme.html">Installing Slackware</a></font>
<br>
<font size="-1"><a href="arch-port.html">Porting UML</a></font>
<br>
<font size="-1"><a href="iomem.html">IO memory emulation</a></font>
<br>
<font size="-1"><a href="2G-2G.html">UML on 2G/2G hosts</a></font>
<br>
<font size="-1"><a href="lksct/index.html">Adding a UML system call</a></font>
</td></tr>
<tr align="left"><td valign="top" bgcolor="#e0e0e0">How you can help<br>
<font size="-1"><a href="help-gen.html">Overview</a></font>
<br>
<font size="-1"><a href="help-doc.html">Documentation</a></font>
<br>
<font size="-1"><a href="help-userspace.html">Utilities</a></font>
<br>
<font size="-1"><a href="help-kernel-v1.html">Kernel bugs</a></font>
<br>
<font size="-1"><a href="projects.html">Kernel projects</a></font>
</td></tr>
<tr align="left"><td valign="top" bgcolor="#e0e0e0">Screenshots<br>
<font size="-1"><a href="net.html">A virtual network</a></font>
<br>
<font size="-1"><a href="x.html">An X session</a></font>
</td></tr>
<tr align="left"><td valign="top" bgcolor="#e0e0e0">Transcripts<br>
<font size="-1"><a href="login.html">A login session</a></font>
<br>
<font size="-1"><a href="debug-session.html">A debugging session</a></font>
<br>
<font size="-1"><a href="slackinst.html">Slackware installation</a></font>
</td></tr>
<tr align="left"><td valign="top" bgcolor="#e0e0e0">Reference<br>
<font size="-1"><a href="switches.html">Kernel switches</a></font>
<br>
<font size="-1"><a href="slack_readme.html">Slackware README</a></font>
</td></tr>
<tr align="left"><td valign="top" bgcolor="#e0e0e0">Papers<br>
<font size="-1"><a href="als2000/index.html">ALS 2000 paper (html)</a></font>
<br>
<font size="-1"><a href="als2000.tex">ALS 2000 paper (TeX)</a></font>
<br>
<font size="-1"><a href="slides/als2000/slides.html">ALS 2000 slides</a></font>
<br>
<font size="-1"><a href="slides/lca2001/lca.html">LCA 2001 slides</a></font>
<br>
<font size="-1"><a href="slides/ols2001/index.html">OLS 2001 paper (html)</a></font>
<br>
<font size="-1"><a href="ols2001.tex">OLS 2001 paper (TeX)</a></font>
<br>
<font size="-1"><a href="als2001/index.html">ALS 2001 paper (html)</a></font>
<br>
<font size="-1"><a href="als2001.tex">ALS 2001 paper (TeX)</a></font>
<br>
<font size="-1"><a href="slides/ists2002/umlsec.htm">UML security (html)</a></font>
<br>
<font size="-1"><a href="slides/lca2002/lca2002.htm">LCA 2002 (html)</a></font>
<br>
<font size="-1"><a href="slides/wvu2002/wvu2002.htm">WVU 2002 (html)</a></font>
</td></tr>
<tr align="left"><td valign="top" bgcolor="#e0e0e0">Fun and Games<br>
<font size="-1"><a href="http://user-mode-linux.sourceforge.net/cgi-bin/hangman">Kernel Hangman</a></font>
<br>
<font size="-1"><a href="sdotm.html">Disaster of the Month</a></font>
</td></tr>
</table>
</td>
<td valign="top" align="left">
<center>
<h3>A debugging session</h3>
</center>
The following is the beginning of a gdb session with the kernel under
gdb from the beginning. It starts at the top of start_kernel() and
goes one line at a time through the initial kernel startup.
<tt>
<pre>
<font size="-1">
GNU gdb 4.17.0.11 with Linux support
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux"...
(gdb) <font color="#880000">att 1</font>
Attaching to program `/home/dike/linux/2.3.26/um/linux', Pid 1
0x1009f791 in __kill ()
(gdb) <font color="#880000">b start_kernel</font>
Breakpoint 1 at 0x100ddf83: file init/main.c, line 515.
(gdb) <font color="#880000">c</font>
Continuing.
Breakpoint 1, start_kernel () at init/main.c:515
515 printk(linux_banner);
(gdb) <font color="#880000">n</font>
516 setup_arch(&command_line);
(gdb)
517 printk("Kernel command line: %s\n", saved_command_line);
(gdb)
518 parse_options(command_line);
(gdb)
519 trap_init();
(gdb)
520 init_IRQ();
(gdb)
521 sched_init();
(gdb)
522 time_init();
(gdb)
523 softirq_init();
(gdb)
530 console_init();
</font>
</pre>
</tt>
This is tiring, so I just let it continue booting.
<tt>
<pre>
<font size="-1">
(gdb) <font color="#880000">c</font>
Continuing.
</font>
</pre>
</tt>
It's booted, so I ^C it to see what it thinks is up.
<tt>
<pre>
<font size="-1">
Program received signal SIGINT, Interrupt.
0x100a4bc1 in __libc_nanosleep ()
(gdb) <font color="#880000">bt</font>
#0 0x100a4bc1 in __libc_nanosleep ()
#1 0x100a4b7d in __sleep (seconds=10) at ../sysdeps/unix/sysv/linux/sleep.c:78
#2 0x10095fbf in do_idle () at process_kern.c:424
#3 0x10096052 in cpu_idle () at process_kern.c:450
#4 0x100de0a4 in start_kernel () at init/main.c:593
#5 0x10098df2 in start_kernel_proc (unused=0x0) at um_arch.c:72
#6 0x1009858f in signal_tramp (arg=0x10098db8) at trap_user.c:50
(gdb)
</font>
</pre>
</tt>
It's busy sleeping in the idle loop. I'll set a breakpoint in the
scheduler and pick it up on the next context switch.
<tt>
<pre>
<font size="-1">
(gdb) <font color="#880000">b schedule</font>
Breakpoint 2 at 0x10004acd: file sched.c, line 496.
(gdb) <font color="#880000">c</font>
Continuing.
Breakpoint 2, schedule () at sched.c:496
496 if (!current->active_mm) BUG();
(gdb) <font color="#880000">bt</font>
#0 schedule () at sched.c:496
#1 0x10095fb3 in do_idle () at process_kern.c:421
#2 0x10096052 in cpu_idle () at process_kern.c:450
#3 0x100de0a4 in start_kernel () at init/main.c:593
#4 0x10098df2 in start_kernel_proc (unused=0x0) at um_arch.c:72
#5 0x1009858f in signal_tramp (arg=0x10098db8) at trap_user.c:50
</font>
</pre>
</tt>
Here we are in the scheduler. I'll 'next' through the first few lines
of the scheduler, get bored, and set a breakpoint in the SIGIO
interrupt handler.
<tt>
<pre>
<font size="-1">
(gdb) <font color="#880000">n</font>
497 if (tq_scheduler)
(gdb)
501 prev = current;
(gdb)
502 this_cpu = prev->processor;
(gdb)
504 if (in_interrupt())
(gdb)
510 if (softirq_state[this_cpu].active & softirq_state[this_cpu].mask)
(gdb)
518 sched_data = & aligned_data[this_cpu].schedule_data;
(gdb)
520 spin_lock_irq(&runqueue_lock);
(gdb) <font color="#880000">b sigio_handler</font>
Breakpoint 3 at 0x10094fdc: file irq_user.c, line 36.
(gdb) <font color="#880000">c</font>
Continuing.
Breakpoint 2, schedule () at sched.c:496
496 if (!current->active_mm) BUG();
</font>
</pre>
</tt>
Oops, that process scheduled back to the idle thread. Get rid of that
breakpoint and continue again.
<tt>
<pre>
<font size="-1">
(gdb) <font color="#880000">d 2</font>
(gdb) <font color="#880000">c</font>
</font>
</pre>
</tt>
Well, the SIGIO handler is waiting for something and nothing is
happening by itself. So, I'll type something at one of the login
prompts to wake it up.
<tt>
<pre>
<font size="-1">
Breakpoint 3, sigio_handler (sig=29) at irq_user.c:36
36 user_mode = set_user_thread(NULL, 0, 0);
</font>
</pre>
</tt>
That did the trick. I'll climb down the call chain into the actual
driver interrupt handler, starting with a breakpoint in do_IRQ.
<tt>
<pre>
<font size="-1">
(gdb) <font color="#880000">l</font>
31 struct irq_fd *irq_fd;
32 struct timeval tv;
33 fd_set fds;
34 int i, n, user_mode;
35
36 user_mode = set_user_thread(NULL, 0, 0);
37 if(user_mode){
38 fill_in_regs(process_state(NULL, NULL, NULL), &sig + 1);
39 change_sig(SIGUSR1, 1);
40 }
(gdb) <font color="#880000">l</font>
41 fds = active_fd_mask;
42 tv.tv_sec = 0;
43 tv.tv_usec = 0;
44 if((n = select(max_fd + 1, &fds, NULL, NULL, &tv)) < 0){
45 printk("sigio_handler : select returned %d, "
46 "errno = %d\n", n, errno);
47 return;
48 }
49 for(i=0;i<=max_fd;i++){
50 if(FD_ISSET(i, &fds)) FD_CLR(i, &active_fd_mask);
(gdb) <font color="#880000">l</font>
51 }
52 for(irq_fd=active_fds;irq_fd != NULL;irq_fd = irq_fd->next){
53 if(FD_ISSET(irq_fd->fd, &fds)) do_IRQ(irq_fd->irq, user_mode);
54 }
55 if(user_mode){
56 interrupt_end();
57 change_sig(SIGUSR1, 0);
58 }
59 set_user_thread(NULL, user_mode, 0);
60 }
(gdb) <font color="#880000">b do_IRQ</font>
Breakpoint 4 at 0x10094960: file irq.c, line 266.
(gdb) <font color="#880000">c</font>
Continuing.
</font>
</pre>
</tt>
From here, I'll go into handle_IRQ_event.
<tt>
<pre>
<font size="-1">
Breakpoint 4, do_IRQ (irq=2, user_mode=0) at irq.c:266
266 irq_desc_t *desc = irq_desc + irq;
(gdb) <font color="#880000">n</font>
271 regs.user_mode = user_mode;
(gdb)
272 kstat.irqs[cpu][irq]++;
(gdb)
274 desc->handler->ack(irq);
(gdb)
279 status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
(gdb)
280 status |= IRQ_PENDING; /* we _want_ to handle it */
(gdb)
286 action = NULL;
(gdb)
287 if (!(status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
(gdb) <font color="#880000">l</font>
282 /*
283 * If the IRQ is disabled for whatever reason, we cannot
284 * use the action we have.
285 */
286 action = NULL;
287 if (!(status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
288 action = desc->action;
289 status &= ~IRQ_PENDING; /* we commit to handling */
290 status |= IRQ_INPROGRESS; /* we are handling it */
291 }
(gdb) <font color="#880000">l</font>
292 desc->status = status;
293
294 /*
295 * If there is no IRQ handler or it was disabled, exit early.
296 Since we set PENDING, if another processor is handling
297 a different instance of this same irq, the other processor
298 will take care of it.
299 */
300 if (!action)
301 goto out;
(gdb) <font color="#880000">l</font>
302
303 /*
304 * Edge triggered interrupts need to remember
305 * pending events.
306 * This applies to any hw interrupts that allow a second
307 * instance of the same irq to arrive while we are in do_IRQ
308 * or in the handler. But the code here only handles the _second_
309 * instance of the irq, not the third or fourth. So it is mostly
310 * useful for irq hardware that does not mask cleanly in an
311 * SMP environment.
(gdb) <font color="#880000">l</font>
312 */
313 for (;;) {
314 spin_unlock(&desc->lock);
315 handle_IRQ_event(irq, &regs, action);
316 spin_lock(&desc->lock);
317
318 if (!(desc->status & IRQ_PENDING))
319 break;
320 desc->status &= ~IRQ_PENDING;
321 }
(gdb) <font color="#880000">b 315</font>
Breakpoint 5 at 0x100949b7: file irq.c, line 315.
(gdb) <font color="#880000">c</font>
Continuing.
</font>
</pre>
</tt>
Next, I'll step into handle_IRQ_event and stop just before entering
the driver.
<tt>
<pre>
<font size="-1">
Breakpoint 5, do_IRQ (irq=2, user_mode=0) at irq.c:315
315 handle_IRQ_event(irq, &regs, action);
(gdb) <font color="#880000">s</font>
handle_IRQ_event (irq=2, regs=0x10113c40, action=0x50fef380) at irq.c:141
141 irq_enter(cpu, irq);
(gdb) <font color="#880000">l</font>
136 struct irqaction * action)
137 {
138 int status;
139 int cpu = smp_processor_id();
140
141 irq_enter(cpu, irq);
142
143 status = 1; /* Force the "do bottom halves" bit */
144
145 if (!(action->flags & SA_INTERRUPT))
(gdb) <font color="#880000">l</font>
146 __sti();
147
148 do {
149 status |= action->flags;
150 action->handler(irq, action->dev_id, regs);
151 action = action->next;
152 } while (action);
153 if (status & SA_SAMPLE_RANDOM)
154 add_interrupt_randomness(irq);
155 __cli();
(gdb) <font color="#880000">l</font>
156
157 irq_exit(cpu, irq);
158
159 return status;
160 }
161
162 /*
163 * Generic enable/disable code: this just calls
164 * down into the PIC-specific version for the actual
165 * hardware disable after having gotten the irq
(gdb) <font color="#880000">b 150</font>
Breakpoint 6 at 0x10094813: file irq.c, line 150.
(gdb) <font color="#880000">c</font>
Continuing.
Breakpoint 6, handle_IRQ_event (irq=2, regs=0x10113c40, action=0x50fef380)
at irq.c:150
150 action->handler(irq, action->dev_id, regs);
</font>
</pre>
</tt>
So, here we are in the console driver. I think I've made whatever
point I was making, so I'll just delete all the breakpoints, and let
the kernel run so I can log in and halt it.
<tt>
<pre>
<font size="-1">
(gdb) <font color="#880000">s</font>
con_handler (irq=2, dev=0x10120000, unused=0x10113c40) at stdio_console.c:41
41 stdio_rcv_proc(term->fd);
(gdb)
(gdb) <font color="#880000">d</font>
Delete all breakpoints? (y or n) y
(gdb) <font color="#880000">c</font>
Continuing.
</font>
</pre>
</tt>
</td>
</tr>
</table>
<center>
<font size="-1">
Hosted at </font>
<a href="http://sourceforge.net">
<IMG alt="SourceForge Logo" border="0" height="31" width="88" src="http://sourceforge.net/sflogo.php?group_id=429">
</a>
</center>
</body>
</html>
|