Related to this, I have this change in https://github.com/riscv/riscv-openocd.
The intent is to allow automated software to know when OpenOCD is ready for gdb
to connect to it:
```
diff --git a/src/server/server.c b/src/server/server.c
index 8009d40..f3ae34e 100644
--- a/src/server/server.c
+++ b/src/server/server.c
@@ -273,7 +273,8 @@ int add_service(char *name,
c->sin.sin_port = htons(c->portnumber);
if (bind(c->fd, (struct sockaddr *)&c->sin, sizeof(c->sin)) ==
-1) {
- LOG_ERROR("couldn't bind %s to socket: %s", name,
strerror(errno));
+ LOG_ERROR("couldn't bind %s to socket on port %d: %s",
name,
+ c->portnumber, strerror(errno));
close_socket(c->fd);
free_service(c);
return ERROR_FAIL;
@@ -298,6 +299,12 @@ int add_service(char *name,
free_service(c);
return ERROR_FAIL;
}
+
+ struct sockaddr_in addr_in;
+ socklen_t addr_in_size = sizeof(addr_in);
+ getsockname(c->fd, (struct sockaddr *)&addr_in, &addr_in_size);
+ LOG_INFO("Listening on port %d for %s connections",
+ ntohs(addr_in.sin_port), name);
} else if (c->type == CONNECTION_STDINOUT) {
c->fd = fileno(stdin);
```
---
** [tickets:#147] How to know when OpenOCD is fully ready?**
**Status:** new
**Milestone:** 0.9.0
**Created:** Tue Mar 07, 2017 11:29 PM UTC by Tommy Murphy
**Last Updated:** Sat Sep 02, 2017 09:37 PM UTC
**Owner:** nobody
Hi there - I searched the existing tickets but didn't see any obvious mention
of this issue.
I cannot see any way to know that OpenOCD is fully initialized and ready to
accept connections - e.g. GDB/MI connections on port 3333 (by default). For
example the GNU ARM Eclipse plugins call OpenOCD with any user specified
command line options as well as -c 'echo "Started by GNU ARM Eclipse"' and then
waits for OpenOCD to output the string "Started by GNU ARM Eclipse" before
starting gdb which will then connect to OpenOCD's GDB/MI socket interface via
target remote ... etc. See
https://github.com/gnuarmeclipse/plug-ins/issues/186#issuecomment-284703073.
Liviu Ionescu (creator of GNU ARM Eclipse) chose this as the only way he could
see to attempt to synchronize OpenOCD with gdb so that gdb was only launched
when OpenOCD was ready. However there is still a race condition here as OpenOCD
processes the echo command before it has fully initialized the target
interface, opened/initialized the GDB/MI socket interface etc. In some cases
OpenOCD may be fuly ready for gdb by the time that gdb connects but if the
OpenOCD startup/init code takes "too long" then it may not and then gdb fails
to connect.
Is there any mechanism whereby a process can know that OpenOCD is "fully ready"
before starting another process such as gdb which will connect to it? Even if
OpenOCD output a simple string indicating that the relevant interface was
initialized and ready for connections would help (e.g. Ready for GDB/MI
connections on port 3333").
Any suggestions?
Thanks a lot.
---
Sent from sourceforge.net because [email protected] is
subscribed to https://sourceforge.net/p/openocd/tickets/
To unsubscribe from further messages, a project admin can change settings at
https://sourceforge.net/p/openocd/admin/tickets/options. Or, if this is a
mailing list, you can unsubscribe from the mailing list.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
OpenOCD-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openocd-devel