static fields and consts on a class

I've explored the internal and external apis for LLDB, but I cannot find any way to expose (from LLVM) a static field on a class (like Java: class Test { public static int A = 15; }) or a constant on a class. How do I do this and read it out again with LLDB?

Are you asking how to read a static variable from a SBTarget? Or are you asking how to expose a static variable through the lldb::SB API?

You have to be careful about including static variables in the type of a class, since it is not uncommon to have a class which has a static variable that is an instance of itself, so you can get into display cycles. gdb showed statics as part of the object display, and had some "set" variable you would set to avoid cycles (usually after you had hung once because of it...) We didn't want to play that game, plus I think it's kind of ugly to have the statics show up in object displays, so at present we just leave the statics out of the type representations. But we could add them as a side-car to the type, but leave them separate from the ivars. I assume you can get them from the clang's type for the class...

Jim

I can get the type yes. I wouldn't show them as part of an instance of a variable but my users expect to be able to type MyClass.StaticField (which corresponds to a global variable called __namespace_myclass_staticfield) and see it when hovering over Myclass.

Are you asking how to read a static variable from a SBTarget? Or are you asking how to expose a static variable through the lldb::SB API?

I'm asking how I can say "There's a static variable inside this class" in LLVM and then read it back with LLDB once I did that.

If you have the following code:

#include <stdio.h>
#include <stdint.h>

class A {
    public:
    static int a;
};

int A::a = 123;

int main (int argc, char const *argv[], char const *envp[])
{
    puts("hello");
    return A::a;
}

You can get to it using when running using the "frame variable" or "expression" commands:

% lldb a.out
(lldb) b main
(lldb) run
(lldb) fr var A::a
(int) A::a = 123
(lldb) expression A::a
(int) $0 = 123

You can also access it when you are not running because it is a static variable by using the "target variable" (a command that allows access to global and static variables). Since its value is stored in the data sections:

% xcrun lldb a.out
Current executable set to 'a.out' (x86_64).
(lldb) target variable A::a
(int) A::a = 123