Turn off Compiler Optimization in Modustoolbox Eclipse IDE

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

cross mob
lock attach
Attachments are accessible only for community members.
shsh_4753781
Employee
Employee
10 sign-ins 5 sign-ins First reply posted

Hello, I am trying to debug PDM to I2S sample example, I want to see the values inside the variables but it comes as <optimized value>. For example cy_rslt_t result , the result appears as optimszed.

The toolchain setting dont provide an option to directly turn off the optimisation.

Refer the screenshot here.

The make file has 

INCLUDES=

# Add additional defines to the build process (without a leading -D).
DEFINES=

# Select softfp or hardfp floating point. Default is softfp.
VFP_SELECT=

# Additional / custom C compiler flags.
#
# NOTE: Includes and defines should use the INCLUDES and DEFINES variable
# above.
CFLAGS =

# Additional / custom C++ compiler flags.
#
# NOTE: Includes and defines should use the INCLUDES and DEFINES variable
# above.
CXXFLAGS =

# Additional / custom assembler flags.
#
# NOTE: Includes and defines should use the INCLUDES and DEFINES variable
# above.
ASFLAGS=

# Additional / custom linker flags.
LDFLAGS=

# Additional / custom libraries to link in to the application.
LDLIBS=

 

Setting these CXX nd CFlags as -g -O0 or -O also does not work.

How can I turn/skip optimizations in order to see the actual values. I was using volatile keyword until now but that can not be permanent solution. It has to do something with setting the compiler flags correctly.  Can you please help me on this?

0 Likes
1 Solution
Rakshith
Moderator
Moderator
Moderator
250 likes received 1000 replies posted 750 replies posted

Hi @shsh_4753781

Can you please let me know if the variable is used anywhere? If the variable is not used then gcc will not generate the code. Maybe this thread will help -  gcc -O0 still optimizes out “unused” code. Is there a compile flag to change that?

Thanks and Regards,
Rakshith M B

View solution in original post

0 Likes
2 Replies
Rakshith
Moderator
Moderator
Moderator
250 likes received 1000 replies posted 750 replies posted

Hi @shsh_4753781

Can you please let me know if the variable is used anywhere? If the variable is not used then gcc will not generate the code. Maybe this thread will help -  gcc -O0 still optimizes out “unused” code. Is there a compile flag to change that?

Thanks and Regards,
Rakshith M B
0 Likes
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

shsh,

If your are using a variable and during debugging it appears to be "optimized" try placing a "volatile" at the beginning of a variable declaration.

For example the following variable might be optimized:

 

int some_function(int some_var)

{

int var2debug;  /* This autovar can be optimized to a register */

...

}

 

However by placing a "volatile" in front of the declaration, it forces the variable to be stored in a physical memory location instead of a CPU register.

 

int some_function(int some_var)

{

volatile int var2debug;   /* This forces the compiler/linker to find a memory location */

...

}

 

 

However as Rakshith indicated, if the variable is declared but never used, the linker will optimize it out even if a "volatile" is used.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes