debugger not stopping at breakpoint, but 2 lines later

Post here first, or if you can't find a relevant section!
Post Reply
STM32_Newbbe
Posts: 50
Joined: Thu Nov 05, 2020 10:26 am

debugger not stopping at breakpoint, but 2 lines later

Post 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
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

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

Post by fpiSTM »

Ensure to disable optimisation.
-O0 instead of -Os
STM32_Newbbe
Posts: 50
Joined: Thu Nov 05, 2020 10:26 am

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

Post 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?
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

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

Post by fpiSTM »

yes some optimization are done. So if you want exactly saw where you are you should enable assembler view.
STM32_Newbbe
Posts: 50
Joined: Thu Nov 05, 2020 10:26 am

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

Post by STM32_Newbbe »

thanks
Post Reply

Return to “General discussion”