Skip to content

Commit ab9a4cf

Browse files
committed
add infallible primitive type lookups to template arg resolver
1 parent 4f84d9f commit ab9a4cf

1 file changed

Lines changed: 38 additions & 1 deletion

File tree

src/etc/lldb_providers.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22
import sys
3-
from typing import Generator, List, TYPE_CHECKING, Optional
3+
from typing import Generator, Dict, List, TYPE_CHECKING, Optional
44
from enum import Flag, auto
55

66
from lldb import (
@@ -9,6 +9,16 @@
99
eBasicTypeLong,
1010
eBasicTypeUnsignedLong,
1111
eBasicTypeUnsignedChar,
12+
eBasicTypeUnsignedShort,
13+
eBasicTypeUnsignedLongLong,
14+
eBasicTypeSignedChar,
15+
eBasicTypeShort,
16+
eBasicTypeLongLong,
17+
eBasicTypeFloat,
18+
eBasicTypeDouble,
19+
eBasicTypeFloat128,
20+
eBasicTypeHalf,
21+
eBasicTypeChar32,
1222
eFormatChar,
1323
eTypeIsInteger,
1424
)
@@ -198,6 +208,22 @@ def get_template_args(type_name: str) -> Generator[str, None, None]:
198208

199209
MSVC_PTR_PREFIX: List[str] = ["ref$<", "ref_mut$<", "ptr_const$<", "ptr_mut$<"]
200210

211+
PRIMITIVE_TYPES: Dict[str, int] = {
212+
"u8": eBasicTypeUnsignedChar,
213+
"u16": eBasicTypeUnsignedShort,
214+
"u32": eBasicTypeUnsignedLong,
215+
"u64": eBasicTypeUnsignedLongLong,
216+
"i8": eBasicTypeSignedChar,
217+
"i16": eBasicTypeShort,
218+
"i32": eBasicTypeLong,
219+
"i64": eBasicTypeLongLong,
220+
"f16": eBasicTypeHalf,
221+
"f32": eBasicTypeFloat,
222+
"f64": eBasicTypeDouble,
223+
"f128": eBasicTypeFloat128,
224+
"char": eBasicTypeChar32,
225+
}
226+
201227

202228
def resolve_msvc_template_arg(arg_name: str, target: SBTarget) -> SBType:
203229
"""
@@ -214,6 +240,17 @@ def resolve_msvc_template_arg(arg_name: str, target: SBTarget) -> SBType:
214240
current version of LLDB, so instead the types are generated via `base_type.GetPointerType()` and
215241
`base_type.GetArrayType()`, which bypass the PDB file and ask clang directly for the type node.
216242
"""
243+
244+
# As of LLDB 22, finding primitives based on `FindFirstType` with their rust name no longer
245+
# works. Instead, we can look them up by their `eBasicType` equivalent. For usize and isize,
246+
# we convert them to their bit-sized counterpart before the lookup
247+
if arg_name == "isize" or arg_name == "usize":
248+
equivalent = f"{arg_name[0]}{target.GetAddressByteSize() * 8}"
249+
return target.GetBasicType(PRIMITIVE_TYPES[equivalent])
250+
251+
if (basic_type := PRIMITIVE_TYPES.get(arg_name)) is not None:
252+
return target.GetBasicType(basic_type)
253+
217254
result = target.FindFirstType(arg_name)
218255

219256
if result.IsValid():

0 commit comments

Comments
 (0)