blob: 040412036b373e7caff263d8ab7db887e1aadc9a [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
45using namespace lldb;
46using namespace lldb_private;
47
Greg Clayton334d33a2012-01-30 07:41:31 +000048
Chris Lattner24943d22010-06-08 16:52:24 +000049SBFrame::SBFrame () :
Greg Claytona894fe72012-04-05 16:12:35 +000050 m_opaque_sp (new ExecutionContextRef())
Chris Lattner24943d22010-06-08 16:52:24 +000051{
52}
53
Greg Clayton4e9267d2010-12-14 18:39:31 +000054SBFrame::SBFrame (const StackFrameSP &lldb_object_sp) :
Greg Claytona894fe72012-04-05 16:12:35 +000055 m_opaque_sp (new ExecutionContextRef (lldb_object_sp))
Chris Lattner24943d22010-06-08 16:52:24 +000056{
Greg Clayton4e9267d2010-12-14 18:39:31 +000057 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +000058
59 if (log)
60 {
61 SBStream sstr;
62 GetDescription (sstr);
Greg Claytona66ba462010-10-30 04:51:46 +000063 log->Printf ("SBFrame::SBFrame (sp=%p) => SBFrame(%p): %s",
Greg Clayton334d33a2012-01-30 07:41:31 +000064 lldb_object_sp.get(), lldb_object_sp.get(), sstr.GetData());
Caroline Tice61ba7ec2010-10-26 23:49:36 +000065
Caroline Tice7826c882010-10-26 03:11:13 +000066 }
Chris Lattner24943d22010-06-08 16:52:24 +000067}
68
Greg Clayton538eb822010-11-05 23:17:00 +000069SBFrame::SBFrame(const SBFrame &rhs) :
Greg Claytona894fe72012-04-05 16:12:35 +000070 m_opaque_sp (new ExecutionContextRef (*rhs.m_opaque_sp))
Greg Clayton538eb822010-11-05 23:17:00 +000071{
72}
73
74const SBFrame &
75SBFrame::operator = (const SBFrame &rhs)
76{
77 if (this != &rhs)
Greg Claytona894fe72012-04-05 16:12:35 +000078 *m_opaque_sp = *rhs.m_opaque_sp;
Greg Clayton538eb822010-11-05 23:17:00 +000079 return *this;
80}
81
Chris Lattner24943d22010-06-08 16:52:24 +000082SBFrame::~SBFrame()
83{
84}
85
Greg Clayton334d33a2012-01-30 07:41:31 +000086StackFrameSP
87SBFrame::GetFrameSP() const
Chris Lattner24943d22010-06-08 16:52:24 +000088{
Greg Clayton26425852012-04-12 20:58:26 +000089 if (m_opaque_sp)
90 return m_opaque_sp->GetFrameSP();
91 return StackFrameSP();
Chris Lattner24943d22010-06-08 16:52:24 +000092}
93
Greg Clayton334d33a2012-01-30 07:41:31 +000094void
95SBFrame::SetFrameSP (const StackFrameSP &lldb_object_sp)
96{
Greg Claytona894fe72012-04-05 16:12:35 +000097 return m_opaque_sp->SetFrameSP(lldb_object_sp);
Greg Clayton334d33a2012-01-30 07:41:31 +000098}
Chris Lattner24943d22010-06-08 16:52:24 +000099
100bool
101SBFrame::IsValid() const
102{
Greg Claytona894fe72012-04-05 16:12:35 +0000103 return GetFrameSP().get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +0000104}
105
106SBSymbolContext
107SBFrame::GetSymbolContext (uint32_t resolve_scope) const
108{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000109 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +0000110 SBSymbolContext sb_sym_ctx;
Greg Claytona894fe72012-04-05 16:12:35 +0000111 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000112 StackFrame *frame = exe_ctx.GetFramePtr();
113 Target *target = exe_ctx.GetTargetPtr();
114 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000115 {
Greg Claytona894fe72012-04-05 16:12:35 +0000116 Process::StopLocker stop_locker;
117 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
118 {
119 Mutex::Locker api_locker (target->GetAPIMutex());
120 sb_sym_ctx.SetSymbolContext(&frame->GetSymbolContext (resolve_scope));
121 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000122 else
123 {
124 if (log)
125 log->Printf ("SBFrame(%p)::GetSymbolContext () => error: process is running", frame);
126 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000127 }
Caroline Tice7826c882010-10-26 03:11:13 +0000128
129 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000130 log->Printf ("SBFrame(%p)::GetSymbolContext (resolve_scope=0x%8.8x) => SBSymbolContext(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000131 frame, resolve_scope, sb_sym_ctx.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000132
Chris Lattner24943d22010-06-08 16:52:24 +0000133 return sb_sym_ctx;
134}
135
136SBModule
137SBFrame::GetModule () const
138{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000139 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytondd62d722010-12-14 04:58:53 +0000140 SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000141 ModuleSP module_sp;
Greg Claytona894fe72012-04-05 16:12:35 +0000142 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000143 StackFrame *frame = exe_ctx.GetFramePtr();
144 Target *target = exe_ctx.GetTargetPtr();
145 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000146 {
Greg Claytona894fe72012-04-05 16:12:35 +0000147 Process::StopLocker stop_locker;
148 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
149 {
150 Mutex::Locker api_locker (target->GetAPIMutex());
151 module_sp = frame->GetSymbolContext (eSymbolContextModule).module_sp;
152 sb_module.SetSP (module_sp);
153 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000154 else
155 {
156 if (log)
157 log->Printf ("SBFrame(%p)::GetModule () => error: process is running", frame);
158 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000159 }
Greg Claytondd62d722010-12-14 04:58:53 +0000160
Greg Claytona66ba462010-10-30 04:51:46 +0000161 if (log)
162 log->Printf ("SBFrame(%p)::GetModule () => SBModule(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000163 frame, module_sp.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000164
Chris Lattner24943d22010-06-08 16:52:24 +0000165 return sb_module;
166}
167
168SBCompileUnit
169SBFrame::GetCompileUnit () const
170{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000171 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytondd62d722010-12-14 04:58:53 +0000172 SBCompileUnit sb_comp_unit;
Greg Claytona894fe72012-04-05 16:12:35 +0000173 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000174 StackFrame *frame = exe_ctx.GetFramePtr();
175 Target *target = exe_ctx.GetTargetPtr();
176 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000177 {
Greg Claytona894fe72012-04-05 16:12:35 +0000178 Process::StopLocker stop_locker;
179 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
180 {
181 Mutex::Locker api_locker (target->GetAPIMutex());
182 sb_comp_unit.reset (frame->GetSymbolContext (eSymbolContextCompUnit).comp_unit);
183 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000184 else
185 {
186 if (log)
187 log->Printf ("SBFrame(%p)::GetCompileUnit () => error: process is running", frame);
188 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000189 }
Caroline Tice7826c882010-10-26 03:11:13 +0000190 if (log)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000191 log->Printf ("SBFrame(%p)::GetCompileUnit () => SBCompileUnit(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000192 frame, sb_comp_unit.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000193
Chris Lattner24943d22010-06-08 16:52:24 +0000194 return sb_comp_unit;
195}
196
197SBFunction
198SBFrame::GetFunction () const
199{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000200 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytondd62d722010-12-14 04:58:53 +0000201 SBFunction sb_function;
Greg Claytona894fe72012-04-05 16:12:35 +0000202 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000203 StackFrame *frame = exe_ctx.GetFramePtr();
204 Target *target = exe_ctx.GetTargetPtr();
205 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000206 {
Greg Claytona894fe72012-04-05 16:12:35 +0000207 Process::StopLocker stop_locker;
208 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
209 {
210 Mutex::Locker api_locker (target->GetAPIMutex());
211 sb_function.reset(frame->GetSymbolContext (eSymbolContextFunction).function);
212 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000213 else
214 {
215 if (log)
216 log->Printf ("SBFrame(%p)::GetFunction () => error: process is running", frame);
217 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000218 }
Greg Claytona66ba462010-10-30 04:51:46 +0000219 if (log)
220 log->Printf ("SBFrame(%p)::GetFunction () => SBFunction(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000221 frame, sb_function.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000222
Chris Lattner24943d22010-06-08 16:52:24 +0000223 return sb_function;
224}
225
Greg Clayton8f1e08b2010-10-04 18:37:52 +0000226SBSymbol
227SBFrame::GetSymbol () const
228{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000229 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytondd62d722010-12-14 04:58:53 +0000230 SBSymbol sb_symbol;
Greg Claytona894fe72012-04-05 16:12:35 +0000231 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000232 StackFrame *frame = exe_ctx.GetFramePtr();
233 Target *target = exe_ctx.GetTargetPtr();
234 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000235 {
Greg Claytona894fe72012-04-05 16:12:35 +0000236 Process::StopLocker stop_locker;
237 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
238 {
239 Mutex::Locker api_locker (target->GetAPIMutex());
240 sb_symbol.reset(frame->GetSymbolContext (eSymbolContextSymbol).symbol);
241 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000242 else
243 {
244 if (log)
245 log->Printf ("SBFrame(%p)::GetSymbol () => error: process is running", frame);
246 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000247 }
Greg Claytona66ba462010-10-30 04:51:46 +0000248 if (log)
249 log->Printf ("SBFrame(%p)::GetSymbol () => SBSymbol(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000250 frame, sb_symbol.get());
Greg Clayton8f1e08b2010-10-04 18:37:52 +0000251 return sb_symbol;
252}
253
Chris Lattner24943d22010-06-08 16:52:24 +0000254SBBlock
255SBFrame::GetBlock () const
256{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000257 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytondd62d722010-12-14 04:58:53 +0000258 SBBlock sb_block;
Greg Claytona894fe72012-04-05 16:12:35 +0000259 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000260 StackFrame *frame = exe_ctx.GetFramePtr();
261 Target *target = exe_ctx.GetTargetPtr();
262 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000263 {
Greg Claytona894fe72012-04-05 16:12:35 +0000264 Process::StopLocker stop_locker;
265 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
266 {
267 Mutex::Locker api_locker (target->GetAPIMutex());
268 sb_block.SetPtr (frame->GetSymbolContext (eSymbolContextBlock).block);
269 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000270 else
271 {
272 if (log)
273 log->Printf ("SBFrame(%p)::GetBlock () => error: process is running", frame);
274 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000275 }
Greg Claytona66ba462010-10-30 04:51:46 +0000276 if (log)
277 log->Printf ("SBFrame(%p)::GetBlock () => SBBlock(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000278 frame, sb_block.GetPtr());
Chris Lattner24943d22010-06-08 16:52:24 +0000279 return sb_block;
280}
281
Greg Clayton69aa5d92010-09-07 04:20:48 +0000282SBBlock
283SBFrame::GetFrameBlock () const
284{
Greg Claytondd62d722010-12-14 04:58:53 +0000285 SBBlock sb_block;
Greg Claytona894fe72012-04-05 16:12:35 +0000286 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000287 StackFrame *frame = exe_ctx.GetFramePtr();
288 Target *target = exe_ctx.GetTargetPtr();
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000289 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton289afcb2012-02-18 05:35:26 +0000290 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000291 {
Greg Claytona894fe72012-04-05 16:12:35 +0000292 Process::StopLocker stop_locker;
293 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
294 {
295 Mutex::Locker api_locker (target->GetAPIMutex());
296 sb_block.SetPtr(frame->GetFrameBlock ());
297 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000298 else
299 {
300 if (log)
301 log->Printf ("SBFrame(%p)::GetFrameBlock () => error: process is running", frame);
302 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000303 }
Greg Claytona66ba462010-10-30 04:51:46 +0000304 if (log)
305 log->Printf ("SBFrame(%p)::GetFrameBlock () => SBBlock(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000306 frame, sb_block.GetPtr());
Greg Clayton69aa5d92010-09-07 04:20:48 +0000307 return sb_block;
308}
309
Chris Lattner24943d22010-06-08 16:52:24 +0000310SBLineEntry
311SBFrame::GetLineEntry () const
312{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000313 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytondd62d722010-12-14 04:58:53 +0000314 SBLineEntry sb_line_entry;
Greg Claytona894fe72012-04-05 16:12:35 +0000315 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000316 StackFrame *frame = exe_ctx.GetFramePtr();
317 Target *target = exe_ctx.GetTargetPtr();
318 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000319 {
Greg Claytona894fe72012-04-05 16:12:35 +0000320 Process::StopLocker stop_locker;
321 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
322 {
323 Mutex::Locker api_locker (target->GetAPIMutex());
324 sb_line_entry.SetLineEntry (frame->GetSymbolContext (eSymbolContextLineEntry).line_entry);
325 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000326 else
327 {
328 if (log)
329 log->Printf ("SBFrame(%p)::GetLineEntry () => error: process is running", frame);
330 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000331 }
Greg Claytona66ba462010-10-30 04:51:46 +0000332 if (log)
333 log->Printf ("SBFrame(%p)::GetLineEntry () => SBLineEntry(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000334 frame, sb_line_entry.get());
Chris Lattner24943d22010-06-08 16:52:24 +0000335 return sb_line_entry;
336}
337
338uint32_t
339SBFrame::GetFrameID () const
340{
Greg Clayton334d33a2012-01-30 07:41:31 +0000341 uint32_t frame_idx = UINT32_MAX;
342
Greg Claytona894fe72012-04-05 16:12:35 +0000343 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000344 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Claytona894fe72012-04-05 16:12:35 +0000345 if (frame)
Greg Clayton289afcb2012-02-18 05:35:26 +0000346 frame_idx = frame->GetFrameIndex ();
Greg Claytona66ba462010-10-30 04:51:46 +0000347
Greg Clayton4e9267d2010-12-14 18:39:31 +0000348 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000349 if (log)
350 log->Printf ("SBFrame(%p)::GetFrameID () => %u",
Greg Clayton289afcb2012-02-18 05:35:26 +0000351 frame, frame_idx);
Greg Claytona66ba462010-10-30 04:51:46 +0000352 return frame_idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000353}
354
Greg Clayton4e9267d2010-12-14 18:39:31 +0000355addr_t
Chris Lattner24943d22010-06-08 16:52:24 +0000356SBFrame::GetPC () const
357{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000358 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton4e9267d2010-12-14 18:39:31 +0000359 addr_t addr = LLDB_INVALID_ADDRESS;
Greg Claytona894fe72012-04-05 16:12:35 +0000360 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000361 StackFrame *frame = exe_ctx.GetFramePtr();
362 Target *target = exe_ctx.GetTargetPtr();
363 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000364 {
Greg Claytona894fe72012-04-05 16:12:35 +0000365 Process::StopLocker stop_locker;
366 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
367 {
368 Mutex::Locker api_locker (target->GetAPIMutex());
369 addr = frame->GetFrameCodeAddress().GetOpcodeLoadAddress (target);
370 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000371 else
372 {
373 if (log)
374 log->Printf ("SBFrame(%p)::GetPC () => error: process is running", frame);
375 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000376 }
Caroline Tice7826c882010-10-26 03:11:13 +0000377
378 if (log)
Greg Clayton289afcb2012-02-18 05:35:26 +0000379 log->Printf ("SBFrame(%p)::GetPC () => 0x%llx", frame, addr);
Caroline Tice7826c882010-10-26 03:11:13 +0000380
381 return addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000382}
383
384bool
Greg Clayton4e9267d2010-12-14 18:39:31 +0000385SBFrame::SetPC (addr_t new_pc)
Chris Lattner24943d22010-06-08 16:52:24 +0000386{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000387 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000388 bool ret_val = false;
Greg Claytona894fe72012-04-05 16:12:35 +0000389 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000390 StackFrame *frame = exe_ctx.GetFramePtr();
391 Target *target = exe_ctx.GetTargetPtr();
392 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000393 {
Greg Claytona894fe72012-04-05 16:12:35 +0000394 Process::StopLocker stop_locker;
395 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
396 {
397 Mutex::Locker api_locker (target->GetAPIMutex());
398 ret_val = frame->GetRegisterContext()->SetPC (new_pc);
399 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000400 else
401 {
402 if (log)
403 log->Printf ("SBFrame(%p)::SetPC () => error: process is running", frame);
404 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000405 }
Caroline Tice7826c882010-10-26 03:11:13 +0000406
407 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000408 log->Printf ("SBFrame(%p)::SetPC (new_pc=0x%llx) => %i",
Greg Clayton289afcb2012-02-18 05:35:26 +0000409 frame, new_pc, ret_val);
Caroline Tice7826c882010-10-26 03:11:13 +0000410
411 return ret_val;
Chris Lattner24943d22010-06-08 16:52:24 +0000412}
413
Greg Clayton4e9267d2010-12-14 18:39:31 +0000414addr_t
Chris Lattner24943d22010-06-08 16:52:24 +0000415SBFrame::GetSP () const
416{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000417 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000418 addr_t addr = LLDB_INVALID_ADDRESS;
Greg Claytona894fe72012-04-05 16:12:35 +0000419 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000420 StackFrame *frame = exe_ctx.GetFramePtr();
421 Target *target = exe_ctx.GetTargetPtr();
422 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000423 {
Greg Claytona894fe72012-04-05 16:12:35 +0000424 Process::StopLocker stop_locker;
425 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
426 {
427 Mutex::Locker api_locker (target->GetAPIMutex());
428 addr = frame->GetRegisterContext()->GetSP();
429 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000430 else
431 {
432 if (log)
433 log->Printf ("SBFrame(%p)::GetSP () => error: process is running", frame);
434 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000435 }
Greg Claytona66ba462010-10-30 04:51:46 +0000436 if (log)
Greg Clayton289afcb2012-02-18 05:35:26 +0000437 log->Printf ("SBFrame(%p)::GetSP () => 0x%llx", frame, addr);
Greg Claytona66ba462010-10-30 04:51:46 +0000438
439 return addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000440}
441
442
Greg Clayton4e9267d2010-12-14 18:39:31 +0000443addr_t
Chris Lattner24943d22010-06-08 16:52:24 +0000444SBFrame::GetFP () const
445{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000446 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton4e9267d2010-12-14 18:39:31 +0000447 addr_t addr = LLDB_INVALID_ADDRESS;
Greg Claytona894fe72012-04-05 16:12:35 +0000448 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000449 StackFrame *frame = exe_ctx.GetFramePtr();
450 Target *target = exe_ctx.GetTargetPtr();
451 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000452 {
Greg Claytona894fe72012-04-05 16:12:35 +0000453 Process::StopLocker stop_locker;
454 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
455 {
456 Mutex::Locker api_locker (target->GetAPIMutex());
457 addr = frame->GetRegisterContext()->GetFP();
458 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000459 else
460 {
461 if (log)
462 log->Printf ("SBFrame(%p)::GetFP () => error: process is running", frame);
463 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000464 }
Caroline Tice7826c882010-10-26 03:11:13 +0000465
466 if (log)
Greg Clayton289afcb2012-02-18 05:35:26 +0000467 log->Printf ("SBFrame(%p)::GetFP () => 0x%llx", frame, addr);
Caroline Tice7826c882010-10-26 03:11:13 +0000468 return addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000469}
470
471
472SBAddress
473SBFrame::GetPCAddress () const
474{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000475 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +0000476 SBAddress sb_addr;
Greg Claytona894fe72012-04-05 16:12:35 +0000477 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000478 StackFrame *frame = exe_ctx.GetFramePtr();
479 Target *target = exe_ctx.GetTargetPtr();
480 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000481 {
Greg Claytona894fe72012-04-05 16:12:35 +0000482 Process::StopLocker stop_locker;
483 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
484 {
485 Mutex::Locker api_locker (target->GetAPIMutex());
486 sb_addr.SetAddress (&frame->GetFrameCodeAddress());
487 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000488 else
489 {
490 if (log)
491 log->Printf ("SBFrame(%p)::GetPCAddress () => error: process is running", frame);
492 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000493 }
Greg Claytona66ba462010-10-30 04:51:46 +0000494 if (log)
Greg Clayton289afcb2012-02-18 05:35:26 +0000495 log->Printf ("SBFrame(%p)::GetPCAddress () => SBAddress(%p)", frame, sb_addr.get());
Chris Lattner24943d22010-06-08 16:52:24 +0000496 return sb_addr;
497}
498
499void
500SBFrame::Clear()
501{
Greg Clayton26425852012-04-12 20:58:26 +0000502 m_opaque_sp->Clear();
Chris Lattner24943d22010-06-08 16:52:24 +0000503}
504
Greg Claytond62b9c12012-02-03 07:02:37 +0000505lldb::SBValue
506SBFrame::GetValueForVariablePath (const char *var_path)
507{
508 SBValue sb_value;
Greg Claytona894fe72012-04-05 16:12:35 +0000509 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000510 StackFrame *frame = exe_ctx.GetFramePtr();
511 Target *target = exe_ctx.GetTargetPtr();
512 if (frame && target)
Greg Claytond62b9c12012-02-03 07:02:37 +0000513 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000514 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
515 sb_value = GetValueForVariablePath (var_path, use_dynamic);
Greg Claytond62b9c12012-02-03 07:02:37 +0000516 }
517 return sb_value;
518}
519
520lldb::SBValue
521SBFrame::GetValueForVariablePath (const char *var_path, DynamicValueType use_dynamic)
522{
523 SBValue sb_value;
Greg Claytona894fe72012-04-05 16:12:35 +0000524 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000525 StackFrame *frame = exe_ctx.GetFramePtr();
526 Target *target = exe_ctx.GetTargetPtr();
527 if (frame && target && var_path && var_path[0])
Greg Claytond62b9c12012-02-03 07:02:37 +0000528 {
Greg Claytona894fe72012-04-05 16:12:35 +0000529 Process::StopLocker stop_locker;
530 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
531 {
532 Mutex::Locker api_locker (target->GetAPIMutex());
533 VariableSP var_sp;
534 Error error;
535 ValueObjectSP value_sp (frame->GetValueForVariableExpressionPath (var_path,
536 use_dynamic,
Greg Claytonb3a1a2b2012-07-14 00:53:55 +0000537 StackFrame::eExpressionPathOptionCheckPtrVsMember | StackFrame::eExpressionPathOptionsAllowDirectIVarAccess,
Greg Claytona894fe72012-04-05 16:12:35 +0000538 var_sp,
539 error));
540 sb_value.SetSP(value_sp);
541 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000542 else
543 {
544 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
545 if (log)
546 log->Printf ("SBFrame(%p)::GetValueForVariablePath () => error: process is running", frame);
547 }
Greg Claytond62b9c12012-02-03 07:02:37 +0000548 }
549 return sb_value;
550}
551
Chris Lattner24943d22010-06-08 16:52:24 +0000552SBValue
Greg Clayton4e9267d2010-12-14 18:39:31 +0000553SBFrame::FindVariable (const char *name)
Chris Lattner24943d22010-06-08 16:52:24 +0000554{
Greg Clayton582ed0e2011-06-18 20:06:08 +0000555 SBValue value;
Greg Claytona894fe72012-04-05 16:12:35 +0000556 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000557 StackFrame *frame = exe_ctx.GetFramePtr();
558 Target *target = exe_ctx.GetTargetPtr();
559 if (frame && target)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000560 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000561 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton582ed0e2011-06-18 20:06:08 +0000562 value = FindVariable (name, use_dynamic);
563 }
564 return value;
Jim Inghame41494a2011-04-16 00:01:13 +0000565}
Greg Claytond62b9c12012-02-03 07:02:37 +0000566
Jim Inghame41494a2011-04-16 00:01:13 +0000567
568SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000569SBFrame::FindVariable (const char *name, lldb::DynamicValueType use_dynamic)
Jim Inghame41494a2011-04-16 00:01:13 +0000570{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000571 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton4e9267d2010-12-14 18:39:31 +0000572 VariableSP var_sp;
Jim Ingham47da8102011-04-22 23:53:53 +0000573 SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000574 ValueObjectSP value_sp;
Greg Claytona894fe72012-04-05 16:12:35 +0000575 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000576 StackFrame *frame = exe_ctx.GetFramePtr();
577 Target *target = exe_ctx.GetTargetPtr();
578 if (frame && target && name && name[0])
Chris Lattner24943d22010-06-08 16:52:24 +0000579 {
Greg Claytona894fe72012-04-05 16:12:35 +0000580 Process::StopLocker stop_locker;
581 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Chris Lattner24943d22010-06-08 16:52:24 +0000582 {
Greg Claytona894fe72012-04-05 16:12:35 +0000583 VariableList variable_list;
584 Mutex::Locker api_locker (target->GetAPIMutex());
585 SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock));
586
587 if (sc.block)
Greg Claytondd62d722010-12-14 04:58:53 +0000588 {
Greg Claytona894fe72012-04-05 16:12:35 +0000589 const bool can_create = true;
590 const bool get_parent_variables = true;
591 const bool stop_if_block_is_inlined_function = true;
592
593 if (sc.block->AppendVariables (can_create,
594 get_parent_variables,
595 stop_if_block_is_inlined_function,
596 &variable_list))
597 {
598 var_sp = variable_list.FindVariable (ConstString(name));
599 }
600 }
601
602 if (var_sp)
603 {
604 value_sp = frame->GetValueObjectForFrameVariable(var_sp, use_dynamic);
605 sb_value.SetSP(value_sp);
Greg Claytondd62d722010-12-14 04:58:53 +0000606 }
Chris Lattner24943d22010-06-08 16:52:24 +0000607 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000608 else
609 {
610 if (log)
611 log->Printf ("SBFrame(%p)::FindVariable () => error: process is running", frame);
612 }
Chris Lattner24943d22010-06-08 16:52:24 +0000613 }
Caroline Tice98f930f2010-09-20 05:20:02 +0000614
Greg Claytona66ba462010-10-30 04:51:46 +0000615 if (log)
Greg Clayton4e9267d2010-12-14 18:39:31 +0000616 log->Printf ("SBFrame(%p)::FindVariable (name=\"%s\") => SBValue(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000617 frame, name, value_sp.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000618
Chris Lattner24943d22010-06-08 16:52:24 +0000619 return sb_value;
620}
621
622SBValue
Greg Clayton4e9267d2010-12-14 18:39:31 +0000623SBFrame::FindValue (const char *name, ValueType value_type)
Chris Lattner24943d22010-06-08 16:52:24 +0000624{
Greg Clayton582ed0e2011-06-18 20:06:08 +0000625 SBValue value;
Greg Claytona894fe72012-04-05 16:12:35 +0000626 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000627 StackFrame *frame = exe_ctx.GetFramePtr();
628 Target *target = exe_ctx.GetTargetPtr();
629 if (frame && target)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000630 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000631 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton582ed0e2011-06-18 20:06:08 +0000632 value = FindValue (name, value_type, use_dynamic);
633 }
634 return value;
Jim Inghame41494a2011-04-16 00:01:13 +0000635}
636
637SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000638SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueType use_dynamic)
Jim Inghame41494a2011-04-16 00:01:13 +0000639{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000640 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton4e9267d2010-12-14 18:39:31 +0000641 SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000642 ValueObjectSP value_sp;
Greg Claytona894fe72012-04-05 16:12:35 +0000643 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000644 StackFrame *frame = exe_ctx.GetFramePtr();
645 Target *target = exe_ctx.GetTargetPtr();
646 if (frame && target && name && name[0])
Chris Lattner24943d22010-06-08 16:52:24 +0000647 {
Greg Claytona894fe72012-04-05 16:12:35 +0000648 Process::StopLocker stop_locker;
649 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Chris Lattner24943d22010-06-08 16:52:24 +0000650 {
Greg Claytona894fe72012-04-05 16:12:35 +0000651 Mutex::Locker api_locker (target->GetAPIMutex());
652
653 switch (value_type)
Chris Lattner24943d22010-06-08 16:52:24 +0000654 {
Greg Claytona894fe72012-04-05 16:12:35 +0000655 case eValueTypeVariableGlobal: // global variable
656 case eValueTypeVariableStatic: // static variable
657 case eValueTypeVariableArgument: // function argument variables
658 case eValueTypeVariableLocal: // function local variables
659 {
660 VariableList *variable_list = frame->GetVariableList(true);
Greg Clayton4e9267d2010-12-14 18:39:31 +0000661
Greg Claytona894fe72012-04-05 16:12:35 +0000662 SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock));
Greg Clayton4e9267d2010-12-14 18:39:31 +0000663
Greg Claytona894fe72012-04-05 16:12:35 +0000664 const bool can_create = true;
665 const bool get_parent_variables = true;
666 const bool stop_if_block_is_inlined_function = true;
Greg Clayton4e9267d2010-12-14 18:39:31 +0000667
Greg Claytona894fe72012-04-05 16:12:35 +0000668 if (sc.block && sc.block->AppendVariables (can_create,
669 get_parent_variables,
670 stop_if_block_is_inlined_function,
671 variable_list))
672 {
673 ConstString const_name(name);
674 const uint32_t num_variables = variable_list->GetSize();
675 for (uint32_t i = 0; i < num_variables; ++i)
676 {
677 VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
678 if (variable_sp &&
679 variable_sp->GetScope() == value_type &&
680 variable_sp->GetName() == const_name)
681 {
682 value_sp = frame->GetValueObjectForFrameVariable (variable_sp, use_dynamic);
683 sb_value.SetSP (value_sp);
684 break;
685 }
686 }
687 }
688 }
689 break;
690
691 case eValueTypeRegister: // stack frame register value
692 {
693 RegisterContextSP reg_ctx (frame->GetRegisterContext());
694 if (reg_ctx)
695 {
696 const uint32_t num_regs = reg_ctx->GetRegisterCount();
697 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx)
698 {
699 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
700 if (reg_info &&
701 ((reg_info->name && strcasecmp (reg_info->name, name) == 0) ||
702 (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0)))
703 {
704 value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx);
705 sb_value.SetSP (value_sp);
706 break;
707 }
708 }
709 }
710 }
711 break;
712
713 case eValueTypeRegisterSet: // A collection of stack frame register values
714 {
715 RegisterContextSP reg_ctx (frame->GetRegisterContext());
716 if (reg_ctx)
717 {
718 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
719 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
720 {
721 const RegisterSet *reg_set = reg_ctx->GetRegisterSet (set_idx);
722 if (reg_set &&
723 ((reg_set->name && strcasecmp (reg_set->name, name) == 0) ||
724 (reg_set->short_name && strcasecmp (reg_set->short_name, name) == 0)))
725 {
726 value_sp = ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx);
727 sb_value.SetSP (value_sp);
728 break;
729 }
730 }
731 }
732 }
733 break;
734
735 case eValueTypeConstResult: // constant result variables
Johnny Chenc35750a2010-11-19 18:07:14 +0000736 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000737 ConstString const_name(name);
Greg Claytona894fe72012-04-05 16:12:35 +0000738 ClangExpressionVariableSP expr_var_sp (target->GetPersistentVariables().GetVariable (const_name));
739 if (expr_var_sp)
Johnny Chenc35750a2010-11-19 18:07:14 +0000740 {
Greg Claytona894fe72012-04-05 16:12:35 +0000741 value_sp = expr_var_sp->GetValueObject();
742 sb_value.SetSP (value_sp);
Johnny Chenc35750a2010-11-19 18:07:14 +0000743 }
744 }
Greg Claytona894fe72012-04-05 16:12:35 +0000745 break;
Greg Clayton4e9267d2010-12-14 18:39:31 +0000746
Greg Claytona894fe72012-04-05 16:12:35 +0000747 default:
748 break;
Greg Clayton4e9267d2010-12-14 18:39:31 +0000749 }
Chris Lattner24943d22010-06-08 16:52:24 +0000750 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000751 else
752 {
753 if (log)
754 log->Printf ("SBFrame(%p)::FindValue () => error: process is running", frame);
755 }
Chris Lattner24943d22010-06-08 16:52:24 +0000756 }
Caroline Tice98f930f2010-09-20 05:20:02 +0000757
Greg Claytona66ba462010-10-30 04:51:46 +0000758 if (log)
Greg Clayton4e9267d2010-12-14 18:39:31 +0000759 log->Printf ("SBFrame(%p)::FindVariableInScope (name=\"%s\", value_type=%i) => SBValue(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000760 frame, name, value_type, value_sp.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000761
762
Chris Lattner24943d22010-06-08 16:52:24 +0000763 return sb_value;
764}
765
766bool
Johnny Chen0164b752012-03-05 19:53:24 +0000767SBFrame::IsEqual (const SBFrame &that) const
768{
769 lldb::StackFrameSP this_sp = GetFrameSP();
770 lldb::StackFrameSP that_sp = that.GetFrameSP();
771 return (this_sp && that_sp && this_sp->GetStackID() == that_sp->GetStackID());
772}
773
774bool
Chris Lattner24943d22010-06-08 16:52:24 +0000775SBFrame::operator == (const SBFrame &rhs) const
776{
Johnny Chen0164b752012-03-05 19:53:24 +0000777 return IsEqual(rhs);
Chris Lattner24943d22010-06-08 16:52:24 +0000778}
779
780bool
781SBFrame::operator != (const SBFrame &rhs) const
782{
Johnny Chen0164b752012-03-05 19:53:24 +0000783 return !IsEqual(rhs);
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000784}
Chris Lattner24943d22010-06-08 16:52:24 +0000785
786SBThread
787SBFrame::GetThread () const
788{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000789 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000790
Greg Claytona894fe72012-04-05 16:12:35 +0000791 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000792 ThreadSP thread_sp (exe_ctx.GetThreadSP());
793 SBThread sb_thread (thread_sp);
Caroline Tice7826c882010-10-26 03:11:13 +0000794
795 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000796 {
797 SBStream sstr;
798 sb_thread.GetDescription (sstr);
Greg Clayton289afcb2012-02-18 05:35:26 +0000799 log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s",
800 exe_ctx.GetFramePtr(),
801 thread_sp.get(),
802 sstr.GetData());
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000803 }
Caroline Tice7826c882010-10-26 03:11:13 +0000804
Chris Lattner24943d22010-06-08 16:52:24 +0000805 return sb_thread;
806}
807
808const char *
809SBFrame::Disassemble () const
810{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000811 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000812 const char *disassembly = NULL;
Greg Claytona894fe72012-04-05 16:12:35 +0000813 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000814 StackFrame *frame = exe_ctx.GetFramePtr();
815 Target *target = exe_ctx.GetTargetPtr();
816 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000817 {
Greg Claytona894fe72012-04-05 16:12:35 +0000818 Process::StopLocker stop_locker;
819 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
820 {
821 Mutex::Locker api_locker (target->GetAPIMutex());
822 disassembly = frame->Disassemble();
823 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000824 else
825 {
826 if (log)
827 log->Printf ("SBFrame(%p)::Disassemble () => error: process is running", frame);
828 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000829 }
Greg Claytona66ba462010-10-30 04:51:46 +0000830
831 if (log)
Greg Clayton289afcb2012-02-18 05:35:26 +0000832 log->Printf ("SBFrame(%p)::Disassemble () => %s", frame, disassembly);
Greg Claytona66ba462010-10-30 04:51:46 +0000833
834 return disassembly;
Chris Lattner24943d22010-06-08 16:52:24 +0000835}
836
837
Chris Lattner24943d22010-06-08 16:52:24 +0000838SBValueList
839SBFrame::GetVariables (bool arguments,
840 bool locals,
841 bool statics,
842 bool in_scope_only)
843{
Greg Clayton582ed0e2011-06-18 20:06:08 +0000844 SBValueList value_list;
Greg Claytona894fe72012-04-05 16:12:35 +0000845 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000846 StackFrame *frame = exe_ctx.GetFramePtr();
847 Target *target = exe_ctx.GetTargetPtr();
848 if (frame && target)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000849 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000850 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton582ed0e2011-06-18 20:06:08 +0000851 value_list = GetVariables (arguments, locals, statics, in_scope_only, use_dynamic);
852 }
853 return value_list;
Jim Inghame41494a2011-04-16 00:01:13 +0000854}
855
856SBValueList
857SBFrame::GetVariables (bool arguments,
858 bool locals,
859 bool statics,
860 bool in_scope_only,
Jim Ingham10de7d12011-05-04 03:43:18 +0000861 lldb::DynamicValueType use_dynamic)
Jim Inghame41494a2011-04-16 00:01:13 +0000862{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000863 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000864
Greg Clayton334d33a2012-01-30 07:41:31 +0000865 SBValueList value_list;
Greg Claytona894fe72012-04-05 16:12:35 +0000866 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000867 StackFrame *frame = exe_ctx.GetFramePtr();
868 Target *target = exe_ctx.GetTargetPtr();
Greg Clayton334d33a2012-01-30 07:41:31 +0000869
Caroline Tice7826c882010-10-26 03:11:13 +0000870 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000871 log->Printf ("SBFrame(%p)::GetVariables (arguments=%i, locals=%i, statics=%i, in_scope_only=%i)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000872 frame,
Greg Claytona66ba462010-10-30 04:51:46 +0000873 arguments,
874 locals,
875 statics,
876 in_scope_only);
Greg Clayton334d33a2012-01-30 07:41:31 +0000877
Greg Clayton289afcb2012-02-18 05:35:26 +0000878 if (frame && target)
Chris Lattner24943d22010-06-08 16:52:24 +0000879 {
Greg Claytona894fe72012-04-05 16:12:35 +0000880 Process::StopLocker stop_locker;
881 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
882 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000883
Greg Claytona894fe72012-04-05 16:12:35 +0000884 size_t i;
885 VariableList *variable_list = NULL;
Jim Ingham887f62d2012-04-13 23:29:44 +0000886 Mutex::Locker api_locker (target->GetAPIMutex());
887 variable_list = frame->GetVariableList(true);
Greg Claytona894fe72012-04-05 16:12:35 +0000888 if (variable_list)
889 {
890 const size_t num_variables = variable_list->GetSize();
891 if (num_variables)
Chris Lattner24943d22010-06-08 16:52:24 +0000892 {
Greg Claytona894fe72012-04-05 16:12:35 +0000893 for (i = 0; i < num_variables; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000894 {
Greg Claytona894fe72012-04-05 16:12:35 +0000895 VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
896 if (variable_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000897 {
Greg Claytona894fe72012-04-05 16:12:35 +0000898 bool add_variable = false;
899 switch (variable_sp->GetScope())
900 {
901 case eValueTypeVariableGlobal:
902 case eValueTypeVariableStatic:
903 add_variable = statics;
904 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000905
Greg Claytona894fe72012-04-05 16:12:35 +0000906 case eValueTypeVariableArgument:
907 add_variable = arguments;
908 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000909
Greg Claytona894fe72012-04-05 16:12:35 +0000910 case eValueTypeVariableLocal:
911 add_variable = locals;
912 break;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000913
Greg Claytona894fe72012-04-05 16:12:35 +0000914 default:
915 break;
916 }
917 if (add_variable)
918 {
919 if (in_scope_only && !variable_sp->IsInScope(frame))
920 continue;
Chris Lattner24943d22010-06-08 16:52:24 +0000921
Greg Claytona894fe72012-04-05 16:12:35 +0000922 value_list.Append(frame->GetValueObjectForFrameVariable (variable_sp, use_dynamic));
923 }
Chris Lattner24943d22010-06-08 16:52:24 +0000924 }
925 }
926 }
927 }
Greg Claytona894fe72012-04-05 16:12:35 +0000928 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000929 else
930 {
931 if (log)
932 log->Printf ("SBFrame(%p)::GetVariables () => error: process is running", frame);
933 }
Chris Lattner24943d22010-06-08 16:52:24 +0000934 }
Caroline Tice7826c882010-10-26 03:11:13 +0000935
936 if (log)
937 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000938 log->Printf ("SBFrame(%p)::GetVariables (...) => SBValueList(%p)", frame,
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000939 value_list.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000940 }
941
Chris Lattner24943d22010-06-08 16:52:24 +0000942 return value_list;
943}
944
Greg Clayton4e9267d2010-12-14 18:39:31 +0000945SBValueList
Chris Lattner24943d22010-06-08 16:52:24 +0000946SBFrame::GetRegisters ()
947{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000948 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000949
Chris Lattner24943d22010-06-08 16:52:24 +0000950 SBValueList value_list;
Greg Claytona894fe72012-04-05 16:12:35 +0000951 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000952 StackFrame *frame = exe_ctx.GetFramePtr();
953 Target *target = exe_ctx.GetTargetPtr();
954 if (frame && target)
Chris Lattner24943d22010-06-08 16:52:24 +0000955 {
Greg Claytona894fe72012-04-05 16:12:35 +0000956 Process::StopLocker stop_locker;
957 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Chris Lattner24943d22010-06-08 16:52:24 +0000958 {
Greg Claytona894fe72012-04-05 16:12:35 +0000959 Mutex::Locker api_locker (target->GetAPIMutex());
960 RegisterContextSP reg_ctx (frame->GetRegisterContext());
961 if (reg_ctx)
Chris Lattner24943d22010-06-08 16:52:24 +0000962 {
Greg Claytona894fe72012-04-05 16:12:35 +0000963 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
964 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
965 {
966 value_list.Append(ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx));
967 }
Chris Lattner24943d22010-06-08 16:52:24 +0000968 }
969 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000970 else
971 {
972 if (log)
973 log->Printf ("SBFrame(%p)::GetRegisters () => error: process is running", frame);
974 }
Chris Lattner24943d22010-06-08 16:52:24 +0000975 }
Caroline Tice7826c882010-10-26 03:11:13 +0000976
977 if (log)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000978 log->Printf ("SBFrame(%p)::GetRegisters () => SBValueList(%p)", frame, value_list.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000979
Chris Lattner24943d22010-06-08 16:52:24 +0000980 return value_list;
981}
982
Caroline Tice98f930f2010-09-20 05:20:02 +0000983bool
984SBFrame::GetDescription (SBStream &description)
985{
Greg Clayton96154be2011-11-13 06:57:31 +0000986 Stream &strm = description.ref();
987
Greg Claytona894fe72012-04-05 16:12:35 +0000988 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000989 StackFrame *frame = exe_ctx.GetFramePtr();
990 Target *target = exe_ctx.GetTargetPtr();
991 if (frame && target)
Caroline Tice98f930f2010-09-20 05:20:02 +0000992 {
Greg Claytona894fe72012-04-05 16:12:35 +0000993 Process::StopLocker stop_locker;
994 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
995 {
996 Mutex::Locker api_locker (target->GetAPIMutex());
997 frame->DumpUsingSettingsFormat (&strm);
998 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000999 else
1000 {
1001 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1002 if (log)
1003 log->Printf ("SBFrame(%p)::GetDescription () => error: process is running", frame);
1004 }
1005
Caroline Tice98f930f2010-09-20 05:20:02 +00001006 }
1007 else
Greg Clayton96154be2011-11-13 06:57:31 +00001008 strm.PutCString ("No value");
Caroline Tice98f930f2010-09-20 05:20:02 +00001009
1010 return true;
1011}
Greg Clayton66ed2fb2010-10-05 00:00:42 +00001012
Greg Clayton4e9267d2010-12-14 18:39:31 +00001013SBValue
Greg Clayton66ed2fb2010-10-05 00:00:42 +00001014SBFrame::EvaluateExpression (const char *expr)
1015{
Greg Clayton582ed0e2011-06-18 20:06:08 +00001016 SBValue result;
Greg Claytona894fe72012-04-05 16:12:35 +00001017 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +00001018 StackFrame *frame = exe_ctx.GetFramePtr();
1019 Target *target = exe_ctx.GetTargetPtr();
1020 if (frame && target)
Greg Clayton582ed0e2011-06-18 20:06:08 +00001021 {
Greg Clayton289afcb2012-02-18 05:35:26 +00001022 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton582ed0e2011-06-18 20:06:08 +00001023 result = EvaluateExpression (expr, use_dynamic);
1024 }
1025 return result;
Jim Inghame41494a2011-04-16 00:01:13 +00001026}
1027
1028SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +00001029SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value)
Jim Inghame41494a2011-04-16 00:01:13 +00001030{
Jim Inghamd82bc6d2012-05-11 23:47:32 +00001031 return EvaluateExpression (expr, fetch_dynamic_value, true);
1032}
1033
1034SBValue
1035SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value, bool unwind_on_error)
1036{
Greg Clayton4e9267d2010-12-14 18:39:31 +00001037 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Sean Callanan94d255f2010-12-07 22:55:01 +00001038
Greg Clayton4e9267d2010-12-14 18:39:31 +00001039 LogSP expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Greg Claytona66ba462010-10-30 04:51:46 +00001040
Johnny Chenee6e7902011-08-10 22:06:24 +00001041 ExecutionResults exe_results;
Greg Clayton4e9267d2010-12-14 18:39:31 +00001042 SBValue expr_result;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001043 ValueObjectSP expr_value_sp;
Greg Claytona66ba462010-10-30 04:51:46 +00001044
Greg Claytona894fe72012-04-05 16:12:35 +00001045 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +00001046 StackFrame *frame = exe_ctx.GetFramePtr();
1047 Target *target = exe_ctx.GetTargetPtr();
Greg Clayton334d33a2012-01-30 07:41:31 +00001048 if (log)
Greg Clayton289afcb2012-02-18 05:35:26 +00001049 log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\")...", frame, expr);
Greg Clayton334d33a2012-01-30 07:41:31 +00001050
Greg Clayton289afcb2012-02-18 05:35:26 +00001051 if (frame && target)
Greg Clayton66ed2fb2010-10-05 00:00:42 +00001052 {
Jim Ingham9274ba32012-04-19 00:14:53 +00001053 Mutex::Locker api_locker (target->GetAPIMutex());
1054
Greg Claytona894fe72012-04-05 16:12:35 +00001055 Process::StopLocker stop_locker;
1056 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1057 {
Enrico Granata299aa702012-05-29 18:06:49 +00001058#ifdef LLDB_CONFIGURATION_DEBUG
Greg Claytona894fe72012-04-05 16:12:35 +00001059 StreamString frame_description;
1060 frame->DumpUsingSettingsFormat (&frame_description);
Greg Claytona894fe72012-04-05 16:12:35 +00001061 Host::SetCrashDescriptionWithFormat ("SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
1062 expr, fetch_dynamic_value, frame_description.GetString().c_str());
Enrico Granata299aa702012-05-29 18:06:49 +00001063#endif
Greg Claytona894fe72012-04-05 16:12:35 +00001064 const bool coerce_to_id = false;
Greg Claytona894fe72012-04-05 16:12:35 +00001065 const bool keep_in_memory = false;
1066
1067 exe_results = target->EvaluateExpression (expr,
1068 frame,
1069 eExecutionPolicyOnlyWhenNeeded,
1070 coerce_to_id,
1071 unwind_on_error,
1072 keep_in_memory,
1073 fetch_dynamic_value,
1074 expr_value_sp);
1075 expr_result.SetSP(expr_value_sp);
Enrico Granata299aa702012-05-29 18:06:49 +00001076#ifdef LLDB_CONFIGURATION_DEBUG
Greg Claytona894fe72012-04-05 16:12:35 +00001077 Host::SetCrashDescription (NULL);
Enrico Granata299aa702012-05-29 18:06:49 +00001078#endif
Greg Claytona894fe72012-04-05 16:12:35 +00001079 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001080 else
1081 {
1082 if (log)
1083 log->Printf ("SBFrame(%p)::EvaluateExpression () => error: process is running", frame);
1084 }
Greg Clayton66ed2fb2010-10-05 00:00:42 +00001085 }
Jason Molendac48ca822012-02-21 05:33:55 +00001086
1087#ifndef LLDB_DISABLE_PYTHON
Sean Callanan94d255f2010-12-07 22:55:01 +00001088 if (expr_log)
Jim Inghame41494a2011-04-16 00:01:13 +00001089 expr_log->Printf("** [SBFrame::EvaluateExpression] Expression result is %s, summary %s **",
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001090 expr_result.GetValue(),
1091 expr_result.GetSummary());
Sean Callanan94d255f2010-12-07 22:55:01 +00001092
Greg Claytona66ba462010-10-30 04:51:46 +00001093 if (log)
Greg Clayton289afcb2012-02-18 05:35:26 +00001094 log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)",
1095 frame,
Jim Inghame41494a2011-04-16 00:01:13 +00001096 expr,
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001097 expr_value_sp.get(),
Johnny Chenee6e7902011-08-10 22:06:24 +00001098 exe_results);
Jason Molendac48ca822012-02-21 05:33:55 +00001099#endif
Greg Claytona66ba462010-10-30 04:51:46 +00001100
Greg Clayton49ce6822010-10-31 03:01:06 +00001101 return expr_result;
Greg Clayton66ed2fb2010-10-05 00:00:42 +00001102}
Greg Clayton582ed0e2011-06-18 20:06:08 +00001103
1104bool
1105SBFrame::IsInlined()
1106{
Greg Claytona894fe72012-04-05 16:12:35 +00001107 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +00001108 StackFrame *frame = exe_ctx.GetFramePtr();
1109 Target *target = exe_ctx.GetTargetPtr();
1110 if (frame && target)
Greg Clayton582ed0e2011-06-18 20:06:08 +00001111 {
Greg Claytona894fe72012-04-05 16:12:35 +00001112 Process::StopLocker stop_locker;
1113 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1114 {
1115
1116 Block *block = frame->GetSymbolContext(eSymbolContextBlock).block;
1117 if (block)
1118 return block->GetContainingInlinedBlock () != NULL;
1119 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001120 else
1121 {
1122 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1123 if (log)
1124 log->Printf ("SBFrame(%p)::IsInlined () => error: process is running", frame);
1125 }
1126
Greg Clayton582ed0e2011-06-18 20:06:08 +00001127 }
1128 return false;
1129}
1130
1131const char *
1132SBFrame::GetFunctionName()
1133{
1134 const char *name = NULL;
Greg Claytona894fe72012-04-05 16:12:35 +00001135 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +00001136 StackFrame *frame = exe_ctx.GetFramePtr();
1137 Target *target = exe_ctx.GetTargetPtr();
1138 if (frame && target)
Greg Clayton582ed0e2011-06-18 20:06:08 +00001139 {
Greg Claytona894fe72012-04-05 16:12:35 +00001140 Process::StopLocker stop_locker;
1141 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Greg Clayton582ed0e2011-06-18 20:06:08 +00001142 {
Greg Claytona894fe72012-04-05 16:12:35 +00001143 SymbolContext sc (frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol));
1144 if (sc.block)
Greg Clayton582ed0e2011-06-18 20:06:08 +00001145 {
Greg Claytona894fe72012-04-05 16:12:35 +00001146 Block *inlined_block = sc.block->GetContainingInlinedBlock ();
1147 if (inlined_block)
1148 {
1149 const InlineFunctionInfo* inlined_info = inlined_block->GetInlinedFunctionInfo();
1150 name = inlined_info->GetName().AsCString();
1151 }
Greg Clayton582ed0e2011-06-18 20:06:08 +00001152 }
Greg Claytona894fe72012-04-05 16:12:35 +00001153
1154 if (name == NULL)
1155 {
1156 if (sc.function)
1157 name = sc.function->GetName().GetCString();
1158 }
Greg Clayton582ed0e2011-06-18 20:06:08 +00001159
Greg Claytona894fe72012-04-05 16:12:35 +00001160 if (name == NULL)
1161 {
1162 if (sc.symbol)
1163 name = sc.symbol->GetName().GetCString();
1164 }
Greg Clayton582ed0e2011-06-18 20:06:08 +00001165 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001166 else
1167 {
1168 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1169 if (log)
1170 log->Printf ("SBFrame(%p)::GetFunctionName() => error: process is running", frame);
1171
1172 }
Greg Clayton582ed0e2011-06-18 20:06:08 +00001173 }
1174 return name;
1175}
1176