blob: a1bb7062ce46e82ed9302ad5ffc0cfede955b911 [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
458SBValue
Greg Clayton4e9267d2010-12-14 18:39:31 +0000459SBFrame::FindVariable (const char *name)
Chris Lattner24943d22010-06-08 16:52:24 +0000460{
Greg Clayton582ed0e2011-06-18 20:06:08 +0000461 SBValue value;
Greg Clayton334d33a2012-01-30 07:41:31 +0000462 StackFrameSP frame_sp(GetFrameSP());
463 if (frame_sp)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000464 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000465 lldb::DynamicValueType use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton582ed0e2011-06-18 20:06:08 +0000466 value = FindVariable (name, use_dynamic);
467 }
468 return value;
Jim Inghame41494a2011-04-16 00:01:13 +0000469}
470
471SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000472SBFrame::FindVariable (const char *name, lldb::DynamicValueType use_dynamic)
Jim Inghame41494a2011-04-16 00:01:13 +0000473{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000474 VariableSP var_sp;
Jim Ingham47da8102011-04-22 23:53:53 +0000475 SBValue sb_value;
Greg Clayton334d33a2012-01-30 07:41:31 +0000476 StackFrameSP frame_sp(GetFrameSP());
477 if (frame_sp && name && name[0])
Chris Lattner24943d22010-06-08 16:52:24 +0000478 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000479 VariableList variable_list;
Greg Clayton334d33a2012-01-30 07:41:31 +0000480 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
481 SymbolContext sc (frame_sp->GetSymbolContext (eSymbolContextBlock));
Chris Lattner24943d22010-06-08 16:52:24 +0000482
Greg Claytondd62d722010-12-14 04:58:53 +0000483 if (sc.block)
Chris Lattner24943d22010-06-08 16:52:24 +0000484 {
Greg Claytondd62d722010-12-14 04:58:53 +0000485 const bool can_create = true;
486 const bool get_parent_variables = true;
487 const bool stop_if_block_is_inlined_function = true;
488
489 if (sc.block->AppendVariables (can_create,
490 get_parent_variables,
491 stop_if_block_is_inlined_function,
492 &variable_list))
493 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000494 var_sp = variable_list.FindVariable (ConstString(name));
Greg Claytondd62d722010-12-14 04:58:53 +0000495 }
Chris Lattner24943d22010-06-08 16:52:24 +0000496 }
Greg Clayton582ed0e2011-06-18 20:06:08 +0000497
498 if (var_sp)
Greg Clayton334d33a2012-01-30 07:41:31 +0000499 *sb_value = ValueObjectSP (frame_sp->GetValueObjectForFrameVariable(var_sp, use_dynamic));
Greg Clayton582ed0e2011-06-18 20:06:08 +0000500
Chris Lattner24943d22010-06-08 16:52:24 +0000501 }
Caroline Tice98f930f2010-09-20 05:20:02 +0000502
Greg Clayton4e9267d2010-12-14 18:39:31 +0000503 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000504 if (log)
Greg Clayton4e9267d2010-12-14 18:39:31 +0000505 log->Printf ("SBFrame(%p)::FindVariable (name=\"%s\") => SBValue(%p)",
Greg Clayton334d33a2012-01-30 07:41:31 +0000506 frame_sp.get(), name, sb_value.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000507
Chris Lattner24943d22010-06-08 16:52:24 +0000508 return sb_value;
509}
510
511SBValue
Greg Clayton4e9267d2010-12-14 18:39:31 +0000512SBFrame::FindValue (const char *name, ValueType value_type)
Chris Lattner24943d22010-06-08 16:52:24 +0000513{
Greg Clayton582ed0e2011-06-18 20:06:08 +0000514 SBValue value;
Greg Clayton334d33a2012-01-30 07:41:31 +0000515 StackFrameSP frame_sp(GetFrameSP());
516 if (frame_sp)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000517 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000518 lldb::DynamicValueType use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton582ed0e2011-06-18 20:06:08 +0000519 value = FindValue (name, value_type, use_dynamic);
520 }
521 return value;
Jim Inghame41494a2011-04-16 00:01:13 +0000522}
523
524SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000525SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueType use_dynamic)
Jim Inghame41494a2011-04-16 00:01:13 +0000526{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000527 SBValue sb_value;
Greg Clayton334d33a2012-01-30 07:41:31 +0000528 StackFrameSP frame_sp(GetFrameSP());
529 if (frame_sp && name && name[0])
Chris Lattner24943d22010-06-08 16:52:24 +0000530 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000531 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
Greg Clayton4e9267d2010-12-14 18:39:31 +0000532
533 switch (value_type)
Chris Lattner24943d22010-06-08 16:52:24 +0000534 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000535 case eValueTypeVariableGlobal: // global variable
536 case eValueTypeVariableStatic: // static variable
537 case eValueTypeVariableArgument: // function argument variables
538 case eValueTypeVariableLocal: // function local variables
Chris Lattner24943d22010-06-08 16:52:24 +0000539 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000540 VariableList *variable_list = frame_sp->GetVariableList(true);
Greg Clayton4e9267d2010-12-14 18:39:31 +0000541
Greg Clayton334d33a2012-01-30 07:41:31 +0000542 SymbolContext sc (frame_sp->GetSymbolContext (eSymbolContextBlock));
Greg Clayton4e9267d2010-12-14 18:39:31 +0000543
544 const bool can_create = true;
545 const bool get_parent_variables = true;
546 const bool stop_if_block_is_inlined_function = true;
547
548 if (sc.block && sc.block->AppendVariables (can_create,
549 get_parent_variables,
550 stop_if_block_is_inlined_function,
551 variable_list))
Johnny Chenc35750a2010-11-19 18:07:14 +0000552 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000553 ConstString const_name(name);
554 const uint32_t num_variables = variable_list->GetSize();
555 for (uint32_t i = 0; i < num_variables; ++i)
Johnny Chenc35750a2010-11-19 18:07:14 +0000556 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000557 VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
558 if (variable_sp &&
559 variable_sp->GetScope() == value_type &&
560 variable_sp->GetName() == const_name)
561 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000562 *sb_value = ValueObjectSP (frame_sp->GetValueObjectForFrameVariable(variable_sp,
Jim Inghame41494a2011-04-16 00:01:13 +0000563 use_dynamic));
Greg Clayton4e9267d2010-12-14 18:39:31 +0000564 break;
565 }
Johnny Chenc35750a2010-11-19 18:07:14 +0000566 }
567 }
Chris Lattner24943d22010-06-08 16:52:24 +0000568 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000569 break;
570
571 case eValueTypeRegister: // stack frame register value
572 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000573 RegisterContextSP reg_ctx (frame_sp->GetRegisterContext());
Greg Clayton4e9267d2010-12-14 18:39:31 +0000574 if (reg_ctx)
575 {
576 const uint32_t num_regs = reg_ctx->GetRegisterCount();
577 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx)
578 {
579 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
580 if (reg_info &&
581 ((reg_info->name && strcasecmp (reg_info->name, name) == 0) ||
582 (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0)))
583 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000584 *sb_value = ValueObjectRegister::Create (frame_sp.get(), reg_ctx, reg_idx);
Greg Clayton4e9267d2010-12-14 18:39:31 +0000585 }
586 }
587 }
588 }
589 break;
590
591 case eValueTypeRegisterSet: // A collection of stack frame register values
592 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000593 RegisterContextSP reg_ctx (frame_sp->GetRegisterContext());
Greg Clayton4e9267d2010-12-14 18:39:31 +0000594 if (reg_ctx)
595 {
596 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
597 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
598 {
599 const RegisterSet *reg_set = reg_ctx->GetRegisterSet (set_idx);
600 if (reg_set &&
601 ((reg_set->name && strcasecmp (reg_set->name, name) == 0) ||
602 (reg_set->short_name && strcasecmp (reg_set->short_name, name) == 0)))
603 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000604 *sb_value = ValueObjectRegisterSet::Create (frame_sp.get(), reg_ctx, set_idx);
Greg Clayton4e9267d2010-12-14 18:39:31 +0000605 }
606 }
607 }
608 }
609 break;
610
611 case eValueTypeConstResult: // constant result variables
612 {
613 ConstString const_name(name);
Greg Clayton334d33a2012-01-30 07:41:31 +0000614 ClangExpressionVariableSP expr_var_sp (frame_sp->GetThread().GetProcess().GetTarget().GetPersistentVariables().GetVariable (const_name));
Greg Clayton4e9267d2010-12-14 18:39:31 +0000615 if (expr_var_sp)
616 *sb_value = expr_var_sp->GetValueObject();
617 }
618 break;
619
620 default:
621 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000622 }
623 }
Caroline Tice98f930f2010-09-20 05:20:02 +0000624
Greg Clayton4e9267d2010-12-14 18:39:31 +0000625 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000626 if (log)
Greg Clayton4e9267d2010-12-14 18:39:31 +0000627 log->Printf ("SBFrame(%p)::FindVariableInScope (name=\"%s\", value_type=%i) => SBValue(%p)",
Greg Clayton334d33a2012-01-30 07:41:31 +0000628 frame_sp.get(), name, value_type, sb_value.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000629
630
Chris Lattner24943d22010-06-08 16:52:24 +0000631 return sb_value;
632}
633
634bool
635SBFrame::operator == (const SBFrame &rhs) const
636{
Greg Clayton334d33a2012-01-30 07:41:31 +0000637 return GetFrameSP().get() == rhs.GetFrameSP().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000638}
639
640bool
641SBFrame::operator != (const SBFrame &rhs) const
642{
Greg Clayton334d33a2012-01-30 07:41:31 +0000643 return GetFrameSP().get() != rhs.GetFrameSP().get();
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000644}
Chris Lattner24943d22010-06-08 16:52:24 +0000645
646SBThread
647SBFrame::GetThread () const
648{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000649 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000650
Greg Claytondd62d722010-12-14 04:58:53 +0000651 SBThread sb_thread;
Greg Clayton90c52142012-01-30 02:53:15 +0000652 ThreadSP thread_sp;
Greg Clayton334d33a2012-01-30 07:41:31 +0000653 StackFrameSP frame_sp(GetFrameSP());
654 if (frame_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000655 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000656 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
657 thread_sp = frame_sp->GetThread().shared_from_this();
Greg Clayton90c52142012-01-30 02:53:15 +0000658 sb_thread.SetThread (thread_sp);
Greg Claytonbdcda462010-12-20 20:49:23 +0000659 }
Caroline Tice7826c882010-10-26 03:11:13 +0000660
661 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000662 {
663 SBStream sstr;
664 sb_thread.GetDescription (sstr);
Greg Clayton334d33a2012-01-30 07:41:31 +0000665 log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s", frame_sp.get(),
Greg Clayton90c52142012-01-30 02:53:15 +0000666 thread_sp.get(), sstr.GetData());
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000667 }
Caroline Tice7826c882010-10-26 03:11:13 +0000668
Chris Lattner24943d22010-06-08 16:52:24 +0000669 return sb_thread;
670}
671
672const char *
673SBFrame::Disassemble () const
674{
Greg Claytona66ba462010-10-30 04:51:46 +0000675 const char *disassembly = NULL;
Greg Clayton334d33a2012-01-30 07:41:31 +0000676 StackFrameSP frame_sp(GetFrameSP());
677 if (frame_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000678 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000679 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
680 disassembly = frame_sp->Disassemble();
Greg Claytonbdcda462010-12-20 20:49:23 +0000681 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000682 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000683
684 if (log)
Greg Clayton334d33a2012-01-30 07:41:31 +0000685 log->Printf ("SBFrame(%p)::Disassemble () => %s", frame_sp.get(), disassembly);
Greg Claytona66ba462010-10-30 04:51:46 +0000686
687 return disassembly;
Chris Lattner24943d22010-06-08 16:52:24 +0000688}
689
690
Chris Lattner24943d22010-06-08 16:52:24 +0000691SBValueList
692SBFrame::GetVariables (bool arguments,
693 bool locals,
694 bool statics,
695 bool in_scope_only)
696{
Greg Clayton582ed0e2011-06-18 20:06:08 +0000697 SBValueList value_list;
Greg Clayton334d33a2012-01-30 07:41:31 +0000698 StackFrameSP frame_sp(GetFrameSP());
699 if (frame_sp)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000700 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000701 lldb::DynamicValueType use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton582ed0e2011-06-18 20:06:08 +0000702 value_list = GetVariables (arguments, locals, statics, in_scope_only, use_dynamic);
703 }
704 return value_list;
Jim Inghame41494a2011-04-16 00:01:13 +0000705}
706
707SBValueList
708SBFrame::GetVariables (bool arguments,
709 bool locals,
710 bool statics,
711 bool in_scope_only,
Jim Ingham10de7d12011-05-04 03:43:18 +0000712 lldb::DynamicValueType use_dynamic)
Jim Inghame41494a2011-04-16 00:01:13 +0000713{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000714 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000715
Greg Clayton334d33a2012-01-30 07:41:31 +0000716 SBValueList value_list;
717 StackFrameSP frame_sp(GetFrameSP());
718
Caroline Tice7826c882010-10-26 03:11:13 +0000719 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000720 log->Printf ("SBFrame(%p)::GetVariables (arguments=%i, locals=%i, statics=%i, in_scope_only=%i)",
Greg Clayton334d33a2012-01-30 07:41:31 +0000721 frame_sp.get(),
Greg Claytona66ba462010-10-30 04:51:46 +0000722 arguments,
723 locals,
724 statics,
725 in_scope_only);
Greg Clayton334d33a2012-01-30 07:41:31 +0000726
727 if (frame_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000728 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000729
Chris Lattner24943d22010-06-08 16:52:24 +0000730 size_t i;
Greg Claytonbdcda462010-12-20 20:49:23 +0000731 VariableList *variable_list = NULL;
732 // Scope for locker
733 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000734 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
735 variable_list = frame_sp->GetVariableList(true);
Greg Claytonbdcda462010-12-20 20:49:23 +0000736 }
Chris Lattner24943d22010-06-08 16:52:24 +0000737 if (variable_list)
738 {
739 const size_t num_variables = variable_list->GetSize();
740 if (num_variables)
741 {
742 for (i = 0; i < num_variables; ++i)
743 {
744 VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
745 if (variable_sp)
746 {
747 bool add_variable = false;
748 switch (variable_sp->GetScope())
749 {
750 case eValueTypeVariableGlobal:
751 case eValueTypeVariableStatic:
752 add_variable = statics;
753 break;
754
755 case eValueTypeVariableArgument:
756 add_variable = arguments;
757 break;
758
759 case eValueTypeVariableLocal:
760 add_variable = locals;
761 break;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000762
763 default:
764 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000765 }
766 if (add_variable)
767 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000768 if (in_scope_only && !variable_sp->IsInScope(frame_sp.get()))
Chris Lattner24943d22010-06-08 16:52:24 +0000769 continue;
770
Greg Clayton334d33a2012-01-30 07:41:31 +0000771 value_list.Append(frame_sp->GetValueObjectForFrameVariable (variable_sp, use_dynamic));
Chris Lattner24943d22010-06-08 16:52:24 +0000772 }
773 }
774 }
775 }
Greg Clayton17dae082010-09-02 02:59:18 +0000776 }
Chris Lattner24943d22010-06-08 16:52:24 +0000777 }
Caroline Tice7826c882010-10-26 03:11:13 +0000778
779 if (log)
780 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000781 log->Printf ("SBFrame(%p)::GetVariables (...) => SBValueList(%p)", frame_sp.get(),
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000782 value_list.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000783 }
784
Chris Lattner24943d22010-06-08 16:52:24 +0000785 return value_list;
786}
787
Greg Clayton4e9267d2010-12-14 18:39:31 +0000788SBValueList
Chris Lattner24943d22010-06-08 16:52:24 +0000789SBFrame::GetRegisters ()
790{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000791 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000792
Chris Lattner24943d22010-06-08 16:52:24 +0000793 SBValueList value_list;
Greg Clayton334d33a2012-01-30 07:41:31 +0000794 StackFrameSP frame_sp(GetFrameSP());
795 if (frame_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000796 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000797 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
798 RegisterContextSP reg_ctx (frame_sp->GetRegisterContext());
Chris Lattner24943d22010-06-08 16:52:24 +0000799 if (reg_ctx)
800 {
801 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
802 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
803 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000804 value_list.Append(ValueObjectRegisterSet::Create (frame_sp.get(), reg_ctx, set_idx));
Chris Lattner24943d22010-06-08 16:52:24 +0000805 }
806 }
807 }
Caroline Tice7826c882010-10-26 03:11:13 +0000808
809 if (log)
Greg Clayton334d33a2012-01-30 07:41:31 +0000810 log->Printf ("SBFrame(%p)::Registers () => SBValueList(%p)", frame_sp.get(), value_list.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000811
Chris Lattner24943d22010-06-08 16:52:24 +0000812 return value_list;
813}
814
Caroline Tice98f930f2010-09-20 05:20:02 +0000815bool
816SBFrame::GetDescription (SBStream &description)
817{
Greg Clayton96154be2011-11-13 06:57:31 +0000818 Stream &strm = description.ref();
819
Greg Clayton334d33a2012-01-30 07:41:31 +0000820 StackFrameSP frame_sp(GetFrameSP());
821 if (frame_sp)
Caroline Tice98f930f2010-09-20 05:20:02 +0000822 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000823 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
824 frame_sp->DumpUsingSettingsFormat (&strm);
Caroline Tice98f930f2010-09-20 05:20:02 +0000825 }
826 else
Greg Clayton96154be2011-11-13 06:57:31 +0000827 strm.PutCString ("No value");
Caroline Tice98f930f2010-09-20 05:20:02 +0000828
829 return true;
830}
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000831
Greg Clayton4e9267d2010-12-14 18:39:31 +0000832SBValue
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000833SBFrame::EvaluateExpression (const char *expr)
834{
Greg Clayton582ed0e2011-06-18 20:06:08 +0000835 SBValue result;
Greg Clayton334d33a2012-01-30 07:41:31 +0000836 StackFrameSP frame_sp(GetFrameSP());
837 if (frame_sp)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000838 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000839 lldb::DynamicValueType use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton582ed0e2011-06-18 20:06:08 +0000840 result = EvaluateExpression (expr, use_dynamic);
841 }
842 return result;
Jim Inghame41494a2011-04-16 00:01:13 +0000843}
844
845SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000846SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value)
Jim Inghame41494a2011-04-16 00:01:13 +0000847{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000848 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Sean Callanan94d255f2010-12-07 22:55:01 +0000849
Greg Clayton4e9267d2010-12-14 18:39:31 +0000850 LogSP expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Greg Claytona66ba462010-10-30 04:51:46 +0000851
Johnny Chenee6e7902011-08-10 22:06:24 +0000852 ExecutionResults exe_results;
Greg Clayton4e9267d2010-12-14 18:39:31 +0000853 SBValue expr_result;
Greg Claytona66ba462010-10-30 04:51:46 +0000854
Greg Clayton334d33a2012-01-30 07:41:31 +0000855 StackFrameSP frame_sp(GetFrameSP());
856 if (log)
857 log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\")...", frame_sp.get(), expr);
858
859 if (frame_sp)
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000860 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000861 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
Greg Clayton582ed0e2011-06-18 20:06:08 +0000862
Greg Clayton87ac9022011-06-25 04:35:01 +0000863
864 StreamString frame_description;
Greg Clayton334d33a2012-01-30 07:41:31 +0000865 frame_sp->DumpUsingSettingsFormat (&frame_description);
Greg Clayton87ac9022011-06-25 04:35:01 +0000866
867 Host::SetCrashDescriptionWithFormat ("SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
868 expr, fetch_dynamic_value, frame_description.GetString().c_str());
869
Sean Callanandaa6efe2011-12-21 22:22:58 +0000870 const bool coerce_to_id = false;
Greg Clayton427f2902010-12-14 02:59:59 +0000871 const bool unwind_on_error = true;
Sean Callanan6a925532011-01-13 08:53:35 +0000872 const bool keep_in_memory = false;
Greg Clayton427f2902010-12-14 02:59:59 +0000873
Greg Clayton334d33a2012-01-30 07:41:31 +0000874 exe_results = frame_sp->GetThread().GetProcess().GetTarget().EvaluateExpression(expr,
875 frame_sp.get(),
876 eExecutionPolicyOnlyWhenNeeded,
877 coerce_to_id,
878 unwind_on_error,
879 keep_in_memory,
880 fetch_dynamic_value,
881 *expr_result);
Greg Clayton668a6c72011-11-10 18:31:53 +0000882
883 Host::SetCrashDescription (NULL);
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000884 }
Greg Claytona66ba462010-10-30 04:51:46 +0000885
Sean Callanan94d255f2010-12-07 22:55:01 +0000886 if (expr_log)
Jim Inghame41494a2011-04-16 00:01:13 +0000887 expr_log->Printf("** [SBFrame::EvaluateExpression] Expression result is %s, summary %s **",
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000888 expr_result.GetValue(),
889 expr_result.GetSummary());
Sean Callanan94d255f2010-12-07 22:55:01 +0000890
Greg Claytona66ba462010-10-30 04:51:46 +0000891 if (log)
Greg Clayton334d33a2012-01-30 07:41:31 +0000892 log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)", frame_sp.get(),
Jim Inghame41494a2011-04-16 00:01:13 +0000893 expr,
Johnny Chenee6e7902011-08-10 22:06:24 +0000894 expr_result.get(),
895 exe_results);
Greg Claytona66ba462010-10-30 04:51:46 +0000896
Greg Clayton49ce6822010-10-31 03:01:06 +0000897 return expr_result;
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000898}
Greg Clayton582ed0e2011-06-18 20:06:08 +0000899
900bool
901SBFrame::IsInlined()
902{
Greg Clayton334d33a2012-01-30 07:41:31 +0000903 StackFrameSP frame_sp(GetFrameSP());
904 if (frame_sp)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000905 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000906 Block *block = frame_sp->GetSymbolContext(eSymbolContextBlock).block;
Greg Clayton582ed0e2011-06-18 20:06:08 +0000907 if (block)
908 return block->GetContainingInlinedBlock () != NULL;
909 }
910 return false;
911}
912
913const char *
914SBFrame::GetFunctionName()
915{
916 const char *name = NULL;
Greg Clayton334d33a2012-01-30 07:41:31 +0000917 StackFrameSP frame_sp(GetFrameSP());
918 if (frame_sp)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000919 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000920 SymbolContext sc (frame_sp->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol));
Greg Clayton582ed0e2011-06-18 20:06:08 +0000921 if (sc.block)
922 {
923 Block *inlined_block = sc.block->GetContainingInlinedBlock ();
924 if (inlined_block)
925 {
926 const InlineFunctionInfo* inlined_info = inlined_block->GetInlinedFunctionInfo();
927 name = inlined_info->GetName().AsCString();
928 }
929 }
930
931 if (name == NULL)
932 {
933 if (sc.function)
934 name = sc.function->GetName().GetCString();
935 }
936
937 if (name == NULL)
938 {
939 if (sc.symbol)
940 name = sc.symbol->GetName().GetCString();
941 }
942 }
943 return name;
944}
945