VEX is a CLI tool that combines deterministic memory leak analysis with Mistral AI to provide intelligent, guided debugging assistance for C programs.
Memory leak analysis is a domain where LLMs perform poorly when used naively. They don't simulate memory, propagate early mistakes, and often fail on non-trivial cases involving aliasing, embedded allocations, or container lifetimes.
VEX takes a different approach: Instead of asking an LLM to find the root cause, it separates the problem into two phases:
- Deterministic root cause identification - A Python algorithm tracks memory paths through your code, following Valgrind's execution trace line by line
- LLM-assisted explanation - Mistral AI (mistral-small-latest) explains the leak, justifies the root cause, and suggests a minimal fix
The LLM never guesses ownership or simulates memory. It only explains what the deterministic analysis has already proven.
super_vex.mov
Before installing VEX, make sure you have:
- Docker
- Python 3.x
- A Mistral AI API key
Note: For the best visual experience, use a terminal with a dark background.
- Clone the repository
git clone <repository-url>
cd vex- Install VEX
make installYou'll be prompted for your sudo password to install the tool system-wide.
- Configure your API key
vex configureEnter your Mistral AI API key when prompted.
vex <executable> [arguments]VEX will:
- Run your program through Valgrind
- Analyze memory paths deterministically
- Provide AI-powered explanations and fix suggestions
cd examples/Type_1
make
vex ./leakyThe examples directory contains three types of memory leak scenarios to help you understand how VEX works.
Given a Valgrind report, VEX tracks one allocation at a time through your code:
- Maintains roots (variables that can reach the allocation)
- Tracks access paths (e.g.,
node->data) - Updates paths when encountering aliases, reassignments, frees, or scope exits
When no valid path remains and the allocation wasn't freed, the root cause is identified.
VEX categorizes leaks into three concrete types:
- Missing free - Allocation never freed before paths disappear
- Path loss by reassignment - Last access path overwritten or set to NULL
- Container freed first - Structure freed while owning embedded allocations
Each points to the precise line of code responsible.
After deterministic analysis, Mistral AI receives:
- The Valgrind report
- Relevant source code
- The identified root cause
- The leak classification
It then explains the leak step-by-step and proposes a correct fix.
What VEX avoids:
- Global program analysis
- Heuristics or "smart" guessing
- Overfitting to simple examples
What VEX focuses on:
- Constrained reasoning
- Explicit assumptions
- Trustworthy results within supported scope
Current limitations:
- No loop handling
- Single execution path only
- One allocation tracked at a time
- Conditions not handled
- External free functions not tracked
These features are on the TODO list.
This project explores how deterministic analysis and LLMs can complement each other by assigning each tool a role aligned with its strengths:
- Deterministic analysis: Root cause identification with zero false positives
- LLMs: Explanation, pedagogy, and fix suggestions
The goal isn't to replace Valgrind, but to make its output actionable for developers learning C.
