blob: 564cf7736f255a662d9160d0ecb085bd7f406b82 [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 Clayton334d33a2012-01-30 07:41:31 +0000225 StackFrameSP frame_sp(GetFrameSP());
226 if (frame_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000227 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000228 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
229 *sb_module = frame_sp->GetSymbolContext (eSymbolContextModule).module_sp;
Greg Claytonbdcda462010-12-20 20:49:23 +0000230 }
Greg Claytondd62d722010-12-14 04:58:53 +0000231
Greg Clayton4e9267d2010-12-14 18:39:31 +0000232 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000233 if (log)
234 log->Printf ("SBFrame(%p)::GetModule () => SBModule(%p)",
Greg Clayton334d33a2012-01-30 07:41:31 +0000235 frame_sp.get(), sb_module.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000236
Chris Lattner24943d22010-06-08 16:52:24 +0000237 return sb_module;
238}
239
240SBCompileUnit
241SBFrame::GetCompileUnit () const
242{
Greg Claytondd62d722010-12-14 04:58:53 +0000243 SBCompileUnit sb_comp_unit;
Greg Clayton334d33a2012-01-30 07:41:31 +0000244 StackFrameSP frame_sp(GetFrameSP());
245 if (frame_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000246 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000247 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
248 sb_comp_unit.reset (frame_sp->GetSymbolContext (eSymbolContextCompUnit).comp_unit);
Greg Claytonbdcda462010-12-20 20:49:23 +0000249 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000250 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000251 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000252 log->Printf ("SBFrame(%p)::GetModule () => SBCompileUnit(%p)",
Greg Clayton334d33a2012-01-30 07:41:31 +0000253 frame_sp.get(), sb_comp_unit.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000254
Chris Lattner24943d22010-06-08 16:52:24 +0000255 return sb_comp_unit;
256}
257
258SBFunction
259SBFrame::GetFunction () const
260{
Greg Claytondd62d722010-12-14 04:58:53 +0000261 SBFunction sb_function;
Greg Clayton334d33a2012-01-30 07:41:31 +0000262 StackFrameSP frame_sp(GetFrameSP());
263 if (frame_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000264 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000265 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
266 sb_function.reset(frame_sp->GetSymbolContext (eSymbolContextFunction).function);
Greg Claytonbdcda462010-12-20 20:49:23 +0000267 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000268 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000269 if (log)
270 log->Printf ("SBFrame(%p)::GetFunction () => SBFunction(%p)",
Greg Clayton334d33a2012-01-30 07:41:31 +0000271 frame_sp.get(), sb_function.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000272
Chris Lattner24943d22010-06-08 16:52:24 +0000273 return sb_function;
274}
275
Greg Clayton8f1e08b2010-10-04 18:37:52 +0000276SBSymbol
277SBFrame::GetSymbol () const
278{
Greg Claytondd62d722010-12-14 04:58:53 +0000279 SBSymbol sb_symbol;
Greg Clayton334d33a2012-01-30 07:41:31 +0000280 StackFrameSP frame_sp(GetFrameSP());
281 if (frame_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000282 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000283 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
284 sb_symbol.reset(frame_sp->GetSymbolContext (eSymbolContextSymbol).symbol);
Greg Claytonbdcda462010-12-20 20:49:23 +0000285 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000286 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000287 if (log)
288 log->Printf ("SBFrame(%p)::GetSymbol () => SBSymbol(%p)",
Greg Clayton334d33a2012-01-30 07:41:31 +0000289 frame_sp.get(), sb_symbol.get());
Greg Clayton8f1e08b2010-10-04 18:37:52 +0000290 return sb_symbol;
291}
292
Chris Lattner24943d22010-06-08 16:52:24 +0000293SBBlock
294SBFrame::GetBlock () const
295{
Greg Claytondd62d722010-12-14 04:58:53 +0000296 SBBlock sb_block;
Greg Clayton334d33a2012-01-30 07:41:31 +0000297 StackFrameSP frame_sp(GetFrameSP());
298 if (frame_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000299 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000300 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
301 sb_block.reset (frame_sp->GetSymbolContext (eSymbolContextBlock).block);
Greg Claytonbdcda462010-12-20 20:49:23 +0000302 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000303 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000304 if (log)
305 log->Printf ("SBFrame(%p)::GetBlock () => SBBlock(%p)",
Greg Clayton334d33a2012-01-30 07:41:31 +0000306 frame_sp.get(), sb_block.get());
Chris Lattner24943d22010-06-08 16:52:24 +0000307 return sb_block;
308}
309
Greg Clayton69aa5d92010-09-07 04:20:48 +0000310SBBlock
311SBFrame::GetFrameBlock () const
312{
Greg Claytondd62d722010-12-14 04:58:53 +0000313 SBBlock sb_block;
Greg Clayton334d33a2012-01-30 07:41:31 +0000314 StackFrameSP frame_sp(GetFrameSP());
315 if (frame_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000316 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000317 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
318 sb_block.reset(frame_sp->GetFrameBlock ());
Greg Claytonbdcda462010-12-20 20:49:23 +0000319 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000320 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000321 if (log)
322 log->Printf ("SBFrame(%p)::GetFrameBlock () => SBBlock(%p)",
Greg Clayton334d33a2012-01-30 07:41:31 +0000323 frame_sp.get(), sb_block.get());
Greg Clayton69aa5d92010-09-07 04:20:48 +0000324 return sb_block;
325}
326
Chris Lattner24943d22010-06-08 16:52:24 +0000327SBLineEntry
328SBFrame::GetLineEntry () const
329{
Greg Claytondd62d722010-12-14 04:58:53 +0000330 SBLineEntry sb_line_entry;
Greg Clayton334d33a2012-01-30 07:41:31 +0000331 StackFrameSP frame_sp(GetFrameSP());
332 if (frame_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000333 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000334 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
335 sb_line_entry.SetLineEntry (frame_sp->GetSymbolContext (eSymbolContextLineEntry).line_entry);
Greg Claytonbdcda462010-12-20 20:49:23 +0000336 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000337 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000338 if (log)
339 log->Printf ("SBFrame(%p)::GetLineEntry () => SBLineEntry(%p)",
Greg Clayton334d33a2012-01-30 07:41:31 +0000340 frame_sp.get(), sb_line_entry.get());
Chris Lattner24943d22010-06-08 16:52:24 +0000341 return sb_line_entry;
342}
343
344uint32_t
345SBFrame::GetFrameID () const
346{
Greg Clayton334d33a2012-01-30 07:41:31 +0000347 uint32_t frame_idx = UINT32_MAX;
348
349
350 StackFrameSP frame_sp(GetFrameSP());
351 if (frame_sp)
352 frame_idx = frame_sp->GetFrameIndex ();
Greg Claytona66ba462010-10-30 04:51:46 +0000353
Greg Clayton4e9267d2010-12-14 18:39:31 +0000354 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000355 if (log)
356 log->Printf ("SBFrame(%p)::GetFrameID () => %u",
Greg Clayton334d33a2012-01-30 07:41:31 +0000357 frame_sp.get(), frame_idx);
Greg Claytona66ba462010-10-30 04:51:46 +0000358 return frame_idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000359}
360
Greg Clayton4e9267d2010-12-14 18:39:31 +0000361addr_t
Chris Lattner24943d22010-06-08 16:52:24 +0000362SBFrame::GetPC () const
363{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000364 addr_t addr = LLDB_INVALID_ADDRESS;
Greg Clayton334d33a2012-01-30 07:41:31 +0000365 StackFrameSP frame_sp(GetFrameSP());
366 if (frame_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000367 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000368 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
369 addr = frame_sp->GetFrameCodeAddress().GetOpcodeLoadAddress (&frame_sp->GetThread().GetProcess().GetTarget());
Greg Claytonbdcda462010-12-20 20:49:23 +0000370 }
Caroline Tice7826c882010-10-26 03:11:13 +0000371
Greg Clayton4e9267d2010-12-14 18:39:31 +0000372 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000373 if (log)
Greg Clayton334d33a2012-01-30 07:41:31 +0000374 log->Printf ("SBFrame(%p)::GetPC () => 0x%llx", frame_sp.get(), addr);
Caroline Tice7826c882010-10-26 03:11:13 +0000375
376 return addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000377}
378
379bool
Greg Clayton4e9267d2010-12-14 18:39:31 +0000380SBFrame::SetPC (addr_t new_pc)
Chris Lattner24943d22010-06-08 16:52:24 +0000381{
Caroline Tice7826c882010-10-26 03:11:13 +0000382 bool ret_val = false;
Greg Clayton334d33a2012-01-30 07:41:31 +0000383 StackFrameSP frame_sp(GetFrameSP());
384 if (frame_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000385 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000386 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
387 ret_val = frame_sp->GetRegisterContext()->SetPC (new_pc);
Greg Claytonbdcda462010-12-20 20:49:23 +0000388 }
Caroline Tice7826c882010-10-26 03:11:13 +0000389
Greg Clayton4e9267d2010-12-14 18:39:31 +0000390 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000391 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000392 log->Printf ("SBFrame(%p)::SetPC (new_pc=0x%llx) => %i",
Greg Clayton334d33a2012-01-30 07:41:31 +0000393 frame_sp.get(), new_pc, ret_val);
Caroline Tice7826c882010-10-26 03:11:13 +0000394
395 return ret_val;
Chris Lattner24943d22010-06-08 16:52:24 +0000396}
397
Greg Clayton4e9267d2010-12-14 18:39:31 +0000398addr_t
Chris Lattner24943d22010-06-08 16:52:24 +0000399SBFrame::GetSP () const
400{
Greg Claytona66ba462010-10-30 04:51:46 +0000401 addr_t addr = LLDB_INVALID_ADDRESS;
Greg Clayton334d33a2012-01-30 07:41:31 +0000402 StackFrameSP frame_sp(GetFrameSP());
403 if (frame_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000404 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000405 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
406 addr = frame_sp->GetRegisterContext()->GetSP();
Greg Claytonbdcda462010-12-20 20:49:23 +0000407 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000408 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000409 if (log)
Greg Clayton334d33a2012-01-30 07:41:31 +0000410 log->Printf ("SBFrame(%p)::GetSP () => 0x%llx", frame_sp.get(), addr);
Greg Claytona66ba462010-10-30 04:51:46 +0000411
412 return addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000413}
414
415
Greg Clayton4e9267d2010-12-14 18:39:31 +0000416addr_t
Chris Lattner24943d22010-06-08 16:52:24 +0000417SBFrame::GetFP () const
418{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000419 addr_t addr = LLDB_INVALID_ADDRESS;
Greg Clayton334d33a2012-01-30 07:41:31 +0000420 StackFrameSP frame_sp(GetFrameSP());
421 if (frame_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000422 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000423 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
424 addr = frame_sp->GetRegisterContext()->GetFP();
Greg Claytonbdcda462010-12-20 20:49:23 +0000425 }
Caroline Tice7826c882010-10-26 03:11:13 +0000426
Greg Clayton4e9267d2010-12-14 18:39:31 +0000427 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000428 if (log)
Greg Clayton334d33a2012-01-30 07:41:31 +0000429 log->Printf ("SBFrame(%p)::GetFP () => 0x%llx", frame_sp.get(), addr);
Caroline Tice7826c882010-10-26 03:11:13 +0000430 return addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000431}
432
433
434SBAddress
435SBFrame::GetPCAddress () const
436{
437 SBAddress sb_addr;
Greg Clayton334d33a2012-01-30 07:41:31 +0000438 StackFrameSP frame_sp(GetFrameSP());
439 if (frame_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000440 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000441 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
442 sb_addr.SetAddress (&frame_sp->GetFrameCodeAddress());
Greg Claytonbdcda462010-12-20 20:49:23 +0000443 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000444 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000445 if (log)
Greg Clayton334d33a2012-01-30 07:41:31 +0000446 log->Printf ("SBFrame(%p)::GetPCAddress () => SBAddress(%p)", frame_sp.get(), sb_addr.get());
Chris Lattner24943d22010-06-08 16:52:24 +0000447 return sb_addr;
448}
449
450void
451SBFrame::Clear()
452{
Greg Clayton63094e02010-06-23 01:19:29 +0000453 m_opaque_sp.reset();
Chris Lattner24943d22010-06-08 16:52:24 +0000454}
455
456SBValue
Greg Clayton4e9267d2010-12-14 18:39:31 +0000457SBFrame::FindVariable (const char *name)
Chris Lattner24943d22010-06-08 16:52:24 +0000458{
Greg Clayton582ed0e2011-06-18 20:06:08 +0000459 SBValue value;
Greg Clayton334d33a2012-01-30 07:41:31 +0000460 StackFrameSP frame_sp(GetFrameSP());
461 if (frame_sp)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000462 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000463 lldb::DynamicValueType use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton582ed0e2011-06-18 20:06:08 +0000464 value = FindVariable (name, use_dynamic);
465 }
466 return value;
Jim Inghame41494a2011-04-16 00:01:13 +0000467}
468
469SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000470SBFrame::FindVariable (const char *name, lldb::DynamicValueType use_dynamic)
Jim Inghame41494a2011-04-16 00:01:13 +0000471{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000472 VariableSP var_sp;
Jim Ingham47da8102011-04-22 23:53:53 +0000473 SBValue sb_value;
Greg Clayton334d33a2012-01-30 07:41:31 +0000474 StackFrameSP frame_sp(GetFrameSP());
475 if (frame_sp && name && name[0])
Chris Lattner24943d22010-06-08 16:52:24 +0000476 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000477 VariableList variable_list;
Greg Clayton334d33a2012-01-30 07:41:31 +0000478 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
479 SymbolContext sc (frame_sp->GetSymbolContext (eSymbolContextBlock));
Chris Lattner24943d22010-06-08 16:52:24 +0000480
Greg Claytondd62d722010-12-14 04:58:53 +0000481 if (sc.block)
Chris Lattner24943d22010-06-08 16:52:24 +0000482 {
Greg Claytondd62d722010-12-14 04:58:53 +0000483 const bool can_create = true;
484 const bool get_parent_variables = true;
485 const bool stop_if_block_is_inlined_function = true;
486
487 if (sc.block->AppendVariables (can_create,
488 get_parent_variables,
489 stop_if_block_is_inlined_function,
490 &variable_list))
491 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000492 var_sp = variable_list.FindVariable (ConstString(name));
Greg Claytondd62d722010-12-14 04:58:53 +0000493 }
Chris Lattner24943d22010-06-08 16:52:24 +0000494 }
Greg Clayton582ed0e2011-06-18 20:06:08 +0000495
496 if (var_sp)
Greg Clayton334d33a2012-01-30 07:41:31 +0000497 *sb_value = ValueObjectSP (frame_sp->GetValueObjectForFrameVariable(var_sp, use_dynamic));
Greg Clayton582ed0e2011-06-18 20:06:08 +0000498
Chris Lattner24943d22010-06-08 16:52:24 +0000499 }
Caroline Tice98f930f2010-09-20 05:20:02 +0000500
Greg Clayton4e9267d2010-12-14 18:39:31 +0000501 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000502 if (log)
Greg Clayton4e9267d2010-12-14 18:39:31 +0000503 log->Printf ("SBFrame(%p)::FindVariable (name=\"%s\") => SBValue(%p)",
Greg Clayton334d33a2012-01-30 07:41:31 +0000504 frame_sp.get(), name, sb_value.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000505
Chris Lattner24943d22010-06-08 16:52:24 +0000506 return sb_value;
507}
508
509SBValue
Greg Clayton4e9267d2010-12-14 18:39:31 +0000510SBFrame::FindValue (const char *name, ValueType value_type)
Chris Lattner24943d22010-06-08 16:52:24 +0000511{
Greg Clayton582ed0e2011-06-18 20:06:08 +0000512 SBValue value;
Greg Clayton334d33a2012-01-30 07:41:31 +0000513 StackFrameSP frame_sp(GetFrameSP());
514 if (frame_sp)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000515 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000516 lldb::DynamicValueType use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton582ed0e2011-06-18 20:06:08 +0000517 value = FindValue (name, value_type, use_dynamic);
518 }
519 return value;
Jim Inghame41494a2011-04-16 00:01:13 +0000520}
521
522SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000523SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueType use_dynamic)
Jim Inghame41494a2011-04-16 00:01:13 +0000524{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000525 SBValue sb_value;
Greg Clayton334d33a2012-01-30 07:41:31 +0000526 StackFrameSP frame_sp(GetFrameSP());
527 if (frame_sp && name && name[0])
Chris Lattner24943d22010-06-08 16:52:24 +0000528 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000529 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
Greg Clayton4e9267d2010-12-14 18:39:31 +0000530
531 switch (value_type)
Chris Lattner24943d22010-06-08 16:52:24 +0000532 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000533 case eValueTypeVariableGlobal: // global variable
534 case eValueTypeVariableStatic: // static variable
535 case eValueTypeVariableArgument: // function argument variables
536 case eValueTypeVariableLocal: // function local variables
Chris Lattner24943d22010-06-08 16:52:24 +0000537 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000538 VariableList *variable_list = frame_sp->GetVariableList(true);
Greg Clayton4e9267d2010-12-14 18:39:31 +0000539
Greg Clayton334d33a2012-01-30 07:41:31 +0000540 SymbolContext sc (frame_sp->GetSymbolContext (eSymbolContextBlock));
Greg Clayton4e9267d2010-12-14 18:39:31 +0000541
542 const bool can_create = true;
543 const bool get_parent_variables = true;
544 const bool stop_if_block_is_inlined_function = true;
545
546 if (sc.block && sc.block->AppendVariables (can_create,
547 get_parent_variables,
548 stop_if_block_is_inlined_function,
549 variable_list))
Johnny Chenc35750a2010-11-19 18:07:14 +0000550 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000551 ConstString const_name(name);
552 const uint32_t num_variables = variable_list->GetSize();
553 for (uint32_t i = 0; i < num_variables; ++i)
Johnny Chenc35750a2010-11-19 18:07:14 +0000554 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000555 VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
556 if (variable_sp &&
557 variable_sp->GetScope() == value_type &&
558 variable_sp->GetName() == const_name)
559 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000560 *sb_value = ValueObjectSP (frame_sp->GetValueObjectForFrameVariable(variable_sp,
Jim Inghame41494a2011-04-16 00:01:13 +0000561 use_dynamic));
Greg Clayton4e9267d2010-12-14 18:39:31 +0000562 break;
563 }
Johnny Chenc35750a2010-11-19 18:07:14 +0000564 }
565 }
Chris Lattner24943d22010-06-08 16:52:24 +0000566 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000567 break;
568
569 case eValueTypeRegister: // stack frame register value
570 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000571 RegisterContextSP reg_ctx (frame_sp->GetRegisterContext());
Greg Clayton4e9267d2010-12-14 18:39:31 +0000572 if (reg_ctx)
573 {
574 const uint32_t num_regs = reg_ctx->GetRegisterCount();
575 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx)
576 {
577 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
578 if (reg_info &&
579 ((reg_info->name && strcasecmp (reg_info->name, name) == 0) ||
580 (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0)))
581 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000582 *sb_value = ValueObjectRegister::Create (frame_sp.get(), reg_ctx, reg_idx);
Greg Clayton4e9267d2010-12-14 18:39:31 +0000583 }
584 }
585 }
586 }
587 break;
588
589 case eValueTypeRegisterSet: // A collection of stack frame register values
590 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000591 RegisterContextSP reg_ctx (frame_sp->GetRegisterContext());
Greg Clayton4e9267d2010-12-14 18:39:31 +0000592 if (reg_ctx)
593 {
594 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
595 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
596 {
597 const RegisterSet *reg_set = reg_ctx->GetRegisterSet (set_idx);
598 if (reg_set &&
599 ((reg_set->name && strcasecmp (reg_set->name, name) == 0) ||
600 (reg_set->short_name && strcasecmp (reg_set->short_name, name) == 0)))
601 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000602 *sb_value = ValueObjectRegisterSet::Create (frame_sp.get(), reg_ctx, set_idx);
Greg Clayton4e9267d2010-12-14 18:39:31 +0000603 }
604 }
605 }
606 }
607 break;
608
609 case eValueTypeConstResult: // constant result variables
610 {
611 ConstString const_name(name);
Greg Clayton334d33a2012-01-30 07:41:31 +0000612 ClangExpressionVariableSP expr_var_sp (frame_sp->GetThread().GetProcess().GetTarget().GetPersistentVariables().GetVariable (const_name));
Greg Clayton4e9267d2010-12-14 18:39:31 +0000613 if (expr_var_sp)
614 *sb_value = expr_var_sp->GetValueObject();
615 }
616 break;
617
618 default:
619 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000620 }
621 }
Caroline Tice98f930f2010-09-20 05:20:02 +0000622
Greg Clayton4e9267d2010-12-14 18:39:31 +0000623 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000624 if (log)
Greg Clayton4e9267d2010-12-14 18:39:31 +0000625 log->Printf ("SBFrame(%p)::FindVariableInScope (name=\"%s\", value_type=%i) => SBValue(%p)",
Greg Clayton334d33a2012-01-30 07:41:31 +0000626 frame_sp.get(), name, value_type, sb_value.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000627
628
Chris Lattner24943d22010-06-08 16:52:24 +0000629 return sb_value;
630}
631
632bool
633SBFrame::operator == (const SBFrame &rhs) const
634{
Greg Clayton334d33a2012-01-30 07:41:31 +0000635 return GetFrameSP().get() == rhs.GetFrameSP().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000636}
637
638bool
639SBFrame::operator != (const SBFrame &rhs) const
640{
Greg Clayton334d33a2012-01-30 07:41:31 +0000641 return GetFrameSP().get() != rhs.GetFrameSP().get();
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000642}
Chris Lattner24943d22010-06-08 16:52:24 +0000643
644SBThread
645SBFrame::GetThread () const
646{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000647 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000648
Greg Claytondd62d722010-12-14 04:58:53 +0000649 SBThread sb_thread;
Greg Clayton90c52142012-01-30 02:53:15 +0000650 ThreadSP thread_sp;
Greg Clayton334d33a2012-01-30 07:41:31 +0000651 StackFrameSP frame_sp(GetFrameSP());
652 if (frame_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000653 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000654 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
655 thread_sp = frame_sp->GetThread().shared_from_this();
Greg Clayton90c52142012-01-30 02:53:15 +0000656 sb_thread.SetThread (thread_sp);
Greg Claytonbdcda462010-12-20 20:49:23 +0000657 }
Caroline Tice7826c882010-10-26 03:11:13 +0000658
659 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000660 {
661 SBStream sstr;
662 sb_thread.GetDescription (sstr);
Greg Clayton334d33a2012-01-30 07:41:31 +0000663 log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s", frame_sp.get(),
Greg Clayton90c52142012-01-30 02:53:15 +0000664 thread_sp.get(), sstr.GetData());
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000665 }
Caroline Tice7826c882010-10-26 03:11:13 +0000666
Chris Lattner24943d22010-06-08 16:52:24 +0000667 return sb_thread;
668}
669
670const char *
671SBFrame::Disassemble () const
672{
Greg Claytona66ba462010-10-30 04:51:46 +0000673 const char *disassembly = NULL;
Greg Clayton334d33a2012-01-30 07:41:31 +0000674 StackFrameSP frame_sp(GetFrameSP());
675 if (frame_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000676 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000677 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
678 disassembly = frame_sp->Disassemble();
Greg Claytonbdcda462010-12-20 20:49:23 +0000679 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000680 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000681
682 if (log)
Greg Clayton334d33a2012-01-30 07:41:31 +0000683 log->Printf ("SBFrame(%p)::Disassemble () => %s", frame_sp.get(), disassembly);
Greg Claytona66ba462010-10-30 04:51:46 +0000684
685 return disassembly;
Chris Lattner24943d22010-06-08 16:52:24 +0000686}
687
688
Chris Lattner24943d22010-06-08 16:52:24 +0000689SBValueList
690SBFrame::GetVariables (bool arguments,
691 bool locals,
692 bool statics,
693 bool in_scope_only)
694{
Greg Clayton582ed0e2011-06-18 20:06:08 +0000695 SBValueList value_list;
Greg Clayton334d33a2012-01-30 07:41:31 +0000696 StackFrameSP frame_sp(GetFrameSP());
697 if (frame_sp)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000698 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000699 lldb::DynamicValueType use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton582ed0e2011-06-18 20:06:08 +0000700 value_list = GetVariables (arguments, locals, statics, in_scope_only, use_dynamic);
701 }
702 return value_list;
Jim Inghame41494a2011-04-16 00:01:13 +0000703}
704
705SBValueList
706SBFrame::GetVariables (bool arguments,
707 bool locals,
708 bool statics,
709 bool in_scope_only,
Jim Ingham10de7d12011-05-04 03:43:18 +0000710 lldb::DynamicValueType use_dynamic)
Jim Inghame41494a2011-04-16 00:01:13 +0000711{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000712 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000713
Greg Clayton334d33a2012-01-30 07:41:31 +0000714 SBValueList value_list;
715 StackFrameSP frame_sp(GetFrameSP());
716
Caroline Tice7826c882010-10-26 03:11:13 +0000717 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000718 log->Printf ("SBFrame(%p)::GetVariables (arguments=%i, locals=%i, statics=%i, in_scope_only=%i)",
Greg Clayton334d33a2012-01-30 07:41:31 +0000719 frame_sp.get(),
Greg Claytona66ba462010-10-30 04:51:46 +0000720 arguments,
721 locals,
722 statics,
723 in_scope_only);
Greg Clayton334d33a2012-01-30 07:41:31 +0000724
725 if (frame_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000726 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000727
Chris Lattner24943d22010-06-08 16:52:24 +0000728 size_t i;
Greg Claytonbdcda462010-12-20 20:49:23 +0000729 VariableList *variable_list = NULL;
730 // Scope for locker
731 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000732 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
733 variable_list = frame_sp->GetVariableList(true);
Greg Claytonbdcda462010-12-20 20:49:23 +0000734 }
Chris Lattner24943d22010-06-08 16:52:24 +0000735 if (variable_list)
736 {
737 const size_t num_variables = variable_list->GetSize();
738 if (num_variables)
739 {
740 for (i = 0; i < num_variables; ++i)
741 {
742 VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
743 if (variable_sp)
744 {
745 bool add_variable = false;
746 switch (variable_sp->GetScope())
747 {
748 case eValueTypeVariableGlobal:
749 case eValueTypeVariableStatic:
750 add_variable = statics;
751 break;
752
753 case eValueTypeVariableArgument:
754 add_variable = arguments;
755 break;
756
757 case eValueTypeVariableLocal:
758 add_variable = locals;
759 break;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000760
761 default:
762 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000763 }
764 if (add_variable)
765 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000766 if (in_scope_only && !variable_sp->IsInScope(frame_sp.get()))
Chris Lattner24943d22010-06-08 16:52:24 +0000767 continue;
768
Greg Clayton334d33a2012-01-30 07:41:31 +0000769 value_list.Append(frame_sp->GetValueObjectForFrameVariable (variable_sp, use_dynamic));
Chris Lattner24943d22010-06-08 16:52:24 +0000770 }
771 }
772 }
773 }
Greg Clayton17dae082010-09-02 02:59:18 +0000774 }
Chris Lattner24943d22010-06-08 16:52:24 +0000775 }
Caroline Tice7826c882010-10-26 03:11:13 +0000776
777 if (log)
778 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000779 log->Printf ("SBFrame(%p)::GetVariables (...) => SBValueList(%p)", frame_sp.get(),
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000780 value_list.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000781 }
782
Chris Lattner24943d22010-06-08 16:52:24 +0000783 return value_list;
784}
785
Greg Clayton4e9267d2010-12-14 18:39:31 +0000786SBValueList
Chris Lattner24943d22010-06-08 16:52:24 +0000787SBFrame::GetRegisters ()
788{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000789 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000790
Chris Lattner24943d22010-06-08 16:52:24 +0000791 SBValueList value_list;
Greg Clayton334d33a2012-01-30 07:41:31 +0000792 StackFrameSP frame_sp(GetFrameSP());
793 if (frame_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000794 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000795 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
796 RegisterContextSP reg_ctx (frame_sp->GetRegisterContext());
Chris Lattner24943d22010-06-08 16:52:24 +0000797 if (reg_ctx)
798 {
799 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
800 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
801 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000802 value_list.Append(ValueObjectRegisterSet::Create (frame_sp.get(), reg_ctx, set_idx));
Chris Lattner24943d22010-06-08 16:52:24 +0000803 }
804 }
805 }
Caroline Tice7826c882010-10-26 03:11:13 +0000806
807 if (log)
Greg Clayton334d33a2012-01-30 07:41:31 +0000808 log->Printf ("SBFrame(%p)::Registers () => SBValueList(%p)", frame_sp.get(), value_list.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000809
Chris Lattner24943d22010-06-08 16:52:24 +0000810 return value_list;
811}
812
Caroline Tice98f930f2010-09-20 05:20:02 +0000813bool
814SBFrame::GetDescription (SBStream &description)
815{
Greg Clayton96154be2011-11-13 06:57:31 +0000816 Stream &strm = description.ref();
817
Greg Clayton334d33a2012-01-30 07:41:31 +0000818 StackFrameSP frame_sp(GetFrameSP());
819 if (frame_sp)
Caroline Tice98f930f2010-09-20 05:20:02 +0000820 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000821 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
822 frame_sp->DumpUsingSettingsFormat (&strm);
Caroline Tice98f930f2010-09-20 05:20:02 +0000823 }
824 else
Greg Clayton96154be2011-11-13 06:57:31 +0000825 strm.PutCString ("No value");
Caroline Tice98f930f2010-09-20 05:20:02 +0000826
827 return true;
828}
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000829
Greg Clayton4e9267d2010-12-14 18:39:31 +0000830SBValue
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000831SBFrame::EvaluateExpression (const char *expr)
832{
Greg Clayton582ed0e2011-06-18 20:06:08 +0000833 SBValue result;
Greg Clayton334d33a2012-01-30 07:41:31 +0000834 StackFrameSP frame_sp(GetFrameSP());
835 if (frame_sp)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000836 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000837 lldb::DynamicValueType use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton582ed0e2011-06-18 20:06:08 +0000838 result = EvaluateExpression (expr, use_dynamic);
839 }
840 return result;
Jim Inghame41494a2011-04-16 00:01:13 +0000841}
842
843SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000844SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value)
Jim Inghame41494a2011-04-16 00:01:13 +0000845{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000846 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Sean Callanan94d255f2010-12-07 22:55:01 +0000847
Greg Clayton4e9267d2010-12-14 18:39:31 +0000848 LogSP expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Greg Claytona66ba462010-10-30 04:51:46 +0000849
Johnny Chenee6e7902011-08-10 22:06:24 +0000850 ExecutionResults exe_results;
Greg Clayton4e9267d2010-12-14 18:39:31 +0000851 SBValue expr_result;
Greg Claytona66ba462010-10-30 04:51:46 +0000852
Greg Clayton334d33a2012-01-30 07:41:31 +0000853 StackFrameSP frame_sp(GetFrameSP());
854 if (log)
855 log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\")...", frame_sp.get(), expr);
856
857 if (frame_sp)
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000858 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000859 Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
Greg Clayton582ed0e2011-06-18 20:06:08 +0000860
Greg Clayton87ac9022011-06-25 04:35:01 +0000861
862 StreamString frame_description;
Greg Clayton334d33a2012-01-30 07:41:31 +0000863 frame_sp->DumpUsingSettingsFormat (&frame_description);
Greg Clayton87ac9022011-06-25 04:35:01 +0000864
865 Host::SetCrashDescriptionWithFormat ("SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
866 expr, fetch_dynamic_value, frame_description.GetString().c_str());
867
Sean Callanandaa6efe2011-12-21 22:22:58 +0000868 const bool coerce_to_id = false;
Greg Clayton427f2902010-12-14 02:59:59 +0000869 const bool unwind_on_error = true;
Sean Callanan6a925532011-01-13 08:53:35 +0000870 const bool keep_in_memory = false;
Greg Clayton427f2902010-12-14 02:59:59 +0000871
Greg Clayton334d33a2012-01-30 07:41:31 +0000872 exe_results = frame_sp->GetThread().GetProcess().GetTarget().EvaluateExpression(expr,
873 frame_sp.get(),
874 eExecutionPolicyOnlyWhenNeeded,
875 coerce_to_id,
876 unwind_on_error,
877 keep_in_memory,
878 fetch_dynamic_value,
879 *expr_result);
Greg Clayton668a6c72011-11-10 18:31:53 +0000880
881 Host::SetCrashDescription (NULL);
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000882 }
Greg Claytona66ba462010-10-30 04:51:46 +0000883
Sean Callanan94d255f2010-12-07 22:55:01 +0000884 if (expr_log)
Jim Inghame41494a2011-04-16 00:01:13 +0000885 expr_log->Printf("** [SBFrame::EvaluateExpression] Expression result is %s, summary %s **",
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000886 expr_result.GetValue(),
887 expr_result.GetSummary());
Sean Callanan94d255f2010-12-07 22:55:01 +0000888
Greg Claytona66ba462010-10-30 04:51:46 +0000889 if (log)
Greg Clayton334d33a2012-01-30 07:41:31 +0000890 log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)", frame_sp.get(),
Jim Inghame41494a2011-04-16 00:01:13 +0000891 expr,
Johnny Chenee6e7902011-08-10 22:06:24 +0000892 expr_result.get(),
893 exe_results);
Greg Claytona66ba462010-10-30 04:51:46 +0000894
Greg Clayton49ce6822010-10-31 03:01:06 +0000895 return expr_result;
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000896}
Greg Clayton582ed0e2011-06-18 20:06:08 +0000897
898bool
899SBFrame::IsInlined()
900{
Greg Clayton334d33a2012-01-30 07:41:31 +0000901 StackFrameSP frame_sp(GetFrameSP());
902 if (frame_sp)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000903 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000904 Block *block = frame_sp->GetSymbolContext(eSymbolContextBlock).block;
Greg Clayton582ed0e2011-06-18 20:06:08 +0000905 if (block)
906 return block->GetContainingInlinedBlock () != NULL;
907 }
908 return false;
909}
910
911const char *
912SBFrame::GetFunctionName()
913{
914 const char *name = NULL;
Greg Clayton334d33a2012-01-30 07:41:31 +0000915 StackFrameSP frame_sp(GetFrameSP());
916 if (frame_sp)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000917 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000918 SymbolContext sc (frame_sp->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol));
Greg Clayton582ed0e2011-06-18 20:06:08 +0000919 if (sc.block)
920 {
921 Block *inlined_block = sc.block->GetContainingInlinedBlock ();
922 if (inlined_block)
923 {
924 const InlineFunctionInfo* inlined_info = inlined_block->GetInlinedFunctionInfo();
925 name = inlined_info->GetName().AsCString();
926 }
927 }
928
929 if (name == NULL)
930 {
931 if (sc.function)
932 name = sc.function->GetName().GetCString();
933 }
934
935 if (name == NULL)
936 {
937 if (sc.symbol)
938 name = sc.symbol->GetName().GetCString();
939 }
940 }
941 return name;
942}
943