I am writing a simulator program for a custom microcontroler in C++. I would like a user to be able to use GDB to debug their program as if it was running on the real target.
The best solution I've found seems to involve writing a GDB stub for my simulator that would communicate with GDB using a network protocol. However, this involves writing a complete program that would take care of network communication and communication with GDB itself.
This seems a bit overkill since the client and the target will be running on the same machine. Is there not a simpler way? If there is not, with the popularity of GDB, I would have thought that a library, or at least examples, would exist to help embedding a stub in a normal desktop PC program?
You can certainly write a "stub" that is part of the main application - all that you need to do is listen to the relevant communications channel, and respond appropriately to the commands/data being sent.
Here's an article that fairly well describes the process of writing a stub: http://www.embecosm.com/appnotes/ean4/embecosm-howto-rsp-server-ean4-issue-2.html
It also discusses (albeit briefly) the "using a simulator".