Skip to content

Commit 7bbe502

Browse files
committed
cvdump symbols: ignore S_LDATA32 outside of a function
1 parent 5e5f816 commit 7bbe502

2 files changed

Lines changed: 41 additions & 2 deletions

File tree

reccmp/isledecomp/cvdump/symbols.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ def _parse_generic_case(self, line, line_match: Match[str]):
203203
type=match.group("type"),
204204
name=match.group("name"),
205205
)
206-
assert self.current_function is not None
207-
self.current_function.static_variables.append(new_var)
206+
if self.current_function is not None:
207+
self.current_function.static_variables.append(new_var)
208208

209209
elif symbol_type in self._unhandled_symbols:
210210
return

tests/test_cvdump_symbols.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,42 @@ def test_sblock32():
3636
# Make sure we can read the proc and all its stack references
3737
assert len(parser.symbols) == 1
3838
assert len(parser.symbols[0].stack_symbols) == 8
39+
40+
41+
LDATA32_INSIDE_FUNCTION = """\
42+
(004368) S_GPROC32: [0001:00050A28], Cb: 000000B5, Type: 0x1010, GetCDPathFromPathsTxtFile
43+
44+
(0043AC) S_BPREL32: [00000008], Type: T_32PRCHAR(0470), pPath_name
45+
(0043C4) S_LDATA32: [0003:0000B3C4], Type: T_INT4(0074), got_it_already
46+
(0043E4) S_LDATA32: [0003:0003C488], Type: 0x100B, cd_pathname
47+
48+
(004400) S_END
49+
"""
50+
51+
52+
def test_ldata32_inside_function():
53+
"""S_LDATA32 leaves inside of a function (S_GPROC32) are assumed to be
54+
static variables from that function."""
55+
parser = CvdumpSymbolsParser()
56+
for line in LDATA32_INSIDE_FUNCTION.split("\n"):
57+
parser.read_line(line)
58+
59+
assert len(parser.symbols) == 1
60+
assert len(parser.symbols[0].static_variables) == 2
61+
assert [v.name for v in parser.symbols[0].static_variables] == [
62+
"got_it_already",
63+
"cd_pathname",
64+
]
65+
66+
67+
def test_ldata32_outside_function():
68+
"""Should ignore an S_LDATA32 leaf found outside a function.
69+
These appear to indicate const global variables and they should be
70+
repeated in the GLOBALS section."""
71+
parser = CvdumpSymbolsParser()
72+
parser.read_line(
73+
"(00045C) S_LDATA32: [0003:0000E298], Type: 0x1060, TestVariable"
74+
)
75+
76+
# ignored... for now.
77+
assert len(parser.symbols) == 0

0 commit comments

Comments
 (0)