1//===-- ThreadMachCore.cpp --------------------------------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10
11#include "ThreadMachCore.h"
12
13#include "llvm/Support/MachO.h"
14
15#include "lldb/Core/ArchSpec.h"
16#include "lldb/Core/DataExtractor.h"
17#include "lldb/Core/StreamString.h"
18#include "lldb/Core/State.h"
19#include "lldb/Symbol/ObjectFile.h"
20#include "lldb/Target/Process.h"
21#include "lldb/Target/RegisterContext.h"
22#include "lldb/Target/StopInfo.h"
23#include "lldb/Target/Target.h"
24#include "lldb/Target/Unwind.h"
25#include "lldb/Breakpoint/Watchpoint.h"
26
27#include "ProcessMachCore.h"
28//#include "RegisterContextKDP_arm.h"
29//#include "RegisterContextKDP_i386.h"
30//#include "RegisterContextKDP_x86_64.h"
31
32using namespace lldb;
33using namespace lldb_private;
34
35//----------------------------------------------------------------------
36// Thread Registers
37//----------------------------------------------------------------------
38
39ThreadMachCore::ThreadMachCore (Process &process, lldb::tid_t tid) :
40    Thread(process, tid),
41    m_thread_name (),
42    m_dispatch_queue_name (),
43    m_thread_dispatch_qaddr (LLDB_INVALID_ADDRESS),
44    m_thread_reg_ctx_sp ()
45{
46}
47
48ThreadMachCore::~ThreadMachCore ()
49{
50    DestroyThread();
51}
52
53const char *
54ThreadMachCore::GetName ()
55{
56    if (m_thread_name.empty())
57        return NULL;
58    return m_thread_name.c_str();
59}
60
61void
62ThreadMachCore::RefreshStateAfterStop()
63{
64    // Invalidate all registers in our register context. We don't set "force" to
65    // true because the stop reply packet might have had some register values
66    // that were expedited and these will already be copied into the register
67    // context by the time this function gets called. The KDPRegisterContext
68    // class has been made smart enough to detect when it needs to invalidate
69    // which registers are valid by putting hooks in the register read and
70    // register supply functions where they check the process stop ID and do
71    // the right thing.
72    const bool force = false;
73    GetRegisterContext()->InvalidateIfNeeded (force);
74}
75
76bool
77ThreadMachCore::ThreadIDIsValid (lldb::tid_t thread)
78{
79    return thread != 0;
80}
81
82lldb::RegisterContextSP
83ThreadMachCore::GetRegisterContext ()
84{
85    if (m_reg_context_sp.get() == NULL)
86        m_reg_context_sp = CreateRegisterContextForFrame (NULL);
87    return m_reg_context_sp;
88}
89
90lldb::RegisterContextSP
91ThreadMachCore::CreateRegisterContextForFrame (StackFrame *frame)
92{
93    lldb::RegisterContextSP reg_ctx_sp;
94    uint32_t concrete_frame_idx = 0;
95
96    if (frame)
97        concrete_frame_idx = frame->GetConcreteFrameIndex ();
98
99    if (concrete_frame_idx == 0)
100    {
101        if (!m_thread_reg_ctx_sp)
102        {
103            ProcessSP process_sp (GetProcess());
104
105            ObjectFile *core_objfile = static_cast<ProcessMachCore *>(process_sp.get())->GetCoreObjectFile ();
106            if (core_objfile)
107                m_thread_reg_ctx_sp = core_objfile->GetThreadContextAtIndex (GetID(), *this);
108        }
109        reg_ctx_sp = m_thread_reg_ctx_sp;
110    }
111    else
112    {
113        Unwind *unwinder = GetUnwinder ();
114        if (unwinder)
115            reg_ctx_sp = unwinder->CreateRegisterContextForFrame (frame);
116    }
117    return reg_ctx_sp;
118}
119
120bool
121ThreadMachCore::CalculateStopInfo ()
122{
123    ProcessSP process_sp (GetProcess());
124    if (process_sp)
125    {
126        SetStopInfo(StopInfo::CreateStopReasonWithSignal (*this, SIGSTOP));
127        return true;
128    }
129    return false;
130}
131
132
133