Page 1 of 1
Disable optimization (optimize for JTAG debugging)
Posted: Sat Jul 29, 2017 12:31 pm
by xrCyhxcPN
Hi all,
I would like to disable any optimization of the C code. I am using the Eclipse IDE, having the CFLAGS env variable set to optimize for gdb.
It this the right approach? When debugging via JTAG, I still can see cases when I hover over a varaiable, it says "Optimized Out".
Thanks and best regards
Patrick
Re: Disable optimization (optimize for JTAG debugging)
Posted: Fri Nov 02, 2018 9:56 am
by k.ifantidis
Hello I'm looking for the same stuff here. How am i supposed to disable the compiler optimization ? I've checked sdkconfig file and it seems that there are only 2 options as mentions in the "readthedocs" website. -Og (debug) and -Os (release).
The reason why I want to disable the optimization is because when I'm debugging my code some of my variable's values are characterized as "<optimized out>" and I can't see the vale of this variable. I do not know all stuff about a compiler but with some research in the web I've found out that I should turn off compiler's optimization.
Re: Disable optimization (optimize for JTAG debugging)
Posted: Fri Nov 02, 2018 10:54 am
by PaulVdBergh
My guess is the compiler put these variables in registers, so they are optimized away. Try to make them volatile ?
Paul.
Re: Disable optimization (optimize for JTAG debugging)
Posted: Fri Nov 02, 2018 1:43 pm
by k.ifantidis
Dear Paul, thank you for your reply.
Firstly I would like to describe my situation. I'm inside a module's function which is started as a Task from main.
I've used my breakpoint right in the begging of the task and I've also set-up the expressions that I want to watch (test var).
Case 1. Variable declared inside func(local var) the compiler optimizes the value of the variable and I can not see it's contents.
Case 2. Variable declared volatile inside func( volatile uint8_t test = 0;) -> variable's value becomes unavailiable.(attached img)
Case 3. Declare the variable global (tested both volatile and non-volatile declaration)-> It works like a charm.
What am I supposed to do ?! I want to avoid declaring my variables as global :-/ It was quite hard for me to get used to using local variables that I don't want to go back to using globals.
Regards, Kostas.
Re: Disable optimization (optimize for JTAG debugging)
Posted: Sat Nov 03, 2018 2:43 pm
by PaulVdBergh
Hi Kostas,
If it's only to observe the value of some variables, why not use any kind of the printf or LOGx() functions? It's only for debugging, isn't it? Keep in mind that making a varaible global or static whitin a function makes the function non-reenrtant.
Paul
Re: Disable optimization (optimize for JTAG debugging)
Posted: Mon Nov 05, 2018 10:38 am
by k.ifantidis
Thank you for your reply. I'll keep this in mind !!
I've used printf in order to read the optimized variable.
Best regards, Kostas.