Repository navigation
Description
I hope it's OK to post this here in case anybody has some insight even though admittedly it's almost certainly not a GNU ARM Eclipse plugin issue per se (or at all) and I realise that the FAQ says to only post GNU ARM Eclipse issues.
I see here (http://gnuarmeclipse.github.io/debug/openocd/) under "Quote the entire echo command" a snippet about gdb synchronizing with openocd using the -c 'echo "Started by GNU ARM Eclipse"' command.
Is that the sum total of synchronization between gdb and openocd?
At what point does it happen?
In particular does that synchronization ensure that openocd has initialized fully (e.g. gdb/mi port 3333 and telnet port 4444 servers if applicable etc.) or just that it has started up but may still have initialization to do?
My problem is that in some cases it looks like gdb tries to attach to openocd's gdb/mi port 3333 before openocd has successfully initialized that "server" and I get this:
Error in final launch sequence
Failed to execute MI command:
-target-select remote localhost:3333
Error message from debugger back end:
localhost:3333: No connection could be made because the target machine actively refused it.
Failed to execute MI command:
-target-select remote localhost:3333
Error message from debugger back end:
localhost:3333: No connection could be made because the target machine actively refused it.
localhost:3333: No connection could be made because the target machine actively refused it.
Specifically I don't get this if I have one of our FlashPro programmers attached (driven by a custom JTAG driver that I have added to openocd). But if I have more than one then the added time taken to enumerate/init etc. these seems to delay openocd sufficiently that it has not yet initialized the gdb/mi port 3333 server by the time that gdb attempts to connect.
However even though it has not happened to date with a single programmer attached it seems to me that there is some latent race condition between gdb and openocd and it was simply luck that avoided problems previously?
Any tips on how to synchronize gdb and openocd in order to avoid this problem?
Thanks and apologies again if this is somewhat off topic from GNU ARM Eclipse proper.
Regards
Tommy`
Activity
ilg-ul commentedon Mar 7, 2017
let's say it is somehow related, but generally questions should be addressed via the project forum.
unfortunately it is the only portable synchronisation method I could find.
it happens when OpenOCD decides to print this message. in most cases it is when the board is ready.
I have no control over this.
for you to have a reference, the SEGGER J-Link GDB Server, by design, prints a message to confirm it is waiting for connections. this method is a good synchronisation method, and I don't recall such problems with the J-Link plug-in.
OpenOCD does not print such messages, so I had to find a workaround. I personally do not use OpenOCD, and do not recommend it to users.
if you decide to improve OpenOCD, I suggest you contribute a patch to OpenOCD, to print the waiting connection message, and later I can update the plug-ins to use it.
TommyMurphyTM1234 commentedon Mar 7, 2017
Hi Liviu - thanks for the feedback.
That's very useful.
I will investigate further on the openocd side of things.
Just to clarify one thing - I guess that the plugin waits for the "Started by GNU ARM Eclipse" string to appear from openocd?
What does it do once it sees it?
Regards
Tommy
ilg-ul commentedon Mar 7, 2017
starts the GDB client.
TommyMurphyTM1234 commentedon Mar 7, 2017
Thanks Liviu - I was confusing gdb starting openocd (piped mode) with socket mode used here where openocd and gdb are started separately (in this case by the plugin). I'll continue looking into this to see if I can get a better solution. At the moment the only one I have is to put a counter delay at the top of gdbinit which is a real hack! :-)
ilg-ul commentedon Mar 7, 2017
yeah, you can switch to J-Link.
TommyMurphyTM1234 commentedon Mar 7, 2017
I hear ya! :-) But unfortunately I have to support OpenOCD in this case. :-(
Thanks a lot for your feedback on this issue.
TommyMurphyTM1234 commentedon Mar 7, 2017
In case it helps anybody else ... one hack (obviously not ideal) which helps is to delay for a period before allowing gdb to proceed. The period to delay will vary and must be chosen by trial and error.
One way to do this in a portable way (since Windows doesn't seem to have a workable equivalent of
shell sleep x) is to useping- e.g. change Debugger > GDB Client Setup > Commands toWhere
-nspecifies the number of seconds (- 1?) to delay and the value needs to be large enough to give OpenOCD time to fully init.But as I said it's just a hack and the value may differ from one machine/environment/load to another.
TommyMurphyTM1234 commentedon Apr 5, 2017
FWIW I have worked around this for now using my own hack to OpenOCD but this is not an ideal/general fix for everybody. When I get the time I will follow up on this with the OpenOCD project - e.g. start a discussion about the issue and maybe request an enhancement to address it.
For now here is my code change to
src/openocd.c(0.10.0 release version) in case it helps anybody else:Liviu - I presume that you build OpenOCD as-is and don't apply any of your own patches/mods to it?
ilg-ul commentedon Apr 5, 2017
that's correct. unless absolutely necessary, I avoid adding patches, since they increase maintenance cost.
unfortunately your patch is not very fortunate, I would search for a more elaborate solution.
TommyMurphyTM1234 commentedon Apr 5, 2017
I agree but I am using that for now as I build OpenOCD with some other mods right now.
As I said I will chase it up with the OpenOCD project when I get a chance - hopefully soon.
Thanks.
ilg-ul commentedon Apr 5, 2017
a more portable trick would be a small delay in ms, default 500, user configurable in the plug-in.
TommyMurphyTM1234 commentedon Apr 5, 2017
I don't think that depending on a timed delay is a good idea.
I think your original idea of having openocd (optionally?) emit some message/banner to announce when it is truly ready for connections is a better idea.
Or having it delay processing command line specified "echo" commands until it is ready for connections so that the existing synchronization with the "Started by GNU ARM Eclipse" output works as is.
As I said I'll flag the issue with the OpenOCD project ASAP to see what they think about this and to see if it has been reported/mentioned before now.
ilg-ul commentedon Apr 5, 2017
if you manage to push some changes to the mainstream openocd to have a stable, 100% reliable way of getting this message, even if when enabled by a switch or command, then I'll consider updating the plug-in, although we need to maintain compatibility with older versions too.
18 remaining items
ilg-ul commentedon Sep 4, 2017
if you confirm that hunting for this string solves your problem, I'll update the plug-ins.
TommyMurphyTM1234 commentedon Sep 4, 2017
Hmmm - yes - forward compatibility is always a challenge... :-|
Thanks - I'm looking into it now with my modified GME openocd plugin and will do some experimentation and report back.
BTW - in relation to earlier questions about the relative timing of messages from OpenOCD this might clarify:
The "Listening on port 3333 for gdb connections" message seems to be a SiFive addition - not sure why.
Note that the "Started by GNU MCU Eclipse" message appears very early on and (in relative terms) well before the "accepting 'gdb' connections on tcp/3333" message.
In some (many?) cases the intervening initialization will happen "quick enough" that by the time the plugin starts gdb and it tries to make a GDB RSP connection to port 3333 everything is ready and it works.
But in some cases (e.g. a JTAG interface driver that takes "longer" to init - such as ours) then this will not be the case and GDB will be launched and will attempt a GDB RSP connection to 3333 before the socket it completely ready.
AntonKrug commentedon Sep 4, 2017
I apologise if this is a stupid question, but would it be viable to probe the port with netstat or lsof to see if the advertised port is really LISTENING?
Not even sure if there is Windows equivalent for it.
ilg-ul commentedon Sep 4, 2017
as long as it is intended to help, there is no such thing as a stupid question.
it might work, but:
it seems complicated and heavy.
truhlikfredy commentedon Sep 4, 2017
Probing it on Java level gets rid of the parsing:
http://www.geekality.net/2013/04/30/java-simple-check-to-see-if-a-server-is-listening-on-a-port/
But I'm not sure that a empty connection and disconnecting will trigger something undesired on the openOCD side.
I was trying to change the wait till the "accepting 'gdb' connection" and I got timeouts, so I wondered if I never received that text.
So I put lot of System.out.println and run eclipse with -consoleLog and for some reason last text I received was the "Started by GNU ARM Eclipse". I'm wondering would it be possible that something interrupts/breaks the error pipe and I'm not receiving any more information from the current pipe?
ilg-ul commentedon Sep 4, 2017
where exactly is written the openocd log, to stdout or stderr? is it the same stream as the one used for
-c echo?TommyMurphyTM1234 commentedon Sep 4, 2017
This is what we were getting in the log (e.g. when Eclipse is launched with -consoleLog):
The "accepting 'gdb' connections on tcp/3333" message does't appear there even though it is appearing in the OpenOCD log in Eclipse and is going to the stderr as it's coloured red in the console and other LOG_INFO messages are obviously visible to the plugin Java code.
It's very very odd....
TommyMurphyTM1234 commentedon Sep 4, 2017
Just to clarify - Anton sees "Started by GNU ARM Eclipse" last because he is using a version of OpenOCD with my ugly hack that moves this log message to the end of openocd.c:openocd_thread() instead of it appearing at the start as it normally does in the unhacked openocd.
ilg-ul commentedon Sep 4, 2017
it looks like there was a good reason why I used the
-c echohack...truhlikfredy commentedon Sep 4, 2017
In our case it should be the stderr
I should probably try the same with the vanilla OpenOCD. I tried to debug the plugin, so I got the Eclipse SDK and I got so far that the SDK Eclipse was able to compile the plugin and then run Eclipse Oxygen with it, but I didn't far enough to be able to debug it.
Something odd/funny is on the OpenOCD which doesn't not work well with the pipes the way they are handled.
h4tr3d commentedon Dec 7, 2017
Hi guys!
By the way, I found that GDB 8.0 + OpenOCD 0.10.0 in most case unusable combination in case, when some RTOS (ThreadX in my case) is used and RTOS support module used by OpenOCD. Often I observe such messages when try to stop process:
All work good with GDB 7.7.1 (original) and 7.8 (Linaro branch) and OpenOCD 0.10.0. Currently I have no ideas how it report and just freeze used GDB version.
Issue found on Manjaro Linux using GDB located in repos and Qt Creator, but I reproduce issues using only GDB and OpenOCD from command line. I deal with Cypress FX3 chip in our production board.
ilg-ul commentedon Dec 7, 2017
I cannot confirm it, for my RISC-V tests I use the latest GDB and the latest OpenOCD and did not encounter this problem.
h4tr3d commentedon Dec 7, 2017
Cypress FX3 uses ARM926E-JS core and RTOS ThreadX. OpenOCD ability to handle RTOS threads is used too. Seems, that RTOS and it handling on the OpenOCD/GDB side is a major thing.
TommyMurphyTM1234 commentedon Dec 7, 2017
I don't see what these posts have to do with the original topic of this thread?!
ilg-ul commentedon Dec 7, 2017
they probably don't.
@h4tr3d, for support and general questions, please use the project forum.