blob: ce57c83520dd3bf178be914b4da7025693a3ede6 [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));
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000486 sb_value.SetSP(value_sp);
Greg Claytond62b9c12012-02-03 07:02:37 +0000487 }
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 Clayton0a19a1b2012-02-04 02:27:34 +0000510 ValueObjectSP value_sp;
Greg Clayton334d33a2012-01-30 07:41:31 +0000511 StackFrameSP frame_sp(GetFrameSP());
512 if (frame_sp && name && name[0])
Chris Lattner24943d22010-06-08 16:52:24 +0000513 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000514 VariableList variable_list;
Greg Clayton334d33a2012-01-30 07:41:31 +0000515 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
516 SymbolContext sc (frame_sp->GetSymbolContext (eSymbolContextBlock));
Chris Lattner24943d22010-06-08 16:52:24 +0000517
Greg Claytondd62d722010-12-14 04:58:53 +0000518 if (sc.block)
Chris Lattner24943d22010-06-08 16:52:24 +0000519 {
Greg Claytondd62d722010-12-14 04:58:53 +0000520 const bool can_create = true;
521 const bool get_parent_variables = true;
522 const bool stop_if_block_is_inlined_function = true;
523
524 if (sc.block->AppendVariables (can_create,
525 get_parent_variables,
526 stop_if_block_is_inlined_function,
527 &variable_list))
528 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000529 var_sp = variable_list.FindVariable (ConstString(name));
Greg Claytondd62d722010-12-14 04:58:53 +0000530 }
Chris Lattner24943d22010-06-08 16:52:24 +0000531 }
Greg Clayton582ed0e2011-06-18 20:06:08 +0000532
533 if (var_sp)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000534 {
535 value_sp = frame_sp->GetValueObjectForFrameVariable(var_sp, use_dynamic);
536 sb_value.SetSP(value_sp);
537 }
Greg Clayton582ed0e2011-06-18 20:06:08 +0000538
Chris Lattner24943d22010-06-08 16:52:24 +0000539 }
Caroline Tice98f930f2010-09-20 05:20:02 +0000540
Greg Clayton4e9267d2010-12-14 18:39:31 +0000541 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000542 if (log)
Greg Clayton4e9267d2010-12-14 18:39:31 +0000543 log->Printf ("SBFrame(%p)::FindVariable (name=\"%s\") => SBValue(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000544 frame_sp.get(), name, value_sp.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000545
Chris Lattner24943d22010-06-08 16:52:24 +0000546 return sb_value;
547}
548
549SBValue
Greg Clayton4e9267d2010-12-14 18:39:31 +0000550SBFrame::FindValue (const char *name, ValueType value_type)
Chris Lattner24943d22010-06-08 16:52:24 +0000551{
Greg Clayton582ed0e2011-06-18 20:06:08 +0000552 SBValue value;
Greg Clayton334d33a2012-01-30 07:41:31 +0000553 StackFrameSP frame_sp(GetFrameSP());
554 if (frame_sp)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000555 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000556 lldb::DynamicValueType use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton582ed0e2011-06-18 20:06:08 +0000557 value = FindValue (name, value_type, use_dynamic);
558 }
559 return value;
Jim Inghame41494a2011-04-16 00:01:13 +0000560}
561
562SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000563SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueType use_dynamic)
Jim Inghame41494a2011-04-16 00:01:13 +0000564{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000565 SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000566 ValueObjectSP value_sp;
Greg Clayton334d33a2012-01-30 07:41:31 +0000567 StackFrameSP frame_sp(GetFrameSP());
568 if (frame_sp && name && name[0])
Chris Lattner24943d22010-06-08 16:52:24 +0000569 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000570 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
Greg Clayton4e9267d2010-12-14 18:39:31 +0000571
572 switch (value_type)
Chris Lattner24943d22010-06-08 16:52:24 +0000573 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000574 case eValueTypeVariableGlobal: // global variable
575 case eValueTypeVariableStatic: // static variable
576 case eValueTypeVariableArgument: // function argument variables
577 case eValueTypeVariableLocal: // function local variables
Chris Lattner24943d22010-06-08 16:52:24 +0000578 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000579 VariableList *variable_list = frame_sp->GetVariableList(true);
Greg Clayton4e9267d2010-12-14 18:39:31 +0000580
Greg Clayton334d33a2012-01-30 07:41:31 +0000581 SymbolContext sc (frame_sp->GetSymbolContext (eSymbolContextBlock));
Greg Clayton4e9267d2010-12-14 18:39:31 +0000582
583 const bool can_create = true;
584 const bool get_parent_variables = true;
585 const bool stop_if_block_is_inlined_function = true;
586
587 if (sc.block && sc.block->AppendVariables (can_create,
588 get_parent_variables,
589 stop_if_block_is_inlined_function,
590 variable_list))
Johnny Chenc35750a2010-11-19 18:07:14 +0000591 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000592 ConstString const_name(name);
593 const uint32_t num_variables = variable_list->GetSize();
594 for (uint32_t i = 0; i < num_variables; ++i)
Johnny Chenc35750a2010-11-19 18:07:14 +0000595 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000596 VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
597 if (variable_sp &&
598 variable_sp->GetScope() == value_type &&
599 variable_sp->GetName() == const_name)
600 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000601 value_sp = frame_sp->GetValueObjectForFrameVariable (variable_sp, use_dynamic);
602 sb_value.SetSP (value_sp);
Greg Clayton4e9267d2010-12-14 18:39:31 +0000603 break;
604 }
Johnny Chenc35750a2010-11-19 18:07:14 +0000605 }
606 }
Chris Lattner24943d22010-06-08 16:52:24 +0000607 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000608 break;
609
610 case eValueTypeRegister: // stack frame register value
611 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000612 RegisterContextSP reg_ctx (frame_sp->GetRegisterContext());
Greg Clayton4e9267d2010-12-14 18:39:31 +0000613 if (reg_ctx)
614 {
615 const uint32_t num_regs = reg_ctx->GetRegisterCount();
616 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx)
617 {
618 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
619 if (reg_info &&
620 ((reg_info->name && strcasecmp (reg_info->name, name) == 0) ||
621 (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0)))
622 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000623 value_sp = ValueObjectRegister::Create (frame_sp.get(), reg_ctx, reg_idx);
624 sb_value.SetSP (value_sp);
625 break;
Greg Clayton4e9267d2010-12-14 18:39:31 +0000626 }
627 }
628 }
629 }
630 break;
631
632 case eValueTypeRegisterSet: // A collection of stack frame register values
633 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000634 RegisterContextSP reg_ctx (frame_sp->GetRegisterContext());
Greg Clayton4e9267d2010-12-14 18:39:31 +0000635 if (reg_ctx)
636 {
637 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
638 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
639 {
640 const RegisterSet *reg_set = reg_ctx->GetRegisterSet (set_idx);
641 if (reg_set &&
642 ((reg_set->name && strcasecmp (reg_set->name, name) == 0) ||
643 (reg_set->short_name && strcasecmp (reg_set->short_name, name) == 0)))
644 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000645 value_sp = ValueObjectRegisterSet::Create (frame_sp.get(), reg_ctx, set_idx);
646 sb_value.SetSP (value_sp);
647 break;
Greg Clayton4e9267d2010-12-14 18:39:31 +0000648 }
649 }
650 }
651 }
652 break;
653
654 case eValueTypeConstResult: // constant result variables
655 {
656 ConstString const_name(name);
Greg Clayton334d33a2012-01-30 07:41:31 +0000657 ClangExpressionVariableSP expr_var_sp (frame_sp->GetThread().GetProcess().GetTarget().GetPersistentVariables().GetVariable (const_name));
Greg Clayton4e9267d2010-12-14 18:39:31 +0000658 if (expr_var_sp)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000659 {
660 value_sp = expr_var_sp->GetValueObject();
661 sb_value.SetSP (value_sp);
662 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000663 }
664 break;
665
666 default:
667 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000668 }
669 }
Caroline Tice98f930f2010-09-20 05:20:02 +0000670
Greg Clayton4e9267d2010-12-14 18:39:31 +0000671 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000672 if (log)
Greg Clayton4e9267d2010-12-14 18:39:31 +0000673 log->Printf ("SBFrame(%p)::FindVariableInScope (name=\"%s\", value_type=%i) => SBValue(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000674 frame_sp.get(), name, value_type, value_sp.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000675
676
Chris Lattner24943d22010-06-08 16:52:24 +0000677 return sb_value;
678}
679
680bool
681SBFrame::operator == (const SBFrame &rhs) const
682{
Greg Clayton334d33a2012-01-30 07:41:31 +0000683 return GetFrameSP().get() == rhs.GetFrameSP().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000684}
685
686bool
687SBFrame::operator != (const SBFrame &rhs) const
688{
Greg Clayton334d33a2012-01-30 07:41:31 +0000689 return GetFrameSP().get() != rhs.GetFrameSP().get();
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000690}
Chris Lattner24943d22010-06-08 16:52:24 +0000691
692SBThread
693SBFrame::GetThread () const
694{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000695 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000696
Greg Claytondd62d722010-12-14 04:58:53 +0000697 SBThread sb_thread;
Greg Clayton90c52142012-01-30 02:53:15 +0000698 ThreadSP thread_sp;
Greg Clayton334d33a2012-01-30 07:41:31 +0000699 StackFrameSP frame_sp(GetFrameSP());
700 if (frame_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000701 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000702 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
703 thread_sp = frame_sp->GetThread().shared_from_this();
Greg Clayton90c52142012-01-30 02:53:15 +0000704 sb_thread.SetThread (thread_sp);
Greg Claytonbdcda462010-12-20 20:49:23 +0000705 }
Caroline Tice7826c882010-10-26 03:11:13 +0000706
707 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000708 {
709 SBStream sstr;
710 sb_thread.GetDescription (sstr);
Greg Clayton334d33a2012-01-30 07:41:31 +0000711 log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s", frame_sp.get(),
Greg Clayton90c52142012-01-30 02:53:15 +0000712 thread_sp.get(), sstr.GetData());
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000713 }
Caroline Tice7826c882010-10-26 03:11:13 +0000714
Chris Lattner24943d22010-06-08 16:52:24 +0000715 return sb_thread;
716}
717
718const char *
719SBFrame::Disassemble () const
720{
Greg Claytona66ba462010-10-30 04:51:46 +0000721 const char *disassembly = NULL;
Greg Clayton334d33a2012-01-30 07:41:31 +0000722 StackFrameSP frame_sp(GetFrameSP());
723 if (frame_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000724 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000725 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
726 disassembly = frame_sp->Disassemble();
Greg Claytonbdcda462010-12-20 20:49:23 +0000727 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000728 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000729
730 if (log)
Greg Clayton334d33a2012-01-30 07:41:31 +0000731 log->Printf ("SBFrame(%p)::Disassemble () => %s", frame_sp.get(), disassembly);
Greg Claytona66ba462010-10-30 04:51:46 +0000732
733 return disassembly;
Chris Lattner24943d22010-06-08 16:52:24 +0000734}
735
736
Chris Lattner24943d22010-06-08 16:52:24 +0000737SBValueList
738SBFrame::GetVariables (bool arguments,
739 bool locals,
740 bool statics,
741 bool in_scope_only)
742{
Greg Clayton582ed0e2011-06-18 20:06:08 +0000743 SBValueList value_list;
Greg Clayton334d33a2012-01-30 07:41:31 +0000744 StackFrameSP frame_sp(GetFrameSP());
745 if (frame_sp)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000746 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000747 lldb::DynamicValueType use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton582ed0e2011-06-18 20:06:08 +0000748 value_list = GetVariables (arguments, locals, statics, in_scope_only, use_dynamic);
749 }
750 return value_list;
Jim Inghame41494a2011-04-16 00:01:13 +0000751}
752
753SBValueList
754SBFrame::GetVariables (bool arguments,
755 bool locals,
756 bool statics,
757 bool in_scope_only,
Jim Ingham10de7d12011-05-04 03:43:18 +0000758 lldb::DynamicValueType use_dynamic)
Jim Inghame41494a2011-04-16 00:01:13 +0000759{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000760 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000761
Greg Clayton334d33a2012-01-30 07:41:31 +0000762 SBValueList value_list;
763 StackFrameSP frame_sp(GetFrameSP());
764
Caroline Tice7826c882010-10-26 03:11:13 +0000765 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000766 log->Printf ("SBFrame(%p)::GetVariables (arguments=%i, locals=%i, statics=%i, in_scope_only=%i)",
Greg Clayton334d33a2012-01-30 07:41:31 +0000767 frame_sp.get(),
Greg Claytona66ba462010-10-30 04:51:46 +0000768 arguments,
769 locals,
770 statics,
771 in_scope_only);
Greg Clayton334d33a2012-01-30 07:41:31 +0000772
773 if (frame_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000774 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000775
Chris Lattner24943d22010-06-08 16:52:24 +0000776 size_t i;
Greg Claytonbdcda462010-12-20 20:49:23 +0000777 VariableList *variable_list = NULL;
778 // Scope for locker
779 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000780 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
781 variable_list = frame_sp->GetVariableList(true);
Greg Claytonbdcda462010-12-20 20:49:23 +0000782 }
Chris Lattner24943d22010-06-08 16:52:24 +0000783 if (variable_list)
784 {
785 const size_t num_variables = variable_list->GetSize();
786 if (num_variables)
787 {
788 for (i = 0; i < num_variables; ++i)
789 {
790 VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
791 if (variable_sp)
792 {
793 bool add_variable = false;
794 switch (variable_sp->GetScope())
795 {
796 case eValueTypeVariableGlobal:
797 case eValueTypeVariableStatic:
798 add_variable = statics;
799 break;
800
801 case eValueTypeVariableArgument:
802 add_variable = arguments;
803 break;
804
805 case eValueTypeVariableLocal:
806 add_variable = locals;
807 break;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000808
809 default:
810 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000811 }
812 if (add_variable)
813 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000814 if (in_scope_only && !variable_sp->IsInScope(frame_sp.get()))
Chris Lattner24943d22010-06-08 16:52:24 +0000815 continue;
816
Greg Clayton334d33a2012-01-30 07:41:31 +0000817 value_list.Append(frame_sp->GetValueObjectForFrameVariable (variable_sp, use_dynamic));
Chris Lattner24943d22010-06-08 16:52:24 +0000818 }
819 }
820 }
821 }
Greg Clayton17dae082010-09-02 02:59:18 +0000822 }
Chris Lattner24943d22010-06-08 16:52:24 +0000823 }
Caroline Tice7826c882010-10-26 03:11:13 +0000824
825 if (log)
826 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000827 log->Printf ("SBFrame(%p)::GetVariables (...) => SBValueList(%p)", frame_sp.get(),
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000828 value_list.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000829 }
830
Chris Lattner24943d22010-06-08 16:52:24 +0000831 return value_list;
832}
833
Greg Clayton4e9267d2010-12-14 18:39:31 +0000834SBValueList
Chris Lattner24943d22010-06-08 16:52:24 +0000835SBFrame::GetRegisters ()
836{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000837 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000838
Chris Lattner24943d22010-06-08 16:52:24 +0000839 SBValueList value_list;
Greg Clayton334d33a2012-01-30 07:41:31 +0000840 StackFrameSP frame_sp(GetFrameSP());
841 if (frame_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000842 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000843 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
844 RegisterContextSP reg_ctx (frame_sp->GetRegisterContext());
Chris Lattner24943d22010-06-08 16:52:24 +0000845 if (reg_ctx)
846 {
847 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
848 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
849 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000850 value_list.Append(ValueObjectRegisterSet::Create (frame_sp.get(), reg_ctx, set_idx));
Chris Lattner24943d22010-06-08 16:52:24 +0000851 }
852 }
853 }
Caroline Tice7826c882010-10-26 03:11:13 +0000854
855 if (log)
Greg Clayton334d33a2012-01-30 07:41:31 +0000856 log->Printf ("SBFrame(%p)::Registers () => SBValueList(%p)", frame_sp.get(), value_list.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000857
Chris Lattner24943d22010-06-08 16:52:24 +0000858 return value_list;
859}
860
Caroline Tice98f930f2010-09-20 05:20:02 +0000861bool
862SBFrame::GetDescription (SBStream &description)
863{
Greg Clayton96154be2011-11-13 06:57:31 +0000864 Stream &strm = description.ref();
865
Greg Clayton334d33a2012-01-30 07:41:31 +0000866 StackFrameSP frame_sp(GetFrameSP());
867 if (frame_sp)
Caroline Tice98f930f2010-09-20 05:20:02 +0000868 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000869 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
870 frame_sp->DumpUsingSettingsFormat (&strm);
Caroline Tice98f930f2010-09-20 05:20:02 +0000871 }
872 else
Greg Clayton96154be2011-11-13 06:57:31 +0000873 strm.PutCString ("No value");
Caroline Tice98f930f2010-09-20 05:20:02 +0000874
875 return true;
876}
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000877
Greg Clayton4e9267d2010-12-14 18:39:31 +0000878SBValue
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000879SBFrame::EvaluateExpression (const char *expr)
880{
Greg Clayton582ed0e2011-06-18 20:06:08 +0000881 SBValue result;
Greg Clayton334d33a2012-01-30 07:41:31 +0000882 StackFrameSP frame_sp(GetFrameSP());
883 if (frame_sp)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000884 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000885 lldb::DynamicValueType use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton582ed0e2011-06-18 20:06:08 +0000886 result = EvaluateExpression (expr, use_dynamic);
887 }
888 return result;
Jim Inghame41494a2011-04-16 00:01:13 +0000889}
890
891SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000892SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value)
Jim Inghame41494a2011-04-16 00:01:13 +0000893{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000894 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Sean Callanan94d255f2010-12-07 22:55:01 +0000895
Greg Clayton4e9267d2010-12-14 18:39:31 +0000896 LogSP expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Greg Claytona66ba462010-10-30 04:51:46 +0000897
Johnny Chenee6e7902011-08-10 22:06:24 +0000898 ExecutionResults exe_results;
Greg Clayton4e9267d2010-12-14 18:39:31 +0000899 SBValue expr_result;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000900 ValueObjectSP expr_value_sp;
Greg Claytona66ba462010-10-30 04:51:46 +0000901
Greg Clayton334d33a2012-01-30 07:41:31 +0000902 StackFrameSP frame_sp(GetFrameSP());
903 if (log)
904 log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\")...", frame_sp.get(), expr);
905
906 if (frame_sp)
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000907 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000908 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
Greg Clayton582ed0e2011-06-18 20:06:08 +0000909
Greg Clayton87ac9022011-06-25 04:35:01 +0000910
911 StreamString frame_description;
Greg Clayton334d33a2012-01-30 07:41:31 +0000912 frame_sp->DumpUsingSettingsFormat (&frame_description);
Greg Clayton87ac9022011-06-25 04:35:01 +0000913
914 Host::SetCrashDescriptionWithFormat ("SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
915 expr, fetch_dynamic_value, frame_description.GetString().c_str());
916
Sean Callanandaa6efe2011-12-21 22:22:58 +0000917 const bool coerce_to_id = false;
Greg Clayton427f2902010-12-14 02:59:59 +0000918 const bool unwind_on_error = true;
Sean Callanan6a925532011-01-13 08:53:35 +0000919 const bool keep_in_memory = false;
Greg Clayton427f2902010-12-14 02:59:59 +0000920
Greg Clayton334d33a2012-01-30 07:41:31 +0000921 exe_results = frame_sp->GetThread().GetProcess().GetTarget().EvaluateExpression(expr,
922 frame_sp.get(),
923 eExecutionPolicyOnlyWhenNeeded,
924 coerce_to_id,
925 unwind_on_error,
926 keep_in_memory,
927 fetch_dynamic_value,
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000928 expr_value_sp);
929 expr_result.SetSP(expr_value_sp);
Greg Clayton668a6c72011-11-10 18:31:53 +0000930 Host::SetCrashDescription (NULL);
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000931 }
Greg Claytona66ba462010-10-30 04:51:46 +0000932
Sean Callanan94d255f2010-12-07 22:55:01 +0000933 if (expr_log)
Jim Inghame41494a2011-04-16 00:01:13 +0000934 expr_log->Printf("** [SBFrame::EvaluateExpression] Expression result is %s, summary %s **",
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000935 expr_result.GetValue(),
936 expr_result.GetSummary());
Sean Callanan94d255f2010-12-07 22:55:01 +0000937
Greg Claytona66ba462010-10-30 04:51:46 +0000938 if (log)
Greg Clayton334d33a2012-01-30 07:41:31 +0000939 log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)", frame_sp.get(),
Jim Inghame41494a2011-04-16 00:01:13 +0000940 expr,
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000941 expr_value_sp.get(),
Johnny Chenee6e7902011-08-10 22:06:24 +0000942 exe_results);
Greg Claytona66ba462010-10-30 04:51:46 +0000943
Greg Clayton49ce6822010-10-31 03:01:06 +0000944 return expr_result;
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000945}
Greg Clayton582ed0e2011-06-18 20:06:08 +0000946
947bool
948SBFrame::IsInlined()
949{
Greg Clayton334d33a2012-01-30 07:41:31 +0000950 StackFrameSP frame_sp(GetFrameSP());
951 if (frame_sp)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000952 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000953 Block *block = frame_sp->GetSymbolContext(eSymbolContextBlock).block;
Greg Clayton582ed0e2011-06-18 20:06:08 +0000954 if (block)
955 return block->GetContainingInlinedBlock () != NULL;
956 }
957 return false;
958}
959
960const char *
961SBFrame::GetFunctionName()
962{
963 const char *name = NULL;
Greg Clayton334d33a2012-01-30 07:41:31 +0000964 StackFrameSP frame_sp(GetFrameSP());
965 if (frame_sp)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000966 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000967 SymbolContext sc (frame_sp->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol));
Greg Clayton582ed0e2011-06-18 20:06:08 +0000968 if (sc.block)
969 {
970 Block *inlined_block = sc.block->GetContainingInlinedBlock ();
971 if (inlined_block)
972 {
973 const InlineFunctionInfo* inlined_info = inlined_block->GetInlinedFunctionInfo();
974 name = inlined_info->GetName().AsCString();
975 }
976 }
977
978 if (name == NULL)
979 {
980 if (sc.function)
981 name = sc.function->GetName().GetCString();
982 }
983
984 if (name == NULL)
985 {
986 if (sc.symbol)
987 name = sc.symbol->GetName().GetCString();
988 }
989 }
990 return name;
991}
992