Getting the instance/static methods on an objc class

How do I get a list of the methods (and the signatures) if I have the SBType for a given objc type?

If that can't be derived from the objc type info, what do I need to do to expose it from the llvm side?

llvm doesn't include method definitions in the type DIEs for an ObjC class, just the properties and ivars(neither did gcc.) The method table for ObjC is dynamic so I'm not sure it would make sense to do this.

lldb currently looks up method invocations one by one when it needs them (mostly in the expression parser) from the subroutine DIEs at the definition sites of the methods if we have debug information for them, or from the ObjC runtime as a fallback. Since there's no reason to do so and it would be fairly expensive, lldb doesn't try to gather all the methods into its type representation for the class by hand.

The internal API's have FindSymbols & FindFunctions APIs that take regular expression search patterns. You could get all the symbols & functions matching "^-[MyClass" and "^+[MyClass", that would get you the methods whose names we know about (though not necessarily which method would actually get invoked when a given selector is sent.) A lookup by regexp on SBTarget wouldn't be a bad addition either...

Jim

llvm doesn't include method definitions in the type DIEs for an ObjC class, just the properties and ivars(neither did gcc.) The method table for ObjC is dynamic so I'm not sure it would make sense to do this.

lldb currently looks up method invocations one by one when it needs them (mostly in the expression parser) from the subroutine DIEs at the definition sites of the methods if we have debug information for them, or from the ObjC runtime as a fallback. Since there's no reason to do so and it would be fairly expensive, lldb doesn't try to gather all the methods into its type representation for the class by hand.

I need that info for my own language frontend, would there be any interest in a patch that lets me find this information (and maybe the static vars/consts on a class once i figure out how to encode them) from the SBType side?

The internal API's have FindSymbols & FindFunctions APIs that take regular expression search patterns. You could get all the symbols & functions matching "^-[MyClass" and "^+[MyClass", that would get you the methods whose names we know about (though not necessarily which method would actually get invoked when a given selector is sent.) A lookup by regexp on SBTarget wouldn't be a bad addition either...

I can try and build a patch for that.

This could be expensive and you don't need this information for most common task of presenting the values of a variable of this type. So this would have to be done only lazily, like only in result to a specific request for the methods of that type.

C++ debug info already encodes the methods in the class definitions in DWARF, so you would presumably make it look like that. It would also have to stay out of the way of the current method signature lookup between us & clang. You'd have to do something sensible with categories that provide overriding definitions as well. But other than that this seems like it would be useful in some circumstances.

Jim

You can currently look through the symbol table each module using SBModule:

    size_t
    GetNumSymbols ();
    
    lldb::SBSymbol
    GetSymbolAtIndex (size_t idx);

Or you can set a breakpoint by regular expression:

    lldb::SBBreakpoint
    BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name = NULL);
    
    lldb::SBBreakpoint
    BreakpointCreateByRegex (const char *symbol_name_regex,
                             const SBFileSpecList &module_list,
                             const SBFileSpecList &comp_unit_list);

Then inspect the SBBreakpoint's locations.