[Open SoC Debug] CDM: Next Steps

Philipp Wagner philipp.wagner at tum.de
Sat Jun 23 17:25:05 CEST 2018


Hi Shivam,

Am 23.06.2018 um 14:21 schrieb SHIVAM AGGARWAL:
> I went through the implementation of gdbserver in openOCD and QEMU over
> the last week.

Great, you probably are now a bit confused, a bit enlightened and
hopefully not overly scared. It's now time to get your hands dirty by
writing code to try things out.

> 4. *gdbserver.c*
> 
> Here’s how this program will work:
> 
> 1. The gdb server first connects with OSD host controller and verifies
> the connection.

What is the host controller doing here? And what do you mean by
"verifies connection"?

> 2. On success, gdbserver waits for connection from client - GDB
> 
> 3. It calls socket() to make a socket which will listen for connections.
> 
> 4. It then calls bind() to bind our socket to the port number and
> listen() to indicate that we want to accept incoming connections.
> 
> 5. It then accepts the socket that has been created with socket() and
> bound to an address with bind() and that is listening for connections
> after a call to listen(). 
> (add_service() function
> http://repo.or.cz/openocd.git/blob/HEAD:/src/server/server.c#l203 )
> 
> The client will be added to the end of a linked list. This is to ensure
> that we can connect TELNET as the client along with GDB to test our program.
> 
> 6. It then accepts the connection and transfers the control to functions
> for reading/writing data over TCP.

Step 1-6 are the standard setup setups for a TCP connection, nothing
special here for GDB. You can find tons of code on the internet that
shows and explains how that is done.

> 7. The rest program implements the API for RSP protocol and calls
> functions from target.c to add_target, read/write registers, etc.
> 
> This program code accomplishes the above tasks:
> http://repo.or.cz/openocd.git/blob/HEAD:/src/server/server.c
> http://repo.or.cz/openocd.git/blob/HEAD:/src/server/gdb_server.c

I just read through
https://www.embecosm.com/appnotes/ean4/embecosm-howto-rsp-server-ean4-issue-2.html,
which quite well explains the GDB Remote Server protocol. Based on my
(not exhaustive) understanding you need:

1) Code to listen to a TCP socket for incoming connections from the GDB
(client).

2) Code to create and unpack the RSP packets according to the specs.

3) Code that does the actual work, i.e. that handles the commands GDB
sends to the gdbserver instance.

The first two parts are fundamental infrastructure which you cannot
reduce in scope. Since the RSP protocol is rather old and not very fancy
writing an implementation based on the specs should be viable.

For part 3 you can reduce the number of supported commands to a minimum
to demonstrate an initial solution, and/or hard-code some things instead
of dynamically reading them from the target system.

You can place all code required for this implementation in a new file
e.g. osd_gdbserver.c/.h. You can then create a standalone application,
e.g. osd-gdbserver, which uses this class (similar to osd-target-run,
only much simpler).

With these two parts you already should be able to have GDB connect to
your gdbserver implementation. By issuing commands in GDB and seeing how
they are received in your implementation it should be easier to make
progress, since you can develop and test your work in a small little
island instead of involving the full OSD stack.

A final note of warning: you can of course copy code from other
implementations, but please be aware of license restrictions. OSD is
licensed under the MIT license, so you may take code from other projects
which are MIT, BSD or public domain. You may not take code from GPL,
LGPL or similarly licensed projects. If you are unsure please ask. (You
can of course read and understand the source code, and then implement it
on your own.)

Philipp


More information about the OpenSoCDebug mailing list