GDB recently introduced the compile
command to inject code at runtime, see this answer for requirements and a minimal example.
But I noticed that a few things do not work as if I had written them in the original source code at the current location:
compile code return;
does not end the current function, only the injected code.Hypothesis: code runs in a new stack frame, but one in which local variables are still visible.
register modification fails, e.g.:
compile code asm volatile ("mov $0x123, %rbp"); p $rbp
Output: not
0x123
.Hypothesis: registers are all saved and restored on the function run.
Besides those, the documentation clearly explains that injected code symbols and types are not visible outside.
So what is the general theory / full list of those constructs that "do not work"?
The GNU Cauldron presentation of the feature contains an overview of the feature usage and internals: video, presentation
The feature is implemented on the compile/
subdirectory of the 7.9.1 GDB source code.