As the current state is pretty much usable and
most of the tests are passing, I'm ready to merge it into mainline. Besides the emulation (which is installed out of the ML tree), the "qemu" branch also provides a debugging API, explained below. I've used this API for the
new DryOS task hooks (6D, 100D, 70D and EOS M2), so these new ports (all but 6D) depend on "qemu" being merged first.
I just need a second pair of eyes to look over it and make sure:
1) there's nothing broken in the main builds (build system, functionality);
2) the debugging API works as described below.
The main debugging function is
qprintf (and its lightweight friends: qprint, qprintn and qdisas). Feel free to use them *anywhere* - they won't get compiled in regular builds (therefore they won't increase the executable size). These functions will print to QEMU console whenever ML (or a subset of it) is compiled with CONFIG_QEMU=y. Example:
cd platform/550D.109
make clean; make # regular build
make clean; make CONFIG_QEMU=y # debug build for QEMU
It works for modules as well:
cd modules/lua
# add some qprintf call in lua_init for testing
make clean; make # regular build
make clean; make CONFIG_QEMU=y # debug build for QEMU
(Side note: as we don't emulate ML shutdown properly yet, you'll have to enable Debug -> Load modules after crash. Solving this is a little above easy coding task level, but doable.)
You can also specify CONFIG_QEMU=y in Makefile.user - but as this is more likely to be used as a temporary option, the command line makes a little more sense to me.
The QEMU debugging API is header-only (qemu-util.h), auto-included by dryos.h. You can use it for either the entire ML, or just for a subset of it - e.g. the source file(s) you are currently editing, or only some modules. The lightweight functions can also be used in very early boot code, where you can't call vsnprintf or you may not even have a stack properly set up.
In a nutshell:
CONFIG_QEMU=n (default):
- regular build
- the executable works in QEMU (within the limitations of the emulation)
- no guest debugging code (no additional debugging facilities)
CONFIG_QEMU=y (optional, on the command line or in Makefile.user):
- debug build for QEMU only
- does
not run on the camera (!)
- enables qprintf and friends to print on the QEMU console
- enables unlimited number of ROM patches - useful for dm-spy-experiments (in QEMU you can simply write to ROM as if it were RAM)
- may enable other workarounds for models that are not emulated very well
Additionally, you have better support for debugging ML at source level, in gdb (or any front-end you like). Uncomment the symbol-file line in your GDB script:
symbol-file ../magic-lantern/platform/80D.102/magiclantern
and you can now run ML code step by step in the debugger, or set breakpoints to any ML function:
b my_init_task
For debugging very early boot code (e.g. reboot.c), you'll have to use "autoexec" for symbol-file.
More details on debugging on the EOS M2 thread.
Unfortunately I don't have a good solution for debugging modules in the same way...
Also started a
README - proof-reading welcome
