Skip to content

mohitmishra786/low-level-dev-skills / skills/profilers/valgrind

valgrind

Verified

Valgrind profiler skill for memory error detection and cache profiling. Use when running Memcheck to find heap corruption, use-after-free, memory leaks, or uninitialised reads; or Cachegrind/Callgrind for cache simulation and function-level profiling. Activates on queries about valgrind, memcheck, heap leaks, use-after-free without sanitizers, cachegrind, callgrind, KCachegrind, or massif memory profiling.

FileKindSize
SKILL.mdskill md5.1 KB
references/valgrind-vs-asan.mdmarkdown1.8 KB

references/valgrind-vs-asan.md

View on GitHub
# Valgrind vs AddressSanitizer

## Comparison

| Feature | Valgrind Memcheck | AddressSanitizer (ASan) |
|---------|-------------------|------------------------|
| Slowdown | 10-50x | 2x |
| Memory overhead | 2-4x | ~2x |
| Requires recompile | No | Yes |
| Root required | No | No |
| Heap OOB | Yes | Yes |
| Stack OOB | Limited | Yes |
| Global OOB | No | Yes |
| Use-after-free | Yes | Yes |
| Use-after-return | No | Yes (with flag) |
| Uninit reads | Yes | No (use MSan) |
| Leak detection | Yes | Yes (with LeakSanitizer) |
| Platform | Linux/macOS/FreeBSD | GCC/Clang on Linux/macOS/Windows |
| Kernel/unmodified bins | Yes | No (need instrumented build) |

## When to use which

**Use ASan when:**

- You control the build process
- You want fast iteration in development
- You need to catch stack overflows and global OOB
- CI/CD integration (speed matters)

**Use Valgrind when:**

- You cannot recompile (testing pre-built binaries)
- You need uninitialised value detection (use `--track-origins=yes`)
- You need cache profiling (Cachegrind) or call graphs (Callgrind)
- You need heap usage profiling (Massif)
- You are on an older toolchain that doesn't support sanitizers

## Both together

Running ASan + Valgrind on the same binary is not recommended (both intercept `malloc`/`free`). Choose one per run.

However: compile with ASan for dev CI, run Valgrind Memcheck as a separate nightly check on a non-instrumented binary for uninit-value detection.

## Combining sanitizers for maximum coverage

```bash
# ASan + UBSan + LeakSanitizer (all Clang/GCC)
clang -fsanitize=address,undefined -g -O1 -o prog main.c

# MemorySanitizer (uninit reads; Clang only; all-clang build required)
clang -fsanitize=memory -g -O1 -o prog main.c

# ThreadSanitizer (data races)
clang -fsanitize=thread -g -O1 -o prog main.c
```
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall