Skip to content

Commit 0819c16

Browse files
committed
Fix import/attribute errors related to SBTypeStaticField
1 parent 0f12b8c commit 0819c16

File tree

1 file changed

+43
-13
lines changed

1 file changed

+43
-13
lines changed

src/etc/lldb_providers.py

+43-13
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1+
from __future__ import annotations
12
import sys
2-
from typing import List
3+
from typing import List, TYPE_CHECKING
34

45
from lldb import (
56
SBData,
67
SBError,
7-
SBType,
8-
SBTypeStaticField,
9-
SBValue,
108
eBasicTypeLong,
119
eBasicTypeUnsignedLong,
1210
eBasicTypeUnsignedChar,
1311
eFormatChar,
1412
)
1513

14+
if TYPE_CHECKING:
15+
from lldb import SBValue, SBType, SBTypeStaticField
16+
1617
# from lldb.formatters import Logger
1718

1819
####################################################################################################
@@ -497,9 +498,18 @@ def update(self):
497498
continue
498499

499500
variant_type: SBType = child.GetType()
500-
exact: SBTypeStaticField = variant_type.GetStaticFieldWithName(
501-
"DISCR_EXACT"
502-
)
501+
try:
502+
exact: SBTypeStaticField = variant_type.GetStaticFieldWithName(
503+
"DISCR_EXACT"
504+
)
505+
except AttributeError:
506+
# LLDB versions prior to 19.0.0 do not have the `SBTypeGetStaticField` API.
507+
# With current DI generation there's not a great way to provide a "best effort"
508+
# evaluation either, so we just return the object itself with no further
509+
# attempts to inspect the type information
510+
self.variant = self.valobj
511+
self.value = self.valobj
512+
return
503513

504514
if exact.IsValid():
505515
discr: int = exact.GetConstantValue(
@@ -648,12 +658,32 @@ def MSVCEnumSummaryProvider(valobj: SBValue, _dict: LLDBOpaque) -> str:
648658
variant_names: SBType = valobj.target.FindFirstType(
649659
f"{enum_synth.valobj.GetTypeName()}::VariantNames"
650660
)
651-
name_idx = (
652-
enum_synth.variant.GetType()
653-
.GetStaticFieldWithName("NAME")
654-
.GetConstantValue(valobj.target)
655-
.GetValueAsUnsigned()
656-
)
661+
try:
662+
name_idx = (
663+
enum_synth.variant.GetType()
664+
.GetStaticFieldWithName("NAME")
665+
.GetConstantValue(valobj.target)
666+
.GetValueAsUnsigned()
667+
)
668+
except AttributeError:
669+
# LLDB versions prior to 19 do not have the `SBTypeGetStaticField` API, and have no way
670+
# to determine the value based on the tag field.
671+
tag: SBValue = valobj.GetChildMemberWithName("tag")
672+
673+
if tag.IsValid():
674+
discr: int = tag.GetValueAsUnsigned()
675+
return "".join(["{tag = ", str(tag.unsigned), "}"])
676+
else:
677+
tag_lo: int = valobj.GetChildMemberWithName(
678+
"tag128_lo"
679+
).GetValueAsUnsigned()
680+
tag_hi: int = valobj.GetChildMemberWithName(
681+
"tag128_hi"
682+
).GetValueAsUnsigned()
683+
684+
discr: int = (tag_hi << 64) | tag_lo
685+
686+
return "".join(["{tag = ", str(discr), "}"])
657687

658688
name: str = variant_names.enum_members[name_idx].name
659689

0 commit comments

Comments
 (0)