blob: 8b7cacca988f7fc9d69c52e89fe94c110be8186a [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"
Greg Clayton49ce8962012-08-29 21:13:06 +000027#include "lldb/Symbol/Function.h"
28#include "lldb/Symbol/Symbol.h"
Chris Lattner24943d22010-06-08 16:52:24 +000029#include "lldb/Symbol/SymbolContext.h"
30#include "lldb/Symbol/VariableList.h"
31#include "lldb/Symbol/Variable.h"
32#include "lldb/Target/ExecutionContext.h"
33#include "lldb/Target/Target.h"
34#include "lldb/Target/Process.h"
35#include "lldb/Target/RegisterContext.h"
36#include "lldb/Target/StackFrame.h"
Greg Clayton334d33a2012-01-30 07:41:31 +000037#include "lldb/Target/StackID.h"
Chris Lattner24943d22010-06-08 16:52:24 +000038#include "lldb/Target/Thread.h"
39
Eli Friedman7a62c8b2010-06-09 07:44:37 +000040#include "lldb/API/SBDebugger.h"
41#include "lldb/API/SBValue.h"
42#include "lldb/API/SBAddress.h"
Jim Ingham47beabb2012-10-16 21:41:58 +000043#include "lldb/API/SBExpressionOptions.h"
Caroline Tice98f930f2010-09-20 05:20:02 +000044#include "lldb/API/SBStream.h"
Eli Friedman7a62c8b2010-06-09 07:44:37 +000045#include "lldb/API/SBSymbolContext.h"
46#include "lldb/API/SBThread.h"
Chris Lattner24943d22010-06-08 16:52:24 +000047
48using namespace lldb;
49using namespace lldb_private;
50
Greg Clayton334d33a2012-01-30 07:41:31 +000051
Chris Lattner24943d22010-06-08 16:52:24 +000052SBFrame::SBFrame () :
Greg Claytona894fe72012-04-05 16:12:35 +000053 m_opaque_sp (new ExecutionContextRef())
Chris Lattner24943d22010-06-08 16:52:24 +000054{
55}
56
Greg Clayton4e9267d2010-12-14 18:39:31 +000057SBFrame::SBFrame (const StackFrameSP &lldb_object_sp) :
Greg Claytona894fe72012-04-05 16:12:35 +000058 m_opaque_sp (new ExecutionContextRef (lldb_object_sp))
Chris Lattner24943d22010-06-08 16:52:24 +000059{
Greg Clayton4e9267d2010-12-14 18:39:31 +000060 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +000061
62 if (log)
63 {
64 SBStream sstr;
65 GetDescription (sstr);
Greg Claytona66ba462010-10-30 04:51:46 +000066 log->Printf ("SBFrame::SBFrame (sp=%p) => SBFrame(%p): %s",
Greg Clayton334d33a2012-01-30 07:41:31 +000067 lldb_object_sp.get(), lldb_object_sp.get(), sstr.GetData());
Caroline Tice61ba7ec2010-10-26 23:49:36 +000068
Caroline Tice7826c882010-10-26 03:11:13 +000069 }
Chris Lattner24943d22010-06-08 16:52:24 +000070}
71
Greg Clayton538eb822010-11-05 23:17:00 +000072SBFrame::SBFrame(const SBFrame &rhs) :
Greg Claytona894fe72012-04-05 16:12:35 +000073 m_opaque_sp (new ExecutionContextRef (*rhs.m_opaque_sp))
Greg Clayton538eb822010-11-05 23:17:00 +000074{
75}
76
77const SBFrame &
78SBFrame::operator = (const SBFrame &rhs)
79{
80 if (this != &rhs)
Greg Claytona894fe72012-04-05 16:12:35 +000081 *m_opaque_sp = *rhs.m_opaque_sp;
Greg Clayton538eb822010-11-05 23:17:00 +000082 return *this;
83}
84
Chris Lattner24943d22010-06-08 16:52:24 +000085SBFrame::~SBFrame()
86{
87}
88
Greg Clayton334d33a2012-01-30 07:41:31 +000089StackFrameSP
90SBFrame::GetFrameSP() const
Chris Lattner24943d22010-06-08 16:52:24 +000091{
Greg Clayton26425852012-04-12 20:58:26 +000092 if (m_opaque_sp)
93 return m_opaque_sp->GetFrameSP();
94 return StackFrameSP();
Chris Lattner24943d22010-06-08 16:52:24 +000095}
96
Greg Clayton334d33a2012-01-30 07:41:31 +000097void
98SBFrame::SetFrameSP (const StackFrameSP &lldb_object_sp)
99{
Greg Claytona894fe72012-04-05 16:12:35 +0000100 return m_opaque_sp->SetFrameSP(lldb_object_sp);
Greg Clayton334d33a2012-01-30 07:41:31 +0000101}
Chris Lattner24943d22010-06-08 16:52:24 +0000102
103bool
104SBFrame::IsValid() const
105{
Greg Claytona894fe72012-04-05 16:12:35 +0000106 return GetFrameSP().get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +0000107}
108
109SBSymbolContext
110SBFrame::GetSymbolContext (uint32_t resolve_scope) const
111{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000112 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +0000113 SBSymbolContext sb_sym_ctx;
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000114 Mutex::Locker api_locker;
115 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
116
Jim Ingham15fd97d2012-11-29 00:26:19 +0000117 StackFrame *frame = NULL;
Greg Clayton289afcb2012-02-18 05:35:26 +0000118 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham15fd97d2012-11-29 00:26:19 +0000119 Process *process = exe_ctx.GetProcessPtr();
120 if (target && process)
Greg Claytonbdcda462010-12-20 20:49:23 +0000121 {
Greg Claytona894fe72012-04-05 16:12:35 +0000122 Process::StopLocker stop_locker;
Jim Ingham15fd97d2012-11-29 00:26:19 +0000123 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Claytona894fe72012-04-05 16:12:35 +0000124 {
Jim Ingham15fd97d2012-11-29 00:26:19 +0000125 frame = exe_ctx.GetFramePtr();
126 if (frame)
127 {
128 sb_sym_ctx.SetSymbolContext(&frame->GetSymbolContext (resolve_scope));
129 }
130 else
131 {
132 if (log)
133 log->Printf ("SBFrame::GetVariables () => error: could not reconstruct frame object for this SBFrame.");
134 }
Greg Claytona894fe72012-04-05 16:12:35 +0000135 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000136 else
137 {
138 if (log)
Jim Ingham15fd97d2012-11-29 00:26:19 +0000139 log->Printf ("SBFrame::GetSymbolContext () => error: process is running");
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000140 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000141 }
Caroline Tice7826c882010-10-26 03:11:13 +0000142
143 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000144 log->Printf ("SBFrame(%p)::GetSymbolContext (resolve_scope=0x%8.8x) => SBSymbolContext(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000145 frame, resolve_scope, sb_sym_ctx.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000146
Chris Lattner24943d22010-06-08 16:52:24 +0000147 return sb_sym_ctx;
148}
149
150SBModule
151SBFrame::GetModule () const
152{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000153 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytondd62d722010-12-14 04:58:53 +0000154 SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000155 ModuleSP module_sp;
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000156 Mutex::Locker api_locker;
157 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
158
Jim Ingham15fd97d2012-11-29 00:26:19 +0000159 StackFrame *frame = NULL;
Greg Clayton289afcb2012-02-18 05:35:26 +0000160 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham15fd97d2012-11-29 00:26:19 +0000161 Process *process = exe_ctx.GetProcessPtr();
162 if (target && process)
Greg Claytonbdcda462010-12-20 20:49:23 +0000163 {
Greg Claytona894fe72012-04-05 16:12:35 +0000164 Process::StopLocker stop_locker;
Jim Ingham15fd97d2012-11-29 00:26:19 +0000165 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Claytona894fe72012-04-05 16:12:35 +0000166 {
Jim Ingham15fd97d2012-11-29 00:26:19 +0000167 frame = exe_ctx.GetFramePtr();
168 if (frame)
169 {
170 module_sp = frame->GetSymbolContext (eSymbolContextModule).module_sp;
171 sb_module.SetSP (module_sp);
172 }
173 else
174 {
175 if (log)
176 log->Printf ("SBFrame::GetModule () => error: could not reconstruct frame object for this SBFrame.");
177 }
Greg Claytona894fe72012-04-05 16:12:35 +0000178 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000179 else
180 {
181 if (log)
Jim Ingham15fd97d2012-11-29 00:26:19 +0000182 log->Printf ("SBFrame::GetModule () => error: process is running");
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000183 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000184 }
Greg Claytondd62d722010-12-14 04:58:53 +0000185
Greg Claytona66ba462010-10-30 04:51:46 +0000186 if (log)
187 log->Printf ("SBFrame(%p)::GetModule () => SBModule(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000188 frame, module_sp.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000189
Chris Lattner24943d22010-06-08 16:52:24 +0000190 return sb_module;
191}
192
193SBCompileUnit
194SBFrame::GetCompileUnit () const
195{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000196 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytondd62d722010-12-14 04:58:53 +0000197 SBCompileUnit sb_comp_unit;
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000198 Mutex::Locker api_locker;
199 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
200
Jim Ingham15fd97d2012-11-29 00:26:19 +0000201 StackFrame *frame = NULL;
Greg Clayton289afcb2012-02-18 05:35:26 +0000202 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham15fd97d2012-11-29 00:26:19 +0000203 Process *process = exe_ctx.GetProcessPtr();
204 if (target && process)
Greg Claytonbdcda462010-12-20 20:49:23 +0000205 {
Greg Claytona894fe72012-04-05 16:12:35 +0000206 Process::StopLocker stop_locker;
Jim Ingham15fd97d2012-11-29 00:26:19 +0000207 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Claytona894fe72012-04-05 16:12:35 +0000208 {
Jim Ingham15fd97d2012-11-29 00:26:19 +0000209 frame = exe_ctx.GetFramePtr();
210 if (frame)
211 {
212 sb_comp_unit.reset (frame->GetSymbolContext (eSymbolContextCompUnit).comp_unit);
213 }
214 else
215 {
216 if (log)
217 log->Printf ("SBFrame::GetCompileUnit () => error: could not reconstruct frame object for this SBFrame.");
218 }
Greg Claytona894fe72012-04-05 16:12:35 +0000219 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000220 else
221 {
222 if (log)
Jim Ingham15fd97d2012-11-29 00:26:19 +0000223 log->Printf ("SBFrame::GetCompileUnit () => error: process is running");
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000224 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000225 }
Caroline Tice7826c882010-10-26 03:11:13 +0000226 if (log)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000227 log->Printf ("SBFrame(%p)::GetCompileUnit () => SBCompileUnit(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000228 frame, sb_comp_unit.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000229
Chris Lattner24943d22010-06-08 16:52:24 +0000230 return sb_comp_unit;
231}
232
233SBFunction
234SBFrame::GetFunction () const
235{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000236 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytondd62d722010-12-14 04:58:53 +0000237 SBFunction sb_function;
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000238 Mutex::Locker api_locker;
239 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
240
Jim Ingham15fd97d2012-11-29 00:26:19 +0000241 StackFrame *frame = NULL;
Greg Clayton289afcb2012-02-18 05:35:26 +0000242 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham15fd97d2012-11-29 00:26:19 +0000243 Process *process = exe_ctx.GetProcessPtr();
244 if (target && process)
Greg Claytonbdcda462010-12-20 20:49:23 +0000245 {
Greg Claytona894fe72012-04-05 16:12:35 +0000246 Process::StopLocker stop_locker;
Jim Ingham15fd97d2012-11-29 00:26:19 +0000247 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Claytona894fe72012-04-05 16:12:35 +0000248 {
Jim Ingham15fd97d2012-11-29 00:26:19 +0000249 frame = exe_ctx.GetFramePtr();
250 if (frame)
251 {
252 sb_function.reset(frame->GetSymbolContext (eSymbolContextFunction).function);
253 }
254 else
255 {
256 if (log)
257 log->Printf ("SBFrame::GetFunction () => error: could not reconstruct frame object for this SBFrame.");
258 }
Greg Claytona894fe72012-04-05 16:12:35 +0000259 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000260 else
261 {
262 if (log)
Jim Ingham15fd97d2012-11-29 00:26:19 +0000263 log->Printf ("SBFrame::GetFunction () => error: process is running");
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000264 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000265 }
Greg Claytona66ba462010-10-30 04:51:46 +0000266 if (log)
267 log->Printf ("SBFrame(%p)::GetFunction () => SBFunction(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000268 frame, sb_function.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000269
Chris Lattner24943d22010-06-08 16:52:24 +0000270 return sb_function;
271}
272
Greg Clayton8f1e08b2010-10-04 18:37:52 +0000273SBSymbol
274SBFrame::GetSymbol () const
275{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000276 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytondd62d722010-12-14 04:58:53 +0000277 SBSymbol sb_symbol;
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000278 Mutex::Locker api_locker;
279 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
280
Jim Ingham15fd97d2012-11-29 00:26:19 +0000281 StackFrame *frame = NULL;
Greg Clayton289afcb2012-02-18 05:35:26 +0000282 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham15fd97d2012-11-29 00:26:19 +0000283 Process *process = exe_ctx.GetProcessPtr();
284 if (target && process)
Greg Claytonbdcda462010-12-20 20:49:23 +0000285 {
Greg Claytona894fe72012-04-05 16:12:35 +0000286 Process::StopLocker stop_locker;
Jim Ingham15fd97d2012-11-29 00:26:19 +0000287 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Claytona894fe72012-04-05 16:12:35 +0000288 {
Jim Ingham15fd97d2012-11-29 00:26:19 +0000289 frame = exe_ctx.GetFramePtr();
290 if (frame)
291 {
292 sb_symbol.reset(frame->GetSymbolContext (eSymbolContextSymbol).symbol);
293 }
294 else
295 {
296 if (log)
297 log->Printf ("SBFrame::GetSymbol () => error: could not reconstruct frame object for this SBFrame.");
298 }
Greg Claytona894fe72012-04-05 16:12:35 +0000299 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000300 else
301 {
302 if (log)
Jim Ingham15fd97d2012-11-29 00:26:19 +0000303 log->Printf ("SBFrame::GetSymbol () => error: process is running");
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000304 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000305 }
Greg Claytona66ba462010-10-30 04:51:46 +0000306 if (log)
307 log->Printf ("SBFrame(%p)::GetSymbol () => SBSymbol(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000308 frame, sb_symbol.get());
Greg Clayton8f1e08b2010-10-04 18:37:52 +0000309 return sb_symbol;
310}
311
Chris Lattner24943d22010-06-08 16:52:24 +0000312SBBlock
313SBFrame::GetBlock () const
314{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000315 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytondd62d722010-12-14 04:58:53 +0000316 SBBlock sb_block;
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000317 Mutex::Locker api_locker;
318 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
319
Jim Ingham15fd97d2012-11-29 00:26:19 +0000320 StackFrame *frame = NULL;
Greg Clayton289afcb2012-02-18 05:35:26 +0000321 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham15fd97d2012-11-29 00:26:19 +0000322 Process *process = exe_ctx.GetProcessPtr();
323 if (target && process)
Greg Claytonbdcda462010-12-20 20:49:23 +0000324 {
Greg Claytona894fe72012-04-05 16:12:35 +0000325 Process::StopLocker stop_locker;
Jim Ingham15fd97d2012-11-29 00:26:19 +0000326 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Claytona894fe72012-04-05 16:12:35 +0000327 {
Jim Ingham15fd97d2012-11-29 00:26:19 +0000328 frame = exe_ctx.GetFramePtr();
329 if (frame)
330 {
331 sb_block.SetPtr (frame->GetSymbolContext (eSymbolContextBlock).block);
332 }
333 else
334 {
335 if (log)
336 log->Printf ("SBFrame::GetBlock () => error: could not reconstruct frame object for this SBFrame.");
337 }
Greg Claytona894fe72012-04-05 16:12:35 +0000338 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000339 else
340 {
341 if (log)
342 log->Printf ("SBFrame(%p)::GetBlock () => error: process is running", frame);
343 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000344 }
Greg Claytona66ba462010-10-30 04:51:46 +0000345 if (log)
346 log->Printf ("SBFrame(%p)::GetBlock () => SBBlock(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000347 frame, sb_block.GetPtr());
Chris Lattner24943d22010-06-08 16:52:24 +0000348 return sb_block;
349}
350
Greg Clayton69aa5d92010-09-07 04:20:48 +0000351SBBlock
352SBFrame::GetFrameBlock () const
353{
Greg Claytondd62d722010-12-14 04:58:53 +0000354 SBBlock sb_block;
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000355 Mutex::Locker api_locker;
356 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
357
Jim Ingham15fd97d2012-11-29 00:26:19 +0000358 StackFrame *frame = NULL;
Greg Clayton289afcb2012-02-18 05:35:26 +0000359 Target *target = exe_ctx.GetTargetPtr();
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000360 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham15fd97d2012-11-29 00:26:19 +0000361 Process *process = exe_ctx.GetProcessPtr();
362 if (target && process)
Greg Claytonbdcda462010-12-20 20:49:23 +0000363 {
Greg Claytona894fe72012-04-05 16:12:35 +0000364 Process::StopLocker stop_locker;
Jim Ingham15fd97d2012-11-29 00:26:19 +0000365 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Claytona894fe72012-04-05 16:12:35 +0000366 {
Jim Ingham15fd97d2012-11-29 00:26:19 +0000367 frame = exe_ctx.GetFramePtr();
368 if (frame)
369 {
370 sb_block.SetPtr(frame->GetFrameBlock ());
371 }
372 else
373 {
374 if (log)
375 log->Printf ("SBFrame::GetFrameBlock () => error: could not reconstruct frame object for this SBFrame.");
376 }
Greg Claytona894fe72012-04-05 16:12:35 +0000377 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000378 else
379 {
380 if (log)
Jim Ingham15fd97d2012-11-29 00:26:19 +0000381 log->Printf ("SBFrame::GetFrameBlock () => error: process is running");
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000382 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000383 }
Greg Claytona66ba462010-10-30 04:51:46 +0000384 if (log)
385 log->Printf ("SBFrame(%p)::GetFrameBlock () => SBBlock(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000386 frame, sb_block.GetPtr());
Greg Clayton69aa5d92010-09-07 04:20:48 +0000387 return sb_block;
388}
389
Chris Lattner24943d22010-06-08 16:52:24 +0000390SBLineEntry
391SBFrame::GetLineEntry () const
392{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000393 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytondd62d722010-12-14 04:58:53 +0000394 SBLineEntry sb_line_entry;
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000395 Mutex::Locker api_locker;
396 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
397
Jim Ingham15fd97d2012-11-29 00:26:19 +0000398 StackFrame *frame = NULL;
Greg Clayton289afcb2012-02-18 05:35:26 +0000399 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham15fd97d2012-11-29 00:26:19 +0000400 Process *process = exe_ctx.GetProcessPtr();
401 if (target && process)
Greg Claytonbdcda462010-12-20 20:49:23 +0000402 {
Greg Claytona894fe72012-04-05 16:12:35 +0000403 Process::StopLocker stop_locker;
Jim Ingham15fd97d2012-11-29 00:26:19 +0000404 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Claytona894fe72012-04-05 16:12:35 +0000405 {
Jim Ingham15fd97d2012-11-29 00:26:19 +0000406 frame = exe_ctx.GetFramePtr();
407 if (frame)
408 {
409 sb_line_entry.SetLineEntry (frame->GetSymbolContext (eSymbolContextLineEntry).line_entry);
410 }
411 else
412 {
413 if (log)
414 log->Printf ("SBFrame::GetLineEntry () => error: could not reconstruct frame object for this SBFrame.");
415 }
Greg Claytona894fe72012-04-05 16:12:35 +0000416 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000417 else
418 {
419 if (log)
Jim Ingham15fd97d2012-11-29 00:26:19 +0000420 log->Printf ("SBFrame::GetLineEntry () => error: process is running");
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000421 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000422 }
Greg Claytona66ba462010-10-30 04:51:46 +0000423 if (log)
424 log->Printf ("SBFrame(%p)::GetLineEntry () => SBLineEntry(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000425 frame, sb_line_entry.get());
Chris Lattner24943d22010-06-08 16:52:24 +0000426 return sb_line_entry;
427}
428
429uint32_t
430SBFrame::GetFrameID () const
431{
Greg Clayton334d33a2012-01-30 07:41:31 +0000432 uint32_t frame_idx = UINT32_MAX;
433
Greg Claytona894fe72012-04-05 16:12:35 +0000434 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000435 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Claytona894fe72012-04-05 16:12:35 +0000436 if (frame)
Greg Clayton289afcb2012-02-18 05:35:26 +0000437 frame_idx = frame->GetFrameIndex ();
Greg Claytona66ba462010-10-30 04:51:46 +0000438
Greg Clayton4e9267d2010-12-14 18:39:31 +0000439 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000440 if (log)
441 log->Printf ("SBFrame(%p)::GetFrameID () => %u",
Greg Clayton289afcb2012-02-18 05:35:26 +0000442 frame, frame_idx);
Greg Claytona66ba462010-10-30 04:51:46 +0000443 return frame_idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000444}
445
Greg Clayton4e9267d2010-12-14 18:39:31 +0000446addr_t
Chris Lattner24943d22010-06-08 16:52:24 +0000447SBFrame::GetPC () const
448{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000449 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton4e9267d2010-12-14 18:39:31 +0000450 addr_t addr = LLDB_INVALID_ADDRESS;
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000451 Mutex::Locker api_locker;
452 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
453
Jim Ingham15fd97d2012-11-29 00:26:19 +0000454 StackFrame *frame = NULL;
Greg Clayton289afcb2012-02-18 05:35:26 +0000455 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham15fd97d2012-11-29 00:26:19 +0000456 Process *process = exe_ctx.GetProcessPtr();
457 if (target && process)
Greg Claytonbdcda462010-12-20 20:49:23 +0000458 {
Greg Claytona894fe72012-04-05 16:12:35 +0000459 Process::StopLocker stop_locker;
Jim Ingham15fd97d2012-11-29 00:26:19 +0000460 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Claytona894fe72012-04-05 16:12:35 +0000461 {
Jim Ingham15fd97d2012-11-29 00:26:19 +0000462 frame = exe_ctx.GetFramePtr();
463 if (frame)
464 {
465 addr = frame->GetFrameCodeAddress().GetOpcodeLoadAddress (target);
466 }
467 else
468 {
469 if (log)
470 log->Printf ("SBFrame::GetPC () => error: could not reconstruct frame object for this SBFrame.");
471 }
Greg Claytona894fe72012-04-05 16:12:35 +0000472 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000473 else
474 {
475 if (log)
Jim Ingham15fd97d2012-11-29 00:26:19 +0000476 log->Printf ("SBFrame::GetPC () => error: process is running");
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000477 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000478 }
Caroline Tice7826c882010-10-26 03:11:13 +0000479
480 if (log)
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000481 log->Printf ("SBFrame(%p)::GetPC () => 0x%" PRIx64, frame, addr);
Caroline Tice7826c882010-10-26 03:11:13 +0000482
483 return addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000484}
485
486bool
Greg Clayton4e9267d2010-12-14 18:39:31 +0000487SBFrame::SetPC (addr_t new_pc)
Chris Lattner24943d22010-06-08 16:52:24 +0000488{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000489 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000490 bool ret_val = false;
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000491 Mutex::Locker api_locker;
492 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
493
Jim Ingham15fd97d2012-11-29 00:26:19 +0000494 StackFrame *frame = NULL;
Greg Clayton289afcb2012-02-18 05:35:26 +0000495 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham15fd97d2012-11-29 00:26:19 +0000496 Process *process = exe_ctx.GetProcessPtr();
497 if (target && process)
Greg Claytonbdcda462010-12-20 20:49:23 +0000498 {
Greg Claytona894fe72012-04-05 16:12:35 +0000499 Process::StopLocker stop_locker;
Jim Ingham15fd97d2012-11-29 00:26:19 +0000500 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Claytona894fe72012-04-05 16:12:35 +0000501 {
Jim Ingham15fd97d2012-11-29 00:26:19 +0000502 frame = exe_ctx.GetFramePtr();
503 if (frame)
504 {
505 ret_val = frame->GetRegisterContext()->SetPC (new_pc);
506 }
507 else
508 {
509 if (log)
510 log->Printf ("SBFrame::SetPC () => error: could not reconstruct frame object for this SBFrame.");
511 }
Greg Claytona894fe72012-04-05 16:12:35 +0000512 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000513 else
514 {
515 if (log)
Jim Ingham15fd97d2012-11-29 00:26:19 +0000516 log->Printf ("SBFrame::SetPC () => error: process is running");
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000517 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000518 }
Caroline Tice7826c882010-10-26 03:11:13 +0000519
520 if (log)
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000521 log->Printf ("SBFrame(%p)::SetPC (new_pc=0x%" PRIx64 ") => %i",
Greg Clayton289afcb2012-02-18 05:35:26 +0000522 frame, new_pc, ret_val);
Caroline Tice7826c882010-10-26 03:11:13 +0000523
524 return ret_val;
Chris Lattner24943d22010-06-08 16:52:24 +0000525}
526
Greg Clayton4e9267d2010-12-14 18:39:31 +0000527addr_t
Chris Lattner24943d22010-06-08 16:52:24 +0000528SBFrame::GetSP () const
529{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000530 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000531 addr_t addr = LLDB_INVALID_ADDRESS;
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000532 Mutex::Locker api_locker;
533 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
534
Jim Ingham15fd97d2012-11-29 00:26:19 +0000535 StackFrame *frame = NULL;
Greg Clayton289afcb2012-02-18 05:35:26 +0000536 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham15fd97d2012-11-29 00:26:19 +0000537 Process *process = exe_ctx.GetProcessPtr();
538 if (target && process)
Greg Claytonbdcda462010-12-20 20:49:23 +0000539 {
Greg Claytona894fe72012-04-05 16:12:35 +0000540 Process::StopLocker stop_locker;
Jim Ingham15fd97d2012-11-29 00:26:19 +0000541 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Claytona894fe72012-04-05 16:12:35 +0000542 {
Jim Ingham15fd97d2012-11-29 00:26:19 +0000543 frame = exe_ctx.GetFramePtr();
544 if (frame)
545 {
546 addr = frame->GetRegisterContext()->GetSP();
547 }
548 else
549 {
550 if (log)
551 log->Printf ("SBFrame::GetSP () => error: could not reconstruct frame object for this SBFrame.");
552 }
Greg Claytona894fe72012-04-05 16:12:35 +0000553 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000554 else
555 {
556 if (log)
Jim Ingham15fd97d2012-11-29 00:26:19 +0000557 log->Printf ("SBFrame::GetSP () => error: process is running");
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000558 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000559 }
Greg Claytona66ba462010-10-30 04:51:46 +0000560 if (log)
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000561 log->Printf ("SBFrame(%p)::GetSP () => 0x%" PRIx64, frame, addr);
Greg Claytona66ba462010-10-30 04:51:46 +0000562
563 return addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000564}
565
566
Greg Clayton4e9267d2010-12-14 18:39:31 +0000567addr_t
Chris Lattner24943d22010-06-08 16:52:24 +0000568SBFrame::GetFP () const
569{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000570 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton4e9267d2010-12-14 18:39:31 +0000571 addr_t addr = LLDB_INVALID_ADDRESS;
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000572 Mutex::Locker api_locker;
573 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
574
Jim Ingham15fd97d2012-11-29 00:26:19 +0000575 StackFrame *frame = NULL;
Greg Clayton289afcb2012-02-18 05:35:26 +0000576 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham15fd97d2012-11-29 00:26:19 +0000577 Process *process = exe_ctx.GetProcessPtr();
578 if (target && process)
Greg Claytonbdcda462010-12-20 20:49:23 +0000579 {
Greg Claytona894fe72012-04-05 16:12:35 +0000580 Process::StopLocker stop_locker;
Jim Ingham15fd97d2012-11-29 00:26:19 +0000581 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Claytona894fe72012-04-05 16:12:35 +0000582 {
Jim Ingham15fd97d2012-11-29 00:26:19 +0000583 frame = exe_ctx.GetFramePtr();
584 if (frame)
585 {
586 addr = frame->GetRegisterContext()->GetFP();
587 }
588 else
589 {
590 if (log)
591 log->Printf ("SBFrame::GetFP () => error: could not reconstruct frame object for this SBFrame.");
592 }
Greg Claytona894fe72012-04-05 16:12:35 +0000593 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000594 else
595 {
596 if (log)
Jim Ingham15fd97d2012-11-29 00:26:19 +0000597 log->Printf ("SBFrame::GetFP () => error: process is running");
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000598 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000599 }
Caroline Tice7826c882010-10-26 03:11:13 +0000600
601 if (log)
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000602 log->Printf ("SBFrame(%p)::GetFP () => 0x%" PRIx64, frame, addr);
Caroline Tice7826c882010-10-26 03:11:13 +0000603 return addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000604}
605
606
607SBAddress
608SBFrame::GetPCAddress () const
609{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000610 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +0000611 SBAddress sb_addr;
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000612 Mutex::Locker api_locker;
613 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
614
Greg Clayton289afcb2012-02-18 05:35:26 +0000615 StackFrame *frame = exe_ctx.GetFramePtr();
616 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham15fd97d2012-11-29 00:26:19 +0000617 Process *process = exe_ctx.GetProcessPtr();
618 if (target && process)
Greg Claytonbdcda462010-12-20 20:49:23 +0000619 {
Greg Claytona894fe72012-04-05 16:12:35 +0000620 Process::StopLocker stop_locker;
Jim Ingham15fd97d2012-11-29 00:26:19 +0000621 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Claytona894fe72012-04-05 16:12:35 +0000622 {
Jim Ingham15fd97d2012-11-29 00:26:19 +0000623 frame = exe_ctx.GetFramePtr();
624 if (frame)
625 {
626 sb_addr.SetAddress (&frame->GetFrameCodeAddress());
627 }
628 else
629 {
630 if (log)
631 log->Printf ("SBFrame::GetPCAddress () => error: could not reconstruct frame object for this SBFrame.");
632 }
Greg Claytona894fe72012-04-05 16:12:35 +0000633 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000634 else
635 {
636 if (log)
Jim Ingham15fd97d2012-11-29 00:26:19 +0000637 log->Printf ("SBFrame::GetPCAddress () => error: process is running");
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000638 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000639 }
Greg Claytona66ba462010-10-30 04:51:46 +0000640 if (log)
Greg Clayton289afcb2012-02-18 05:35:26 +0000641 log->Printf ("SBFrame(%p)::GetPCAddress () => SBAddress(%p)", frame, sb_addr.get());
Chris Lattner24943d22010-06-08 16:52:24 +0000642 return sb_addr;
643}
644
645void
646SBFrame::Clear()
647{
Greg Clayton26425852012-04-12 20:58:26 +0000648 m_opaque_sp->Clear();
Chris Lattner24943d22010-06-08 16:52:24 +0000649}
650
Greg Claytond62b9c12012-02-03 07:02:37 +0000651lldb::SBValue
652SBFrame::GetValueForVariablePath (const char *var_path)
653{
654 SBValue sb_value;
Greg Claytona894fe72012-04-05 16:12:35 +0000655 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000656 StackFrame *frame = exe_ctx.GetFramePtr();
657 Target *target = exe_ctx.GetTargetPtr();
658 if (frame && target)
Greg Claytond62b9c12012-02-03 07:02:37 +0000659 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000660 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
661 sb_value = GetValueForVariablePath (var_path, use_dynamic);
Greg Claytond62b9c12012-02-03 07:02:37 +0000662 }
663 return sb_value;
664}
665
666lldb::SBValue
667SBFrame::GetValueForVariablePath (const char *var_path, DynamicValueType use_dynamic)
668{
669 SBValue sb_value;
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000670 Mutex::Locker api_locker;
Jim Ingham15fd97d2012-11-29 00:26:19 +0000671 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
672 if (var_path == NULL || var_path[0] == '\0')
673 {
674 if (log)
675 log->Printf ("SBFrame::GetValueForVariablePath called with empty variable path.");
676 return sb_value;
677 }
678
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000679 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
680
Greg Clayton289afcb2012-02-18 05:35:26 +0000681 StackFrame *frame = exe_ctx.GetFramePtr();
682 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham15fd97d2012-11-29 00:26:19 +0000683 Process *process = exe_ctx.GetProcessPtr();
684 if (target && process)
Greg Claytond62b9c12012-02-03 07:02:37 +0000685 {
Greg Claytona894fe72012-04-05 16:12:35 +0000686 Process::StopLocker stop_locker;
Jim Ingham15fd97d2012-11-29 00:26:19 +0000687 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Claytona894fe72012-04-05 16:12:35 +0000688 {
Jim Ingham15fd97d2012-11-29 00:26:19 +0000689 frame = exe_ctx.GetFramePtr();
690 if (frame)
691 {
692 VariableSP var_sp;
693 Error error;
694 ValueObjectSP value_sp (frame->GetValueForVariableExpressionPath (var_path,
695 eNoDynamicValues,
696 StackFrame::eExpressionPathOptionCheckPtrVsMember | StackFrame::eExpressionPathOptionsAllowDirectIVarAccess,
697 var_sp,
698 error));
699 sb_value.SetSP(value_sp, use_dynamic);
700 }
701 else
702 {
703 if (log)
704 log->Printf ("SBFrame::GetValueForVariablePath () => error: could not reconstruct frame object for this SBFrame.");
705 }
Greg Claytona894fe72012-04-05 16:12:35 +0000706 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000707 else
708 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000709 if (log)
Jim Ingham15fd97d2012-11-29 00:26:19 +0000710 log->Printf ("SBFrame::GetValueForVariablePath () => error: process is running");
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000711 }
Greg Claytond62b9c12012-02-03 07:02:37 +0000712 }
713 return sb_value;
714}
715
Chris Lattner24943d22010-06-08 16:52:24 +0000716SBValue
Greg Clayton4e9267d2010-12-14 18:39:31 +0000717SBFrame::FindVariable (const char *name)
Chris Lattner24943d22010-06-08 16:52:24 +0000718{
Greg Clayton582ed0e2011-06-18 20:06:08 +0000719 SBValue value;
Greg Claytona894fe72012-04-05 16:12:35 +0000720 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000721 StackFrame *frame = exe_ctx.GetFramePtr();
722 Target *target = exe_ctx.GetTargetPtr();
723 if (frame && target)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000724 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000725 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton582ed0e2011-06-18 20:06:08 +0000726 value = FindVariable (name, use_dynamic);
727 }
728 return value;
Jim Inghame41494a2011-04-16 00:01:13 +0000729}
Greg Claytond62b9c12012-02-03 07:02:37 +0000730
Jim Inghame41494a2011-04-16 00:01:13 +0000731
732SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000733SBFrame::FindVariable (const char *name, lldb::DynamicValueType use_dynamic)
Jim Inghame41494a2011-04-16 00:01:13 +0000734{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000735 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton4e9267d2010-12-14 18:39:31 +0000736 VariableSP var_sp;
Jim Ingham47da8102011-04-22 23:53:53 +0000737 SBValue sb_value;
Jim Ingham15fd97d2012-11-29 00:26:19 +0000738
739 if (name == NULL || name[0] == '\0')
740 {
741 if (log)
742 log->Printf ("SBFrame::FindVariable called with empty name");
743 return sb_value;
744 }
745
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000746 ValueObjectSP value_sp;
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000747 Mutex::Locker api_locker;
748 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
749
Jim Ingham15fd97d2012-11-29 00:26:19 +0000750 StackFrame *frame = NULL;
Greg Clayton289afcb2012-02-18 05:35:26 +0000751 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham15fd97d2012-11-29 00:26:19 +0000752 Process *process = exe_ctx.GetProcessPtr();
753 if (target && process)
Chris Lattner24943d22010-06-08 16:52:24 +0000754 {
Greg Claytona894fe72012-04-05 16:12:35 +0000755 Process::StopLocker stop_locker;
Jim Ingham15fd97d2012-11-29 00:26:19 +0000756 if (stop_locker.TryLock(&process->GetRunLock()))
Chris Lattner24943d22010-06-08 16:52:24 +0000757 {
Jim Ingham15fd97d2012-11-29 00:26:19 +0000758 frame = exe_ctx.GetFramePtr();
759 if (frame)
Greg Claytondd62d722010-12-14 04:58:53 +0000760 {
Jim Ingham15fd97d2012-11-29 00:26:19 +0000761 VariableList variable_list;
762 SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock));
763
764 if (sc.block)
Greg Claytona894fe72012-04-05 16:12:35 +0000765 {
Jim Ingham15fd97d2012-11-29 00:26:19 +0000766 const bool can_create = true;
767 const bool get_parent_variables = true;
768 const bool stop_if_block_is_inlined_function = true;
769
770 if (sc.block->AppendVariables (can_create,
771 get_parent_variables,
772 stop_if_block_is_inlined_function,
773 &variable_list))
774 {
775 var_sp = variable_list.FindVariable (ConstString(name));
776 }
777 }
778
779 if (var_sp)
780 {
781 value_sp = frame->GetValueObjectForFrameVariable(var_sp, eNoDynamicValues);
782 sb_value.SetSP(value_sp, use_dynamic);
Greg Claytona894fe72012-04-05 16:12:35 +0000783 }
784 }
Jim Ingham15fd97d2012-11-29 00:26:19 +0000785 else
Greg Claytona894fe72012-04-05 16:12:35 +0000786 {
Jim Ingham15fd97d2012-11-29 00:26:19 +0000787 if (log)
788 log->Printf ("SBFrame::FindVariable () => error: could not reconstruct frame object for this SBFrame.");
Greg Claytondd62d722010-12-14 04:58:53 +0000789 }
Chris Lattner24943d22010-06-08 16:52:24 +0000790 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000791 else
792 {
793 if (log)
Jim Ingham15fd97d2012-11-29 00:26:19 +0000794 log->Printf ("SBFrame::FindVariable () => error: process is running");
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000795 }
Chris Lattner24943d22010-06-08 16:52:24 +0000796 }
Caroline Tice98f930f2010-09-20 05:20:02 +0000797
Greg Claytona66ba462010-10-30 04:51:46 +0000798 if (log)
Greg Clayton4e9267d2010-12-14 18:39:31 +0000799 log->Printf ("SBFrame(%p)::FindVariable (name=\"%s\") => SBValue(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000800 frame, name, value_sp.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000801
Chris Lattner24943d22010-06-08 16:52:24 +0000802 return sb_value;
803}
804
805SBValue
Greg Clayton4e9267d2010-12-14 18:39:31 +0000806SBFrame::FindValue (const char *name, ValueType value_type)
Chris Lattner24943d22010-06-08 16:52:24 +0000807{
Greg Clayton582ed0e2011-06-18 20:06:08 +0000808 SBValue value;
Greg Claytona894fe72012-04-05 16:12:35 +0000809 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000810 StackFrame *frame = exe_ctx.GetFramePtr();
811 Target *target = exe_ctx.GetTargetPtr();
812 if (frame && target)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000813 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000814 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton582ed0e2011-06-18 20:06:08 +0000815 value = FindValue (name, value_type, use_dynamic);
816 }
817 return value;
Jim Inghame41494a2011-04-16 00:01:13 +0000818}
819
820SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000821SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueType use_dynamic)
Jim Inghame41494a2011-04-16 00:01:13 +0000822{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000823 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton4e9267d2010-12-14 18:39:31 +0000824 SBValue sb_value;
Jim Ingham15fd97d2012-11-29 00:26:19 +0000825
826 if (name == NULL || name[0] == '\0')
827 {
828 if (log)
829 log->Printf ("SBFrame::FindValue called with empty name.");
830 return sb_value;
831 }
832
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000833 ValueObjectSP value_sp;
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000834 Mutex::Locker api_locker;
835 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
836
Jim Ingham15fd97d2012-11-29 00:26:19 +0000837 StackFrame *frame = NULL;
Greg Clayton289afcb2012-02-18 05:35:26 +0000838 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham15fd97d2012-11-29 00:26:19 +0000839 Process *process = exe_ctx.GetProcessPtr();
840 if (target && process)
Chris Lattner24943d22010-06-08 16:52:24 +0000841 {
Greg Claytona894fe72012-04-05 16:12:35 +0000842 Process::StopLocker stop_locker;
Jim Ingham15fd97d2012-11-29 00:26:19 +0000843 if (stop_locker.TryLock(&process->GetRunLock()))
Chris Lattner24943d22010-06-08 16:52:24 +0000844 {
Jim Ingham15fd97d2012-11-29 00:26:19 +0000845 frame = exe_ctx.GetFramePtr();
846 if (frame)
Chris Lattner24943d22010-06-08 16:52:24 +0000847 {
Jim Ingham15fd97d2012-11-29 00:26:19 +0000848 switch (value_type)
Greg Claytona894fe72012-04-05 16:12:35 +0000849 {
Jim Ingham15fd97d2012-11-29 00:26:19 +0000850 case eValueTypeVariableGlobal: // global variable
851 case eValueTypeVariableStatic: // static variable
852 case eValueTypeVariableArgument: // function argument variables
853 case eValueTypeVariableLocal: // function local variables
854 {
855 VariableList *variable_list = frame->GetVariableList(true);
Greg Clayton4e9267d2010-12-14 18:39:31 +0000856
Jim Ingham15fd97d2012-11-29 00:26:19 +0000857 SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock));
Greg Clayton4e9267d2010-12-14 18:39:31 +0000858
Jim Ingham15fd97d2012-11-29 00:26:19 +0000859 const bool can_create = true;
860 const bool get_parent_variables = true;
861 const bool stop_if_block_is_inlined_function = true;
Greg Clayton4e9267d2010-12-14 18:39:31 +0000862
Jim Ingham15fd97d2012-11-29 00:26:19 +0000863 if (sc.block && sc.block->AppendVariables (can_create,
864 get_parent_variables,
865 stop_if_block_is_inlined_function,
866 variable_list))
867 {
868 ConstString const_name(name);
869 const uint32_t num_variables = variable_list->GetSize();
870 for (uint32_t i = 0; i < num_variables; ++i)
871 {
872 VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
873 if (variable_sp &&
874 variable_sp->GetScope() == value_type &&
875 variable_sp->GetName() == const_name)
876 {
877 value_sp = frame->GetValueObjectForFrameVariable (variable_sp, eNoDynamicValues);
878 sb_value.SetSP (value_sp, use_dynamic);
879 break;
880 }
881 }
882 }
883 }
884 break;
885
886 case eValueTypeRegister: // stack frame register value
887 {
888 RegisterContextSP reg_ctx (frame->GetRegisterContext());
889 if (reg_ctx)
890 {
891 const uint32_t num_regs = reg_ctx->GetRegisterCount();
892 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx)
893 {
894 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
895 if (reg_info &&
896 ((reg_info->name && strcasecmp (reg_info->name, name) == 0) ||
897 (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0)))
898 {
899 value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx);
900 sb_value.SetSP (value_sp);
901 break;
902 }
903 }
904 }
905 }
906 break;
907
908 case eValueTypeRegisterSet: // A collection of stack frame register values
909 {
910 RegisterContextSP reg_ctx (frame->GetRegisterContext());
911 if (reg_ctx)
912 {
913 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
914 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
915 {
916 const RegisterSet *reg_set = reg_ctx->GetRegisterSet (set_idx);
917 if (reg_set &&
918 ((reg_set->name && strcasecmp (reg_set->name, name) == 0) ||
919 (reg_set->short_name && strcasecmp (reg_set->short_name, name) == 0)))
920 {
921 value_sp = ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx);
922 sb_value.SetSP (value_sp);
923 break;
924 }
925 }
926 }
927 }
928 break;
929
930 case eValueTypeConstResult: // constant result variables
Greg Claytona894fe72012-04-05 16:12:35 +0000931 {
932 ConstString const_name(name);
Jim Ingham15fd97d2012-11-29 00:26:19 +0000933 ClangExpressionVariableSP expr_var_sp (target->GetPersistentVariables().GetVariable (const_name));
934 if (expr_var_sp)
Greg Claytona894fe72012-04-05 16:12:35 +0000935 {
Jim Ingham15fd97d2012-11-29 00:26:19 +0000936 value_sp = expr_var_sp->GetValueObject();
937 sb_value.SetSP (value_sp, use_dynamic);
Greg Claytona894fe72012-04-05 16:12:35 +0000938 }
939 }
Jim Ingham15fd97d2012-11-29 00:26:19 +0000940 break;
Greg Claytona894fe72012-04-05 16:12:35 +0000941
Jim Ingham15fd97d2012-11-29 00:26:19 +0000942 default:
943 break;
Greg Claytona894fe72012-04-05 16:12:35 +0000944 }
Jim Ingham15fd97d2012-11-29 00:26:19 +0000945 }
946 else
947 {
948 if (log)
949 log->Printf ("SBFrame::FindValue () => error: could not reconstruct frame object for this SBFrame.");
Greg Clayton4e9267d2010-12-14 18:39:31 +0000950 }
Chris Lattner24943d22010-06-08 16:52:24 +0000951 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000952 else
953 {
954 if (log)
Jim Ingham15fd97d2012-11-29 00:26:19 +0000955 log->Printf ("SBFrame::FindValue () => error: process is running");
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000956 }
Chris Lattner24943d22010-06-08 16:52:24 +0000957 }
Caroline Tice98f930f2010-09-20 05:20:02 +0000958
Greg Claytona66ba462010-10-30 04:51:46 +0000959 if (log)
Greg Clayton4e9267d2010-12-14 18:39:31 +0000960 log->Printf ("SBFrame(%p)::FindVariableInScope (name=\"%s\", value_type=%i) => SBValue(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000961 frame, name, value_type, value_sp.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000962
963
Chris Lattner24943d22010-06-08 16:52:24 +0000964 return sb_value;
965}
966
967bool
Johnny Chen0164b752012-03-05 19:53:24 +0000968SBFrame::IsEqual (const SBFrame &that) const
969{
970 lldb::StackFrameSP this_sp = GetFrameSP();
971 lldb::StackFrameSP that_sp = that.GetFrameSP();
972 return (this_sp && that_sp && this_sp->GetStackID() == that_sp->GetStackID());
973}
974
975bool
Chris Lattner24943d22010-06-08 16:52:24 +0000976SBFrame::operator == (const SBFrame &rhs) const
977{
Johnny Chen0164b752012-03-05 19:53:24 +0000978 return IsEqual(rhs);
Chris Lattner24943d22010-06-08 16:52:24 +0000979}
980
981bool
982SBFrame::operator != (const SBFrame &rhs) const
983{
Johnny Chen0164b752012-03-05 19:53:24 +0000984 return !IsEqual(rhs);
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000985}
Chris Lattner24943d22010-06-08 16:52:24 +0000986
987SBThread
988SBFrame::GetThread () const
989{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000990 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000991
Greg Claytona894fe72012-04-05 16:12:35 +0000992 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000993 ThreadSP thread_sp (exe_ctx.GetThreadSP());
994 SBThread sb_thread (thread_sp);
Caroline Tice7826c882010-10-26 03:11:13 +0000995
996 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000997 {
998 SBStream sstr;
999 sb_thread.GetDescription (sstr);
Greg Clayton289afcb2012-02-18 05:35:26 +00001000 log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s",
1001 exe_ctx.GetFramePtr(),
1002 thread_sp.get(),
1003 sstr.GetData());
Caroline Tice61ba7ec2010-10-26 23:49:36 +00001004 }
Caroline Tice7826c882010-10-26 03:11:13 +00001005
Chris Lattner24943d22010-06-08 16:52:24 +00001006 return sb_thread;
1007}
1008
1009const char *
1010SBFrame::Disassemble () const
1011{
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001012 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +00001013 const char *disassembly = NULL;
Jim Inghamd0bdddf2012-08-22 21:34:33 +00001014 Mutex::Locker api_locker;
1015 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1016
Jim Ingham15fd97d2012-11-29 00:26:19 +00001017 StackFrame *frame = NULL;
Greg Clayton289afcb2012-02-18 05:35:26 +00001018 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham15fd97d2012-11-29 00:26:19 +00001019 Process *process = exe_ctx.GetProcessPtr();
1020 if (target && process)
Greg Claytonbdcda462010-12-20 20:49:23 +00001021 {
Greg Claytona894fe72012-04-05 16:12:35 +00001022 Process::StopLocker stop_locker;
Jim Ingham15fd97d2012-11-29 00:26:19 +00001023 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Claytona894fe72012-04-05 16:12:35 +00001024 {
Jim Ingham15fd97d2012-11-29 00:26:19 +00001025 frame = exe_ctx.GetFramePtr();
1026 if (frame)
1027 {
1028 disassembly = frame->Disassemble();
1029 }
1030 else
1031 {
1032 if (log)
1033 log->Printf ("SBFrame::Disassemble () => error: could not reconstruct frame object for this SBFrame.");
1034 }
Greg Claytona894fe72012-04-05 16:12:35 +00001035 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001036 else
1037 {
1038 if (log)
Jim Ingham15fd97d2012-11-29 00:26:19 +00001039 log->Printf ("SBFrame::Disassemble () => error: process is running");
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001040 }
Greg Claytonbdcda462010-12-20 20:49:23 +00001041 }
Greg Claytona66ba462010-10-30 04:51:46 +00001042
1043 if (log)
Greg Clayton289afcb2012-02-18 05:35:26 +00001044 log->Printf ("SBFrame(%p)::Disassemble () => %s", frame, disassembly);
Greg Claytona66ba462010-10-30 04:51:46 +00001045
1046 return disassembly;
Chris Lattner24943d22010-06-08 16:52:24 +00001047}
1048
1049
Chris Lattner24943d22010-06-08 16:52:24 +00001050SBValueList
1051SBFrame::GetVariables (bool arguments,
1052 bool locals,
1053 bool statics,
1054 bool in_scope_only)
1055{
Greg Clayton582ed0e2011-06-18 20:06:08 +00001056 SBValueList value_list;
Greg Claytona894fe72012-04-05 16:12:35 +00001057 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +00001058 StackFrame *frame = exe_ctx.GetFramePtr();
1059 Target *target = exe_ctx.GetTargetPtr();
1060 if (frame && target)
Greg Clayton582ed0e2011-06-18 20:06:08 +00001061 {
Greg Clayton289afcb2012-02-18 05:35:26 +00001062 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton582ed0e2011-06-18 20:06:08 +00001063 value_list = GetVariables (arguments, locals, statics, in_scope_only, use_dynamic);
1064 }
1065 return value_list;
Jim Inghame41494a2011-04-16 00:01:13 +00001066}
1067
1068SBValueList
1069SBFrame::GetVariables (bool arguments,
1070 bool locals,
1071 bool statics,
1072 bool in_scope_only,
Jim Ingham10de7d12011-05-04 03:43:18 +00001073 lldb::DynamicValueType use_dynamic)
Jim Inghame41494a2011-04-16 00:01:13 +00001074{
Greg Clayton4e9267d2010-12-14 18:39:31 +00001075 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001076
Greg Clayton334d33a2012-01-30 07:41:31 +00001077 SBValueList value_list;
Jim Inghamd0bdddf2012-08-22 21:34:33 +00001078 Mutex::Locker api_locker;
1079 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1080
Jim Ingham15fd97d2012-11-29 00:26:19 +00001081 StackFrame *frame = NULL;
Greg Clayton289afcb2012-02-18 05:35:26 +00001082 Target *target = exe_ctx.GetTargetPtr();
Greg Clayton334d33a2012-01-30 07:41:31 +00001083
Caroline Tice7826c882010-10-26 03:11:13 +00001084 if (log)
Jim Ingham15fd97d2012-11-29 00:26:19 +00001085 log->Printf ("SBFrame::GetVariables (arguments=%i, locals=%i, statics=%i, in_scope_only=%i)",
Greg Claytona66ba462010-10-30 04:51:46 +00001086 arguments,
1087 locals,
1088 statics,
1089 in_scope_only);
Greg Clayton334d33a2012-01-30 07:41:31 +00001090
Jim Ingham15fd97d2012-11-29 00:26:19 +00001091 Process *process = exe_ctx.GetProcessPtr();
1092 if (target && process)
Chris Lattner24943d22010-06-08 16:52:24 +00001093 {
Greg Claytona894fe72012-04-05 16:12:35 +00001094 Process::StopLocker stop_locker;
Jim Ingham15fd97d2012-11-29 00:26:19 +00001095 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Claytona894fe72012-04-05 16:12:35 +00001096 {
Jim Ingham15fd97d2012-11-29 00:26:19 +00001097 frame = exe_ctx.GetFramePtr();
1098 if (frame)
Greg Claytona894fe72012-04-05 16:12:35 +00001099 {
Jim Ingham15fd97d2012-11-29 00:26:19 +00001100 size_t i;
1101 VariableList *variable_list = NULL;
1102 variable_list = frame->GetVariableList(true);
1103 if (variable_list)
Chris Lattner24943d22010-06-08 16:52:24 +00001104 {
Jim Ingham15fd97d2012-11-29 00:26:19 +00001105 const size_t num_variables = variable_list->GetSize();
1106 if (num_variables)
Chris Lattner24943d22010-06-08 16:52:24 +00001107 {
Jim Ingham15fd97d2012-11-29 00:26:19 +00001108 for (i = 0; i < num_variables; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +00001109 {
Jim Ingham15fd97d2012-11-29 00:26:19 +00001110 VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
1111 if (variable_sp)
Greg Claytona894fe72012-04-05 16:12:35 +00001112 {
Jim Ingham15fd97d2012-11-29 00:26:19 +00001113 bool add_variable = false;
1114 switch (variable_sp->GetScope())
1115 {
1116 case eValueTypeVariableGlobal:
1117 case eValueTypeVariableStatic:
1118 add_variable = statics;
1119 break;
Chris Lattner24943d22010-06-08 16:52:24 +00001120
Jim Ingham15fd97d2012-11-29 00:26:19 +00001121 case eValueTypeVariableArgument:
1122 add_variable = arguments;
1123 break;
Chris Lattner24943d22010-06-08 16:52:24 +00001124
Jim Ingham15fd97d2012-11-29 00:26:19 +00001125 case eValueTypeVariableLocal:
1126 add_variable = locals;
1127 break;
Greg Clayton54e7afa2010-07-09 20:39:50 +00001128
Jim Ingham15fd97d2012-11-29 00:26:19 +00001129 default:
1130 break;
1131 }
1132 if (add_variable)
1133 {
1134 if (in_scope_only && !variable_sp->IsInScope(frame))
1135 continue;
Chris Lattner24943d22010-06-08 16:52:24 +00001136
Jim Ingham15fd97d2012-11-29 00:26:19 +00001137 ValueObjectSP valobj_sp(frame->GetValueObjectForFrameVariable (variable_sp, eNoDynamicValues));
1138 SBValue value_sb;
1139 value_sb.SetSP(valobj_sp,use_dynamic);
1140 value_list.Append(value_sb);
1141 }
Greg Claytona894fe72012-04-05 16:12:35 +00001142 }
Chris Lattner24943d22010-06-08 16:52:24 +00001143 }
1144 }
1145 }
1146 }
Jim Ingham15fd97d2012-11-29 00:26:19 +00001147 else
1148 {
1149 if (log)
1150 log->Printf ("SBFrame::GetVariables () => error: could not reconstruct frame object for this SBFrame.");
1151 }
Greg Claytona894fe72012-04-05 16:12:35 +00001152 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001153 else
1154 {
1155 if (log)
Jim Ingham15fd97d2012-11-29 00:26:19 +00001156 log->Printf ("SBFrame::GetVariables () => error: process is running");
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001157 }
Chris Lattner24943d22010-06-08 16:52:24 +00001158 }
Caroline Tice7826c882010-10-26 03:11:13 +00001159
1160 if (log)
1161 {
Greg Clayton289afcb2012-02-18 05:35:26 +00001162 log->Printf ("SBFrame(%p)::GetVariables (...) => SBValueList(%p)", frame,
Caroline Tice61ba7ec2010-10-26 23:49:36 +00001163 value_list.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001164 }
1165
Chris Lattner24943d22010-06-08 16:52:24 +00001166 return value_list;
1167}
1168
Greg Clayton4e9267d2010-12-14 18:39:31 +00001169SBValueList
Chris Lattner24943d22010-06-08 16:52:24 +00001170SBFrame::GetRegisters ()
1171{
Greg Clayton4e9267d2010-12-14 18:39:31 +00001172 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001173
Chris Lattner24943d22010-06-08 16:52:24 +00001174 SBValueList value_list;
Jim Inghamd0bdddf2012-08-22 21:34:33 +00001175 Mutex::Locker api_locker;
1176 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1177
Jim Ingham15fd97d2012-11-29 00:26:19 +00001178 StackFrame *frame = NULL;
Greg Clayton289afcb2012-02-18 05:35:26 +00001179 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham15fd97d2012-11-29 00:26:19 +00001180 Process *process = exe_ctx.GetProcessPtr();
1181 if (target && process)
Chris Lattner24943d22010-06-08 16:52:24 +00001182 {
Greg Claytona894fe72012-04-05 16:12:35 +00001183 Process::StopLocker stop_locker;
Jim Ingham15fd97d2012-11-29 00:26:19 +00001184 if (stop_locker.TryLock(&process->GetRunLock()))
Chris Lattner24943d22010-06-08 16:52:24 +00001185 {
Jim Ingham15fd97d2012-11-29 00:26:19 +00001186 frame = exe_ctx.GetFramePtr();
1187 if (frame)
Chris Lattner24943d22010-06-08 16:52:24 +00001188 {
Jim Ingham15fd97d2012-11-29 00:26:19 +00001189 RegisterContextSP reg_ctx (frame->GetRegisterContext());
1190 if (reg_ctx)
Greg Claytona894fe72012-04-05 16:12:35 +00001191 {
Jim Ingham15fd97d2012-11-29 00:26:19 +00001192 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
1193 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
1194 {
1195 value_list.Append(ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx));
1196 }
Greg Claytona894fe72012-04-05 16:12:35 +00001197 }
Chris Lattner24943d22010-06-08 16:52:24 +00001198 }
Jim Ingham15fd97d2012-11-29 00:26:19 +00001199 else
1200 {
1201 if (log)
1202 log->Printf ("SBFrame::GetRegisters () => error: could not reconstruct frame object for this SBFrame.");
1203 }
Chris Lattner24943d22010-06-08 16:52:24 +00001204 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001205 else
1206 {
1207 if (log)
Jim Ingham15fd97d2012-11-29 00:26:19 +00001208 log->Printf ("SBFrame::GetRegisters () => error: process is running");
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001209 }
Chris Lattner24943d22010-06-08 16:52:24 +00001210 }
Caroline Tice7826c882010-10-26 03:11:13 +00001211
1212 if (log)
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001213 log->Printf ("SBFrame(%p)::GetRegisters () => SBValueList(%p)", frame, value_list.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001214
Chris Lattner24943d22010-06-08 16:52:24 +00001215 return value_list;
1216}
1217
Caroline Tice98f930f2010-09-20 05:20:02 +00001218bool
1219SBFrame::GetDescription (SBStream &description)
1220{
Jim Ingham15fd97d2012-11-29 00:26:19 +00001221 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton96154be2011-11-13 06:57:31 +00001222 Stream &strm = description.ref();
1223
Jim Inghamd0bdddf2012-08-22 21:34:33 +00001224 Mutex::Locker api_locker;
1225 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1226
Jim Ingham15fd97d2012-11-29 00:26:19 +00001227 StackFrame *frame;
Greg Clayton289afcb2012-02-18 05:35:26 +00001228 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham15fd97d2012-11-29 00:26:19 +00001229 Process *process = exe_ctx.GetProcessPtr();
1230 if (target && process)
Caroline Tice98f930f2010-09-20 05:20:02 +00001231 {
Greg Claytona894fe72012-04-05 16:12:35 +00001232 Process::StopLocker stop_locker;
Jim Ingham15fd97d2012-11-29 00:26:19 +00001233 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Claytona894fe72012-04-05 16:12:35 +00001234 {
Jim Ingham15fd97d2012-11-29 00:26:19 +00001235 frame = exe_ctx.GetFramePtr();
1236 if (frame)
1237 {
1238 frame->DumpUsingSettingsFormat (&strm);
1239 }
1240 else
1241 {
1242 if (log)
1243 log->Printf ("SBFrame::GetDescription () => error: could not reconstruct frame object for this SBFrame.");
1244 }
Greg Claytona894fe72012-04-05 16:12:35 +00001245 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001246 else
1247 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001248 if (log)
Jim Ingham15fd97d2012-11-29 00:26:19 +00001249 log->Printf ("SBFrame::GetDescription () => error: process is running");
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001250 }
1251
Caroline Tice98f930f2010-09-20 05:20:02 +00001252 }
1253 else
Greg Clayton96154be2011-11-13 06:57:31 +00001254 strm.PutCString ("No value");
Caroline Tice98f930f2010-09-20 05:20:02 +00001255
1256 return true;
1257}
Greg Clayton66ed2fb2010-10-05 00:00:42 +00001258
Greg Clayton4e9267d2010-12-14 18:39:31 +00001259SBValue
Greg Clayton66ed2fb2010-10-05 00:00:42 +00001260SBFrame::EvaluateExpression (const char *expr)
1261{
Greg Clayton582ed0e2011-06-18 20:06:08 +00001262 SBValue result;
Greg Claytona894fe72012-04-05 16:12:35 +00001263 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +00001264 StackFrame *frame = exe_ctx.GetFramePtr();
1265 Target *target = exe_ctx.GetTargetPtr();
1266 if (frame && target)
Greg Clayton582ed0e2011-06-18 20:06:08 +00001267 {
Jim Ingham47beabb2012-10-16 21:41:58 +00001268 SBExpressionOptions options;
1269 lldb::DynamicValueType fetch_dynamic_value = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton75a443b2012-10-16 22:58:25 +00001270 options.SetFetchDynamicValue (fetch_dynamic_value);
Jim Ingham47beabb2012-10-16 21:41:58 +00001271 options.SetUnwindOnError (true);
1272 return EvaluateExpression (expr, options);
Greg Clayton582ed0e2011-06-18 20:06:08 +00001273 }
1274 return result;
Jim Inghame41494a2011-04-16 00:01:13 +00001275}
1276
1277SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +00001278SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value)
Jim Inghame41494a2011-04-16 00:01:13 +00001279{
Jim Ingham47beabb2012-10-16 21:41:58 +00001280 SBExpressionOptions options;
Greg Clayton75a443b2012-10-16 22:58:25 +00001281 options.SetFetchDynamicValue (fetch_dynamic_value);
Jim Ingham47beabb2012-10-16 21:41:58 +00001282 options.SetUnwindOnError (true);
1283 return EvaluateExpression (expr, options);
Jim Inghamd82bc6d2012-05-11 23:47:32 +00001284}
1285
1286SBValue
1287SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value, bool unwind_on_error)
1288{
Jim Ingham47beabb2012-10-16 21:41:58 +00001289 SBExpressionOptions options;
Greg Clayton75a443b2012-10-16 22:58:25 +00001290 options.SetFetchDynamicValue (fetch_dynamic_value);
Jim Ingham47beabb2012-10-16 21:41:58 +00001291 options.SetUnwindOnError (unwind_on_error);
1292 return EvaluateExpression (expr, options);
1293}
1294
1295lldb::SBValue
1296SBFrame::EvaluateExpression (const char *expr, const SBExpressionOptions &options)
1297{
Greg Clayton4e9267d2010-12-14 18:39:31 +00001298 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Sean Callanan94d255f2010-12-07 22:55:01 +00001299
Greg Clayton4e9267d2010-12-14 18:39:31 +00001300 LogSP expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Greg Claytona66ba462010-10-30 04:51:46 +00001301
Greg Clayton4a379b12012-07-17 03:23:13 +00001302 ExecutionResults exe_results = eExecutionSetupError;
Greg Clayton4e9267d2010-12-14 18:39:31 +00001303 SBValue expr_result;
Jim Ingham15fd97d2012-11-29 00:26:19 +00001304
1305 if (expr == NULL || expr[0] == '\0')
1306 {
1307 if (log)
1308 log->Printf ("SBFrame::EvaluateExpression called with an empty expression");
1309 return expr_result;
1310 }
1311
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001312 ValueObjectSP expr_value_sp;
Greg Claytona66ba462010-10-30 04:51:46 +00001313
Jim Inghamd0bdddf2012-08-22 21:34:33 +00001314 Mutex::Locker api_locker;
1315 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1316
Greg Clayton334d33a2012-01-30 07:41:31 +00001317 if (log)
Jim Ingham15fd97d2012-11-29 00:26:19 +00001318 log->Printf ("SBFrame()::EvaluateExpression (expr=\"%s\")...", expr);
Greg Clayton334d33a2012-01-30 07:41:31 +00001319
Jim Ingham15fd97d2012-11-29 00:26:19 +00001320 StackFrame *frame = NULL;
1321 Target *target = exe_ctx.GetTargetPtr();
1322 Process *process = exe_ctx.GetProcessPtr();
1323
1324 if (target && process)
1325 {
Greg Claytona894fe72012-04-05 16:12:35 +00001326 Process::StopLocker stop_locker;
Jim Ingham15fd97d2012-11-29 00:26:19 +00001327 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Claytona894fe72012-04-05 16:12:35 +00001328 {
Jim Ingham15fd97d2012-11-29 00:26:19 +00001329 frame = exe_ctx.GetFramePtr();
1330 if (frame)
1331 {
Enrico Granata299aa702012-05-29 18:06:49 +00001332#ifdef LLDB_CONFIGURATION_DEBUG
Jim Ingham15fd97d2012-11-29 00:26:19 +00001333 StreamString frame_description;
1334 frame->DumpUsingSettingsFormat (&frame_description);
1335 Host::SetCrashDescriptionWithFormat ("SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
1336 expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str());
Enrico Granata299aa702012-05-29 18:06:49 +00001337#endif
Jim Ingham15fd97d2012-11-29 00:26:19 +00001338 exe_results = target->EvaluateExpression (expr,
1339 frame,
1340 expr_value_sp,
1341 options.ref());
1342 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
Enrico Granata299aa702012-05-29 18:06:49 +00001343#ifdef LLDB_CONFIGURATION_DEBUG
Jim Ingham15fd97d2012-11-29 00:26:19 +00001344 Host::SetCrashDescription (NULL);
Enrico Granata299aa702012-05-29 18:06:49 +00001345#endif
Jim Ingham15fd97d2012-11-29 00:26:19 +00001346 }
1347 else
1348 {
1349 if (log)
1350 log->Printf ("SBFrame::EvaluateExpression () => error: could not reconstruct frame object for this SBFrame.");
1351 }
Greg Claytona894fe72012-04-05 16:12:35 +00001352 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001353 else
1354 {
1355 if (log)
Jim Ingham15fd97d2012-11-29 00:26:19 +00001356 log->Printf ("SBFrame::EvaluateExpression () => error: process is running");
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001357 }
Greg Clayton66ed2fb2010-10-05 00:00:42 +00001358 }
Jason Molendac48ca822012-02-21 05:33:55 +00001359
1360#ifndef LLDB_DISABLE_PYTHON
Sean Callanan94d255f2010-12-07 22:55:01 +00001361 if (expr_log)
Jim Inghame41494a2011-04-16 00:01:13 +00001362 expr_log->Printf("** [SBFrame::EvaluateExpression] Expression result is %s, summary %s **",
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001363 expr_result.GetValue(),
1364 expr_result.GetSummary());
Sean Callanan94d255f2010-12-07 22:55:01 +00001365
Greg Claytona66ba462010-10-30 04:51:46 +00001366 if (log)
Greg Clayton289afcb2012-02-18 05:35:26 +00001367 log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)",
1368 frame,
Jim Inghame41494a2011-04-16 00:01:13 +00001369 expr,
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001370 expr_value_sp.get(),
Johnny Chenee6e7902011-08-10 22:06:24 +00001371 exe_results);
Jason Molendac48ca822012-02-21 05:33:55 +00001372#endif
Greg Claytona66ba462010-10-30 04:51:46 +00001373
Greg Clayton49ce6822010-10-31 03:01:06 +00001374 return expr_result;
Greg Clayton66ed2fb2010-10-05 00:00:42 +00001375}
Greg Clayton582ed0e2011-06-18 20:06:08 +00001376
1377bool
1378SBFrame::IsInlined()
1379{
Jim Ingham15fd97d2012-11-29 00:26:19 +00001380 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona894fe72012-04-05 16:12:35 +00001381 ExecutionContext exe_ctx(m_opaque_sp.get());
Jim Ingham15fd97d2012-11-29 00:26:19 +00001382 StackFrame *frame = NULL;
Greg Clayton289afcb2012-02-18 05:35:26 +00001383 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham15fd97d2012-11-29 00:26:19 +00001384 Process *process = exe_ctx.GetProcessPtr();
1385 if (target && process)
Greg Clayton582ed0e2011-06-18 20:06:08 +00001386 {
Greg Claytona894fe72012-04-05 16:12:35 +00001387 Process::StopLocker stop_locker;
Jim Ingham15fd97d2012-11-29 00:26:19 +00001388 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Claytona894fe72012-04-05 16:12:35 +00001389 {
Jim Ingham15fd97d2012-11-29 00:26:19 +00001390 frame = exe_ctx.GetFramePtr();
1391 if (frame)
1392 {
Greg Claytona894fe72012-04-05 16:12:35 +00001393
Jim Ingham15fd97d2012-11-29 00:26:19 +00001394 Block *block = frame->GetSymbolContext(eSymbolContextBlock).block;
1395 if (block)
1396 return block->GetContainingInlinedBlock () != NULL;
1397 }
1398 else
1399 {
1400 if (log)
1401 log->Printf ("SBFrame::IsInlined () => error: could not reconstruct frame object for this SBFrame.");
1402 }
Greg Claytona894fe72012-04-05 16:12:35 +00001403 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001404 else
1405 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001406 if (log)
Jim Ingham15fd97d2012-11-29 00:26:19 +00001407 log->Printf ("SBFrame::IsInlined () => error: process is running");
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001408 }
1409
Greg Clayton582ed0e2011-06-18 20:06:08 +00001410 }
1411 return false;
1412}
1413
1414const char *
1415SBFrame::GetFunctionName()
1416{
Jim Ingham15fd97d2012-11-29 00:26:19 +00001417 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton582ed0e2011-06-18 20:06:08 +00001418 const char *name = NULL;
Greg Claytona894fe72012-04-05 16:12:35 +00001419 ExecutionContext exe_ctx(m_opaque_sp.get());
Jim Ingham15fd97d2012-11-29 00:26:19 +00001420 StackFrame *frame = NULL;
Greg Clayton289afcb2012-02-18 05:35:26 +00001421 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham15fd97d2012-11-29 00:26:19 +00001422 Process *process = exe_ctx.GetProcessPtr();
1423 if (target && process)
Greg Clayton582ed0e2011-06-18 20:06:08 +00001424 {
Greg Claytona894fe72012-04-05 16:12:35 +00001425 Process::StopLocker stop_locker;
Jim Ingham15fd97d2012-11-29 00:26:19 +00001426 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton582ed0e2011-06-18 20:06:08 +00001427 {
Jim Ingham15fd97d2012-11-29 00:26:19 +00001428 frame = exe_ctx.GetFramePtr();
1429 if (frame)
Greg Clayton582ed0e2011-06-18 20:06:08 +00001430 {
Jim Ingham15fd97d2012-11-29 00:26:19 +00001431 SymbolContext sc (frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol));
1432 if (sc.block)
Greg Claytona894fe72012-04-05 16:12:35 +00001433 {
Jim Ingham15fd97d2012-11-29 00:26:19 +00001434 Block *inlined_block = sc.block->GetContainingInlinedBlock ();
1435 if (inlined_block)
1436 {
1437 const InlineFunctionInfo* inlined_info = inlined_block->GetInlinedFunctionInfo();
1438 name = inlined_info->GetName().AsCString();
1439 }
1440 }
1441
1442 if (name == NULL)
1443 {
1444 if (sc.function)
1445 name = sc.function->GetName().GetCString();
1446 }
1447
1448 if (name == NULL)
1449 {
1450 if (sc.symbol)
1451 name = sc.symbol->GetName().GetCString();
Greg Claytona894fe72012-04-05 16:12:35 +00001452 }
Greg Clayton582ed0e2011-06-18 20:06:08 +00001453 }
Jim Ingham15fd97d2012-11-29 00:26:19 +00001454 else
Greg Claytona894fe72012-04-05 16:12:35 +00001455 {
Jim Ingham15fd97d2012-11-29 00:26:19 +00001456 if (log)
1457 log->Printf ("SBFrame::GetFunctionName () => error: could not reconstruct frame object for this SBFrame.");
Greg Claytona894fe72012-04-05 16:12:35 +00001458 }
Greg Clayton582ed0e2011-06-18 20:06:08 +00001459 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001460 else
1461 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001462 if (log)
Jim Ingham15fd97d2012-11-29 00:26:19 +00001463 log->Printf ("SBFrame::GetFunctionName() => error: process is running");
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001464
1465 }
Greg Clayton582ed0e2011-06-18 20:06:08 +00001466 }
1467 return name;
1468}
1469