Skip to content

Commit 8d6bfdd

Browse files
authored
Merge pull request diffblue#2575 from nmanthey/upstream-ls_parse
Upstream ls parse
2 parents 2d14b22 + d5ea306 commit 8d6bfdd

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

scripts/ls_parse.py

+11
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import subprocess
1616
import sys
1717
import textwrap
18+
import traceback
1819

1920

2021
def epilog():
@@ -81,6 +82,7 @@ def get_linker_script_data(script):
8182
text = re.sub(r"/\*.*?\*/", " ", text)
8283

8384
close_brace = re.compile(r"\s}(\s*>\s*\w+)?")
85+
uwnknown_cmd = re.compile(r"\sPHDRS\s*{") # only this pattern for now, more might follow!
8486
memory_cmd = re.compile(r"\sMEMORY\s*{")
8587
sections_cmd = re.compile(r"\sSECTIONS\s*{")
8688
assign_current = re.compile(r"\s(?P<sym>\w+)\s*=\s*\.\s*;")
@@ -102,6 +104,7 @@ def get_linker_script_data(script):
102104
# with the info gleaned from the matched string.
103105
jump_table = {
104106
close_brace : close_brace_fun,
107+
uwnknown_cmd : unknown_cmd_fun,
105108
memory_cmd : memory_cmd_fun,
106109
sections_cmd : sections_cmd_fun,
107110
assign_current : assign_current_fun,
@@ -146,6 +149,7 @@ def get_linker_script_data(script):
146149
state["MEM"] = False
147150
state["SEC"] = False
148151
state["DEF"] = False
152+
state["UNKNOWN"] = False
149153

150154
i = 0
151155
while i < len(text):
@@ -274,8 +278,12 @@ def close_brace_fun(state, _, buf):
274278
elif state["MEM"]:
275279
info("Closing memory command")
276280
state["MEM"] = False
281+
elif state["UNKNOWN"]:
282+
info("Closing unknown command")
283+
state["UNKNOWN"] = False
277284
else:
278285
error("Not in block\n%s", buf)
286+
traceback.print_stack()
279287
exit(1)
280288

281289

@@ -306,6 +314,9 @@ def memory_cmd_fun(state, _, buf):
306314
asrt(not state["MEM"], "encountered MEMORY twice", buf)
307315
state["MEM"] = True
308316

317+
def unknown_cmd_fun(state, _, buf):
318+
asrt(not state["MEM"], "encountered UNKNOWN twice", buf)
319+
state["UNKNOWN"] = True
309320

310321
def match_up_expr_assigns(state):
311322
blocks = set([data["origin"] for data in state["expr-assigns"]])

0 commit comments

Comments
 (0)