void listener_func() {
  while (!g_done) {
    SBEvent event;
    bool got_event = g_listener.WaitForEvent(1, event);
    if (got_event) {
      if (!event.IsValid())
        throw Exception("event is not valid in listener thread");
        // send process description
        SBProcess process = SBProcess::GetProcessFromEvent(event);
        if (!process.IsValid())
            throw Exception("process is not valid");
        if (SBProcess::GetStateFromEvent(event) != lldb::eStateStopped || SBProcess::GetRestartedFromEvent(event))
            continue; // Only interested in "stopped" events.

        SBStream description;

        for (int i = 0; i < process.GetNumThreads(); ++i) {
            // send each thread description
            SBThread thread = process.GetThreadAtIndex(i);
            // send each frame function name
            uint32_t num_frames = thread.GetNumFrames();
            for(int j = 0; j < num_frames; ++j) {
                const char* function_name = thread.GetFrameAtIndex(j).GetSymbol().GetName();
                if (function_name)
                    g_frame_functions.push(string(function_name));
            }
        }
    }
  }
}
void listener_func() {
  while (!g_done) {
    SBEvent event;
    bool got_event = g_listener.WaitForEvent(1, event);
    if (got_event) {
      if (!event.IsValid())
        throw Exception("event is not valid in listener thread");

      // send process description
      SBProcess process = SBProcess::GetProcessFromEvent(event);
      SBStream description;

      for (int i = 0; i < process.GetNumThreads(); ++i) {
        // send each thread description
        description.Clear();
        SBThread thread = process.GetThreadAtIndex(i);
        thread.GetDescription(description);
        g_thread_descriptions.push(description.GetData());

        // send each frame function name
        uint32_t num_frames = thread.GetNumFrames();
        for(int j = 0; j < num_frames; ++j) {
          const char* function_name = thread.GetFrameAtIndex(j).GetSymbol().GetName();
          if (function_name)
            g_frame_functions.push(function_name);
        }
      }
    }
  }
}
示例#3
0
char *
formatThreadInfo (StringB &threaddescB, SBProcess process, int threadindexid)
{
	logprintf (LOG_TRACE, "formatThreadInfo (0x%x, 0x%x, %d)\n", &threaddescB, &process, threadindexid);
	threaddescB.clear();
	if (!process.IsValid())
		return threaddescB.c_str();
	int pid=process.GetProcessID();
	int state = process.GetState ();
	if (state == eStateStopped) {
		int tmin, tmax;
		bool useindexid;
		if (threadindexid < 0) {
			tmin = 0;
			tmax = process.GetNumThreads();
			useindexid = false;
		}
		else{
			tmin = threadindexid;
			tmax = threadindexid+1;
			useindexid = false;
		}
		const char *separator="";
		for (int ithread=tmin; ithread<tmax; ithread++) {
			SBThread thread;
			if (useindexid)
				thread = process.GetThreadByIndexID(ithread);
			else
				thread = process.GetThreadAtIndex(ithread);
			if (!thread.IsValid())
				continue;
			int tid=thread.GetThreadID();
			threadindexid=thread.GetIndexID();
			int frames = getNumFrames (thread);
			if (frames > 0) {
				SBFrame frame = thread.GetFrameAtIndex(0);
				if (frame.IsValid()) {
					char * framedescstr = formatFrame (frame, WITH_LEVEL_AND_ARGS);
					threaddescB.catsprintf (
						"%s{id=\"%d\",target-id=\"Thread 0x%x of process %d\",%s,state=\"stopped\"}",
						separator, threadindexid, tid, pid, framedescstr);
				}
			}
			separator=",";
		}
	}
	return threaddescB.c_str();
}
示例#4
0
// get the number of frames in a thread
// adjust the number of frames if libdyld.dylib is there
int
getNumFrames (SBThread thread)
{
	logprintf (LOG_TRACE, "getNumFrames(0x%x)\n", &thread);
	int numframes=thread.GetNumFrames();
	logprintf (LOG_DEBUG, "getNumFrames(0x%x) = %d\n", &thread, numframes);
	return numframes;
}
示例#5
0
bool
SBProcess::SetSelectedThread (const SBThread &thread)
{
    if (m_opaque_sp)
    {
        Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
        return m_opaque_sp->GetThreadList().SetSelectedThreadByID (thread.GetThreadID());
    }
    return false;
}
示例#6
0
bool
SBProcess::SetSelectedThread (const SBThread &thread)
{
    ProcessSP process_sp(GetSP());
    if (process_sp)
    {
        Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
        return process_sp->GetThreadList().SetSelectedThreadByID (thread.GetThreadID());
    }
    return false;
}
示例#7
0
SBThread
SBProcess::GetThreadAtIndex (size_t index)
{
    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));

    SBThread thread;
    if (m_opaque_sp)
    {
        Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
        thread.SetThread (m_opaque_sp->GetThreadList().GetThreadAtIndex(index));
    }

    if (log)
    {
        log->Printf ("SBProcess(%p)::GetThreadAtIndex (index=%d) => SBThread(%p)",
                     m_opaque_sp.get(), (uint32_t) index, thread.get());
    }

    return thread;
}
示例#8
0
文件: SBValue.cpp 项目: markpeek/lldb
lldb::SBThread
SBValue::GetThread()
{
    SBThread result;
    if (m_opaque_sp)
    {
        if (m_opaque_sp->GetExecutionContextScope())
        {
            result = SBThread(m_opaque_sp->GetExecutionContextScope()->CalculateThread()->GetSP());
        }
    }
    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
    if (log)
    {
        if (result.get() == NULL)
            log->Printf ("SBValue(%p)::GetThread () => NULL", m_opaque_sp.get());
        else
            log->Printf ("SBValue(%p)::GetThread () => %p", m_opaque_sp.get(), result.get());
    }
    return result;
}
示例#9
0
void
Driver::UpdateSelectedThread ()
{
    using namespace lldb;
    SBProcess process(m_debugger.GetSelectedTarget().GetProcess());
    if (!process.IsValid())
        return;
    
    SBThread curr_thread (process.GetSelectedThread());
    SBThread thread;
    StopReason curr_thread_stop_reason = eStopReasonInvalid;
    curr_thread_stop_reason = curr_thread.GetStopReason();

    if (!curr_thread.IsValid() ||
        curr_thread_stop_reason == eStopReasonInvalid ||
        curr_thread_stop_reason == eStopReasonNone)
    {
        // Prefer a thread that has just completed its plan over another thread as current thread.
        SBThread plan_thread;
        SBThread other_thread;
       const size_t num_threads = process.GetNumThreads();
        size_t i;
        for (i = 0; i < num_threads; ++i)
        {
            thread = process.GetThreadAtIndex(i);
            StopReason thread_stop_reason = thread.GetStopReason();
            switch (thread_stop_reason)
			{
            default:
            case eStopReasonInvalid:
            case eStopReasonNone:
                break;

            case eStopReasonTrace:
            case eStopReasonBreakpoint:
            case eStopReasonWatchpoint:
            case eStopReasonSignal:
            case eStopReasonException:
                if (!other_thread.IsValid())
                    other_thread = thread;
                break;
            case eStopReasonPlanComplete:
                if (!plan_thread.IsValid())
                    plan_thread = thread;
                break;
            }
        }
        if (plan_thread.IsValid())
            process.SetSelectedThread (plan_thread);
        else if (other_thread.IsValid())
            process.SetSelectedThread (other_thread);
        else
		{
			if (curr_thread.IsValid())
				thread = curr_thread;
			else
				thread = process.GetThreadAtIndex(0);

			if (thread.IsValid())
				process.SetSelectedThread (thread);
        }
    }
}
示例#10
0
void
Xcode::Next (SBThread thread)
{
	thread.StepOver();
}