[Lldb-commits] [lldb] Make only one function that needs to be implemented when searching for types (PR #74786)

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Tue Jan 2 16:43:24 PST 2024


clayborg wrote:

> absl::cord_internal::RefcountAndFlags::Flags::kNumFlags

I have a small repro case from the code pointer you gave. I will look into this and report back what I find. 

Are you guys using the expression parser in your pretty printer? As Michael pointed out, you can get the enum type as a `lldb::SBType` in and explore the enumerators via the API. Above Michael used a variable to get the type, but you can use the `lldb::SBType lldb::SBTarget::FindFirstType(const char *type)` API:
```
>>> t = lldb.target.FindFirstType("absl::cord_internal::RefcountAndFlags::Flags")
>>> t
enum Flags {
    kNumFlags,
    kImmortalFlag,
    kRefIncrement
}
>>> t.GetEnumMembers()
<lldb.SBTypeEnumMemberList; proxy of <Swig Object of type 'lldb::SBTypeEnumMemberList *' at 0x107d0fdb0> >
>>> t.GetEnumMembers()['kNumFlags']
unsigned int kNumFlags
>>> t.GetEnumMembers()['kNumFlags'].GetValueAsUnsigned()
1
```

That being said, it does seem like this issue is due to https://github.com/llvm/llvm-project/issues/53904. Getting the type from the target and getting the enum value directly will be much more efficient than using the expression parser, but we do need to fix the expression parser as I wasn't aware of this bug where running the expression multiple times would eventually allow it to work.

https://github.com/llvm/llvm-project/pull/74786


More information about the lldb-commits mailing list