Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic nrf51822 + STLink Hardware Debugging - Variable Optimized Out (Read 1475 times)
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2431
Joined: Feb 13th, 2019
nrf51822 + STLink Hardware Debugging - Variable Optimized Out
Dec 15th, 2020 at 9:42am
Print Post  
About debugging, can I know why variable values are set to "optimzed out" while I have checked "No project + library optimization" (also tried "no optimization") ?
  
Back to top
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2431
Joined: Feb 13th, 2019
Re: nrf51822 + STLink Hardware Debugging - Variable Optimized Out
Reply #1 - Dec 15th, 2020 at 10:56am
Print Post  
Variables/Functions can be optimized out by the toolchain compiler for a variety of reasons.

If the optimization is left as "Default", with the Hardware debugger enabled the system will use -Og (debug optimization), and this should suffice in most cases for debugging.  No Optimization (-O0) can also work to avoid this, though may slow the program down, and increase the code size considerably.

Can you confirm (with example) what you are seeing that is optimized, which you want to inspect?

Also, the Visual Micro Serial Debugger avoids the optimization issue completely, and allows variable tracking, charting, conditional breakpoints, trace points and more via the Serial port.
« Last Edit: Dec 15th, 2020 at 10:56am by Simon@Visual Micro »  
Back to top
IP Logged
 
entretoize1
Junior Member
**
Offline


Posts: 20
Joined: Dec 4th, 2020
Re: nrf51822 + STLink Hardware Debugging - Variable Optimized Out
Reply #2 - Dec 15th, 2020 at 1:53pm
Print Post  
With "No optimization" I still can see that variable I want to see in this example:

Code
Select All
		float x = mpu.getAngleX();
		timer = millis();
		Serial.println(x);            //breakpoint here
 



x value is <optimized out> but should be a float, I tried by adding 1 (x=x+1;) and then I can see it but it's not practical.

What is Visual Micro Serial Debugger ? Is it another software ? You help page seems to explain how to do in Visual studio but it's what I'm already doing.

  
Back to top
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2431
Joined: Feb 13th, 2019
Re: nrf51822 + STLink Hardware Debugging - Variable Optimized Out
Reply #3 - Dec 15th, 2020 at 2:09pm
Print Post  
Have you tried watching "mpu.getAngleX()" instead of "x"?
(In this case I expect the compiler can see it is assigned, just to be used with no other operations, so reduces this to essentially "Serial.println(mpu.getAngleX())")

The Visual Micro Serial debugger is the "Serial" option on the Debug Listing (set to Hardware to use STLink), and works slightly differently to the hardware debugger as no additional hardware is needed.  It is built into the Visual Micro Extension, so looks very similar from the UI as both are in VS.

The differences between these two debugging methods are listed below, with a vide example of the Serial Debug Charting in action.

Doc: Differences between Visual Micro Debugging, Gdb Debugging and Visual Studio's Debugging of Native Platforms
Video Example: Serial Debugger Charting with vMicro
  
Back to top
IP Logged
 
entretoize1
Junior Member
**
Offline


Posts: 20
Joined: Dec 4th, 2020
Re: nrf51822 + STLink Hardware Debugging - Variable Optimized Out
Reply #4 - Dec 15th, 2020 at 3:01pm
Print Post  
Watching mpu.getAngleX() doesn't work (can't be evaluated).
Anyway , I can (and will) do x=x+0 and then x is visible...


From what I understand, I can't use the serial option (tried and breakpoints doesn't work) as I'm using a STlink, right ?
  
Back to top
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2431
Joined: Feb 13th, 2019
Re: nrf51822 + STLink Hardware Debugging - Variable Optimized Out
Reply #5 - Dec 15th, 2020 at 5:14pm
Print Post  
Understood, there may be alternative options to step into the getAngleX() method to review this at runtime.

The Serial Debugger is a complete replacement for the Hardware Debugging, so the options cannot be selected together.   

It also requires the Serial output to work for the board in the Serial Monitor (which I believe is an issue for your configuration from the other thread), as this is what the debugger uses to send the messages to/from the board/pc.
  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint