GithubHelp home page GithubHelp logo

warriorhanamy / introduction_to_valgrind Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rodrigorandel/introduction_to_valgrind

0.0 0.0 0.0 275 KB

TUTORIAL: INTRODUCTION TO VALGRIND

C++ 60.74% C 8.75% Makefile 30.50%

introduction_to_valgrind's Introduction

Tutorial: Introduction to Valgrind

This tutorial aims to cover the basic principles of Valgrind. It was presented by Rodrigo Randel.

Motivation

Valgrind is a widely used programming tool for debugging and profiling programs. Valgrind's tools are designed to dynamically perform analysis of your program and automatically detect commons and rares bugs, many of which would take hours to be found manually, or would never be found at all.

By using Valgrind tools, such as the memory checker and the cache profiler, you can easily identify when a bug occurs, and get instant feedback about what the bug is, where it occurred, and why. As for Valgrind's profiling tools, use those whenever you want to gather information about how your program is spending its time, or you if want to speed it up. Moreover, Valgrind works with programs written in any language, such as C, C++, Java, Python and many others.

In this tutorial, we are going to cover the following topics:

  • Present the main aspects of Valgrind and explain why and when you should use it.
  • Give an overview of all the six tools present in the Valgrind's current release, explaining in details two of them: Memcheck and Cachegrind.
  • Present how to use Valgrind and how to interpret its output, either via a terminal window or via using an IDE such as Eclipse.

1. How to run the examples

Each folder has an Eclipse project with the code and Makefile for the correspondent example.

1.1 Example 1:

To run valgrind with memcheck:

$ valgrind --tool=memcheck ./main

Use --leak-check=full to obtain details for each definitely lost or possibly lost block:

$ valgrind --tool=memcheck --leak-check=full ./main

1.2 Example 2:

To check for memory errors run:

$ valgrind --tool=memcheck --leak-check=full ./main

Use --gen-suppressions=yes to ask valgrind to generate suppressions:

$ valgrind --tool=memcheck --gen-suppressions=yes --leak-check=full ./main

Copy the generated suppressions in a file called ex2.supp and run:

$ valgrind --tool=memcheck --suppressions-file=ex2.supp --leak-check=full ./main

Use -v to run Valgrind with verbose to check the suppressed files:

$ valgrind --tool=memcheck --suppressions=ex2.supp  -v --leak-check=full ./main

1.3 Example 3:

To check for errors run:

$ valgrind ./main

Use valgrind gdbserver to debug with gdb:

$ valgrind --vgdb=yes --vgdb-error=0 ./main

In another shell, run gdb and connect to valgrind:

$ gdb ./main
$ (gdb) target remote | vgdb (--pid=<pid>)

Use monitor commands of presented in slides 22 and 23.

1.4 Example 4:

To run memcheck and check for errors run:

$ valgrind --leak-check=full ./main

Use --track-origins=yes easier to track down the root causes of uninitialized value errors

$ valgrind --leak-check=full --track-origins=yes ./main

1.5 Examples for massif and cachegrind

The demonstrations 5 and 7 were made using the Valgrind support on Eclipse.

1.6 Example for callgrind

The demonstration 6 was made using the KCachegrind tool.

introduction_to_valgrind's People

Contributors

matbesancon avatar rodrigorandel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.