def GetPintoolOptions(self, replay_pb, log_pb, options):
        """
        Add the default knobs required for replaying and any user defined options.

        Need '-log' knob in this GDB 'replay' script because the script is
        actually used for both replaying and relogging.  By adding this knob,
        the script can relog if the user enables it with the correct GDB pin
        command.

        @param replay_pb pinball to replay
        @param log_pb is not used
        @param options dictionary of user options

        @return string of options
        """

        replay_o = ' -log'  # No name for the new pinball, use the default name
        replay_o += drd_util.GdbBaseLogOpt()
        replay_o += util.AddMt(options, replay_pb)

        # Add any options user gave on command line.
        #
        if hasattr(options, 'pintool_options') and options.pintool_options:
            replay_o = ' ' + options.pintool_options
        replay_o = ' --replay_options "%s"' % (replay_o)

        return replay_o
    def GetPintoolOptions(self, replay_pb, log_pb, options):
        """
        Add the default knobs required for logging and any user defined options.

        @param replay_pb pinball to replay
        @param log_pb new pinball created by relogging
        @param options dictionary of user options

        @return string of options
        """

        log_o = ' -log -log:basename ' + log_pb
        log_o += config.drdebug_base_log_options
        log_o += util.AddMt(options, replay_pb)

        # Parameter '--log_options' has some knobs which are always used and
        # might have additional knobs from the user.
        #
        if hasattr(options, 'pintool_options') and options.pintool_options:
            log_o += ' ' + options.pintool_options
        log_o = ' --log_options "%s"' % (log_o)

        return log_o
