I wanted to run and debug embedded firmware for microcontrollers on my PC while the real hardware is either unavailable or inconvenient. Unit testing alone doesn’t cut it—I want to execute the entire firmware, see it interact, crash, leak, and behave similarly as it would on a microcontroller.
The problem: some legacy projects I have to debug are tightly coupled to HALs, registers, and inline assembly. Sprinkling preprocessor directivies like #ifdef SIMULATION everywhere quickly becomes un‑maintainable. I needed a cleaner way.
mockshadow is the tool I wrote to make that possible.
A CLI that builds a shadow copy of your C project where any function, variable, macro, typedef, enum, struct, or union can be swapped for a user‑written mock without modifying the original source tree.
- ❌ Generate mocks for you – you still write the replacement code.
- ❌ Fix compilation errors automatically – you decide what must be mocked or stubbed.
- ❌ Compile or link – it only rewrites text.
- ✅ Uses Clang to pinpoint symbols accurately (no brittle regex).
- ✅ Applies all substitutions in one shot, producing a clean shadow tree.
- ✅ Leaves the pristine firmware untouched and under version control.
- ✅ Eliminates the flood of pre‑processor directives usually required for simulation builds.
- Attempt to compile the firmware natively – watch it fail on register access, inline ASM, HAL calls…
- Create a mock file under
MOCK_TREE/…/__mock__*.cor.h, containing directives that say what to replace and with what. - Run
mockshadow mock– the tool clones the project, applies your mocks and writes the result toSHADOW_OUT/…. - Build the shadow tree with your favourite system (Make, CMake, VSCode tasks…).
- Execute the firmware as a normal PC process, run sanitizers, fuzzers, debuggers—you name it.
- Initialize clang-code-extractor submodule
# Ubuntu
sudo git submodule update --init --recursive
# Windows
git submodule update --init --recursive-
Install clang-code-extractor dependencies Follow DEPENDENCIES section listed on
clang-code-extractor/README.md -
Execute Mockshadow Setup Script
# Ubuntu
python3 setup.py
# Windows
python setup.py-
Add Mockshadow to Path (Windows only)
On Windows, you must add mockshadow directory to PATH variable. -
Test installation
mockshadow versionThe project is experimental but functional. A hands‑on example that mocks a simple STM32 HAL project is on the way.
PRs, issues and feedback are welcome!