Skip to content

Commit ea46e16

Browse files
committed
store only 1 target's data per file
1 parent 4909d45 commit ea46e16

2 files changed

Lines changed: 19 additions & 60 deletions

File tree

src/etc/lldb_batchmode/common.py

Lines changed: 18 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ def annot_to_ty(annot: str) -> type[Any]:
6565
"dict": dict,
6666
"str": str,
6767
"ByteSize": int,
68-
"TestData": TestData,
6968
"TargetData": TargetData,
7069
"Variable": Variable,
7170
"Type": Type,
@@ -244,6 +243,20 @@ class BlessMetadata:
244243

245244
@dataclass(slots=True)
246245
class TargetData:
246+
"""
247+
Top-level container for all test data.
248+
249+
Due to the differences between PDB and DWARF debug info, we cannot guarantee their output
250+
will be identical. Since LLDB can handle both, we need to conditionally select the correct
251+
test data to use.
252+
253+
Additionally, since there are differences in the internals of some structs based on OS (e.g.
254+
`PathBuf`/`OsString`), we need to be aware of whether we're on Windows or not.
255+
256+
A global var `TARGET` is set to the current variant upon `lldb_batchmode`'s instantiation using
257+
an env var passed from `compiletest` and is not expected to change afterwards.
258+
"""
259+
247260
bless_metadata: BlessMetadata = field(default_factory=BlessMetadata)
248261
"""Miscellaneous data included to make diagnosing issues easier. This data is not intended to be
249262
tested against."""
@@ -260,30 +273,9 @@ class TargetData:
260273
"""Each element corresponds to one stopping point in the test. The element itself is a
261274
dictionary mapping variable names to their respective test data."""
262275

263-
264-
@dataclass(slots=True)
265-
class TestData:
266-
"""
267-
Top-level container for all test data.
268-
269-
Due to the differences between PDB and DWARF debug info, we cannot guarantee their output
270-
will be identical. Since LLDB can handle both, we need to conditionally select the correct
271-
test data to use.
272-
273-
Additionally, since there are differences in the internals of some structs based on OS (e.g.
274-
`PathBuf`/`OsString`), we need to be aware of whether we're on Windows or not.
275-
276-
A global var `TARGET` is set to the current variant upon `lldb_batchmode`'s instantiation using
277-
an env var passed from `compiletest` and is not expected to change afterwards.
278-
"""
279-
280-
non_windows: TargetData = field(default_factory=TargetData)
281-
windows_gnu: TargetData = field(default_factory=TargetData)
282-
windows_msvc: TargetData = field(default_factory=TargetData)
283-
284276
@staticmethod
285-
def initialize() -> "TestData":
286-
result = TestData()
277+
def initialize() -> "TargetData":
278+
result = TargetData()
287279
path = os.environ["LLDB_BATCHMODE_INPUT_DATA_PATH"]
288280
if not os.path.isfile(path):
289281
if BLESS:
@@ -296,47 +288,17 @@ def initialize() -> "TestData":
296288

297289
with open(path, "r") as f:
298290
try:
299-
data: dict[str, JsonType] = json.load(f)
291+
result = from_dict(TargetData, json.load(f))
300292
except json.decoder.JSONDecodeError:
301293
print("Warning: Malformed input data, reverting to default")
302-
result.non_windows = TargetData()
303-
result.windows_gnu = TargetData()
304-
result.windows_msvc = TargetData()
305-
return result
306-
307-
if BLESS and TARGET == Target.WindowsGnu:
308-
result.windows_gnu = TargetData()
309-
else:
310-
result.windows_gnu = from_dict(TargetData, data["windows_gnu"])
311-
312-
if BLESS and TARGET == Target.WindowsMsvc:
313-
result.windows_msvc = TargetData()
314-
else:
315-
result.windows_msvc = from_dict(TargetData, data["windows_msvc"])
316-
317-
if BLESS and TARGET == Target.NonWindows:
318-
result.non_windows = TargetData()
319-
else:
320-
result.non_windows = from_dict(TargetData, data["non_windows"])
321294

322295
return result
323296

324-
def get_target_data(self) -> TargetData:
325-
"""Retrieves data from the target specified by `compiletest`"""
326-
327-
if TARGET == Target.WindowsGnu:
328-
return self.windows_gnu
329-
330-
if TARGET == Target.WindowsMsvc:
331-
return self.windows_msvc
332-
333-
return self.non_windows
334-
335297
def save_blessing(self, metadata: BlessMetadata):
336298
"""Writes the entirety of `self` to the input file. Used to finalize changes made by
337299
one or more `TestData.bless_variable` calls."""
338300

339-
self.get_target_data().bless_metadata = metadata
301+
self.bless_metadata = metadata
340302
path = os.environ["LLDB_BATCHMODE_INPUT_DATA_PATH"]
341303
# dumping directly to a file is somewhat unsafe. If the json ends up malformed, we could
342304
# end up overwriting valid test data with a complete mess. Since the in-memory data

src/etc/lldb_batchmode/from_lldb.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
Field,
1313
Target,
1414
TargetData,
15-
TestData,
1615
Type,
1716
Variable,
1817
)
@@ -231,7 +230,7 @@ def variable_from_lldb(var: lldb.SBValue) -> Variable:
231230

232231

233232
def bless_variable(
234-
test_data: TestData, var_name: str, breakpoint_idx: int, frame: lldb.SBFrame
233+
target_data: TargetData, var_name: str, breakpoint_idx: int, frame: lldb.SBFrame
235234
):
236235
"""Updates the mapping with data generated from the given variable. Only affects the mapping
237236
of the current target and breakpoint. This function **does not** write to the input file.
@@ -242,8 +241,6 @@ def bless_variable(
242241
# FIXME (todo) error handling
243242
raise Exception(f"<bless error: Cannot find variable {var_name}>")
244243

245-
target_data = test_data.get_target_data()
246-
247244
if len(target_data.breakpoints) <= breakpoint_idx:
248245
target_data.breakpoints.append({})
249246

0 commit comments

Comments
 (0)