Пример #1
0
//++ ------------------------------------------------------------------------------------
// Details: Check the arguments that were passed to this program to make sure they are
//          valid and to get their argument values (if any). The following are options
//          that are only handled by *this driver:
//              --executable
//          The application's options --interpreter and --executable in code act very similar.
//          The --executable is necessary to differentiate whether the MI Driver is being
//          used by a client (e.g. Eclipse) or from the command line. Eclipse issues the option
//          --interpreter and also passes additional arguments which can be interpreted as an
//          executable if called from the command line. Using --executable tells the MI
//          Driver is being called the command line and that the executable argument is indeed
//          a specified executable an so actions commands to set up the executable for a
//          debug session. Using --interpreter on the commnd line does not action additional
//          commands to initialise a debug session and so be able to launch the process.
// Type:    Overridden.
// Args:    argc        - (R)   An integer that contains the count of arguments that follow in
//                              argv. The argc parameter is always greater than or equal to 1.
//          argv        - (R)   An array of null-terminated strings representing command-line
//                              arguments entered by the user of the program. By convention,
//                              argv[0] is the command with which the program is invoked.
//          vpStdOut    - (R)   Pointer to a standard output stream.
//          vwbExiting  - (W)   True = *this want to exit, Reasons: help, invalid arg(s),
//                              version information only.
//                              False = Continue to work, start debugger i.e. Command
//                              interpreter.
// Return:  lldb::SBError - LLDB current error status.
// Throws:  None.
//--
lldb::SBError
CMIDriver::ParseArgs(const int argc, const char *argv[], FILE *vpStdOut, bool &vwbExiting)
{
    lldb::SBError errStatus;
    const bool bHaveArgs(argc >= 2);

    // *** Add any args handled here to GetHelpOnCmdLineArgOptions() ***

    // CODETAG_MIDRIVE_CMD_LINE_ARG_HANDLING
    // Look for the command line options
    bool bHaveExecutableFileNamePath = false;
    bool bHaveExecutableLongOption = false;

    if (bHaveArgs)
    {
        // Search right to left to look for the executable
        for (MIint i = argc - 1; i > 0; i--)
        {
            const CMIUtilString strArg(argv[i]);
            const CMICmdArgValFile argFile;
            if (argFile.IsFilePath(strArg) || CMICmdArgValString(true, false, true).IsStringArg(strArg))
            {
                bHaveExecutableFileNamePath = true;
                m_strCmdLineArgExecuteableFileNamePath = strArg;
                m_bHaveExecutableFileNamePathOnCmdLine = true;
            }
            // This argument is also check for in CMIDriverMgr::ParseArgs()
            if (0 == strArg.compare("--executable")) // Used to specify that there is executable argument also on the command line
            {                                        // See fn description.
                bHaveExecutableLongOption = true;
            }
        }
    }

    if (bHaveExecutableFileNamePath && bHaveExecutableLongOption)
    {
        SetDriverDebuggingArgExecutable();
    }

    return errStatus;
}
Пример #2
0
//++ ------------------------------------------------------------------------------------
// Details: Check the arguments that were passed to this program to make sure they are
//          valid and to get their argument values (if any). The following are options
//          that are only handled by *this driver:
//              --executable <file>
//              --source <file> or -s <file>
//          The application's options --interpreter and --executable in code act very similar.
//          The --executable is necessary to differentiate whether the MI Driver is being
//          used by a client (e.g. Eclipse) or from the command line. Eclipse issues the option
//          --interpreter and also passes additional arguments which can be interpreted as an
//          executable if called from the command line. Using --executable tells the MI Driver
//          it is being called from the command line and to prepare to launch the executable
//          argument for a debug session. Using --interpreter on the command line does not
//          issue additional commands to initialise a debug session.
// Type:    Overridden.
// Args:    argc        - (R)   An integer that contains the count of arguments that follow in
//                              argv. The argc parameter is always greater than or equal to 1.
//          argv        - (R)   An array of null-terminated strings representing command-line
//                              arguments entered by the user of the program. By convention,
//                              argv[0] is the command with which the program is invoked.
//          vpStdOut    - (R)   Pointer to a standard output stream.
//          vwbExiting  - (W)   True = *this want to exit, Reasons: help, invalid arg(s),
//                              version information only.
//                              False = Continue to work, start debugger i.e. Command
//                              interpreter.
// Return:  lldb::SBError - LLDB current error status.
// Throws:  None.
//--
lldb::SBError
CMIDriver::ParseArgs(const int argc, const char *argv[], FILE *vpStdOut, bool &vwbExiting)
{
    lldb::SBError errStatus;
    const bool bHaveArgs(argc >= 2);

    // *** Add any args handled here to GetHelpOnCmdLineArgOptions() ***

    // CODETAG_MIDRIVE_CMD_LINE_ARG_HANDLING
    // Look for the command line options
    bool bHaveExecutableFileNamePath = false;
    bool bHaveExecutableLongOption = false;

    if (bHaveArgs)
    {
        // Search right to left to look for filenames
        for (MIint i = argc - 1; i > 0; i--)
        {
            const CMIUtilString strArg(argv[i]);
            const CMICmdArgValFile argFile;

            // Check for a filename
            if (argFile.IsFilePath(strArg) || CMICmdArgValString(true, false, true).IsStringArg(strArg))
            {
                // Is this the command file for the '-s' or '--source' options?
                const CMIUtilString strPrevArg(argv[i - 1]);
                if (strPrevArg.compare("-s") == 0 || strPrevArg.compare("--source") == 0)
                {
                    m_strCmdLineArgCommandFileNamePath = strArg;
                    m_bHaveCommandFileNamePathOnCmdLine = true;
                    i--; // skip '-s' on the next loop
                    continue;
                }
                // Else, must be the executable
                bHaveExecutableFileNamePath = true;
                m_strCmdLineArgExecuteableFileNamePath = strArg;
                m_bHaveExecutableFileNamePathOnCmdLine = true;
            }
            // Report error if no command file was specified for the '-s' or '--source' options
            else if (strArg.compare("-s") == 0 || strArg.compare("--source") == 0)
            {
                vwbExiting = true;
                const CMIUtilString errMsg = CMIUtilString::Format(MIRSRC(IDS_CMD_ARGS_ERR_VALIDATION_MISSING_INF), strArg.c_str());
                errStatus.SetErrorString(errMsg.c_str());
                break;
            }
            // This argument is also checked for in CMIDriverMgr::ParseArgs()
            else if (strArg.compare("--executable") == 0) // Used to specify that there is executable argument also on the command line
            {                                             // See fn description.
                bHaveExecutableLongOption = true;
            }
        }
    }

    if (bHaveExecutableFileNamePath && bHaveExecutableLongOption)
    {
        SetDriverDebuggingArgExecutable();
    }

    return errStatus;
}