diff --git a/puncover/gcc_tools.py b/puncover/gcc_tools.py index 245e04f..876007a 100644 --- a/puncover/gcc_tools.py +++ b/puncover/gcc_tools.py @@ -5,13 +5,18 @@ class GCCTools: - def __init__(self, gcc_base_filename): + def __init__(self, gcc_base_filename, asm_no_src=False): # if base filename is a directory, make sure we have the trailing slash if os.path.isdir(gcc_base_filename): gcc_base_filename = os.path.join(gcc_base_filename, '') self.gcc_base_filename = gcc_base_filename + # include source code in the disassembly + self.asm_src = "S" + if asm_no_src: + self.asm_src = "" + def gcc_tool_path(self, name): path = self.gcc_base_filename + name if not os.path.isfile(path): @@ -24,7 +29,7 @@ def gcc_tool_lines(self, name, args, cwd=None): return [l.decode() for l in proc.stdout.readlines()] def get_assembly_lines(self, elf_file): - return self.gcc_tool_lines('objdump', ['-dslw', os.path.basename(elf_file)], os.path.dirname(elf_file)) + return self.gcc_tool_lines('objdump', ['-dslw' + self.asm_src, os.path.basename(elf_file)], os.path.dirname(elf_file)) def get_size_lines(self, elf_file): # http://linux.die.net/man/1/nm diff --git a/puncover/puncover.py b/puncover/puncover.py index 79bb9ad..cb36218 100755 --- a/puncover/puncover.py +++ b/puncover/puncover.py @@ -12,8 +12,8 @@ from puncover.gcc_tools import GCCTools from puncover.version import __version__ -def create_builder(gcc_base_filename, elf_file=None, su_dir=None, src_root=None): - c = Collector(GCCTools(gcc_base_filename)) +def create_builder(gcc_base_filename, elf_file=None, su_dir=None, src_root=None, asm_no_src=False): + c = Collector(GCCTools(gcc_base_filename, asm_no_src)) if elf_file: return ElfBuilder(c, src_root, elf_file, su_dir) else: @@ -42,6 +42,8 @@ def main(): help='location of your build output') parser.add_argument('--debug', action='store_true', help='enable Flask debugger') + parser.add_argument('--asm-no-src', action='store_true', + help='Include source code in disassembly') parser.add_argument('--port', dest='port', default=5000, type=int, help='port the HTTP server runs on') parser.add_argument('--host', dest='host', default='127.0.0.1', @@ -54,7 +56,8 @@ def main(): args.gcc_tools_base = os.path.join(args.arm_tools_dir, 'bin/arm-none-eabi-') builder = create_builder(args.gcc_tools_base, elf_file=args.elf_file, - src_root=args.src_root, su_dir=args.build_dir) + src_root=args.src_root, su_dir=args.build_dir, + asm_no_src=args.asm_no_src) builder.build_if_needed() renderers.register_jinja_filters(app.jinja_env) renderers.register_urls(app, builder.collector) diff --git a/tests/test_collector.py b/tests/test_collector.py index 78e74c8..93181e7 100644 --- a/tests/test_collector.py +++ b/tests/test_collector.py @@ -90,6 +90,26 @@ def test_parses_assembly_and_ignores_c(self): self.assertEqual(len(c.symbols[0x00000098]["asm"]), 2) self.assertEqual(c.symbols[0x00000098]["asm"][0], "pbl_table_addr():") + def test_parses_assembly_and_ignores_c2(self): + assembly = """ +int ad; +00000098 : +/path/to.c:8 +pbl_table_addr(): +int pbl_table_addr(void) +{ +int am; + 98: a8a8a8a8 .word 0xa8a8a8a8 +""" + c = Collector(None) + self.assertEqual(1, c.parse_assembly_text(assembly)) + self.assertTrue(0x00000098 in c.symbols) + self.assertEqual(c.symbols[0x00000098]["name"], "pbl_table_addr") + print(c.symbols[0x00000098]["asm"]) + self.assertEqual(len(c.symbols[0x00000098]["asm"]), 5) + self.assertEqual(c.symbols[0x00000098]["asm"][0], "pbl_table_addr():") + + def test_parses_assembly_and_stops_after_function(self): assembly = """ 000034fc :