Loading...
Loading...
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.
npx skill4agent add mohitmishra786/low-level-dev-skills valgrind-g -O1-O0-O2valgrind --tool=memcheck \
--leak-check=full \
--show-leak-kinds=all \
--track-origins=yes \
--error-exitcode=1 \
./prog [args]| Flag | Default | Effect |
|---|---|---|
| summary | Full leak details |
| definite | Show all leak kinds |
| no | Show where uninit values came from (slow) |
| 0 | Exit N if errors found (CI integration) |
| stderr | Save report to file |
| none | Suppress known FPs |
| no | Print suppression directives for errors |
| 2000000 | Increase for deep stacks |
| off | Fill allocated memory (detect uninit use) |
| off | Fill freed memory (detect use-after-free) |
==12345== Invalid read of size 4
==12345== at 0x4007A2: foo (main.c:15)
==12345== by 0x400846: main (main.c:30)
==12345== Address 0x5204040 is 0 bytes after a block of size 40 alloc'd
==12345== at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck.so)
==12345== by 0x40074B: main (main.c:25)--track-origins=yes| Kind | Meaning |
|---|---|
| Definitely lost | No pointer to block |
| Indirectly lost | Lost via another lost block |
| Possibly lost | Pointer into middle of block |
| Still reachable | Pointer exists at exit; not a leak but never freed |
--show-leak-kinds=definite,indirect# Generate suppression for current error
valgrind --gen-suppressions=yes ./prog 2>&1 | grep -A20 '{'
# Example suppression file (valgrind.supp)
{
openssl_uninit
Memcheck:Cond
fun:SHA256_Init
...
}
# Use suppression file
valgrind --suppressions=valgrind.supp ./progvalgrind --tool=cachegrind ./prog
# Output: cachegrind.out.PID
# Annotate source
cg_annotate cachegrind.out.12345 --auto=yes
# Diff two runs
cg_diff cachegrind.out.before cachegrind.out.afterI1mrILmrD1mrDLmrD1mwDLmwvalgrind --tool=callgrind --callgrind-out-file=callgrind.out ./prog
# Analyse
callgrind_annotate callgrind.out
# Visualise in KCachegrind (GUI)
kcachegrind callgrind.outperfvalgrind --tool=massif ./prog
# Visualise
ms_print massif.out.PID | less
# GUI
massif-visualizer massif.out.PID--error-exitcode=1-fsanitize=addressskills/runtimes/sanitizersskills/profilers/linux-perfskills/profilers/flamegraphs