diff --git a/src/etc/lldb_lookup.py b/src/etc/lldb_lookup.py index 3533d149e7494..f23081246ede7 100644 --- a/src/etc/lldb_lookup.py +++ b/src/etc/lldb_lookup.py @@ -175,14 +175,28 @@ def register_providers_compatibility(): register( StdSliceSyntheticProvider, StdStrSummaryProvider, - r"^&(mut )?str$", + r"^((&(mut )?)|(\*(const|mut) ))str$", + ) + + # Box GNU + register( + StdSliceSyntheticProvider, + StdStrSummaryProvider, + r"^(alloc::([a-z_]+::)+)Box$", ) # str MSVC register( MSVCStrSyntheticProvider, StdStrSummaryProvider, - r"^ref(_mut)?\$$", + r"^((ref(_mut)?)|(ptr_(const|mut)))\$$", + ) + + # Box MSVC + register( + MSVCStrSyntheticProvider, + StdStrSummaryProvider, + r"^(alloc::([a-z_]+::)+)Box$", ) # slice GNU diff --git a/src/etc/lldb_providers.py b/src/etc/lldb_providers.py index f6c2ab8f2b8c7..729214ff45e1e 100644 --- a/src/etc/lldb_providers.py +++ b/src/etc/lldb_providers.py @@ -1,31 +1,31 @@ from __future__ import annotations + import sys -from typing import Generator, Dict, List, TYPE_CHECKING, Optional from enum import Flag, auto +from typing import TYPE_CHECKING, Dict, Generator, List, Optional from lldb import ( SBData, SBError, + eBasicTypeChar32, + eBasicTypeDouble, + eBasicTypeFloat, + eBasicTypeHalf, eBasicTypeLong, - eBasicTypeUnsignedLong, + eBasicTypeLongLong, + eBasicTypeShort, + eBasicTypeSignedChar, eBasicTypeUnsignedChar, - eBasicTypeUnsignedShort, + eBasicTypeUnsignedLong, eBasicTypeUnsignedLongLong, - eBasicTypeSignedChar, - eBasicTypeShort, - eBasicTypeLongLong, - eBasicTypeFloat, - eBasicTypeDouble, - eBasicTypeHalf, - eBasicTypeChar32, + eBasicTypeUnsignedShort, eFormatChar, eTypeIsInteger, ) - from rust_types import is_tuple_fields if TYPE_CHECKING: - from lldb import SBValue, SBType, SBTypeStaticField, SBTarget, SBProcess + from lldb import SBProcess, SBTarget, SBType, SBTypeStaticField, SBValue # from lldb.formatters import Logger @@ -564,7 +564,13 @@ def get_child_at_index(self, index: int) -> Optional[SBValue]: class MSVCStrSyntheticProvider: - __slots__ = ["valobj", "data_ptr", "length"] + _name_map: Dict[str, str] = { + "ref$": "&str", + "ref_mut$": "&mut str", + "ptr_const$": "*const str", + "ptr_mut$": "*mut str", + } + __slots__ = ["data_ptr", "length", "valobj"] def __init__(self, valobj: SBValue, _dict: LLDBOpaque): self.valobj = valobj @@ -598,10 +604,14 @@ def get_child_at_index(self, index: int) -> Optional[SBValue]: return element def get_type_name(self): - if self.valobj.GetTypeName().startswith("ref_mut"): - return "&mut str" + name = self.valobj.GetTypeName() + + if (type_name := self._name_map.get(name)) is not None: + return type_name + elif name.startswith("alloc::boxed::Box" else: - return "&str" + return name def _getVariantName(variant: SBValue) -> str: diff --git a/tests/debuginfo/strings-and-strs.rs b/tests/debuginfo/strings-and-strs.rs index ee2702d1bcf74..a860aa6106d07 100644 --- a/tests/debuginfo/strings-and-strs.rs +++ b/tests/debuginfo/strings-and-strs.rs @@ -1,6 +1,5 @@ //@ min-gdb-version: 15.1 // LLDB 1800+ tests were not tested in CI, broke, and now are disabled -//@ ignore-lldb //@ compile-flags:-g //@ disable-gdb-pretty-printers @@ -38,16 +37,16 @@ //@ lldb-check:(&str) plain_str = "Hello" { [0] = 'H' [1] = 'e' [2] = 'l' [3] = 'l' [4] = 'o' } //@ lldb-command:v str_in_struct -//@ lldb-check:(strings_and_strs::Foo) str_in_struct = { inner = "Hello" { [0] = 'H' [1] = 'e' [2] = 'l' [3] = 'l' [4] = 'o' } } +//@ lldb-check:(strings_and_strs::Foo) str_in_struct = {inner:"Hello"} //@ lldb-command:v str_in_tuple -//@ lldb-check:((&str, &str)) str_in_tuple = ("Hello", "World") { 0 = "Hello" { [0] = 'H' [1] = 'e' [2] = 'l' [3] = 'l' [4] = 'o' } 1 = "World" { [0] = 'W' [1] = 'o' [2] = 'r' [3] = 'l' [4] = 'd' } } +//@ lldb-check:((&str, &str)) str_in_tuple = ("Hello", "World") //@ lldb-command:v str_in_rc //@ lldb-check:(alloc::rc::Rc<&str, alloc::alloc::Global>) str_in_rc = strong=1, weak=0 { value = "Hello" { [0] = 'H' [1] = 'e' [2] = 'l' [3] = 'l' [4] = 'o' } } //@ lldb-command:v box_str -//@ lldb-check:(alloc::boxed::Box) box_str = { __0 = { pointer = { pointer = { data_ptr = 0x[...] "World" length = 5 } } _marker = } __1 = } +//@ lldb-check:(alloc::boxed::Box) box_str = "World" { [0] = 'W' [1] = 'o' [2] = 'r' [3] = 'l' [4] = 'd' } //@ lldb-command:v rc_str //@ lldb-check:(alloc::rc::Rc) rc_str = strong=1, weak=0 { value = "World" }