Skip to content

Commit 1ba3499

Browse files
authored
Merge pull request #3003 from c1728p9/fix_memory_map
Revert "Allow max-depth specification in memap"
2 parents 73e708d + 7a50832 commit 1ba3499

File tree

1 file changed

+43
-42
lines changed

1 file changed

+43
-42
lines changed

tools/memap.py

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
RE_IAR = re.compile(
2121
r'^\s+(.+)\s+(zero|const|ro code|inited|uninit)\s'
2222
r'+0x(\w{8})\s+0x(\w+)\s+(.+)\s.+$')
23-
RE_LIB_MATCH = re.compile("^.*/(.*\.a)\((.*)\)$")
2423

2524
class MemapParser(object):
2625
"""An object that represents parsed results, parses the memory map files,
@@ -38,16 +37,13 @@ class MemapParser(object):
3837

3938
# sections to print info (generic for all toolchains)
4039
sections = ('.text', '.data', '.bss', '.heap', '.stack')
41-
MAXDEPTH = object()
4240

43-
def __init__(self, depth=2):
41+
def __init__(self, detailed_misc=False):
4442
""" General initialization
4543
"""
46-
47-
self.depth = depth
48-
49-
self.mapfile = None
50-
44+
#
45+
self.detailed_misc = detailed_misc
46+
5147
# list of all modules and their sections
5248
self.modules = dict()
5349

@@ -102,7 +98,7 @@ def check_new_section_gcc(self, line):
10298
else:
10399
return False # everything else, means no change in section
104100

105-
101+
106102
def path_object_to_module_name(self, txt):
107103
""" Parse a path to object file to extract it's module and object data
108104
@@ -111,25 +107,32 @@ def path_object_to_module_name(self, txt):
111107
"""
112108

113109
txt = txt.replace('\\', '/')
114-
name = txt.split('/')
115-
mapfile_beginning = os.path.dirname(self.mapfile).split('/')
116-
if name[0] == "." or name[0] == "":
117-
name = name[1:]
118-
for thing in mapfile_beginning:
119-
if name[0] == thing:
120-
name = name[1:]
121-
elif name[0] in mapfile_beginning:
122-
pass
110+
rex_mbed_os_name = r'^.+mbed-os\/(.+)\/(.+\.o)$'
111+
test_rex_mbed_os_name = re.match(rex_mbed_os_name, txt)
112+
113+
if test_rex_mbed_os_name:
114+
115+
object_name = test_rex_mbed_os_name.group(2)
116+
data = test_rex_mbed_os_name.group(1).split('/')
117+
ndata = len(data)
118+
119+
if ndata == 1:
120+
module_name = data[0]
123121
else:
124-
break
125-
if name[0] == "mbed-os":
126-
name = name[1:]
127-
if name[0] == "features":
128-
name = name[1:]
129-
is_lib = RE_LIB_MATCH.match(txt)
130-
if is_lib:
131-
name = ["libraries", is_lib.group(1), is_lib.group(2)]
132-
return "/".join(name), name[-1]
122+
module_name = data[0] + '/' + data[1]
123+
124+
return [module_name, object_name]
125+
126+
elif self.detailed_misc:
127+
rex_obj_name = r'^.+\/(.+\.o\)*)$'
128+
test_rex_obj_name = re.match(rex_obj_name, txt)
129+
if test_rex_obj_name:
130+
object_name = test_rex_obj_name.group(1)
131+
return ['Misc/' + object_name, ""]
132+
133+
return ['Misc', ""]
134+
else:
135+
return ['Misc', ""]
133136

134137
def parse_section_gcc(self, line):
135138
""" Parse data from a section of gcc map file
@@ -364,7 +367,15 @@ def search_objects(self, path):
364367

365368
path = path.replace('\\', '/')
366369

367-
search_path = os.path.dirname(path)
370+
# check location of map file
371+
rex = r'^(.+)' + r'\/(.+\.map)$'
372+
test_rex = re.match(rex, path)
373+
374+
if test_rex:
375+
search_path = test_rex.group(1) + '/mbed-os/'
376+
else:
377+
print "Warning: this doesn't look like an mbed project"
378+
return
368379

369380
for root, _, obj_files in os.walk(search_path):
370381
for obj_file in obj_files:
@@ -479,19 +490,11 @@ def generate_table(self, file_desc):
479490
for i in list(self.print_sections):
480491
table.align[i] = 'r'
481492

482-
local_modules = {}
483493
for i in sorted(self.modules):
484-
module_name = "/".join(i.split("/")[:self.depth])
485-
local_modules.setdefault(module_name,
486-
{k: 0 for k in self.print_sections})
487-
for k in self.print_sections:
488-
local_modules[module_name][k] += self.modules[i][k]
489-
490-
for i in sorted(local_modules.keys()):
491494
row = [i]
492495

493496
for k in self.print_sections:
494-
row.append(local_modules[i][k])
497+
row.append(self.modules[i][k])
495498

496499
table.add_row(row)
497500

@@ -572,8 +575,6 @@ def parse(self, mapfile, toolchain):
572575
toolchain - the toolchain used to create the file
573576
"""
574577

575-
self.mapfile = mapfile
576-
577578
result = True
578579
try:
579580
with open(mapfile, 'r') as file_input:
@@ -588,8 +589,9 @@ def parse(self, mapfile, toolchain):
588589
self.parse_map_file_iar(file_input)
589590
else:
590591
result = False
592+
591593
self.compute_report()
592-
594+
593595
except IOError as error:
594596
print "I/O error({0}): {1}".format(error.errno, error.strerror)
595597
result = False
@@ -629,7 +631,6 @@ def main():
629631

630632
parser.add_argument('-d', '--detailed', action='store_true', help='Displays the elements in "Misc" in a detailed fashion', required=False)
631633

632-
parser.add_argument('--max-depth', dest='max_depth', type=int, help='Displays the elements in "Misc" in a detailed fashion', required=False, default=None)
633634
# Parse/run command
634635
if len(sys.argv) <= 1:
635636
parser.print_help()
@@ -639,7 +640,7 @@ def main():
639640
args = parser.parse_args()
640641

641642
# Create memap object
642-
memap = MemapParser(depth=(args.max_depth or (MemapParser.MAXDEPTH if args.detailed else 2)))
643+
memap = MemapParser(detailed_misc=args.detailed)
643644

644645
# Parse and decode a map file
645646
if args.file and args.toolchain:

0 commit comments

Comments
 (0)