Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/etc/lldb_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,38 @@ def register_providers_compatibility():

global RUST_CATEGORY

# Don't format 8-bit builtins as chars
unsigned_format = lldb.SBTypeFormat(
lldb.eFormatUnsigned,
lldb.eTypeOptionCascade
| lldb.eTypeOptionSkipPointers
| lldb.eTypeOptionSkipReferences,
)

RUST_CATEGORY.AddTypeFormat(lldb.SBTypeNameSpecifier("u8", False), unsigned_format)
RUST_CATEGORY.AddTypeFormat(
lldb.SBTypeNameSpecifier("unsigned char", False),
unsigned_format,
)

signed_format = lldb.SBTypeFormat(
lldb.eFormatDecimal,
lldb.eTypeOptionCascade
| lldb.eTypeOptionSkipPointers
| lldb.eTypeOptionSkipReferences,
)
RUST_CATEGORY.AddTypeFormat(
lldb.SBTypeNameSpecifier("i8", False), lldb.SBTypeFormat(lldb.eFormatDecimal)
)

# i8 translates to signed char on msvc
RUST_CATEGORY.AddTypeFormat(
lldb.SBTypeNameSpecifier("signed char", False),
signed_format,
)
# Does not conflict with rust char, which ends up with the type name `char32_t`
RUST_CATEGORY.AddTypeFormat(lldb.SBTypeNameSpecifier("char", False), signed_format)

if LLDBFeature.TypeRecognizers in FEATURE_FLAGS:
# enforce uniform aggregate formatting
register_summary(
Expand Down Expand Up @@ -357,6 +389,7 @@ def register_providers_compatibility():
MSVCTupleSyntheticProvider,
TupleSummaryProvider,
r"^tuple\$<.+>$",
type_options=DEFAULT_TYPE_OPTIONS | lldb.eTypeOptionHideChildren,
)


Expand Down
55 changes: 54 additions & 1 deletion src/etc/lldb_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,29 @@ class LLDBFeature(Flag):
Float128 = auto()
"""Added in LLDB 22.1. Adds builtin support for Float 128's, including an `eBasicTypeFloat128`,
a formatter, and handlers in `TypeSystemClang`"""
GetParent = auto()
"""Added in LLDB 23.1. Adds `SBValue.GetParent`, which retrieves the `SBValue` that the caller
originates from. Useful when a child object must be modified/styled based on information only
available to is parent e.g. unsized array types that must determine their length via the parent
wide pointer value."""
ProviderDecorator = auto()
"""Added in LLDB 23.1. Adds `@lldb.summary` and `@lldb.synthetic`, which can automatically
register decorated providers. At time of writing, we do not use this feature for the following
reasons:

1. backwards compatibility
2. to maintain more strict control over the order in which providers are loaded"""
PerObjectSynthetics = auto()
"""Currently only available in prerelease. Adds:

* `SBValue.SetTypeSynthetic` - allows synthetic providers to override their children's synthetic
provider without overriding the synthetic provider of all objects with that share a type name.
* `SBValue.GetTypeSyntheticImplementation` - retrieves the *instance* of the synthetic provider
associated with that variable. This allows us to easily inspect the state of a parent/child
and use it to make decisions about the current object without needing to redo work. It is worth
noting that this can be achieved backwards-compatibly (though less elegantly) by using a global
`weakref.WeakValueDictionary`, with the keys being `SBValue.GetID()` (which are unique per
session) and the values being the provider instance."""


def detect_features() -> LLDBFeature:
Expand All @@ -93,6 +116,12 @@ def detect_features() -> LLDBFeature:
features |= LLDBFeature.TypeRecognizers
if getattr(lldb, "eBasicTypeFloat128", None) is not None:
features |= LLDBFeature.Float128
if getattr(lldb.SBValue, "GetParent", None) is not None:
features |= LLDBFeature.GetParent
if getattr(lldb, "summary", None) is not None:
features |= LLDBFeature.ProviderDecorator
if getattr(lldb.SBValue, "SetTypeSynthetic", None) is not None:
features |= LLDBFeature.PerObjectSynthetics

return features

Expand Down Expand Up @@ -680,6 +709,9 @@ def get_child_at_index(self, index: int) -> Optional[SBValue]:
element = self.data_ptr.CreateValueFromAddress(
f"[{index}]", address, self.data_ptr.GetType().GetPointeeType()
)

element.SetFormat(eFormatChar)

