From faac445b34d16012d4399bba660ebefeb19a955f Mon Sep 17 00:00:00 2001 From: Jeroen de Bruijn Date: Tue, 26 Feb 2019 14:46:19 +0100 Subject: [PATCH] feat: add support for .obj files in memap --- tools/memap.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/tools/memap.py b/tools/memap.py index f6c4c4a81b..ad8230c278 100644 --- a/tools/memap.py +++ b/tools/memap.py @@ -104,10 +104,11 @@ class _Parser(object): class _GccParser(_Parser): - RE_OBJECT_FILE = re.compile(r'^(.+\/.+\.o)$') - RE_LIBRARY_OBJECT = re.compile(r'^.+' + r''.format(sep) + r'lib((.+\.a)\((.+\.o)\))$') + RE_OBJECT_FILE = re.compile(r'^(.+\/.+\.o(bj)?)$') + RE_LIBRARY_OBJECT = re.compile(r'^.+' + r''.format(sep) + r'lib((.+\.a)\((.+\.o(bj)?)\))$') RE_STD_SECTION = re.compile(r'^\s+.*0x(\w{8,16})\s+0x(\w+)\s(.+)$') RE_FILL_SECTION = re.compile(r'^\s*\*fill\*\s+0x(\w{8,16})\s+0x(\w+).*$') + OBJECT_EXTENSIONS = (".o", ".obj") ALL_SECTIONS = _Parser.SECTIONS + _Parser.OTHER_SECTIONS + \ _Parser.MISC_FLASH_SECTIONS + ('unknown', 'OUTPUT') @@ -214,12 +215,12 @@ class _GccParser(_Parser): self.module_add(object_name, object_size, current_section) common_prefix = dirname(commonprefix([ - o for o in self.modules.keys() if (o.endswith(".o") and not o.startswith("[lib]"))])) + o for o in self.modules.keys() if (o.endswith(self.OBJECT_EXTENSIONS) and not o.startswith("[lib]"))])) new_modules = {} for name, stats in self.modules.items(): if name.startswith("[lib]"): new_modules[name] = stats - elif name.endswith(".o"): + elif name.endswith(self.OBJECT_EXTENSIONS): new_modules[relpath(name, common_prefix)] = stats else: new_modules[name] = stats @@ -229,7 +230,8 @@ class _GccParser(_Parser): class _ArmccParser(_Parser): RE = re.compile( r'^\s+0x(\w{8})\s+0x(\w{8})\s+(\w+)\s+(\w+)\s+(\d+)\s+[*]?.+\s+(.+)$') - RE_OBJECT = re.compile(r'(.+\.(l|ar))\((.+\.o)\)') + RE_OBJECT = re.compile(r'(.+\.(l|ar))\((.+\.o(bj)?)\)') + OBJECT_EXTENSIONS = (".o", ".obj") def parse_object_name(self, line): """ Parse object file @@ -237,7 +239,7 @@ class _ArmccParser(_Parser): Positional arguments: line - the line containing the object or library """ - if line.endswith(".o"): + if line.endswith(self.OBJECT_EXTENSIONS): return line else: @@ -305,12 +307,12 @@ class _ArmccParser(_Parser): self.module_add(*self.parse_section(line)) common_prefix = dirname(commonprefix([ - o for o in self.modules.keys() if (o.endswith(".o") and o != "anon$$obj.o" and not o.startswith("[lib]"))])) + o for o in self.modules.keys() if (o.endswith(self.OBJECT_EXTENSIONS) and o != "anon$$obj.o" and o != "anon$$obj.obj" and not o.startswith("[lib]"))])) new_modules = {} for name, stats in self.modules.items(): - if name == "anon$$obj.o" or name.startswith("[lib]"): + if name == "anon$$obj.o" or name == "anon$$obj.obj" or name.startswith("[lib]"): new_modules[name] = stats - elif name.endswith(".o"): + elif name.endswith(self.OBJECT_EXTENSIONS): new_modules[relpath(name, common_prefix)] = stats else: new_modules[name] = stats @@ -322,9 +324,10 @@ class _IarParser(_Parser): r'^\s+(.+)\s+(zero|const|ro code|inited|uninit)\s' r'+0x([\'\w]+)\s+0x(\w+)\s+(.+)\s.+$') - RE_CMDLINE_FILE = re.compile(r'^#\s+(.+\.o)') + RE_CMDLINE_FILE = re.compile(r'^#\s+(.+\.o(bj)?)') RE_LIBRARY = re.compile(r'^(.+\.a)\:.+$') - RE_OBJECT_LIBRARY = re.compile(r'^\s+(.+\.o)\s.*') + RE_OBJECT_LIBRARY = re.compile(r'^\s+(.+\.o(bj)?)\s.*') + OBJECT_EXTENSIONS = (".o", ".obj") def __init__(self): _Parser.__init__(self) @@ -338,7 +341,7 @@ class _IarParser(_Parser): Positional arguments: line - the line containing the object or library """ - if object_name.endswith(".o"): + if object_name.endswith(self.OBJECT_EXTENSIONS): try: return self.cmd_modules[object_name] except KeyError: @@ -432,7 +435,7 @@ class _IarParser(_Parser): break for arg in line.split(" "): arg = arg.rstrip(" \n") - if (not arg.startswith("-")) and arg.endswith(".o"): + if (not arg.startswith("-")) and arg.endswith(self.OBJECT_EXTENSIONS): self.cmd_modules[basename(arg)] = arg common_prefix = dirname(commonprefix(list(self.cmd_modules.values())))