4
votes

For the needs of project, I wrote a simple java socket program to implement a "fake" gdbserver stub. Thus, support the minimum number of gdb RSP commands:g,G,m,M,c and s. For other commands, just response with "$#00". According to the manual of gdb, this would tell gdb that the "server" doesn't support other commands.

I use the Eclipse CDT to help me debug. In the debug configurations, I selected c/c++ remote application, and set the debugger connection using TCP on localhost:10000, where my java program will use to listen.

At first, gdb send commands like qSupported, Hg0, qTStatus, ?, and qC. The response to all of them are "$#00" to tell gdb the "server" doesn't support those commands. Then, gdb send qAttached and qOffsets. After sending two "$#00" responses and received a "+" from gdb, gdb says "warning: invalid remote reply:".

Can someone please tell me why did this occur? Why gdb doesn't send commands and say"invalid remote reply:", which I don't know what reply is invalid, after all, I just send "$#00" and "+" to gdb.

1
Not that I'll be able to help you, but it might make it more clear what is happening in your scenario if you showed a log of the actual conversation between GDB and your stub in a format similar to the examples used in the GDB docs: sourceware.org/gdb/onlinedocs/gdb/Examples.html#ExamplesMichael Burr
I'm new to gdb and not sure how to generate that kind of conversation. But after I generate a "$S05#" response to "$?#", gdb seems work. It send "$g#" request and "$p8#" request. But now I get "PC register is not available" error after response to "$p8#" with "$#00"...Daniel
I too can't help you fully, but what I understood from the last sentence of this page: sourceware.org/gdb/onlinedocs/gdb/Overview.html#Overview, is that a minimal stub must support commands: 'g', 'G', 'm' and 'M'. In case not the comm will fail. And you don't as per your last comment.Frankie_C
Should be OK to not support "P". To see remote protocol logging: "set debug remote 1". Presumably, since you are writing the server, you can make it write a log file with sent and received data.joeking
Also, if you create a file ".gdbinit" in your home directory, you can put commands like "set debug remote 1" and "set remotelogfile /tmp/remotelog.txt" into it - and it should get executed even when you start GDB from eclipse. I'd strongly suggest though that you run GDB from shell directly to start with - just to reduce the complexity - since Eclipse is going to be sending a bunch of GDB commands.joeking

1 Answers

2
votes

This baffled me too when I read the GDB manual. I suspect that the set of commands you need to implement (i.e. those that should effect the state of your simulator) is a subset of the commands your server needs to be able to reply to.

This excellent guide to writing an RSP server by Embecosm has a very handy sequence diagram in Section 3.1 which describes the initial handshake between GDB and your RSP server:

Handshake sequence diagram

Once you have the handshake working, it's much easier to see how the protocol fits together and start writing in the code that interacts with your simulator (or other target).