Debug error: new lines stepped through by debugger

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
TaSz_4393831
Level 1
Level 1
First like received First like given

Hi All!

I have a very strange situation in debug mode. If I create a new project, or write new lines of code in older ones, my code looks like dead to the project.  The debugger steps through my lines either i use "step into"(F11) or "step over"(F10) commands. I tried to toggle breakpoints to the new lines, but it didnt work. Never seen like this before, please help me!

Device: CYBLE-416045-02 

0 Likes
6 Replies
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

There could be many reasons to be imagined.

But from my experience, the most likely happened scenario is

when the compiler failed, still I kept on debugging.

Or I debug a board that has a different firmware programmed.

So would you check if

(1) compile(build) succeeded?

(2) you are not skipping the program to the board

If both of the above are confirmed and still facing the same problem,

please clean the project and make archive and upload(attached) the zip file in this topic.

moto

0 Likes
lock attach
Attachments are accessible only for community members.

I checked the listed things, but the problem still occurs (build was succeeced and every firmware is up to date). Can you check my very basic project?

Thank you very much!

Regards, Tamas

0 Likes
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Dear Tamas-san,

First of all, I'm sorry but I don't have a board with the same MCU,  so I can not debug it right away.

May be skimming the following document give you some feeling about what to do.

Getting Started with PSoC 6 MCU with Bluetooth Low Energy (BLE) Connectivity.

https://www.cypress.com/file/385696/download

Seeing your project I noticed that this is a PSoC 6 (or dual core type MCU).

Some thoughts came up to my mind are

(1) Which MCU core are you debugging?

    I suppose that you are debugging the CM4 (main_cm4.c)

(2) Yes, your code seems to be static (= dead) to me,

which means the variables are assigned value at line 20.

  function Foo() called only once.

  The result "sum" is not used at all, which means that the compiler can opt out

  sum, and Foo, then data1, data2... nothing remains...

  And most of all, you have no component(s) in the schematic,

  so there is no input or output in your design!

MAY BE, if you set the compiler's optimization level to NONE,

you might be able to step through the lines. (I'm not sure about it though)

To do it,

From the Project > Build Settings...

In the Build Settings Dialog > Design > CM4 ARM GCC ... > Compiler > Optimization

The "Optimization Level" is set to "Debug" as the default.

000-optimize.JPG

Change it to "None" and select [OK] Button.

000-optimize-none.JPG

Then clean and build the project again.

Try debug now, we might be able to step through.

Or how about changing the project with some real activities?

So how about changing your project as below

(1) schematic add a Digital Output "LED" and assign pin to it

To use debugger, you don't need LED physically attached,

but the pin must be the pin which is not used for other purpose.

000-schematic.JPG

LED Configuration (double click the LED above will show this dialog)

001-LED-pin.JPG

In the Workbench > Workspace Explorer select "Pins" and specify Port for "LED" pin.

002-pin-assign.JPG

I modified the main_cm4.c as below.

I intentionally used "sum" and changed data1 and data2 so that they will not be opt-outed.

main_cm4.c

=================

#include "project.h"

uint8_t Foo(uint8_t a, uint8_t b)

{

    return (a+b);

}

int main(void)

{

    int i ;

  uint8_t count = 0 ;  

  uint8_t data1=1,data2=2,sum;

    uint8_t check;

    /* Place your initialization/startup code here (e.g. MyInst_Start()) */

    sum = Foo(data1,data2);

  

    __enable_irq(); /* Enable global interrupts. */

      

    for(;;)

    {

        data1 = count ;

        data2++ ;

        for (i = 0 ; i < sum ; i++ ) {

            Cy_GPIO_Write(LED_0_PORT, LED_0_NUM, 0) ;

            CyDelay(100) ;

            Cy_GPIO_Write(LED_0_PORT, LED_0_NUM, 1) ;

            CyDelay(100) ;

        }

      

        sum = Foo(data1, data2) ;

        count++ ;

        if (count > 20) {

            count = 0 ;

        }

        if (data2 > 10) {

            data2 = 0 ;

        }

    }

}

=================

Attached is your project with above modifications.

I hope that you can step some of the lines now.

Best Regards,

25-Oct-2019

Motoo Tanaka

MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Dear Tamas-san,

From my curiosity,

I wrote a similar program for PSoC 4

and tried debugging.

source_debug.JPG

I could not step lines,

so I selected menu

   Debug > Windows > Disassembly

Note: this shows us the real code generated from the compiler instead of the original source code.

disassembly_debug.JPG

For the main() function, only 2 lines were generated.

(1) cpsie i

     this is Enable Interrupt => CyGlobalIntEnable;

(2) b.n 162 <main+0x2>

    this is an infinite loop, jumping to the current address.

So as I imagined the line of calling Foo() was optimized out.

It could have been nicer if  (2) was mapped to the line of for(;;)

so that we could at least step twice.

Then I tried to disable optimization

step0_optimize_none.JPG

Then I could step through the program

step1_source_debug.JPG

I could even step-in to Foo()

step2_source_debug.JPG

and the final for() loop.

step3_source_debug.JPG

Best Regards,

25-Oct-2019

Motoo Tanaka

Dear Motoo Tanaka,

You were right, the compiler optimized out the function and the declarations also! I used volatile keyword without changing optimization settings and its worked . I also check what if I abandon volatile and change the settings, and its worked well too! But the how is it possible? I dont change any settings before...its came up from nothing.

I'm very appreciate your help! Thanks a lot!

Regards, Tamas

MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Dear Tamas-san,

If you define a variable as volatile,

any assignment to that variable will not be optimised

even the variable is not referenced from others.

Probably the variable is assumed to be a peripheral or I/O

or accessed in an ISR function. (this line was added on 27-Oct-2019)

Anyway, I also learned a lot from this topic.

Thank you, too 😉

Best Regards,

25-Oct-2019

Motoo Tanaka

0 Likes