blob: d17e32b1707f1faf6519300d8f7f4902df933fb8 [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 {
57 m_thread_wp = frame_sp->GetThread().shared_from_this();
58 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()));
84 if (tmp_frame_sp.get() == frame_sp.get())
85 return frame_sp;
86 }
87 // The original stack frame might have gone away,
88 // we need to check for the stac
89 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;
101 m_thread_wp = frame_sp->GetThread().shared_from_this();
102 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 Clayton334d33a2012-01-30 07:41:31 +0000206 StackFrameSP frame_sp(GetFrameSP());
207 if (frame_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000208 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000209 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
210 sb_sym_ctx.SetSymbolContext(&frame_sp->GetSymbolContext (resolve_scope));
Greg Claytonbdcda462010-12-20 20:49:23 +0000211 }
Caroline Tice7826c882010-10-26 03:11:13 +0000212
Greg Clayton4e9267d2010-12-14 18:39:31 +0000213 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000214 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000215 log->Printf ("SBFrame(%p)::GetSymbolContext (resolve_scope=0x%8.8x) => SBSymbolContext(%p)",
Greg Clayton334d33a2012-01-30 07:41:31 +0000216 frame_sp.get(), resolve_scope, sb_sym_ctx.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000217
Chris Lattner24943d22010-06-08 16:52:24 +0000218 return sb_sym_ctx;
219}
220
221SBModule
222SBFrame::GetModule () const
223{
Greg Claytondd62d722010-12-14 04:58:53 +0000224 SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000225 ModuleSP module_sp;
Greg Clayton334d33a2012-01-30 07:41:31 +0000226 StackFrameSP frame_sp(GetFrameSP());
227 if (frame_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000228 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000229 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
Greg Clayton0416bdf2012-01-30 09:04:36 +0000230 module_sp = frame_sp->GetSymbolContext (eSymbolContextModule).module_sp;
231 sb_module.SetSP (module_sp);
Greg Claytonbdcda462010-12-20 20:49:23 +0000232 }
Greg Claytondd62d722010-12-14 04:58:53 +0000233
Greg Clayton4e9267d2010-12-14 18:39:31 +0000234 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000235 if (log)
236 log->Printf ("SBFrame(%p)::GetModule () => SBModule(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000237 frame_sp.get(), module_sp.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000238
Chris Lattner24943d22010-06-08 16:52:24 +0000239 return sb_module;
240}
241
242SBCompileUnit
243SBFrame::GetCompileUnit () const
244{
Greg Claytondd62d722010-12-14 04:58:53 +0000245 SBCompileUnit sb_comp_unit;
Greg Clayton334d33a2012-01-30 07:41:31 +0000246 StackFrameSP frame_sp(GetFrameSP());
247 if (frame_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000248 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000249 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
250 sb_comp_unit.reset (frame_sp->GetSymbolContext (eSymbolContextCompUnit).comp_unit);
Greg Claytonbdcda462010-12-20 20:49:23 +0000251 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000252 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000253 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000254 log->Printf ("SBFrame(%p)::GetModule () => SBCompileUnit(%p)",
Greg Clayton334d33a2012-01-30 07:41:31 +0000255 frame_sp.get(), sb_comp_unit.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000256
Chris Lattner24943d22010-06-08 16:52:24 +0000257 return sb_comp_unit;
258}
259
260SBFunction
261SBFrame::GetFunction () const
262{
Greg Claytondd62d722010-12-14 04:58:53 +0000263 SBFunction sb_function;
Greg Clayton334d33a2012-01-30 07:41:31 +0000264 StackFrameSP frame_sp(GetFrameSP());
265 if (frame_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000266 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000267 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
268 sb_function.reset(frame_sp->GetSymbolContext (eSymbolContextFunction).function);
Greg Claytonbdcda462010-12-20 20:49:23 +0000269 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000270 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000271 if (log)
272 log->Printf ("SBFrame(%p)::GetFunction () => SBFunction(%p)",
Greg Clayton334d33a2012-01-30 07:41:31 +0000273 frame_sp.get(), sb_function.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000274
Chris Lattner24943d22010-06-08 16:52:24 +0000275 return sb_function;
276}
277
Greg Clayton8f1e08b2010-10-04 18:37:52 +0000278SBSymbol
279SBFrame::GetSymbol () const
280{
Greg Claytondd62d722010-12-14 04:58:53 +0000281 SBSymbol sb_symbol;
Greg Clayton334d33a2012-01-30 07:41:31 +0000282 StackFrameSP frame_sp(GetFrameSP());
283 if (frame_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000284 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000285 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
286 sb_symbol.reset(frame_sp->GetSymbolContext (eSymbolContextSymbol).symbol);
Greg Claytonbdcda462010-12-20 20:49:23 +0000287 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000288 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000289 if (log)
290 log->Printf ("SBFrame(%p)::GetSymbol () => SBSymbol(%p)",
Greg Clayton334d33a2012-01-30 07:41:31 +0000291 frame_sp.get(), sb_symbol.get());
Greg Clayton8f1e08b2010-10-04 18:37:52 +0000292 return sb_symbol;
293}
294
Chris Lattner24943d22010-06-08 16:52:24 +0000295SBBlock
296SBFrame::GetBlock () const
297{
Greg Claytondd62d722010-12-14 04:58:53 +0000298 SBBlock sb_block;
Greg Clayton334d33a2012-01-30 07:41:31 +0000299 StackFrameSP frame_sp(GetFrameSP());
300 if (frame_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000301 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000302 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
303 sb_block.reset (frame_sp->GetSymbolContext (eSymbolContextBlock).block);
Greg Claytonbdcda462010-12-20 20:49:23 +0000304 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000305 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000306 if (log)
307 log->Printf ("SBFrame(%p)::GetBlock () => SBBlock(%p)",
Greg Clayton334d33a2012-01-30 07:41:31 +0000308 frame_sp.get(), sb_block.get());
Chris Lattner24943d22010-06-08 16:52:24 +0000309 return sb_block;
310}
311
Greg Clayton69aa5d92010-09-07 04:20:48 +0000312SBBlock
313SBFrame::GetFrameBlock () const
314{
Greg Claytondd62d722010-12-14 04:58:53 +0000315 SBBlock sb_block;
Greg Clayton334d33a2012-01-30 07:41:31 +0000316 StackFrameSP frame_sp(GetFrameSP());
317 if (frame_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000318 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000319 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
320 sb_block.reset(frame_sp->GetFrameBlock ());
Greg Claytonbdcda462010-12-20 20:49:23 +0000321 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000322 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000323 if (log)
324 log->Printf ("SBFrame(%p)::GetFrameBlock () => SBBlock(%p)",
Greg Clayton334d33a2012-01-30 07:41:31 +0000325 frame_sp.get(), sb_block.get());
Greg Clayton69aa5d92010-09-07 04:20:48 +0000326 return sb_block;
327}
328
Chris Lattner24943d22010-06-08 16:52:24 +0000329SBLineEntry
330SBFrame::GetLineEntry () const
331{
Greg Claytondd62d722010-12-14 04:58:53 +0000332 SBLineEntry sb_line_entry;
Greg Clayton334d33a2012-01-30 07:41:31 +0000333 StackFrameSP frame_sp(GetFrameSP());
334 if (frame_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000335 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000336 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
337 sb_line_entry.SetLineEntry (frame_sp->GetSymbolContext (eSymbolContextLineEntry).line_entry);
Greg Claytonbdcda462010-12-20 20:49:23 +0000338 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000339 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000340 if (log)
341 log->Printf ("SBFrame(%p)::GetLineEntry () => SBLineEntry(%p)",
Greg Clayton334d33a2012-01-30 07:41:31 +0000342 frame_sp.get(), sb_line_entry.get());
Chris Lattner24943d22010-06-08 16:52:24 +0000343 return sb_line_entry;
344}
345
346uint32_t
347SBFrame::GetFrameID () const
348{
Greg Clayton334d33a2012-01-30 07:41:31 +0000349 uint32_t frame_idx = UINT32_MAX;
350
351
352 StackFrameSP frame_sp(GetFrameSP());
353 if (frame_sp)
354 frame_idx = frame_sp->GetFrameIndex ();
Greg Claytona66ba462010-10-30 04:51:46 +0000355
Greg Clayton4e9267d2010-12-14 18:39:31 +0000356 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000357 if (log)
358 log->Printf ("SBFrame(%p)::GetFrameID () => %u",
Greg Clayton334d33a2012-01-30 07:41:31 +0000359 frame_sp.get(), frame_idx);
Greg Claytona66ba462010-10-30 04:51:46 +0000360 return frame_idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000361}
362
Greg Clayton4e9267d2010-12-14 18:39:31 +0000363addr_t
Chris Lattner24943d22010-06-08 16:52:24 +0000364SBFrame::GetPC () const
365{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000366 addr_t addr = LLDB_INVALID_ADDRESS;
Greg Clayton334d33a2012-01-30 07:41:31 +0000367 StackFrameSP frame_sp(GetFrameSP());
368 if (frame_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000369 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000370 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
371 addr = frame_sp->GetFrameCodeAddress().GetOpcodeLoadAddress (&frame_sp->GetThread().GetProcess().GetTarget());
Greg Claytonbdcda462010-12-20 20:49:23 +0000372 }
Caroline Tice7826c882010-10-26 03:11:13 +0000373
Greg Clayton4e9267d2010-12-14 18:39:31 +0000374 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000375 if (log)
Greg Clayton334d33a2012-01-30 07:41:31 +0000376 log->Printf ("SBFrame(%p)::GetPC () => 0x%llx", frame_sp.get(), addr);
Caroline Tice7826c882010-10-26 03:11:13 +0000377
378 return addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000379}
380
381bool
Greg Clayton4e9267d2010-12-14 18:39:31 +0000382SBFrame::SetPC (addr_t new_pc)
Chris Lattner24943d22010-06-08 16:52:24 +0000383{
Caroline Tice7826c882010-10-26 03:11:13 +0000384 bool ret_val = false;
Greg Clayton334d33a2012-01-30 07:41:31 +0000385 StackFrameSP frame_sp(GetFrameSP());
386 if (frame_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000387 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000388 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
389 ret_val = frame_sp->GetRegisterContext()->SetPC (new_pc);
Greg Claytonbdcda462010-12-20 20:49:23 +0000390 }
Caroline Tice7826c882010-10-26 03:11:13 +0000391
Greg Clayton4e9267d2010-12-14 18:39:31 +0000392 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000393 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000394 log->Printf ("SBFrame(%p)::SetPC (new_pc=0x%llx) => %i",
Greg Clayton334d33a2012-01-30 07:41:31 +0000395 frame_sp.get(), new_pc, ret_val);
Caroline Tice7826c882010-10-26 03:11:13 +0000396
397 return ret_val;
Chris Lattner24943d22010-06-08 16:52:24 +0000398}
399
Greg Clayton4e9267d2010-12-14 18:39:31 +0000400addr_t
Chris Lattner24943d22010-06-08 16:52:24 +0000401SBFrame::GetSP () const
402{
Greg Claytona66ba462010-10-30 04:51:46 +0000403 addr_t addr = LLDB_INVALID_ADDRESS;
Greg Clayton334d33a2012-01-30 07:41:31 +0000404 StackFrameSP frame_sp(GetFrameSP());
405 if (frame_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000406 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000407 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
408 addr = frame_sp->GetRegisterContext()->GetSP();
Greg Claytonbdcda462010-12-20 20:49:23 +0000409 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000410 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000411 if (log)
Greg Clayton334d33a2012-01-30 07:41:31 +0000412 log->Printf ("SBFrame(%p)::GetSP () => 0x%llx", frame_sp.get(), addr);
Greg Claytona66ba462010-10-30 04:51:46 +0000413
414 return addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000415}
416
417
Greg Clayton4e9267d2010-12-14 18:39:31 +0000418addr_t
Chris Lattner24943d22010-06-08 16:52:24 +0000419SBFrame::GetFP () const
420{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000421 addr_t addr = LLDB_INVALID_ADDRESS;
Greg Clayton334d33a2012-01-30 07:41:31 +0000422 StackFrameSP frame_sp(GetFrameSP());
423 if (frame_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000424 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000425 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
426 addr = frame_sp->GetRegisterContext()->GetFP();
Greg Claytonbdcda462010-12-20 20:49:23 +0000427 }
Caroline Tice7826c882010-10-26 03:11:13 +0000428
Greg Clayton4e9267d2010-12-14 18:39:31 +0000429 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000430 if (log)
Greg Clayton334d33a2012-01-30 07:41:31 +0000431 log->Printf ("SBFrame(%p)::GetFP () => 0x%llx", frame_sp.get(), addr);
Caroline Tice7826c882010-10-26 03:11:13 +0000432 return addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000433}
434
435
436SBAddress
437SBFrame::GetPCAddress () const
438{
439 SBAddress sb_addr;
Greg Clayton334d33a2012-01-30 07:41:31 +0000440 StackFrameSP frame_sp(GetFrameSP());
441 if (frame_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000442 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000443 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
444 sb_addr.SetAddress (&frame_sp->GetFrameCodeAddress());
Greg Claytonbdcda462010-12-20 20:49:23 +0000445 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000446 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000447 if (log)
Greg Clayton334d33a2012-01-30 07:41:31 +0000448 log->Printf ("SBFrame(%p)::GetPCAddress () => SBAddress(%p)", frame_sp.get(), sb_addr.get());
Chris Lattner24943d22010-06-08 16:52:24 +0000449 return sb_addr;
450}
451
452void
453SBFrame::Clear()
454{
Greg Clayton63094e02010-06-23 01:19:29 +0000455 m_opaque_sp.reset();
Chris Lattner24943d22010-06-08 16:52:24 +0000456}
457
Greg Claytond62b9c12012-02-03 07:02:37 +0000458lldb::SBValue
459SBFrame::GetValueForVariablePath (const char *var_path)
460{
461 SBValue sb_value;
462 StackFrameSP frame_sp(GetFrameSP());
463 if (frame_sp)
464 {
465 lldb::DynamicValueType use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue();
466 sb_value = GetValueForVariablePath (var_path, use_dynamic);
467 }
468 return sb_value;
469}
470
471lldb::SBValue
472SBFrame::GetValueForVariablePath (const char *var_path, DynamicValueType use_dynamic)
473{
474 SBValue sb_value;
475 StackFrameSP frame_sp(GetFrameSP());
476 if (frame_sp && var_path && var_path[0])
477 {
478 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
479 VariableSP var_sp;
480 Error error;
481 ValueObjectSP value_sp (frame_sp->GetValueForVariableExpressionPath (var_path,
482 use_dynamic,
483 StackFrame::eExpressionPathOptionCheckPtrVsMember,
484 var_sp,
485 error));
486 *sb_value = value_sp;
487 }
488 return sb_value;
489}
490
Chris Lattner24943d22010-06-08 16:52:24 +0000491SBValue
Greg Clayton4e9267d2010-12-14 18:39:31 +0000492SBFrame::FindVariable (const char *name)
Chris Lattner24943d22010-06-08 16:52:24 +0000493{
Greg Clayton582ed0e2011-06-18 20:06:08 +0000494 SBValue value;
Greg Clayton334d33a2012-01-30 07:41:31 +0000495 StackFrameSP frame_sp(GetFrameSP());
496 if (frame_sp)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000497 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000498 lldb::DynamicValueType use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton582ed0e2011-06-18 20:06:08 +0000499 value = FindVariable (name, use_dynamic);
500 }
501 return value;
Jim Inghame41494a2011-04-16 00:01:13 +0000502}
Greg Claytond62b9c12012-02-03 07:02:37 +0000503
Jim Inghame41494a2011-04-16 00:01:13 +0000504
505SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000506SBFrame::FindVariable (const char *name, lldb::DynamicValueType use_dynamic)
Jim Inghame41494a2011-04-16 00:01:13 +0000507{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000508 VariableSP var_sp;
Jim Ingham47da8102011-04-22 23:53:53 +0000509 SBValue sb_value;
Greg Clayton334d33a2012-01-30 07:41:31 +0000510 StackFrameSP frame_sp(GetFrameSP());
511 if (frame_sp && name && name[0])
Chris Lattner24943d22010-06-08 16:52:24 +0000512 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000513 VariableList variable_list;
Greg Clayton334d33a2012-01-30 07:41:31 +0000514 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
515 SymbolContext sc (frame_sp->GetSymbolContext (eSymbolContextBlock));
Chris Lattner24943d22010-06-08 16:52:24 +0000516
Greg Claytondd62d722010-12-14 04:58:53 +0000517 if (sc.block)
Chris Lattner24943d22010-06-08 16:52:24 +0000518 {
Greg Claytondd62d722010-12-14 04:58:53 +0000519 const bool can_create = true;
520 const bool get_parent_variables = true;
521 const bool stop_if_block_is_inlined_function = true;
522
523 if (sc.block->AppendVariables (can_create,
524 get_parent_variables,
525 stop_if_block_is_inlined_function,
526 &variable_list))
527 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000528 var_sp = variable_list.FindVariable (ConstString(name));
Greg Claytondd62d722010-12-14 04:58:53 +0000529 }
Chris Lattner24943d22010-06-08 16:52:24 +0000530 }
Greg Clayton582ed0e2011-06-18 20:06:08 +0000531
532 if (var_sp)
Greg Clayton334d33a2012-01-30 07:41:31 +0000533 *sb_value = ValueObjectSP (frame_sp->GetValueObjectForFrameVariable(var_sp, use_dynamic));
Greg Clayton582ed0e2011-06-18 20:06:08 +0000534
Chris Lattner24943d22010-06-08 16:52:24 +0000535 }
Caroline Tice98f930f2010-09-20 05:20:02 +0000536
Greg Clayton4e9267d2010-12-14 18:39:31 +0000537 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000538 if (log)
Greg Clayton4e9267d2010-12-14 18:39:31 +0000539 log->Printf ("SBFrame(%p)::FindVariable (name=\"%s\") => SBValue(%p)",
Greg Clayton334d33a2012-01-30 07:41:31 +0000540 frame_sp.get(), name, sb_value.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000541
Chris Lattner24943d22010-06-08 16:52:24 +0000542 return sb_value;
543}
544
545SBValue
Greg Clayton4e9267d2010-12-14 18:39:31 +0000546SBFrame::FindValue (const char *name, ValueType value_type)
Chris Lattner24943d22010-06-08 16:52:24 +0000547{
Greg Clayton582ed0e2011-06-18 20:06:08 +0000548 SBValue value;
Greg Clayton334d33a2012-01-30 07:41:31 +0000549 StackFrameSP frame_sp(GetFrameSP());
550 if (frame_sp)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000551 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000552 lldb::DynamicValueType use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton582ed0e2011-06-18 20:06:08 +0000553 value = FindValue (name, value_type, use_dynamic);
554 }
555 return value;
Jim Inghame41494a2011-04-16 00:01:13 +0000556}
557
558SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000559SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueType use_dynamic)
Jim Inghame41494a2011-04-16 00:01:13 +0000560{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000561 SBValue sb_value;
Greg Clayton334d33a2012-01-30 07:41:31 +0000562 StackFrameSP frame_sp(GetFrameSP());
563 if (frame_sp && name && name[0])
Chris Lattner24943d22010-06-08 16:52:24 +0000564 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000565 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
Greg Clayton4e9267d2010-12-14 18:39:31 +0000566
567 switch (value_type)
Chris Lattner24943d22010-06-08 16:52:24 +0000568 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000569 case eValueTypeVariableGlobal: // global variable
570 case eValueTypeVariableStatic: // static variable
571 case eValueTypeVariableArgument: // function argument variables
572 case eValueTypeVariableLocal: // function local variables
Chris Lattner24943d22010-06-08 16:52:24 +0000573 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000574 VariableList *variable_list = frame_sp->GetVariableList(true);
Greg Clayton4e9267d2010-12-14 18:39:31 +0000575
Greg Clayton334d33a2012-01-30 07:41:31 +0000576 SymbolContext sc (frame_sp->GetSymbolContext (eSymbolContextBlock));
Greg Clayton4e9267d2010-12-14 18:39:31 +0000577
578 const bool can_create = true;
579 const bool get_parent_variables = true;
580 const bool stop_if_block_is_inlined_function = true;
581
582 if (sc.block && sc.block->AppendVariables (can_create,
583 get_parent_variables,
584 stop_if_block_is_inlined_function,
585 variable_list))
Johnny Chenc35750a2010-11-19 18:07:14 +0000586 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000587 ConstString const_name(name);
588 const uint32_t num_variables = variable_list->GetSize();
589 for (uint32_t i = 0; i < num_variables; ++i)
Johnny Chenc35750a2010-11-19 18:07:14 +0000590 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000591 VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
592 if (variable_sp &&
593 variable_sp->GetScope() == value_type &&
594 variable_sp->GetName() == const_name)
595 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000596 *sb_value = ValueObjectSP (frame_sp->GetValueObjectForFrameVariable(variable_sp,
Jim Inghame41494a2011-04-16 00:01:13 +0000597 use_dynamic));
Greg Clayton4e9267d2010-12-14 18:39:31 +0000598 break;
599 }
Johnny Chenc35750a2010-11-19 18:07:14 +0000600 }
601 }
Chris Lattner24943d22010-06-08 16:52:24 +0000602 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000603 break;
604
605 case eValueTypeRegister: // stack frame register value
606 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000607 RegisterContextSP reg_ctx (frame_sp->GetRegisterContext());
Greg Clayton4e9267d2010-12-14 18:39:31 +0000608 if (reg_ctx)
609 {
610 const uint32_t num_regs = reg_ctx->GetRegisterCount();
611 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx)
612 {
613 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
614 if (reg_info &&
615 ((reg_info->name && strcasecmp (reg_info->name, name) == 0) ||
616 (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0)))
617 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000618 *sb_value = ValueObjectRegister::Create (frame_sp.get(), reg_ctx, reg_idx);
Greg Clayton4e9267d2010-12-14 18:39:31 +0000619 }
620 }
621 }
622 }
623 break;
624
625 case eValueTypeRegisterSet: // A collection of stack frame register values
626 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000627 RegisterContextSP reg_ctx (frame_sp->GetRegisterContext());
Greg Clayton4e9267d2010-12-14 18:39:31 +0000628 if (reg_ctx)
629 {
630 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
631 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
632 {
633 const RegisterSet *reg_set = reg_ctx->GetRegisterSet (set_idx);
634 if (reg_set &&
635 ((reg_set->name && strcasecmp (reg_set->name, name) == 0) ||
636 (reg_set->short_name && strcasecmp (reg_set->short_name, name) == 0)))
637 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000638 *sb_value = ValueObjectRegisterSet::Create (frame_sp.get(), reg_ctx, set_idx);
Greg Clayton4e9267d2010-12-14 18:39:31 +0000639 }
640 }
641 }
642 }
643 break;
644
645 case eValueTypeConstResult: // constant result variables
646 {
647 ConstString const_name(name);
Greg Clayton334d33a2012-01-30 07:41:31 +0000648 ClangExpressionVariableSP expr_var_sp (frame_sp->GetThread().GetProcess().GetTarget().GetPersistentVariables().GetVariable (const_name));
Greg Clayton4e9267d2010-12-14 18:39:31 +0000649 if (expr_var_sp)
650 *sb_value = expr_var_sp->GetValueObject();
651 }
652 break;
653
654 default:
655 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000656 }
657 }
Caroline Tice98f930f2010-09-20 05:20:02 +0000658
Greg Clayton4e9267d2010-12-14 18:39:31 +0000659 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000660 if (log)
Greg Clayton4e9267d2010-12-14 18:39:31 +0000661 log->Printf ("SBFrame(%p)::FindVariableInScope (name=\"%s\", value_type=%i) => SBValue(%p)",
Greg Clayton334d33a2012-01-30 07:41:31 +0000662 frame_sp.get(), name, value_type, sb_value.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000663
664
Chris Lattner24943d22010-06-08 16:52:24 +0000665 return sb_value;
666}
667
668bool
669SBFrame::operator == (const SBFrame &rhs) const
670{
Greg Clayton334d33a2012-01-30 07:41:31 +0000671 return GetFrameSP().get() == rhs.GetFrameSP().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000672}
673
674bool
675SBFrame::operator != (const SBFrame &rhs) const
676{
Greg Clayton334d33a2012-01-30 07:41:31 +0000677 return GetFrameSP().get() != rhs.GetFrameSP().get();
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000678}
Chris Lattner24943d22010-06-08 16:52:24 +0000679
680SBThread
681SBFrame::GetThread () const
682{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000683 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000684
Greg Claytondd62d722010-12-14 04:58:53 +0000685 SBThread sb_thread;
Greg Clayton90c52142012-01-30 02:53:15 +0000686 ThreadSP thread_sp;
Greg Clayton334d33a2012-01-30 07:41:31 +0000687 StackFrameSP frame_sp(GetFrameSP());
688 if (frame_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000689 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000690 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
691 thread_sp = frame_sp->GetThread().shared_from_this();
Greg Clayton90c52142012-01-30 02:53:15 +0000692 sb_thread.SetThread (thread_sp);
Greg Claytonbdcda462010-12-20 20:49:23 +0000693 }
Caroline Tice7826c882010-10-26 03:11:13 +0000694
695 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000696 {
697 SBStream sstr;
698 sb_thread.GetDescription (sstr);
Greg Clayton334d33a2012-01-30 07:41:31 +0000699 log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s", frame_sp.get(),
Greg Clayton90c52142012-01-30 02:53:15 +0000700 thread_sp.get(), sstr.GetData());
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000701 }
Caroline Tice7826c882010-10-26 03:11:13 +0000702
Chris Lattner24943d22010-06-08 16:52:24 +0000703 return sb_thread;
704}
705
706const char *
707SBFrame::Disassemble () const
708{
Greg Claytona66ba462010-10-30 04:51:46 +0000709 const char *disassembly = NULL;
Greg Clayton334d33a2012-01-30 07:41:31 +0000710 StackFrameSP frame_sp(GetFrameSP());
711 if (frame_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000712 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000713 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
714 disassembly = frame_sp->Disassemble();
Greg Claytonbdcda462010-12-20 20:49:23 +0000715 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000716 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000717
718 if (log)
Greg Clayton334d33a2012-01-30 07:41:31 +0000719 log->Printf ("SBFrame(%p)::Disassemble () => %s", frame_sp.get(), disassembly);
Greg Claytona66ba462010-10-30 04:51:46 +0000720
721 return disassembly;
Chris Lattner24943d22010-06-08 16:52:24 +0000722}
723
724
Chris Lattner24943d22010-06-08 16:52:24 +0000725SBValueList
726SBFrame::GetVariables (bool arguments,
727 bool locals,
728 bool statics,
729 bool in_scope_only)
730{
Greg Clayton582ed0e2011-06-18 20:06:08 +0000731 SBValueList value_list;
Greg Clayton334d33a2012-01-30 07:41:31 +0000732 StackFrameSP frame_sp(GetFrameSP());
733 if (frame_sp)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000734 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000735 lldb::DynamicValueType use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton582ed0e2011-06-18 20:06:08 +0000736 value_list = GetVariables (arguments, locals, statics, in_scope_only, use_dynamic);
737 }
738 return value_list;
Jim Inghame41494a2011-04-16 00:01:13 +0000739}
740
741SBValueList
742SBFrame::GetVariables (bool arguments,
743 bool locals,
744 bool statics,
745 bool in_scope_only,
Jim Ingham10de7d12011-05-04 03:43:18 +0000746 lldb::DynamicValueType use_dynamic)
Jim Inghame41494a2011-04-16 00:01:13 +0000747{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000748 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000749
Greg Clayton334d33a2012-01-30 07:41:31 +0000750 SBValueList value_list;
751 StackFrameSP frame_sp(GetFrameSP());
752
Caroline Tice7826c882010-10-26 03:11:13 +0000753 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000754 log->Printf ("SBFrame(%p)::GetVariables (arguments=%i, locals=%i, statics=%i, in_scope_only=%i)",
Greg Clayton334d33a2012-01-30 07:41:31 +0000755 frame_sp.get(),
Greg Claytona66ba462010-10-30 04:51:46 +0000756 arguments,
757 locals,
758 statics,
759 in_scope_only);
Greg Clayton334d33a2012-01-30 07:41:31 +0000760
761 if (frame_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000762 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000763
Chris Lattner24943d22010-06-08 16:52:24 +0000764 size_t i;
Greg Claytonbdcda462010-12-20 20:49:23 +0000765 VariableList *variable_list = NULL;
766 // Scope for locker
767 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000768 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
769 variable_list = frame_sp->GetVariableList(true);
Greg Claytonbdcda462010-12-20 20:49:23 +0000770 }
Chris Lattner24943d22010-06-08 16:52:24 +0000771 if (variable_list)
772 {
773 const size_t num_variables = variable_list->GetSize();
774 if (num_variables)
775 {
776 for (i = 0; i < num_variables; ++i)
777 {
778 VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
779 if (variable_sp)
780 {
781 bool add_variable = false;
782 switch (variable_sp->GetScope())
783 {
784 case eValueTypeVariableGlobal:
785 case eValueTypeVariableStatic:
786 add_variable = statics;
787 break;
788
789 case eValueTypeVariableArgument:
790 add_variable = arguments;
791 break;
792
793 case eValueTypeVariableLocal:
794 add_variable = locals;
795 break;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000796
797 default:
798 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000799 }
800 if (add_variable)
801 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000802 if (in_scope_only && !variable_sp->IsInScope(frame_sp.get()))
Chris Lattner24943d22010-06-08 16:52:24 +0000803 continue;
804
Greg Clayton334d33a2012-01-30 07:41:31 +0000805 value_list.Append(frame_sp->GetValueObjectForFrameVariable (variable_sp, use_dynamic));
Chris Lattner24943d22010-06-08 16:52:24 +0000806 }
807 }
808 }
809 }
Greg Clayton17dae082010-09-02 02:59:18 +0000810 }
Chris Lattner24943d22010-06-08 16:52:24 +0000811 }
Caroline Tice7826c882010-10-26 03:11:13 +0000812
813 if (log)
814 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000815 log->Printf ("SBFrame(%p)::GetVariables (...) => SBValueList(%p)", frame_sp.get(),
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000816 value_list.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000817 }
818
Chris Lattner24943d22010-06-08 16:52:24 +0000819 return value_list;
820}
821
Greg Clayton4e9267d2010-12-14 18:39:31 +0000822SBValueList
Chris Lattner24943d22010-06-08 16:52:24 +0000823SBFrame::GetRegisters ()
824{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000825 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000826
Chris Lattner24943d22010-06-08 16:52:24 +0000827 SBValueList value_list;
Greg Clayton334d33a2012-01-30 07:41:31 +0000828 StackFrameSP frame_sp(GetFrameSP());
829 if (frame_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000830 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000831 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
832 RegisterContextSP reg_ctx (frame_sp->GetRegisterContext());
Chris Lattner24943d22010-06-08 16:52:24 +0000833 if (reg_ctx)
834 {
835 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
836 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
837 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000838 value_list.Append(ValueObjectRegisterSet::Create (frame_sp.get(), reg_ctx, set_idx));
Chris Lattner24943d22010-06-08 16:52:24 +0000839 }
840 }
841 }
Caroline Tice7826c882010-10-26 03:11:13 +0000842
843 if (log)
Greg Clayton334d33a2012-01-30 07:41:31 +0000844 log->Printf ("SBFrame(%p)::Registers () => SBValueList(%p)", frame_sp.get(), value_list.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000845
Chris Lattner24943d22010-06-08 16:52:24 +0000846 return value_list;
847}
848
Caroline Tice98f930f2010-09-20 05:20:02 +0000849bool
850SBFrame::GetDescription (SBStream &description)
851{
Greg Clayton96154be2011-11-13 06:57:31 +0000852 Stream &strm = description.ref();
853
Greg Clayton334d33a2012-01-30 07:41:31 +0000854 StackFrameSP frame_sp(GetFrameSP());
855 if (frame_sp)
Caroline Tice98f930f2010-09-20 05:20:02 +0000856 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000857 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
858 frame_sp->DumpUsingSettingsFormat (&strm);
Caroline Tice98f930f2010-09-20 05:20:02 +0000859 }
860 else
Greg Clayton96154be2011-11-13 06:57:31 +0000861 strm.PutCString ("No value");
Caroline Tice98f930f2010-09-20 05:20:02 +0000862
863 return true;
864}
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000865
Greg Clayton4e9267d2010-12-14 18:39:31 +0000866SBValue
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000867SBFrame::EvaluateExpression (const char *expr)
868{
Greg Clayton582ed0e2011-06-18 20:06:08 +0000869 SBValue result;
Greg Clayton334d33a2012-01-30 07:41:31 +0000870 StackFrameSP frame_sp(GetFrameSP());
871 if (frame_sp)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000872 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000873 lldb::DynamicValueType use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton582ed0e2011-06-18 20:06:08 +0000874 result = EvaluateExpression (expr, use_dynamic);
875 }
876 return result;
Jim Inghame41494a2011-04-16 00:01:13 +0000877}
878
879SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000880SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value)
Jim Inghame41494a2011-04-16 00:01:13 +0000881{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000882 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Sean Callanan94d255f2010-12-07 22:55:01 +0000883
Greg Clayton4e9267d2010-12-14 18:39:31 +0000884 LogSP expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Greg Claytona66ba462010-10-30 04:51:46 +0000885
Johnny Chenee6e7902011-08-10 22:06:24 +0000886 ExecutionResults exe_results;
Greg Clayton4e9267d2010-12-14 18:39:31 +0000887 SBValue expr_result;
Greg Claytona66ba462010-10-30 04:51:46 +0000888
Greg Clayton334d33a2012-01-30 07:41:31 +0000889 StackFrameSP frame_sp(GetFrameSP());
890 if (log)
891 log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\")...", frame_sp.get(), expr);
892
893 if (frame_sp)
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000894 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000895 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
Greg Clayton582ed0e2011-06-18 20:06:08 +0000896
Greg Clayton87ac9022011-06-25 04:35:01 +0000897
898 StreamString frame_description;
Greg Clayton334d33a2012-01-30 07:41:31 +0000899 frame_sp->DumpUsingSettingsFormat (&frame_description);
Greg Clayton87ac9022011-06-25 04:35:01 +0000900
901 Host::SetCrashDescriptionWithFormat ("SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
902 expr, fetch_dynamic_value, frame_description.GetString().c_str());
903
Sean Callanandaa6efe2011-12-21 22:22:58 +0000904 const bool coerce_to_id = false;
Greg Clayton427f2902010-12-14 02:59:59 +0000905 const bool unwind_on_error = true;
Sean Callanan6a925532011-01-13 08:53:35 +0000906 const bool keep_in_memory = false;
Greg Clayton427f2902010-12-14 02:59:59 +0000907
Greg Clayton334d33a2012-01-30 07:41:31 +0000908 exe_results = frame_sp->GetThread().GetProcess().GetTarget().EvaluateExpression(expr,
909 frame_sp.get(),
910 eExecutionPolicyOnlyWhenNeeded,
911 coerce_to_id,
912 unwind_on_error,
913 keep_in_memory,
914 fetch_dynamic_value,
915 *expr_result);
Greg Clayton668a6c72011-11-10 18:31:53 +0000916
917 Host::SetCrashDescription (NULL);
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000918 }
Greg Claytona66ba462010-10-30 04:51:46 +0000919
Sean Callanan94d255f2010-12-07 22:55:01 +0000920 if (expr_log)
Jim Inghame41494a2011-04-16 00:01:13 +0000921 expr_log->Printf("** [SBFrame::EvaluateExpression] Expression result is %s, summary %s **",
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000922 expr_result.GetValue(),
923 expr_result.GetSummary());
Sean Callanan94d255f2010-12-07 22:55:01 +0000924
Greg Claytona66ba462010-10-30 04:51:46 +0000925 if (log)
Greg Clayton334d33a2012-01-30 07:41:31 +0000926 log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)", frame_sp.get(),
Jim Inghame41494a2011-04-16 00:01:13 +0000927 expr,
Johnny Chenee6e7902011-08-10 22:06:24 +0000928 expr_result.get(),
929 exe_results);
Greg Claytona66ba462010-10-30 04:51:46 +0000930
Greg Clayton49ce6822010-10-31 03:01:06 +0000931 return expr_result;
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000932}
Greg Clayton582ed0e2011-06-18 20:06:08 +0000933
934bool
935SBFrame::IsInlined()
936{
Greg Clayton334d33a2012-01-30 07:41:31 +0000937 StackFrameSP frame_sp(GetFrameSP());
938 if (frame_sp)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000939 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000940 Block *block = frame_sp->GetSymbolContext(eSymbolContextBlock).block;
Greg Clayton582ed0e2011-06-18 20:06:08 +0000941 if (block)
942 return block->GetContainingInlinedBlock () != NULL;
943 }
944 return false;
945}
946
947const char *
948SBFrame::GetFunctionName()
949{
950 const char *name = NULL;
Greg Clayton334d33a2012-01-30 07:41:31 +0000951 StackFrameSP frame_sp(GetFrameSP());
952 if (frame_sp)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000953 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000954 SymbolContext sc (frame_sp->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol));
Greg Clayton582ed0e2011-06-18 20:06:08 +0000955 if (sc.block)
956 {
957 Block *inlined_block = sc.block->GetContainingInlinedBlock ();
958 if (inlined_block)
959 {
960 const InlineFunctionInfo* inlined_info = inlined_block->GetInlinedFunctionInfo();
961 name = inlined_info->GetName().AsCString();
962 }
963 }
964
965 if (name == NULL)
966 {
967 if (sc.function)
968 name = sc.function->GetName().GetCString();
969 }
970
971 if (name == NULL)
972 {
973 if (sc.symbol)
974 name = sc.symbol->GetName().GetCString();
975 }
976 }
977 return name;
978}
979