-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DebugWire/GDB] Cannot execute command while target is running #87
Comments
(Btw., there is a "Discussions" section as well.) First of all, you need AVRDUDE to the very least to program the debugWIRE is a bit of a strange beast: it's not a genuine debugging mode (as JTAG or UPDI is), but rather a monitor ROM. (You can see that still in one spot in the docs, where it says Reset with MonCon disabled.) That primarily means that you only can do those things in the debugger the CPU can do – altering fuses explicitly does not belong to that feature set. Likewise, there are no data breakpoints ("watchpoint" in GDB terms), and code breakpoints are handled by the ICE reflashing the respective flash page with a The bad thing with that is, until you enable the In order to return from debugWIRE mode, the ICE has to issue the mentioned Reset with MonCon disabled instruction. The next reset (but no power-on!) then temporarily returns the /RESET pin to its original function, so normal ISP can proceed. This state is maintained until the next power cycle, when the fuses are re-evaluated. If The downside is that such a setup cannot be operated without the option to occasionally power-cycle the target, for obvious reasons. AVRDUDE handles all that by starting in normal ISP mode. When it fails to enter ISP mode on a target that has debugWIRE capabilities, it next attempts to issue the respective "return from debugWIRE" command, and restarts the ISP initialization. If debugWIRE did work, this ISP session can then be used to upload new flash contents, and/or to alter fuses. (Unlike Atmel/Microchip Studio, which then always turns off I hope that made the entire picture a bit clearer … if anyone feels like it, we could start a set of "recipes" or such in Wiki to record that as hints for the users. |
Thank you for the awesome in-depth writeup. But this only answers the question:
I still have no clue what causes the "Cannot execute command while target is running". Do you have any clue? The parameters I'm using are:
Seems pretty standard... |
What you are showing is only the AVaRICE side (the GDB server). |
What exactly do you want to see? |
What arre yoiur AVR-GDB commands used? Here is a full transaction. First, AVRDUDE and AVaRICE side:
(At that point, it just waits for GDB to connect. That's the part quoted below.)
(I have to force an ATmega168P because AVaRICE currently doesn't know about the ATmega168PB used.) Here is the GDB end:
|
Your instructions work, as I expected. I had one more go at it, and this time captured the traffic between GDB and the server. This is the traffic when PlatformIO is involved: https://pastebin.com/k47erNvv I tried to add a breakpoint here, but it still got me the "Cannot execute command while target is running" error. And this is the traffic when PlatformIO is not involved - so AVaRICE directly to CLion: https://pastebin.com/CHSgVa9u When I tried to add a breakpoint in the latter scenario, it replied with Reading this traffic is beyond my knowledge, but maybe you might spot something... |
Well, I don't really have an idea what PIO is all doing here. (I've been using PIO only on Cortex-M devices in the past.) |
What I also found is that debugging seems to work (it breaks correctly on the breakpoints), but there is no feedback in the IDE. For example, when I place a breakpoint in a very simple LED blink program (on delay), it stops. However, the IDE doesn't report anything about it. Clearing the breakpoint gets the execution going again. Could it be that the GDB client of CLion tries to use some GDB options the gdb server of AVaRICE doesn't support? Remember, this is not via PIO, but CLion directly launching AVaRICE and attaching to it. (See also the last log link in my previous post, no PIO involved there) |
Sure, if they try to directly forward GDB server commands ("monitor" command in GDB), this can happen. These commands are always specific to the actual GDB server implementation. For example, to trigger an MCU reset, with AVaRICE you say (inside GDB) "monitor reset", while in OpenOCD (e.g for Cortex-M) you say "monitor reset halt". Can you upload a full minimal project? Sorry, I don't have the slightest idea about what CLion does. |
One point a friend just remarked: are you sure the AVaRICE versions used by Platform.IO and on your commandline are the same? After all, Keep in mind that Platform.IO tends to prefer its own locally installed tools over the system-wide tool installations. |
PIO doesn't have AVaRICE by itself - it supports using a custom debugger. I cloned the repository and used compiled it. I'm using CLion 2021.3.3. This is the sourcecode I used - it's purely to test the debugger, nothing special: main.cpp #include <Arduino.h>
void setup() {
// put your setup code here, to run once:
int ledPin = 13;
pinMode(ledPin, OUTPUT);
}
void switchLED(int pinId) {
bool newState = !digitalRead(pinId);
digitalWrite(pinId, newState);
}
void loop() {
// put your main code here, to run repeatedly:
int ledPin = 13;
int oneHzDelay = 1000;
int twoHzDelay = 500;
int amountOneHz = 2;
int amountTwoHz = 16;
for(int i = 0; i < amountOneHz; i++) {
switchLED(ledPin);
delay(oneHzDelay);
}
for(int i = 0; i < amountTwoHz; i++) {
delay(twoHzDelay);
switchLED(ledPin);
}
} platformio.ini
And these are the debugger settings I'm using: If you test without AVaRICE without PIO, obviously make sure it does compile with debugging options. Edit: I might add that if you use PIO, just select the 'Arduino Uno' option from the boards list - you can also directly use the CLion debugger when using PIO (see the attached screenshot) |
Well, someone else seems to have "stolen" the screenshot already … you could always attach it here if you think it's needed. Well, I'm not sure, your pio_reset_halt_target is empty. You could try putting "monitor reset" into it. (For pio_reset_run, it would be "monitor reset", then "continue" in a second line.) Where / how did you program the DWEN fuse? Somewhere outside, using a manual AVRDUDE command? |
Yes, I was having trouble with those (GDB errored with 'pio_reset_run: no such command'). I will try those lines. I programmed the fuses using AVRDUDE and I am sure DWEN is enabled correctly. Edit: I tried including the 'monitor reset' commands and it made no difference, unfortunately. |
I'm trying to get AVaRICE working with PlatformIO and CLion for debugging (using debugwire). It seems pretty straight forward, but I can't get it working.
The debugger initializes and shows a (suspiciously empty) hex file. From there, it just freezes. I can't add any breakpoints, pause or resume don't work. The error from the GDB server is "Cannot execute command while target is running".
I get similar results when I directly access the GDB server, so I suspect it's not related to the IDE I'm using.
Also, is it nessecary to flash the firmware before using AVaRICE? I can't find a way to disable the DWEN fuse on macOS, as with the GDB server open the USB port is occupied and I can't launch avrdude to do so.
Sorry for creating a bug report for this, I couldn't find any other ways to get in touch.
I might add that debugging is working fine in Microchip Studio - obviously. But I would like to use an open source toolchain as it's not available on macOS and MPLabX doesn't fit my needs.
The text was updated successfully, but these errors were encountered: