`SBType` and non-type template arguments

It seems that SBType doesn’t have any methods to retrieve the value of an integral template argument. The only relevant methods I see are these:

  uint32_t GetNumberOfTemplateArguments();

  lldb::SBType GetTemplateArgumentType(uint32_t idx);

  /// Return the TemplateArgumentKind of the template argument at index idx.
  /// Variadic argument packs are automatically expanded.
  lldb::TemplateArgumentKind GetTemplateArgumentKind(uint32_t idx);

so I can find out the kinds of each template argument, but only get the ones that are types.

I don’t mind writing a patch myself to expose integral values as well but I’d need some advice. What would be a good way to expose integral template arguments in the SB API?

The internal API has this function in TypeSystemClang:

Optional<CompilerType::IntegralTemplateArgument>
TypeSystemClang::GetIntegralTemplateArgument(lldb::opaque_compiler_type_t type,
                                             size_t idx, bool expand_pack)

but the actual integral value in IntegralTemplateArgument is stored in an llvm::APSInt which is an arbitrary precision integer so I don’t even know what would be the right type to return from a hypothetical SBType::GetIntegralTemplateArgument method.

lldb::SBValue seems like a good candidate. It can hold an arbitrary value and has a type associated with it too, which makes it even more convenient.

Apparently this came up a few years ago – LLDB SBAPI questions
CC @vadimcn in case it’s still relevant :slight_smile:

1 Like