1 //===-- SBExecutionContext.cpp ------------------------------------*- C++
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
8 //===----------------------------------------------------------------------===//
10 #include "lldb/API/SBExecutionContext.h"
11 #include "SBReproducerPrivate.h"
13 #include "lldb/API/SBFrame.h"
14 #include "lldb/API/SBProcess.h"
15 #include "lldb/API/SBTarget.h"
16 #include "lldb/API/SBThread.h"
18 #include "lldb/Target/ExecutionContext.h"
21 using namespace lldb_private;
23 SBExecutionContext::SBExecutionContext() : m_exe_ctx_sp() {
24 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBExecutionContext);
27 SBExecutionContext::SBExecutionContext(const lldb::SBExecutionContext &rhs)
28 : m_exe_ctx_sp(rhs.m_exe_ctx_sp) {
29 LLDB_RECORD_CONSTRUCTOR(SBExecutionContext,
30 (const lldb::SBExecutionContext &), rhs);
33 SBExecutionContext::SBExecutionContext(
34 lldb::ExecutionContextRefSP exe_ctx_ref_sp)
35 : m_exe_ctx_sp(exe_ctx_ref_sp) {
36 LLDB_RECORD_CONSTRUCTOR(SBExecutionContext, (lldb::ExecutionContextRefSP),
40 SBExecutionContext::SBExecutionContext(const lldb::SBTarget &target)
41 : m_exe_ctx_sp(new ExecutionContextRef()) {
42 LLDB_RECORD_CONSTRUCTOR(SBExecutionContext, (const lldb::SBTarget &), target);
44 m_exe_ctx_sp->SetTargetSP(target.GetSP());
47 SBExecutionContext::SBExecutionContext(const lldb::SBProcess &process)
48 : m_exe_ctx_sp(new ExecutionContextRef()) {
49 LLDB_RECORD_CONSTRUCTOR(SBExecutionContext, (const lldb::SBProcess &),
52 m_exe_ctx_sp->SetProcessSP(process.GetSP());
55 SBExecutionContext::SBExecutionContext(lldb::SBThread thread)
56 : m_exe_ctx_sp(new ExecutionContextRef()) {
57 LLDB_RECORD_CONSTRUCTOR(SBExecutionContext, (lldb::SBThread), thread);
59 m_exe_ctx_sp->SetThreadPtr(thread.get());
62 SBExecutionContext::SBExecutionContext(const lldb::SBFrame &frame)
63 : m_exe_ctx_sp(new ExecutionContextRef()) {
64 LLDB_RECORD_CONSTRUCTOR(SBExecutionContext, (const lldb::SBFrame &), frame);
66 m_exe_ctx_sp->SetFrameSP(frame.GetFrameSP());
69 SBExecutionContext::~SBExecutionContext() {}
71 const SBExecutionContext &SBExecutionContext::
72 operator=(const lldb::SBExecutionContext &rhs) {
74 const lldb::SBExecutionContext &,
75 SBExecutionContext, operator=,(const lldb::SBExecutionContext &), rhs);
77 m_exe_ctx_sp = rhs.m_exe_ctx_sp;
78 return LLDB_RECORD_RESULT(*this);
81 ExecutionContextRef *SBExecutionContext::get() const {
82 return m_exe_ctx_sp.get();
85 SBTarget SBExecutionContext::GetTarget() const {
86 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBTarget, SBExecutionContext,
91 TargetSP target_sp(m_exe_ctx_sp->GetTargetSP());
93 sb_target.SetSP(target_sp);
95 return LLDB_RECORD_RESULT(sb_target);
98 SBProcess SBExecutionContext::GetProcess() const {
99 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBProcess, SBExecutionContext,
102 SBProcess sb_process;
104 ProcessSP process_sp(m_exe_ctx_sp->GetProcessSP());
106 sb_process.SetSP(process_sp);
108 return LLDB_RECORD_RESULT(sb_process);
111 SBThread SBExecutionContext::GetThread() const {
112 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBThread, SBExecutionContext,
117 ThreadSP thread_sp(m_exe_ctx_sp->GetThreadSP());
119 sb_thread.SetThread(thread_sp);
121 return LLDB_RECORD_RESULT(sb_thread);
124 SBFrame SBExecutionContext::GetFrame() const {
125 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBFrame, SBExecutionContext, GetFrame);
129 StackFrameSP frame_sp(m_exe_ctx_sp->GetFrameSP());
131 sb_frame.SetFrameSP(frame_sp);
133 return LLDB_RECORD_RESULT(sb_frame);
136 namespace lldb_private {
140 void RegisterMethods<SBExecutionContext>(Registry &R) {
141 LLDB_REGISTER_CONSTRUCTOR(SBExecutionContext, ());
142 LLDB_REGISTER_CONSTRUCTOR(SBExecutionContext,
143 (const lldb::SBExecutionContext &));
144 LLDB_REGISTER_CONSTRUCTOR(SBExecutionContext,
145 (lldb::ExecutionContextRefSP));
146 LLDB_REGISTER_CONSTRUCTOR(SBExecutionContext, (const lldb::SBTarget &));
147 LLDB_REGISTER_CONSTRUCTOR(SBExecutionContext, (const lldb::SBProcess &));
148 LLDB_REGISTER_CONSTRUCTOR(SBExecutionContext, (lldb::SBThread));
149 LLDB_REGISTER_CONSTRUCTOR(SBExecutionContext, (const lldb::SBFrame &));
150 LLDB_REGISTER_METHOD(
151 const lldb::SBExecutionContext &,
152 SBExecutionContext, operator=,(const lldb::SBExecutionContext &));
153 LLDB_REGISTER_METHOD_CONST(lldb::SBTarget, SBExecutionContext, GetTarget,
155 LLDB_REGISTER_METHOD_CONST(lldb::SBProcess, SBExecutionContext, GetProcess,
157 LLDB_REGISTER_METHOD_CONST(lldb::SBThread, SBExecutionContext, GetThread,
159 LLDB_REGISTER_METHOD_CONST(lldb::SBFrame, SBExecutionContext, GetFrame, ());