1 //===-- SBExecutionContext.cpp --------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "lldb/API/SBExecutionContext.h"
10 #include "SBReproducerPrivate.h"
12 #include "lldb/API/SBFrame.h"
13 #include "lldb/API/SBProcess.h"
14 #include "lldb/API/SBTarget.h"
15 #include "lldb/API/SBThread.h"
17 #include "lldb/Target/ExecutionContext.h"
20 using namespace lldb_private;
22 SBExecutionContext::SBExecutionContext() : m_exe_ctx_sp() {
23 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBExecutionContext);
26 SBExecutionContext::SBExecutionContext(const lldb::SBExecutionContext &rhs)
27 : m_exe_ctx_sp(rhs.m_exe_ctx_sp) {
28 LLDB_RECORD_CONSTRUCTOR(SBExecutionContext,
29 (const lldb::SBExecutionContext &), rhs);
32 SBExecutionContext::SBExecutionContext(
33 lldb::ExecutionContextRefSP exe_ctx_ref_sp)
34 : m_exe_ctx_sp(exe_ctx_ref_sp) {
35 LLDB_RECORD_CONSTRUCTOR(SBExecutionContext, (lldb::ExecutionContextRefSP),
39 SBExecutionContext::SBExecutionContext(const lldb::SBTarget &target)
40 : m_exe_ctx_sp(new ExecutionContextRef()) {
41 LLDB_RECORD_CONSTRUCTOR(SBExecutionContext, (const lldb::SBTarget &), target);
43 m_exe_ctx_sp->SetTargetSP(target.GetSP());
46 SBExecutionContext::SBExecutionContext(const lldb::SBProcess &process)
47 : m_exe_ctx_sp(new ExecutionContextRef()) {
48 LLDB_RECORD_CONSTRUCTOR(SBExecutionContext, (const lldb::SBProcess &),
51 m_exe_ctx_sp->SetProcessSP(process.GetSP());
54 SBExecutionContext::SBExecutionContext(lldb::SBThread thread)
55 : m_exe_ctx_sp(new ExecutionContextRef()) {
56 LLDB_RECORD_CONSTRUCTOR(SBExecutionContext, (lldb::SBThread), thread);
58 m_exe_ctx_sp->SetThreadPtr(thread.get());
61 SBExecutionContext::SBExecutionContext(const lldb::SBFrame &frame)
62 : m_exe_ctx_sp(new ExecutionContextRef()) {
63 LLDB_RECORD_CONSTRUCTOR(SBExecutionContext, (const lldb::SBFrame &), frame);
65 m_exe_ctx_sp->SetFrameSP(frame.GetFrameSP());
68 SBExecutionContext::~SBExecutionContext() = default;
70 const SBExecutionContext &SBExecutionContext::
71 operator=(const lldb::SBExecutionContext &rhs) {
73 const lldb::SBExecutionContext &,
74 SBExecutionContext, operator=,(const lldb::SBExecutionContext &), rhs);
76 m_exe_ctx_sp = rhs.m_exe_ctx_sp;
77 return LLDB_RECORD_RESULT(*this);
80 ExecutionContextRef *SBExecutionContext::get() const {
81 return m_exe_ctx_sp.get();
84 SBTarget SBExecutionContext::GetTarget() const {
85 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBTarget, SBExecutionContext,
90 TargetSP target_sp(m_exe_ctx_sp->GetTargetSP());
92 sb_target.SetSP(target_sp);
94 return LLDB_RECORD_RESULT(sb_target);
97 SBProcess SBExecutionContext::GetProcess() const {
98 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBProcess, SBExecutionContext,
101 SBProcess sb_process;
103 ProcessSP process_sp(m_exe_ctx_sp->GetProcessSP());
105 sb_process.SetSP(process_sp);
107 return LLDB_RECORD_RESULT(sb_process);
110 SBThread SBExecutionContext::GetThread() const {
111 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBThread, SBExecutionContext,
116 ThreadSP thread_sp(m_exe_ctx_sp->GetThreadSP());
118 sb_thread.SetThread(thread_sp);
120 return LLDB_RECORD_RESULT(sb_thread);
123 SBFrame SBExecutionContext::GetFrame() const {
124 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBFrame, SBExecutionContext, GetFrame);
128 StackFrameSP frame_sp(m_exe_ctx_sp->GetFrameSP());
130 sb_frame.SetFrameSP(frame_sp);
132 return LLDB_RECORD_RESULT(sb_frame);
135 namespace lldb_private {
139 void RegisterMethods<SBExecutionContext>(Registry &R) {
140 LLDB_REGISTER_CONSTRUCTOR(SBExecutionContext, ());
141 LLDB_REGISTER_CONSTRUCTOR(SBExecutionContext,
142 (const lldb::SBExecutionContext &));
143 LLDB_REGISTER_CONSTRUCTOR(SBExecutionContext,
144 (lldb::ExecutionContextRefSP));
145 LLDB_REGISTER_CONSTRUCTOR(SBExecutionContext, (const lldb::SBTarget &));
146 LLDB_REGISTER_CONSTRUCTOR(SBExecutionContext, (const lldb::SBProcess &));
147 LLDB_REGISTER_CONSTRUCTOR(SBExecutionContext, (lldb::SBThread));
148 LLDB_REGISTER_CONSTRUCTOR(SBExecutionContext, (const lldb::SBFrame &));
149 LLDB_REGISTER_METHOD(
150 const lldb::SBExecutionContext &,
151 SBExecutionContext, operator=,(const lldb::SBExecutionContext &));
152 LLDB_REGISTER_METHOD_CONST(lldb::SBTarget, SBExecutionContext, GetTarget,
154 LLDB_REGISTER_METHOD_CONST(lldb::SBProcess, SBExecutionContext, GetProcess,
156 LLDB_REGISTER_METHOD_CONST(lldb::SBThread, SBExecutionContext, GetThread,
158 LLDB_REGISTER_METHOD_CONST(lldb::SBFrame, SBExecutionContext, GetFrame, ());