/[gentoo]/xml/htdocs/doc/en/draft/debugging-howto.xml
Gentoo

Diff of /xml/htdocs/doc/en/draft/debugging-howto.xml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.2 Revision 1.3
1<?xml version="1.0" encoding="UTF-8"?> 1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE guide SYSTEM "/dtd/guide.dtd"> 2<!DOCTYPE guide SYSTEM "/dtd/guide.dtd">
3<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/draft/debugging-howto.xml,v 1.2 2005/07/13 18:58:31 fox2mike Exp $ --> 3<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/draft/debugging-howto.xml,v 1.3 2005/07/14 09:42:27 swift Exp $ -->
4 4
5<guide link="/doc/en/debugging-howto.xml"> 5<guide link="/doc/en/debugging-howto.xml">
6<title>Gentoo Linux Debugging Guide</title> 6<title>Gentoo Linux Debugging Guide</title>
7 7
8<author title="Author"> 8<author title="Author">
136CFLAGS="-O2 -pipe -ggdb3" 136CFLAGS="-O2 -pipe -ggdb3"
137CXXFLAGS="${CFLAGS}" 137CXXFLAGS="${CFLAGS}"
138</pre> 138</pre>
139 139
140<p> 140<p>
141Lastly, you can also add debug to the package's USE flags. This can be done with the 141Lastly, you can also add debug to the package's USE flags. This can be done
142<path>package.use</path> file. 142with the <path>package.use</path> file.
143</p> 143</p>
144 144
145<pre caption="Using package.use to add debug USE flag"> 145<pre caption="Using package.use to add debug USE flag">
146# <i>echo "category/package debug" >> /etc/portage/package.use</i> 146# <i>echo "category/package debug" >> /etc/portage/package.use</i>
147</pre> 147</pre>
243<p> 243<p>
244You can notice the trace pattern clearly. main() is called first, followed by 244You can notice the trace pattern clearly. main() is called first, followed by
245run_it(), and somewhere in run_it() lies the strcpy() at fault. Things such as 245run_it(), and somewhere in run_it() lies the strcpy() at fault. Things such as
246this help developers narrow down problems. There are a few exceptions to the 246this help developers narrow down problems. There are a few exceptions to the
247output. First off is forgetting to enable debug symbols with 247output. First off is forgetting to enable debug symbols with
248<c>FEATURES="nostrip"</c>. With debug symbols stripped, the output looks something 248<c>FEATURES="nostrip"</c>. With debug symbols stripped, the output looks
249like this: 249something like this:
250</p> 250</p>
251 251
252<pre caption="Program backtrace With debug symbols stripped"> 252<pre caption="Program backtrace With debug symbols stripped">
253(gdb) <i>bt</i> 253(gdb) <i>bt</i>
254#0 0xb7e2cdc0 in strcpy () from /lib/libc.so.6 254#0 0xb7e2cdc0 in strcpy () from /lib/libc.so.6
309<comment>(-ggdb3 flag enabled)</comment> 309<comment>(-ggdb3 flag enabled)</comment>
310-rwxr-xr-x 1 chris users 19552 6/28 13:11 bad_code 310-rwxr-xr-x 1 chris users 19552 6/28 13:11 bad_code
311</pre> 311</pre>
312 312
313<p> 313<p>
314As you can see, -ggdb3 adds about <e>13178</e> more bytes to the file size over the one 314As you can see, -ggdb3 adds about <e>13178</e> more bytes to the file size
315with debugging symbols. However, as shown above, this increase in file size can 315over the one with debugging symbols. However, as shown above, this increase
316be worth it if presenting debug information to developers. The backtrace can be 316in file size can be worth it if presenting debug information to developers.
317saved to a file by copying and pasting from the terminal (if it's a non-x based 317The backtrace can be saved to a file by copying and pasting from the
318terminal, you can use gpm. To keep this doc simple, I recommend you read up on 318terminal (if it's a non-x based terminal, you can use gpm. To keep this
319the documentation for gpm to see how to copy and paste with it). Now that we're 319doc simple, I recommend you read up on the documentation for gpm to see
320done with <c>gdb</c>, we can quit. 320how to copy and paste with it). Now that we're done with <c>gdb</c>, we
321can quit.
321</p> 322</p>
322 323
323<pre caption="Quitting GDB"> 324<pre caption="Quitting GDB">
324(gdb) <i>quit</i> 325(gdb) <i>quit</i>
325The program is running. Exit anyway? (y or n) <i>y</i> 326The program is running. Exit anyway? (y or n) <i>y</i>
326$ 327$
327</pre> 328</pre>
328 329
329<p> 330<p>
330This ends the walk-through of <c>gdb</c>. Using <c>gdb</c>, we hope that you will 331This ends the walk-through of <c>gdb</c>. Using <c>gdb</c>, we hope that you
331be able to use it to create better bug reports. However, there are other types 332will be able to use it to create better bug reports. However, there are other
332of errors that can cause a program to fail during run time. One of the other 333types of errors that can cause a program to fail during run time. One of the
333ways is through improper file access. We can find those using a nifty little 334other ways is through improper file access. We can find those using a nifty
334tool called <c>strace</c>. 335little tool called <c>strace</c>.
335</p> 336</p>
336 337
337</body> 338</body>
338</section> 339</section>
339</chapter> 340</chapter>
348Programs often use files to fetch configuration information, access hardware or 349Programs often use files to fetch configuration information, access hardware or
349write logs. Sometimes, a program attempts to reach such files incorrectly. A 350write logs. Sometimes, a program attempts to reach such files incorrectly. A
350tool called <c>strace</c> was created to help deal with this. <c>strace</c> 351tool called <c>strace</c> was created to help deal with this. <c>strace</c>
351traces system calls (hence the name) which include calls that use the memory and 352traces system calls (hence the name) which include calls that use the memory and
352files. For our example, we're going to take a program foobar2. This is an 353files. For our example, we're going to take a program foobar2. This is an
353updated version of foobar. However, during the change over to foobar2, you notice 354updated version of foobar. However, during the change over to foobar2, you
354all your configurations are missing! In foobar version 1, you had it setup to 355notice all your configurations are missing! In foobar version 1, you had it
355say "foo", but now it's using the default "bar". 356setup to say "foo", but now it's using the default "bar".
356</p> 357</p>
357 358
358<pre caption="Foobar2 With an invalid configuration"> 359<pre caption="Foobar2 With an invalid configuration">
359$ <i>./foobar2</i> 360$ <i>./foobar2</i>
360Configuration says: bar 361Configuration says: bar
404<section> 405<section>
405<title>Conclusion</title> 406<title>Conclusion</title>
406<body> 407<body>
407 408
408<p> 409<p>
409<c>strace</c> is a great way at seeing what the kernel is doing to with the filesystem. 410<c>strace</c> is a great way at seeing what the kernel is doing to with the
410Another program exists to help users see what the kernel is doing, and help with 411filesystem. Another program exists to help users see what the kernel is doing,
411kernel debugging. This program is called <c>dmesg</c> 412and help with kernel debugging. This program is called <c>dmesg</c>.
412</p> 413</p>
413 414
414</body> 415</body>
415</section> 416</section>
416</chapter> 417</chapter>
567!!! Make failed! 568!!! Make failed!
568!!! If you need support, post the topmost build error, NOT this status message 569!!! If you need support, post the topmost build error, NOT this status message
569</pre> 570</pre>
570 571
571<p> 572<p>
572The program is compiling smoothly when it suddenly stops and presents an error message. This 573The program is compiling smoothly when it suddenly stops and presents an error
573particular error can be split into 3 different sections, The compile messages, the build 574message. This particular error can be split into 3 different sections, The
574error, and the emerge error message as shown below. 575compile messages, the build error, and the emerge error message as shown below.
575</p> 576</p>
576 577
577<pre caption="Parts of the error"> 578<pre caption="Parts of the error">
578<comment>(Compilation Messages)</comment> 579<comment>(Compilation Messages)</comment>
579gcc -D__TEST__ -D__GNU__ -D__LINUX__ -L/usr/lib -I/usr/include -L/usr/lib/nspr/ -I/usr/include/fmod -c -o foobar2-7.o foobar2-7.c 580gcc -D__TEST__ -D__GNU__ -D__LINUX__ -L/usr/lib -I/usr/include -L/usr/lib/nspr/ -I/usr/include/fmod -c -o foobar2-7.o foobar2-7.c

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

  ViewVC Help
Powered by ViewVC 1.1.20