Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to use valgrind and gdb

88 views
Skip to first unread message

cs240

unread,
Jul 18, 2011, 11:05:21 AM7/18/11
to
gdb is a c++ debugger, to use it compile your code using g++ with the -g
flag, then call gdb on the compiled object

EG:
g++ -g *.cpp
gdb a.out

http://www.student.cs.uwaterloo.ca/~cs343/documents/C++GDBTutorial.pdf


valgrind is a programming tool for memory debugging, memory leak
detection, and profiling.

If you have a segmentation fault, run valgrind on your program to check
for any uninitialized values.

EG:
valgrind a.out

--
Patrick Lee
CS240 Tutor

Daniel S. Roche

unread,
Jul 18, 2011, 11:23:30 AM7/18/11
to
On 11-07-18 11:05 AM, cs240 wrote:
> valgrind is a programming tool for memory debugging, memory leak
> detection, and profiling.
>
> If you have a segmentation fault, run valgrind on your program to check
> for any uninitialized values.
>
> EG:
> valgrind a.out

Yes, valgrind is a wonderful (and free!) tool. I recommend the "quick
start guide" here: http://valgrind.org/docs/manual/quick-start.html

Tips:
-Compile with -g for gdb AND for valgrind
-Run valgrind with --leak-check=yes since memory leaks are probably what
you're after.
-All the sizes are in terms of bytes. For reference, a char is typically
1 byte, an int is typically 4, and a double is always 8 bytes.
-valgrind is really slow. Don't use big data on it! Start with very
small examples and build up slowly until you get some errors.

-Dan Roche
CS 240 Instructor, Section 003

0 new messages