124 lines · cpp
1//===-- SBExecutionContext.cpp --------------------------------------------===//2//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-exception6//7//===----------------------------------------------------------------------===//8 9#include "lldb/API/SBExecutionContext.h"10#include "lldb/Utility/Instrumentation.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 19using namespace lldb;20using namespace lldb_private;21 22SBExecutionContext::SBExecutionContext() { LLDB_INSTRUMENT_VA(this); }23 24SBExecutionContext::SBExecutionContext(const lldb::SBExecutionContext &rhs)25 : m_exe_ctx_sp(rhs.m_exe_ctx_sp) {26 LLDB_INSTRUMENT_VA(this, rhs);27}28 29SBExecutionContext::SBExecutionContext(30 lldb::ExecutionContextRefSP exe_ctx_ref_sp)31 : m_exe_ctx_sp(exe_ctx_ref_sp) {32 LLDB_INSTRUMENT_VA(this, exe_ctx_ref_sp);33}34 35SBExecutionContext::SBExecutionContext(const lldb::SBTarget &target)36 : m_exe_ctx_sp(new ExecutionContextRef()) {37 LLDB_INSTRUMENT_VA(this, target);38 39 m_exe_ctx_sp->SetTargetSP(target.GetSP());40}41 42SBExecutionContext::SBExecutionContext(const lldb::SBProcess &process)43 : m_exe_ctx_sp(new ExecutionContextRef()) {44 LLDB_INSTRUMENT_VA(this, process);45 46 m_exe_ctx_sp->SetProcessSP(process.GetSP());47}48 49SBExecutionContext::SBExecutionContext(lldb::SBThread thread)50 : m_exe_ctx_sp(new ExecutionContextRef()) {51 LLDB_INSTRUMENT_VA(this, thread);52 53 m_exe_ctx_sp->SetThreadPtr(thread.get());54}55 56SBExecutionContext::SBExecutionContext(const lldb::SBFrame &frame)57 : m_exe_ctx_sp(new ExecutionContextRef()) {58 LLDB_INSTRUMENT_VA(this, frame);59 60 m_exe_ctx_sp->SetFrameSP(frame.GetFrameSP());61}62 63SBExecutionContext::~SBExecutionContext() = default;64 65const SBExecutionContext &SBExecutionContext::66operator=(const lldb::SBExecutionContext &rhs) {67 LLDB_INSTRUMENT_VA(this, rhs);68 69 m_exe_ctx_sp = rhs.m_exe_ctx_sp;70 return *this;71}72 73ExecutionContextRef *SBExecutionContext::get() const {74 return m_exe_ctx_sp.get();75}76 77SBTarget SBExecutionContext::GetTarget() const {78 LLDB_INSTRUMENT_VA(this);79 80 SBTarget sb_target;81 if (m_exe_ctx_sp) {82 TargetSP target_sp(m_exe_ctx_sp->GetTargetSP());83 if (target_sp)84 sb_target.SetSP(target_sp);85 }86 return sb_target;87}88 89SBProcess SBExecutionContext::GetProcess() const {90 LLDB_INSTRUMENT_VA(this);91 92 SBProcess sb_process;93 if (m_exe_ctx_sp) {94 ProcessSP process_sp(m_exe_ctx_sp->GetProcessSP());95 if (process_sp)96 sb_process.SetSP(process_sp);97 }98 return sb_process;99}100 101SBThread SBExecutionContext::GetThread() const {102 LLDB_INSTRUMENT_VA(this);103 104 SBThread sb_thread;105 if (m_exe_ctx_sp) {106 ThreadSP thread_sp(m_exe_ctx_sp->GetThreadSP());107 if (thread_sp)108 sb_thread.SetThread(thread_sp);109 }110 return sb_thread;111}112 113SBFrame SBExecutionContext::GetFrame() const {114 LLDB_INSTRUMENT_VA(this);115 116 SBFrame sb_frame;117 if (m_exe_ctx_sp) {118 StackFrameSP frame_sp(m_exe_ctx_sp->GetFrameSP());119 if (frame_sp)120 sb_frame.SetFrameSP(frame_sp);121 }122 return sb_frame;123}124