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
22 changes: 18 additions & 4 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
DETAILED = False
Copy link
Contributor

@theotherjimmy theotherjimmy Sep 28, 2016

Choose a reason for hiding this comment

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

Global variables should not change, so that if we ever need to run many of these concurrently in the same process, we can. Could we make this an object variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean by this? just define it as lowercase?

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean: Don't use a global variable for something that changes at runtime.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

args cannot be accessed from inside the path_object_to_module_name so, unless I add another parameter to path_object_to_module_name signature and propagate it all the way up to the main, I don't see how to implement this without a global variable.

Is this what you would like me to implement? Is there an easier solution?

It is like the 5th time or so that I code something in python so I'd appreciate the input :)

Copy link
Contributor

@theotherjimmy theotherjimmy Sep 29, 2016

Choose a reason for hiding this comment

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

You could: remove the @statictmethod decorator from path_object_to_module_name giving you access to self (you would also have to add it as the first parameter). Then you could pass detailed into the constructor, with a default value of False, assigning it to an attirbute of the object, say detailed_names. That's how I would do it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the input :)

Done

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 Down Expand Up @@ -114,9 +115,17 @@ def path_object_to_module_name(txt):
module_name = data[0] + '/' + data[1]

return [module_name, object_name]
else:

elif DETAILED:
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,14 +629,19 @@ 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:
parser.print_help()
sys.exit(1)


args = parser.parse_args()
args, remainder = parser.parse_known_args()
Copy link
Contributor

@theotherjimmy theotherjimmy Sep 28, 2016

Choose a reason for hiding this comment

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

We don't use parse_know_args. Could you undo this change as well? it also seems unrelated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one slipped trough (I was porting my changes from an older version of memap.py

I'll change it right away :)


global DETAILED
DETAILED = args.detailed

# Create memap object
memap = MemapParser()
Expand Down