Search code examples
cgdb

How to declare a variable in the scope of a given function with GDB?


I know that gdb allows for an already declared variable to be set using the set command.

Is it possible for gdb to dynamically declare a new variable inside the scope of a given function?


Solution

  • For C (and probably C++) code, that would be very hard, since doing so in most implementations would involve shifting the stack pointer, which would make the function's exit code fail due to it no longer matching the size of the stack frame. Also all the code in the function that accesses local variables would suddenly risk hitting the wrong location, which is also bad.

    So, I don't think so, no.