blob: c0e272e1bcd4f357414cfbcb43444e36d4240a56 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- SBFrame.cpp ---------------------------------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006//
7//===----------------------------------------------------------------------===//
8
Chris Lattner30fdc8d2010-06-08 16:52:24 +00009#include <algorithm>
Greg Clayton349213f2016-04-29 21:00:38 +000010#include <set>
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +000011#include <string>
12
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +000013#include "lldb/API/SBFrame.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000014
15#include "lldb/lldb-types.h"
16
Jonas Devliegherebaf56642019-03-06 00:06:00 +000017#include "SBReproducerPrivate.h"
Jonas Devliegherebd4bf822019-03-06 00:05:55 +000018#include "Utils.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "lldb/Core/Address.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020#include "lldb/Core/StreamFile.h"
21#include "lldb/Core/ValueObjectRegister.h"
22#include "lldb/Core/ValueObjectVariable.h"
Alex Langford347ec0f2019-06-13 23:40:34 +000023#include "lldb/Expression/ExpressionVariable.h"
Jim Ingham151c0322015-09-15 21:13:50 +000024#include "lldb/Expression/UserExpression.h"
Greg Clayton1ba7c4d2011-06-25 04:35:01 +000025#include "lldb/Host/Host.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026#include "lldb/Symbol/Block.h"
Greg Clayton1f746072012-08-29 21:13:06 +000027#include "lldb/Symbol/Function.h"
28#include "lldb/Symbol/Symbol.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Symbol/SymbolContext.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030#include "lldb/Symbol/Variable.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000031#include "lldb/Symbol/VariableList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032#include "lldb/Target/ExecutionContext.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033#include "lldb/Target/Process.h"
34#include "lldb/Target/RegisterContext.h"
Jason Molendab57e4a12013-11-04 09:33:30 +000035#include "lldb/Target/StackFrame.h"
Kuba Mracek41ae8e72018-10-31 04:00:22 +000036#include "lldb/Target/StackFrameRecognizer.h"
Greg Claytonb9556ac2012-01-30 07:41:31 +000037#include "lldb/Target/StackID.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000038#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039#include "lldb/Target/Thread.h"
Zachary Turnerbf9a7732017-02-02 21:39:50 +000040#include "lldb/Utility/ConstString.h"
41#include "lldb/Utility/Stream.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000042
Eli Friedman4c5de692010-06-09 07:44:37 +000043#include "lldb/API/SBAddress.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000044#include "lldb/API/SBDebugger.h"
Jim Ingham35e1bda2012-10-16 21:41:58 +000045#include "lldb/API/SBExpressionOptions.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000046#include "lldb/API/SBStream.h"
Eli Friedman4c5de692010-06-09 07:44:37 +000047#include "lldb/API/SBSymbolContext.h"
48#include "lldb/API/SBThread.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000049#include "lldb/API/SBValue.h"
Zachary Turner51f96ee2015-02-17 17:55:50 +000050#include "lldb/API/SBVariablesOptions.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000051
Sean Callanan237c3ed2016-12-14 21:31:31 +000052#include "llvm/Support/PrettyStackTrace.h"
53
Chris Lattner30fdc8d2010-06-08 16:52:24 +000054using namespace lldb;
55using namespace lldb_private;
56
Jonas Devliegherebaf56642019-03-06 00:06:00 +000057SBFrame::SBFrame() : m_opaque_sp(new ExecutionContextRef()) {
58 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBFrame);
59}
Kate Stoneb9c1b512016-09-06 20:57:50 +000060
61SBFrame::SBFrame(const StackFrameSP &lldb_object_sp)
62 : m_opaque_sp(new ExecutionContextRef(lldb_object_sp)) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +000063 LLDB_RECORD_CONSTRUCTOR(SBFrame, (const lldb::StackFrameSP &),
64 lldb_object_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000065}
66
Jonas Devliegherebd4bf822019-03-06 00:05:55 +000067SBFrame::SBFrame(const SBFrame &rhs) : m_opaque_sp() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +000068 LLDB_RECORD_CONSTRUCTOR(SBFrame, (const lldb::SBFrame &), rhs);
69
Jonas Devliegherebd4bf822019-03-06 00:05:55 +000070 m_opaque_sp = clone(rhs.m_opaque_sp);
71}
Greg Claytonefabb122010-11-05 23:17:00 +000072
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +000073SBFrame::~SBFrame() = default;
74
Kate Stoneb9c1b512016-09-06 20:57:50 +000075const SBFrame &SBFrame::operator=(const SBFrame &rhs) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +000076 LLDB_RECORD_METHOD(const lldb::SBFrame &,
77 SBFrame, operator=,(const lldb::SBFrame &), rhs);
78
Kate Stoneb9c1b512016-09-06 20:57:50 +000079 if (this != &rhs)
Jonas Devliegherebd4bf822019-03-06 00:05:55 +000080 m_opaque_sp = clone(rhs.m_opaque_sp);
Jonas Devlieghere306809f2019-04-03 21:31:22 +000081 return LLDB_RECORD_RESULT(*this);
Greg Claytonefabb122010-11-05 23:17:00 +000082}
83
Kate Stoneb9c1b512016-09-06 20:57:50 +000084StackFrameSP SBFrame::GetFrameSP() const {
85 return (m_opaque_sp ? m_opaque_sp->GetFrameSP() : StackFrameSP());
Chris Lattner30fdc8d2010-06-08 16:52:24 +000086}
87
Kate Stoneb9c1b512016-09-06 20:57:50 +000088void SBFrame::SetFrameSP(const StackFrameSP &lldb_object_sp) {
89 return m_opaque_sp->SetFrameSP(lldb_object_sp);
Greg Claytonb9556ac2012-01-30 07:41:31 +000090}
Chris Lattner30fdc8d2010-06-08 16:52:24 +000091
Kate Stoneb9c1b512016-09-06 20:57:50 +000092bool SBFrame::IsValid() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +000093 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBFrame, IsValid);
Pavel Labath7f5237b2019-03-11 13:58:46 +000094 return this->operator bool();
95}
96SBFrame::operator bool() const {
97 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBFrame, operator bool);
Jonas Devliegherebaf56642019-03-06 00:06:00 +000098
Kate Stoneb9c1b512016-09-06 20:57:50 +000099 std::unique_lock<std::recursive_mutex> lock;
100 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Jim Ingham7fa7dc32016-05-07 00:54:56 +0000101
Kate Stoneb9c1b512016-09-06 20:57:50 +0000102 Target *target = exe_ctx.GetTargetPtr();
103 Process *process = exe_ctx.GetProcessPtr();
104 if (target && process) {
105 Process::StopLocker stop_locker;
106 if (stop_locker.TryLock(&process->GetRunLock()))
107 return GetFrameSP().get() != nullptr;
108 }
109
110 // Without a target & process we can't have a valid stack frame.
111 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000112}
113
Kate Stoneb9c1b512016-09-06 20:57:50 +0000114SBSymbolContext SBFrame::GetSymbolContext(uint32_t resolve_scope) const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000115 LLDB_RECORD_METHOD_CONST(lldb::SBSymbolContext, SBFrame, GetSymbolContext,
116 (uint32_t), resolve_scope);
117
Kate Stoneb9c1b512016-09-06 20:57:50 +0000118 SBSymbolContext sb_sym_ctx;
119 std::unique_lock<std::recursive_mutex> lock;
120 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Zachary Turner991e4452018-10-25 20:45:19 +0000121 SymbolContextItem scope = static_cast<SymbolContextItem>(resolve_scope);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000122 StackFrame *frame = nullptr;
123 Target *target = exe_ctx.GetTargetPtr();
124 Process *process = exe_ctx.GetProcessPtr();
125 if (target && process) {
126 Process::StopLocker stop_locker;
127 if (stop_locker.TryLock(&process->GetRunLock())) {
128 frame = exe_ctx.GetFramePtr();
Jonas Devlieghere581af8b2019-03-07 22:47:13 +0000129 if (frame)
Zachary Turner991e4452018-10-25 20:45:19 +0000130 sb_sym_ctx.SetSymbolContext(&frame->GetSymbolContext(scope));
Jim Ingham7730b9a2012-11-29 00:26:19 +0000131 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000132 }
Saleem Abdulrasoolbb19a132016-05-19 05:13:57 +0000133
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000134 return LLDB_RECORD_RESULT(sb_sym_ctx);
Greg Clayton7edbdfc2012-02-03 07:02:37 +0000135}
136
Kate Stoneb9c1b512016-09-06 20:57:50 +0000137SBModule SBFrame::GetModule() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000138 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBModule, SBFrame, GetModule);
139
Kate Stoneb9c1b512016-09-06 20:57:50 +0000140 SBModule sb_module;
141 ModuleSP module_sp;
142 std::unique_lock<std::recursive_mutex> lock;
143 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Jim Inghamc481c7e2016-06-10 00:37:44 +0000144
Kate Stoneb9c1b512016-09-06 20:57:50 +0000145 StackFrame *frame = nullptr;
146 Target *target = exe_ctx.GetTargetPtr();
147 Process *process = exe_ctx.GetProcessPtr();
148 if (target && process) {
149 Process::StopLocker stop_locker;
150 if (stop_locker.TryLock(&process->GetRunLock())) {
151 frame = exe_ctx.GetFramePtr();
152 if (frame) {
153 module_sp = frame->GetSymbolContext(eSymbolContextModule).module_sp;
154 sb_module.SetSP(module_sp);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000155 }
Jim Ingham7730b9a2012-11-29 00:26:19 +0000156 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000157 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000158
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000159 return LLDB_RECORD_RESULT(sb_module);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000160}
161
Kate Stoneb9c1b512016-09-06 20:57:50 +0000162SBCompileUnit SBFrame::GetCompileUnit() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000163 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBCompileUnit, SBFrame,
164 GetCompileUnit);
165
Kate Stoneb9c1b512016-09-06 20:57:50 +0000166 SBCompileUnit sb_comp_unit;
167 std::unique_lock<std::recursive_mutex> lock;
168 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Jim Inghamc481c7e2016-06-10 00:37:44 +0000169
Kate Stoneb9c1b512016-09-06 20:57:50 +0000170 StackFrame *frame = nullptr;
171 Target *target = exe_ctx.GetTargetPtr();
172 Process *process = exe_ctx.GetProcessPtr();
173 if (target && process) {
174 Process::StopLocker stop_locker;
175 if (stop_locker.TryLock(&process->GetRunLock())) {
176 frame = exe_ctx.GetFramePtr();
177 if (frame) {
178 sb_comp_unit.reset(
179 frame->GetSymbolContext(eSymbolContextCompUnit).comp_unit);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000180 }
Jim Ingham7730b9a2012-11-29 00:26:19 +0000181 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000182 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000183
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000184 return LLDB_RECORD_RESULT(sb_comp_unit);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000185}
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000186
Kate Stoneb9c1b512016-09-06 20:57:50 +0000187SBFunction SBFrame::GetFunction() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000188 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBFunction, SBFrame, GetFunction);
189
Kate Stoneb9c1b512016-09-06 20:57:50 +0000190 SBFunction sb_function;
191 std::unique_lock<std::recursive_mutex> lock;
192 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000193
Kate Stoneb9c1b512016-09-06 20:57:50 +0000194 StackFrame *frame = nullptr;
195 Target *target = exe_ctx.GetTargetPtr();
196 Process *process = exe_ctx.GetProcessPtr();
197 if (target && process) {
198 Process::StopLocker stop_locker;
199 if (stop_locker.TryLock(&process->GetRunLock())) {
200 frame = exe_ctx.GetFramePtr();
201 if (frame) {
202 sb_function.reset(
203 frame->GetSymbolContext(eSymbolContextFunction).function);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000204 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000205 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000206 }
Greg Clayton48381312010-10-30 04:51:46 +0000207
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000208 return LLDB_RECORD_RESULT(sb_function);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000209}
210
211SBSymbol SBFrame::GetSymbol() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000212 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBSymbol, SBFrame, GetSymbol);
213
Kate Stoneb9c1b512016-09-06 20:57:50 +0000214 SBSymbol sb_symbol;
215 std::unique_lock<std::recursive_mutex> lock;
216 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
217
218 StackFrame *frame = nullptr;
219 Target *target = exe_ctx.GetTargetPtr();
220 Process *process = exe_ctx.GetProcessPtr();
221 if (target && process) {
222 Process::StopLocker stop_locker;
223 if (stop_locker.TryLock(&process->GetRunLock())) {
224 frame = exe_ctx.GetFramePtr();
225 if (frame) {
226 sb_symbol.reset(frame->GetSymbolContext(eSymbolContextSymbol).symbol);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000227 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000228 }
229 }
Jonas Devlieghere581af8b2019-03-07 22:47:13 +0000230
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000231 return LLDB_RECORD_RESULT(sb_symbol);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000232}
233
234SBBlock SBFrame::GetBlock() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000235 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBBlock, SBFrame, GetBlock);
236
Kate Stoneb9c1b512016-09-06 20:57:50 +0000237 SBBlock sb_block;
238 std::unique_lock<std::recursive_mutex> lock;
239 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
240
241 StackFrame *frame = nullptr;
242 Target *target = exe_ctx.GetTargetPtr();
243 Process *process = exe_ctx.GetProcessPtr();
244 if (target && process) {
245 Process::StopLocker stop_locker;
246 if (stop_locker.TryLock(&process->GetRunLock())) {
247 frame = exe_ctx.GetFramePtr();
Jonas Devlieghere581af8b2019-03-07 22:47:13 +0000248 if (frame)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000249 sb_block.SetPtr(frame->GetSymbolContext(eSymbolContextBlock).block);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000250 }
251 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000252 return LLDB_RECORD_RESULT(sb_block);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000253}
254
255SBBlock SBFrame::GetFrameBlock() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000256 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBBlock, SBFrame, GetFrameBlock);
257
Kate Stoneb9c1b512016-09-06 20:57:50 +0000258 SBBlock sb_block;
259 std::unique_lock<std::recursive_mutex> lock;
260 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
261
262 StackFrame *frame = nullptr;
263 Target *target = exe_ctx.GetTargetPtr();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000264 Process *process = exe_ctx.GetProcessPtr();
265 if (target && process) {
266 Process::StopLocker stop_locker;
267 if (stop_locker.TryLock(&process->GetRunLock())) {
268 frame = exe_ctx.GetFramePtr();
Jonas Devlieghere581af8b2019-03-07 22:47:13 +0000269 if (frame)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000270 sb_block.SetPtr(frame->GetFrameBlock());
Kate Stoneb9c1b512016-09-06 20:57:50 +0000271 }
272 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000273 return LLDB_RECORD_RESULT(sb_block);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000274}
275
276SBLineEntry SBFrame::GetLineEntry() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000277 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBLineEntry, SBFrame, GetLineEntry);
278
Kate Stoneb9c1b512016-09-06 20:57:50 +0000279 SBLineEntry sb_line_entry;
280 std::unique_lock<std::recursive_mutex> lock;
281 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
282
283 StackFrame *frame = nullptr;
284 Target *target = exe_ctx.GetTargetPtr();
285 Process *process = exe_ctx.GetProcessPtr();
286 if (target && process) {
287 Process::StopLocker stop_locker;
288 if (stop_locker.TryLock(&process->GetRunLock())) {
289 frame = exe_ctx.GetFramePtr();
290 if (frame) {
291 sb_line_entry.SetLineEntry(
292 frame->GetSymbolContext(eSymbolContextLineEntry).line_entry);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000293 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000294 }
295 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000296 return LLDB_RECORD_RESULT(sb_line_entry);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000297}
298
299uint32_t SBFrame::GetFrameID() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000300 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBFrame, GetFrameID);
301
Kate Stoneb9c1b512016-09-06 20:57:50 +0000302 uint32_t frame_idx = UINT32_MAX;
303
304 std::unique_lock<std::recursive_mutex> lock;
305 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
306
307 StackFrame *frame = exe_ctx.GetFramePtr();
308 if (frame)
309 frame_idx = frame->GetFrameIndex();
310
Kate Stoneb9c1b512016-09-06 20:57:50 +0000311 return frame_idx;
312}
313
314lldb::addr_t SBFrame::GetCFA() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000315 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::addr_t, SBFrame, GetCFA);
316
Kate Stoneb9c1b512016-09-06 20:57:50 +0000317 std::unique_lock<std::recursive_mutex> lock;
318 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
319
320 StackFrame *frame = exe_ctx.GetFramePtr();
321 if (frame)
322 return frame->GetStackID().GetCallFrameAddress();
323 return LLDB_INVALID_ADDRESS;
324}
325
326addr_t SBFrame::GetPC() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000327 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::addr_t, SBFrame, GetPC);
328
Kate Stoneb9c1b512016-09-06 20:57:50 +0000329 addr_t addr = LLDB_INVALID_ADDRESS;
330 std::unique_lock<std::recursive_mutex> lock;
331 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
332
333 StackFrame *frame = nullptr;
334 Target *target = exe_ctx.GetTargetPtr();
335 Process *process = exe_ctx.GetProcessPtr();
336 if (target && process) {
337 Process::StopLocker stop_locker;
338 if (stop_locker.TryLock(&process->GetRunLock())) {
339 frame = exe_ctx.GetFramePtr();
340 if (frame) {
341 addr = frame->GetFrameCodeAddress().GetOpcodeLoadAddress(
Tatyana Krasnukha04803b32018-06-26 13:06:54 +0000342 target, AddressClass::eCode);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000343 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000344 }
345 }
346
Kate Stoneb9c1b512016-09-06 20:57:50 +0000347 return addr;
348}
349
350bool SBFrame::SetPC(addr_t new_pc) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000351 LLDB_RECORD_METHOD(bool, SBFrame, SetPC, (lldb::addr_t), new_pc);
352
Kate Stoneb9c1b512016-09-06 20:57:50 +0000353 bool ret_val = false;
354 std::unique_lock<std::recursive_mutex> lock;
355 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
356
357 StackFrame *frame = nullptr;
358 Target *target = exe_ctx.GetTargetPtr();
359 Process *process = exe_ctx.GetProcessPtr();
360 if (target && process) {
361 Process::StopLocker stop_locker;
362 if (stop_locker.TryLock(&process->GetRunLock())) {
363 frame = exe_ctx.GetFramePtr();
364 if (frame) {
365 ret_val = frame->GetRegisterContext()->SetPC(new_pc);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000366 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000367 }
368 }
369
Kate Stoneb9c1b512016-09-06 20:57:50 +0000370 return ret_val;
371}
372
373addr_t SBFrame::GetSP() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000374 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::addr_t, SBFrame, GetSP);
375
Kate Stoneb9c1b512016-09-06 20:57:50 +0000376 addr_t addr = LLDB_INVALID_ADDRESS;
377 std::unique_lock<std::recursive_mutex> lock;
378 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
379
380 StackFrame *frame = nullptr;
381 Target *target = exe_ctx.GetTargetPtr();
382 Process *process = exe_ctx.GetProcessPtr();
383 if (target && process) {
384 Process::StopLocker stop_locker;
385 if (stop_locker.TryLock(&process->GetRunLock())) {
386 frame = exe_ctx.GetFramePtr();
387 if (frame) {
388 addr = frame->GetRegisterContext()->GetSP();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000389 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000390 }
391 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000392
393 return addr;
394}
395
396addr_t SBFrame::GetFP() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000397 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::addr_t, SBFrame, GetFP);
398
Kate Stoneb9c1b512016-09-06 20:57:50 +0000399 addr_t addr = LLDB_INVALID_ADDRESS;
400 std::unique_lock<std::recursive_mutex> lock;
401 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
402
403 StackFrame *frame = nullptr;
404 Target *target = exe_ctx.GetTargetPtr();
405 Process *process = exe_ctx.GetProcessPtr();
406 if (target && process) {
407 Process::StopLocker stop_locker;
408 if (stop_locker.TryLock(&process->GetRunLock())) {
409 frame = exe_ctx.GetFramePtr();
Jonas Devlieghere581af8b2019-03-07 22:47:13 +0000410 if (frame)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000411 addr = frame->GetRegisterContext()->GetFP();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000412 }
413 }
414
Kate Stoneb9c1b512016-09-06 20:57:50 +0000415 return addr;
416}
417
418SBAddress SBFrame::GetPCAddress() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000419 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBAddress, SBFrame, GetPCAddress);
420
Kate Stoneb9c1b512016-09-06 20:57:50 +0000421 SBAddress sb_addr;
422 std::unique_lock<std::recursive_mutex> lock;
423 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
424
425 StackFrame *frame = exe_ctx.GetFramePtr();
426 Target *target = exe_ctx.GetTargetPtr();
427 Process *process = exe_ctx.GetProcessPtr();
428 if (target && process) {
429 Process::StopLocker stop_locker;
430 if (stop_locker.TryLock(&process->GetRunLock())) {
431 frame = exe_ctx.GetFramePtr();
Jonas Devlieghere581af8b2019-03-07 22:47:13 +0000432 if (frame)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000433 sb_addr.SetAddress(&frame->GetFrameCodeAddress());
Kate Stoneb9c1b512016-09-06 20:57:50 +0000434 }
435 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000436 return LLDB_RECORD_RESULT(sb_addr);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000437}
438
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000439void SBFrame::Clear() {
440 LLDB_RECORD_METHOD_NO_ARGS(void, SBFrame, Clear);
441
442 m_opaque_sp->Clear();
443}
Kate Stoneb9c1b512016-09-06 20:57:50 +0000444
445lldb::SBValue SBFrame::GetValueForVariablePath(const char *var_path) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000446 LLDB_RECORD_METHOD(lldb::SBValue, SBFrame, GetValueForVariablePath,
447 (const char *), var_path);
448
Kate Stoneb9c1b512016-09-06 20:57:50 +0000449 SBValue sb_value;
450 std::unique_lock<std::recursive_mutex> lock;
451 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
452
453 StackFrame *frame = exe_ctx.GetFramePtr();
454 Target *target = exe_ctx.GetTargetPtr();
455 if (frame && target) {
456 lldb::DynamicValueType use_dynamic =
457 frame->CalculateTarget()->GetPreferDynamicValue();
458 sb_value = GetValueForVariablePath(var_path, use_dynamic);
459 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000460 return LLDB_RECORD_RESULT(sb_value);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000461}
462
463lldb::SBValue SBFrame::GetValueForVariablePath(const char *var_path,
464 DynamicValueType use_dynamic) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000465 LLDB_RECORD_METHOD(lldb::SBValue, SBFrame, GetValueForVariablePath,
466 (const char *, lldb::DynamicValueType), var_path,
467 use_dynamic);
468
Kate Stoneb9c1b512016-09-06 20:57:50 +0000469 SBValue sb_value;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000470 if (var_path == nullptr || var_path[0] == '\0') {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000471 return LLDB_RECORD_RESULT(sb_value);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000472 }
473
474 std::unique_lock<std::recursive_mutex> lock;
475 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
476
477 StackFrame *frame = nullptr;
478 Target *target = exe_ctx.GetTargetPtr();
479 Process *process = exe_ctx.GetProcessPtr();
480 if (target && process) {
481 Process::StopLocker stop_locker;
482 if (stop_locker.TryLock(&process->GetRunLock())) {
483 frame = exe_ctx.GetFramePtr();
484 if (frame) {
485 VariableSP var_sp;
Zachary Turner97206d52017-05-12 04:51:55 +0000486 Status error;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000487 ValueObjectSP value_sp(frame->GetValueForVariableExpressionPath(
488 var_path, eNoDynamicValues,
489 StackFrame::eExpressionPathOptionCheckPtrVsMember |
490 StackFrame::eExpressionPathOptionsAllowDirectIVarAccess,
491 var_sp, error));
492 sb_value.SetSP(value_sp, use_dynamic);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000493 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000494 }
495 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000496 return LLDB_RECORD_RESULT(sb_value);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000497}
498
Kate Stoneb9c1b512016-09-06 20:57:50 +0000499SBValue SBFrame::FindVariable(const char *name) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000500 LLDB_RECORD_METHOD(lldb::SBValue, SBFrame, FindVariable, (const char *),
501 name);
502
Kate Stoneb9c1b512016-09-06 20:57:50 +0000503 SBValue value;
504 std::unique_lock<std::recursive_mutex> lock;
505 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
506
507 StackFrame *frame = exe_ctx.GetFramePtr();
508 Target *target = exe_ctx.GetTargetPtr();
509 if (frame && target) {
510 lldb::DynamicValueType use_dynamic =
511 frame->CalculateTarget()->GetPreferDynamicValue();
512 value = FindVariable(name, use_dynamic);
513 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000514 return LLDB_RECORD_RESULT(value);
Johnny Chen35e2ab62012-03-05 19:53:24 +0000515}
516
Kate Stoneb9c1b512016-09-06 20:57:50 +0000517SBValue SBFrame::FindVariable(const char *name,
518 lldb::DynamicValueType use_dynamic) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000519 LLDB_RECORD_METHOD(lldb::SBValue, SBFrame, FindVariable,
520 (const char *, lldb::DynamicValueType), name, use_dynamic);
521
Kate Stoneb9c1b512016-09-06 20:57:50 +0000522 VariableSP var_sp;
523 SBValue sb_value;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000524
Kate Stoneb9c1b512016-09-06 20:57:50 +0000525 if (name == nullptr || name[0] == '\0') {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000526 return LLDB_RECORD_RESULT(sb_value);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000527 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000528
Kate Stoneb9c1b512016-09-06 20:57:50 +0000529 ValueObjectSP value_sp;
530 std::unique_lock<std::recursive_mutex> lock;
531 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
532
533 StackFrame *frame = nullptr;
534 Target *target = exe_ctx.GetTargetPtr();
535 Process *process = exe_ctx.GetProcessPtr();
536 if (target && process) {
537 Process::StopLocker stop_locker;
538 if (stop_locker.TryLock(&process->GetRunLock())) {
539 frame = exe_ctx.GetFramePtr();
540 if (frame) {
Shafik Yaghmoure23d0b62018-09-20 17:06:34 +0000541 value_sp = frame->FindVariable(ConstString(name));
Kate Stoneb9c1b512016-09-06 20:57:50 +0000542
Shafik Yaghmoure23d0b62018-09-20 17:06:34 +0000543 if (value_sp)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000544 sb_value.SetSP(value_sp, use_dynamic);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000545 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000546 }
547 }
548
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000549 return LLDB_RECORD_RESULT(sb_value);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000550}
551
Kate Stoneb9c1b512016-09-06 20:57:50 +0000552SBValue SBFrame::FindValue(const char *name, ValueType value_type) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000553 LLDB_RECORD_METHOD(lldb::SBValue, SBFrame, FindValue,
554 (const char *, lldb::ValueType), name, value_type);
555
Kate Stoneb9c1b512016-09-06 20:57:50 +0000556 SBValue value;
557 std::unique_lock<std::recursive_mutex> lock;
558 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000559
Kate Stoneb9c1b512016-09-06 20:57:50 +0000560 StackFrame *frame = exe_ctx.GetFramePtr();
561 Target *target = exe_ctx.GetTargetPtr();
562 if (frame && target) {
563 lldb::DynamicValueType use_dynamic =
564 frame->CalculateTarget()->GetPreferDynamicValue();
565 value = FindValue(name, value_type, use_dynamic);
566 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000567 return LLDB_RECORD_RESULT(value);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000568}
Greg Clayton48381312010-10-30 04:51:46 +0000569
Kate Stoneb9c1b512016-09-06 20:57:50 +0000570SBValue SBFrame::FindValue(const char *name, ValueType value_type,
571 lldb::DynamicValueType use_dynamic) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000572 LLDB_RECORD_METHOD(lldb::SBValue, SBFrame, FindValue,
573 (const char *, lldb::ValueType, lldb::DynamicValueType),
574 name, value_type, use_dynamic);
575
Kate Stoneb9c1b512016-09-06 20:57:50 +0000576 SBValue sb_value;
577
578 if (name == nullptr || name[0] == '\0') {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000579 return LLDB_RECORD_RESULT(sb_value);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000580 }
Greg Clayton48381312010-10-30 04:51:46 +0000581
Kate Stoneb9c1b512016-09-06 20:57:50 +0000582 ValueObjectSP value_sp;
583 std::unique_lock<std::recursive_mutex> lock;
584 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000585
Kate Stoneb9c1b512016-09-06 20:57:50 +0000586 StackFrame *frame = nullptr;
587 Target *target = exe_ctx.GetTargetPtr();
588 Process *process = exe_ctx.GetProcessPtr();
589 if (target && process) {
590 Process::StopLocker stop_locker;
591 if (stop_locker.TryLock(&process->GetRunLock())) {
592 frame = exe_ctx.GetFramePtr();
593 if (frame) {
594 VariableList variable_list;
Jim Inghamc481c7e2016-06-10 00:37:44 +0000595
Kate Stoneb9c1b512016-09-06 20:57:50 +0000596 switch (value_type) {
597 case eValueTypeVariableGlobal: // global variable
598 case eValueTypeVariableStatic: // static variable
599 case eValueTypeVariableArgument: // function argument variables
600 case eValueTypeVariableLocal: // function local variables
601 case eValueTypeVariableThreadLocal: // thread local variables
602 {
603 SymbolContext sc(frame->GetSymbolContext(eSymbolContextBlock));
604
605 const bool can_create = true;
606 const bool get_parent_variables = true;
607 const bool stop_if_block_is_inlined_function = true;
608
609 if (sc.block)
610 sc.block->AppendVariables(
611 can_create, get_parent_variables,
612 stop_if_block_is_inlined_function,
613 [frame](Variable *v) { return v->IsInScope(frame); },
614 &variable_list);
615 if (value_type == eValueTypeVariableGlobal) {
616 const bool get_file_globals = true;
617 VariableList *frame_vars = frame->GetVariableList(get_file_globals);
618 if (frame_vars)
619 frame_vars->AppendVariablesIfUnique(variable_list);
620 }
621 ConstString const_name(name);
622 VariableSP variable_sp(
623 variable_list.FindVariable(const_name, value_type));
624 if (variable_sp) {
625 value_sp = frame->GetValueObjectForFrameVariable(variable_sp,
626 eNoDynamicValues);
627 sb_value.SetSP(value_sp, use_dynamic);
628 }
629 } break;
630
631 case eValueTypeRegister: // stack frame register value
632 {
633 RegisterContextSP reg_ctx(frame->GetRegisterContext());
634 if (reg_ctx) {
635 const uint32_t num_regs = reg_ctx->GetRegisterCount();
636 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx) {
637 const RegisterInfo *reg_info =
638 reg_ctx->GetRegisterInfoAtIndex(reg_idx);
639 if (reg_info &&
640 ((reg_info->name && strcasecmp(reg_info->name, name) == 0) ||
641 (reg_info->alt_name &&
642 strcasecmp(reg_info->alt_name, name) == 0))) {
643 value_sp = ValueObjectRegister::Create(frame, reg_ctx, reg_idx);
644 sb_value.SetSP(value_sp);
645 break;
646 }
647 }
648 }
649 } break;
650
651 case eValueTypeRegisterSet: // A collection of stack frame register
652 // values
653 {
654 RegisterContextSP reg_ctx(frame->GetRegisterContext());
655 if (reg_ctx) {
656 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
657 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx) {
658 const RegisterSet *reg_set = reg_ctx->GetRegisterSet(set_idx);
659 if (reg_set &&
660 ((reg_set->name && strcasecmp(reg_set->name, name) == 0) ||
661 (reg_set->short_name &&
662 strcasecmp(reg_set->short_name, name) == 0))) {
663 value_sp =
664 ValueObjectRegisterSet::Create(frame, reg_ctx, set_idx);
665 sb_value.SetSP(value_sp);
666 break;
667 }
668 }
669 }
670 } break;
671
672 case eValueTypeConstResult: // constant result variables
673 {
674 ConstString const_name(name);
675 ExpressionVariableSP expr_var_sp(
676 target->GetPersistentVariable(const_name));
677 if (expr_var_sp) {
678 value_sp = expr_var_sp->GetValueObject();
679 sb_value.SetSP(value_sp, use_dynamic);
680 }
681 } break;
682
683 default:
684 break;
685 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000686 }
Greg Clayton316d4982011-06-18 20:06:08 +0000687 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000688 }
689
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000690 return LLDB_RECORD_RESULT(sb_value);
Jim Ingham78a685a2011-04-16 00:01:13 +0000691}
692
Kate Stoneb9c1b512016-09-06 20:57:50 +0000693bool SBFrame::IsEqual(const SBFrame &that) const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000694 LLDB_RECORD_METHOD_CONST(bool, SBFrame, IsEqual, (const lldb::SBFrame &),
695 that);
696
Kate Stoneb9c1b512016-09-06 20:57:50 +0000697 lldb::StackFrameSP this_sp = GetFrameSP();
698 lldb::StackFrameSP that_sp = that.GetFrameSP();
699 return (this_sp && that_sp && this_sp->GetStackID() == that_sp->GetStackID());
700}
Jim Inghamc481c7e2016-06-10 00:37:44 +0000701
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000702bool SBFrame::operator==(const SBFrame &rhs) const {
703 LLDB_RECORD_METHOD_CONST(bool, SBFrame, operator==,(const lldb::SBFrame &),
704 rhs);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000705
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000706 return IsEqual(rhs);
707}
708
709bool SBFrame::operator!=(const SBFrame &rhs) const {
710 LLDB_RECORD_METHOD_CONST(bool, SBFrame, operator!=,(const lldb::SBFrame &),
711 rhs);
712
713 return !IsEqual(rhs);
714}
Kate Stoneb9c1b512016-09-06 20:57:50 +0000715
716SBThread SBFrame::GetThread() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000717 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBThread, SBFrame, GetThread);
718
Kate Stoneb9c1b512016-09-06 20:57:50 +0000719 std::unique_lock<std::recursive_mutex> lock;
720 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
721
722 ThreadSP thread_sp(exe_ctx.GetThreadSP());
723 SBThread sb_thread(thread_sp);
724
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000725 return LLDB_RECORD_RESULT(sb_thread);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000726}
727
728const char *SBFrame::Disassemble() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000729 LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBFrame, Disassemble);
730
Kate Stoneb9c1b512016-09-06 20:57:50 +0000731 const char *disassembly = nullptr;
732 std::unique_lock<std::recursive_mutex> lock;
733 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
734
735 StackFrame *frame = nullptr;
736 Target *target = exe_ctx.GetTargetPtr();
737 Process *process = exe_ctx.GetProcessPtr();
738 if (target && process) {
739 Process::StopLocker stop_locker;
740 if (stop_locker.TryLock(&process->GetRunLock())) {
741 frame = exe_ctx.GetFramePtr();
742 if (frame) {
743 disassembly = frame->Disassemble();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000744 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000745 }
746 }
747
Kate Stoneb9c1b512016-09-06 20:57:50 +0000748 return disassembly;
749}
750
751SBValueList SBFrame::GetVariables(bool arguments, bool locals, bool statics,
752 bool in_scope_only) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000753 LLDB_RECORD_METHOD(lldb::SBValueList, SBFrame, GetVariables,
754 (bool, bool, bool, bool), arguments, locals, statics,
755 in_scope_only);
756
Kate Stoneb9c1b512016-09-06 20:57:50 +0000757 SBValueList value_list;
758 std::unique_lock<std::recursive_mutex> lock;
759 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
760
761 StackFrame *frame = exe_ctx.GetFramePtr();
762 Target *target = exe_ctx.GetTargetPtr();
763 if (frame && target) {
764 lldb::DynamicValueType use_dynamic =
765 frame->CalculateTarget()->GetPreferDynamicValue();
766 const bool include_runtime_support_values =
767 target ? target->GetDisplayRuntimeSupportValues() : false;
768
Zachary Turner51f96ee2015-02-17 17:55:50 +0000769 SBVariablesOptions options;
770 options.SetIncludeArguments(arguments);
771 options.SetIncludeLocals(locals);
772 options.SetIncludeStatics(statics);
773 options.SetInScopeOnly(in_scope_only);
774 options.SetIncludeRuntimeSupportValues(include_runtime_support_values);
775 options.SetUseDynamic(use_dynamic);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000776
777 value_list = GetVariables(options);
778 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000779 return LLDB_RECORD_RESULT(value_list);
Enrico Granata560558e2015-02-11 02:35:39 +0000780}
781
Kate Stoneb9c1b512016-09-06 20:57:50 +0000782lldb::SBValueList SBFrame::GetVariables(bool arguments, bool locals,
783 bool statics, bool in_scope_only,
784 lldb::DynamicValueType use_dynamic) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000785 LLDB_RECORD_METHOD(lldb::SBValueList, SBFrame, GetVariables,
786 (bool, bool, bool, bool, lldb::DynamicValueType),
787 arguments, locals, statics, in_scope_only, use_dynamic);
788
Kate Stoneb9c1b512016-09-06 20:57:50 +0000789 std::unique_lock<std::recursive_mutex> lock;
790 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000791
Kate Stoneb9c1b512016-09-06 20:57:50 +0000792 Target *target = exe_ctx.GetTargetPtr();
793 const bool include_runtime_support_values =
794 target ? target->GetDisplayRuntimeSupportValues() : false;
795 SBVariablesOptions options;
796 options.SetIncludeArguments(arguments);
797 options.SetIncludeLocals(locals);
798 options.SetIncludeStatics(statics);
799 options.SetInScopeOnly(in_scope_only);
800 options.SetIncludeRuntimeSupportValues(include_runtime_support_values);
801 options.SetUseDynamic(use_dynamic);
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000802 return LLDB_RECORD_RESULT(GetVariables(options));
Kate Stoneb9c1b512016-09-06 20:57:50 +0000803}
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000804
Kate Stoneb9c1b512016-09-06 20:57:50 +0000805SBValueList SBFrame::GetVariables(const lldb::SBVariablesOptions &options) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000806 LLDB_RECORD_METHOD(lldb::SBValueList, SBFrame, GetVariables,
807 (const lldb::SBVariablesOptions &), options);
808
Kate Stoneb9c1b512016-09-06 20:57:50 +0000809 SBValueList value_list;
810 std::unique_lock<std::recursive_mutex> lock;
811 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Greg Clayton349213f2016-04-29 21:00:38 +0000812
Kate Stoneb9c1b512016-09-06 20:57:50 +0000813 StackFrame *frame = nullptr;
814 Target *target = exe_ctx.GetTargetPtr();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000815
Kate Stoneb9c1b512016-09-06 20:57:50 +0000816 const bool statics = options.GetIncludeStatics();
817 const bool arguments = options.GetIncludeArguments();
Kuba Mracek4c7f5d52018-12-20 23:38:19 +0000818 const bool recognized_arguments =
819 options.GetIncludeRecognizedArguments(SBTarget(exe_ctx.GetTargetSP()));
Kate Stoneb9c1b512016-09-06 20:57:50 +0000820 const bool locals = options.GetIncludeLocals();
821 const bool in_scope_only = options.GetInScopeOnly();
822 const bool include_runtime_support_values =
823 options.GetIncludeRuntimeSupportValues();
824 const lldb::DynamicValueType use_dynamic = options.GetUseDynamic();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000825
Greg Claytonc982c762010-07-09 20:39:50 +0000826
Kate Stoneb9c1b512016-09-06 20:57:50 +0000827 std::set<VariableSP> variable_set;
828 Process *process = exe_ctx.GetProcessPtr();
829 if (target && process) {
830 Process::StopLocker stop_locker;
831 if (stop_locker.TryLock(&process->GetRunLock())) {
832 frame = exe_ctx.GetFramePtr();
833 if (frame) {
834 size_t i;
835 VariableList *variable_list = nullptr;
836 variable_list = frame->GetVariableList(true);
837 if (variable_list) {
838 const size_t num_variables = variable_list->GetSize();
839 if (num_variables) {
840 for (i = 0; i < num_variables; ++i) {
841 VariableSP variable_sp(variable_list->GetVariableAtIndex(i));
842 if (variable_sp) {
843 bool add_variable = false;
844 switch (variable_sp->GetScope()) {
845 case eValueTypeVariableGlobal:
846 case eValueTypeVariableStatic:
847 case eValueTypeVariableThreadLocal:
848 add_variable = statics;
849 break;
Greg Clayton349213f2016-04-29 21:00:38 +0000850
Kate Stoneb9c1b512016-09-06 20:57:50 +0000851 case eValueTypeVariableArgument:
852 add_variable = arguments;
853 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000854
Kate Stoneb9c1b512016-09-06 20:57:50 +0000855 case eValueTypeVariableLocal:
856 add_variable = locals;
857 break;
858
859 default:
860 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000861 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000862 if (add_variable) {
863 // Only add variables once so we don't end up with duplicates
864 if (variable_set.find(variable_sp) == variable_set.end())
865 variable_set.insert(variable_sp);
866 else
867 continue;
Caroline Ticeceb6b132010-10-26 03:11:13 +0000868
Kate Stoneb9c1b512016-09-06 20:57:50 +0000869 if (in_scope_only && !variable_sp->IsInScope(frame))
870 continue;
Caroline Ticeceb6b132010-10-26 03:11:13 +0000871
Kate Stoneb9c1b512016-09-06 20:57:50 +0000872 ValueObjectSP valobj_sp(frame->GetValueObjectForFrameVariable(
873 variable_sp, eNoDynamicValues));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000874
Kate Stoneb9c1b512016-09-06 20:57:50 +0000875 if (!include_runtime_support_values && valobj_sp != nullptr &&
876 valobj_sp->IsRuntimeSupportValue())
877 continue;
Caroline Ticeceb6b132010-10-26 03:11:13 +0000878
Kate Stoneb9c1b512016-09-06 20:57:50 +0000879 SBValue value_sb;
880 value_sb.SetSP(valobj_sp, use_dynamic);
881 value_list.Append(value_sb);
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000882 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000883 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000884 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000885 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000886 }
Kuba Mracek41ae8e72018-10-31 04:00:22 +0000887 if (recognized_arguments) {
888 auto recognized_frame = frame->GetRecognizedFrame();
889 if (recognized_frame) {
890 ValueObjectListSP recognized_arg_list =
891 recognized_frame->GetRecognizedArguments();
892 if (recognized_arg_list) {
893 for (auto &rec_value_sp : recognized_arg_list->GetObjects()) {
894 SBValue value_sb;
895 value_sb.SetSP(rec_value_sp, use_dynamic);
896 value_list.Append(value_sb);
897 }
898 }
899 }
900 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000901 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000902 }
903 }
904
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000905 return LLDB_RECORD_RESULT(value_list);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000906}
907
908SBValueList SBFrame::GetRegisters() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000909 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBValueList, SBFrame, GetRegisters);
910
Kate Stoneb9c1b512016-09-06 20:57:50 +0000911 SBValueList value_list;
912 std::unique_lock<std::recursive_mutex> lock;
913 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
914
915 StackFrame *frame = nullptr;
916 Target *target = exe_ctx.GetTargetPtr();
917 Process *process = exe_ctx.GetProcessPtr();
918 if (target && process) {
919 Process::StopLocker stop_locker;
920 if (stop_locker.TryLock(&process->GetRunLock())) {
921 frame = exe_ctx.GetFramePtr();
922 if (frame) {
923 RegisterContextSP reg_ctx(frame->GetRegisterContext());
924 if (reg_ctx) {
925 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
926 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx) {
927 value_list.Append(
928 ValueObjectRegisterSet::Create(frame, reg_ctx, set_idx));
929 }
930 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000931 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000932 }
933 }
934
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000935 return LLDB_RECORD_RESULT(value_list);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000936}
937
938SBValue SBFrame::FindRegister(const char *name) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000939 LLDB_RECORD_METHOD(lldb::SBValue, SBFrame, FindRegister, (const char *),
940 name);
941
Kate Stoneb9c1b512016-09-06 20:57:50 +0000942 SBValue result;
943 ValueObjectSP value_sp;
944 std::unique_lock<std::recursive_mutex> lock;
945 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
946
947 StackFrame *frame = nullptr;
948 Target *target = exe_ctx.GetTargetPtr();
949 Process *process = exe_ctx.GetProcessPtr();
950 if (target && process) {
951 Process::StopLocker stop_locker;
952 if (stop_locker.TryLock(&process->GetRunLock())) {
953 frame = exe_ctx.GetFramePtr();
954 if (frame) {
955 RegisterContextSP reg_ctx(frame->GetRegisterContext());
956 if (reg_ctx) {
957 const uint32_t num_regs = reg_ctx->GetRegisterCount();
958 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx) {
959 const RegisterInfo *reg_info =
960 reg_ctx->GetRegisterInfoAtIndex(reg_idx);
961 if (reg_info &&
962 ((reg_info->name && strcasecmp(reg_info->name, name) == 0) ||
963 (reg_info->alt_name &&
964 strcasecmp(reg_info->alt_name, name) == 0))) {
965 value_sp = ValueObjectRegister::Create(frame, reg_ctx, reg_idx);
966 result.SetSP(value_sp);
967 break;
968 }
969 }
970 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000971 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000972 }
973 }
974
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000975 return LLDB_RECORD_RESULT(result);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000976}
977
978bool SBFrame::GetDescription(SBStream &description) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000979 LLDB_RECORD_METHOD(bool, SBFrame, GetDescription, (lldb::SBStream &),
980 description);
981
Kate Stoneb9c1b512016-09-06 20:57:50 +0000982 Stream &strm = description.ref();
983
984 std::unique_lock<std::recursive_mutex> lock;
985 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
986
987 StackFrame *frame;
988 Target *target = exe_ctx.GetTargetPtr();
989 Process *process = exe_ctx.GetProcessPtr();
990 if (target && process) {
991 Process::StopLocker stop_locker;
992 if (stop_locker.TryLock(&process->GetRunLock())) {
993 frame = exe_ctx.GetFramePtr();
994 if (frame) {
995 frame->DumpUsingSettingsFormat(&strm);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000996 }
Jim Ingham7730b9a2012-11-29 00:26:19 +0000997 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000998
Kate Stoneb9c1b512016-09-06 20:57:50 +0000999 } else
1000 strm.PutCString("No value");
Greg Clayton48381312010-10-30 04:51:46 +00001001
Kate Stoneb9c1b512016-09-06 20:57:50 +00001002 return true;
1003}
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001004
Kate Stoneb9c1b512016-09-06 20:57:50 +00001005SBValue SBFrame::EvaluateExpression(const char *expr) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001006 LLDB_RECORD_METHOD(lldb::SBValue, SBFrame, EvaluateExpression, (const char *),
1007 expr);
1008
Kate Stoneb9c1b512016-09-06 20:57:50 +00001009 SBValue result;
1010 std::unique_lock<std::recursive_mutex> lock;
1011 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Greg Claytonb9556ac2012-01-30 07:41:31 +00001012
Kate Stoneb9c1b512016-09-06 20:57:50 +00001013 StackFrame *frame = exe_ctx.GetFramePtr();
1014 Target *target = exe_ctx.GetTargetPtr();
1015 if (frame && target) {
1016 SBExpressionOptions options;
1017 lldb::DynamicValueType fetch_dynamic_value =
1018 frame->CalculateTarget()->GetPreferDynamicValue();
1019 options.SetFetchDynamicValue(fetch_dynamic_value);
1020 options.SetUnwindOnError(true);
1021 options.SetIgnoreBreakpoints(true);
1022 if (target->GetLanguage() != eLanguageTypeUnknown)
1023 options.SetLanguage(target->GetLanguage());
1024 else
1025 options.SetLanguage(frame->GetLanguage());
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001026 return LLDB_RECORD_RESULT(EvaluateExpression(expr, options));
Kate Stoneb9c1b512016-09-06 20:57:50 +00001027 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001028 return LLDB_RECORD_RESULT(result);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001029}
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001030
Kate Stoneb9c1b512016-09-06 20:57:50 +00001031SBValue
1032SBFrame::EvaluateExpression(const char *expr,
1033 lldb::DynamicValueType fetch_dynamic_value) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001034 LLDB_RECORD_METHOD(lldb::SBValue, SBFrame, EvaluateExpression,
1035 (const char *, lldb::DynamicValueType), expr,
1036 fetch_dynamic_value);
1037
Kate Stoneb9c1b512016-09-06 20:57:50 +00001038 SBExpressionOptions options;
1039 options.SetFetchDynamicValue(fetch_dynamic_value);
1040 options.SetUnwindOnError(true);
1041 options.SetIgnoreBreakpoints(true);
1042 std::unique_lock<std::recursive_mutex> lock;
1043 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001044
Kate Stoneb9c1b512016-09-06 20:57:50 +00001045 StackFrame *frame = exe_ctx.GetFramePtr();
1046 Target *target = exe_ctx.GetTargetPtr();
1047 if (target && target->GetLanguage() != eLanguageTypeUnknown)
1048 options.SetLanguage(target->GetLanguage());
1049 else if (frame)
1050 options.SetLanguage(frame->GetLanguage());
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001051 return LLDB_RECORD_RESULT(EvaluateExpression(expr, options));
Kate Stoneb9c1b512016-09-06 20:57:50 +00001052}
Greg Claytonfb6621e2013-12-06 21:59:52 +00001053
Kate Stoneb9c1b512016-09-06 20:57:50 +00001054SBValue SBFrame::EvaluateExpression(const char *expr,
1055 lldb::DynamicValueType fetch_dynamic_value,
1056 bool unwind_on_error) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001057 LLDB_RECORD_METHOD(lldb::SBValue, SBFrame, EvaluateExpression,
1058 (const char *, lldb::DynamicValueType, bool), expr,
1059 fetch_dynamic_value, unwind_on_error);
1060
Kate Stoneb9c1b512016-09-06 20:57:50 +00001061 SBExpressionOptions options;
1062 std::unique_lock<std::recursive_mutex> lock;
1063 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1064
1065 options.SetFetchDynamicValue(fetch_dynamic_value);
1066 options.SetUnwindOnError(unwind_on_error);
1067 options.SetIgnoreBreakpoints(true);
1068 StackFrame *frame = exe_ctx.GetFramePtr();
1069 Target *target = exe_ctx.GetTargetPtr();
1070 if (target && target->GetLanguage() != eLanguageTypeUnknown)
1071 options.SetLanguage(target->GetLanguage());
1072 else if (frame)
1073 options.SetLanguage(frame->GetLanguage());
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001074 return LLDB_RECORD_RESULT(EvaluateExpression(expr, options));
Kate Stoneb9c1b512016-09-06 20:57:50 +00001075}
1076
1077lldb::SBValue SBFrame::EvaluateExpression(const char *expr,
1078 const SBExpressionOptions &options) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001079 LLDB_RECORD_METHOD(lldb::SBValue, SBFrame, EvaluateExpression,
1080 (const char *, const lldb::SBExpressionOptions &), expr,
1081 options);
1082
Kate Stoneb9c1b512016-09-06 20:57:50 +00001083 Log *expr_log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
Greg Clayton48381312010-10-30 04:51:46 +00001084
Kate Stoneb9c1b512016-09-06 20:57:50 +00001085 SBValue expr_result;
1086
1087 if (expr == nullptr || expr[0] == '\0') {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001088 return LLDB_RECORD_RESULT(expr_result);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001089 }
Greg Clayton316d4982011-06-18 20:06:08 +00001090
Kate Stoneb9c1b512016-09-06 20:57:50 +00001091 ValueObjectSP expr_value_sp;
Oleksiy Vyalov05f75e92015-06-25 17:41:41 +00001092
Kate Stoneb9c1b512016-09-06 20:57:50 +00001093 std::unique_lock<std::recursive_mutex> lock;
1094 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Jim Inghamc481c7e2016-06-10 00:37:44 +00001095
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001096
Kate Stoneb9c1b512016-09-06 20:57:50 +00001097 StackFrame *frame = nullptr;
1098 Target *target = exe_ctx.GetTargetPtr();
1099 Process *process = exe_ctx.GetProcessPtr();
1100
1101 if (target && process) {
1102 Process::StopLocker stop_locker;
1103 if (stop_locker.TryLock(&process->GetRunLock())) {
1104 frame = exe_ctx.GetFramePtr();
1105 if (frame) {
Jim Ingham8f7db522016-12-15 00:30:30 +00001106 std::unique_ptr<llvm::PrettyStackTraceFormat> stack_trace;
Kate Stoneb9c1b512016-09-06 20:57:50 +00001107 if (target->GetDisplayExpressionsInCrashlogs()) {
1108 StreamString frame_description;
1109 frame->DumpUsingSettingsFormat(&frame_description);
Jonas Devliegherea8f3ae72019-08-14 22:19:23 +00001110 stack_trace = std::make_unique<llvm::PrettyStackTraceFormat>(
Kate Stoneb9c1b512016-09-06 20:57:50 +00001111 "SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value "
1112 "= %u) %s",
1113 expr, options.GetFetchDynamicValue(),
Zachary Turnerc1564272016-11-16 21:15:24 +00001114 frame_description.GetData());
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001115 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001116
Pavel Labath370e5db2019-03-18 16:04:46 +00001117 target->EvaluateExpression(expr, frame, expr_value_sp, options.ref());
Kate Stoneb9c1b512016-09-06 20:57:50 +00001118 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
Kate Stoneb9c1b512016-09-06 20:57:50 +00001119 }
Greg Clayton316d4982011-06-18 20:06:08 +00001120 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001121 }
1122
Jonas Devlieghere63e5fb72019-07-24 17:56:10 +00001123 LLDB_LOGF(expr_log,
1124 "** [SBFrame::EvaluateExpression] Expression result is "
1125 "%s, summary %s **",
1126 expr_result.GetValue(), expr_result.GetSummary());
Kate Stoneb9c1b512016-09-06 20:57:50 +00001127
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001128 return LLDB_RECORD_RESULT(expr_result);
Greg Clayton316d4982011-06-18 20:06:08 +00001129}
1130
Kate Stoneb9c1b512016-09-06 20:57:50 +00001131bool SBFrame::IsInlined() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001132 LLDB_RECORD_METHOD_NO_ARGS(bool, SBFrame, IsInlined);
1133
Kate Stoneb9c1b512016-09-06 20:57:50 +00001134 return static_cast<const SBFrame *>(this)->IsInlined();
Oleksiy Vyalov05f75e92015-06-25 17:41:41 +00001135}
1136
Kate Stoneb9c1b512016-09-06 20:57:50 +00001137bool SBFrame::IsInlined() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001138 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBFrame, IsInlined);
1139
Kate Stoneb9c1b512016-09-06 20:57:50 +00001140 std::unique_lock<std::recursive_mutex> lock;
1141 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Jim Inghamc481c7e2016-06-10 00:37:44 +00001142
Kate Stoneb9c1b512016-09-06 20:57:50 +00001143 StackFrame *frame = nullptr;
1144 Target *target = exe_ctx.GetTargetPtr();
1145 Process *process = exe_ctx.GetProcessPtr();
1146 if (target && process) {
1147 Process::StopLocker stop_locker;
1148 if (stop_locker.TryLock(&process->GetRunLock())) {
1149 frame = exe_ctx.GetFramePtr();
1150 if (frame) {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001151
Kate Stoneb9c1b512016-09-06 20:57:50 +00001152 Block *block = frame->GetSymbolContext(eSymbolContextBlock).block;
1153 if (block)
1154 return block->GetContainingInlinedBlock() != nullptr;
Kate Stoneb9c1b512016-09-06 20:57:50 +00001155 }
Greg Clayton316d4982011-06-18 20:06:08 +00001156 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001157 }
1158 return false;
Greg Clayton316d4982011-06-18 20:06:08 +00001159}
Enrico Granatac1f705c2015-07-06 18:28:46 +00001160
Vedant Kumar4b36f792018-10-05 23:23:15 +00001161bool SBFrame::IsArtificial() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001162 LLDB_RECORD_METHOD_NO_ARGS(bool, SBFrame, IsArtificial);
1163
Vedant Kumar4b36f792018-10-05 23:23:15 +00001164 return static_cast<const SBFrame *>(this)->IsArtificial();
1165}
1166
1167bool SBFrame::IsArtificial() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001168 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBFrame, IsArtificial);
1169
Vedant Kumar4b36f792018-10-05 23:23:15 +00001170 std::unique_lock<std::recursive_mutex> lock;
1171 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1172
1173 StackFrame *frame = exe_ctx.GetFramePtr();
1174 if (frame)
1175 return frame->IsArtificial();
1176
1177 return false;
1178}
1179
Kate Stoneb9c1b512016-09-06 20:57:50 +00001180const char *SBFrame::GetFunctionName() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001181 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBFrame, GetFunctionName);
1182
Kate Stoneb9c1b512016-09-06 20:57:50 +00001183 return static_cast<const SBFrame *>(this)->GetFunctionName();
1184}
Jim Inghamc481c7e2016-06-10 00:37:44 +00001185
Jim Inghambdbdd222017-04-12 00:19:54 +00001186lldb::LanguageType SBFrame::GuessLanguage() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001187 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::LanguageType, SBFrame, GuessLanguage);
1188
Jim Inghambdbdd222017-04-12 00:19:54 +00001189 std::unique_lock<std::recursive_mutex> lock;
1190 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001191
Jim Inghambdbdd222017-04-12 00:19:54 +00001192 StackFrame *frame = nullptr;
1193 Target *target = exe_ctx.GetTargetPtr();
1194 Process *process = exe_ctx.GetProcessPtr();
1195 if (target && process) {
1196 Process::StopLocker stop_locker;
1197 if (stop_locker.TryLock(&process->GetRunLock())) {
1198 frame = exe_ctx.GetFramePtr();
1199 if (frame) {
1200 return frame->GuessLanguage();
1201 }
1202 }
1203 }
1204 return eLanguageTypeUnknown;
1205}
1206
Kate Stoneb9c1b512016-09-06 20:57:50 +00001207const char *SBFrame::GetFunctionName() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001208 LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBFrame, GetFunctionName);
1209
Kate Stoneb9c1b512016-09-06 20:57:50 +00001210 const char *name = nullptr;
1211 std::unique_lock<std::recursive_mutex> lock;
1212 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Jim Inghamc481c7e2016-06-10 00:37:44 +00001213
Kate Stoneb9c1b512016-09-06 20:57:50 +00001214 StackFrame *frame = nullptr;
1215 Target *target = exe_ctx.GetTargetPtr();
1216 Process *process = exe_ctx.GetProcessPtr();
1217 if (target && process) {
1218 Process::StopLocker stop_locker;
1219 if (stop_locker.TryLock(&process->GetRunLock())) {
1220 frame = exe_ctx.GetFramePtr();
1221 if (frame) {
1222 SymbolContext sc(frame->GetSymbolContext(eSymbolContextFunction |
1223 eSymbolContextBlock |
1224 eSymbolContextSymbol));
1225 if (sc.block) {
1226 Block *inlined_block = sc.block->GetContainingInlinedBlock();
1227 if (inlined_block) {
1228 const InlineFunctionInfo *inlined_info =
1229 inlined_block->GetInlinedFunctionInfo();
1230 name =
1231 inlined_info->GetName(sc.function->GetLanguage()).AsCString();
1232 }
Enrico Granatac1f705c2015-07-06 18:28:46 +00001233 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001234
1235 if (name == nullptr) {
1236 if (sc.function)
1237 name = sc.function->GetName().GetCString();
Enrico Granatac1f705c2015-07-06 18:28:46 +00001238 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001239
1240 if (name == nullptr) {
1241 if (sc.symbol)
1242 name = sc.symbol->GetName().GetCString();
1243 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001244 }
Enrico Granatac1f705c2015-07-06 18:28:46 +00001245 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001246 }
1247 return name;
1248}
1249
1250const char *SBFrame::GetDisplayFunctionName() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001251 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBFrame, GetDisplayFunctionName);
1252
Kate Stoneb9c1b512016-09-06 20:57:50 +00001253 const char *name = nullptr;
1254
1255 std::unique_lock<std::recursive_mutex> lock;
1256 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1257
1258 StackFrame *frame = nullptr;
1259 Target *target = exe_ctx.GetTargetPtr();
1260 Process *process = exe_ctx.GetProcessPtr();
1261 if (target && process) {
1262 Process::StopLocker stop_locker;
1263 if (stop_locker.TryLock(&process->GetRunLock())) {
1264 frame = exe_ctx.GetFramePtr();
1265 if (frame) {
1266 SymbolContext sc(frame->GetSymbolContext(eSymbolContextFunction |
1267 eSymbolContextBlock |
1268 eSymbolContextSymbol));
1269 if (sc.block) {
1270 Block *inlined_block = sc.block->GetContainingInlinedBlock();
1271 if (inlined_block) {
1272 const InlineFunctionInfo *inlined_info =
1273 inlined_block->GetInlinedFunctionInfo();
1274 name = inlined_info->GetDisplayName(sc.function->GetLanguage())
1275 .AsCString();
1276 }
1277 }
1278
1279 if (name == nullptr) {
1280 if (sc.function)
1281 name = sc.function->GetDisplayName().GetCString();
1282 }
1283
1284 if (name == nullptr) {
1285 if (sc.symbol)
1286 name = sc.symbol->GetDisplayName().GetCString();
1287 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001288 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001289 }
1290 }
1291 return name;
Enrico Granatac1f705c2015-07-06 18:28:46 +00001292}
Michal Gornyae211ec2019-03-19 17:13:13 +00001293
1294namespace lldb_private {
1295namespace repro {
1296
1297template <>
1298void RegisterMethods<SBFrame>(Registry &R) {
1299 LLDB_REGISTER_CONSTRUCTOR(SBFrame, ());
1300 LLDB_REGISTER_CONSTRUCTOR(SBFrame, (const lldb::StackFrameSP &));
1301 LLDB_REGISTER_CONSTRUCTOR(SBFrame, (const lldb::SBFrame &));
1302 LLDB_REGISTER_METHOD(const lldb::SBFrame &,
1303 SBFrame, operator=,(const lldb::SBFrame &));
1304 LLDB_REGISTER_METHOD_CONST(bool, SBFrame, IsValid, ());
1305 LLDB_REGISTER_METHOD_CONST(bool, SBFrame, operator bool, ());
1306 LLDB_REGISTER_METHOD_CONST(lldb::SBSymbolContext, SBFrame, GetSymbolContext,
1307 (uint32_t));
1308 LLDB_REGISTER_METHOD_CONST(lldb::SBModule, SBFrame, GetModule, ());
1309 LLDB_REGISTER_METHOD_CONST(lldb::SBCompileUnit, SBFrame, GetCompileUnit,
1310 ());
1311 LLDB_REGISTER_METHOD_CONST(lldb::SBFunction, SBFrame, GetFunction, ());
1312 LLDB_REGISTER_METHOD_CONST(lldb::SBSymbol, SBFrame, GetSymbol, ());
1313 LLDB_REGISTER_METHOD_CONST(lldb::SBBlock, SBFrame, GetBlock, ());
1314 LLDB_REGISTER_METHOD_CONST(lldb::SBBlock, SBFrame, GetFrameBlock, ());
1315 LLDB_REGISTER_METHOD_CONST(lldb::SBLineEntry, SBFrame, GetLineEntry, ());
1316 LLDB_REGISTER_METHOD_CONST(uint32_t, SBFrame, GetFrameID, ());
1317 LLDB_REGISTER_METHOD_CONST(lldb::addr_t, SBFrame, GetCFA, ());
1318 LLDB_REGISTER_METHOD_CONST(lldb::addr_t, SBFrame, GetPC, ());
1319 LLDB_REGISTER_METHOD(bool, SBFrame, SetPC, (lldb::addr_t));
1320 LLDB_REGISTER_METHOD_CONST(lldb::addr_t, SBFrame, GetSP, ());
1321 LLDB_REGISTER_METHOD_CONST(lldb::addr_t, SBFrame, GetFP, ());
1322 LLDB_REGISTER_METHOD_CONST(lldb::SBAddress, SBFrame, GetPCAddress, ());
1323 LLDB_REGISTER_METHOD(void, SBFrame, Clear, ());
1324 LLDB_REGISTER_METHOD(lldb::SBValue, SBFrame, GetValueForVariablePath,
1325 (const char *));
1326 LLDB_REGISTER_METHOD(lldb::SBValue, SBFrame, GetValueForVariablePath,
1327 (const char *, lldb::DynamicValueType));
1328 LLDB_REGISTER_METHOD(lldb::SBValue, SBFrame, FindVariable, (const char *));
1329 LLDB_REGISTER_METHOD(lldb::SBValue, SBFrame, FindVariable,
1330 (const char *, lldb::DynamicValueType));
1331 LLDB_REGISTER_METHOD(lldb::SBValue, SBFrame, FindValue,
1332 (const char *, lldb::ValueType));
1333 LLDB_REGISTER_METHOD(
1334 lldb::SBValue, SBFrame, FindValue,
1335 (const char *, lldb::ValueType, lldb::DynamicValueType));
1336 LLDB_REGISTER_METHOD_CONST(bool, SBFrame, IsEqual, (const lldb::SBFrame &));
1337 LLDB_REGISTER_METHOD_CONST(bool,
1338 SBFrame, operator==,(const lldb::SBFrame &));
1339 LLDB_REGISTER_METHOD_CONST(bool,
1340 SBFrame, operator!=,(const lldb::SBFrame &));
1341 LLDB_REGISTER_METHOD_CONST(lldb::SBThread, SBFrame, GetThread, ());
1342 LLDB_REGISTER_METHOD_CONST(const char *, SBFrame, Disassemble, ());
1343 LLDB_REGISTER_METHOD(lldb::SBValueList, SBFrame, GetVariables,
1344 (bool, bool, bool, bool));
1345 LLDB_REGISTER_METHOD(lldb::SBValueList, SBFrame, GetVariables,
1346 (bool, bool, bool, bool, lldb::DynamicValueType));
1347 LLDB_REGISTER_METHOD(lldb::SBValueList, SBFrame, GetVariables,
1348 (const lldb::SBVariablesOptions &));
1349 LLDB_REGISTER_METHOD(lldb::SBValueList, SBFrame, GetRegisters, ());
1350 LLDB_REGISTER_METHOD(lldb::SBValue, SBFrame, FindRegister, (const char *));
1351 LLDB_REGISTER_METHOD(bool, SBFrame, GetDescription, (lldb::SBStream &));
1352 LLDB_REGISTER_METHOD(lldb::SBValue, SBFrame, EvaluateExpression,
1353 (const char *));
1354 LLDB_REGISTER_METHOD(lldb::SBValue, SBFrame, EvaluateExpression,
1355 (const char *, lldb::DynamicValueType));
1356 LLDB_REGISTER_METHOD(lldb::SBValue, SBFrame, EvaluateExpression,
1357 (const char *, lldb::DynamicValueType, bool));
1358 LLDB_REGISTER_METHOD(lldb::SBValue, SBFrame, EvaluateExpression,
1359 (const char *, const lldb::SBExpressionOptions &));
1360 LLDB_REGISTER_METHOD(bool, SBFrame, IsInlined, ());
1361 LLDB_REGISTER_METHOD_CONST(bool, SBFrame, IsInlined, ());
1362 LLDB_REGISTER_METHOD(bool, SBFrame, IsArtificial, ());
1363 LLDB_REGISTER_METHOD_CONST(bool, SBFrame, IsArtificial, ());
1364 LLDB_REGISTER_METHOD(const char *, SBFrame, GetFunctionName, ());
1365 LLDB_REGISTER_METHOD_CONST(lldb::LanguageType, SBFrame, GuessLanguage, ());
1366 LLDB_REGISTER_METHOD_CONST(const char *, SBFrame, GetFunctionName, ());
1367 LLDB_REGISTER_METHOD(const char *, SBFrame, GetDisplayFunctionName, ());
1368}
1369
1370}
1371}