Consider, for example, a target that runs on QEMU. QEMU won't start
the binary in exactly the same way as gdbserver running on linux.
Thus, global variable initialization procedures may not have
happened at that point yet. Consider that we start even before the
dynamic loader had a chance to run and do all the relocation magic.
The part I don't get is why this even enters the picture. If it was
a C++ program, with elaboration code that's run when the binary is
loaded in memory, I would understand. But this is a plain C program,
where I imagine the variables are simply located in data, with their
default value provided there. So, even if the program hasn't started
at all, GDB should be able to fetch it from the binary.
That being said, I don't want to hold your patch. I think it's fine
to run the program till main. I was just curious as to why this was
sometimes necessary. Still can't get it :-).