Variables now "Optimized away"

Go To Last Post
22 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I too have SOME global variables now, "Optimized away", in C, using AStudio 6.1.2674, SP1, JTAGICE3, on ATXMega256A3U. Again, only some global structs have this issue, so I'm examining diffs in the data structures themselves, like, size, embedded pointers, structs, unions, anonymous or otherwise, and such. I too don't believe this is an optimization problem, I'm thinking it's a problem in the debug symbol chain?

Has anyone made any headway on this (besides rolling back to a previous version)?

Thank you.

//*** UPDATE ***//
Atmel Studio 6.1, SP2 seems to fix the "Optimized Away" problem, and updates the JTAGICE3 firmware. I've now safely rolled back to the future!

Field the chicken, ignore the ball.

Last Edited: Wed. Sep 18, 2013 - 10:03 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are we having a fun game of "chase the post". I actually already replied to this before it was posted (apparently!) here:

https://www.avrfreaks.net/index.p...

(that's what happens if you post/delete/repost)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Fantastic, we must have run through some form of "super-freakish" time warp. My apologies, I just wasn't sure if anyone would see it. Thank you for replying, I'm fiddling with this now and I'll be sure to post any significant findings. So far, no joy with the "volatile" qualifier, for this surely must be pure evil.

Field the chicken, ignore the ball.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Can you reduce this to a minimal test case and post that to demonstrate the effect you are seeing (or rather not seeing).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The appearance of "Optimized away" on global data in a debugger watch window appears be the application of optimization, and perhaps not the evil I had imagined. I certainly don't wish to cast aspersions on AStudio 6.1-sp1, or steer anyone to wrong conclusions.

I thought that a C-language (not C++) global data structure, appearing in the COMMON area of the .map file, with a valid address and size, should always be available in the watch window. But this is not the case. Code in which the data appears, may or may not, cause it to be "Optimized away".

To prove this, I declared a duplicate data structure, com99, immediately after two affected ones com1, and com2, but did not reference com99 in any of the code. All three appeared to consume SRAM, according to the .map. At the start of debug, both com1 and com2 always appeared "Optimized away", however, com99 data was present at it's assigned address (which actually seemed like a paradox, almost).

The com99 data became "Optimized away" in the watch window only after I recompiled with it in some of the code as the others, using identical C statements. Yes, I know, I've proven it is the product of bad coding - so please forgive me. But narrowing down the offending statement(s), and figuring out how to repair them, will take some time. The app seems to run ok, but I'm unable to examine the data to be sure.

To attempt a quick fix, here's what I've tried, with no joy:
- Turned off compiler optimization, -O0 (normally 1)
- Forced the volatile qualifier on the data
- Unchecked the "Prepare data for garbage collection

For those new to suffering this, you are well advised to read Clawson's fantastic post about how to avoid optimization evil. I'm heading over there again, right after this.

https://www.avrfreaks.net/index.p...

Field the chicken, ignore the ball.

Last Edited: Fri. Jun 28, 2013 - 10:33 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Unchecked the "Prepare data for garbage collection

But if -fdata-sections and -gc-sections are used (as AS6 defaults to) then what were you expecting? That specifically says discard anything that isn't referenced. So the linker is doing exactly what you asked for. The debugger can't show something that isn't there.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, I threw in the towel and decided to roll back from AS 6.1 SP1 to AS 6.0, just until this gets sorted out. I found that I had to use the older project file, since new version's xml was different enough to cause the rebuild targets to get lost. So, that's it for now. Thank you for your help.

Field the chicken, ignore the ball.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've just run into this too. In 6.1, a C global struct is "optimized away" in the watch window. But if I step through some code that accesses the struct, it appears in the watch window, only to be optimized away again when I step out of the function.

If I debug the same .elf file with 6.0 and 6.1 (no recompiling), the struct is always visible in 6.0, but optimized away in 6.1. So this does not appear to be an optimization issue at all; the .elf file obviously contains the necessary information to display the object in question.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have the same experience. Running currently 6.1 beta and it works fine.

Dean and your other Atmel people, where are you?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

WHY HAS THOUST SUMMONED ME?

But seriously, this is a Dan issue, since he managed the ELF file parsing in the backend (and may be related to the toolchain version upgrade). I'll send him an email but it's vacation period at the moment.

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Asle or xargs,

Can you PM me your ELF file (and the name of the global variable that gets optimized away) ?

Thanks,
Dan

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Asle was kind enough to send me one of his ELF files. From what I can see, AtmekStudio picks the first description of the variable in the debug info, which happens to be a declaring, not defining declaration.

A possible, untested workaround is to make sure the object file declaring the globals is the first compilation unit seen by the linker. This could e.g. be done with avr32-objcopy if Studio's makefile generator does not co-operate.

Anyway, here's a couple of DLLs that hopefully fix the problem. Drop them over the existing ones in the AtmelStudio6.1sp1 atbackend directory (as administrator).

https://www.dropbox.com/s/jxxw3n...

https://www.dropbox.com/s/7tmwhv...

Edit: I corrected the link to the elfdwarf DLL

Dan

Last Edited: Fri. Jul 5, 2013 - 07:53 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dan,

Thanks for the speedy response. I first tried your workaround (I'm using makefiles so it was easy to try), and it works.

Your second Dropbox link returns a 404 so I wasn't able to try it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I also had file-not-found for the DLLs.

Call me a wuzz but I don't want to touch the makefile!

regards
Greg

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

I've also the problem with "optimized away".

I have replaced the two DLLs but then I get a problem while selecting debugger/programmer in my Atmel Studio V6.1.2674. I can't see/select the JTAGICE3 anymore.

Best ragards,
K-laus

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

K-laus wrote:

I have replaced the two DLLs but then I get a problem while selecting debugger/programmer in my Atmel Studio V6.1.2674. I can't see/select the JTAGICE3 anymore.

Sorry for the 404 link (now corrected).
I just verified this fix myself:
1. clean install of 2674,
2. start studio at least once
3. close studio. makes sure atbackend.exe is not running.
3. delete the 2 dll's from the atbackend\codecache directory
4. paste in the 2 dlls's from dropbox
5. start studio and check that all is ok and jtagice3 is listed in available tools and works

dan

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello Dan,

thank you very much. Now I can select the JTAGICE3 again.

Best ragrds,
K-laus

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Dan,

I have installed the patch on two computers and it works fine.
Thank you.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Has this fix been incorporated into a new release? And if not when should we expect it?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The fix will be incorporated in the new maintenance release planned for late August. But plans change all the time, so grab the 2 dll's from here. Currently, they fix:
1. Variables showing up as optimized away
2. Studio did not load ARM_EXIDX section
3. Reduce chance of exhausting virtual memory on systems where the .Net garbage collector is too lazy.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are these fixes in sp2?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, I believe the changes were added to the 6.1 SP2 release.

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!