diff options
| author | Walnut <39544927+Walnut356@users.noreply.github.com> | 2025-02-07 20:41:57 -0600 |
|---|---|---|
| committer | Walnut <39544927+Walnut356@users.noreply.github.com> | 2025-02-07 20:41:57 -0600 |
| commit | 0819c1638c6fdb41884d7aadd1528611b2f09d7b (patch) | |
| tree | 98c82a82cd39ba8e9209df481ce1fd3849c96f31 | |
| parent | 0f12b8cf121365ba48703fda854e5b5b523e8938 (diff) | |
| download | rust-0819c1638c6fdb41884d7aadd1528611b2f09d7b.tar.gz rust-0819c1638c6fdb41884d7aadd1528611b2f09d7b.zip | |
Fix import/attribute errors related to `SBTypeStaticField`
| -rw-r--r-- | src/etc/lldb_providers.py | 56 |
1 files changed, 43 insertions, 13 deletions
diff --git a/src/etc/lldb_providers.py b/src/etc/lldb_providers.py index 319682a1c8c..573cc50a868 100644 --- a/src/etc/lldb_providers.py +++ b/src/etc/lldb_providers.py @@ -1,18 +1,19 @@ +from __future__ import annotations import sys -from typing import List +from typing import List, TYPE_CHECKING from lldb import ( SBData, SBError, - SBType, - SBTypeStaticField, - SBValue, eBasicTypeLong, eBasicTypeUnsignedLong, eBasicTypeUnsignedChar, eFormatChar, ) +if TYPE_CHECKING: + from lldb import SBValue, SBType, SBTypeStaticField + # from lldb.formatters import Logger #################################################################################################### @@ -497,9 +498,18 @@ class MSVCEnumSyntheticProvider: continue variant_type: SBType = child.GetType() - exact: SBTypeStaticField = variant_type.GetStaticFieldWithName( - "DISCR_EXACT" - ) + try: + exact: SBTypeStaticField = variant_type.GetStaticFieldWithName( + "DISCR_EXACT" + ) + except AttributeError: + # LLDB versions prior to 19.0.0 do not have the `SBTypeGetStaticField` API. + # With current DI generation there's not a great way to provide a "best effort" + # evaluation either, so we just return the object itself with no further + # attempts to inspect the type information + self.variant = self.valobj + self.value = self.valobj + return if exact.IsValid(): discr: int = exact.GetConstantValue( @@ -648,12 +658,32 @@ def MSVCEnumSummaryProvider(valobj: SBValue, _dict: LLDBOpaque) -> str: variant_names: SBType = valobj.target.FindFirstType( f"{enum_synth.valobj.GetTypeName()}::VariantNames" ) - name_idx = ( - enum_synth.variant.GetType() - .GetStaticFieldWithName("NAME") - .GetConstantValue(valobj.target) - .GetValueAsUnsigned() - ) + try: + name_idx = ( + enum_synth.variant.GetType() + .GetStaticFieldWithName("NAME") + .GetConstantValue(valobj.target) + .GetValueAsUnsigned() + ) + except AttributeError: + # LLDB versions prior to 19 do not have the `SBTypeGetStaticField` API, and have no way + # to determine the value based on the tag field. + tag: SBValue = valobj.GetChildMemberWithName("tag") + + if tag.IsValid(): + discr: int = tag.GetValueAsUnsigned() + return "".join(["{tag = ", str(tag.unsigned), "}"]) + else: + tag_lo: int = valobj.GetChildMemberWithName( + "tag128_lo" + ).GetValueAsUnsigned() + tag_hi: int = valobj.GetChildMemberWithName( + "tag128_hi" + ).GetValueAsUnsigned() + + discr: int = (tag_hi << 64) | tag_lo + + return "".join(["{tag = ", str(discr), "}"]) name: str = variant_names.enum_members[name_idx].name |
