Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tools] Added -d (--detailed) paremeter to unfold 'Misc' contents in memap.py table #2845

Merged
merged 5 commits into from
Sep 30, 2016
29 changes: 21 additions & 8 deletions tools/memap.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
import argparse
from prettytable import PrettyTable

from tools.utils import argparse_filestring_type, \
from utils import argparse_filestring_type, \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You cannot correctly drop the tools. from the front of this import. Please undo this change, as it has nothing to do with the feature being implemented.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I didn't drop the tool from the front of the import I get the following error runing memap.py as standalone from the tools folder (python memap.py ...)

Traceback (most recent call last):
File "memap.py", line 13, in
from tools.utils import argparse_filestring_type,
ImportError: No module named tools.utils

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll leave it as it is then.

argparse_lowercase_hyphen_type, argparse_uppercase_type

DEBUG = False

RE_ARMCC = re.compile(
r'^\s+0x(\w{8})\s+0x(\w{8})\s+(\w+)\s+(\w+)\s+(\d+)\s+[*]?.+\s+(.+)$')
RE_IAR = re.compile(
Expand All @@ -37,10 +38,12 @@ class MemapParser(object):
# sections to print info (generic for all toolchains)
sections = ('.text', '.data', '.bss', '.heap', '.stack')

def __init__(self):
def __init__(self, detailed_misc=False):
""" General initialization
"""

#
self.detailed_misc = detailed_misc

# list of all modules and their sections
self.modules = dict()

Expand Down Expand Up @@ -90,8 +93,8 @@ def check_new_section_gcc(self, line):
else:
return False # everything else, means no change in section

@staticmethod
def path_object_to_module_name(txt):

def path_object_to_module_name(self, txt):
""" Parse a path to object file to extract it's module and object data

Positional arguments:
Expand All @@ -114,9 +117,17 @@ def path_object_to_module_name(txt):
module_name = data[0] + '/' + data[1]

return [module_name, object_name]
else:

elif self.detailed_misc:
rex_obj_name = r'^.+\/(.+\.o\)*)$'
test_rex_obj_name = re.match(rex_obj_name, txt)
if test_rex_obj_name:
object_name = test_rex_obj_name.group(1)
return ['Misc/' + object_name, ""]

return ['Misc', ""]
else:
return ['Misc', ""]


def parse_section_gcc(self, line):
""" Parse data from a section of gcc map file
Expand Down Expand Up @@ -620,6 +631,8 @@ def main():
", ".join(MemapParser.export_formats))

parser.add_argument('-v', '--version', action='version', version=version)

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

# Parse/run command
if len(sys.argv) <= 1:
Expand All @@ -630,7 +643,7 @@ def main():
args = parser.parse_args()

# Create memap object
memap = MemapParser()
memap = MemapParser(detailed_misc=args.detailed)

# Parse and decode a map file
if args.file and args.toolchain:
Expand Down