Exemplo n.º 1
0
void CodeLiteLLDBApp::NotifyStopped()
{
    m_variables.clear();
    LLDBReply reply;
    wxPrintf("codelite-lldb: NotifyStopped() called. m_interruptReason=%d\n", (int)m_interruptReason);
    reply.SetReplyType(kReplyTypeDebuggerStopped);
    reply.SetInterruptResaon(m_interruptReason);

    // If we find a thread that was stopped due to breakpoint, make it the active one
    int threadCount = m_target.GetProcess().GetNumThreads();
    for(int i = 0; i < threadCount; ++i) {
        lldb::SBThread thr = m_target.GetProcess().GetThreadAtIndex(i);
        if(thr.GetStopReason() == lldb::eStopReasonBreakpoint) {
            m_target.GetProcess().SetSelectedThread(thr);
            break;
        }
    }

    lldb::SBThread thread = m_target.GetProcess().GetSelectedThread();
    LLDBBacktrace bt(thread, m_settings);
    reply.SetBacktrace(bt);

    int selectedThreadId = thread.GetThreadID();

    // set the selected frame file:line
    if(thread.IsValid() && thread.GetSelectedFrame().IsValid()) {
        lldb::SBFrame frame = thread.GetSelectedFrame();
        lldb::SBLineEntry lineEntry = thread.GetSelectedFrame().GetLineEntry();
        if(lineEntry.IsValid()) {
            reply.SetLine(lineEntry.GetLine());
            lldb::SBFileSpec fileSepc = frame.GetLineEntry().GetFileSpec();
            reply.SetFilename(wxFileName(fileSepc.GetDirectory(), fileSepc.GetFilename()).GetFullPath());
        }
    }

    // Prepare list of threads
    LLDBThread::Vect_t threads;
    for(int i = 0; i < threadCount; ++i) {
        LLDBThread t;
        lldb::SBThread thr = m_target.GetProcess().GetThreadAtIndex(i);
        t.SetStopReason(thr.GetStopReason());
        t.SetId(thr.GetThreadID());
        t.SetActive(selectedThreadId == (int)thr.GetThreadID());
        lldb::SBFrame frame = thr.GetSelectedFrame();
        t.SetFunc(frame.GetFunctionName() ? frame.GetFunctionName() : "");
        lldb::SBLineEntry lineEntry = thr.GetSelectedFrame().GetLineEntry();

        // get the stop reason string
        char buffer[1024];
        memset(buffer, 0x0, sizeof(buffer));
        thr.GetStopDescription(buffer, sizeof(buffer));
        t.SetStopReasonString(buffer);

        wxPrintf("codelite-lldb: thread %d stop reason is %s\n", t.GetId(), t.GetStopReasonString());
        if(lineEntry.IsValid()) {
            t.SetLine(lineEntry.GetLine());
            lldb::SBFileSpec fileSepc = frame.GetLineEntry().GetFileSpec();
            t.SetFile(wxFileName(fileSepc.GetDirectory(), fileSepc.GetFilename()).GetFullPath());
        }
        threads.push_back(t);
    }

    reply.SetThreads(threads);
    SendReply(reply);

    // reset the interrupt reason
    m_interruptReason = kInterruptReasonNone;
}