Page 1 of 1

debugger not stopping at breakpoint, but 2 lines later

Posted: Tue Aug 23, 2022 12:25 pm
by STM32_Newbbe
After I got debugging to work, I now sometimes have the issue that the program does not halt at the exact position I set a breakpoint, but one or two lines later.
Since I am fairly new to debugging the stm32(duino), I am not sure what can cause this behaviour.

I have a slightly modified Arduino Web Server example and I set a breakpoint in the W5100.cpp on line 285

Code: Select all

phystatus = readPHYCFGR_W5500();
in function

Code: Select all

W5100Linkstatus W5100Class::getLinkStatus()
{
	uint8_t phystatus;

	if (!init()) return UNKNOWN;
	switch (chip) {
	  case 52:
		SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
		phystatus = readPSTATUS_W5200();
		SPI.endTransaction();
		if (phystatus & 0x20) return LINK_ON;
		return LINK_OFF;
	  case 55:
		SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
		delay(1000);
		phystatus = readPHYCFGR_W5500();
		SPI.endTransaction();
		if (phystatus & 0x01) return LINK_ON;
		return LINK_OFF;
	  default:
		return UNKNOWN;
	}
}
the delay is a change I made

The debugger stops on line 287

Code: Select all

if (phystatus & 0x01) return LINK_ON;
This is a bit annoying since, I am hunting down a problem where I get incorrect LinkStatus when running normally, but the correct Linkstatus when debugging and stepping through the functions and statements.
And this is the exact location where I want to check what could possibly be the difference

Re: debugger not stopping at breakpoint, but 2 lines later

Posted: Tue Aug 23, 2022 12:48 pm
by fpiSTM
Ensure to disable optimisation.
-O0 instead of -Os

Re: debugger not stopping at breakpoint, but 2 lines later

Posted: Tue Aug 23, 2022 1:09 pm
by STM32_Newbbe
I had -Og (debug), but changing it to O0 makes the debugger halt on point :)
Thank you very much !!

Does this mean that with -Og, there is still some optimization going on, that is deemed safe, but nonetheless interferes with the debugger?

Re: debugger not stopping at breakpoint, but 2 lines later

Posted: Tue Aug 23, 2022 1:48 pm
by fpiSTM
yes some optimization are done. So if you want exactly saw where you are you should enable assembler view.

Re: debugger not stopping at breakpoint, but 2 lines later

Posted: Wed Aug 24, 2022 5:22 am
by STM32_Newbbe
thanks