return element

def get_type_name(self):
Expand Down Expand Up @@ -1154,10 +1186,28 @@ def has_children(self) -> bool:


class StdSliceSyntheticProvider:
__slots__ = ["valobj", "length", "data_ptr", "element_type", "element_size"]
__slots__ = [
"valobj",
"length",
"data_ptr",
"element_type",
"element_size",
"is_str",
]

def __init__(self, valobj: SBValue, _dict: LLDBOpaque):
self.valobj = valobj
type_name = self.valobj.GetTypeName()
self.is_str = type_name.startswith("alloc::boxed::Box<str") or type_name in {
"&str",
"&mut str",
"*const str",
"*mut str",
"ref$<str>",
"ref_mut$<str>",
"ptr_const$<str>",
"ptr_mut$<str>",
}
self.update()

def num_children(self) -> int:
Expand All @@ -1176,6 +1226,9 @@ def get_child_at_index(self, index: int) -> Optional[SBValue]:
element = self.data_ptr.CreateValueFromAddress(
"[%s]" % index, address, self.element_type
)

if self.is_str:
element.SetFormat(eFormatChar)
return element

def update(self):
Expand Down
5 changes: 0 additions & 5 deletions src/tools/tidy/src/issues.txt
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,6 @@ ui/consts/issue-28113.rs
ui/consts/issue-28822.rs
ui/consts/issue-29798.rs
ui/consts/issue-29914-2.rs
ui/consts/issue-29914-3.rs
ui/consts/issue-29914.rs
ui/consts/issue-29927-1.rs
ui/consts/issue-29927.rs
Expand Down Expand Up @@ -1915,7 +1914,6 @@ ui/parser/issues/issue-17718-parse-const.rs
ui/parser/issues/issue-17904-2.rs
ui/parser/issues/issue-17904.rs
ui/parser/issues/issue-1802-1.rs
ui/parser/issues/issue-1802-2.rs
ui/parser/issues/issue-19096.rs
ui/parser/issues/issue-19398.rs
ui/parser/issues/issue-20616-1.rs
Expand Down Expand Up @@ -2764,7 +2762,6 @@ ui/type-alias-impl-trait/issue-57961.rs
ui/type-alias-impl-trait/issue-58662-coroutine-with-lifetime.rs
ui/type-alias-impl-trait/issue-58662-simplified.rs
ui/type-alias-impl-trait/issue-58887.rs
ui/type-alias-impl-trait/issue-58951-2.rs
ui/type-alias-impl-trait/issue-58951.rs
ui/type-alias-impl-trait/issue-60371.rs
ui/type-alias-impl-trait/issue-60407.rs
Expand All @@ -2790,7 +2787,6 @@ ui/type-alias-impl-trait/issue-70121.rs
ui/type-alias-impl-trait/issue-72793.rs
ui/type-alias-impl-trait/issue-74244.rs
ui/type-alias-impl-trait/issue-74280.rs
ui/type-alias-impl-trait/issue-74761-2.rs
ui/type-alias-impl-trait/issue-74761.rs
ui/type-alias-impl-trait/issue-76202-trait-impl-for-tait.rs
ui/type-alias-impl-trait/issue-77179.rs
Expand Down Expand Up @@ -2955,7 +2951,6 @@ ui/unsafe/issue-45107-unnecessary-unsafe-in-closure.rs
ui/unsafe/issue-47412.rs
ui/unsafe/issue-85435-unsafe-op-in-let-under-unsafe-under-closure.rs
ui/unsafe/issue-87414-query-cycle.rs
ui/unsized-locals/issue-30276-feature-flagged.rs
ui/unsized-locals/issue-30276.rs
ui/unsized-locals/issue-50940-with-feature.rs
ui/unsized-locals/issue-50940.rs
Expand Down
1 change: 1 addition & 0 deletions tests/debuginfo/associated-types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ impl TraitWithAssocType for i32 {
fn get_value(&self) -> i64 { *self as i64 }
}

