Exemplo n.º 1
0
void
Driver::OptionData::AddInitialCommand (const char *command, CommandPlacement placement, bool is_file, SBError &error)
{
    std::vector<InitialCmdEntry> *command_set;
    switch (placement)
    {
    case eCommandPlacementBeforeFile:
        command_set = &(m_initial_commands);
        break;
    case eCommandPlacementAfterFile:
        command_set = &(m_after_file_commands);
        break;
    case eCommandPlacementAfterCrash:
        command_set = &(m_after_crash_commands);
        break;
    }

    if (is_file)
    {
        SBFileSpec file(command);
        if (file.Exists())
            command_set->push_back (InitialCmdEntry(command, is_file));
        else if (file.ResolveExecutableLocation())
        {
            char final_path[PATH_MAX];
            file.GetPath (final_path, sizeof(final_path));
            command_set->push_back (InitialCmdEntry(final_path, is_file));
        }
        else
            error.SetErrorStringWithFormat("file specified in --source (-s) option doesn't exist: '%s'", optarg);
    }
    else
        command_set->push_back (InitialCmdEntry(command, is_file));
}
Exemplo n.º 2
0
void
Driver::OptionData::AddInitialCommand (const char *command, bool before_file, bool is_file, SBError &error)
{
    std::vector<std::pair<bool, std::string> > *command_set;
    if (before_file)
        command_set = &(m_initial_commands);
    else
        command_set = &(m_after_file_commands);

    if (is_file)
    {
        SBFileSpec file(command);
        if (file.Exists())
            command_set->push_back (std::pair<bool, std::string> (true, optarg));
        else if (file.ResolveExecutableLocation())
        {
            char final_path[PATH_MAX];
            file.GetPath (final_path, sizeof(final_path));
            std::string path_str (final_path);
            command_set->push_back (std::pair<bool, std::string> (true, path_str));
        }
        else
            error.SetErrorStringWithFormat("file specified in --source (-s) option doesn't exist: '%s'", optarg);
    }
    else
        command_set->push_back (std::pair<bool, std::string> (false, optarg));
}
Exemplo n.º 3
0
bool
SBValue::SetData (lldb::SBData &data, SBError &error)
{
    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
    ValueLocker locker;
    lldb::ValueObjectSP value_sp(GetSP(locker));
    bool ret = true;
    
    if (value_sp)
    {
        DataExtractor *data_extractor = data.get();
        
        if (!data_extractor)
        {
            if (log)
                log->Printf ("SBValue(%p)::SetData() => error: no data to set", value_sp.get());
            
            error.SetErrorString("No data to set");
            ret = false;
        }
        else
        {
            Error set_error;
            
            value_sp->SetData(*data_extractor, set_error);
            
            if (!set_error.Success())
            {
                error.SetErrorStringWithFormat("Couldn't set data: %s", set_error.AsCString());
                ret = false;
            }
        }
    }
    else
    {
        error.SetErrorStringWithFormat ("Couldn't set data: could not get SBValue: %s", locker.GetError().AsCString());
        ret = false;
    }
    
    if (log)
        log->Printf ("SBValue(%p)::SetData (%p) => %s",
                     value_sp.get(),
                     data.get(),
                     ret ? "true" : "false");
    return ret;
}
Exemplo n.º 4
0
uint64_t
SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
{
    error.Clear();
    ValueLocker locker;
    lldb::ValueObjectSP value_sp(GetSP(locker));
    if (value_sp)
    {
        Scalar scalar;
        if (value_sp->ResolveValue (scalar))
            return scalar.ULongLong(fail_value);
        else
            error.SetErrorString("could not resolve value");
    }
    else
        error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString());
    
    return fail_value;
}
Exemplo n.º 5
0
SBError
Driver::ParseArgs (int argc, const char *argv[], FILE *out_fh, bool &exiting)
{
    ResetOptionValues ();

    SBCommandReturnObject result;

    SBError error;
    std::string option_string;
    struct option *long_options = NULL;
    std::vector<struct option> long_options_vector;
    uint32_t num_options;

    for (num_options = 0; g_options[num_options].long_option != NULL; ++num_options)
        /* Do Nothing. */;

    if (num_options == 0)
    {
        if (argc > 1)
            error.SetErrorStringWithFormat ("invalid number of options");
        return error;
    }

    BuildGetOptTable (g_options, long_options_vector, num_options);

    if (long_options_vector.empty())
        long_options = NULL;
    else
        long_options = &long_options_vector.front();

    if (long_options == NULL)
    {
        error.SetErrorStringWithFormat ("invalid long options");
        return error;
    }

    // Build the option_string argument for call to getopt_long_only.

    for (int i = 0; long_options[i].name != NULL; ++i)
    {
        if (long_options[i].flag == NULL)
        {
            option_string.push_back ((char) long_options[i].val);
            switch (long_options[i].has_arg)
            {
                default:
                case no_argument:
                    break;
                case required_argument:
                    option_string.push_back (':');
                    break;
                case optional_argument:
                    option_string.append ("::");
                    break;
            }
        }
    }

    // This is kind of a pain, but since we make the debugger in the Driver's constructor, we can't
    // know at that point whether we should read in init files yet.  So we don't read them in in the
    // Driver constructor, then set the flags back to "read them in" here, and then if we see the
    // "-n" flag, we'll turn it off again.  Finally we have to read them in by hand later in the
    // main loop.
    
    m_debugger.SkipLLDBInitFiles (false);
    m_debugger.SkipAppInitFiles (false);

    // Prepare for & make calls to getopt_long_only.
#if __GLIBC__
    optind = 0;
#else
    optreset = 1;
    optind = 1;
#endif
    int val;
    while (1)
    {
        int long_options_index = -1;
        val = ::getopt_long_only (argc, const_cast<char **>(argv), option_string.c_str(), long_options, &long_options_index);

        if (val == -1)
            break;
        else if (val == '?')
        {
            m_option_data.m_print_help = true;
            error.SetErrorStringWithFormat ("unknown or ambiguous option");
            break;
        }
        else if (val == 0)
            continue;
        else
        {
            m_option_data.m_seen_options.insert ((char) val);
            if (long_options_index == -1)
            {
                for (int i = 0;
                     long_options[i].name || long_options[i].has_arg || long_options[i].flag || long_options[i].val;
                     ++i)
                {
                    if (long_options[i].val == val)
                    {
                        long_options_index = i;
                        break;
                    }
                }
            }

            if (long_options_index >= 0)
            {
                const int short_option = g_options[long_options_index].short_option;

                switch (short_option)
                {
                    case 'h':
                        m_option_data.m_print_help = true;
                        break;

                    case 'v':
                        m_option_data.m_print_version = true;
                        break;

                    case 'P':
                        m_option_data.m_print_python_path = true;
                        break;

                    case 'b':
                        m_option_data.m_batch = true;
                        break;

                    case 'c':
                        {
                            SBFileSpec file(optarg);
                            if (file.Exists())
                            {
                                m_option_data.m_core_file = optarg;
                            }
                            else
                                error.SetErrorStringWithFormat("file specified in --core (-c) option doesn't exist: '%s'", optarg);
                        }
                        break;
                    
                    case 'e':
                        m_option_data.m_use_external_editor = true;
                        break;

                    case 'x':
                        m_debugger.SkipLLDBInitFiles (true);
                        m_debugger.SkipAppInitFiles (true);
                        break;

                    case 'X':
                        m_debugger.SetUseColor (false);
                        break;

                    case 'f':
                        {
                            SBFileSpec file(optarg);
                            if (file.Exists())
                            {
                                m_option_data.m_args.push_back (optarg);
                            }
                            else if (file.ResolveExecutableLocation())
                            {
                                char path[PATH_MAX];
                                file.GetPath (path, sizeof(path));
                                m_option_data.m_args.push_back (path);
                            }
                            else
                                error.SetErrorStringWithFormat("file specified in --file (-f) option doesn't exist: '%s'", optarg);
                        }
                        break;

                    case 'a':
                        if (!m_debugger.SetDefaultArchitecture (optarg))
                            error.SetErrorStringWithFormat("invalid architecture in the -a or --arch option: '%s'", optarg);
                        break;

                    case 'l':
                        m_option_data.m_script_lang = m_debugger.GetScriptingLanguage (optarg);
                        break;

                    case 'd':
                        m_option_data.m_debug_mode = true;
                        break;

                    case 'Q':
                        m_option_data.m_source_quietly = true;
                        break;

                    case 'K':
                        m_option_data.AddInitialCommand(optarg, eCommandPlacementAfterCrash, true, error);
                        break;
                    case 'k':
                        m_option_data.AddInitialCommand(optarg, eCommandPlacementAfterCrash, false, error);
                        break;

                    case 'n':
                        m_option_data.m_process_name = optarg;
                        break;
                    
                    case 'w':
                        m_option_data.m_wait_for = true;
                        break;
                        
                    case 'p':
                        {
                            char *remainder;
                            m_option_data.m_process_pid = strtol (optarg, &remainder, 0);
                            if (remainder == optarg || *remainder != '\0')
                                error.SetErrorStringWithFormat ("Could not convert process PID: \"%s\" into a pid.",
                                                                optarg);
                        }
                        break;
                        
                    case 'r':
                        m_option_data.m_repl = true;
                        if (optarg && optarg[0])
                            m_option_data.m_repl_options = optarg;
                        else
                            m_option_data.m_repl_options.clear();
                        break;
                    
                    case 'R':
                        m_option_data.m_repl_lang = SBLanguageRuntime::GetLanguageTypeFromString (optarg);
                        if (m_option_data.m_repl_lang == eLanguageTypeUnknown)
                        {
                            error.SetErrorStringWithFormat ("Unrecognized language name: \"%s\"", optarg);
                        }
                        break;

                    case 's':
                        m_option_data.AddInitialCommand(optarg, eCommandPlacementAfterFile, true, error);
                        break;
                    case 'o':
                        m_option_data.AddInitialCommand(optarg, eCommandPlacementAfterFile, false, error);
                        break;
                    case 'S':
                        m_option_data.AddInitialCommand(optarg, eCommandPlacementBeforeFile, true, error);
                        break;
                    case 'O':
                        m_option_data.AddInitialCommand(optarg, eCommandPlacementBeforeFile, false, error);
                        break;
                    default:
                        m_option_data.m_print_help = true;
                        error.SetErrorStringWithFormat ("unrecognized option %c", short_option);
                        break;
                }
            }
            else
            {
                error.SetErrorStringWithFormat ("invalid option with value %i", val);
            }
            if (error.Fail())
            {
                return error;
            }
        }
    }
    
    if (error.Fail() || m_option_data.m_print_help)
    {
        ShowUsage (out_fh, g_options, m_option_data);
        exiting = true;
    }
    else if (m_option_data.m_print_version)
    {
        ::fprintf (out_fh, "%s\n", m_debugger.GetVersionString());
        exiting = true;
    }
    else if (m_option_data.m_print_python_path)
    {
        SBFileSpec python_file_spec = SBHostOS::GetLLDBPythonPath();
        if (python_file_spec.IsValid())
        {
            char python_path[PATH_MAX];
            size_t num_chars = python_file_spec.GetPath(python_path, PATH_MAX);
            if (num_chars < PATH_MAX)
            {
                ::fprintf (out_fh, "%s\n", python_path);
            }
            else
                ::fprintf (out_fh, "<PATH TOO LONG>\n");
        }
        else
            ::fprintf (out_fh, "<COULD NOT FIND PATH>\n");
        exiting = true;
    }
    else if (m_option_data.m_process_name.empty() && m_option_data.m_process_pid == LLDB_INVALID_PROCESS_ID)
    {
        // Any arguments that are left over after option parsing are for
        // the program. If a file was specified with -f then the filename
        // is already in the m_option_data.m_args array, and any remaining args
        // are arguments for the inferior program. If no file was specified with
        // -f, then what is left is the program name followed by any arguments.

        // Skip any options we consumed with getopt_long_only
        argc -= optind;
        argv += optind;

        if (argc > 0)
        {
            for (int arg_idx=0; arg_idx<argc; ++arg_idx)
            {
                const char *arg = argv[arg_idx];
                if (arg)
                    m_option_data.m_args.push_back (arg);
            }
        }
        
    }
    else
    {
        // Skip any options we consumed with getopt_long_only
        argc -= optind;
        //argv += optind; // Commented out to keep static analyzer happy

        if (argc > 0)
            ::fprintf (out_fh, "Warning: program arguments are ignored when attaching.\n");
    }

    return error;
}
Exemplo n.º 6
0
lldb::SBWatchpoint
SBValue::Watch (bool resolve_location, bool read, bool write, SBError &error)
{
    SBWatchpoint sb_watchpoint;
    
    // If the SBValue is not valid, there's no point in even trying to watch it.
    ValueLocker locker;
    lldb::ValueObjectSP value_sp(GetSP(locker));
    TargetSP target_sp (GetTarget().GetSP());
    if (value_sp && target_sp)
    {
        // Read and Write cannot both be false.
        if (!read && !write)
            return sb_watchpoint;
        
        // If the value is not in scope, don't try and watch and invalid value
        if (!IsInScope())
            return sb_watchpoint;
        
        addr_t addr = GetLoadAddress();
        if (addr == LLDB_INVALID_ADDRESS)
            return sb_watchpoint;
        size_t byte_size = GetByteSize();
        if (byte_size == 0)
            return sb_watchpoint;
                
        uint32_t watch_type = 0;
        if (read)
            watch_type |= LLDB_WATCH_TYPE_READ;
        if (write)
            watch_type |= LLDB_WATCH_TYPE_WRITE;
        
        Error rc;
        ClangASTType type (value_sp->GetClangType());
        WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, &type, watch_type, rc);
        error.SetError(rc);
                
        if (watchpoint_sp) 
        {
            sb_watchpoint.SetSP (watchpoint_sp);
            Declaration decl;
            if (value_sp->GetDeclaration (decl))
            {
                if (decl.GetFile()) 
                {
                    StreamString ss;
                    // True to show fullpath for declaration file.
                    decl.DumpStopContext(&ss, true);
                    watchpoint_sp->SetDeclInfo(ss.GetString());
                }
            }
        }
    }
    else if (target_sp)
    {
        Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
        if (log)
            log->Printf ("SBValue(%p)::Watch() => error getting SBValue: %s", value_sp.get(), locker.GetError().AsCString());
        
        error.SetErrorStringWithFormat("could not get SBValue: %s", locker.GetError().AsCString());
    }
    else
    {
        Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
        if (log)
            log->Printf ("SBValue(%p)::Watch() => error getting SBValue: no target", value_sp.get());
        error.SetErrorString("could not set watchpoint, a target is required");
    }
    
    return sb_watchpoint;
}