|
| 1 | +from __future__ import annotations |
1 | 2 | import sys
|
2 |
| -from typing import List |
| 3 | +from typing import List, TYPE_CHECKING |
3 | 4 |
|
4 | 5 | from lldb import (
|
5 | 6 | SBData,
|
6 | 7 | SBError,
|
7 |
| - SBType, |
8 |
| - SBTypeStaticField, |
9 |
| - SBValue, |
10 | 8 | eBasicTypeLong,
|
11 | 9 | eBasicTypeUnsignedLong,
|
12 | 10 | eBasicTypeUnsignedChar,
|
13 | 11 | eFormatChar,
|
14 | 12 | )
|
15 | 13 |
|
| 14 | +if TYPE_CHECKING: |
| 15 | + from lldb import SBValue, SBType, SBTypeStaticField |
| 16 | + |
16 | 17 | # from lldb.formatters import Logger
|
17 | 18 |
|
18 | 19 | ####################################################################################################
|
@@ -497,9 +498,18 @@ def update(self):
|
497 | 498 | continue
|
498 | 499 |
|
499 | 500 | 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 |
503 | 513 |
|
504 | 514 | if exact.IsValid():
|
505 | 515 | discr: int = exact.GetConstantValue(
|
@@ -648,12 +658,32 @@ def MSVCEnumSummaryProvider(valobj: SBValue, _dict: LLDBOpaque) -> str:
|
648 | 658 | variant_names: SBType = valobj.target.FindFirstType(
|
649 | 659 | f"{enum_synth.valobj.GetTypeName()}::VariantNames"
|
650 | 660 | )
|
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), "}"]) |
657 | 687 |
|
658 | 688 | name: str = variant_names.enum_members[name_idx].name
|
659 | 689 |
|
|
0 commit comments