|
From: <sv...@va...> - 2005-08-03 18:06:43
|
Author: de Date: 2005-08-03 19:06:37 +0100 (Wed, 03 Aug 2005) New Revision: 153 Log: /docs/mini-tut.html - deleted as unwanted /docs/bookset/ - deleted old v.2.1.1 of manual Removed: trunk/docs/bookset/ trunk/docs/mini-tut.html Deleted: trunk/docs/mini-tut.html =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/docs/mini-tut.html 2005-08-03 18:02:48 UTC (rev 152) +++ trunk/docs/mini-tut.html 2005-08-03 18:06:37 UTC (rev 153) @@ -1,70 +0,0 @@ -<h1>Mini-Tutorial</h1> - -<h4>Courtesy of=20 -<a href=3D"http://www.cs.swarthmore.edu/~newhall/">Dr Tia Newhall</a></h= 4> -<?php -/* http://www.cs.swarthmore.edu/~newhall/unixhelp/purify.html */ -?> - -<p>Valgrind is a tool for finding memory access errors in your -code (memory leaks, reading uninitialized memory, accessing -unallocated memory, array out-of-bounds errors, ...). For C and -C++ programs, memory access errors are the most difficult bugs to -find and to fix. These tools can save you days worth of debugging -time by quickly pointing you to the source and type of memory -access errors in your code, so that you can easily determine what -to fix and how to fix it.</p> - -<p>In /home/newhall/public/purify_valgrind_examples/ is an -example program with bad memory access errors that you can use to -try out valgrind. Included are sample Makefiles for building -executables on Linux. The README file gives simple instructions -for using valgrind. More detailed instructions are listed -below:</p> - -<p>Running valgrind is easy. Just compile your program with -g, then -run the executable (for non-interactive programs, you will likely -want to re-direct output to a file since valgrind can generate a -lot of output):</p> -<pre class=3D"programlisting"> -% valgrind -v ./a.out=20 -% valgrind -v ./a.out >& out # re-direct valgrind (and a.out) output t= o file 'out' -</pre> - -<p>If you look through the out file, you may see memory errors -listed like this:</p> -<pre class=3D"programlisting"> -=3D=3D9860=3D=3D Invalid write of size 1 -=3D=3D9860=3D=3D at 0x8048532: foo (main.c:28) -=3D=3D9860=3D=3D by 0x804859F: main (main.c:48) -=3D=3D9860=3D=3D by 0x4023514E: __libc_start_main (in /lib/libc-2.2.5= .so) -=3D=3D9860=3D=3D by 0x80483D0: (within ~/newhall/public/purify_exampl= es/badprog) -=3D=3D9860=3D=3D Address 0x40F33061 is 0 bytes after a block of size = 5 alloc'd -=3D=3D9860=3D=3D at 0x401678B8: malloc (vg_clientfuncs.c:103) -=3D=3D9860=3D=3D by 0x80484C8: foo (main.c:17) -=3D=3D9860=3D=3D by 0x804859F: main (main.c:48) -=3D=3D9860=3D=3D by 0x4023514E: __libc_start_main (in /lib/libc-2.2.5= .so) -</pre> - -<p>This tells me that in function foo, at line 28 in main.c, my -program is writing 1 byte beyond the array that was allocated at -line 17 in function foo (9860 was the process ID of my running -program). If I look at lines 17 and 28 of my program, the error -is obvious (my loop executes one to many times, accessing c[5], -which is beyond the end of array c, on the last iteration):</p> - -<pre class=3D"programlisting"> -17 c =3D (char *)malloc(sizeof(char)*5); -18 strcpy(c, "cccc"); -19=20 -... -27 for( i=3D0; i <=3D 5; i++ ) { -28 c[i] =3D str[i]; -29 } -</pre> - -<br /> -<p><b>Note:</b> See the "Usage" section of the=20 -<a href=3D"/docs/valgrind-HOWTO/">HOWTO</a> for more information on -using valgrind.</p> - |