#[repr(C)]
struct Struct<T: TraitWithAssocType> {
b: T,
b1: T::Type,
Expand Down
24 changes: 19 additions & 5 deletions tests/debuginfo/basic-types/lldb_input/non_windows.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
},
"i8": {
"type": "char",
"pretty_print": "'D'",
"value": 68
"pretty_print": "68",
"value": 68,
"format": 9
},
"i16": {
"type": "short",
Expand All @@ -48,8 +49,9 @@
},
"u8": {
"type": "unsigned char",
"pretty_print": "'d'",
"value": 100
"pretty_print": "100",
"value": 100,
"format": 18
},
"u16": {
"type": "unsigned short",
Expand Down Expand Up @@ -77,5 +79,17 @@
"value": 3.5
}
}
]
],
"types": {
"char": {
"size": 1,
"type_class": 4,
"basic_type": 3
},
"unsigned char": {
"size": 1,
"type_class": 4,
"basic_type": 4
}
}
}
24 changes: 19 additions & 5 deletions tests/debuginfo/basic-types/lldb_input/windows_gnu.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
},
"i8": {
"type": "char",
"pretty_print": "'D'",
"value": 68
"pretty_print": "68",
"value": 68,
"format": 9
},
"i16": {
"type": "short",
Expand All @@ -48,8 +49,9 @@
},
"u8": {
"type": "unsigned char",
"pretty_print": "'d'",
"value": 100
"pretty_print": "100",
"value": 100,
"format": 18
},
"u16": {
"type": "unsigned short",
Expand Down Expand Up @@ -77,5 +79,17 @@
"value": 3.5
}
}
]
],
"types": {
"char": {
"size": 1,
"type_class": 4,
"basic_type": 3
},
"unsigned char": {
"size": 1,
"type_class": 4,
"basic_type": 4
}
}
}
24 changes: 19 additions & 5 deletions tests/debuginfo/basic-types/lldb_input/windows_msvc.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
},
"i8": {
"type": "signed char",
"pretty_print": "'D'",
"value": 68
"pretty_print": "68",
"value": 68,
"format": 9
},
"i16": {
"type": "short",
Expand All @@ -48,8 +49,9 @@
},
"u8": {
"type": "unsigned char",
"pretty_print": "'d'",
"value": 100
"pretty_print": "100",
"value": 100,
"format": 18
},
"u16": {
"type": "unsigned short",
Expand Down Expand Up @@ -77,5 +79,17 @@
"value": 3.5
}
}
]
],
"types": {
"signed char": {
"size": 1,
"type_class": 4,
"basic_type": 3
},
"unsigned char": {
"size": 1,
"type_class": 4,
"basic_type": 4
}
}
}
6 changes: 4 additions & 2 deletions tests/debuginfo/borrowed-basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@
//@ lldb-command:v *int_ref
//@ lldb-check:[...] -1

//@ lldb-command:v *char_ref
//@ lldb-check: [...] U+0x00000061 U'a'

//@ lldb-command:v *i8_ref
//@ lldb-check:[...] 'D'
//@ lldb-check:[...] 68

//@ lldb-command:v *i16_ref
//@ lldb-check:[...] -16
Expand All @@ -77,7 +79,7 @@
//@ lldb-check:[...] 1

//@ lldb-command:v *u8_ref
//@ lldb-check:[...] 'd'
//@ lldb-check:[...] 100

//@ lldb-command:v *u16_ref
//@ lldb-check:[...] 16
Expand Down
2 changes: 2 additions & 0 deletions tests/debuginfo/boxed-struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@

#![allow(unused_variables)]

#[repr(C)]
struct StructWithSomePadding {
x: i16,
y: i32,
z: i32,
w: i64
}

#[repr(C)]
struct StructWithDestructor {
x: i16,
y: i32,
Expand Down
6 changes: 5 additions & 1 deletion tests/debuginfo/c-style-enum-in-composite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,21 @@
use self::AnEnum::{OneHundred, OneThousand, OneMillion};
use self::AnotherEnum::{MountainView, Toronto, Vienna};

#[repr(u32)]
enum AnEnum {
OneHundred = 100,
OneThousand = 1000,
OneMillion = 1000000
}

#[repr(u8)]
enum AnotherEnum {
MountainView,
Toronto,
Vienna
}

#[repr(C)]
struct PaddedStruct {
a: i16,
b: AnEnum,
Expand All @@ -77,7 +80,7 @@ struct PaddedStruct {
e: i16
}

#[repr(packed)]
#[repr(C, packed)]
struct PackedStruct {
a: i16,
b: AnEnum,
Expand All @@ -86,6 +89,7 @@ struct PackedStruct {
e: i16
}

#[repr(C)]
struct NonPaddedStruct {
a: AnEnum,
b: AnotherEnum,
Expand Down
Loading
Loading