How do gdb and OpenOCD communicate?

It says in the OpenOCD wiki that OpenOCD runs as a daemon, waiting for connections from clients (Telnet or GDB). What is a connection in this context, how do they connect? Through what meduim do they communicate? I guess the connection is using the [gdb remote protocol if it’s connected to gdb.](http://sourceware.org/gdb/current/onlinedocs/gdb_33.html#SEC702)

openocd listens on TCP/IP port 4444 for telnet and 3333 for gdb. (Default port numbers that can be changed.) Once running, you can:

> telnet localhost 4444

This gives you a prompt that you can type commands in:

Open On-Chip Debugger
> poll
target state: halted
target halted in ARM state due to debug request, current mode: System
cpsr: 0x200000df pc: 0x000015b0
> exit

You can telnet in from a different computer, as long as there’s no firewall in the way. I guess the ‘medium’ in this case would be ethernet, but the most common case would be connecting from the same computer you’re running the openocd server on.

gdb can also make a connection to openocd through TCP/IP to a different port (default 4444). It communicates with its own protocol. Again, the common case is to run gdb on the same machine and connect to the localhost.

So, even if OpenOCD is running on the same computer as gdb, it still communicates through TCP/IP (I guess this is what I ment by medium :slight_smile: ) … is there some documentation telling how to do this? I’m writing an own program for MIPS systems, and I can’t find anything in the gdb manual about this… :confused:

I don’t know much about it, but Googling “gdb remote target” returned some info, especially chapters 16 and 17 of:

http://sourceware.org/gdb/download/onlinedocs/gdb.html

gdb’s “monitor” command will send things directly to openocd. An example series of gdb commands that connects to openocd on the localhost at its default port 3333 would be something like this:

target remote localhost:3333
monitor reset
monitor armv4_5 core_state arm
monitor mww 0xffffff64 0x5a000004
monitor poll

load
break main
continue