Disable optimization (optimize for JTAG debugging)

xrCyhxcPN
Posts: 6
Joined: Sun Jul 23, 2017 8:43 am

Disable optimization (optimize for JTAG debugging)

Postby xrCyhxcPN » Sat Jul 29, 2017 12:31 pm

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
Attachments
eclipse-disableOptimization.png
eclipse-disableOptimization.png (59.64 KiB) Viewed 8816 times

k.ifantidis
Posts: 33
Joined: Wed Mar 28, 2018 6:58 am

Re: Disable optimization (optimize for JTAG debugging)

Postby k.ifantidis » Fri Nov 02, 2018 9:56 am

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.
Attachments
optimized_out_variables.jpg
optimized_out_variables.jpg (10.89 KiB) Viewed 8395 times

User avatar
PaulVdBergh
Posts: 58
Joined: Fri Feb 23, 2018 4:45 pm
Location: Brasschaat, Belgium

Re: Disable optimization (optimize for JTAG debugging)

Postby PaulVdBergh » Fri Nov 02, 2018 10:54 am

My guess is the compiler put these variables in registers, so they are optimized away. Try to make them volatile ?

Paul.

k.ifantidis
Posts: 33
Joined: Wed Mar 28, 2018 6:58 am

Re: Disable optimization (optimize for JTAG debugging)

Postby k.ifantidis » Fri Nov 02, 2018 1:43 pm

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.
Attachments
optimized_out_variables02.jpg
optimized_out_variables02.jpg (9.48 KiB) Viewed 8381 times

User avatar
PaulVdBergh
Posts: 58
Joined: Fri Feb 23, 2018 4:45 pm
Location: Brasschaat, Belgium

Re: Disable optimization (optimize for JTAG debugging)

Postby PaulVdBergh » Sat Nov 03, 2018 2:43 pm

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

k.ifantidis
Posts: 33
Joined: Wed Mar 28, 2018 6:58 am

Re: Disable optimization (optimize for JTAG debugging)

Postby k.ifantidis » Mon Nov 05, 2018 10:38 am

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.

Who is online

Users browsing this forum: ESP_Roland, gomez9656, Google [Bot], Majestic-12 [Bot], tahseenabbas52 and 53 guests