Example #3
0
    def Run(self):
        """
        Get all the user options and run the logger.

        @return Exit code from the logger pintool
        """

        # import pdb;  pdb.set_trace()
        options = self.ParseCommandLine()

        # Get the kit to be used for logging.
        #
        kit = self.GetKit()

        # Set the binary type in the kit.  Assume the first string in the
        # command line is the binary.  Only do this if user hasn't given 'pid'
        # or 'pintool_help'.
        #
        if not (hasattr(options, 'pid') and options.pid) and \
           not (hasattr(options, 'pintool_help') and options.pintool_help):
            binary = options.command.split()[0]
            kit.SetBinaryType(binary)
            if kit.binary_type == config.ARCH_INVALID:
                msg.PrintMsg(
                    '\nWARNING: Unable to determine binary file type.\n'
                    'Perhaps the string assumed to be the binary is incorrect.\n'
                    '   Command line:     ' + options.command + '\n'
                    '   Binary: (assumed) ' + binary + '\n'
                    'Setting binary type to \'Intel64\' as the default value.\n'
                )
        else:
            # If user has given 'pid' or wants 'pintool_help', then need to
            # explictly set the architecture of the binary in the kit.
            #
            kit.binary_type = options.arch

        # Now that we know the type of the binary, set the user defined pintool,
        # if one exists.  Need to wait until now to set the tool because the
        # user may only have the tool in the architecture dependent directory
        # for this type of application.  Thus we need the binary type in order
        # to find it.
        #
        if hasattr(options, 'pintool') and options.pintool:
            kit.SetPinTool(options.pintool)

        # If user just wants 'pintool_help' go ahead and print it, then exit
        # the script.  Need to do this after we get the kit in order to print
        # the help for the correct kit.  Also needs to be after any user
        # defined pintools have been added to the kit. This ensures the
        # correct pintool help msg will be displayed.
        #
        if hasattr(options, 'pintool_help') and options.pintool_help:
            result = util.PintoolHelpKit(kit, options)

            return result

        # Get path to the kit pin binary, any user defined Pin knobs and
        # the pintool.
        #
        # import pdb;  pdb.set_trace()
        cmd = os.path.join(kit.path, kit.pin)
        if hasattr(options, 'pin_options') and options.pin_options:
            cmd += ' ' + options.pin_options
        if hasattr(options, 'pid') and options.pid:
            if kit.kit_type == config.PINPLAY:
                cmd += ' -pid ' + str(options.pid)
            elif kit.kit_type == config.SDE:
                cmd += ' -attach-pid ' + str(options.pid)

        cmd += kit.GetPinToolKnob()

        # Pintool knobs required for logging.
        #
        if not (hasattr(options, 'no_log') and options.no_log):
            cmd += ' -log'
            cmd += ' -xyzzy '

            # Add any knobs required by user options or the type of binary
            #
            if hasattr(options, 'log_file') and options.log_file:
                cmd += self.AddOptionIfNotPresent(options, '-log:basename',
                                                  options.log_file)
            cmd += util.AddMt(options)
            cmd += util.AddCompressed(options)
            cmd += util.GetMsgFileOption(options.log_file)

            # Add any user logging options given by the user
            #
            if hasattr(options, 'log_options') and options.log_options:
                cmd += options.log_options

        # Need to add shared memory knobs and create memory pools for MPI/MP apps.
        #
        create_mem_pool = False
        if options.mode == config.MPI_MODE or options.mode == config.MPI_MT_MODE or \
           options.mode == config.MP_MODE or options.mode == config.MP_MT_MODE:

            # Need to add the MPI options to the existing MT options already in
            # 'pintool_options'.
            #
            if not (hasattr(options, 'no_log') and options.no_log):
                cmd += self.MpModeOptions(options)
                create_mem_pool = True
            else:
                create_mem_pool = False

        # Format the MPI command line, if required to run the command line.
        #
        if options.mode == config.MPI_MODE or options.mode == config.MPI_MT_MODE:
            cmd = util.MPICmdLine(options) + ' ' + cmd

        # If logging enabled for multi-threaded app, generate the mp_pool.
        #
        if create_mem_pool:
            log_key = self.RunMPCreate(kit, options)
            cmd += log_key

        # Add program and arguments
        #
        if not options.pid:
            cmd += ' -- ' + options.command

        # Print out command line used for pin and pintool
        #
        if not (hasattr(options, 'no_print_cmd')
                and options.no_print_cmd) or options.verbose:
            string = '\n' + cmd
            msg.PrintMsg(string)

        # Finally execute the command line and gather stdin and stdout.
        # Exit with the return code from executing the logger.
        #
        result = 0
        # import pdb;  pdb.set_trace()
        if not config.debug:
            platform = util.Platform()
            if not (hasattr(options, 'no_print_cmd') and options.no_print_cmd):
                if platform != config.WIN_NATIVE:
                    cmd = 'time ' + cmd
            p = subprocess.Popen(cmd, shell=True)
            p.communicate()
            result = p.returncode

        # If logging enabled for multi-threaded app, delete the mp_pool.
        #
        if create_mem_pool:
            self.RunMPDelete(kit, log_key, options)

        return result
