Exemplo n.º 1
0
void
Driver::WriteCommandsForSourcing (CommandPlacement placement, SBStream &strm)
{
    std::vector<OptionData::InitialCmdEntry> *command_set;
    switch (placement)
    {
    case eCommandPlacementBeforeFile:
        command_set = &m_option_data.m_initial_commands;
        break;
    case eCommandPlacementAfterFile:
        command_set = &m_option_data.m_after_file_commands;
        break;
    case eCommandPlacementAfterCrash:
        command_set = &m_option_data.m_after_crash_commands;
        break;
    }
    
    for (const auto &command_entry : *command_set)
    {
        const char *command = command_entry.contents.c_str();
        if (command_entry.is_file)
        {
            // If this command_entry is a file to be sourced, and it's the ./.lldbinit file (the .lldbinit
            // file in the current working directory), only read it if target.load-cwd-lldbinit is 'true'.
            if (command_entry.is_cwd_lldbinit_file_read)
            {
                SBStringList strlist = m_debugger.GetInternalVariableValue ("target.load-cwd-lldbinit", 
                                                                            m_debugger.GetInstanceName());
                if (strlist.GetSize() == 1 && strcmp (strlist.GetStringAtIndex(0), "warn") == 0)
                {
                    FILE *output = m_debugger.GetOutputFileHandle ();
                    ::fprintf (output, 
                            "There is a .lldbinit file in the current directory which is not being read.\n"
                            "To silence this warning without sourcing in the local .lldbinit,\n"
                            "add the following to the lldbinit file in your home directory:\n"
                            "    settings set target.load-cwd-lldbinit false\n"
                            "To allow lldb to source .lldbinit files in the current working directory,\n"
                            "set the value of this variable to true.  Only do so if you understand and\n"
                            "accept the security risk.\n");
                    return;
                }
                if (strlist.GetSize() == 1 && strcmp (strlist.GetStringAtIndex(0), "false") == 0)
                {
                    return;
                }
            }
            bool source_quietly = m_option_data.m_source_quietly || command_entry.source_quietly;
            strm.Printf("command source -s %i '%s'\n", source_quietly, command);
        }
        else
            strm.Printf("%s\n", command);
    }
}
Exemplo n.º 2
0
unsigned char
IOChannel::HandleCompletion (EditLine *e, int ch)
{
    assert (e == m_edit_line);

    const LineInfo *line_info  = el_line(m_edit_line);
    SBStringList completions;
    int page_size = 40;

    int num_completions = m_driver->GetDebugger().GetCommandInterpreter().HandleCompletion (line_info->buffer,
                                                                                            line_info->cursor,
                                                                                            line_info->lastchar,
                                                                                            0,
                                                                                            -1,
                                                                                            completions);
    
    if (num_completions == -1)
    {
        el_insertstr (m_edit_line, m_completion_key);
        return CC_REDISPLAY;
    }

    // If we get a longer match display that first.
    const char *completion_str = completions.GetStringAtIndex(0);
    if (completion_str != NULL && *completion_str != '\0')
    {
        el_insertstr (m_edit_line, completion_str);
        return CC_REDISPLAY;
    }

    if (num_completions > 1)
    {
        const char *comment = "\nAvailable completions:";

        int num_elements = num_completions + 1;
        OutWrite(comment,  strlen (comment));
        if (num_completions < page_size)
        {
            for (int i = 1; i < num_elements; i++)
            {
                completion_str = completions.GetStringAtIndex(i);
                OutWrite("\n\t", 2);
                OutWrite(completion_str, strlen (completion_str));
            }
            OutWrite ("\n", 1);
        }
        else
        {
            int cur_pos = 1;
            char reply;
            int got_char;
            while (cur_pos < num_elements)
            {
                int endpoint = cur_pos + page_size;
                if (endpoint > num_elements)
                    endpoint = num_elements;
                for (; cur_pos < endpoint; cur_pos++)
                {
                    completion_str = completions.GetStringAtIndex(cur_pos);
                    OutWrite("\n\t", 2);
                    OutWrite(completion_str, strlen (completion_str));
                }

                if (cur_pos >= num_elements)
                {
                    OutWrite("\n", 1);
                    break;
                }

                OutWrite("\nMore (Y/n/a): ", strlen ("\nMore (Y/n/a): "));
                reply = 'n';
                got_char = el_getc(m_edit_line, &reply);
                if (got_char == -1 || reply == 'n')
                    break;
                if (reply == 'a')
                    page_size = num_elements - cur_pos;
            }
        }

    }

    if (num_completions == 0)
        return CC_REFRESH_BEEP;
    else
        return CC_REDISPLAY;
}