Skip to content
Snippets Groups Projects
Commit a7d3bcd8 authored by Laura Abbott's avatar Laura Abbott
Browse files

linux-ramdump-parser-v2: Catch parsing exceptions

For reasons ranging from mangled dumps to bugs in code, the parser may
generate exceptions while parsing. Rather than terminate the entire
script, handle exceptions in a more graceful fashion.

Change-Id: I883ee9c0910802b00c797380af5b21e00990dce8
parent 34cd335d
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,7 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
import sys
import traceback
from contextlib import contextmanager
out_file = None
......@@ -30,6 +31,11 @@ def print_out_str(string):
else:
out_file.write((string + '\n').encode('ascii', 'ignore'))
def print_out_exception():
if out_file is None:
traceback.print_exc(file=sys.stdout)
else:
traceback.print_exc(file=out_file)
@contextmanager
def print_out_section(header):
......
......@@ -25,7 +25,7 @@ from optparse import OptionParser
import parser_util
from ramdump import RamDump
from print_out import print_out_str, set_outfile, print_out_section
from print_out import print_out_str, set_outfile, print_out_section, print_out_exception
# Please update version when something is changed!'
VERSION = '2.0'
......@@ -306,7 +306,11 @@ if __name__ == '__main__':
# p.cls.__name__ attribute.
if getattr(options, p.cls.__name__) or (options.everything and not p.optional):
with print_out_section(p.cls.__name__):
p.cls(dump).parse()
try:
p.cls(dump).parse()
except:
print_out_str('!!! Exception while running {0}'.format(p.cls.__name__))
print_out_exception()
if options.t32launcher or options.everything:
dump.create_t32_launcher()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment