Skip to content

Commit ee2c518

Browse files
Rollup merge of rust-lang#157289 - Walnut356:msvc_template_args, r=jieyouxu
Add infallible primitive type lookups to template arg resolver Fixes a regression that seem to come from LLDB 22 where looking up primitive types by name on MSVC no longer works. Container types use type name lookups to resolve generics, so it causes container types (e.g. `Vec<i32>`) to fail to create their child values. Before: ``` (lldb) v vec_v (alloc::vec::Vec<i32,alloc::alloc::Global>) vec_v = size=5 {} (lldb) v vec_v[0] error: <user expression 0>:1:6: array index 0 is not valid for "(Vec<i32,alloc::alloc::Global>) vec_v" 1 | vec_v[0] | ^ ``` After: ``` (lldb) v vec_v (alloc::vec::Vec<i32,alloc::alloc::Global>) vec_v = size=5 { [0] = 10 [1] = 20 [2] = 30 [3] = 40 [4] = 50 } (lldb) v vec_v[0] (long) vec_v[0] = 10 ``` This patch maps the type name to its `eBasicType` equivalent (i.e. the LLDB enum for primitive types) and looks up the type based on that. AFAIK, `eBasicType` lookups are 100% infallible. Even if the primitive type somehow isn't in the debug info, `TypeSystemClang` will invent the appropriate `SBType` object for it. This isn't a major blocker for the test suite rework, but it does prevent me from blessing tests with container types on MSVC unless I downgrade to LLDB 21. r? @jieyouxu, @Kobzol
2 parents d35668f + c6945a5 commit ee2c518

3 files changed

Lines changed: 47 additions & 2 deletions

File tree

src/etc/lldb_batchmode/runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def execute_command(command_interpreter, command):
9898
"registering breakpoint callback, id = " + str(breakpoint_id)
9999
)
100100
callback_command = f"breakpoint command add -s python {str(breakpoint_id)} -o \
101-
'import lldb_batchmode; lldb_batchmode.breakpoint_callback'"
101+
'import lldb_batchmode; lldb_batchmode.runner.breakpoint_callback'"
102102

103103
command_interpreter.HandleCommand(callback_command, res)
104104
if res.Succeeded():

src/etc/lldb_lookup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ def __lldb_init_module(debugger: lldb.SBDebugger, _dict: LLDBOpaque):
114114
FEATURE_FLAGS |= LLDBFeature.StaticFields
115115
if getattr(lldb, "eFormatterMatchCallback", None) is not None:
116116
FEATURE_FLAGS |= LLDBFeature.TypeRecognizers
117+
if getattr(lldb, "eBasicTypeFloat128", None) is not None:
118+
FEATURE_FLAGS |= LLDBFeature.Float128
117119

118120
register_providers_compatibility()
119121

src/etc/lldb_providers.py

Lines changed: 44 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,15 @@
99
eBasicTypeLong,
1010
eBasicTypeUnsignedLong,
1111
eBasicTypeUnsignedChar,
12+
eBasicTypeUnsignedShort,
13+
eBasicTypeUnsignedLongLong,
14+
eBasicTypeSignedChar,
15+
eBasicTypeShort,
16+
eBasicTypeLongLong,
17+
eBasicTypeFloat,
18+
eBasicTypeDouble,
19+
eBasicTypeHalf,
20+
eBasicTypeChar32,
1221
eFormatChar,
1322
eTypeIsInteger,
1423
)
@@ -67,6 +76,9 @@ class LLDBFeature(Flag):
6776
"""Added in LLDB 18. Adds functions to `SBType` the inspection of a struct's static fields."""
6877
TypeRecognizers = auto()
6978
"""Added in LLDB 19. Callback-based type matching for synthetic/summary providers."""
79+
Float128 = auto()
80+
"""Added in LLDB 22.1. Adds builtin support for Float 128's, including an `eBasicTypeFloat128`,
81+
a formatter, and handlers in `TypeSystemClang`"""
7082

7183

7284
FEATURE_FLAGS: LLDBFeature = LLDBFeature(0)
@@ -198,6 +210,21 @@ def get_template_args(type_name: str) -> Generator[str, None, None]:
198210

199211
MSVC_PTR_PREFIX: List[str] = ["ref$<", "ref_mut$<", "ptr_const$<", "ptr_mut$<"]
200212

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

202229
def resolve_msvc_template_arg(arg_name: str, target: SBTarget) -> SBType:
203230
"""
@@ -214,6 +241,22 @@ def resolve_msvc_template_arg(arg_name: str, target: SBTarget) -> SBType:
214241
current version of LLDB, so instead the types are generated via `base_type.GetPointerType()` and
215242
`base_type.GetArrayType()`, which bypass the PDB file and ask clang directly for the type node.
216243
"""
244+
245+
# As of LLDB 22, finding primitives based on `FindFirstType` with their rust name no longer
246+
# works. Instead, we can look them up by their `eBasicType` equivalent. For usize and isize,
247+
# we convert them to their bit-sized counterpart before the lookup
248+
if arg_name == "isize" or arg_name == "usize":
249+
equivalent = f"{arg_name[0]}{target.GetAddressByteSize() * 8}"
250+
return target.GetBasicType(PRIMITIVE_TYPES[equivalent])
251+
252+
if (basic_type := PRIMITIVE_TYPES.get(arg_name)) is not None:
253+
return target.GetBasicType(basic_type)
254+
255+
if arg_name == "f128" and LLDBFeature.Float128 in FEATURE_FLAGS:
256+
from lldb import eBasicTypeFloat128
257+
258+
return target.GetBasicType(eBasicTypeFloat128)
259+
217260
result = target.FindFirstType(arg_name)
218261

219262
if result.IsValid():

0 commit comments

Comments
 (0)