Visual C++ memory tracing for Vix Note.
PtrLens compiles C++ code with debug information, executes it through LLDB, captures stack variables and pointer relationships, builds a visual memory model, and returns an SVG representation to Vix Note.
int value = 42;
int* pointer = &value;PtrLens turns this relationship into a visual result:
Stack
┌─────────────────────┐
│ value │◄─────────┐
│ int │ │
│ 42 │ │
└─────────────────────┘ │
│
┌─────────────────────┐ │
│ pointer │──────────┘
│ int* │
│ 0x...
└─────────────────────┘
- C++ compilation with debug information;
- LLDB-based source-level tracing;
- stack frame discovery;
- local variable inspection;
- pointer and reference detection;
- resolved and unresolved memory relationships;
- null pointer detection;
- visual memory snapshots;
- SVG output for Vix Note;
- structured diagnostics;
- one-shot Vix Note extension protocol;
- standalone executable runtime.
PtrLens 0.1.0 focuses on:
- stack variables;
- primitive values;
- basic pointers;
- references;
- source locations;
- final memory snapshot rendering.
Heap allocation lifetime tracking, delete detection, smart pointers, dangling pointers, memory leaks, animated timelines, and interactive stepping are planned for later versions.
PtrLens currently targets Unix-like platforms.
Required tools:
C++20 compiler
CMake 3.20 or newer
LLDB
Vix Note
Recommended compiler:
clang++
Default compiler command:
c++
Default debugger command:
lldb
PtrLens/
├── CMakeLists.txt
├── LICENSE
├── README.md
├── vix.json
├── include/
│ └── ptrlens/
│ ├── compiler_process.hpp
│ ├── debugger_process.hpp
│ ├── error.hpp
│ ├── kernel.hpp
│ ├── memory_model.hpp
│ ├── protocol.hpp
│ ├── ptrlens.hpp
│ ├── request.hpp
│ ├── response.hpp
│ ├── result.hpp
│ ├── svg_renderer.hpp
│ ├── trace.hpp
│ └── version.hpp
├── src/
│ ├── compiler_process.cpp
│ ├── debugger_process.cpp
│ ├── kernel.cpp
│ ├── main.cpp
│ ├── memory_model.cpp
│ ├── protocol.cpp
│ ├── svg_renderer.cpp
│ └── trace.cpp
├── tests/
│ ├── kernel_test.cpp
│ ├── memory_model_test.cpp
│ ├── protocol_test.cpp
│ └── svg_renderer_test.cpp
├── examples/
│ ├── basic_pointer.cpp
│ └── heap_allocation.cpp
└── docs/
└── protocol.md
Build PtrLens with Vix:
vix buildThe executable is generated in the active Vix build directory.
For a release build:
vix build --preset releasevix build -- \
-DPTRLENS_BUILD_TESTS=OFFvix build --build-target all -- \
-DPTRLENS_BUILD_EXAMPLES=ONvix testsRun tests with failure details:
vix tests --output-on-failureBuild all targets before running the tests:
vix build --build-target all
vix tests --output-on-failureThe current test targets are:
ptrlens.protocol
ptrlens.kernel
ptrlens.memory_model
ptrlens.svg_renderer
cmake --install build --prefix ~/.localThe executable is installed under:
~/.local/bin/ptrlens
The public headers are installed under:
~/.local/include/ptrlens
PtrLens is a normal Vix executable package with an extensions.note declaration.
The package identity is:
softadastra/ptrlens
The runtime command is:
ptrlens
The contributed cell type is:
ptrlens
The visible label in Vix Note is:
C++ Memory
The extension uses:
protocol: vix-note-extension-1
mode: oneshot
After PtrLens is published to the Vix Registry:
vix registry sync
vix install -g softadastra/ptrlensInspect extension discovery:
vix note --list-extensionsStart Vix Note:
vix noteThe cell type picker should include C++ Memory.
PtrLens reads one JSON request from standard input and writes one JSON response to standard output.
cat <<'JSON' | ./build/ptrlens
{
"protocol": "vix-note-extension-1",
"requestId": "manual-test",
"cellId": "basic-pointer",
"cellType": "ptrlens",
"source": "#include <iostream>\n\nint main()\n{\n int value = 42;\n int* pointer = &value;\n std::cout << *pointer << '\\n';\n return 0;\n}\n",
"executionCount": 0,
"workingDirectory": ".",
"documentPath": "",
"extensionId": "softadastra/ptrlens",
"extensionVersion": "0.1.0"
}
JSONA successful response has this general form:
{
"protocol": "vix-note-extension-1",
"ok": true,
"stdout": "PtrLens captured execution steps and generated memory snapshots.\n",
"outputs": [
{
"mime": "image/svg+xml",
"data": "<svg>...</svg>"
}
]
}Vix Note request
-> JSON validation
-> temporary C++ source
-> debug compilation
-> LLDB execution
-> trace parsing
-> memory model
-> SVG rendering
-> Vix Note response
Override the compiler with:
PTRLENS_COMPILER=clang++ ./build/ptrlensDefault:
c++
PtrLens currently compiles source with options equivalent to:
-std=c++20
-g
-O0
-fno-omit-frame-pointer
-fno-optimize-sibling-calls
Override the debugger with:
PTRLENS_DEBUGGER=lldb ./build/ptrlensDefault:
lldb
The current trace parser expects LLDB-compatible output.
PtrLens normally removes temporary source files, binaries, debugger scripts, and logs after execution.
Preserve them for debugging:
PTRLENS_PRESERVE_ARTIFACTS=1 ./build/ptrlensTemporary artifacts are stored under:
<working-directory>/.ptrlens/tmp/
or under the system temporary directory when no working directory is provided.
PTRLENS_INCLUDE_RAW_TRACE=1 ./build/ptrlensThis adds a text/plain output containing the raw LLDB trace.
| Variable | Purpose |
|---|---|
PTRLENS_COMPILER |
Overrides the C++ compiler command. |
PTRLENS_DEBUGGER |
Overrides the debugger command. |
PTRLENS_PRESERVE_ARTIFACTS |
Preserves temporary execution artifacts. |
PTRLENS_INCLUDE_RAW_TRACE |
Includes raw debugger output in the response. |
Enabled boolean values are:
1
true
yes
on
Expected failures are returned as structured JSON.
{
"protocol": "vix-note-extension-1",
"ok": false,
"error": {
"code": "compilation_failed",
"message": "PtrLens could not compile the C++ source.",
"details": "program.cpp:4: error: expected expression"
}
}Common error codes include:
invalid_request
invalid_protocol
invalid_source
compiler_not_found
compilation_failed
debugger_not_found
debugger_failed
trace_failed
process_failed
timeout
invalid_response
internal_error
Include the umbrella header:
#include <ptrlens/ptrlens.hpp>The public API exposes:
- protocol request and response types;
- compiler process;
- debugger process;
- execution trace model;
- memory model;
- SVG renderer;
- execution kernel;
- structured errors and results.
Example:
#include <ptrlens/ptrlens.hpp>
int main()
{
ptrlens::MemorySnapshot snapshot;
ptrlens::MemoryObject value;
value.id = "value";
value.name = "value";
value.type = "int";
value.value = "42";
value.region = ptrlens::MemoryRegion::stack;
snapshot.objects.push_back(value);
ptrlens::SvgRenderer renderer;
auto result = renderer.render(snapshot);
return result ? 0 : 1;
}PtrLens currently does not provide:
- a persistent debugger process;
- interactive
Step IntoorStep Overcontrols; - frontend JavaScript contributions;
- custom Vix Note CSS;
- runtime sandboxing;
- heap lifetime instrumentation;
- reliable
newanddeleteevent detection; - dangling pointer detection;
- memory leak detection;
- smart pointer ownership graphs;
- GDB support;
- Windows process support.
The current Vix Note extension API starts one external runtime for each execution.
PtrLens compiles and executes user-provided C++ code locally.
The current implementation does not provide:
- filesystem isolation;
- network isolation;
- process isolation;
- container sandboxing;
- interactive permission approval.
Only execute trusted C++ code.
- Vix Note protocol;
- C++ debug compilation;
- LLDB execution;
- stack variables;
- pointer relationships;
- SVG final snapshot.
- improved trace parsing;
- multiple stack frames;
- references and arrays;
- richer source locations;
- multiple SVG snapshots.
- heap object discovery;
newanddeleteevents;- object lifetime tracking;
- released memory visualization.
- smart pointers;
- ownership relationships;
- dangling pointer diagnostics;
- memory leak diagnostics.
- complete execution timeline;
- animated SVG export;
- shareable HTML reports;
- stable extension runtime;
- expanded platform support.
See:
docs/protocol.md
PtrLens is licensed under the MIT License.
Copyright © 2026 Softadastra.