blob: 1845b12cfcd5731c8c54bcc61f88273a1eb5f49d [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- SBFrame.cpp ---------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +000010// C Includes
11// C++ Includes
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012#include <algorithm>
Greg Clayton349213f2016-04-29 21:00:38 +000013#include <set>
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +000014#include <string>
15
16// Other libraries and framework includes
17// Project includes
18#include "lldb/API/SBFrame.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019
20#include "lldb/lldb-types.h"
21
Kate Stoneb9c1b512016-09-06 20:57:50 +000022#include "Plugins/ExpressionParser/Clang/ClangPersistentVariables.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023#include "lldb/Core/Address.h"
24#include "lldb/Core/ConstString.h"
Caroline Ticeceb6b132010-10-26 03:11:13 +000025#include "lldb/Core/Log.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026#include "lldb/Core/Stream.h"
27#include "lldb/Core/StreamFile.h"
28#include "lldb/Core/ValueObjectRegister.h"
29#include "lldb/Core/ValueObjectVariable.h"
Jim Ingham151c0322015-09-15 21:13:50 +000030#include "lldb/Expression/UserExpression.h"
Greg Clayton1ba7c4d2011-06-25 04:35:01 +000031#include "lldb/Host/Host.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032#include "lldb/Symbol/Block.h"
Greg Clayton1f746072012-08-29 21:13:06 +000033#include "lldb/Symbol/Function.h"
34#include "lldb/Symbol/Symbol.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035#include "lldb/Symbol/SymbolContext.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000036#include "lldb/Symbol/Variable.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000037#include "lldb/Symbol/VariableList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000038#include "lldb/Target/ExecutionContext.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039#include "lldb/Target/Process.h"
40#include "lldb/Target/RegisterContext.h"
Jason Molendab57e4a12013-11-04 09:33:30 +000041#include "lldb/Target/StackFrame.h"
Greg Claytonb9556ac2012-01-30 07:41:31 +000042#include "lldb/Target/StackID.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000043#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000044#include "lldb/Target/Thread.h"
45
Eli Friedman4c5de692010-06-09 07:44:37 +000046#include "lldb/API/SBAddress.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000047#include "lldb/API/SBDebugger.h"
Jim Ingham35e1bda2012-10-16 21:41:58 +000048#include "lldb/API/SBExpressionOptions.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000049#include "lldb/API/SBStream.h"
Eli Friedman4c5de692010-06-09 07:44:37 +000050#include "lldb/API/SBSymbolContext.h"
51#include "lldb/API/SBThread.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000052#include "lldb/API/SBValue.h"
Zachary Turner51f96ee2015-02-17 17:55:50 +000053#include "lldb/API/SBVariablesOptions.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000054
55using namespace lldb;
56using namespace lldb_private;
57
Kate Stoneb9c1b512016-09-06 20:57:50 +000058SBFrame::SBFrame() : m_opaque_sp(new ExecutionContextRef()) {}
59
60SBFrame::SBFrame(const StackFrameSP &lldb_object_sp)
61 : m_opaque_sp(new ExecutionContextRef(lldb_object_sp)) {
62 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
63
64 if (log) {
65 SBStream sstr;
66 GetDescription(sstr);
67 log->Printf("SBFrame::SBFrame (sp=%p) => SBFrame(%p): %s",
68 static_cast<void *>(lldb_object_sp.get()),
69 static_cast<void *>(lldb_object_sp.get()), sstr.GetData());
70 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000071}
72
Kate Stoneb9c1b512016-09-06 20:57:50 +000073SBFrame::SBFrame(const SBFrame &rhs)
74 : m_opaque_sp(new ExecutionContextRef(*rhs.m_opaque_sp)) {}
Greg Claytonefabb122010-11-05 23:17:00 +000075
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +000076SBFrame::~SBFrame() = default;
77
Kate Stoneb9c1b512016-09-06 20:57:50 +000078const SBFrame &SBFrame::operator=(const SBFrame &rhs) {
79 if (this != &rhs)
80 *m_opaque_sp = *rhs.m_opaque_sp;
81 return *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 {
93 std::unique_lock<std::recursive_mutex> lock;
94 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Jim Ingham7fa7dc32016-05-07 00:54:56 +000095
Kate Stoneb9c1b512016-09-06 20:57:50 +000096 Target *target = exe_ctx.GetTargetPtr();
97 Process *process = exe_ctx.GetProcessPtr();
98 if (target && process) {
99 Process::StopLocker stop_locker;
100 if (stop_locker.TryLock(&process->GetRunLock()))
101 return GetFrameSP().get() != nullptr;
102 }
103
104 // Without a target & process we can't have a valid stack frame.
105 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000106}
107
Kate Stoneb9c1b512016-09-06 20:57:50 +0000108SBSymbolContext SBFrame::GetSymbolContext(uint32_t resolve_scope) const {
109 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
110 SBSymbolContext sb_sym_ctx;
111 std::unique_lock<std::recursive_mutex> lock;
112 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000113
Kate Stoneb9c1b512016-09-06 20:57:50 +0000114 StackFrame *frame = nullptr;
115 Target *target = exe_ctx.GetTargetPtr();
116 Process *process = exe_ctx.GetProcessPtr();
117 if (target && process) {
118 Process::StopLocker stop_locker;
119 if (stop_locker.TryLock(&process->GetRunLock())) {
120 frame = exe_ctx.GetFramePtr();
121 if (frame) {
122 sb_sym_ctx.SetSymbolContext(&frame->GetSymbolContext(resolve_scope));
123 } else {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000124 if (log)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000125 log->Printf("SBFrame::GetVariables () => error: could not "
126 "reconstruct frame object for this SBFrame.");
127 }
128 } else {
129 if (log)
130 log->Printf(
131 "SBFrame::GetSymbolContext () => error: process is running");
Jim Ingham7730b9a2012-11-29 00:26:19 +0000132 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000133 }
Saleem Abdulrasoolbb19a132016-05-19 05:13:57 +0000134
Kate Stoneb9c1b512016-09-06 20:57:50 +0000135 if (log)
136 log->Printf("SBFrame(%p)::GetSymbolContext (resolve_scope=0x%8.8x) => "
137 "SBSymbolContext(%p)",
138 static_cast<void *>(frame), resolve_scope,
139 static_cast<void *>(sb_sym_ctx.get()));
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000140
Kate Stoneb9c1b512016-09-06 20:57:50 +0000141 return sb_sym_ctx;
Greg Clayton7edbdfc2012-02-03 07:02:37 +0000142}
143
Kate Stoneb9c1b512016-09-06 20:57:50 +0000144SBModule SBFrame::GetModule() const {
145 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
146 SBModule sb_module;
147 ModuleSP module_sp;
148 std::unique_lock<std::recursive_mutex> lock;
149 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Jim Inghamc481c7e2016-06-10 00:37:44 +0000150
Kate Stoneb9c1b512016-09-06 20:57:50 +0000151 StackFrame *frame = nullptr;
152 Target *target = exe_ctx.GetTargetPtr();
153 Process *process = exe_ctx.GetProcessPtr();
154 if (target && process) {
155 Process::StopLocker stop_locker;
156 if (stop_locker.TryLock(&process->GetRunLock())) {
157 frame = exe_ctx.GetFramePtr();
158 if (frame) {
159 module_sp = frame->GetSymbolContext(eSymbolContextModule).module_sp;
160 sb_module.SetSP(module_sp);
161 } else {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000162 if (log)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000163 log->Printf("SBFrame::GetModule () => error: could not reconstruct "
164 "frame object for this SBFrame.");
165 }
166 } else {
167 if (log)
168 log->Printf("SBFrame::GetModule () => error: process is running");
Jim Ingham7730b9a2012-11-29 00:26:19 +0000169 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000170 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000171
Kate Stoneb9c1b512016-09-06 20:57:50 +0000172 if (log)
173 log->Printf("SBFrame(%p)::GetModule () => SBModule(%p)",
174 static_cast<void *>(frame),
175 static_cast<void *>(module_sp.get()));
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000176
Kate Stoneb9c1b512016-09-06 20:57:50 +0000177 return sb_module;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000178}
179
Kate Stoneb9c1b512016-09-06 20:57:50 +0000180SBCompileUnit SBFrame::GetCompileUnit() const {
181 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
182 SBCompileUnit sb_comp_unit;
183 std::unique_lock<std::recursive_mutex> lock;
184 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Jim Inghamc481c7e2016-06-10 00:37:44 +0000185
Kate Stoneb9c1b512016-09-06 20:57:50 +0000186 StackFrame *frame = nullptr;
187 Target *target = exe_ctx.GetTargetPtr();
188 Process *process = exe_ctx.GetProcessPtr();
189 if (target && process) {
190 Process::StopLocker stop_locker;
191 if (stop_locker.TryLock(&process->GetRunLock())) {
192 frame = exe_ctx.GetFramePtr();
193 if (frame) {
194 sb_comp_unit.reset(
195 frame->GetSymbolContext(eSymbolContextCompUnit).comp_unit);
196 } else {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000197 if (log)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000198 log->Printf("SBFrame::GetCompileUnit () => error: could not "
199 "reconstruct frame object for this SBFrame.");
200 }
201 } else {
202 if (log)
203 log->Printf("SBFrame::GetCompileUnit () => error: process is running");
Jim Ingham7730b9a2012-11-29 00:26:19 +0000204 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000205 }
206 if (log)
207 log->Printf("SBFrame(%p)::GetCompileUnit () => SBCompileUnit(%p)",
208 static_cast<void *>(frame),
209 static_cast<void *>(sb_comp_unit.get()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000210
Kate Stoneb9c1b512016-09-06 20:57:50 +0000211 return sb_comp_unit;
212}
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000213
Kate Stoneb9c1b512016-09-06 20:57:50 +0000214SBFunction SBFrame::GetFunction() const {
215 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
216 SBFunction sb_function;
217 std::unique_lock<std::recursive_mutex> lock;
218 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000219
Kate Stoneb9c1b512016-09-06 20:57:50 +0000220 StackFrame *frame = nullptr;
221 Target *target = exe_ctx.GetTargetPtr();
222 Process *process = exe_ctx.GetProcessPtr();
223 if (target && process) {
224 Process::StopLocker stop_locker;
225 if (stop_locker.TryLock(&process->GetRunLock())) {
226 frame = exe_ctx.GetFramePtr();
227 if (frame) {
228 sb_function.reset(
229 frame->GetSymbolContext(eSymbolContextFunction).function);
230 } else {
231 if (log)
232 log->Printf("SBFrame::GetFunction () => error: could not reconstruct "
233 "frame object for this SBFrame.");
234 }
235 } else {
236 if (log)
237 log->Printf("SBFrame::GetFunction () => error: process is running");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000238 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000239 }
240 if (log)
241 log->Printf("SBFrame(%p)::GetFunction () => SBFunction(%p)",
242 static_cast<void *>(frame),
243 static_cast<void *>(sb_function.get()));
Greg Clayton48381312010-10-30 04:51:46 +0000244
Kate Stoneb9c1b512016-09-06 20:57:50 +0000245 return sb_function;
246}
247
248SBSymbol SBFrame::GetSymbol() const {
249 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
250 SBSymbol sb_symbol;
251 std::unique_lock<std::recursive_mutex> lock;
252 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
253
254 StackFrame *frame = nullptr;
255 Target *target = exe_ctx.GetTargetPtr();
256 Process *process = exe_ctx.GetProcessPtr();
257 if (target && process) {
258 Process::StopLocker stop_locker;
259 if (stop_locker.TryLock(&process->GetRunLock())) {
260 frame = exe_ctx.GetFramePtr();
261 if (frame) {
262 sb_symbol.reset(frame->GetSymbolContext(eSymbolContextSymbol).symbol);
263 } else {
264 if (log)
265 log->Printf("SBFrame::GetSymbol () => error: could not reconstruct "
266 "frame object for this SBFrame.");
267 }
268 } else {
269 if (log)
270 log->Printf("SBFrame::GetSymbol () => error: process is running");
271 }
272 }
273 if (log)
274 log->Printf("SBFrame(%p)::GetSymbol () => SBSymbol(%p)",
275 static_cast<void *>(frame),
276 static_cast<void *>(sb_symbol.get()));
277 return sb_symbol;
278}
279
280SBBlock SBFrame::GetBlock() const {
281 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
282 SBBlock sb_block;
283 std::unique_lock<std::recursive_mutex> lock;
284 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
285
286 StackFrame *frame = nullptr;
287 Target *target = exe_ctx.GetTargetPtr();
288 Process *process = exe_ctx.GetProcessPtr();
289 if (target && process) {
290 Process::StopLocker stop_locker;
291 if (stop_locker.TryLock(&process->GetRunLock())) {
292 frame = exe_ctx.GetFramePtr();
293 if (frame) {
294 sb_block.SetPtr(frame->GetSymbolContext(eSymbolContextBlock).block);
295 } else {
296 if (log)
297 log->Printf("SBFrame::GetBlock () => error: could not reconstruct "
298 "frame object for this SBFrame.");
299 }
300 } else {
301 if (log)
302 log->Printf("SBFrame(%p)::GetBlock () => error: process is running",
303 static_cast<void *>(frame));
304 }
305 }
306 if (log)
307 log->Printf("SBFrame(%p)::GetBlock () => SBBlock(%p)",
308 static_cast<void *>(frame),
309 static_cast<void *>(sb_block.GetPtr()));
310 return sb_block;
311}
312
313SBBlock SBFrame::GetFrameBlock() const {
314 SBBlock sb_block;
315 std::unique_lock<std::recursive_mutex> lock;
316 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
317
318 StackFrame *frame = nullptr;
319 Target *target = exe_ctx.GetTargetPtr();
320 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
321 Process *process = exe_ctx.GetProcessPtr();
322 if (target && process) {
323 Process::StopLocker stop_locker;
324 if (stop_locker.TryLock(&process->GetRunLock())) {
325 frame = exe_ctx.GetFramePtr();
326 if (frame) {
327 sb_block.SetPtr(frame->GetFrameBlock());
328 } else {
329 if (log)
330 log->Printf("SBFrame::GetFrameBlock () => error: could not "
331 "reconstruct frame object for this SBFrame.");
332 }
333 } else {
334 if (log)
335 log->Printf("SBFrame::GetFrameBlock () => error: process is running");
336 }
337 }
338 if (log)
339 log->Printf("SBFrame(%p)::GetFrameBlock () => SBBlock(%p)",
340 static_cast<void *>(frame),
341 static_cast<void *>(sb_block.GetPtr()));
342 return sb_block;
343}
344
345SBLineEntry SBFrame::GetLineEntry() const {
346 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
347 SBLineEntry sb_line_entry;
348 std::unique_lock<std::recursive_mutex> lock;
349 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
350
351 StackFrame *frame = nullptr;
352 Target *target = exe_ctx.GetTargetPtr();
353 Process *process = exe_ctx.GetProcessPtr();
354 if (target && process) {
355 Process::StopLocker stop_locker;
356 if (stop_locker.TryLock(&process->GetRunLock())) {
357 frame = exe_ctx.GetFramePtr();
358 if (frame) {
359 sb_line_entry.SetLineEntry(
360 frame->GetSymbolContext(eSymbolContextLineEntry).line_entry);
361 } else {
362 if (log)
363 log->Printf("SBFrame::GetLineEntry () => error: could not "
364 "reconstruct frame object for this SBFrame.");
365 }
366 } else {
367 if (log)
368 log->Printf("SBFrame::GetLineEntry () => error: process is running");
369 }
370 }
371 if (log)
372 log->Printf("SBFrame(%p)::GetLineEntry () => SBLineEntry(%p)",
373 static_cast<void *>(frame),
374 static_cast<void *>(sb_line_entry.get()));
375 return sb_line_entry;
376}
377
378uint32_t SBFrame::GetFrameID() const {
379 uint32_t frame_idx = UINT32_MAX;
380
381 std::unique_lock<std::recursive_mutex> lock;
382 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
383
384 StackFrame *frame = exe_ctx.GetFramePtr();
385 if (frame)
386 frame_idx = frame->GetFrameIndex();
387
388 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
389 if (log)
390 log->Printf("SBFrame(%p)::GetFrameID () => %u", static_cast<void *>(frame),
391 frame_idx);
392 return frame_idx;
393}
394
395lldb::addr_t SBFrame::GetCFA() const {
396 std::unique_lock<std::recursive_mutex> lock;
397 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
398
399 StackFrame *frame = exe_ctx.GetFramePtr();
400 if (frame)
401 return frame->GetStackID().GetCallFrameAddress();
402 return LLDB_INVALID_ADDRESS;
403}
404
405addr_t SBFrame::GetPC() const {
406 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
407 addr_t addr = LLDB_INVALID_ADDRESS;
408 std::unique_lock<std::recursive_mutex> lock;
409 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
410
411 StackFrame *frame = nullptr;
412 Target *target = exe_ctx.GetTargetPtr();
413 Process *process = exe_ctx.GetProcessPtr();
414 if (target && process) {
415 Process::StopLocker stop_locker;
416 if (stop_locker.TryLock(&process->GetRunLock())) {
417 frame = exe_ctx.GetFramePtr();
418 if (frame) {
419 addr = frame->GetFrameCodeAddress().GetOpcodeLoadAddress(
420 target, eAddressClassCode);
421 } else {
422 if (log)
423 log->Printf("SBFrame::GetPC () => error: could not reconstruct frame "
424 "object for this SBFrame.");
425 }
426 } else {
427 if (log)
428 log->Printf("SBFrame::GetPC () => error: process is running");
429 }
430 }
431
432 if (log)
433 log->Printf("SBFrame(%p)::GetPC () => 0x%" PRIx64,
434 static_cast<void *>(frame), addr);
435
436 return addr;
437}
438
439bool SBFrame::SetPC(addr_t new_pc) {
440 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
441 bool ret_val = false;
442 std::unique_lock<std::recursive_mutex> lock;
443 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
444
445 StackFrame *frame = nullptr;
446 Target *target = exe_ctx.GetTargetPtr();
447 Process *process = exe_ctx.GetProcessPtr();
448 if (target && process) {
449 Process::StopLocker stop_locker;
450 if (stop_locker.TryLock(&process->GetRunLock())) {
451 frame = exe_ctx.GetFramePtr();
452 if (frame) {
453 ret_val = frame->GetRegisterContext()->SetPC(new_pc);
454 } else {
455 if (log)
456 log->Printf("SBFrame::SetPC () => error: could not reconstruct frame "
457 "object for this SBFrame.");
458 }
459 } else {
460 if (log)
461 log->Printf("SBFrame::SetPC () => error: process is running");
462 }
463 }
464
465 if (log)
466 log->Printf("SBFrame(%p)::SetPC (new_pc=0x%" PRIx64 ") => %i",
467 static_cast<void *>(frame), new_pc, ret_val);
468
469 return ret_val;
470}
471
472addr_t SBFrame::GetSP() const {
473 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
474 addr_t addr = LLDB_INVALID_ADDRESS;
475 std::unique_lock<std::recursive_mutex> lock;
476 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
477
478 StackFrame *frame = nullptr;
479 Target *target = exe_ctx.GetTargetPtr();
480 Process *process = exe_ctx.GetProcessPtr();
481 if (target && process) {
482 Process::StopLocker stop_locker;
483 if (stop_locker.TryLock(&process->GetRunLock())) {
484 frame = exe_ctx.GetFramePtr();
485 if (frame) {
486 addr = frame->GetRegisterContext()->GetSP();
487 } else {
488 if (log)
489 log->Printf("SBFrame::GetSP () => error: could not reconstruct frame "
490 "object for this SBFrame.");
491 }
492 } else {
493 if (log)
494 log->Printf("SBFrame::GetSP () => error: process is running");
495 }
496 }
497 if (log)
498 log->Printf("SBFrame(%p)::GetSP () => 0x%" PRIx64,
499 static_cast<void *>(frame), addr);
500
501 return addr;
502}
503
504addr_t SBFrame::GetFP() const {
505 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
506 addr_t addr = LLDB_INVALID_ADDRESS;
507 std::unique_lock<std::recursive_mutex> lock;
508 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
509
510 StackFrame *frame = nullptr;
511 Target *target = exe_ctx.GetTargetPtr();
512 Process *process = exe_ctx.GetProcessPtr();
513 if (target && process) {
514 Process::StopLocker stop_locker;
515 if (stop_locker.TryLock(&process->GetRunLock())) {
516 frame = exe_ctx.GetFramePtr();
517 if (frame) {
518 addr = frame->GetRegisterContext()->GetFP();
519 } else {
520 if (log)
521 log->Printf("SBFrame::GetFP () => error: could not reconstruct frame "
522 "object for this SBFrame.");
523 }
524 } else {
525 if (log)
526 log->Printf("SBFrame::GetFP () => error: process is running");
527 }
528 }
529
530 if (log)
531 log->Printf("SBFrame(%p)::GetFP () => 0x%" PRIx64,
532 static_cast<void *>(frame), addr);
533 return addr;
534}
535
536SBAddress SBFrame::GetPCAddress() const {
537 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
538 SBAddress sb_addr;
539 std::unique_lock<std::recursive_mutex> lock;
540 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
541
542 StackFrame *frame = exe_ctx.GetFramePtr();
543 Target *target = exe_ctx.GetTargetPtr();
544 Process *process = exe_ctx.GetProcessPtr();
545 if (target && process) {
546 Process::StopLocker stop_locker;
547 if (stop_locker.TryLock(&process->GetRunLock())) {
548 frame = exe_ctx.GetFramePtr();
549 if (frame) {
550 sb_addr.SetAddress(&frame->GetFrameCodeAddress());
551 } else {
552 if (log)
553 log->Printf("SBFrame::GetPCAddress () => error: could not "
554 "reconstruct frame object for this SBFrame.");
555 }
556 } else {
557 if (log)
558 log->Printf("SBFrame::GetPCAddress () => error: process is running");
559 }
560 }
561 if (log)
562 log->Printf("SBFrame(%p)::GetPCAddress () => SBAddress(%p)",
563 static_cast<void *>(frame), static_cast<void *>(sb_addr.get()));
564 return sb_addr;
565}
566
567void SBFrame::Clear() { m_opaque_sp->Clear(); }
568
569lldb::SBValue SBFrame::GetValueForVariablePath(const char *var_path) {
570 SBValue sb_value;
571 std::unique_lock<std::recursive_mutex> lock;
572 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
573
574 StackFrame *frame = exe_ctx.GetFramePtr();
575 Target *target = exe_ctx.GetTargetPtr();
576 if (frame && target) {
577 lldb::DynamicValueType use_dynamic =
578 frame->CalculateTarget()->GetPreferDynamicValue();
579 sb_value = GetValueForVariablePath(var_path, use_dynamic);
580 }
581 return sb_value;
582}
583
584lldb::SBValue SBFrame::GetValueForVariablePath(const char *var_path,
585 DynamicValueType use_dynamic) {
586 SBValue sb_value;
587 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
588 if (var_path == nullptr || var_path[0] == '\0') {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000589 if (log)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000590 log->Printf(
591 "SBFrame::GetValueForVariablePath called with empty variable path.");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000592 return sb_value;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000593 }
594
595 std::unique_lock<std::recursive_mutex> lock;
596 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
597
598 StackFrame *frame = nullptr;
599 Target *target = exe_ctx.GetTargetPtr();
600 Process *process = exe_ctx.GetProcessPtr();
601 if (target && process) {
602 Process::StopLocker stop_locker;
603 if (stop_locker.TryLock(&process->GetRunLock())) {
604 frame = exe_ctx.GetFramePtr();
605 if (frame) {
606 VariableSP var_sp;
607 Error error;
608 ValueObjectSP value_sp(frame->GetValueForVariableExpressionPath(
609 var_path, eNoDynamicValues,
610 StackFrame::eExpressionPathOptionCheckPtrVsMember |
611 StackFrame::eExpressionPathOptionsAllowDirectIVarAccess,
612 var_sp, error));
613 sb_value.SetSP(value_sp, use_dynamic);
614 } else {
615 if (log)
616 log->Printf("SBFrame::GetValueForVariablePath () => error: could not "
617 "reconstruct frame object for this SBFrame.");
618 }
619 } else {
620 if (log)
621 log->Printf(
622 "SBFrame::GetValueForVariablePath () => error: process is running");
623 }
624 }
625 return sb_value;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000626}
627
Kate Stoneb9c1b512016-09-06 20:57:50 +0000628SBValue SBFrame::FindVariable(const char *name) {
629 SBValue value;
630 std::unique_lock<std::recursive_mutex> lock;
631 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
632
633 StackFrame *frame = exe_ctx.GetFramePtr();
634 Target *target = exe_ctx.GetTargetPtr();
635 if (frame && target) {
636 lldb::DynamicValueType use_dynamic =
637 frame->CalculateTarget()->GetPreferDynamicValue();
638 value = FindVariable(name, use_dynamic);
639 }
640 return value;
Johnny Chen35e2ab62012-03-05 19:53:24 +0000641}
642
Kate Stoneb9c1b512016-09-06 20:57:50 +0000643SBValue SBFrame::FindVariable(const char *name,
644 lldb::DynamicValueType use_dynamic) {
645 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
646 VariableSP var_sp;
647 SBValue sb_value;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000648
Kate Stoneb9c1b512016-09-06 20:57:50 +0000649 if (name == nullptr || name[0] == '\0') {
Caroline Ticeceb6b132010-10-26 03:11:13 +0000650 if (log)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000651 log->Printf("SBFrame::FindVariable called with empty name");
652 return sb_value;
653 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000654
Kate Stoneb9c1b512016-09-06 20:57:50 +0000655 ValueObjectSP value_sp;
656 std::unique_lock<std::recursive_mutex> lock;
657 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
658
659 StackFrame *frame = nullptr;
660 Target *target = exe_ctx.GetTargetPtr();
661 Process *process = exe_ctx.GetProcessPtr();
662 if (target && process) {
663 Process::StopLocker stop_locker;
664 if (stop_locker.TryLock(&process->GetRunLock())) {
665 frame = exe_ctx.GetFramePtr();
666 if (frame) {
667 VariableList variable_list;
668 SymbolContext sc(frame->GetSymbolContext(eSymbolContextBlock));
669
670 if (sc.block) {
671 const bool can_create = true;
672 const bool get_parent_variables = true;
673 const bool stop_if_block_is_inlined_function = true;
674
675 if (sc.block->AppendVariables(
676 can_create, get_parent_variables,
677 stop_if_block_is_inlined_function,
678 [frame](Variable *v) { return v->IsInScope(frame); },
679 &variable_list)) {
680 var_sp = variable_list.FindVariable(ConstString(name));
681 }
682 }
683
684 if (var_sp) {
685 value_sp =
686 frame->GetValueObjectForFrameVariable(var_sp, eNoDynamicValues);
687 sb_value.SetSP(value_sp, use_dynamic);
688 }
689 } else {
690 if (log)
691 log->Printf("SBFrame::FindVariable () => error: could not "
692 "reconstruct frame object for this SBFrame.");
693 }
694 } else {
695 if (log)
696 log->Printf("SBFrame::FindVariable () => error: process is running");
697 }
698 }
699
700 if (log)
701 log->Printf("SBFrame(%p)::FindVariable (name=\"%s\") => SBValue(%p)",
702 static_cast<void *>(frame), name,
703 static_cast<void *>(value_sp.get()));
704
705 return sb_value;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000706}
707
Kate Stoneb9c1b512016-09-06 20:57:50 +0000708SBValue SBFrame::FindValue(const char *name, ValueType value_type) {
709 SBValue value;
710 std::unique_lock<std::recursive_mutex> lock;
711 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000712
Kate Stoneb9c1b512016-09-06 20:57:50 +0000713 StackFrame *frame = exe_ctx.GetFramePtr();
714 Target *target = exe_ctx.GetTargetPtr();
715 if (frame && target) {
716 lldb::DynamicValueType use_dynamic =
717 frame->CalculateTarget()->GetPreferDynamicValue();
718 value = FindValue(name, value_type, use_dynamic);
719 }
720 return value;
721}
Greg Clayton48381312010-10-30 04:51:46 +0000722
Kate Stoneb9c1b512016-09-06 20:57:50 +0000723SBValue SBFrame::FindValue(const char *name, ValueType value_type,
724 lldb::DynamicValueType use_dynamic) {
725 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
726 SBValue sb_value;
727
728 if (name == nullptr || name[0] == '\0') {
Greg Clayton48381312010-10-30 04:51:46 +0000729 if (log)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000730 log->Printf("SBFrame::FindValue called with empty name.");
731 return sb_value;
732 }
Greg Clayton48381312010-10-30 04:51:46 +0000733
Kate Stoneb9c1b512016-09-06 20:57:50 +0000734 ValueObjectSP value_sp;
735 std::unique_lock<std::recursive_mutex> lock;
736 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000737
Kate Stoneb9c1b512016-09-06 20:57:50 +0000738 StackFrame *frame = nullptr;
739 Target *target = exe_ctx.GetTargetPtr();
740 Process *process = exe_ctx.GetProcessPtr();
741 if (target && process) {
742 Process::StopLocker stop_locker;
743 if (stop_locker.TryLock(&process->GetRunLock())) {
744 frame = exe_ctx.GetFramePtr();
745 if (frame) {
746 VariableList variable_list;
Jim Inghamc481c7e2016-06-10 00:37:44 +0000747
Kate Stoneb9c1b512016-09-06 20:57:50 +0000748 switch (value_type) {
749 case eValueTypeVariableGlobal: // global variable
750 case eValueTypeVariableStatic: // static variable
751 case eValueTypeVariableArgument: // function argument variables
752 case eValueTypeVariableLocal: // function local variables
753 case eValueTypeVariableThreadLocal: // thread local variables
754 {
755 SymbolContext sc(frame->GetSymbolContext(eSymbolContextBlock));
756
757 const bool can_create = true;
758 const bool get_parent_variables = true;
759 const bool stop_if_block_is_inlined_function = true;
760
761 if (sc.block)
762 sc.block->AppendVariables(
763 can_create, get_parent_variables,
764 stop_if_block_is_inlined_function,
765 [frame](Variable *v) { return v->IsInScope(frame); },
766 &variable_list);
767 if (value_type == eValueTypeVariableGlobal) {
768 const bool get_file_globals = true;
769 VariableList *frame_vars = frame->GetVariableList(get_file_globals);
770 if (frame_vars)
771 frame_vars->AppendVariablesIfUnique(variable_list);
772 }
773 ConstString const_name(name);
774 VariableSP variable_sp(
775 variable_list.FindVariable(const_name, value_type));
776 if (variable_sp) {
777 value_sp = frame->GetValueObjectForFrameVariable(variable_sp,
778 eNoDynamicValues);
779 sb_value.SetSP(value_sp, use_dynamic);
780 }
781 } break;
782
783 case eValueTypeRegister: // stack frame register value
784 {
785 RegisterContextSP reg_ctx(frame->GetRegisterContext());
786 if (reg_ctx) {
787 const uint32_t num_regs = reg_ctx->GetRegisterCount();
788 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx) {
789 const RegisterInfo *reg_info =
790 reg_ctx->GetRegisterInfoAtIndex(reg_idx);
791 if (reg_info &&
792 ((reg_info->name && strcasecmp(reg_info->name, name) == 0) ||
793 (reg_info->alt_name &&
794 strcasecmp(reg_info->alt_name, name) == 0))) {
795 value_sp = ValueObjectRegister::Create(frame, reg_ctx, reg_idx);
796 sb_value.SetSP(value_sp);
797 break;
798 }
799 }
800 }
801 } break;
802
803 case eValueTypeRegisterSet: // A collection of stack frame register
804 // values
805 {
806 RegisterContextSP reg_ctx(frame->GetRegisterContext());
807 if (reg_ctx) {
808 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
809 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx) {
810 const RegisterSet *reg_set = reg_ctx->GetRegisterSet(set_idx);
811 if (reg_set &&
812 ((reg_set->name && strcasecmp(reg_set->name, name) == 0) ||
813 (reg_set->short_name &&
814 strcasecmp(reg_set->short_name, name) == 0))) {
815 value_sp =
816 ValueObjectRegisterSet::Create(frame, reg_ctx, set_idx);
817 sb_value.SetSP(value_sp);
818 break;
819 }
820 }
821 }
822 } break;
823
824 case eValueTypeConstResult: // constant result variables
825 {
826 ConstString const_name(name);
827 ExpressionVariableSP expr_var_sp(
828 target->GetPersistentVariable(const_name));
829 if (expr_var_sp) {
830 value_sp = expr_var_sp->GetValueObject();
831 sb_value.SetSP(value_sp, use_dynamic);
832 }
833 } break;
834
835 default:
836 break;
837 }
838 } else {
839 if (log)
840 log->Printf("SBFrame::FindValue () => error: could not reconstruct "
841 "frame object for this SBFrame.");
842 }
843 } else {
844 if (log)
845 log->Printf("SBFrame::FindValue () => error: process is running");
Greg Clayton316d4982011-06-18 20:06:08 +0000846 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000847 }
848
849 if (log)
850 log->Printf("SBFrame(%p)::FindVariableInScope (name=\"%s\", value_type=%i) "
851 "=> SBValue(%p)",
852 static_cast<void *>(frame), name, value_type,
853 static_cast<void *>(value_sp.get()));
854
855 return sb_value;
Jim Ingham78a685a2011-04-16 00:01:13 +0000856}
857
Kate Stoneb9c1b512016-09-06 20:57:50 +0000858bool SBFrame::IsEqual(const SBFrame &that) const {
859 lldb::StackFrameSP this_sp = GetFrameSP();
860 lldb::StackFrameSP that_sp = that.GetFrameSP();
861 return (this_sp && that_sp && this_sp->GetStackID() == that_sp->GetStackID());
862}
Jim Inghamc481c7e2016-06-10 00:37:44 +0000863
Kate Stoneb9c1b512016-09-06 20:57:50 +0000864bool SBFrame::operator==(const SBFrame &rhs) const { return IsEqual(rhs); }
865
866bool SBFrame::operator!=(const SBFrame &rhs) const { return !IsEqual(rhs); }
867
868SBThread SBFrame::GetThread() const {
869 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
870
871 std::unique_lock<std::recursive_mutex> lock;
872 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
873
874 ThreadSP thread_sp(exe_ctx.GetThreadSP());
875 SBThread sb_thread(thread_sp);
876
877 if (log) {
878 SBStream sstr;
879 sb_thread.GetDescription(sstr);
880 log->Printf("SBFrame(%p)::GetThread () => SBThread(%p): %s",
881 static_cast<void *>(exe_ctx.GetFramePtr()),
882 static_cast<void *>(thread_sp.get()), sstr.GetData());
883 }
884
885 return sb_thread;
886}
887
888const char *SBFrame::Disassemble() const {
889 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
890 const char *disassembly = nullptr;
891 std::unique_lock<std::recursive_mutex> lock;
892 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
893
894 StackFrame *frame = nullptr;
895 Target *target = exe_ctx.GetTargetPtr();
896 Process *process = exe_ctx.GetProcessPtr();
897 if (target && process) {
898 Process::StopLocker stop_locker;
899 if (stop_locker.TryLock(&process->GetRunLock())) {
900 frame = exe_ctx.GetFramePtr();
901 if (frame) {
902 disassembly = frame->Disassemble();
903 } else {
904 if (log)
905 log->Printf("SBFrame::Disassemble () => error: could not reconstruct "
906 "frame object for this SBFrame.");
907 }
908 } else {
909 if (log)
910 log->Printf("SBFrame::Disassemble () => error: process is running");
911 }
912 }
913
914 if (log)
915 log->Printf("SBFrame(%p)::Disassemble () => %s", static_cast<void *>(frame),
916 disassembly);
917
918 return disassembly;
919}
920
921SBValueList SBFrame::GetVariables(bool arguments, bool locals, bool statics,
922 bool in_scope_only) {
923 SBValueList value_list;
924 std::unique_lock<std::recursive_mutex> lock;
925 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
926
927 StackFrame *frame = exe_ctx.GetFramePtr();
928 Target *target = exe_ctx.GetTargetPtr();
929 if (frame && target) {
930 lldb::DynamicValueType use_dynamic =
931 frame->CalculateTarget()->GetPreferDynamicValue();
932 const bool include_runtime_support_values =
933 target ? target->GetDisplayRuntimeSupportValues() : false;
934
Zachary Turner51f96ee2015-02-17 17:55:50 +0000935 SBVariablesOptions options;
936 options.SetIncludeArguments(arguments);
937 options.SetIncludeLocals(locals);
938 options.SetIncludeStatics(statics);
939 options.SetInScopeOnly(in_scope_only);
940 options.SetIncludeRuntimeSupportValues(include_runtime_support_values);
941 options.SetUseDynamic(use_dynamic);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000942
943 value_list = GetVariables(options);
944 }
945 return value_list;
Enrico Granata560558e2015-02-11 02:35:39 +0000946}
947
Kate Stoneb9c1b512016-09-06 20:57:50 +0000948lldb::SBValueList SBFrame::GetVariables(bool arguments, bool locals,
949 bool statics, bool in_scope_only,
950 lldb::DynamicValueType use_dynamic) {
951 std::unique_lock<std::recursive_mutex> lock;
952 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000953
Kate Stoneb9c1b512016-09-06 20:57:50 +0000954 Target *target = exe_ctx.GetTargetPtr();
955 const bool include_runtime_support_values =
956 target ? target->GetDisplayRuntimeSupportValues() : false;
957 SBVariablesOptions options;
958 options.SetIncludeArguments(arguments);
959 options.SetIncludeLocals(locals);
960 options.SetIncludeStatics(statics);
961 options.SetInScopeOnly(in_scope_only);
962 options.SetIncludeRuntimeSupportValues(include_runtime_support_values);
963 options.SetUseDynamic(use_dynamic);
964 return GetVariables(options);
965}
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000966
Kate Stoneb9c1b512016-09-06 20:57:50 +0000967SBValueList SBFrame::GetVariables(const lldb::SBVariablesOptions &options) {
968 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
Greg Claytonb9556ac2012-01-30 07:41:31 +0000969
Kate Stoneb9c1b512016-09-06 20:57:50 +0000970 SBValueList value_list;
971 std::unique_lock<std::recursive_mutex> lock;
972 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Greg Clayton349213f2016-04-29 21:00:38 +0000973
Kate Stoneb9c1b512016-09-06 20:57:50 +0000974 StackFrame *frame = nullptr;
975 Target *target = exe_ctx.GetTargetPtr();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000976
Kate Stoneb9c1b512016-09-06 20:57:50 +0000977 const bool statics = options.GetIncludeStatics();
978 const bool arguments = options.GetIncludeArguments();
979 const bool locals = options.GetIncludeLocals();
980 const bool in_scope_only = options.GetInScopeOnly();
981 const bool include_runtime_support_values =
982 options.GetIncludeRuntimeSupportValues();
983 const lldb::DynamicValueType use_dynamic = options.GetUseDynamic();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000984
Kate Stoneb9c1b512016-09-06 20:57:50 +0000985 if (log)
986 log->Printf("SBFrame::GetVariables (arguments=%i, locals=%i, statics=%i, "
987 "in_scope_only=%i runtime=%i dynamic=%i)",
988 arguments, locals, statics, in_scope_only,
989 include_runtime_support_values, use_dynamic);
Greg Claytonc982c762010-07-09 20:39:50 +0000990
Kate Stoneb9c1b512016-09-06 20:57:50 +0000991 std::set<VariableSP> variable_set;
992 Process *process = exe_ctx.GetProcessPtr();
993 if (target && process) {
994 Process::StopLocker stop_locker;
995 if (stop_locker.TryLock(&process->GetRunLock())) {
996 frame = exe_ctx.GetFramePtr();
997 if (frame) {
998 size_t i;
999 VariableList *variable_list = nullptr;
1000 variable_list = frame->GetVariableList(true);
1001 if (variable_list) {
1002 const size_t num_variables = variable_list->GetSize();
1003 if (num_variables) {
1004 for (i = 0; i < num_variables; ++i) {
1005 VariableSP variable_sp(variable_list->GetVariableAtIndex(i));
1006 if (variable_sp) {
1007 bool add_variable = false;
1008 switch (variable_sp->GetScope()) {
1009 case eValueTypeVariableGlobal:
1010 case eValueTypeVariableStatic:
1011 case eValueTypeVariableThreadLocal:
1012 add_variable = statics;
1013 break;
Greg Clayton349213f2016-04-29 21:00:38 +00001014
Kate Stoneb9c1b512016-09-06 20:57:50 +00001015 case eValueTypeVariableArgument:
1016 add_variable = arguments;
1017 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001018
Kate Stoneb9c1b512016-09-06 20:57:50 +00001019 case eValueTypeVariableLocal:
1020 add_variable = locals;
1021 break;
1022
1023 default:
1024 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001025 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001026 if (add_variable) {
1027 // Only add variables once so we don't end up with duplicates
1028 if (variable_set.find(variable_sp) == variable_set.end())
1029 variable_set.insert(variable_sp);
1030 else
1031 continue;
Caroline Ticeceb6b132010-10-26 03:11:13 +00001032
Kate Stoneb9c1b512016-09-06 20:57:50 +00001033 if (in_scope_only && !variable_sp->IsInScope(frame))
1034 continue;
Caroline Ticeceb6b132010-10-26 03:11:13 +00001035
Kate Stoneb9c1b512016-09-06 20:57:50 +00001036 ValueObjectSP valobj_sp(frame->GetValueObjectForFrameVariable(
1037 variable_sp, eNoDynamicValues));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001038
Kate Stoneb9c1b512016-09-06 20:57:50 +00001039 if (!include_runtime_support_values && valobj_sp != nullptr &&
1040 valobj_sp->IsRuntimeSupportValue())
1041 continue;
Caroline Ticeceb6b132010-10-26 03:11:13 +00001042
Kate Stoneb9c1b512016-09-06 20:57:50 +00001043 SBValue value_sb;
1044 value_sb.SetSP(valobj_sp, use_dynamic);
1045 value_list.Append(value_sb);
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001046 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001047 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001048 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001049 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001050 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001051 } else {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001052 if (log)
Kate Stoneb9c1b512016-09-06 20:57:50 +00001053 log->Printf("SBFrame::GetVariables () => error: could not "
1054 "reconstruct frame object for this SBFrame.");
1055 }
1056 } else {
1057 if (log)
1058 log->Printf("SBFrame::GetVariables () => error: process is running");
1059 }
1060 }
1061
1062 if (log)
1063 log->Printf("SBFrame(%p)::GetVariables (...) => SBValueList(%p)",
1064 static_cast<void *>(frame),
1065 static_cast<void *>(value_list.opaque_ptr()));
1066
1067 return value_list;
1068}
1069
1070SBValueList SBFrame::GetRegisters() {
1071 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1072
1073 SBValueList value_list;
1074 std::unique_lock<std::recursive_mutex> lock;
1075 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1076
1077 StackFrame *frame = nullptr;
1078 Target *target = exe_ctx.GetTargetPtr();
1079 Process *process = exe_ctx.GetProcessPtr();
1080 if (target && process) {
1081 Process::StopLocker stop_locker;
1082 if (stop_locker.TryLock(&process->GetRunLock())) {
1083 frame = exe_ctx.GetFramePtr();
1084 if (frame) {
1085 RegisterContextSP reg_ctx(frame->GetRegisterContext());
1086 if (reg_ctx) {
1087 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
1088 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx) {
1089 value_list.Append(
1090 ValueObjectRegisterSet::Create(frame, reg_ctx, set_idx));
1091 }
1092 }
1093 } else {
1094 if (log)
1095 log->Printf("SBFrame::GetRegisters () => error: could not "
1096 "reconstruct frame object for this SBFrame.");
1097 }
1098 } else {
1099 if (log)
1100 log->Printf("SBFrame::GetRegisters () => error: process is running");
1101 }
1102 }
1103
1104 if (log)
1105 log->Printf("SBFrame(%p)::GetRegisters () => SBValueList(%p)",
1106 static_cast<void *>(frame),
1107 static_cast<void *>(value_list.opaque_ptr()));
1108
1109 return value_list;
1110}
1111
1112SBValue SBFrame::FindRegister(const char *name) {
1113 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1114
1115 SBValue result;
1116 ValueObjectSP value_sp;
1117 std::unique_lock<std::recursive_mutex> lock;
1118 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1119
1120 StackFrame *frame = nullptr;
1121 Target *target = exe_ctx.GetTargetPtr();
1122 Process *process = exe_ctx.GetProcessPtr();
1123 if (target && process) {
1124 Process::StopLocker stop_locker;
1125 if (stop_locker.TryLock(&process->GetRunLock())) {
1126 frame = exe_ctx.GetFramePtr();
1127 if (frame) {
1128 RegisterContextSP reg_ctx(frame->GetRegisterContext());
1129 if (reg_ctx) {
1130 const uint32_t num_regs = reg_ctx->GetRegisterCount();
1131 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx) {
1132 const RegisterInfo *reg_info =
1133 reg_ctx->GetRegisterInfoAtIndex(reg_idx);
1134 if (reg_info &&
1135 ((reg_info->name && strcasecmp(reg_info->name, name) == 0) ||
1136 (reg_info->alt_name &&
1137 strcasecmp(reg_info->alt_name, name) == 0))) {
1138 value_sp = ValueObjectRegister::Create(frame, reg_ctx, reg_idx);
1139 result.SetSP(value_sp);
1140 break;
1141 }
1142 }
1143 }
1144 } else {
1145 if (log)
1146 log->Printf("SBFrame::FindRegister () => error: could not "
1147 "reconstruct frame object for this SBFrame.");
1148 }
1149 } else {
1150 if (log)
1151 log->Printf("SBFrame::FindRegister () => error: process is running");
1152 }
1153 }
1154
1155 if (log)
1156 log->Printf("SBFrame(%p)::FindRegister () => SBValue(%p)",
1157 static_cast<void *>(frame),
1158 static_cast<void *>(value_sp.get()));
1159
1160 return result;
1161}
1162
1163bool SBFrame::GetDescription(SBStream &description) {
1164 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1165 Stream &strm = description.ref();
1166
1167 std::unique_lock<std::recursive_mutex> lock;
1168 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1169
1170 StackFrame *frame;
1171 Target *target = exe_ctx.GetTargetPtr();
1172 Process *process = exe_ctx.GetProcessPtr();
1173 if (target && process) {
1174 Process::StopLocker stop_locker;
1175 if (stop_locker.TryLock(&process->GetRunLock())) {
1176 frame = exe_ctx.GetFramePtr();
1177 if (frame) {
1178 frame->DumpUsingSettingsFormat(&strm);
1179 } else {
1180 if (log)
1181 log->Printf("SBFrame::GetDescription () => error: could not "
1182 "reconstruct frame object for this SBFrame.");
1183 }
1184 } else {
1185 if (log)
1186 log->Printf("SBFrame::GetDescription () => error: process is running");
Jim Ingham7730b9a2012-11-29 00:26:19 +00001187 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001188
Kate Stoneb9c1b512016-09-06 20:57:50 +00001189 } else
1190 strm.PutCString("No value");
Greg Clayton48381312010-10-30 04:51:46 +00001191
Kate Stoneb9c1b512016-09-06 20:57:50 +00001192 return true;
1193}
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001194
Kate Stoneb9c1b512016-09-06 20:57:50 +00001195SBValue SBFrame::EvaluateExpression(const char *expr) {
1196 SBValue result;
1197 std::unique_lock<std::recursive_mutex> lock;
1198 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Greg Claytonb9556ac2012-01-30 07:41:31 +00001199
Kate Stoneb9c1b512016-09-06 20:57:50 +00001200 StackFrame *frame = exe_ctx.GetFramePtr();
1201 Target *target = exe_ctx.GetTargetPtr();
1202 if (frame && target) {
1203 SBExpressionOptions options;
1204 lldb::DynamicValueType fetch_dynamic_value =
1205 frame->CalculateTarget()->GetPreferDynamicValue();
1206 options.SetFetchDynamicValue(fetch_dynamic_value);
1207 options.SetUnwindOnError(true);
1208 options.SetIgnoreBreakpoints(true);
1209 if (target->GetLanguage() != eLanguageTypeUnknown)
1210 options.SetLanguage(target->GetLanguage());
1211 else
1212 options.SetLanguage(frame->GetLanguage());
1213 return EvaluateExpression(expr, options);
1214 }
1215 return result;
1216}
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001217
Kate Stoneb9c1b512016-09-06 20:57:50 +00001218SBValue
1219SBFrame::EvaluateExpression(const char *expr,
1220 lldb::DynamicValueType fetch_dynamic_value) {
1221 SBExpressionOptions options;
1222 options.SetFetchDynamicValue(fetch_dynamic_value);
1223 options.SetUnwindOnError(true);
1224 options.SetIgnoreBreakpoints(true);
1225 std::unique_lock<std::recursive_mutex> lock;
1226 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001227
Kate Stoneb9c1b512016-09-06 20:57:50 +00001228 StackFrame *frame = exe_ctx.GetFramePtr();
1229 Target *target = exe_ctx.GetTargetPtr();
1230 if (target && target->GetLanguage() != eLanguageTypeUnknown)
1231 options.SetLanguage(target->GetLanguage());
1232 else if (frame)
1233 options.SetLanguage(frame->GetLanguage());
1234 return EvaluateExpression(expr, options);
1235}
Greg Claytonfb6621e2013-12-06 21:59:52 +00001236
Kate Stoneb9c1b512016-09-06 20:57:50 +00001237SBValue SBFrame::EvaluateExpression(const char *expr,
1238 lldb::DynamicValueType fetch_dynamic_value,
1239 bool unwind_on_error) {
1240 SBExpressionOptions options;
1241 std::unique_lock<std::recursive_mutex> lock;
1242 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1243
1244 options.SetFetchDynamicValue(fetch_dynamic_value);
1245 options.SetUnwindOnError(unwind_on_error);
1246 options.SetIgnoreBreakpoints(true);
1247 StackFrame *frame = exe_ctx.GetFramePtr();
1248 Target *target = exe_ctx.GetTargetPtr();
1249 if (target && target->GetLanguage() != eLanguageTypeUnknown)
1250 options.SetLanguage(target->GetLanguage());
1251 else if (frame)
1252 options.SetLanguage(frame->GetLanguage());
1253 return EvaluateExpression(expr, options);
1254}
1255
1256lldb::SBValue SBFrame::EvaluateExpression(const char *expr,
1257 const SBExpressionOptions &options) {
1258 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
Jason Molendacf7e2dc2012-02-21 05:33:55 +00001259
1260#ifndef LLDB_DISABLE_PYTHON
Kate Stoneb9c1b512016-09-06 20:57:50 +00001261 Log *expr_log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
Jason Molendacf7e2dc2012-02-21 05:33:55 +00001262#endif
Greg Clayton48381312010-10-30 04:51:46 +00001263
Kate Stoneb9c1b512016-09-06 20:57:50 +00001264 ExpressionResults exe_results = eExpressionSetupError;
1265 SBValue expr_result;
1266
1267 if (expr == nullptr || expr[0] == '\0') {
1268 if (log)
1269 log->Printf(
1270 "SBFrame::EvaluateExpression called with an empty expression");
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001271 return expr_result;
Kate Stoneb9c1b512016-09-06 20:57:50 +00001272 }
Greg Clayton316d4982011-06-18 20:06:08 +00001273
Kate Stoneb9c1b512016-09-06 20:57:50 +00001274 ValueObjectSP expr_value_sp;
Oleksiy Vyalov05f75e92015-06-25 17:41:41 +00001275
Kate Stoneb9c1b512016-09-06 20:57:50 +00001276 std::unique_lock<std::recursive_mutex> lock;
1277 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Jim Inghamc481c7e2016-06-10 00:37:44 +00001278
Kate Stoneb9c1b512016-09-06 20:57:50 +00001279 if (log)
1280 log->Printf("SBFrame()::EvaluateExpression (expr=\"%s\")...", expr);
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001281
Kate Stoneb9c1b512016-09-06 20:57:50 +00001282 StackFrame *frame = nullptr;
1283 Target *target = exe_ctx.GetTargetPtr();
1284 Process *process = exe_ctx.GetProcessPtr();
1285
1286 if (target && process) {
1287 Process::StopLocker stop_locker;
1288 if (stop_locker.TryLock(&process->GetRunLock())) {
1289 frame = exe_ctx.GetFramePtr();
1290 if (frame) {
1291 if (target->GetDisplayExpressionsInCrashlogs()) {
1292 StreamString frame_description;
1293 frame->DumpUsingSettingsFormat(&frame_description);
1294 Host::SetCrashDescriptionWithFormat(
1295 "SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value "
1296 "= %u) %s",
1297 expr, options.GetFetchDynamicValue(),
Zachary Turnerc1564272016-11-16 21:15:24 +00001298 frame_description.GetData());
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001299 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001300
Kate Stoneb9c1b512016-09-06 20:57:50 +00001301 exe_results = target->EvaluateExpression(expr, frame, expr_value_sp,
1302 options.ref());
1303 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
1304
1305 if (target->GetDisplayExpressionsInCrashlogs())
1306 Host::SetCrashDescription(nullptr);
1307 } else {
1308 if (log)
1309 log->Printf("SBFrame::EvaluateExpression () => error: could not "
1310 "reconstruct frame object for this SBFrame.");
1311 }
1312 } else {
1313 if (log)
1314 log->Printf(
1315 "SBFrame::EvaluateExpression () => error: process is running");
Greg Clayton316d4982011-06-18 20:06:08 +00001316 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001317 }
1318
1319#ifndef LLDB_DISABLE_PYTHON
1320 if (expr_log)
1321 expr_log->Printf("** [SBFrame::EvaluateExpression] Expression result is "
1322 "%s, summary %s **",
1323 expr_result.GetValue(), expr_result.GetSummary());
1324
1325 if (log)
1326 log->Printf("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) "
1327 "(execution result=%d)",
1328 static_cast<void *>(frame), expr,
1329 static_cast<void *>(expr_value_sp.get()), exe_results);
1330#endif
1331
1332 return expr_result;
Greg Clayton316d4982011-06-18 20:06:08 +00001333}
1334
Kate Stoneb9c1b512016-09-06 20:57:50 +00001335bool SBFrame::IsInlined() {
1336 return static_cast<const SBFrame *>(this)->IsInlined();
Oleksiy Vyalov05f75e92015-06-25 17:41:41 +00001337}
1338
Kate Stoneb9c1b512016-09-06 20:57:50 +00001339bool SBFrame::IsInlined() const {
1340 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1341 std::unique_lock<std::recursive_mutex> lock;
1342 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Jim Inghamc481c7e2016-06-10 00:37:44 +00001343
Kate Stoneb9c1b512016-09-06 20:57:50 +00001344 StackFrame *frame = nullptr;
1345 Target *target = exe_ctx.GetTargetPtr();
1346 Process *process = exe_ctx.GetProcessPtr();
1347 if (target && process) {
1348 Process::StopLocker stop_locker;
1349 if (stop_locker.TryLock(&process->GetRunLock())) {
1350 frame = exe_ctx.GetFramePtr();
1351 if (frame) {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001352
Kate Stoneb9c1b512016-09-06 20:57:50 +00001353 Block *block = frame->GetSymbolContext(eSymbolContextBlock).block;
1354 if (block)
1355 return block->GetContainingInlinedBlock() != nullptr;
1356 } else {
1357 if (log)
1358 log->Printf("SBFrame::IsInlined () => error: could not reconstruct "
1359 "frame object for this SBFrame.");
1360 }
1361 } else {
1362 if (log)
1363 log->Printf("SBFrame::IsInlined () => error: process is running");
Greg Clayton316d4982011-06-18 20:06:08 +00001364 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001365 }
1366 return false;
Greg Clayton316d4982011-06-18 20:06:08 +00001367}
Enrico Granatac1f705c2015-07-06 18:28:46 +00001368
Kate Stoneb9c1b512016-09-06 20:57:50 +00001369const char *SBFrame::GetFunctionName() {
1370 return static_cast<const SBFrame *>(this)->GetFunctionName();
1371}
Jim Inghamc481c7e2016-06-10 00:37:44 +00001372
Kate Stoneb9c1b512016-09-06 20:57:50 +00001373const char *SBFrame::GetFunctionName() const {
1374 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1375 const char *name = nullptr;
1376 std::unique_lock<std::recursive_mutex> lock;
1377 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Jim Inghamc481c7e2016-06-10 00:37:44 +00001378
Kate Stoneb9c1b512016-09-06 20:57:50 +00001379 StackFrame *frame = nullptr;
1380 Target *target = exe_ctx.GetTargetPtr();
1381 Process *process = exe_ctx.GetProcessPtr();
1382 if (target && process) {
1383 Process::StopLocker stop_locker;
1384 if (stop_locker.TryLock(&process->GetRunLock())) {
1385 frame = exe_ctx.GetFramePtr();
1386 if (frame) {
1387 SymbolContext sc(frame->GetSymbolContext(eSymbolContextFunction |
1388 eSymbolContextBlock |
1389 eSymbolContextSymbol));
1390 if (sc.block) {
1391 Block *inlined_block = sc.block->GetContainingInlinedBlock();
1392 if (inlined_block) {
1393 const InlineFunctionInfo *inlined_info =
1394 inlined_block->GetInlinedFunctionInfo();
1395 name =
1396 inlined_info->GetName(sc.function->GetLanguage()).AsCString();
1397 }
Enrico Granatac1f705c2015-07-06 18:28:46 +00001398 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001399
1400 if (name == nullptr) {
1401 if (sc.function)
1402 name = sc.function->GetName().GetCString();
Enrico Granatac1f705c2015-07-06 18:28:46 +00001403 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001404
1405 if (name == nullptr) {
1406 if (sc.symbol)
1407 name = sc.symbol->GetName().GetCString();
1408 }
1409 } else {
1410 if (log)
1411 log->Printf("SBFrame::GetFunctionName () => error: could not "
1412 "reconstruct frame object for this SBFrame.");
1413 }
1414 } else {
1415 if (log)
1416 log->Printf("SBFrame::GetFunctionName() => error: process is running");
Enrico Granatac1f705c2015-07-06 18:28:46 +00001417 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001418 }
1419 return name;
1420}
1421
1422const char *SBFrame::GetDisplayFunctionName() {
1423 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1424 const char *name = nullptr;
1425
1426 std::unique_lock<std::recursive_mutex> lock;
1427 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1428
1429 StackFrame *frame = nullptr;
1430 Target *target = exe_ctx.GetTargetPtr();
1431 Process *process = exe_ctx.GetProcessPtr();
1432 if (target && process) {
1433 Process::StopLocker stop_locker;
1434 if (stop_locker.TryLock(&process->GetRunLock())) {
1435 frame = exe_ctx.GetFramePtr();
1436 if (frame) {
1437 SymbolContext sc(frame->GetSymbolContext(eSymbolContextFunction |
1438 eSymbolContextBlock |
1439 eSymbolContextSymbol));
1440 if (sc.block) {
1441 Block *inlined_block = sc.block->GetContainingInlinedBlock();
1442 if (inlined_block) {
1443 const InlineFunctionInfo *inlined_info =
1444 inlined_block->GetInlinedFunctionInfo();
1445 name = inlined_info->GetDisplayName(sc.function->GetLanguage())
1446 .AsCString();
1447 }
1448 }
1449
1450 if (name == nullptr) {
1451 if (sc.function)
1452 name = sc.function->GetDisplayName().GetCString();
1453 }
1454
1455 if (name == nullptr) {
1456 if (sc.symbol)
1457 name = sc.symbol->GetDisplayName().GetCString();
1458 }
1459 } else {
1460 if (log)
1461 log->Printf("SBFrame::GetDisplayFunctionName () => error: could not "
1462 "reconstruct frame object for this SBFrame.");
1463 }
1464 } else {
1465 if (log)
1466 log->Printf(
1467 "SBFrame::GetDisplayFunctionName() => error: process is running");
1468 }
1469 }
1470 return name;
Enrico Granatac1f705c2015-07-06 18:28:46 +00001471}