================
@@ -67,12 +67,18 @@ std::optional<int64_t> GetIndexValue(ValueObject &valobj) {
ValueObjectSP GetNthStorage(ValueObject &outer, int64_t index) {
// We need to find the std::_Variant_storage base class.
- // -> std::_SMF_control (typedef to std::_Variant_base)
- ValueObjectSP container_sp = outer.GetSP()->GetChildAtIndex(0);
- if (!container_sp)
+ // Navigate "down" to std::_Variant_base by finding the holder of "_Which".
----------------
Nerixyz wrote:
`outer` is the `std::variant` type itself. Our goal is to get to the root of
the recursive union (`std::_Variant_storage`).
In libc++, [this is done by looking up
`__data`](https://github.com/llvm/llvm-project/blob/75dd5b3df2905f1a7e56837df6e16c261229576c/lldb/source/Plugins/Language/CPlusPlus/LibCxxVariant.cpp#L126).
Unfortunately, we can't do this for MSVC's STL, as the root is a base class of
the `std::variant`.
Since we don't know how many intermediate base classes (`std::_SMF_control...`)
there are, we look up `_Which`, where we know that the first base class of its
parent is `std::_Variant_storage`.
An alternative could be to get the first child until a class starts with
`std::_Variant_storage`.
I'll put the raw output of a variant below, maybe that clears things up:
<details><summary>Raw output</summary>
```
(lldb) fr v -R --depth 16 v
(std::variant<bool, int, std::string >) v = {
std::_SMF_control<std::_Variant_destroy_layer_<bool, int, std::string >,
bool, int, std::string > = {
std::_SMF_control_copy_assign<std::_Variant_destroy_layer_<bool, int,
std::string >, bool, int, std::string > = {
std::_SMF_control_move<std::_Variant_destroy_layer_<bool, int,
std::string >, bool, int, std::string > = {
std::_SMF_control_copy<std::_Variant_destroy_layer_<bool, int,
std::string >, bool, int, std::string > = {
std::_Variant_destroy_layer_<bool, int, std::string > = {
std::_Variant_base<bool, int, std::string > = {
std::_Variant_storage<bool, int, std::string > = {
= {
_Head = true
_Tail = {
= {
_Head = 7303014
_Tail = {
= {
_Head = {
_Mypair = {
_Myval2 = {
_Bx = {...}
_Mysize = 3
_Myres = 15
}
}
}
_Tail = {}
}
}
}
}
}
}
_Which = '\x02'
}
}
}
}
}
}
}
```
</details>
https://github.com/llvm/llvm-project/pull/171489
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits