Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flitelf: fix _gen_file_line_table for empty dwarfinfo #258

Merged
merged 1 commit into from
Apr 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions scripts/flitcli/flitelf.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@
from elftools.elf.elffile import ELFFile
from elftools.elf.sections import SymbolTableSection

SymbolTuple = namedtuple('SymbolTuple', 'src, symbol, demangled, fname, lineno')
SymbolTuple = namedtuple('SymbolTuple',
'src, symbol, demangled, fname, lineno')
SymbolTuple.__doc__ = '''
Tuple containing information about the symbols in a file. Has the following
attributes:
Expand Down Expand Up @@ -223,6 +224,15 @@ def _locate_symbols(elffile, symbols):
def _gen_file_line_table(dwarfinfo):
'''
Generates and returns a list of (filename, lineno, startaddr, endaddr).

Tests that an empty dwarfinfo object will result in an empty return list
>>> class FakeDwarf:
... def __init__(self):
... pass
... def iter_CUs(self):
... return []
>>> _gen_file_line_table(FakeDwarf())
[]
'''
# generate the table
table = []
Expand All @@ -238,13 +248,18 @@ def _gen_file_line_table(dwarfinfo):
if prevstate is not None:
filename = lineprog['file_entry'][prevstate.file - 1].name
dirno = lineprog['file_entry'][prevstate.file - 1].dir_index
filepath = os.path.join(lineprog['include_directory'][dirno - 1], filename)
filepath = os.path.join(
lineprog['include_directory'][dirno - 1], filename)
line = prevstate.line
fromaddr = prevstate.address
toaddr = max(fromaddr, entry.state.address)
table.append((filepath, line, fromaddr, toaddr))
prevstate = entry.state

# If there are no functions, then return an empty list
if len(table) == 0:
return []

# consolidate the table
consolidated = []
prev = table[0]
Expand Down