Atmel Studio 7: Cannot watch C++ static class variables in debugger

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

Hello,

 

I'm developing an application for AT32 using Atmel Studio 7 and Atme ICE.

 

I have a simple utility class for tracking some ticks with only static members. This is the header file:

#ifndef __TIMETRACKER_H__
#define __TIMETRACKER_H__

#include <stdint.h>
#include "hw/tc.h"

#define TIME_TRACKER_TUPLES  3

class TimeTracker
{
private:
    struct TrackTuple {
        uint32_t current;
        uint32_t max;
    };

private:
    static int last;
    static TrackTuple t[TIME_TRACKER_TUPLES];

public:
    static void track(int i) {
        last = i;
        if (i < TIME_TRACKER_TUPLES) {
            t[i].current = TC1_CV2_RO;
            if (t[i].current > t[i].max) {
                t[i].max = t[i].current;
            }
        }
    }
    
    static uint16_t getLastMax() {
        return t[last].max;
    }
    
    // more getters ...
};

#endif //__TIMETRACKER_H__

And its corresponding cpp-File with only the definition of the static data members:

#include "TimeTracker.h"

int TimeTracker::last;
TimeTracker::TrackTuple TimeTracker::t[TIME_TRACKER_TUPLES];

When I try to watch any of the static data members I only get as value "Unknown identifier" and as type "Error". Same happens with mouse over. Window "Autos" doesn't show the variables as well.

 

Can anybody please give me a hint how to watch static class variables?

 

 

Thanks

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

What reference to them are you using when you try to watch them? Obvious if you have:

TimeTracker foo;

then they won't be foo.last but TimeTracker::last etc.

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

Since it is a utility class I have no instance. What I expect is that if I enter TimeTracker::last and TimeTracker::t as watch I could see the values when debugging.

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

Yeah, that's what I would expect too. I'm not near AS7 so couldn't try it. I tried it in Visual Studio (that AS7 is based on):

 

 

A test like that *should* work in AS7. Of course do make sure you have the very latest issue of AS7 as its ability to view classes/members has been improving over each release. If even my simple test here:

 

class Bar {
public:
    static int barInt;
};

int Bar::barInt = 12345;

int _tmain(int argc, _TCHAR* argv[])
{
    if (Bar::barInt >= 10000) {
        printf("it is\n");
    }
	return 0;
}

doesn't work then it's clearly a bug.

 

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

Thanks, clawson. That's what i get:

 

I added manually access to the memory location (retrieved from linker output) to verify that the value is actually there. But that is what the debugger should do for me.

I can't believe that there are such basic bugs :-\

 

Regards

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

As I say there were a few bugs like this in watching struct/class members in earlier AS7 (and AS6/AS5) so can you confirm you have the very latest one?

 

Also somewhere in there you will find an option to switch the "backend" debugger from Atmel's own one to avr-gdb (the GNU on) maybe try that and see if you have more success?

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

I'm using 7.0.1188 which is the latest version.

 

I searched around how to switch to avr-gdb. I instantly found GDB Settings under Options > Debugger. But I didn't found any information about what "Override toolchain GDB settings" means and how I can use this feature. Moreover it is not clear to me if Atmel Studio is using gdb by default or not.

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

It is NOT using gdb by default (apparently arm-gdb has problems).

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

arm uses gdb, rest does not at the moment. Avr8-gdb works most of the times, av32-gdb does not work...

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)

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

Thanks a lot.

So I will work around that static data members problem and will use a static object instead of a utility class.

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

Or you could just instantiate the class as a singleton without the "static"s ?

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

I also though of this solution but then I will have a static data member again: the (pointer to the) single instance. Leading me to the same problem again.
 

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

But with singletons you would usually have a getInstance() or similar so do you really need to "see" that pointer?

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

Yes, you're right that's the goal of the singleton. But I still may want to investigate the singleton in debugger and will fail to watch that static class variable.

 

More important: I opened a ticket at Atmel and the answer is: This issue has already been reported to the concerned team, they are working on this issue

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

Good news with Atmel Studio 1416. With a type cast I can watch static class variables now:

Atmel Studio 7 Watch Windows showing static class variable.