So that's a different approach: integrate a remote debugging GDB server into the program (could be a shared lib that is dlopen-ed, by the way). Then that server is always used, even in a local session. The server is deeply integrated into the program, taking advantage of the protocol to communicate between application code and the debugging client.
It sounds promising. A particularly interesting area is events:
https://sourceware.org/gdb/onlinedocs/gdb/Notification-Packe...
The program could generate custom notifications.
https://sourceware.org/gdb/onlinedocs/gdb/Remote-Protocol.ht...
In your program you would probably need to link in some code to implement the protocol, like the GDB remote stub:
https://sourceware.org/gdb/onlinedocs/gdb/Remote-Stub.html
Qemu and Valgrind both implement their own gdb stubs.
For ARM targets, there is a similar feature named "semihosting":
http://www.keil.com/support/man/docs/armcc/armcc_pge13587870...