Example #4
0
    def ParseCommandLine(self):
        """
        Process command line arguments, get Kit, tool options, and their paths.

        @return List containing: pin_options, pintool_options, options.replay_file, kit_obj
        """

        # import pdb;  pdb.set_trace()
        version = '$Revision: 1.63 $'
        version = version.replace(' ', '')
        ver = version.replace(' $', '')
        us = '%prog [options] pinball_basename \nVersion: ' + ver
        desc = 'Replays one pinball. Use \'--replay_options\' or ' \
               '\'--log_options\' to modify the pintool behavior during replay.'
        util.CheckNonPrintChar(sys.argv)
        parser = optparse.OptionParser(usage=us, version=ver, description=desc)

        # Define the command line options which control the behavior of the
        # script.
        #
        # Some of these methods take a 2nd argument which is the empty string
        # ''.  If this script used option groups, then the 2nd parameter would
        # be the group.  However, this script does not use option groups, so
        # the argument is empty.
        #
        cmd_options.arch(parser, '')
        cmd_options.config_file(parser)
        cmd_options.cross_os(parser, '')
        cmd_options.debug(parser)
        cmd_options.global_file(parser)
        cmd_options.log_options(parser)
        cmd_options.msgfile_ext(parser)
        cmd_options.no_print_cmd(parser)
        cmd_options.pintool(parser)
        cmd_options.pintool_help(parser)
        cmd_options.pin_options(parser)
        cmd_options.pinplayhome(parser, '')
        cmd_options.playout(parser)
        cmd_options.replay_file(parser)
        cmd_options.replay_options(parser)
        cmd_options.save_global(parser)
        cmd_options.sdehome(parser, '')
        cmd_options.verbose(parser)

        # import pdb;  pdb.set_trace()
        (options, args) = parser.parse_args()

        if options.verbose:
            msg.PrintMsg('Started replayer.py')
        # Check to make sure the pinball basename has been given as an argument or
        # command line option.
        #
        # import pdb;  pdb.set_trace()
        if options.replay_file == '' and \
           not (hasattr(options, 'pintool_help') and options.pintool_help):
            if len(sys.argv) == 1 or len(args) == 0:
                msg.PrintMsg(
                    "ERROR: Must have a trace basename on the command line.\n"
                    "Usage: %s [options] pinball_basename" %
                    os.path.basename(sys.argv[0]))
                util.CheckResult(-1, options, 'Checking command line options')
            options.replay_file = args[0]

        # Read in an optional configuration files and set global variables.
        #
        config_obj = config.ConfigClass()
        config_obj.GetCfgGlobals(options,
                                 False)  # Don't need to require 4 variables

        # Once the tracing configuration parameters are read, get the kit in
        # case pinplayhome was set on the command line.
        #
        # import pdb;  pdb.set_trace()
        kit_obj = self.GetKit()

        # If user just wants 'pintool_help' go ahead and print it, then exit
        # the script.
        #
        if hasattr(options, 'pintool_help') and options.pintool_help:
            result = util.PintoolHelpKit(kit_obj, options)
            sys.exit(result)

        # Translate the 'arch' value given by the user into
        # the internal arch type used by the scripts.
        #
        if hasattr(options, 'arch') and options.arch:
            if 'intel64' in options.arch:
                options.arch = config.ARCH_INTEL64
            elif 'ia32' in options.arch:
                options.arch = config.ARCH_IA32
            else:
                options.arch = config.ARCH_INVALID

        # Now that we know the type of the binary, set the user defined pintool,
        # if one exists.  Need to wait until now to set the tool because the
        # user may only have the tool in the architecture dependent directory
        # for this type of application.  Thus we need the binary type in order
        # to find it.
        #
        # import pdb;  pdb.set_trace()
        kit_obj.binary_type = options.arch

        pin_options = ''
        pintool_options = ''

        # Check to see if there is a pinball to replay.
        #
        if options.replay_file == "":
            msg.PrintHelpAndExit('Replay file not specified!')

        # If the user specified a pintool, replace the default pintool in the kit with
        # it.
        #
        if hasattr(options, "pintool") and options.pintool:
            kit_obj.SetPinTool(options.pintool, options.replay_file)

        platform = util.Platform()
        if platform == config.LINUX:
            pin_options = ' ' + kit_obj.prefix + ' -xyzzy '

            # If using NOT using Linux tools to work with whole program pinballs generated on Windows,
            # then need a set of  knobs for the pin binary itself.
            #
            if not options.cross_os:
                pin_options += kit_obj.prefix + ' -reserve_memory '
                pin_options += kit_obj.prefix + ' ' + options.replay_file + '.address '

        pintool_options += ' -replay:basename ' + options.replay_file
        if options.playout or '-replay:playout 1' in options.replay_options:
            # If present, need to remove the knob '-replay:playout 1' from
            # options.replay_options because it can only be given once on the
            # command line.
            #
            pintool_options += ' -replay:playout 1 '
            options.replay_options = options.replay_options.replace(
                '-replay:playout 1', '')
        else:
            pintool_options += ' -replay:playout 0 '

        # If running Windows WP pinballs on Linux, then need this knob for the replayer pintool.
        #
        if options.cross_os:
            pintool_options += ' -replay:addr_trans'

        # Add knobs for Pin and replay/logging user gave on the command line.
        #
        pin_options += ' ' + options.pin_options
        pintool_options += ' ' + options.replay_options + ' ' + options.log_options

        # If user has log options, then may need to at multi-thread knob.
        #
        if options.log_options:
            pintool_options += util.AddMt(options, options.replay_file)

        return pin_options, pintool_options, options.replay_file, kit_obj, options