コード例 #1
0
bool CodeLiteLLDBApp::InitializeLLDB(const LLDBCommand& command)
{
    if(IsDebugSessionInProgress()) {
        wxPrintf("codelite-lldb: another session is already in progress\n");
        return false;
    }

    if(!command.GetWorkingDirectory().IsEmpty()) {
        ::wxSetWorkingDirectory(command.GetWorkingDirectory());
    }

    wxPrintf("codelite-lldb: working directory is set to %s\n", ::wxGetCwd());
#ifdef __WXMAC__
    // On OSX, debugserver executable must exists otherwise lldb will not work properly
    // we ensure that it exists by checking the environment variable LLDB_DEBUGSERVER_PATH
    wxString lldbDebugServer;
    if(!::wxGetEnv("LLDB_DEBUGSERVER_PATH", &lldbDebugServer) || !wxFileName::Exists(lldbDebugServer)) {
        wxPrintf("codelite-lldb: LLDB_DEBUGSERVER_PATH environment does not exist or contains a path to a non existent "
                 "file\n");
        NotifyExited();
        return false;
    }
#endif

    m_debuggeePid = wxNOT_FOUND;
    wxPrintf("codelite-lldb: creating target for file '%s'\n", command.GetExecutable());
    m_debugger = lldb::SBDebugger::Create();
    lldb::SBError lldbError;
    m_target = m_debugger.CreateTarget(command.GetExecutable().mb_str().data(), NULL, NULL, true, lldbError);
    if(!m_target.IsValid()) {
        wxPrintf("codelite-lldb: could not create target for file %s. %s\n",
                 command.GetExecutable(),
                 lldbError.GetCString());
        NotifyExited();
        return false;
    }
    // Print the content of the summaries (for debugging purposes)
    wxPrintf("codelite-lldb: created target for %s\n", command.GetExecutable());
    m_debugger.SetAsync(true);

    // Keep the settings
    m_settings = command.GetSettings();

    // First, source the .lldbinit file
    wxString source_command;
    source_command << "command source '" << ::wxGetHomeDir() << "/.lldbinit"
                   << "'";
    DoExecutueShellCommand(source_command);

    // Apply the types
    lldb::SBCommandReturnObject ret;
    wxArrayString commands = ::wxStringTokenize(m_settings.GetTypes(), "\n", wxTOKEN_STRTOK);
    for(size_t i = 0; i < commands.GetCount(); ++i) {
        DoExecutueShellCommand(commands.Item(i));
    }
    // DoExecutueShellCommand("type summary list");
    return true;
}