blob: 9f4709fac9e57f29f60839168637fe9af425c4f9 [file] [log] [blame]
Chris Lattner24943d22010-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
Eli Friedman7a62c8b2010-06-09 07:44:37 +000010#include "lldb/API/SBFrame.h"
Chris Lattner24943d22010-06-08 16:52:24 +000011
12#include <string>
13#include <algorithm>
14
15#include "lldb/lldb-types.h"
16
17#include "lldb/Core/Address.h"
18#include "lldb/Core/ConstString.h"
Caroline Tice7826c882010-10-26 03:11:13 +000019#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000020#include "lldb/Core/Stream.h"
21#include "lldb/Core/StreamFile.h"
22#include "lldb/Core/ValueObjectRegister.h"
23#include "lldb/Core/ValueObjectVariable.h"
Greg Claytond1719722010-10-05 03:13:51 +000024#include "lldb/Expression/ClangUserExpression.h"
Greg Clayton87ac9022011-06-25 04:35:01 +000025#include "lldb/Host/Host.h"
Chris Lattner24943d22010-06-08 16:52:24 +000026#include "lldb/Symbol/Block.h"
27#include "lldb/Symbol/SymbolContext.h"
28#include "lldb/Symbol/VariableList.h"
29#include "lldb/Symbol/Variable.h"
30#include "lldb/Target/ExecutionContext.h"
31#include "lldb/Target/Target.h"
32#include "lldb/Target/Process.h"
33#include "lldb/Target/RegisterContext.h"
34#include "lldb/Target/StackFrame.h"
Greg Clayton334d33a2012-01-30 07:41:31 +000035#include "lldb/Target/StackID.h"
Chris Lattner24943d22010-06-08 16:52:24 +000036#include "lldb/Target/Thread.h"
37
Eli Friedman7a62c8b2010-06-09 07:44:37 +000038#include "lldb/API/SBDebugger.h"
39#include "lldb/API/SBValue.h"
40#include "lldb/API/SBAddress.h"
Caroline Tice98f930f2010-09-20 05:20:02 +000041#include "lldb/API/SBStream.h"
Eli Friedman7a62c8b2010-06-09 07:44:37 +000042#include "lldb/API/SBSymbolContext.h"
43#include "lldb/API/SBThread.h"
Chris Lattner24943d22010-06-08 16:52:24 +000044
Greg Clayton334d33a2012-01-30 07:41:31 +000045namespace lldb_private {
46
47 class StackFrameImpl
48 {
49 public:
50 StackFrameImpl (const lldb::StackFrameSP &frame_sp) :
51 m_frame_wp (frame_sp),
52 m_thread_wp (),
53 m_stack_id ()
54 {
55 if (frame_sp)
56 {
Greg Clayton289afcb2012-02-18 05:35:26 +000057 m_thread_wp = frame_sp->GetThread();
Greg Clayton334d33a2012-01-30 07:41:31 +000058 m_stack_id = frame_sp->GetStackID();
59 }
60 }
61
62 ~StackFrameImpl()
63 {
64 }
65
66 lldb::StackFrameSP
67 GetFrameSP ()
68 {
69 lldb::StackFrameSP frame_sp;
70 // We have a weak pointer to our thread, which might
71 // be NULL'ed out if the thread went away, so first
72 // make sure our thread is still alive.
73 lldb::ThreadSP thread_sp (m_thread_wp.lock());
74 if (thread_sp)
75 {
76 // Our thread is still here, check if our frame
77 // is still alive as well.
78 frame_sp = m_frame_wp.lock();
79 if (frame_sp)
80 {
81 // Our frame is still alive, make sure that our thread
82 // still has this exact frame...
83 lldb::StackFrameSP tmp_frame_sp (thread_sp->GetStackFrameAtIndex (frame_sp->GetFrameIndex()));
Greg Clayton289afcb2012-02-18 05:35:26 +000084 if (tmp_frame_sp == frame_sp)
Greg Clayton334d33a2012-01-30 07:41:31 +000085 return frame_sp;
86 }
87 // The original stack frame might have gone away,
Greg Clayton289afcb2012-02-18 05:35:26 +000088 // we need to check for the frame by stack ID
Greg Clayton334d33a2012-01-30 07:41:31 +000089 frame_sp = thread_sp->GetFrameWithStackID (m_stack_id);
90 m_frame_wp = frame_sp;
91 }
92 return frame_sp;
93 }
94
95 void
96 SetFrameSP (const lldb::StackFrameSP &frame_sp)
97 {
98 if (frame_sp)
99 {
100 m_frame_wp = frame_sp;
Greg Clayton289afcb2012-02-18 05:35:26 +0000101 m_thread_wp = frame_sp->GetThread();
Greg Clayton334d33a2012-01-30 07:41:31 +0000102 m_stack_id = frame_sp->GetStackID();
103 }
104 else
105 {
106 m_frame_wp.reset();
107 m_thread_wp.reset();
108 m_stack_id.Clear();
109 }
110 }
111
112 protected:
113 lldb::StackFrameWP m_frame_wp;
114 lldb::ThreadWP m_thread_wp;
115 StackID m_stack_id;
116 };
117} // namespace lldb_private
118
Chris Lattner24943d22010-06-08 16:52:24 +0000119using namespace lldb;
120using namespace lldb_private;
121
Greg Clayton334d33a2012-01-30 07:41:31 +0000122
Chris Lattner24943d22010-06-08 16:52:24 +0000123SBFrame::SBFrame () :
Greg Clayton63094e02010-06-23 01:19:29 +0000124 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +0000125{
126}
127
Greg Clayton4e9267d2010-12-14 18:39:31 +0000128SBFrame::SBFrame (const StackFrameSP &lldb_object_sp) :
Greg Clayton334d33a2012-01-30 07:41:31 +0000129 m_opaque_sp (new StackFrameImpl (lldb_object_sp))
Chris Lattner24943d22010-06-08 16:52:24 +0000130{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000131 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000132
133 if (log)
134 {
135 SBStream sstr;
136 GetDescription (sstr);
Greg Claytona66ba462010-10-30 04:51:46 +0000137 log->Printf ("SBFrame::SBFrame (sp=%p) => SBFrame(%p): %s",
Greg Clayton334d33a2012-01-30 07:41:31 +0000138 lldb_object_sp.get(), lldb_object_sp.get(), sstr.GetData());
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000139
Caroline Tice7826c882010-10-26 03:11:13 +0000140 }
Chris Lattner24943d22010-06-08 16:52:24 +0000141}
142
Greg Clayton538eb822010-11-05 23:17:00 +0000143SBFrame::SBFrame(const SBFrame &rhs) :
144 m_opaque_sp (rhs.m_opaque_sp)
145{
146}
147
148const SBFrame &
149SBFrame::operator = (const SBFrame &rhs)
150{
151 if (this != &rhs)
152 m_opaque_sp = rhs.m_opaque_sp;
153 return *this;
154}
155
Chris Lattner24943d22010-06-08 16:52:24 +0000156SBFrame::~SBFrame()
157{
158}
159
Greg Clayton334d33a2012-01-30 07:41:31 +0000160StackFrameSP
161SBFrame::GetFrameSP() const
Chris Lattner24943d22010-06-08 16:52:24 +0000162{
Greg Clayton334d33a2012-01-30 07:41:31 +0000163 StackFrameImplSP impl_sp (m_opaque_sp);
164 StackFrameSP frame_sp;
165 if (impl_sp)
166 frame_sp = impl_sp->GetFrameSP();
167 return frame_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000168}
169
Greg Clayton334d33a2012-01-30 07:41:31 +0000170void
171SBFrame::SetFrameSP (const StackFrameSP &lldb_object_sp)
172{
173 if (lldb_object_sp)
174 {
175 if (m_opaque_sp)
176 {
177 StackFrameImplSP impl_sp (m_opaque_sp);
178 if (impl_sp)
179 impl_sp->SetFrameSP (lldb_object_sp);
180 }
181 else
182 {
183 m_opaque_sp = StackFrameImplSP (new StackFrameImpl(lldb_object_sp));
184 }
185 }
186 else
187 {
188 m_opaque_sp.reset();
189 }
190}
Chris Lattner24943d22010-06-08 16:52:24 +0000191
192bool
193SBFrame::IsValid() const
194{
Greg Clayton334d33a2012-01-30 07:41:31 +0000195 StackFrameImplSP impl_sp (m_opaque_sp);
196 if (impl_sp)
197 return (impl_sp->GetFrameSP().get() != NULL);
198 return false;
Chris Lattner24943d22010-06-08 16:52:24 +0000199}
200
201SBSymbolContext
202SBFrame::GetSymbolContext (uint32_t resolve_scope) const
203{
Caroline Tice7826c882010-10-26 03:11:13 +0000204
Chris Lattner24943d22010-06-08 16:52:24 +0000205 SBSymbolContext sb_sym_ctx;
Greg Clayton289afcb2012-02-18 05:35:26 +0000206 ExecutionContext exe_ctx(GetFrameSP());
207 StackFrame *frame = exe_ctx.GetFramePtr();
208 Target *target = exe_ctx.GetTargetPtr();
209 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000210 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000211 Mutex::Locker api_locker (target->GetAPIMutex());
212 sb_sym_ctx.SetSymbolContext(&frame->GetSymbolContext (resolve_scope));
Greg Claytonbdcda462010-12-20 20:49:23 +0000213 }
Caroline Tice7826c882010-10-26 03:11:13 +0000214
Greg Clayton4e9267d2010-12-14 18:39:31 +0000215 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000216 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000217 log->Printf ("SBFrame(%p)::GetSymbolContext (resolve_scope=0x%8.8x) => SBSymbolContext(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000218 frame, resolve_scope, sb_sym_ctx.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000219
Chris Lattner24943d22010-06-08 16:52:24 +0000220 return sb_sym_ctx;
221}
222
223SBModule
224SBFrame::GetModule () const
225{
Greg Claytondd62d722010-12-14 04:58:53 +0000226 SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000227 ModuleSP module_sp;
Greg Clayton289afcb2012-02-18 05:35:26 +0000228 ExecutionContext exe_ctx(GetFrameSP());
229 StackFrame *frame = exe_ctx.GetFramePtr();
230 Target *target = exe_ctx.GetTargetPtr();
231 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000232 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000233 Mutex::Locker api_locker (target->GetAPIMutex());
234 module_sp = frame->GetSymbolContext (eSymbolContextModule).module_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000235 sb_module.SetSP (module_sp);
Greg Claytonbdcda462010-12-20 20:49:23 +0000236 }
Greg Claytondd62d722010-12-14 04:58:53 +0000237
Greg Clayton4e9267d2010-12-14 18:39:31 +0000238 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000239 if (log)
240 log->Printf ("SBFrame(%p)::GetModule () => SBModule(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000241 frame, module_sp.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000242
Chris Lattner24943d22010-06-08 16:52:24 +0000243 return sb_module;
244}
245
246SBCompileUnit
247SBFrame::GetCompileUnit () const
248{
Greg Claytondd62d722010-12-14 04:58:53 +0000249 SBCompileUnit sb_comp_unit;
Greg Clayton289afcb2012-02-18 05:35:26 +0000250 ExecutionContext exe_ctx(GetFrameSP());
251 StackFrame *frame = exe_ctx.GetFramePtr();
252 Target *target = exe_ctx.GetTargetPtr();
253 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000254 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000255 Mutex::Locker api_locker (target->GetAPIMutex());
256 sb_comp_unit.reset (frame->GetSymbolContext (eSymbolContextCompUnit).comp_unit);
Greg Claytonbdcda462010-12-20 20:49:23 +0000257 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000258 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000259 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000260 log->Printf ("SBFrame(%p)::GetModule () => SBCompileUnit(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000261 frame, sb_comp_unit.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000262
Chris Lattner24943d22010-06-08 16:52:24 +0000263 return sb_comp_unit;
264}
265
266SBFunction
267SBFrame::GetFunction () const
268{
Greg Claytondd62d722010-12-14 04:58:53 +0000269 SBFunction sb_function;
Greg Clayton289afcb2012-02-18 05:35:26 +0000270 ExecutionContext exe_ctx(GetFrameSP());
271 StackFrame *frame = exe_ctx.GetFramePtr();
272 Target *target = exe_ctx.GetTargetPtr();
273 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000274 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000275 Mutex::Locker api_locker (target->GetAPIMutex());
276 sb_function.reset(frame->GetSymbolContext (eSymbolContextFunction).function);
Greg Claytonbdcda462010-12-20 20:49:23 +0000277 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000278 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000279 if (log)
280 log->Printf ("SBFrame(%p)::GetFunction () => SBFunction(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000281 frame, sb_function.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000282
Chris Lattner24943d22010-06-08 16:52:24 +0000283 return sb_function;
284}
285
Greg Clayton8f1e08b2010-10-04 18:37:52 +0000286SBSymbol
287SBFrame::GetSymbol () const
288{
Greg Claytondd62d722010-12-14 04:58:53 +0000289 SBSymbol sb_symbol;
Greg Clayton289afcb2012-02-18 05:35:26 +0000290 ExecutionContext exe_ctx(GetFrameSP());
291 StackFrame *frame = exe_ctx.GetFramePtr();
292 Target *target = exe_ctx.GetTargetPtr();
293 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000294 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000295 Mutex::Locker api_locker (target->GetAPIMutex());
296 sb_symbol.reset(frame->GetSymbolContext (eSymbolContextSymbol).symbol);
Greg Claytonbdcda462010-12-20 20:49:23 +0000297 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000298 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000299 if (log)
300 log->Printf ("SBFrame(%p)::GetSymbol () => SBSymbol(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000301 frame, sb_symbol.get());
Greg Clayton8f1e08b2010-10-04 18:37:52 +0000302 return sb_symbol;
303}
304
Chris Lattner24943d22010-06-08 16:52:24 +0000305SBBlock
306SBFrame::GetBlock () const
307{
Greg Claytondd62d722010-12-14 04:58:53 +0000308 SBBlock sb_block;
Greg Clayton289afcb2012-02-18 05:35:26 +0000309 ExecutionContext exe_ctx(GetFrameSP());
310 StackFrame *frame = exe_ctx.GetFramePtr();
311 Target *target = exe_ctx.GetTargetPtr();
312 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000313 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000314 Mutex::Locker api_locker (target->GetAPIMutex());
315 sb_block.SetPtr (frame->GetSymbolContext (eSymbolContextBlock).block);
Greg Claytonbdcda462010-12-20 20:49:23 +0000316 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000317 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000318 if (log)
319 log->Printf ("SBFrame(%p)::GetBlock () => SBBlock(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000320 frame, sb_block.GetPtr());
Chris Lattner24943d22010-06-08 16:52:24 +0000321 return sb_block;
322}
323
Greg Clayton69aa5d92010-09-07 04:20:48 +0000324SBBlock
325SBFrame::GetFrameBlock () const
326{
Greg Claytondd62d722010-12-14 04:58:53 +0000327 SBBlock sb_block;
Greg Clayton289afcb2012-02-18 05:35:26 +0000328 ExecutionContext exe_ctx(GetFrameSP());
329 StackFrame *frame = exe_ctx.GetFramePtr();
330 Target *target = exe_ctx.GetTargetPtr();
331 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000332 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000333 Mutex::Locker api_locker (target->GetAPIMutex());
334 sb_block.SetPtr(frame->GetFrameBlock ());
Greg Claytonbdcda462010-12-20 20:49:23 +0000335 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000336 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000337 if (log)
338 log->Printf ("SBFrame(%p)::GetFrameBlock () => SBBlock(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000339 frame, sb_block.GetPtr());
Greg Clayton69aa5d92010-09-07 04:20:48 +0000340 return sb_block;
341}
342
Chris Lattner24943d22010-06-08 16:52:24 +0000343SBLineEntry
344SBFrame::GetLineEntry () const
345{
Greg Claytondd62d722010-12-14 04:58:53 +0000346 SBLineEntry sb_line_entry;
Greg Clayton289afcb2012-02-18 05:35:26 +0000347 ExecutionContext exe_ctx(GetFrameSP());
348 StackFrame *frame = exe_ctx.GetFramePtr();
349 Target *target = exe_ctx.GetTargetPtr();
350 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000351 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000352 Mutex::Locker api_locker (target->GetAPIMutex());
353 sb_line_entry.SetLineEntry (frame->GetSymbolContext (eSymbolContextLineEntry).line_entry);
Greg Claytonbdcda462010-12-20 20:49:23 +0000354 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000355 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000356 if (log)
357 log->Printf ("SBFrame(%p)::GetLineEntry () => SBLineEntry(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000358 frame, sb_line_entry.get());
Chris Lattner24943d22010-06-08 16:52:24 +0000359 return sb_line_entry;
360}
361
362uint32_t
363SBFrame::GetFrameID () const
364{
Greg Clayton334d33a2012-01-30 07:41:31 +0000365 uint32_t frame_idx = UINT32_MAX;
366
367
Greg Clayton289afcb2012-02-18 05:35:26 +0000368 ExecutionContext exe_ctx(GetFrameSP());
369 StackFrame *frame = exe_ctx.GetFramePtr();
370 Target *target = exe_ctx.GetTargetPtr();
371 if (frame && target)
372 frame_idx = frame->GetFrameIndex ();
Greg Claytona66ba462010-10-30 04:51:46 +0000373
Greg Clayton4e9267d2010-12-14 18:39:31 +0000374 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000375 if (log)
376 log->Printf ("SBFrame(%p)::GetFrameID () => %u",
Greg Clayton289afcb2012-02-18 05:35:26 +0000377 frame, frame_idx);
Greg Claytona66ba462010-10-30 04:51:46 +0000378 return frame_idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000379}
380
Greg Clayton4e9267d2010-12-14 18:39:31 +0000381addr_t
Chris Lattner24943d22010-06-08 16:52:24 +0000382SBFrame::GetPC () const
383{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000384 addr_t addr = LLDB_INVALID_ADDRESS;
Greg Clayton289afcb2012-02-18 05:35:26 +0000385 ExecutionContext exe_ctx(GetFrameSP());
386 StackFrame *frame = exe_ctx.GetFramePtr();
387 Target *target = exe_ctx.GetTargetPtr();
388 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000389 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000390 Mutex::Locker api_locker (target->GetAPIMutex());
391 addr = frame->GetFrameCodeAddress().GetOpcodeLoadAddress (target);
Greg Claytonbdcda462010-12-20 20:49:23 +0000392 }
Caroline Tice7826c882010-10-26 03:11:13 +0000393
Greg Clayton4e9267d2010-12-14 18:39:31 +0000394 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000395 if (log)
Greg Clayton289afcb2012-02-18 05:35:26 +0000396 log->Printf ("SBFrame(%p)::GetPC () => 0x%llx", frame, addr);
Caroline Tice7826c882010-10-26 03:11:13 +0000397
398 return addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000399}
400
401bool
Greg Clayton4e9267d2010-12-14 18:39:31 +0000402SBFrame::SetPC (addr_t new_pc)
Chris Lattner24943d22010-06-08 16:52:24 +0000403{
Caroline Tice7826c882010-10-26 03:11:13 +0000404 bool ret_val = false;
Greg Clayton289afcb2012-02-18 05:35:26 +0000405 ExecutionContext exe_ctx(GetFrameSP());
406 StackFrame *frame = exe_ctx.GetFramePtr();
407 Target *target = exe_ctx.GetTargetPtr();
408 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000409 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000410 Mutex::Locker api_locker (target->GetAPIMutex());
411 ret_val = frame->GetRegisterContext()->SetPC (new_pc);
Greg Claytonbdcda462010-12-20 20:49:23 +0000412 }
Caroline Tice7826c882010-10-26 03:11:13 +0000413
Greg Clayton4e9267d2010-12-14 18:39:31 +0000414 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000415 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000416 log->Printf ("SBFrame(%p)::SetPC (new_pc=0x%llx) => %i",
Greg Clayton289afcb2012-02-18 05:35:26 +0000417 frame, new_pc, ret_val);
Caroline Tice7826c882010-10-26 03:11:13 +0000418
419 return ret_val;
Chris Lattner24943d22010-06-08 16:52:24 +0000420}
421
Greg Clayton4e9267d2010-12-14 18:39:31 +0000422addr_t
Chris Lattner24943d22010-06-08 16:52:24 +0000423SBFrame::GetSP () const
424{
Greg Claytona66ba462010-10-30 04:51:46 +0000425 addr_t addr = LLDB_INVALID_ADDRESS;
Greg Clayton289afcb2012-02-18 05:35:26 +0000426 ExecutionContext exe_ctx(GetFrameSP());
427 StackFrame *frame = exe_ctx.GetFramePtr();
428 Target *target = exe_ctx.GetTargetPtr();
429 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000430 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000431 Mutex::Locker api_locker (target->GetAPIMutex());
432 addr = frame->GetRegisterContext()->GetSP();
Greg Claytonbdcda462010-12-20 20:49:23 +0000433 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000434 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000435 if (log)
Greg Clayton289afcb2012-02-18 05:35:26 +0000436 log->Printf ("SBFrame(%p)::GetSP () => 0x%llx", frame, addr);
Greg Claytona66ba462010-10-30 04:51:46 +0000437
438 return addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000439}
440
441
Greg Clayton4e9267d2010-12-14 18:39:31 +0000442addr_t
Chris Lattner24943d22010-06-08 16:52:24 +0000443SBFrame::GetFP () const
444{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000445 addr_t addr = LLDB_INVALID_ADDRESS;
Greg Clayton289afcb2012-02-18 05:35:26 +0000446 ExecutionContext exe_ctx(GetFrameSP());
447 StackFrame *frame = exe_ctx.GetFramePtr();
448 Target *target = exe_ctx.GetTargetPtr();
449 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000450 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000451 Mutex::Locker api_locker (target->GetAPIMutex());
452 addr = frame->GetRegisterContext()->GetFP();
Greg Claytonbdcda462010-12-20 20:49:23 +0000453 }
Caroline Tice7826c882010-10-26 03:11:13 +0000454
Greg Clayton4e9267d2010-12-14 18:39:31 +0000455 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000456 if (log)
Greg Clayton289afcb2012-02-18 05:35:26 +0000457 log->Printf ("SBFrame(%p)::GetFP () => 0x%llx", frame, addr);
Caroline Tice7826c882010-10-26 03:11:13 +0000458 return addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000459}
460
461
462SBAddress
463SBFrame::GetPCAddress () const
464{
465 SBAddress sb_addr;
Greg Clayton289afcb2012-02-18 05:35:26 +0000466 ExecutionContext exe_ctx(GetFrameSP());
467 StackFrame *frame = exe_ctx.GetFramePtr();
468 Target *target = exe_ctx.GetTargetPtr();
469 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000470 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000471 Mutex::Locker api_locker (target->GetAPIMutex());
472 sb_addr.SetAddress (&frame->GetFrameCodeAddress());
Greg Claytonbdcda462010-12-20 20:49:23 +0000473 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000474 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000475 if (log)
Greg Clayton289afcb2012-02-18 05:35:26 +0000476 log->Printf ("SBFrame(%p)::GetPCAddress () => SBAddress(%p)", frame, sb_addr.get());
Chris Lattner24943d22010-06-08 16:52:24 +0000477 return sb_addr;
478}
479
480void
481SBFrame::Clear()
482{
Greg Clayton63094e02010-06-23 01:19:29 +0000483 m_opaque_sp.reset();
Chris Lattner24943d22010-06-08 16:52:24 +0000484}
485
Greg Claytond62b9c12012-02-03 07:02:37 +0000486lldb::SBValue
487SBFrame::GetValueForVariablePath (const char *var_path)
488{
489 SBValue sb_value;
Greg Clayton289afcb2012-02-18 05:35:26 +0000490 ExecutionContext exe_ctx(GetFrameSP());
491 StackFrame *frame = exe_ctx.GetFramePtr();
492 Target *target = exe_ctx.GetTargetPtr();
493 if (frame && target)
Greg Claytond62b9c12012-02-03 07:02:37 +0000494 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000495 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Claytond62b9c12012-02-03 07:02:37 +0000496 sb_value = GetValueForVariablePath (var_path, use_dynamic);
497 }
498 return sb_value;
499}
500
501lldb::SBValue
502SBFrame::GetValueForVariablePath (const char *var_path, DynamicValueType use_dynamic)
503{
504 SBValue sb_value;
Greg Clayton289afcb2012-02-18 05:35:26 +0000505 ExecutionContext exe_ctx(GetFrameSP());
506 StackFrame *frame = exe_ctx.GetFramePtr();
507 Target *target = exe_ctx.GetTargetPtr();
508 if (frame && target && var_path && var_path[0])
Greg Claytond62b9c12012-02-03 07:02:37 +0000509 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000510 Mutex::Locker api_locker (target->GetAPIMutex());
Greg Claytond62b9c12012-02-03 07:02:37 +0000511 VariableSP var_sp;
512 Error error;
Greg Clayton289afcb2012-02-18 05:35:26 +0000513 ValueObjectSP value_sp (frame->GetValueForVariableExpressionPath (var_path,
514 use_dynamic,
515 StackFrame::eExpressionPathOptionCheckPtrVsMember,
516 var_sp,
517 error));
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000518 sb_value.SetSP(value_sp);
Greg Claytond62b9c12012-02-03 07:02:37 +0000519 }
520 return sb_value;
521}
522
Chris Lattner24943d22010-06-08 16:52:24 +0000523SBValue
Greg Clayton4e9267d2010-12-14 18:39:31 +0000524SBFrame::FindVariable (const char *name)
Chris Lattner24943d22010-06-08 16:52:24 +0000525{
Greg Clayton582ed0e2011-06-18 20:06:08 +0000526 SBValue value;
Greg Clayton289afcb2012-02-18 05:35:26 +0000527 ExecutionContext exe_ctx(GetFrameSP());
528 StackFrame *frame = exe_ctx.GetFramePtr();
529 Target *target = exe_ctx.GetTargetPtr();
530 if (frame && target)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000531 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000532 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton582ed0e2011-06-18 20:06:08 +0000533 value = FindVariable (name, use_dynamic);
534 }
535 return value;
Jim Inghame41494a2011-04-16 00:01:13 +0000536}
Greg Claytond62b9c12012-02-03 07:02:37 +0000537
Jim Inghame41494a2011-04-16 00:01:13 +0000538
539SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000540SBFrame::FindVariable (const char *name, lldb::DynamicValueType use_dynamic)
Jim Inghame41494a2011-04-16 00:01:13 +0000541{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000542 VariableSP var_sp;
Jim Ingham47da8102011-04-22 23:53:53 +0000543 SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000544 ValueObjectSP value_sp;
Greg Clayton289afcb2012-02-18 05:35:26 +0000545 ExecutionContext exe_ctx(GetFrameSP());
546 StackFrame *frame = exe_ctx.GetFramePtr();
547 Target *target = exe_ctx.GetTargetPtr();
548 if (frame && target && name && name[0])
Chris Lattner24943d22010-06-08 16:52:24 +0000549 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000550 VariableList variable_list;
Greg Clayton289afcb2012-02-18 05:35:26 +0000551 Mutex::Locker api_locker (target->GetAPIMutex());
552 SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock));
Chris Lattner24943d22010-06-08 16:52:24 +0000553
Greg Claytondd62d722010-12-14 04:58:53 +0000554 if (sc.block)
Chris Lattner24943d22010-06-08 16:52:24 +0000555 {
Greg Claytondd62d722010-12-14 04:58:53 +0000556 const bool can_create = true;
557 const bool get_parent_variables = true;
558 const bool stop_if_block_is_inlined_function = true;
559
560 if (sc.block->AppendVariables (can_create,
561 get_parent_variables,
562 stop_if_block_is_inlined_function,
563 &variable_list))
564 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000565 var_sp = variable_list.FindVariable (ConstString(name));
Greg Claytondd62d722010-12-14 04:58:53 +0000566 }
Chris Lattner24943d22010-06-08 16:52:24 +0000567 }
Greg Clayton582ed0e2011-06-18 20:06:08 +0000568
569 if (var_sp)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000570 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000571 value_sp = frame->GetValueObjectForFrameVariable(var_sp, use_dynamic);
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000572 sb_value.SetSP(value_sp);
573 }
Greg Clayton582ed0e2011-06-18 20:06:08 +0000574
Chris Lattner24943d22010-06-08 16:52:24 +0000575 }
Caroline Tice98f930f2010-09-20 05:20:02 +0000576
Greg Clayton4e9267d2010-12-14 18:39:31 +0000577 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000578 if (log)
Greg Clayton4e9267d2010-12-14 18:39:31 +0000579 log->Printf ("SBFrame(%p)::FindVariable (name=\"%s\") => SBValue(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000580 frame, name, value_sp.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000581
Chris Lattner24943d22010-06-08 16:52:24 +0000582 return sb_value;
583}
584
585SBValue
Greg Clayton4e9267d2010-12-14 18:39:31 +0000586SBFrame::FindValue (const char *name, ValueType value_type)
Chris Lattner24943d22010-06-08 16:52:24 +0000587{
Greg Clayton582ed0e2011-06-18 20:06:08 +0000588 SBValue value;
Greg Clayton289afcb2012-02-18 05:35:26 +0000589 ExecutionContext exe_ctx(GetFrameSP());
590 StackFrame *frame = exe_ctx.GetFramePtr();
591 Target *target = exe_ctx.GetTargetPtr();
592 if (frame && target)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000593 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000594 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton582ed0e2011-06-18 20:06:08 +0000595 value = FindValue (name, value_type, use_dynamic);
596 }
597 return value;
Jim Inghame41494a2011-04-16 00:01:13 +0000598}
599
600SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000601SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueType use_dynamic)
Jim Inghame41494a2011-04-16 00:01:13 +0000602{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000603 SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000604 ValueObjectSP value_sp;
Greg Clayton289afcb2012-02-18 05:35:26 +0000605 ExecutionContext exe_ctx(GetFrameSP());
606 StackFrame *frame = exe_ctx.GetFramePtr();
607 Target *target = exe_ctx.GetTargetPtr();
608 if (frame && target && name && name[0])
Chris Lattner24943d22010-06-08 16:52:24 +0000609 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000610 Mutex::Locker api_locker (target->GetAPIMutex());
Greg Clayton4e9267d2010-12-14 18:39:31 +0000611
612 switch (value_type)
Chris Lattner24943d22010-06-08 16:52:24 +0000613 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000614 case eValueTypeVariableGlobal: // global variable
615 case eValueTypeVariableStatic: // static variable
616 case eValueTypeVariableArgument: // function argument variables
617 case eValueTypeVariableLocal: // function local variables
Chris Lattner24943d22010-06-08 16:52:24 +0000618 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000619 VariableList *variable_list = frame->GetVariableList(true);
Greg Clayton4e9267d2010-12-14 18:39:31 +0000620
Greg Clayton289afcb2012-02-18 05:35:26 +0000621 SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock));
Greg Clayton4e9267d2010-12-14 18:39:31 +0000622
623 const bool can_create = true;
624 const bool get_parent_variables = true;
625 const bool stop_if_block_is_inlined_function = true;
626
627 if (sc.block && sc.block->AppendVariables (can_create,
628 get_parent_variables,
629 stop_if_block_is_inlined_function,
630 variable_list))
Johnny Chenc35750a2010-11-19 18:07:14 +0000631 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000632 ConstString const_name(name);
633 const uint32_t num_variables = variable_list->GetSize();
634 for (uint32_t i = 0; i < num_variables; ++i)
Johnny Chenc35750a2010-11-19 18:07:14 +0000635 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000636 VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
637 if (variable_sp &&
638 variable_sp->GetScope() == value_type &&
639 variable_sp->GetName() == const_name)
640 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000641 value_sp = frame->GetValueObjectForFrameVariable (variable_sp, use_dynamic);
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000642 sb_value.SetSP (value_sp);
Greg Clayton4e9267d2010-12-14 18:39:31 +0000643 break;
644 }
Johnny Chenc35750a2010-11-19 18:07:14 +0000645 }
646 }
Chris Lattner24943d22010-06-08 16:52:24 +0000647 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000648 break;
649
650 case eValueTypeRegister: // stack frame register value
651 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000652 RegisterContextSP reg_ctx (frame->GetRegisterContext());
Greg Clayton4e9267d2010-12-14 18:39:31 +0000653 if (reg_ctx)
654 {
655 const uint32_t num_regs = reg_ctx->GetRegisterCount();
656 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx)
657 {
658 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
659 if (reg_info &&
660 ((reg_info->name && strcasecmp (reg_info->name, name) == 0) ||
661 (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0)))
662 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000663 value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx);
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000664 sb_value.SetSP (value_sp);
665 break;
Greg Clayton4e9267d2010-12-14 18:39:31 +0000666 }
667 }
668 }
669 }
670 break;
671
672 case eValueTypeRegisterSet: // A collection of stack frame register values
673 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000674 RegisterContextSP reg_ctx (frame->GetRegisterContext());
Greg Clayton4e9267d2010-12-14 18:39:31 +0000675 if (reg_ctx)
676 {
677 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
678 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
679 {
680 const RegisterSet *reg_set = reg_ctx->GetRegisterSet (set_idx);
681 if (reg_set &&
682 ((reg_set->name && strcasecmp (reg_set->name, name) == 0) ||
683 (reg_set->short_name && strcasecmp (reg_set->short_name, name) == 0)))
684 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000685 value_sp = ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx);
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000686 sb_value.SetSP (value_sp);
687 break;
Greg Clayton4e9267d2010-12-14 18:39:31 +0000688 }
689 }
690 }
691 }
692 break;
693
694 case eValueTypeConstResult: // constant result variables
695 {
696 ConstString const_name(name);
Greg Clayton289afcb2012-02-18 05:35:26 +0000697 ClangExpressionVariableSP expr_var_sp (target->GetPersistentVariables().GetVariable (const_name));
Greg Clayton4e9267d2010-12-14 18:39:31 +0000698 if (expr_var_sp)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000699 {
700 value_sp = expr_var_sp->GetValueObject();
701 sb_value.SetSP (value_sp);
702 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000703 }
704 break;
705
706 default:
707 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000708 }
709 }
Caroline Tice98f930f2010-09-20 05:20:02 +0000710
Greg Clayton4e9267d2010-12-14 18:39:31 +0000711 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000712 if (log)
Greg Clayton4e9267d2010-12-14 18:39:31 +0000713 log->Printf ("SBFrame(%p)::FindVariableInScope (name=\"%s\", value_type=%i) => SBValue(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000714 frame, name, value_type, value_sp.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000715
716
Chris Lattner24943d22010-06-08 16:52:24 +0000717 return sb_value;
718}
719
720bool
Johnny Chen0164b752012-03-05 19:53:24 +0000721SBFrame::IsEqual (const SBFrame &that) const
722{
723 lldb::StackFrameSP this_sp = GetFrameSP();
724 lldb::StackFrameSP that_sp = that.GetFrameSP();
725 return (this_sp && that_sp && this_sp->GetStackID() == that_sp->GetStackID());
726}
727
728bool
Chris Lattner24943d22010-06-08 16:52:24 +0000729SBFrame::operator == (const SBFrame &rhs) const
730{
Johnny Chen0164b752012-03-05 19:53:24 +0000731 return IsEqual(rhs);
Chris Lattner24943d22010-06-08 16:52:24 +0000732}
733
734bool
735SBFrame::operator != (const SBFrame &rhs) const
736{
Johnny Chen0164b752012-03-05 19:53:24 +0000737 return !IsEqual(rhs);
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000738}
Chris Lattner24943d22010-06-08 16:52:24 +0000739
740SBThread
741SBFrame::GetThread () const
742{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000743 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000744
Greg Clayton289afcb2012-02-18 05:35:26 +0000745 ExecutionContext exe_ctx(GetFrameSP());
746 ThreadSP thread_sp (exe_ctx.GetThreadSP());
747 SBThread sb_thread (thread_sp);
Caroline Tice7826c882010-10-26 03:11:13 +0000748
749 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000750 {
751 SBStream sstr;
752 sb_thread.GetDescription (sstr);
Greg Clayton289afcb2012-02-18 05:35:26 +0000753 log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s",
754 exe_ctx.GetFramePtr(),
755 thread_sp.get(),
756 sstr.GetData());
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000757 }
Caroline Tice7826c882010-10-26 03:11:13 +0000758
Chris Lattner24943d22010-06-08 16:52:24 +0000759 return sb_thread;
760}
761
762const char *
763SBFrame::Disassemble () const
764{
Greg Claytona66ba462010-10-30 04:51:46 +0000765 const char *disassembly = NULL;
Greg Clayton289afcb2012-02-18 05:35:26 +0000766 ExecutionContext exe_ctx(GetFrameSP());
767 StackFrame *frame = exe_ctx.GetFramePtr();
768 Target *target = exe_ctx.GetTargetPtr();
769 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000770 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000771 Mutex::Locker api_locker (target->GetAPIMutex());
772 disassembly = frame->Disassemble();
Greg Claytonbdcda462010-12-20 20:49:23 +0000773 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000774 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000775
776 if (log)
Greg Clayton289afcb2012-02-18 05:35:26 +0000777 log->Printf ("SBFrame(%p)::Disassemble () => %s", frame, disassembly);
Greg Claytona66ba462010-10-30 04:51:46 +0000778
779 return disassembly;
Chris Lattner24943d22010-06-08 16:52:24 +0000780}
781
782
Chris Lattner24943d22010-06-08 16:52:24 +0000783SBValueList
784SBFrame::GetVariables (bool arguments,
785 bool locals,
786 bool statics,
787 bool in_scope_only)
788{
Greg Clayton582ed0e2011-06-18 20:06:08 +0000789 SBValueList value_list;
Greg Clayton289afcb2012-02-18 05:35:26 +0000790 ExecutionContext exe_ctx(GetFrameSP());
791 StackFrame *frame = exe_ctx.GetFramePtr();
792 Target *target = exe_ctx.GetTargetPtr();
793 if (frame && target)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000794 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000795 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton582ed0e2011-06-18 20:06:08 +0000796 value_list = GetVariables (arguments, locals, statics, in_scope_only, use_dynamic);
797 }
798 return value_list;
Jim Inghame41494a2011-04-16 00:01:13 +0000799}
800
801SBValueList
802SBFrame::GetVariables (bool arguments,
803 bool locals,
804 bool statics,
805 bool in_scope_only,
Jim Ingham10de7d12011-05-04 03:43:18 +0000806 lldb::DynamicValueType use_dynamic)
Jim Inghame41494a2011-04-16 00:01:13 +0000807{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000808 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000809
Greg Clayton334d33a2012-01-30 07:41:31 +0000810 SBValueList value_list;
Greg Clayton289afcb2012-02-18 05:35:26 +0000811 ExecutionContext exe_ctx(GetFrameSP());
812 StackFrame *frame = exe_ctx.GetFramePtr();
813 Target *target = exe_ctx.GetTargetPtr();
Greg Clayton334d33a2012-01-30 07:41:31 +0000814
Caroline Tice7826c882010-10-26 03:11:13 +0000815 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000816 log->Printf ("SBFrame(%p)::GetVariables (arguments=%i, locals=%i, statics=%i, in_scope_only=%i)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000817 frame,
Greg Claytona66ba462010-10-30 04:51:46 +0000818 arguments,
819 locals,
820 statics,
821 in_scope_only);
Greg Clayton334d33a2012-01-30 07:41:31 +0000822
Greg Clayton289afcb2012-02-18 05:35:26 +0000823 if (frame && target)
Chris Lattner24943d22010-06-08 16:52:24 +0000824 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000825
Chris Lattner24943d22010-06-08 16:52:24 +0000826 size_t i;
Greg Claytonbdcda462010-12-20 20:49:23 +0000827 VariableList *variable_list = NULL;
828 // Scope for locker
829 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000830 Mutex::Locker api_locker (target->GetAPIMutex());
831 variable_list = frame->GetVariableList(true);
Greg Claytonbdcda462010-12-20 20:49:23 +0000832 }
Chris Lattner24943d22010-06-08 16:52:24 +0000833 if (variable_list)
834 {
835 const size_t num_variables = variable_list->GetSize();
836 if (num_variables)
837 {
838 for (i = 0; i < num_variables; ++i)
839 {
840 VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
841 if (variable_sp)
842 {
843 bool add_variable = false;
844 switch (variable_sp->GetScope())
845 {
846 case eValueTypeVariableGlobal:
847 case eValueTypeVariableStatic:
848 add_variable = statics;
849 break;
850
851 case eValueTypeVariableArgument:
852 add_variable = arguments;
853 break;
854
855 case eValueTypeVariableLocal:
856 add_variable = locals;
857 break;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000858
859 default:
860 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000861 }
862 if (add_variable)
863 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000864 if (in_scope_only && !variable_sp->IsInScope(frame))
Chris Lattner24943d22010-06-08 16:52:24 +0000865 continue;
866
Greg Clayton289afcb2012-02-18 05:35:26 +0000867 value_list.Append(frame->GetValueObjectForFrameVariable (variable_sp, use_dynamic));
Chris Lattner24943d22010-06-08 16:52:24 +0000868 }
869 }
870 }
871 }
Greg Clayton17dae082010-09-02 02:59:18 +0000872 }
Chris Lattner24943d22010-06-08 16:52:24 +0000873 }
Caroline Tice7826c882010-10-26 03:11:13 +0000874
875 if (log)
876 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000877 log->Printf ("SBFrame(%p)::GetVariables (...) => SBValueList(%p)", frame,
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000878 value_list.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000879 }
880
Chris Lattner24943d22010-06-08 16:52:24 +0000881 return value_list;
882}
883
Greg Clayton4e9267d2010-12-14 18:39:31 +0000884SBValueList
Chris Lattner24943d22010-06-08 16:52:24 +0000885SBFrame::GetRegisters ()
886{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000887 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000888
Chris Lattner24943d22010-06-08 16:52:24 +0000889 SBValueList value_list;
Greg Clayton289afcb2012-02-18 05:35:26 +0000890 ExecutionContext exe_ctx(GetFrameSP());
891 StackFrame *frame = exe_ctx.GetFramePtr();
892 Target *target = exe_ctx.GetTargetPtr();
893 if (frame && target)
Chris Lattner24943d22010-06-08 16:52:24 +0000894 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000895 Mutex::Locker api_locker (target->GetAPIMutex());
896 RegisterContextSP reg_ctx (frame->GetRegisterContext());
Chris Lattner24943d22010-06-08 16:52:24 +0000897 if (reg_ctx)
898 {
899 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
900 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
901 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000902 value_list.Append(ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx));
Chris Lattner24943d22010-06-08 16:52:24 +0000903 }
904 }
905 }
Caroline Tice7826c882010-10-26 03:11:13 +0000906
907 if (log)
Greg Clayton289afcb2012-02-18 05:35:26 +0000908 log->Printf ("SBFrame(%p)::Registers () => SBValueList(%p)", frame, value_list.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000909
Chris Lattner24943d22010-06-08 16:52:24 +0000910 return value_list;
911}
912
Caroline Tice98f930f2010-09-20 05:20:02 +0000913bool
914SBFrame::GetDescription (SBStream &description)
915{
Greg Clayton96154be2011-11-13 06:57:31 +0000916 Stream &strm = description.ref();
917
Greg Clayton289afcb2012-02-18 05:35:26 +0000918 ExecutionContext exe_ctx(GetFrameSP());
919 StackFrame *frame = exe_ctx.GetFramePtr();
920 Target *target = exe_ctx.GetTargetPtr();
921 if (frame && target)
Caroline Tice98f930f2010-09-20 05:20:02 +0000922 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000923 Mutex::Locker api_locker (target->GetAPIMutex());
924 frame->DumpUsingSettingsFormat (&strm);
Caroline Tice98f930f2010-09-20 05:20:02 +0000925 }
926 else
Greg Clayton96154be2011-11-13 06:57:31 +0000927 strm.PutCString ("No value");
Caroline Tice98f930f2010-09-20 05:20:02 +0000928
929 return true;
930}
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000931
Greg Clayton4e9267d2010-12-14 18:39:31 +0000932SBValue
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000933SBFrame::EvaluateExpression (const char *expr)
934{
Greg Clayton582ed0e2011-06-18 20:06:08 +0000935 SBValue result;
Greg Clayton289afcb2012-02-18 05:35:26 +0000936 ExecutionContext exe_ctx(GetFrameSP());
937 StackFrame *frame = exe_ctx.GetFramePtr();
938 Target *target = exe_ctx.GetTargetPtr();
939 if (frame && target)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000940 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000941 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton582ed0e2011-06-18 20:06:08 +0000942 result = EvaluateExpression (expr, use_dynamic);
943 }
944 return result;
Jim Inghame41494a2011-04-16 00:01:13 +0000945}
946
947SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000948SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value)
Jim Inghame41494a2011-04-16 00:01:13 +0000949{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000950 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Sean Callanan94d255f2010-12-07 22:55:01 +0000951
Greg Clayton4e9267d2010-12-14 18:39:31 +0000952 LogSP expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Greg Claytona66ba462010-10-30 04:51:46 +0000953
Johnny Chenee6e7902011-08-10 22:06:24 +0000954 ExecutionResults exe_results;
Greg Clayton4e9267d2010-12-14 18:39:31 +0000955 SBValue expr_result;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000956 ValueObjectSP expr_value_sp;
Greg Claytona66ba462010-10-30 04:51:46 +0000957
Greg Clayton289afcb2012-02-18 05:35:26 +0000958 ExecutionContext exe_ctx(GetFrameSP());
959 StackFrame *frame = exe_ctx.GetFramePtr();
960 Target *target = exe_ctx.GetTargetPtr();
Greg Clayton334d33a2012-01-30 07:41:31 +0000961 if (log)
Greg Clayton289afcb2012-02-18 05:35:26 +0000962 log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\")...", frame, expr);
Greg Clayton334d33a2012-01-30 07:41:31 +0000963
Greg Clayton289afcb2012-02-18 05:35:26 +0000964 if (frame && target)
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000965 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000966 Mutex::Locker api_locker (target->GetAPIMutex());
Greg Clayton582ed0e2011-06-18 20:06:08 +0000967
Greg Clayton87ac9022011-06-25 04:35:01 +0000968
969 StreamString frame_description;
Greg Clayton289afcb2012-02-18 05:35:26 +0000970 frame->DumpUsingSettingsFormat (&frame_description);
Greg Clayton87ac9022011-06-25 04:35:01 +0000971
972 Host::SetCrashDescriptionWithFormat ("SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
973 expr, fetch_dynamic_value, frame_description.GetString().c_str());
974
Sean Callanandaa6efe2011-12-21 22:22:58 +0000975 const bool coerce_to_id = false;
Greg Clayton427f2902010-12-14 02:59:59 +0000976 const bool unwind_on_error = true;
Sean Callanan6a925532011-01-13 08:53:35 +0000977 const bool keep_in_memory = false;
Greg Clayton427f2902010-12-14 02:59:59 +0000978
Greg Clayton289afcb2012-02-18 05:35:26 +0000979 exe_results = target->EvaluateExpression (expr,
980 frame,
981 eExecutionPolicyOnlyWhenNeeded,
982 coerce_to_id,
983 unwind_on_error,
984 keep_in_memory,
985 fetch_dynamic_value,
986 expr_value_sp);
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000987 expr_result.SetSP(expr_value_sp);
Greg Clayton668a6c72011-11-10 18:31:53 +0000988 Host::SetCrashDescription (NULL);
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000989 }
Jason Molendac48ca822012-02-21 05:33:55 +0000990
991#ifndef LLDB_DISABLE_PYTHON
Sean Callanan94d255f2010-12-07 22:55:01 +0000992 if (expr_log)
Jim Inghame41494a2011-04-16 00:01:13 +0000993 expr_log->Printf("** [SBFrame::EvaluateExpression] Expression result is %s, summary %s **",
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000994 expr_result.GetValue(),
995 expr_result.GetSummary());
Sean Callanan94d255f2010-12-07 22:55:01 +0000996
Greg Claytona66ba462010-10-30 04:51:46 +0000997 if (log)
Greg Clayton289afcb2012-02-18 05:35:26 +0000998 log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)",
999 frame,
Jim Inghame41494a2011-04-16 00:01:13 +00001000 expr,
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001001 expr_value_sp.get(),
Johnny Chenee6e7902011-08-10 22:06:24 +00001002 exe_results);
Jason Molendac48ca822012-02-21 05:33:55 +00001003#endif
Greg Claytona66ba462010-10-30 04:51:46 +00001004
Greg Clayton49ce6822010-10-31 03:01:06 +00001005 return expr_result;
Greg Clayton66ed2fb2010-10-05 00:00:42 +00001006}
Greg Clayton582ed0e2011-06-18 20:06:08 +00001007
1008bool
1009SBFrame::IsInlined()
1010{
Greg Clayton289afcb2012-02-18 05:35:26 +00001011 ExecutionContext exe_ctx(GetFrameSP());
1012 StackFrame *frame = exe_ctx.GetFramePtr();
1013 Target *target = exe_ctx.GetTargetPtr();
1014 if (frame && target)
Greg Clayton582ed0e2011-06-18 20:06:08 +00001015 {
Greg Clayton289afcb2012-02-18 05:35:26 +00001016 Block *block = frame->GetSymbolContext(eSymbolContextBlock).block;
Greg Clayton582ed0e2011-06-18 20:06:08 +00001017 if (block)
1018 return block->GetContainingInlinedBlock () != NULL;
1019 }
1020 return false;
1021}
1022
1023const char *
1024SBFrame::GetFunctionName()
1025{
1026 const char *name = NULL;
Greg Clayton289afcb2012-02-18 05:35:26 +00001027 ExecutionContext exe_ctx(GetFrameSP());
1028 StackFrame *frame = exe_ctx.GetFramePtr();
1029 Target *target = exe_ctx.GetTargetPtr();
1030 if (frame && target)
Greg Clayton582ed0e2011-06-18 20:06:08 +00001031 {
Greg Clayton289afcb2012-02-18 05:35:26 +00001032 SymbolContext sc (frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol));
Greg Clayton582ed0e2011-06-18 20:06:08 +00001033 if (sc.block)
1034 {
1035 Block *inlined_block = sc.block->GetContainingInlinedBlock ();
1036 if (inlined_block)
1037 {
1038 const InlineFunctionInfo* inlined_info = inlined_block->GetInlinedFunctionInfo();
1039 name = inlined_info->GetName().AsCString();
1040 }
1041 }
1042
1043 if (name == NULL)
1044 {
1045 if (sc.function)
1046 name = sc.function->GetName().GetCString();
1047 }
1048
1049 if (name == NULL)
1050 {
1051 if (sc.symbol)
1052 name = sc.symbol->GetName().GetCString();
1053 }
1054 }
1055 return name;
1056}
1057