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 #include "SBReproducerPrivate.h" 12 13 #include "lldb/API/SBFrame.h" 14 #include "lldb/API/SBProcess.h" 15 #include "lldb/API/SBTarget.h" 16 #include "lldb/API/SBThread.h" 17 18 #include "lldb/Target/ExecutionContext.h" 19 20 using namespace lldb; 21 using namespace lldb_private; 22 23 SBExecutionContext::SBExecutionContext() : m_exe_ctx_sp() { 24 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBExecutionContext); 25 } 26 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); 31 } 32 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), 37 exe_ctx_ref_sp); 38 } 39 40 SBExecutionContext::SBExecutionContext(const lldb::SBTarget &target) 41 : m_exe_ctx_sp(new ExecutionContextRef()) { 42 LLDB_RECORD_CONSTRUCTOR(SBExecutionContext, (const lldb::SBTarget &), target); 43 44 m_exe_ctx_sp->SetTargetSP(target.GetSP()); 45 } 46 47 SBExecutionContext::SBExecutionContext(const lldb::SBProcess &process) 48 : m_exe_ctx_sp(new ExecutionContextRef()) { 49 LLDB_RECORD_CONSTRUCTOR(SBExecutionContext, (const lldb::SBProcess &), 50 process); 51 52 m_exe_ctx_sp->SetProcessSP(process.GetSP()); 53 } 54 55 SBExecutionContext::SBExecutionContext(lldb::SBThread thread) 56 : m_exe_ctx_sp(new ExecutionContextRef()) { 57 LLDB_RECORD_CONSTRUCTOR(SBExecutionContext, (lldb::SBThread), thread); 58 59 m_exe_ctx_sp->SetThreadPtr(thread.get()); 60 } 61 62 SBExecutionContext::SBExecutionContext(const lldb::SBFrame &frame) 63 : m_exe_ctx_sp(new ExecutionContextRef()) { 64 LLDB_RECORD_CONSTRUCTOR(SBExecutionContext, (const lldb::SBFrame &), frame); 65 66 m_exe_ctx_sp->SetFrameSP(frame.GetFrameSP()); 67 } 68 69 SBExecutionContext::~SBExecutionContext() {} 70 71 const SBExecutionContext &SBExecutionContext:: 72 operator=(const lldb::SBExecutionContext &rhs) { 73 LLDB_RECORD_METHOD( 74 const lldb::SBExecutionContext &, 75 SBExecutionContext, operator=,(const lldb::SBExecutionContext &), rhs); 76 77 m_exe_ctx_sp = rhs.m_exe_ctx_sp; 78 return LLDB_RECORD_RESULT(*this); 79 } 80 81 ExecutionContextRef *SBExecutionContext::get() const { 82 return m_exe_ctx_sp.get(); 83 } 84 85 SBTarget SBExecutionContext::GetTarget() const { 86 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBTarget, SBExecutionContext, 87 GetTarget); 88 89 SBTarget sb_target; 90 if (m_exe_ctx_sp) { 91 TargetSP target_sp(m_exe_ctx_sp->GetTargetSP()); 92 if (target_sp) 93 sb_target.SetSP(target_sp); 94 } 95 return LLDB_RECORD_RESULT(sb_target); 96 } 97 98 SBProcess SBExecutionContext::GetProcess() const { 99 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBProcess, SBExecutionContext, 100 GetProcess); 101 102 SBProcess sb_process; 103 if (m_exe_ctx_sp) { 104 ProcessSP process_sp(m_exe_ctx_sp->GetProcessSP()); 105 if (process_sp) 106 sb_process.SetSP(process_sp); 107 } 108 return LLDB_RECORD_RESULT(sb_process); 109 } 110 111 SBThread SBExecutionContext::GetThread() const { 112 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBThread, SBExecutionContext, 113 GetThread); 114 115 SBThread sb_thread; 116 if (m_exe_ctx_sp) { 117 ThreadSP thread_sp(m_exe_ctx_sp->GetThreadSP()); 118 if (thread_sp) 119 sb_thread.SetThread(thread_sp); 120 } 121 return LLDB_RECORD_RESULT(sb_thread); 122 } 123 124 SBFrame SBExecutionContext::GetFrame() const { 125 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBFrame, SBExecutionContext, GetFrame); 126 127 SBFrame sb_frame; 128 if (m_exe_ctx_sp) { 129 StackFrameSP frame_sp(m_exe_ctx_sp->GetFrameSP()); 130 if (frame_sp) 131 sb_frame.SetFrameSP(frame_sp); 132 } 133 return LLDB_RECORD_RESULT(sb_frame); 134 } 135 136 namespace lldb_private { 137 namespace repro { 138 139 template <> 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, 154 ()); 155 LLDB_REGISTER_METHOD_CONST(lldb::SBProcess, SBExecutionContext, GetProcess, 156 ()); 157 LLDB_REGISTER_METHOD_CONST(lldb::SBThread, SBExecutionContext, GetThread, 158 ()); 159 LLDB_REGISTER_METHOD_CONST(lldb::SBFrame, SBExecutionContext, GetFrame, ()); 160 } 161 162 } 163 } 164