blob: c84ac13597c65ffe02b29ef9fdb42cb58bc996f9 [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 Claytona894fe72012-04-05 16:12:35 +000089 return m_opaque_sp->GetFrameSP();
Chris Lattner24943d22010-06-08 16:52:24 +000090}
91
Greg Clayton334d33a2012-01-30 07:41:31 +000092void
93SBFrame::SetFrameSP (const StackFrameSP &lldb_object_sp)
94{
Greg Claytona894fe72012-04-05 16:12:35 +000095 return m_opaque_sp->SetFrameSP(lldb_object_sp);
Greg Clayton334d33a2012-01-30 07:41:31 +000096}
Chris Lattner24943d22010-06-08 16:52:24 +000097
98bool
99SBFrame::IsValid() const
100{
Greg Claytona894fe72012-04-05 16:12:35 +0000101 return GetFrameSP().get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +0000102}
103
104SBSymbolContext
105SBFrame::GetSymbolContext (uint32_t resolve_scope) const
106{
Caroline Tice7826c882010-10-26 03:11:13 +0000107
Chris Lattner24943d22010-06-08 16:52:24 +0000108 SBSymbolContext sb_sym_ctx;
Greg Claytona894fe72012-04-05 16:12:35 +0000109 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000110 StackFrame *frame = exe_ctx.GetFramePtr();
111 Target *target = exe_ctx.GetTargetPtr();
112 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000113 {
Greg Claytona894fe72012-04-05 16:12:35 +0000114 Process::StopLocker stop_locker;
115 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
116 {
117 Mutex::Locker api_locker (target->GetAPIMutex());
118 sb_sym_ctx.SetSymbolContext(&frame->GetSymbolContext (resolve_scope));
119 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000120 }
Caroline Tice7826c882010-10-26 03:11:13 +0000121
Greg Clayton4e9267d2010-12-14 18:39:31 +0000122 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000123 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000124 log->Printf ("SBFrame(%p)::GetSymbolContext (resolve_scope=0x%8.8x) => SBSymbolContext(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000125 frame, resolve_scope, sb_sym_ctx.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000126
Chris Lattner24943d22010-06-08 16:52:24 +0000127 return sb_sym_ctx;
128}
129
130SBModule
131SBFrame::GetModule () const
132{
Greg Claytondd62d722010-12-14 04:58:53 +0000133 SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000134 ModuleSP module_sp;
Greg Claytona894fe72012-04-05 16:12:35 +0000135 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000136 StackFrame *frame = exe_ctx.GetFramePtr();
137 Target *target = exe_ctx.GetTargetPtr();
138 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000139 {
Greg Claytona894fe72012-04-05 16:12:35 +0000140 Process::StopLocker stop_locker;
141 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
142 {
143 Mutex::Locker api_locker (target->GetAPIMutex());
144 module_sp = frame->GetSymbolContext (eSymbolContextModule).module_sp;
145 sb_module.SetSP (module_sp);
146 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000147 }
Greg Claytondd62d722010-12-14 04:58:53 +0000148
Greg Clayton4e9267d2010-12-14 18:39:31 +0000149 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000150 if (log)
151 log->Printf ("SBFrame(%p)::GetModule () => SBModule(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000152 frame, module_sp.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000153
Chris Lattner24943d22010-06-08 16:52:24 +0000154 return sb_module;
155}
156
157SBCompileUnit
158SBFrame::GetCompileUnit () const
159{
Greg Claytondd62d722010-12-14 04:58:53 +0000160 SBCompileUnit sb_comp_unit;
Greg Claytona894fe72012-04-05 16:12:35 +0000161 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000162 StackFrame *frame = exe_ctx.GetFramePtr();
163 Target *target = exe_ctx.GetTargetPtr();
164 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000165 {
Greg Claytona894fe72012-04-05 16:12:35 +0000166 Process::StopLocker stop_locker;
167 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
168 {
169 Mutex::Locker api_locker (target->GetAPIMutex());
170 sb_comp_unit.reset (frame->GetSymbolContext (eSymbolContextCompUnit).comp_unit);
171 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000172 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000173 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000174 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000175 log->Printf ("SBFrame(%p)::GetModule () => SBCompileUnit(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000176 frame, sb_comp_unit.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000177
Chris Lattner24943d22010-06-08 16:52:24 +0000178 return sb_comp_unit;
179}
180
181SBFunction
182SBFrame::GetFunction () const
183{
Greg Claytondd62d722010-12-14 04:58:53 +0000184 SBFunction sb_function;
Greg Claytona894fe72012-04-05 16:12:35 +0000185 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000186 StackFrame *frame = exe_ctx.GetFramePtr();
187 Target *target = exe_ctx.GetTargetPtr();
188 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000189 {
Greg Claytona894fe72012-04-05 16:12:35 +0000190 Process::StopLocker stop_locker;
191 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
192 {
193 Mutex::Locker api_locker (target->GetAPIMutex());
194 sb_function.reset(frame->GetSymbolContext (eSymbolContextFunction).function);
195 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000196 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000197 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000198 if (log)
199 log->Printf ("SBFrame(%p)::GetFunction () => SBFunction(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000200 frame, sb_function.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000201
Chris Lattner24943d22010-06-08 16:52:24 +0000202 return sb_function;
203}
204
Greg Clayton8f1e08b2010-10-04 18:37:52 +0000205SBSymbol
206SBFrame::GetSymbol () const
207{
Greg Claytondd62d722010-12-14 04:58:53 +0000208 SBSymbol sb_symbol;
Greg Claytona894fe72012-04-05 16:12:35 +0000209 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000210 StackFrame *frame = exe_ctx.GetFramePtr();
211 Target *target = exe_ctx.GetTargetPtr();
212 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000213 {
Greg Claytona894fe72012-04-05 16:12:35 +0000214 Process::StopLocker stop_locker;
215 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
216 {
217 Mutex::Locker api_locker (target->GetAPIMutex());
218 sb_symbol.reset(frame->GetSymbolContext (eSymbolContextSymbol).symbol);
219 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000220 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000221 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000222 if (log)
223 log->Printf ("SBFrame(%p)::GetSymbol () => SBSymbol(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000224 frame, sb_symbol.get());
Greg Clayton8f1e08b2010-10-04 18:37:52 +0000225 return sb_symbol;
226}
227
Chris Lattner24943d22010-06-08 16:52:24 +0000228SBBlock
229SBFrame::GetBlock () const
230{
Greg Claytondd62d722010-12-14 04:58:53 +0000231 SBBlock sb_block;
Greg Claytona894fe72012-04-05 16:12:35 +0000232 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000233 StackFrame *frame = exe_ctx.GetFramePtr();
234 Target *target = exe_ctx.GetTargetPtr();
235 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000236 {
Greg Claytona894fe72012-04-05 16:12:35 +0000237 Process::StopLocker stop_locker;
238 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
239 {
240 Mutex::Locker api_locker (target->GetAPIMutex());
241 sb_block.SetPtr (frame->GetSymbolContext (eSymbolContextBlock).block);
242 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000243 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000244 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000245 if (log)
246 log->Printf ("SBFrame(%p)::GetBlock () => SBBlock(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000247 frame, sb_block.GetPtr());
Chris Lattner24943d22010-06-08 16:52:24 +0000248 return sb_block;
249}
250
Greg Clayton69aa5d92010-09-07 04:20:48 +0000251SBBlock
252SBFrame::GetFrameBlock () const
253{
Greg Claytondd62d722010-12-14 04:58:53 +0000254 SBBlock sb_block;
Greg Claytona894fe72012-04-05 16:12:35 +0000255 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000256 StackFrame *frame = exe_ctx.GetFramePtr();
257 Target *target = exe_ctx.GetTargetPtr();
258 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000259 {
Greg Claytona894fe72012-04-05 16:12:35 +0000260 Process::StopLocker stop_locker;
261 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
262 {
263 Mutex::Locker api_locker (target->GetAPIMutex());
264 sb_block.SetPtr(frame->GetFrameBlock ());
265 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000266 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000267 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000268 if (log)
269 log->Printf ("SBFrame(%p)::GetFrameBlock () => SBBlock(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000270 frame, sb_block.GetPtr());
Greg Clayton69aa5d92010-09-07 04:20:48 +0000271 return sb_block;
272}
273
Chris Lattner24943d22010-06-08 16:52:24 +0000274SBLineEntry
275SBFrame::GetLineEntry () const
276{
Greg Claytondd62d722010-12-14 04:58:53 +0000277 SBLineEntry sb_line_entry;
Greg Claytona894fe72012-04-05 16:12:35 +0000278 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000279 StackFrame *frame = exe_ctx.GetFramePtr();
280 Target *target = exe_ctx.GetTargetPtr();
281 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000282 {
Greg Claytona894fe72012-04-05 16:12:35 +0000283 Process::StopLocker stop_locker;
284 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
285 {
286 Mutex::Locker api_locker (target->GetAPIMutex());
287 sb_line_entry.SetLineEntry (frame->GetSymbolContext (eSymbolContextLineEntry).line_entry);
288 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000289 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000290 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000291 if (log)
292 log->Printf ("SBFrame(%p)::GetLineEntry () => SBLineEntry(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000293 frame, sb_line_entry.get());
Chris Lattner24943d22010-06-08 16:52:24 +0000294 return sb_line_entry;
295}
296
297uint32_t
298SBFrame::GetFrameID () const
299{
Greg Clayton334d33a2012-01-30 07:41:31 +0000300 uint32_t frame_idx = UINT32_MAX;
301
Greg Claytona894fe72012-04-05 16:12:35 +0000302 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000303 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Claytona894fe72012-04-05 16:12:35 +0000304 if (frame)
Greg Clayton289afcb2012-02-18 05:35:26 +0000305 frame_idx = frame->GetFrameIndex ();
Greg Claytona66ba462010-10-30 04:51:46 +0000306
Greg Clayton4e9267d2010-12-14 18:39:31 +0000307 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000308 if (log)
309 log->Printf ("SBFrame(%p)::GetFrameID () => %u",
Greg Clayton289afcb2012-02-18 05:35:26 +0000310 frame, frame_idx);
Greg Claytona66ba462010-10-30 04:51:46 +0000311 return frame_idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000312}
313
Greg Clayton4e9267d2010-12-14 18:39:31 +0000314addr_t
Chris Lattner24943d22010-06-08 16:52:24 +0000315SBFrame::GetPC () const
316{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000317 addr_t addr = LLDB_INVALID_ADDRESS;
Greg Claytona894fe72012-04-05 16:12:35 +0000318 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000319 StackFrame *frame = exe_ctx.GetFramePtr();
320 Target *target = exe_ctx.GetTargetPtr();
321 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000322 {
Greg Claytona894fe72012-04-05 16:12:35 +0000323 Process::StopLocker stop_locker;
324 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
325 {
326 Mutex::Locker api_locker (target->GetAPIMutex());
327 addr = frame->GetFrameCodeAddress().GetOpcodeLoadAddress (target);
328 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000329 }
Caroline Tice7826c882010-10-26 03:11:13 +0000330
Greg Clayton4e9267d2010-12-14 18:39:31 +0000331 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000332 if (log)
Greg Clayton289afcb2012-02-18 05:35:26 +0000333 log->Printf ("SBFrame(%p)::GetPC () => 0x%llx", frame, addr);
Caroline Tice7826c882010-10-26 03:11:13 +0000334
335 return addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000336}
337
338bool
Greg Clayton4e9267d2010-12-14 18:39:31 +0000339SBFrame::SetPC (addr_t new_pc)
Chris Lattner24943d22010-06-08 16:52:24 +0000340{
Caroline Tice7826c882010-10-26 03:11:13 +0000341 bool ret_val = false;
Greg Claytona894fe72012-04-05 16:12:35 +0000342 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000343 StackFrame *frame = exe_ctx.GetFramePtr();
344 Target *target = exe_ctx.GetTargetPtr();
345 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000346 {
Greg Claytona894fe72012-04-05 16:12:35 +0000347 Process::StopLocker stop_locker;
348 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
349 {
350 Mutex::Locker api_locker (target->GetAPIMutex());
351 ret_val = frame->GetRegisterContext()->SetPC (new_pc);
352 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000353 }
Caroline Tice7826c882010-10-26 03:11:13 +0000354
Greg Clayton4e9267d2010-12-14 18:39:31 +0000355 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000356 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000357 log->Printf ("SBFrame(%p)::SetPC (new_pc=0x%llx) => %i",
Greg Clayton289afcb2012-02-18 05:35:26 +0000358 frame, new_pc, ret_val);
Caroline Tice7826c882010-10-26 03:11:13 +0000359
360 return ret_val;
Chris Lattner24943d22010-06-08 16:52:24 +0000361}
362
Greg Clayton4e9267d2010-12-14 18:39:31 +0000363addr_t
Chris Lattner24943d22010-06-08 16:52:24 +0000364SBFrame::GetSP () const
365{
Greg Claytona66ba462010-10-30 04:51:46 +0000366 addr_t addr = LLDB_INVALID_ADDRESS;
Greg Claytona894fe72012-04-05 16:12:35 +0000367 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000368 StackFrame *frame = exe_ctx.GetFramePtr();
369 Target *target = exe_ctx.GetTargetPtr();
370 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000371 {
Greg Claytona894fe72012-04-05 16:12:35 +0000372 Process::StopLocker stop_locker;
373 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
374 {
375 Mutex::Locker api_locker (target->GetAPIMutex());
376 addr = frame->GetRegisterContext()->GetSP();
377 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000378 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000379 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000380 if (log)
Greg Clayton289afcb2012-02-18 05:35:26 +0000381 log->Printf ("SBFrame(%p)::GetSP () => 0x%llx", frame, addr);
Greg Claytona66ba462010-10-30 04:51:46 +0000382
383 return addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000384}
385
386
Greg Clayton4e9267d2010-12-14 18:39:31 +0000387addr_t
Chris Lattner24943d22010-06-08 16:52:24 +0000388SBFrame::GetFP () const
389{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000390 addr_t addr = LLDB_INVALID_ADDRESS;
Greg Claytona894fe72012-04-05 16:12:35 +0000391 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000392 StackFrame *frame = exe_ctx.GetFramePtr();
393 Target *target = exe_ctx.GetTargetPtr();
394 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000395 {
Greg Claytona894fe72012-04-05 16:12:35 +0000396 Process::StopLocker stop_locker;
397 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
398 {
399 Mutex::Locker api_locker (target->GetAPIMutex());
400 addr = frame->GetRegisterContext()->GetFP();
401 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000402 }
Caroline Tice7826c882010-10-26 03:11:13 +0000403
Greg Clayton4e9267d2010-12-14 18:39:31 +0000404 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000405 if (log)
Greg Clayton289afcb2012-02-18 05:35:26 +0000406 log->Printf ("SBFrame(%p)::GetFP () => 0x%llx", frame, addr);
Caroline Tice7826c882010-10-26 03:11:13 +0000407 return addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000408}
409
410
411SBAddress
412SBFrame::GetPCAddress () const
413{
414 SBAddress sb_addr;
Greg Claytona894fe72012-04-05 16:12:35 +0000415 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000416 StackFrame *frame = exe_ctx.GetFramePtr();
417 Target *target = exe_ctx.GetTargetPtr();
418 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000419 {
Greg Claytona894fe72012-04-05 16:12:35 +0000420 Process::StopLocker stop_locker;
421 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
422 {
423 Mutex::Locker api_locker (target->GetAPIMutex());
424 sb_addr.SetAddress (&frame->GetFrameCodeAddress());
425 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000426 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000427 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000428 if (log)
Greg Clayton289afcb2012-02-18 05:35:26 +0000429 log->Printf ("SBFrame(%p)::GetPCAddress () => SBAddress(%p)", frame, sb_addr.get());
Chris Lattner24943d22010-06-08 16:52:24 +0000430 return sb_addr;
431}
432
433void
434SBFrame::Clear()
435{
Greg Clayton63094e02010-06-23 01:19:29 +0000436 m_opaque_sp.reset();
Chris Lattner24943d22010-06-08 16:52:24 +0000437}
438
Greg Claytond62b9c12012-02-03 07:02:37 +0000439lldb::SBValue
440SBFrame::GetValueForVariablePath (const char *var_path)
441{
442 SBValue sb_value;
Greg Claytona894fe72012-04-05 16:12:35 +0000443 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000444 StackFrame *frame = exe_ctx.GetFramePtr();
445 Target *target = exe_ctx.GetTargetPtr();
446 if (frame && target)
Greg Claytond62b9c12012-02-03 07:02:37 +0000447 {
Greg Claytona894fe72012-04-05 16:12:35 +0000448 Process::StopLocker stop_locker;
449 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
450 {
451 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
452 sb_value = GetValueForVariablePath (var_path, use_dynamic);
453 }
Greg Claytond62b9c12012-02-03 07:02:37 +0000454 }
455 return sb_value;
456}
457
458lldb::SBValue
459SBFrame::GetValueForVariablePath (const char *var_path, DynamicValueType use_dynamic)
460{
461 SBValue sb_value;
Greg Claytona894fe72012-04-05 16:12:35 +0000462 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000463 StackFrame *frame = exe_ctx.GetFramePtr();
464 Target *target = exe_ctx.GetTargetPtr();
465 if (frame && target && var_path && var_path[0])
Greg Claytond62b9c12012-02-03 07:02:37 +0000466 {
Greg Claytona894fe72012-04-05 16:12:35 +0000467 Process::StopLocker stop_locker;
468 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
469 {
470 Mutex::Locker api_locker (target->GetAPIMutex());
471 VariableSP var_sp;
472 Error error;
473 ValueObjectSP value_sp (frame->GetValueForVariableExpressionPath (var_path,
474 use_dynamic,
475 StackFrame::eExpressionPathOptionCheckPtrVsMember,
476 var_sp,
477 error));
478 sb_value.SetSP(value_sp);
479 }
Greg Claytond62b9c12012-02-03 07:02:37 +0000480 }
481 return sb_value;
482}
483
Chris Lattner24943d22010-06-08 16:52:24 +0000484SBValue
Greg Clayton4e9267d2010-12-14 18:39:31 +0000485SBFrame::FindVariable (const char *name)
Chris Lattner24943d22010-06-08 16:52:24 +0000486{
Greg Clayton582ed0e2011-06-18 20:06:08 +0000487 SBValue value;
Greg Claytona894fe72012-04-05 16:12:35 +0000488 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000489 StackFrame *frame = exe_ctx.GetFramePtr();
490 Target *target = exe_ctx.GetTargetPtr();
491 if (frame && target)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000492 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000493 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton582ed0e2011-06-18 20:06:08 +0000494 value = FindVariable (name, use_dynamic);
495 }
496 return value;
Jim Inghame41494a2011-04-16 00:01:13 +0000497}
Greg Claytond62b9c12012-02-03 07:02:37 +0000498
Jim Inghame41494a2011-04-16 00:01:13 +0000499
500SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000501SBFrame::FindVariable (const char *name, lldb::DynamicValueType use_dynamic)
Jim Inghame41494a2011-04-16 00:01:13 +0000502{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000503 VariableSP var_sp;
Jim Ingham47da8102011-04-22 23:53:53 +0000504 SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000505 ValueObjectSP value_sp;
Greg Claytona894fe72012-04-05 16:12:35 +0000506 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000507 StackFrame *frame = exe_ctx.GetFramePtr();
508 Target *target = exe_ctx.GetTargetPtr();
509 if (frame && target && name && name[0])
Chris Lattner24943d22010-06-08 16:52:24 +0000510 {
Greg Claytona894fe72012-04-05 16:12:35 +0000511 Process::StopLocker stop_locker;
512 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Chris Lattner24943d22010-06-08 16:52:24 +0000513 {
Greg Claytona894fe72012-04-05 16:12:35 +0000514 VariableList variable_list;
515 Mutex::Locker api_locker (target->GetAPIMutex());
516 SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock));
517
518 if (sc.block)
Greg Claytondd62d722010-12-14 04:58:53 +0000519 {
Greg Claytona894fe72012-04-05 16:12:35 +0000520 const bool can_create = true;
521 const bool get_parent_variables = true;
522 const bool stop_if_block_is_inlined_function = true;
523
524 if (sc.block->AppendVariables (can_create,
525 get_parent_variables,
526 stop_if_block_is_inlined_function,
527 &variable_list))
528 {
529 var_sp = variable_list.FindVariable (ConstString(name));
530 }
531 }
532
533 if (var_sp)
534 {
535 value_sp = frame->GetValueObjectForFrameVariable(var_sp, use_dynamic);
536 sb_value.SetSP(value_sp);
Greg Claytondd62d722010-12-14 04:58:53 +0000537 }
Chris Lattner24943d22010-06-08 16:52:24 +0000538 }
Chris Lattner24943d22010-06-08 16:52:24 +0000539 }
Caroline Tice98f930f2010-09-20 05:20:02 +0000540
Greg Clayton4e9267d2010-12-14 18:39:31 +0000541 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000542 if (log)
Greg Clayton4e9267d2010-12-14 18:39:31 +0000543 log->Printf ("SBFrame(%p)::FindVariable (name=\"%s\") => SBValue(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000544 frame, name, value_sp.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000545
Chris Lattner24943d22010-06-08 16:52:24 +0000546 return sb_value;
547}
548
549SBValue
Greg Clayton4e9267d2010-12-14 18:39:31 +0000550SBFrame::FindValue (const char *name, ValueType value_type)
Chris Lattner24943d22010-06-08 16:52:24 +0000551{
Greg Clayton582ed0e2011-06-18 20:06:08 +0000552 SBValue value;
Greg Claytona894fe72012-04-05 16:12:35 +0000553 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000554 StackFrame *frame = exe_ctx.GetFramePtr();
555 Target *target = exe_ctx.GetTargetPtr();
556 if (frame && target)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000557 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000558 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton582ed0e2011-06-18 20:06:08 +0000559 value = FindValue (name, value_type, use_dynamic);
560 }
561 return value;
Jim Inghame41494a2011-04-16 00:01:13 +0000562}
563
564SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000565SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueType use_dynamic)
Jim Inghame41494a2011-04-16 00:01:13 +0000566{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000567 SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000568 ValueObjectSP value_sp;
Greg Claytona894fe72012-04-05 16:12:35 +0000569 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000570 StackFrame *frame = exe_ctx.GetFramePtr();
571 Target *target = exe_ctx.GetTargetPtr();
572 if (frame && target && name && name[0])
Chris Lattner24943d22010-06-08 16:52:24 +0000573 {
Greg Claytona894fe72012-04-05 16:12:35 +0000574 Process::StopLocker stop_locker;
575 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Chris Lattner24943d22010-06-08 16:52:24 +0000576 {
Greg Claytona894fe72012-04-05 16:12:35 +0000577 Mutex::Locker api_locker (target->GetAPIMutex());
578
579 switch (value_type)
Chris Lattner24943d22010-06-08 16:52:24 +0000580 {
Greg Claytona894fe72012-04-05 16:12:35 +0000581 case eValueTypeVariableGlobal: // global variable
582 case eValueTypeVariableStatic: // static variable
583 case eValueTypeVariableArgument: // function argument variables
584 case eValueTypeVariableLocal: // function local variables
585 {
586 VariableList *variable_list = frame->GetVariableList(true);
Greg Clayton4e9267d2010-12-14 18:39:31 +0000587
Greg Claytona894fe72012-04-05 16:12:35 +0000588 SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock));
Greg Clayton4e9267d2010-12-14 18:39:31 +0000589
Greg Claytona894fe72012-04-05 16:12:35 +0000590 const bool can_create = true;
591 const bool get_parent_variables = true;
592 const bool stop_if_block_is_inlined_function = true;
Greg Clayton4e9267d2010-12-14 18:39:31 +0000593
Greg Claytona894fe72012-04-05 16:12:35 +0000594 if (sc.block && sc.block->AppendVariables (can_create,
595 get_parent_variables,
596 stop_if_block_is_inlined_function,
597 variable_list))
598 {
599 ConstString const_name(name);
600 const uint32_t num_variables = variable_list->GetSize();
601 for (uint32_t i = 0; i < num_variables; ++i)
602 {
603 VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
604 if (variable_sp &&
605 variable_sp->GetScope() == value_type &&
606 variable_sp->GetName() == const_name)
607 {
608 value_sp = frame->GetValueObjectForFrameVariable (variable_sp, use_dynamic);
609 sb_value.SetSP (value_sp);
610 break;
611 }
612 }
613 }
614 }
615 break;
616
617 case eValueTypeRegister: // stack frame register value
618 {
619 RegisterContextSP reg_ctx (frame->GetRegisterContext());
620 if (reg_ctx)
621 {
622 const uint32_t num_regs = reg_ctx->GetRegisterCount();
623 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx)
624 {
625 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
626 if (reg_info &&
627 ((reg_info->name && strcasecmp (reg_info->name, name) == 0) ||
628 (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0)))
629 {
630 value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx);
631 sb_value.SetSP (value_sp);
632 break;
633 }
634 }
635 }
636 }
637 break;
638
639 case eValueTypeRegisterSet: // A collection of stack frame register values
640 {
641 RegisterContextSP reg_ctx (frame->GetRegisterContext());
642 if (reg_ctx)
643 {
644 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
645 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
646 {
647 const RegisterSet *reg_set = reg_ctx->GetRegisterSet (set_idx);
648 if (reg_set &&
649 ((reg_set->name && strcasecmp (reg_set->name, name) == 0) ||
650 (reg_set->short_name && strcasecmp (reg_set->short_name, name) == 0)))
651 {
652 value_sp = ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx);
653 sb_value.SetSP (value_sp);
654 break;
655 }
656 }
657 }
658 }
659 break;
660
661 case eValueTypeConstResult: // constant result variables
Johnny Chenc35750a2010-11-19 18:07:14 +0000662 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000663 ConstString const_name(name);
Greg Claytona894fe72012-04-05 16:12:35 +0000664 ClangExpressionVariableSP expr_var_sp (target->GetPersistentVariables().GetVariable (const_name));
665 if (expr_var_sp)
Johnny Chenc35750a2010-11-19 18:07:14 +0000666 {
Greg Claytona894fe72012-04-05 16:12:35 +0000667 value_sp = expr_var_sp->GetValueObject();
668 sb_value.SetSP (value_sp);
Johnny Chenc35750a2010-11-19 18:07:14 +0000669 }
670 }
Greg Claytona894fe72012-04-05 16:12:35 +0000671 break;
Greg Clayton4e9267d2010-12-14 18:39:31 +0000672
Greg Claytona894fe72012-04-05 16:12:35 +0000673 default:
674 break;
Greg Clayton4e9267d2010-12-14 18:39:31 +0000675 }
Chris Lattner24943d22010-06-08 16:52:24 +0000676 }
677 }
Caroline Tice98f930f2010-09-20 05:20:02 +0000678
Greg Clayton4e9267d2010-12-14 18:39:31 +0000679 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000680 if (log)
Greg Clayton4e9267d2010-12-14 18:39:31 +0000681 log->Printf ("SBFrame(%p)::FindVariableInScope (name=\"%s\", value_type=%i) => SBValue(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000682 frame, name, value_type, value_sp.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000683
684
Chris Lattner24943d22010-06-08 16:52:24 +0000685 return sb_value;
686}
687
688bool
Johnny Chen0164b752012-03-05 19:53:24 +0000689SBFrame::IsEqual (const SBFrame &that) const
690{
691 lldb::StackFrameSP this_sp = GetFrameSP();
692 lldb::StackFrameSP that_sp = that.GetFrameSP();
693 return (this_sp && that_sp && this_sp->GetStackID() == that_sp->GetStackID());
694}
695
696bool
Chris Lattner24943d22010-06-08 16:52:24 +0000697SBFrame::operator == (const SBFrame &rhs) const
698{
Johnny Chen0164b752012-03-05 19:53:24 +0000699 return IsEqual(rhs);
Chris Lattner24943d22010-06-08 16:52:24 +0000700}
701
702bool
703SBFrame::operator != (const SBFrame &rhs) const
704{
Johnny Chen0164b752012-03-05 19:53:24 +0000705 return !IsEqual(rhs);
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000706}
Chris Lattner24943d22010-06-08 16:52:24 +0000707
708SBThread
709SBFrame::GetThread () const
710{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000711 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000712
Greg Claytona894fe72012-04-05 16:12:35 +0000713 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000714 ThreadSP thread_sp (exe_ctx.GetThreadSP());
715 SBThread sb_thread (thread_sp);
Caroline Tice7826c882010-10-26 03:11:13 +0000716
717 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000718 {
719 SBStream sstr;
720 sb_thread.GetDescription (sstr);
Greg Clayton289afcb2012-02-18 05:35:26 +0000721 log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s",
722 exe_ctx.GetFramePtr(),
723 thread_sp.get(),
724 sstr.GetData());
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000725 }
Caroline Tice7826c882010-10-26 03:11:13 +0000726
Chris Lattner24943d22010-06-08 16:52:24 +0000727 return sb_thread;
728}
729
730const char *
731SBFrame::Disassemble () const
732{
Greg Claytona66ba462010-10-30 04:51:46 +0000733 const char *disassembly = NULL;
Greg Claytona894fe72012-04-05 16:12:35 +0000734 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000735 StackFrame *frame = exe_ctx.GetFramePtr();
736 Target *target = exe_ctx.GetTargetPtr();
737 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000738 {
Greg Claytona894fe72012-04-05 16:12:35 +0000739 Process::StopLocker stop_locker;
740 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
741 {
742 Mutex::Locker api_locker (target->GetAPIMutex());
743 disassembly = frame->Disassemble();
744 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000745 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000746 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000747
748 if (log)
Greg Clayton289afcb2012-02-18 05:35:26 +0000749 log->Printf ("SBFrame(%p)::Disassemble () => %s", frame, disassembly);
Greg Claytona66ba462010-10-30 04:51:46 +0000750
751 return disassembly;
Chris Lattner24943d22010-06-08 16:52:24 +0000752}
753
754
Chris Lattner24943d22010-06-08 16:52:24 +0000755SBValueList
756SBFrame::GetVariables (bool arguments,
757 bool locals,
758 bool statics,
759 bool in_scope_only)
760{
Greg Clayton582ed0e2011-06-18 20:06:08 +0000761 SBValueList value_list;
Greg Claytona894fe72012-04-05 16:12:35 +0000762 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000763 StackFrame *frame = exe_ctx.GetFramePtr();
764 Target *target = exe_ctx.GetTargetPtr();
765 if (frame && target)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000766 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000767 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton582ed0e2011-06-18 20:06:08 +0000768 value_list = GetVariables (arguments, locals, statics, in_scope_only, use_dynamic);
769 }
770 return value_list;
Jim Inghame41494a2011-04-16 00:01:13 +0000771}
772
773SBValueList
774SBFrame::GetVariables (bool arguments,
775 bool locals,
776 bool statics,
777 bool in_scope_only,
Jim Ingham10de7d12011-05-04 03:43:18 +0000778 lldb::DynamicValueType use_dynamic)
Jim Inghame41494a2011-04-16 00:01:13 +0000779{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000780 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000781
Greg Clayton334d33a2012-01-30 07:41:31 +0000782 SBValueList value_list;
Greg Claytona894fe72012-04-05 16:12:35 +0000783 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000784 StackFrame *frame = exe_ctx.GetFramePtr();
785 Target *target = exe_ctx.GetTargetPtr();
Greg Clayton334d33a2012-01-30 07:41:31 +0000786
Caroline Tice7826c882010-10-26 03:11:13 +0000787 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000788 log->Printf ("SBFrame(%p)::GetVariables (arguments=%i, locals=%i, statics=%i, in_scope_only=%i)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000789 frame,
Greg Claytona66ba462010-10-30 04:51:46 +0000790 arguments,
791 locals,
792 statics,
793 in_scope_only);
Greg Clayton334d33a2012-01-30 07:41:31 +0000794
Greg Clayton289afcb2012-02-18 05:35:26 +0000795 if (frame && target)
Chris Lattner24943d22010-06-08 16:52:24 +0000796 {
Greg Claytona894fe72012-04-05 16:12:35 +0000797 Process::StopLocker stop_locker;
798 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
799 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000800
Greg Claytona894fe72012-04-05 16:12:35 +0000801 size_t i;
802 VariableList *variable_list = NULL;
803 // Scope for locker
Chris Lattner24943d22010-06-08 16:52:24 +0000804 {
Greg Claytona894fe72012-04-05 16:12:35 +0000805 Mutex::Locker api_locker (target->GetAPIMutex());
806 variable_list = frame->GetVariableList(true);
807 }
808 if (variable_list)
809 {
810 const size_t num_variables = variable_list->GetSize();
811 if (num_variables)
Chris Lattner24943d22010-06-08 16:52:24 +0000812 {
Greg Claytona894fe72012-04-05 16:12:35 +0000813 for (i = 0; i < num_variables; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000814 {
Greg Claytona894fe72012-04-05 16:12:35 +0000815 VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
816 if (variable_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000817 {
Greg Claytona894fe72012-04-05 16:12:35 +0000818 bool add_variable = false;
819 switch (variable_sp->GetScope())
820 {
821 case eValueTypeVariableGlobal:
822 case eValueTypeVariableStatic:
823 add_variable = statics;
824 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000825
Greg Claytona894fe72012-04-05 16:12:35 +0000826 case eValueTypeVariableArgument:
827 add_variable = arguments;
828 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000829
Greg Claytona894fe72012-04-05 16:12:35 +0000830 case eValueTypeVariableLocal:
831 add_variable = locals;
832 break;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000833
Greg Claytona894fe72012-04-05 16:12:35 +0000834 default:
835 break;
836 }
837 if (add_variable)
838 {
839 if (in_scope_only && !variable_sp->IsInScope(frame))
840 continue;
Chris Lattner24943d22010-06-08 16:52:24 +0000841
Greg Claytona894fe72012-04-05 16:12:35 +0000842 value_list.Append(frame->GetValueObjectForFrameVariable (variable_sp, use_dynamic));
843 }
Chris Lattner24943d22010-06-08 16:52:24 +0000844 }
845 }
846 }
847 }
Greg Claytona894fe72012-04-05 16:12:35 +0000848 }
Chris Lattner24943d22010-06-08 16:52:24 +0000849 }
Caroline Tice7826c882010-10-26 03:11:13 +0000850
851 if (log)
852 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000853 log->Printf ("SBFrame(%p)::GetVariables (...) => SBValueList(%p)", frame,
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000854 value_list.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000855 }
856
Chris Lattner24943d22010-06-08 16:52:24 +0000857 return value_list;
858}
859
Greg Clayton4e9267d2010-12-14 18:39:31 +0000860SBValueList
Chris Lattner24943d22010-06-08 16:52:24 +0000861SBFrame::GetRegisters ()
862{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000863 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000864
Chris Lattner24943d22010-06-08 16:52:24 +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();
869 if (frame && target)
Chris Lattner24943d22010-06-08 16:52:24 +0000870 {
Greg Claytona894fe72012-04-05 16:12:35 +0000871 Process::StopLocker stop_locker;
872 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Chris Lattner24943d22010-06-08 16:52:24 +0000873 {
Greg Claytona894fe72012-04-05 16:12:35 +0000874 Mutex::Locker api_locker (target->GetAPIMutex());
875 RegisterContextSP reg_ctx (frame->GetRegisterContext());
876 if (reg_ctx)
Chris Lattner24943d22010-06-08 16:52:24 +0000877 {
Greg Claytona894fe72012-04-05 16:12:35 +0000878 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
879 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
880 {
881 value_list.Append(ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx));
882 }
Chris Lattner24943d22010-06-08 16:52:24 +0000883 }
884 }
885 }
Caroline Tice7826c882010-10-26 03:11:13 +0000886
887 if (log)
Greg Clayton289afcb2012-02-18 05:35:26 +0000888 log->Printf ("SBFrame(%p)::Registers () => SBValueList(%p)", frame, value_list.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000889
Chris Lattner24943d22010-06-08 16:52:24 +0000890 return value_list;
891}
892
Caroline Tice98f930f2010-09-20 05:20:02 +0000893bool
894SBFrame::GetDescription (SBStream &description)
895{
Greg Clayton96154be2011-11-13 06:57:31 +0000896 Stream &strm = description.ref();
897
Greg Claytona894fe72012-04-05 16:12:35 +0000898 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000899 StackFrame *frame = exe_ctx.GetFramePtr();
900 Target *target = exe_ctx.GetTargetPtr();
901 if (frame && target)
Caroline Tice98f930f2010-09-20 05:20:02 +0000902 {
Greg Claytona894fe72012-04-05 16:12:35 +0000903 Process::StopLocker stop_locker;
904 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
905 {
906 Mutex::Locker api_locker (target->GetAPIMutex());
907 frame->DumpUsingSettingsFormat (&strm);
908 }
Caroline Tice98f930f2010-09-20 05:20:02 +0000909 }
910 else
Greg Clayton96154be2011-11-13 06:57:31 +0000911 strm.PutCString ("No value");
Caroline Tice98f930f2010-09-20 05:20:02 +0000912
913 return true;
914}
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000915
Greg Clayton4e9267d2010-12-14 18:39:31 +0000916SBValue
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000917SBFrame::EvaluateExpression (const char *expr)
918{
Greg Clayton582ed0e2011-06-18 20:06:08 +0000919 SBValue result;
Greg Claytona894fe72012-04-05 16:12:35 +0000920 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000921 StackFrame *frame = exe_ctx.GetFramePtr();
922 Target *target = exe_ctx.GetTargetPtr();
923 if (frame && target)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000924 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000925 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton582ed0e2011-06-18 20:06:08 +0000926 result = EvaluateExpression (expr, use_dynamic);
927 }
928 return result;
Jim Inghame41494a2011-04-16 00:01:13 +0000929}
930
931SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000932SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value)
Jim Inghame41494a2011-04-16 00:01:13 +0000933{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000934 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Sean Callanan94d255f2010-12-07 22:55:01 +0000935
Greg Clayton4e9267d2010-12-14 18:39:31 +0000936 LogSP expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Greg Claytona66ba462010-10-30 04:51:46 +0000937
Johnny Chenee6e7902011-08-10 22:06:24 +0000938 ExecutionResults exe_results;
Greg Clayton4e9267d2010-12-14 18:39:31 +0000939 SBValue expr_result;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000940 ValueObjectSP expr_value_sp;
Greg Claytona66ba462010-10-30 04:51:46 +0000941
Greg Claytona894fe72012-04-05 16:12:35 +0000942 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000943 StackFrame *frame = exe_ctx.GetFramePtr();
944 Target *target = exe_ctx.GetTargetPtr();
Greg Clayton334d33a2012-01-30 07:41:31 +0000945 if (log)
Greg Clayton289afcb2012-02-18 05:35:26 +0000946 log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\")...", frame, expr);
Greg Clayton334d33a2012-01-30 07:41:31 +0000947
Greg Clayton289afcb2012-02-18 05:35:26 +0000948 if (frame && target)
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000949 {
Greg Claytona894fe72012-04-05 16:12:35 +0000950 Process::StopLocker stop_locker;
951 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
952 {
Greg Clayton87ac9022011-06-25 04:35:01 +0000953
Greg Claytona894fe72012-04-05 16:12:35 +0000954 Mutex::Locker api_locker (target->GetAPIMutex());
955
956
957 StreamString frame_description;
958 frame->DumpUsingSettingsFormat (&frame_description);
Greg Clayton87ac9022011-06-25 04:35:01 +0000959
Greg Claytona894fe72012-04-05 16:12:35 +0000960 Host::SetCrashDescriptionWithFormat ("SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
961 expr, fetch_dynamic_value, frame_description.GetString().c_str());
Greg Clayton427f2902010-12-14 02:59:59 +0000962
Greg Claytona894fe72012-04-05 16:12:35 +0000963 const bool coerce_to_id = false;
964 const bool unwind_on_error = true;
965 const bool keep_in_memory = false;
966
967 exe_results = target->EvaluateExpression (expr,
968 frame,
969 eExecutionPolicyOnlyWhenNeeded,
970 coerce_to_id,
971 unwind_on_error,
972 keep_in_memory,
973 fetch_dynamic_value,
974 expr_value_sp);
975 expr_result.SetSP(expr_value_sp);
976 Host::SetCrashDescription (NULL);
977 }
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000978 }
Jason Molendac48ca822012-02-21 05:33:55 +0000979
980#ifndef LLDB_DISABLE_PYTHON
Sean Callanan94d255f2010-12-07 22:55:01 +0000981 if (expr_log)
Jim Inghame41494a2011-04-16 00:01:13 +0000982 expr_log->Printf("** [SBFrame::EvaluateExpression] Expression result is %s, summary %s **",
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000983 expr_result.GetValue(),
984 expr_result.GetSummary());
Sean Callanan94d255f2010-12-07 22:55:01 +0000985
Greg Claytona66ba462010-10-30 04:51:46 +0000986 if (log)
Greg Clayton289afcb2012-02-18 05:35:26 +0000987 log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)",
988 frame,
Jim Inghame41494a2011-04-16 00:01:13 +0000989 expr,
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000990 expr_value_sp.get(),
Johnny Chenee6e7902011-08-10 22:06:24 +0000991 exe_results);
Jason Molendac48ca822012-02-21 05:33:55 +0000992#endif
Greg Claytona66ba462010-10-30 04:51:46 +0000993
Greg Clayton49ce6822010-10-31 03:01:06 +0000994 return expr_result;
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000995}
Greg Clayton582ed0e2011-06-18 20:06:08 +0000996
997bool
998SBFrame::IsInlined()
999{
Greg Claytona894fe72012-04-05 16:12:35 +00001000 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +00001001 StackFrame *frame = exe_ctx.GetFramePtr();
1002 Target *target = exe_ctx.GetTargetPtr();
1003 if (frame && target)
Greg Clayton582ed0e2011-06-18 20:06:08 +00001004 {
Greg Claytona894fe72012-04-05 16:12:35 +00001005 Process::StopLocker stop_locker;
1006 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1007 {
1008
1009 Block *block = frame->GetSymbolContext(eSymbolContextBlock).block;
1010 if (block)
1011 return block->GetContainingInlinedBlock () != NULL;
1012 }
Greg Clayton582ed0e2011-06-18 20:06:08 +00001013 }
1014 return false;
1015}
1016
1017const char *
1018SBFrame::GetFunctionName()
1019{
1020 const char *name = NULL;
Greg Claytona894fe72012-04-05 16:12:35 +00001021 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +00001022 StackFrame *frame = exe_ctx.GetFramePtr();
1023 Target *target = exe_ctx.GetTargetPtr();
1024 if (frame && target)
Greg Clayton582ed0e2011-06-18 20:06:08 +00001025 {
Greg Claytona894fe72012-04-05 16:12:35 +00001026 Process::StopLocker stop_locker;
1027 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Greg Clayton582ed0e2011-06-18 20:06:08 +00001028 {
Greg Claytona894fe72012-04-05 16:12:35 +00001029 SymbolContext sc (frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol));
1030 if (sc.block)
Greg Clayton582ed0e2011-06-18 20:06:08 +00001031 {
Greg Claytona894fe72012-04-05 16:12:35 +00001032 Block *inlined_block = sc.block->GetContainingInlinedBlock ();
1033 if (inlined_block)
1034 {
1035 const InlineFunctionInfo* inlined_info = inlined_block->GetInlinedFunctionInfo();
1036 name = inlined_info->GetName().AsCString();
1037 }
Greg Clayton582ed0e2011-06-18 20:06:08 +00001038 }
Greg Claytona894fe72012-04-05 16:12:35 +00001039
1040 if (name == NULL)
1041 {
1042 if (sc.function)
1043 name = sc.function->GetName().GetCString();
1044 }
Greg Clayton582ed0e2011-06-18 20:06:08 +00001045
Greg Claytona894fe72012-04-05 16:12:35 +00001046 if (name == NULL)
1047 {
1048 if (sc.symbol)
1049 name = sc.symbol->GetName().GetCString();
1050 }
Greg Clayton582ed0e2011-06-18 20:06:08 +00001051 }
1052 }
1053 return name;
1054}
1055