Skip to content

Commit

Permalink
Add parameter to (not) include source code in the disassembly
Browse files Browse the repository at this point in the history
By default include the source code in the disassembly

Signed-off-by: Adam Wujek <[email protected]>
  • Loading branch information
awujek authored and Adam Wujek committed Mar 2, 2021
1 parent 706dcc5 commit 415c5e7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
9 changes: 7 additions & 2 deletions puncover/gcc_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down
9 changes: 6 additions & 3 deletions puncover/puncover.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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',
Expand All @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions tests/test_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <pbl_table_addr>:
/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 <window_raw_click_subscribe>:
Expand Down

0 comments on commit 415c5e7

Please sign in to comment.