Giter Club home page Giter Club logo

enpm808x-valgrind's Introduction

Valgrind Exercise

Standard install via command-line

# Configure the project and generate a native build system:
  # Must re-run this command whenever any CMakeLists.txt file has been changed.
  cmake -S ./ -B build/
# Compile and build the project:
  # rebuild only files that are modified since the last build
  cmake --build build/
  # or rebuild everything from scracth
  cmake --build build/ --clean-first
  # to see verbose output, do:
  cmake --build build/ --verbose
# Run program:
  ./build/app/shell-app
# Clean
  cmake --build build/ --target clean
# Clean and start over:
  rm -rf build/

Valgrind:

valgrind --leak-check=full --track-origins=yes ./build/app/shell-app > <OUTPUT_file-txt> 2>&1

Bugs:

  • Unitialized variable in main.
  • Memory had to be deallocated for the pointer.

Outputs:

  • out__commented.txt
  • out_modifiedcode_commented.txt
  • out_not_commented.txt

Answers for extra credit:

  • What happens when the executable is linked statically? It tries to compile everything in one single executable.

  • Does Valgrind still detect those same bugs? If the executable is linked statically, Valgrind detects a broader range of memory-related errors, potentially resulting in false negatives, where actual issues are overlooked.

  • Why not? This is because numerous libraries in the shell-app and the CMake build of the project are dynamic. When you link libraries statically, their memory management behavior becomes integrated into your program's build, such as with CMake in this project. Valgrind may not distinguish between memory allocated by your program and that allocated by these libraries.

    valgrind.org answer:

    If your program is statically linked, most Valgrind tools will only work well if they are able to replace certain functions, such as malloc, with their own versions. By default, statically linked malloc functions are not replaced. A key indicator of this is if Memcheck says:

    All heap blocks were freed -- no leaks are possible

    when you know your program calls malloc. The workaround is to use the option --soname-synonyms=somalloc=NONE or to avoid statically linking your program.

    There will also be no replacement if you use an alternative malloc library such as tcmalloc, jemalloc, ... In such a case, the option --soname-synonyms=somalloc=zzzz (where zzzz is the soname of the alternative malloc library) will allow Valgrind to replace the functions.

enpm808x-valgrind's People

Contributors

patrikpordi avatar tommychangumd avatar

Watchers

 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.