Skip to content

Commit

Permalink
symbols: fixed slow symbol load
Browse files Browse the repository at this point in the history
First load all symbols, then sort them.

Signed-off-by: Vitaly Chipounov <[email protected]>
  • Loading branch information
vitalych committed Apr 13, 2024
1 parent 7aa5810 commit 981e12d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
14 changes: 10 additions & 4 deletions s2e_env/symbols/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ def __init__(self, path, search_paths=None):
def add(self, filename, line, addr):
self._lines.add(filename, line, addr)

def add_all(self, lines):
self._lines = LinesByAddr(lines)

def get(self, addr):
"""
Return line and function information for the given address.
Expand Down Expand Up @@ -337,12 +340,15 @@ def parse(self):

lines = json.loads(stdout_data)

resolved_source_lines = {}

for source_file, data in list(lines.items()):
file_path = guess_source_file_path(self._search_paths, source_file)
for line in data.get('lines', []):
for address in line[1]:
self.add(file_path, line[0], address)
parsed = True
resolved_source_lines[file_path] = data
if data.get('lines', []):
parsed = True

self.add_all(resolved_source_lines)

if parsed:
break
Expand Down
15 changes: 14 additions & 1 deletion s2e_env/symbols/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,22 @@ class LinesByAddr:

__slots__ = ('_lines',)

def __init__(self):
def __init__(self, lines = None):
self._lines = []

if not lines:
return

for file_path, data in list(lines.items()):
for line in data.get('lines', []):
line_number = line[0]
line_addresses = line[1]
for line_address in line_addresses:
sym = LineInfoEntry(file_path, line_number, line_address)
self._lines.append(sym)

self._lines.sort()

def _index(self, x):
# Find rightmost value less than or equal to x
i = bisect.bisect_right(self._lines, x)
Expand Down

0 comments on commit 981e12d

Please sign in to comment.