I'm looking at how to modify benchmark_size.py to handle macho files as well as elf files. In addition to the processing of the files, works needs to be done on the parsing of the parameters.
In the current implementation the handling and logging is inconsistent between parameters. For example, if the script is run with no parameters given, the log says:
# Establish logging
setup_logging(args.logdir, 'size')
log_args(args)
# Check args are OK (have to have logging and build directory set up first)
validate_args(args)
The handling of many of the parameters is done by the python paring library but for some (e.g. --text) is done in validate_args. Specifically for --text the relevant part of build_parser is
List arguments are empty by default, a user specified value then takes
precedence. If the list is empty after parsing, then we can install a
for argname in ['text', 'rodata', 'data', 'bss']:
secnames = getattr(args, argname)
gp['secnames'][argname] = secnames
would cause the same processing of the --text parameter to occur but the logging would show the defaults rather than what was on the commend line.
Is there a reason for this? My guess is that the command line parser is so complicated that it seemed easier to do it afterwards, but perhaps there is another reason. I'd like to know before I start making modifications to handle macho.
On reflection: Having looked more closely at the implications of modifying either structure, the original seems better in that, with the proposal I am following for supporting macho, the only change in build_parser is the addition of a --format parameter. All the knowledge of standard section names can be deferred to validate_args without the need for build_parser to have to understand the chosen file format.
I'm looking at how to modify
benchmark_size.py
to handle macho files as well as elf files. In addition to the processing of the files, works needs to be done on the parsing of the parameters.In the current implementation the handling and logging is inconsistent between parameters. For example, if the script is run with no parameters given, the log says:
So, for example,
--builddir
shows the default for the parameter, but--text
shows what was actually supplied.The reason for this is that the handling of parameters is split between
build_parser
andvalidate_args
with the logging occurring between the two:The handling of many of the parameters is done by the python paring library but for some (e.g.
--text
) is done invalidate_args
. Specifically for--text
the relevant part ofbuild_parser
isand of
validate_args
is:My understanding of how
add_argument
works is thatand
would cause the same processing of the
--text
parameter to occur but the logging would show the defaults rather than what was on the commend line.Is there a reason for this? My guess is that the command line parser is so complicated that it seemed easier to do it afterwards, but perhaps there is another reason. I'd like to know before I start making modifications to handle macho.
On reflection: Having looked more closely at the implications of modifying either structure, the original seems better in that, with the proposal I am following for supporting macho, the only change in
build_parser
is the addition of a--format
parameter. All the knowledge of standard section names can be deferred tovalidate_args
without the need forbuild_parser
to have to understand the chosen file format.