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
32 changes: 32 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
26 changes: 25 additions & 1 deletion src/etc/lldb_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,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 +1157,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 +1197,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
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
6 changes: 4 additions & 2 deletions tests/debuginfo/reference-debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,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 @@ -84,7 +86,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
11 changes: 9 additions & 2 deletions tests/debuginfo/strings-and-strs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,15 @@
//@ lldb-command:v box_str
//@ lldb-check:(alloc::boxed::Box<str, alloc::alloc::Global>) box_str = "World" { [0] = 'W' [1] = 'o' [2] = 'r' [3] = 'l' [4] = 'd' }

//@ lldb-command:v rc_str
//@ lldb-check:(alloc::rc::Rc<unsigned char[], alloc::alloc::Global>) rc_str = strong=1, weak=0 { value = "World" }
// Disabled temporarily since it only "works" by accident
// `value` is a wide pointer, whose `data_ptr` type, according to LLDB, is `unsigned char[]`. LLDB
// reads this as a c-string by default. On Linux this fairly consistenly results in the expected
// output below. On Windows, the string data is often not followed by a null byte and attempts to
// read OOB memory. This will be fixed as part of #161657
// lldb-command:v rc_str

// ignore-tidy-linelength
// lldb-check:(alloc::rc::Rc<unsigned char[], alloc::alloc::Global>) rc_str = strong=1, weak=0 { value = "World" }

#![allow(unused_variables)]

Expand Down
4 changes: 2 additions & 2 deletions tests/debuginfo/union-smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

//@ lldb-command:run
//@ lldb-command:v u
//@ lldb-check:[...] {a:('\x02', '\x02'), b:514}
//@ lldb-check:[...] {a:(2, 2), b:514}

//@ lldb-command:print union_smoke::SU
//@ lldb-check:[...] {a:('\x01', '\x01'), b:257}
//@ lldb-check:[...] {a:(1, 1), b:257}

#![allow(unused)]

Expand Down
Loading