1 //===-- SBExecutionContext.cpp ------------------------------------*- C++
2 //-*-===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "lldb/API/SBExecutionContext.h"
11 
12 #include "lldb/API/SBFrame.h"
13 #include "lldb/API/SBProcess.h"
14 #include "lldb/API/SBTarget.h"
15 #include "lldb/API/SBThread.h"
16 
17 #include "lldb/Target/ExecutionContext.h"
18 
19 using namespace lldb;
20 using namespace lldb_private;
21 
22 SBExecutionContext::SBExecutionContext() : m_exe_ctx_sp() {}
23 
24 SBExecutionContext::SBExecutionContext(const lldb::SBExecutionContext &rhs)
25     : m_exe_ctx_sp(rhs.m_exe_ctx_sp) {}
26 
27 SBExecutionContext::SBExecutionContext(
28     lldb::ExecutionContextRefSP exe_ctx_ref_sp)
29     : m_exe_ctx_sp(exe_ctx_ref_sp) {}
30 
31 SBExecutionContext::SBExecutionContext(const lldb::SBTarget &target)
32     : m_exe_ctx_sp(new ExecutionContextRef()) {
33   m_exe_ctx_sp->SetTargetSP(target.GetSP());
34 }
35 
36 SBExecutionContext::SBExecutionContext(const lldb::SBProcess &process)
37     : m_exe_ctx_sp(new ExecutionContextRef()) {
38   m_exe_ctx_sp->SetProcessSP(process.GetSP());
39 }
40 
41 SBExecutionContext::SBExecutionContext(lldb::SBThread thread)
42     : m_exe_ctx_sp(new ExecutionContextRef()) {
43   m_exe_ctx_sp->SetThreadPtr(thread.get());
44 }
45 
46 SBExecutionContext::SBExecutionContext(const lldb::SBFrame &frame)
47     : m_exe_ctx_sp(new ExecutionContextRef()) {
48   m_exe_ctx_sp->SetFrameSP(frame.GetFrameSP());
49 }
50 
51 SBExecutionContext::~SBExecutionContext() {}
52 
53 const SBExecutionContext &SBExecutionContext::
54 operator=(const lldb::SBExecutionContext &rhs) {
55   m_exe_ctx_sp = rhs.m_exe_ctx_sp;
56   return *this;
57 }
58 
59 ExecutionContextRef *SBExecutionContext::get() const {
60   return m_exe_ctx_sp.get();
61 }
62 
63 SBTarget SBExecutionContext::GetTarget() const {
64   SBTarget sb_target;
65   if (m_exe_ctx_sp) {
66     TargetSP target_sp(m_exe_ctx_sp->GetTargetSP());
67     if (target_sp)
68       sb_target.SetSP(target_sp);
69   }
70   return sb_target;
71 }
72 
73 SBProcess SBExecutionContext::GetProcess() const {
74   SBProcess sb_process;
75   if (m_exe_ctx_sp) {
76     ProcessSP process_sp(m_exe_ctx_sp->GetProcessSP());
77     if (process_sp)
78       sb_process.SetSP(process_sp);
79   }
80   return sb_process;
81 }
82 
83 SBThread SBExecutionContext::GetThread() const {
84   SBThread sb_thread;
85   if (m_exe_ctx_sp) {
86     ThreadSP thread_sp(m_exe_ctx_sp->GetThreadSP());
87     if (thread_sp)
88       sb_thread.SetThread(thread_sp);
89   }
90   return sb_thread;
91 }
92 
93 SBFrame SBExecutionContext::GetFrame() const {
94   SBFrame sb_frame;
95   if (m_exe_ctx_sp) {
96     StackFrameSP frame_sp(m_exe_ctx_sp->GetFrameSP());
97     if (frame_sp)
98       sb_frame.SetFrameSP(frame_sp);
99   }
100   return sb_frame;
101 }
102