blob: 1b44b753ea509270843a36c784fa9ffc8d2e7f9a [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{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000107 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
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 Clayton9f3c98e2012-04-06 02:17:47 +0000120 else
121 {
122 if (log)
123 log->Printf ("SBFrame(%p)::GetSymbolContext () => error: process is running", frame);
124 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000125 }
Caroline Tice7826c882010-10-26 03:11:13 +0000126
127 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000128 log->Printf ("SBFrame(%p)::GetSymbolContext (resolve_scope=0x%8.8x) => SBSymbolContext(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000129 frame, resolve_scope, sb_sym_ctx.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000130
Chris Lattner24943d22010-06-08 16:52:24 +0000131 return sb_sym_ctx;
132}
133
134SBModule
135SBFrame::GetModule () const
136{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000137 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytondd62d722010-12-14 04:58:53 +0000138 SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000139 ModuleSP module_sp;
Greg Claytona894fe72012-04-05 16:12:35 +0000140 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000141 StackFrame *frame = exe_ctx.GetFramePtr();
142 Target *target = exe_ctx.GetTargetPtr();
143 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000144 {
Greg Claytona894fe72012-04-05 16:12:35 +0000145 Process::StopLocker stop_locker;
146 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
147 {
148 Mutex::Locker api_locker (target->GetAPIMutex());
149 module_sp = frame->GetSymbolContext (eSymbolContextModule).module_sp;
150 sb_module.SetSP (module_sp);
151 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000152 else
153 {
154 if (log)
155 log->Printf ("SBFrame(%p)::GetModule () => error: process is running", frame);
156 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000157 }
Greg Claytondd62d722010-12-14 04:58:53 +0000158
Greg Claytona66ba462010-10-30 04:51:46 +0000159 if (log)
160 log->Printf ("SBFrame(%p)::GetModule () => SBModule(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000161 frame, module_sp.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000162
Chris Lattner24943d22010-06-08 16:52:24 +0000163 return sb_module;
164}
165
166SBCompileUnit
167SBFrame::GetCompileUnit () const
168{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000169 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytondd62d722010-12-14 04:58:53 +0000170 SBCompileUnit sb_comp_unit;
Greg Claytona894fe72012-04-05 16:12:35 +0000171 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000172 StackFrame *frame = exe_ctx.GetFramePtr();
173 Target *target = exe_ctx.GetTargetPtr();
174 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000175 {
Greg Claytona894fe72012-04-05 16:12:35 +0000176 Process::StopLocker stop_locker;
177 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
178 {
179 Mutex::Locker api_locker (target->GetAPIMutex());
180 sb_comp_unit.reset (frame->GetSymbolContext (eSymbolContextCompUnit).comp_unit);
181 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000182 else
183 {
184 if (log)
185 log->Printf ("SBFrame(%p)::GetCompileUnit () => error: process is running", frame);
186 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000187 }
Caroline Tice7826c882010-10-26 03:11:13 +0000188 if (log)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000189 log->Printf ("SBFrame(%p)::GetCompileUnit () => SBCompileUnit(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000190 frame, sb_comp_unit.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000191
Chris Lattner24943d22010-06-08 16:52:24 +0000192 return sb_comp_unit;
193}
194
195SBFunction
196SBFrame::GetFunction () const
197{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000198 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytondd62d722010-12-14 04:58:53 +0000199 SBFunction sb_function;
Greg Claytona894fe72012-04-05 16:12:35 +0000200 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000201 StackFrame *frame = exe_ctx.GetFramePtr();
202 Target *target = exe_ctx.GetTargetPtr();
203 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000204 {
Greg Claytona894fe72012-04-05 16:12:35 +0000205 Process::StopLocker stop_locker;
206 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
207 {
208 Mutex::Locker api_locker (target->GetAPIMutex());
209 sb_function.reset(frame->GetSymbolContext (eSymbolContextFunction).function);
210 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000211 else
212 {
213 if (log)
214 log->Printf ("SBFrame(%p)::GetFunction () => error: process is running", frame);
215 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000216 }
Greg Claytona66ba462010-10-30 04:51:46 +0000217 if (log)
218 log->Printf ("SBFrame(%p)::GetFunction () => SBFunction(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000219 frame, sb_function.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000220
Chris Lattner24943d22010-06-08 16:52:24 +0000221 return sb_function;
222}
223
Greg Clayton8f1e08b2010-10-04 18:37:52 +0000224SBSymbol
225SBFrame::GetSymbol () const
226{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000227 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytondd62d722010-12-14 04:58:53 +0000228 SBSymbol sb_symbol;
Greg Claytona894fe72012-04-05 16:12:35 +0000229 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000230 StackFrame *frame = exe_ctx.GetFramePtr();
231 Target *target = exe_ctx.GetTargetPtr();
232 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000233 {
Greg Claytona894fe72012-04-05 16:12:35 +0000234 Process::StopLocker stop_locker;
235 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
236 {
237 Mutex::Locker api_locker (target->GetAPIMutex());
238 sb_symbol.reset(frame->GetSymbolContext (eSymbolContextSymbol).symbol);
239 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000240 else
241 {
242 if (log)
243 log->Printf ("SBFrame(%p)::GetSymbol () => error: process is running", frame);
244 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000245 }
Greg Claytona66ba462010-10-30 04:51:46 +0000246 if (log)
247 log->Printf ("SBFrame(%p)::GetSymbol () => SBSymbol(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000248 frame, sb_symbol.get());
Greg Clayton8f1e08b2010-10-04 18:37:52 +0000249 return sb_symbol;
250}
251
Chris Lattner24943d22010-06-08 16:52:24 +0000252SBBlock
253SBFrame::GetBlock () const
254{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000255 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytondd62d722010-12-14 04:58:53 +0000256 SBBlock sb_block;
Greg Claytona894fe72012-04-05 16:12:35 +0000257 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000258 StackFrame *frame = exe_ctx.GetFramePtr();
259 Target *target = exe_ctx.GetTargetPtr();
260 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000261 {
Greg Claytona894fe72012-04-05 16:12:35 +0000262 Process::StopLocker stop_locker;
263 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
264 {
265 Mutex::Locker api_locker (target->GetAPIMutex());
266 sb_block.SetPtr (frame->GetSymbolContext (eSymbolContextBlock).block);
267 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000268 else
269 {
270 if (log)
271 log->Printf ("SBFrame(%p)::GetBlock () => error: process is running", frame);
272 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000273 }
Greg Claytona66ba462010-10-30 04:51:46 +0000274 if (log)
275 log->Printf ("SBFrame(%p)::GetBlock () => SBBlock(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000276 frame, sb_block.GetPtr());
Chris Lattner24943d22010-06-08 16:52:24 +0000277 return sb_block;
278}
279
Greg Clayton69aa5d92010-09-07 04:20:48 +0000280SBBlock
281SBFrame::GetFrameBlock () const
282{
Greg Claytondd62d722010-12-14 04:58:53 +0000283 SBBlock sb_block;
Greg Claytona894fe72012-04-05 16:12:35 +0000284 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000285 StackFrame *frame = exe_ctx.GetFramePtr();
286 Target *target = exe_ctx.GetTargetPtr();
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000287 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton289afcb2012-02-18 05:35:26 +0000288 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000289 {
Greg Claytona894fe72012-04-05 16:12:35 +0000290 Process::StopLocker stop_locker;
291 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
292 {
293 Mutex::Locker api_locker (target->GetAPIMutex());
294 sb_block.SetPtr(frame->GetFrameBlock ());
295 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000296 else
297 {
298 if (log)
299 log->Printf ("SBFrame(%p)::GetFrameBlock () => error: process is running", frame);
300 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000301 }
Greg Claytona66ba462010-10-30 04:51:46 +0000302 if (log)
303 log->Printf ("SBFrame(%p)::GetFrameBlock () => SBBlock(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000304 frame, sb_block.GetPtr());
Greg Clayton69aa5d92010-09-07 04:20:48 +0000305 return sb_block;
306}
307
Chris Lattner24943d22010-06-08 16:52:24 +0000308SBLineEntry
309SBFrame::GetLineEntry () const
310{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000311 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytondd62d722010-12-14 04:58:53 +0000312 SBLineEntry sb_line_entry;
Greg Claytona894fe72012-04-05 16:12:35 +0000313 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000314 StackFrame *frame = exe_ctx.GetFramePtr();
315 Target *target = exe_ctx.GetTargetPtr();
316 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000317 {
Greg Claytona894fe72012-04-05 16:12:35 +0000318 Process::StopLocker stop_locker;
319 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
320 {
321 Mutex::Locker api_locker (target->GetAPIMutex());
322 sb_line_entry.SetLineEntry (frame->GetSymbolContext (eSymbolContextLineEntry).line_entry);
323 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000324 else
325 {
326 if (log)
327 log->Printf ("SBFrame(%p)::GetLineEntry () => error: process is running", frame);
328 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000329 }
Greg Claytona66ba462010-10-30 04:51:46 +0000330 if (log)
331 log->Printf ("SBFrame(%p)::GetLineEntry () => SBLineEntry(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000332 frame, sb_line_entry.get());
Chris Lattner24943d22010-06-08 16:52:24 +0000333 return sb_line_entry;
334}
335
336uint32_t
337SBFrame::GetFrameID () const
338{
Greg Clayton334d33a2012-01-30 07:41:31 +0000339 uint32_t frame_idx = UINT32_MAX;
340
Greg Claytona894fe72012-04-05 16:12:35 +0000341 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000342 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Claytona894fe72012-04-05 16:12:35 +0000343 if (frame)
Greg Clayton289afcb2012-02-18 05:35:26 +0000344 frame_idx = frame->GetFrameIndex ();
Greg Claytona66ba462010-10-30 04:51:46 +0000345
Greg Clayton4e9267d2010-12-14 18:39:31 +0000346 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000347 if (log)
348 log->Printf ("SBFrame(%p)::GetFrameID () => %u",
Greg Clayton289afcb2012-02-18 05:35:26 +0000349 frame, frame_idx);
Greg Claytona66ba462010-10-30 04:51:46 +0000350 return frame_idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000351}
352
Greg Clayton4e9267d2010-12-14 18:39:31 +0000353addr_t
Chris Lattner24943d22010-06-08 16:52:24 +0000354SBFrame::GetPC () const
355{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000356 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton4e9267d2010-12-14 18:39:31 +0000357 addr_t addr = LLDB_INVALID_ADDRESS;
Greg Claytona894fe72012-04-05 16:12:35 +0000358 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000359 StackFrame *frame = exe_ctx.GetFramePtr();
360 Target *target = exe_ctx.GetTargetPtr();
361 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000362 {
Greg Claytona894fe72012-04-05 16:12:35 +0000363 Process::StopLocker stop_locker;
364 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
365 {
366 Mutex::Locker api_locker (target->GetAPIMutex());
367 addr = frame->GetFrameCodeAddress().GetOpcodeLoadAddress (target);
368 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000369 else
370 {
371 if (log)
372 log->Printf ("SBFrame(%p)::GetPC () => error: process is running", frame);
373 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000374 }
Caroline Tice7826c882010-10-26 03:11:13 +0000375
376 if (log)
Greg Clayton289afcb2012-02-18 05:35:26 +0000377 log->Printf ("SBFrame(%p)::GetPC () => 0x%llx", frame, addr);
Caroline Tice7826c882010-10-26 03:11:13 +0000378
379 return addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000380}
381
382bool
Greg Clayton4e9267d2010-12-14 18:39:31 +0000383SBFrame::SetPC (addr_t new_pc)
Chris Lattner24943d22010-06-08 16:52:24 +0000384{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000385 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000386 bool ret_val = false;
Greg Claytona894fe72012-04-05 16:12:35 +0000387 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000388 StackFrame *frame = exe_ctx.GetFramePtr();
389 Target *target = exe_ctx.GetTargetPtr();
390 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000391 {
Greg Claytona894fe72012-04-05 16:12:35 +0000392 Process::StopLocker stop_locker;
393 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
394 {
395 Mutex::Locker api_locker (target->GetAPIMutex());
396 ret_val = frame->GetRegisterContext()->SetPC (new_pc);
397 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000398 else
399 {
400 if (log)
401 log->Printf ("SBFrame(%p)::SetPC () => error: process is running", frame);
402 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000403 }
Caroline Tice7826c882010-10-26 03:11:13 +0000404
405 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000406 log->Printf ("SBFrame(%p)::SetPC (new_pc=0x%llx) => %i",
Greg Clayton289afcb2012-02-18 05:35:26 +0000407 frame, new_pc, ret_val);
Caroline Tice7826c882010-10-26 03:11:13 +0000408
409 return ret_val;
Chris Lattner24943d22010-06-08 16:52:24 +0000410}
411
Greg Clayton4e9267d2010-12-14 18:39:31 +0000412addr_t
Chris Lattner24943d22010-06-08 16:52:24 +0000413SBFrame::GetSP () const
414{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000415 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000416 addr_t addr = LLDB_INVALID_ADDRESS;
Greg Claytona894fe72012-04-05 16:12:35 +0000417 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000418 StackFrame *frame = exe_ctx.GetFramePtr();
419 Target *target = exe_ctx.GetTargetPtr();
420 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000421 {
Greg Claytona894fe72012-04-05 16:12:35 +0000422 Process::StopLocker stop_locker;
423 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
424 {
425 Mutex::Locker api_locker (target->GetAPIMutex());
426 addr = frame->GetRegisterContext()->GetSP();
427 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000428 else
429 {
430 if (log)
431 log->Printf ("SBFrame(%p)::GetSP () => error: process is running", frame);
432 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000433 }
Greg Claytona66ba462010-10-30 04:51:46 +0000434 if (log)
Greg Clayton289afcb2012-02-18 05:35:26 +0000435 log->Printf ("SBFrame(%p)::GetSP () => 0x%llx", frame, addr);
Greg Claytona66ba462010-10-30 04:51:46 +0000436
437 return addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000438}
439
440
Greg Clayton4e9267d2010-12-14 18:39:31 +0000441addr_t
Chris Lattner24943d22010-06-08 16:52:24 +0000442SBFrame::GetFP () const
443{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000444 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton4e9267d2010-12-14 18:39:31 +0000445 addr_t addr = LLDB_INVALID_ADDRESS;
Greg Claytona894fe72012-04-05 16:12:35 +0000446 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000447 StackFrame *frame = exe_ctx.GetFramePtr();
448 Target *target = exe_ctx.GetTargetPtr();
449 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000450 {
Greg Claytona894fe72012-04-05 16:12:35 +0000451 Process::StopLocker stop_locker;
452 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
453 {
454 Mutex::Locker api_locker (target->GetAPIMutex());
455 addr = frame->GetRegisterContext()->GetFP();
456 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000457 else
458 {
459 if (log)
460 log->Printf ("SBFrame(%p)::GetFP () => error: process is running", frame);
461 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000462 }
Caroline Tice7826c882010-10-26 03:11:13 +0000463
464 if (log)
Greg Clayton289afcb2012-02-18 05:35:26 +0000465 log->Printf ("SBFrame(%p)::GetFP () => 0x%llx", frame, addr);
Caroline Tice7826c882010-10-26 03:11:13 +0000466 return addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000467}
468
469
470SBAddress
471SBFrame::GetPCAddress () const
472{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000473 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +0000474 SBAddress sb_addr;
Greg Claytona894fe72012-04-05 16:12:35 +0000475 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000476 StackFrame *frame = exe_ctx.GetFramePtr();
477 Target *target = exe_ctx.GetTargetPtr();
478 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000479 {
Greg Claytona894fe72012-04-05 16:12:35 +0000480 Process::StopLocker stop_locker;
481 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
482 {
483 Mutex::Locker api_locker (target->GetAPIMutex());
484 sb_addr.SetAddress (&frame->GetFrameCodeAddress());
485 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000486 else
487 {
488 if (log)
489 log->Printf ("SBFrame(%p)::GetPCAddress () => error: process is running", frame);
490 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000491 }
Greg Claytona66ba462010-10-30 04:51:46 +0000492 if (log)
Greg Clayton289afcb2012-02-18 05:35:26 +0000493 log->Printf ("SBFrame(%p)::GetPCAddress () => SBAddress(%p)", frame, sb_addr.get());
Chris Lattner24943d22010-06-08 16:52:24 +0000494 return sb_addr;
495}
496
497void
498SBFrame::Clear()
499{
Greg Clayton63094e02010-06-23 01:19:29 +0000500 m_opaque_sp.reset();
Chris Lattner24943d22010-06-08 16:52:24 +0000501}
502
Greg Claytond62b9c12012-02-03 07:02:37 +0000503lldb::SBValue
504SBFrame::GetValueForVariablePath (const char *var_path)
505{
506 SBValue sb_value;
Greg Claytona894fe72012-04-05 16:12:35 +0000507 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000508 StackFrame *frame = exe_ctx.GetFramePtr();
509 Target *target = exe_ctx.GetTargetPtr();
510 if (frame && target)
Greg Claytond62b9c12012-02-03 07:02:37 +0000511 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000512 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
513 sb_value = GetValueForVariablePath (var_path, use_dynamic);
Greg Claytond62b9c12012-02-03 07:02:37 +0000514 }
515 return sb_value;
516}
517
518lldb::SBValue
519SBFrame::GetValueForVariablePath (const char *var_path, DynamicValueType use_dynamic)
520{
521 SBValue sb_value;
Greg Claytona894fe72012-04-05 16:12:35 +0000522 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000523 StackFrame *frame = exe_ctx.GetFramePtr();
524 Target *target = exe_ctx.GetTargetPtr();
525 if (frame && target && var_path && var_path[0])
Greg Claytond62b9c12012-02-03 07:02:37 +0000526 {
Greg Claytona894fe72012-04-05 16:12:35 +0000527 Process::StopLocker stop_locker;
528 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
529 {
530 Mutex::Locker api_locker (target->GetAPIMutex());
531 VariableSP var_sp;
532 Error error;
533 ValueObjectSP value_sp (frame->GetValueForVariableExpressionPath (var_path,
534 use_dynamic,
535 StackFrame::eExpressionPathOptionCheckPtrVsMember,
536 var_sp,
537 error));
538 sb_value.SetSP(value_sp);
539 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000540 else
541 {
542 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
543 if (log)
544 log->Printf ("SBFrame(%p)::GetValueForVariablePath () => error: process is running", frame);
545 }
Greg Claytond62b9c12012-02-03 07:02:37 +0000546 }
547 return sb_value;
548}
549
Chris Lattner24943d22010-06-08 16:52:24 +0000550SBValue
Greg Clayton4e9267d2010-12-14 18:39:31 +0000551SBFrame::FindVariable (const char *name)
Chris Lattner24943d22010-06-08 16:52:24 +0000552{
Greg Clayton582ed0e2011-06-18 20:06:08 +0000553 SBValue value;
Greg Claytona894fe72012-04-05 16:12:35 +0000554 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000555 StackFrame *frame = exe_ctx.GetFramePtr();
556 Target *target = exe_ctx.GetTargetPtr();
557 if (frame && target)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000558 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000559 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton582ed0e2011-06-18 20:06:08 +0000560 value = FindVariable (name, use_dynamic);
561 }
562 return value;
Jim Inghame41494a2011-04-16 00:01:13 +0000563}
Greg Claytond62b9c12012-02-03 07:02:37 +0000564
Jim Inghame41494a2011-04-16 00:01:13 +0000565
566SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000567SBFrame::FindVariable (const char *name, lldb::DynamicValueType use_dynamic)
Jim Inghame41494a2011-04-16 00:01:13 +0000568{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000569 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton4e9267d2010-12-14 18:39:31 +0000570 VariableSP var_sp;
Jim Ingham47da8102011-04-22 23:53:53 +0000571 SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000572 ValueObjectSP value_sp;
Greg Claytona894fe72012-04-05 16:12:35 +0000573 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000574 StackFrame *frame = exe_ctx.GetFramePtr();
575 Target *target = exe_ctx.GetTargetPtr();
576 if (frame && target && name && name[0])
Chris Lattner24943d22010-06-08 16:52:24 +0000577 {
Greg Claytona894fe72012-04-05 16:12:35 +0000578 Process::StopLocker stop_locker;
579 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Chris Lattner24943d22010-06-08 16:52:24 +0000580 {
Greg Claytona894fe72012-04-05 16:12:35 +0000581 VariableList variable_list;
582 Mutex::Locker api_locker (target->GetAPIMutex());
583 SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock));
584
585 if (sc.block)
Greg Claytondd62d722010-12-14 04:58:53 +0000586 {
Greg Claytona894fe72012-04-05 16:12:35 +0000587 const bool can_create = true;
588 const bool get_parent_variables = true;
589 const bool stop_if_block_is_inlined_function = true;
590
591 if (sc.block->AppendVariables (can_create,
592 get_parent_variables,
593 stop_if_block_is_inlined_function,
594 &variable_list))
595 {
596 var_sp = variable_list.FindVariable (ConstString(name));
597 }
598 }
599
600 if (var_sp)
601 {
602 value_sp = frame->GetValueObjectForFrameVariable(var_sp, use_dynamic);
603 sb_value.SetSP(value_sp);
Greg Claytondd62d722010-12-14 04:58:53 +0000604 }
Chris Lattner24943d22010-06-08 16:52:24 +0000605 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000606 else
607 {
608 if (log)
609 log->Printf ("SBFrame(%p)::FindVariable () => error: process is running", frame);
610 }
Chris Lattner24943d22010-06-08 16:52:24 +0000611 }
Caroline Tice98f930f2010-09-20 05:20:02 +0000612
Greg Claytona66ba462010-10-30 04:51:46 +0000613 if (log)
Greg Clayton4e9267d2010-12-14 18:39:31 +0000614 log->Printf ("SBFrame(%p)::FindVariable (name=\"%s\") => SBValue(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000615 frame, name, value_sp.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000616
Chris Lattner24943d22010-06-08 16:52:24 +0000617 return sb_value;
618}
619
620SBValue
Greg Clayton4e9267d2010-12-14 18:39:31 +0000621SBFrame::FindValue (const char *name, ValueType value_type)
Chris Lattner24943d22010-06-08 16:52:24 +0000622{
Greg Clayton582ed0e2011-06-18 20:06:08 +0000623 SBValue value;
Greg Claytona894fe72012-04-05 16:12:35 +0000624 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000625 StackFrame *frame = exe_ctx.GetFramePtr();
626 Target *target = exe_ctx.GetTargetPtr();
627 if (frame && target)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000628 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000629 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton582ed0e2011-06-18 20:06:08 +0000630 value = FindValue (name, value_type, use_dynamic);
631 }
632 return value;
Jim Inghame41494a2011-04-16 00:01:13 +0000633}
634
635SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000636SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueType use_dynamic)
Jim Inghame41494a2011-04-16 00:01:13 +0000637{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000638 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton4e9267d2010-12-14 18:39:31 +0000639 SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000640 ValueObjectSP value_sp;
Greg Claytona894fe72012-04-05 16:12:35 +0000641 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000642 StackFrame *frame = exe_ctx.GetFramePtr();
643 Target *target = exe_ctx.GetTargetPtr();
644 if (frame && target && name && name[0])
Chris Lattner24943d22010-06-08 16:52:24 +0000645 {
Greg Claytona894fe72012-04-05 16:12:35 +0000646 Process::StopLocker stop_locker;
647 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Chris Lattner24943d22010-06-08 16:52:24 +0000648 {
Greg Claytona894fe72012-04-05 16:12:35 +0000649 Mutex::Locker api_locker (target->GetAPIMutex());
650
651 switch (value_type)
Chris Lattner24943d22010-06-08 16:52:24 +0000652 {
Greg Claytona894fe72012-04-05 16:12:35 +0000653 case eValueTypeVariableGlobal: // global variable
654 case eValueTypeVariableStatic: // static variable
655 case eValueTypeVariableArgument: // function argument variables
656 case eValueTypeVariableLocal: // function local variables
657 {
658 VariableList *variable_list = frame->GetVariableList(true);
Greg Clayton4e9267d2010-12-14 18:39:31 +0000659
Greg Claytona894fe72012-04-05 16:12:35 +0000660 SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock));
Greg Clayton4e9267d2010-12-14 18:39:31 +0000661
Greg Claytona894fe72012-04-05 16:12:35 +0000662 const bool can_create = true;
663 const bool get_parent_variables = true;
664 const bool stop_if_block_is_inlined_function = true;
Greg Clayton4e9267d2010-12-14 18:39:31 +0000665
Greg Claytona894fe72012-04-05 16:12:35 +0000666 if (sc.block && sc.block->AppendVariables (can_create,
667 get_parent_variables,
668 stop_if_block_is_inlined_function,
669 variable_list))
670 {
671 ConstString const_name(name);
672 const uint32_t num_variables = variable_list->GetSize();
673 for (uint32_t i = 0; i < num_variables; ++i)
674 {
675 VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
676 if (variable_sp &&
677 variable_sp->GetScope() == value_type &&
678 variable_sp->GetName() == const_name)
679 {
680 value_sp = frame->GetValueObjectForFrameVariable (variable_sp, use_dynamic);
681 sb_value.SetSP (value_sp);
682 break;
683 }
684 }
685 }
686 }
687 break;
688
689 case eValueTypeRegister: // stack frame register value
690 {
691 RegisterContextSP reg_ctx (frame->GetRegisterContext());
692 if (reg_ctx)
693 {
694 const uint32_t num_regs = reg_ctx->GetRegisterCount();
695 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx)
696 {
697 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
698 if (reg_info &&
699 ((reg_info->name && strcasecmp (reg_info->name, name) == 0) ||
700 (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0)))
701 {
702 value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx);
703 sb_value.SetSP (value_sp);
704 break;
705 }
706 }
707 }
708 }
709 break;
710
711 case eValueTypeRegisterSet: // A collection of stack frame register values
712 {
713 RegisterContextSP reg_ctx (frame->GetRegisterContext());
714 if (reg_ctx)
715 {
716 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
717 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
718 {
719 const RegisterSet *reg_set = reg_ctx->GetRegisterSet (set_idx);
720 if (reg_set &&
721 ((reg_set->name && strcasecmp (reg_set->name, name) == 0) ||
722 (reg_set->short_name && strcasecmp (reg_set->short_name, name) == 0)))
723 {
724 value_sp = ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx);
725 sb_value.SetSP (value_sp);
726 break;
727 }
728 }
729 }
730 }
731 break;
732
733 case eValueTypeConstResult: // constant result variables
Johnny Chenc35750a2010-11-19 18:07:14 +0000734 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000735 ConstString const_name(name);
Greg Claytona894fe72012-04-05 16:12:35 +0000736 ClangExpressionVariableSP expr_var_sp (target->GetPersistentVariables().GetVariable (const_name));
737 if (expr_var_sp)
Johnny Chenc35750a2010-11-19 18:07:14 +0000738 {
Greg Claytona894fe72012-04-05 16:12:35 +0000739 value_sp = expr_var_sp->GetValueObject();
740 sb_value.SetSP (value_sp);
Johnny Chenc35750a2010-11-19 18:07:14 +0000741 }
742 }
Greg Claytona894fe72012-04-05 16:12:35 +0000743 break;
Greg Clayton4e9267d2010-12-14 18:39:31 +0000744
Greg Claytona894fe72012-04-05 16:12:35 +0000745 default:
746 break;
Greg Clayton4e9267d2010-12-14 18:39:31 +0000747 }
Chris Lattner24943d22010-06-08 16:52:24 +0000748 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000749 else
750 {
751 if (log)
752 log->Printf ("SBFrame(%p)::FindValue () => error: process is running", frame);
753 }
Chris Lattner24943d22010-06-08 16:52:24 +0000754 }
Caroline Tice98f930f2010-09-20 05:20:02 +0000755
Greg Claytona66ba462010-10-30 04:51:46 +0000756 if (log)
Greg Clayton4e9267d2010-12-14 18:39:31 +0000757 log->Printf ("SBFrame(%p)::FindVariableInScope (name=\"%s\", value_type=%i) => SBValue(%p)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000758 frame, name, value_type, value_sp.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000759
760
Chris Lattner24943d22010-06-08 16:52:24 +0000761 return sb_value;
762}
763
764bool
Johnny Chen0164b752012-03-05 19:53:24 +0000765SBFrame::IsEqual (const SBFrame &that) const
766{
767 lldb::StackFrameSP this_sp = GetFrameSP();
768 lldb::StackFrameSP that_sp = that.GetFrameSP();
769 return (this_sp && that_sp && this_sp->GetStackID() == that_sp->GetStackID());
770}
771
772bool
Chris Lattner24943d22010-06-08 16:52:24 +0000773SBFrame::operator == (const SBFrame &rhs) const
774{
Johnny Chen0164b752012-03-05 19:53:24 +0000775 return IsEqual(rhs);
Chris Lattner24943d22010-06-08 16:52:24 +0000776}
777
778bool
779SBFrame::operator != (const SBFrame &rhs) const
780{
Johnny Chen0164b752012-03-05 19:53:24 +0000781 return !IsEqual(rhs);
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000782}
Chris Lattner24943d22010-06-08 16:52:24 +0000783
784SBThread
785SBFrame::GetThread () const
786{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000787 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000788
Greg Claytona894fe72012-04-05 16:12:35 +0000789 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000790 ThreadSP thread_sp (exe_ctx.GetThreadSP());
791 SBThread sb_thread (thread_sp);
Caroline Tice7826c882010-10-26 03:11:13 +0000792
793 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000794 {
795 SBStream sstr;
796 sb_thread.GetDescription (sstr);
Greg Clayton289afcb2012-02-18 05:35:26 +0000797 log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s",
798 exe_ctx.GetFramePtr(),
799 thread_sp.get(),
800 sstr.GetData());
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000801 }
Caroline Tice7826c882010-10-26 03:11:13 +0000802
Chris Lattner24943d22010-06-08 16:52:24 +0000803 return sb_thread;
804}
805
806const char *
807SBFrame::Disassemble () const
808{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000809 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000810 const char *disassembly = NULL;
Greg Claytona894fe72012-04-05 16:12:35 +0000811 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000812 StackFrame *frame = exe_ctx.GetFramePtr();
813 Target *target = exe_ctx.GetTargetPtr();
814 if (frame && target)
Greg Claytonbdcda462010-12-20 20:49:23 +0000815 {
Greg Claytona894fe72012-04-05 16:12:35 +0000816 Process::StopLocker stop_locker;
817 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
818 {
819 Mutex::Locker api_locker (target->GetAPIMutex());
820 disassembly = frame->Disassemble();
821 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000822 else
823 {
824 if (log)
825 log->Printf ("SBFrame(%p)::Disassemble () => error: process is running", frame);
826 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000827 }
Greg Claytona66ba462010-10-30 04:51:46 +0000828
829 if (log)
Greg Clayton289afcb2012-02-18 05:35:26 +0000830 log->Printf ("SBFrame(%p)::Disassemble () => %s", frame, disassembly);
Greg Claytona66ba462010-10-30 04:51:46 +0000831
832 return disassembly;
Chris Lattner24943d22010-06-08 16:52:24 +0000833}
834
835
Chris Lattner24943d22010-06-08 16:52:24 +0000836SBValueList
837SBFrame::GetVariables (bool arguments,
838 bool locals,
839 bool statics,
840 bool in_scope_only)
841{
Greg Clayton582ed0e2011-06-18 20:06:08 +0000842 SBValueList value_list;
Greg Claytona894fe72012-04-05 16:12:35 +0000843 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000844 StackFrame *frame = exe_ctx.GetFramePtr();
845 Target *target = exe_ctx.GetTargetPtr();
846 if (frame && target)
Greg Clayton582ed0e2011-06-18 20:06:08 +0000847 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000848 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton582ed0e2011-06-18 20:06:08 +0000849 value_list = GetVariables (arguments, locals, statics, in_scope_only, use_dynamic);
850 }
851 return value_list;
Jim Inghame41494a2011-04-16 00:01:13 +0000852}
853
854SBValueList
855SBFrame::GetVariables (bool arguments,
856 bool locals,
857 bool statics,
858 bool in_scope_only,
Jim Ingham10de7d12011-05-04 03:43:18 +0000859 lldb::DynamicValueType use_dynamic)
Jim Inghame41494a2011-04-16 00:01:13 +0000860{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000861 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000862
Greg Clayton334d33a2012-01-30 07:41:31 +0000863 SBValueList value_list;
Greg Claytona894fe72012-04-05 16:12:35 +0000864 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000865 StackFrame *frame = exe_ctx.GetFramePtr();
866 Target *target = exe_ctx.GetTargetPtr();
Greg Clayton334d33a2012-01-30 07:41:31 +0000867
Caroline Tice7826c882010-10-26 03:11:13 +0000868 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000869 log->Printf ("SBFrame(%p)::GetVariables (arguments=%i, locals=%i, statics=%i, in_scope_only=%i)",
Greg Clayton289afcb2012-02-18 05:35:26 +0000870 frame,
Greg Claytona66ba462010-10-30 04:51:46 +0000871 arguments,
872 locals,
873 statics,
874 in_scope_only);
Greg Clayton334d33a2012-01-30 07:41:31 +0000875
Greg Clayton289afcb2012-02-18 05:35:26 +0000876 if (frame && target)
Chris Lattner24943d22010-06-08 16:52:24 +0000877 {
Greg Claytona894fe72012-04-05 16:12:35 +0000878 Process::StopLocker stop_locker;
879 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
880 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000881
Greg Claytona894fe72012-04-05 16:12:35 +0000882 size_t i;
883 VariableList *variable_list = NULL;
884 // Scope for locker
Chris Lattner24943d22010-06-08 16:52:24 +0000885 {
Greg Claytona894fe72012-04-05 16:12:35 +0000886 Mutex::Locker api_locker (target->GetAPIMutex());
887 variable_list = frame->GetVariableList(true);
888 }
889 if (variable_list)
890 {
891 const size_t num_variables = variable_list->GetSize();
892 if (num_variables)
Chris Lattner24943d22010-06-08 16:52:24 +0000893 {
Greg Claytona894fe72012-04-05 16:12:35 +0000894 for (i = 0; i < num_variables; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000895 {
Greg Claytona894fe72012-04-05 16:12:35 +0000896 VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
897 if (variable_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000898 {
Greg Claytona894fe72012-04-05 16:12:35 +0000899 bool add_variable = false;
900 switch (variable_sp->GetScope())
901 {
902 case eValueTypeVariableGlobal:
903 case eValueTypeVariableStatic:
904 add_variable = statics;
905 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000906
Greg Claytona894fe72012-04-05 16:12:35 +0000907 case eValueTypeVariableArgument:
908 add_variable = arguments;
909 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000910
Greg Claytona894fe72012-04-05 16:12:35 +0000911 case eValueTypeVariableLocal:
912 add_variable = locals;
913 break;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000914
Greg Claytona894fe72012-04-05 16:12:35 +0000915 default:
916 break;
917 }
918 if (add_variable)
919 {
920 if (in_scope_only && !variable_sp->IsInScope(frame))
921 continue;
Chris Lattner24943d22010-06-08 16:52:24 +0000922
Greg Claytona894fe72012-04-05 16:12:35 +0000923 value_list.Append(frame->GetValueObjectForFrameVariable (variable_sp, use_dynamic));
924 }
Chris Lattner24943d22010-06-08 16:52:24 +0000925 }
926 }
927 }
928 }
Greg Claytona894fe72012-04-05 16:12:35 +0000929 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000930 else
931 {
932 if (log)
933 log->Printf ("SBFrame(%p)::GetVariables () => error: process is running", frame);
934 }
Chris Lattner24943d22010-06-08 16:52:24 +0000935 }
Caroline Tice7826c882010-10-26 03:11:13 +0000936
937 if (log)
938 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000939 log->Printf ("SBFrame(%p)::GetVariables (...) => SBValueList(%p)", frame,
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000940 value_list.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000941 }
942
Chris Lattner24943d22010-06-08 16:52:24 +0000943 return value_list;
944}
945
Greg Clayton4e9267d2010-12-14 18:39:31 +0000946SBValueList
Chris Lattner24943d22010-06-08 16:52:24 +0000947SBFrame::GetRegisters ()
948{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000949 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000950
Chris Lattner24943d22010-06-08 16:52:24 +0000951 SBValueList value_list;
Greg Claytona894fe72012-04-05 16:12:35 +0000952 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000953 StackFrame *frame = exe_ctx.GetFramePtr();
954 Target *target = exe_ctx.GetTargetPtr();
955 if (frame && target)
Chris Lattner24943d22010-06-08 16:52:24 +0000956 {
Greg Claytona894fe72012-04-05 16:12:35 +0000957 Process::StopLocker stop_locker;
958 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Chris Lattner24943d22010-06-08 16:52:24 +0000959 {
Greg Claytona894fe72012-04-05 16:12:35 +0000960 Mutex::Locker api_locker (target->GetAPIMutex());
961 RegisterContextSP reg_ctx (frame->GetRegisterContext());
962 if (reg_ctx)
Chris Lattner24943d22010-06-08 16:52:24 +0000963 {
Greg Claytona894fe72012-04-05 16:12:35 +0000964 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
965 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
966 {
967 value_list.Append(ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx));
968 }
Chris Lattner24943d22010-06-08 16:52:24 +0000969 }
970 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000971 else
972 {
973 if (log)
974 log->Printf ("SBFrame(%p)::GetRegisters () => error: process is running", frame);
975 }
Chris Lattner24943d22010-06-08 16:52:24 +0000976 }
Caroline Tice7826c882010-10-26 03:11:13 +0000977
978 if (log)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000979 log->Printf ("SBFrame(%p)::GetRegisters () => SBValueList(%p)", frame, value_list.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000980
Chris Lattner24943d22010-06-08 16:52:24 +0000981 return value_list;
982}
983
Caroline Tice98f930f2010-09-20 05:20:02 +0000984bool
985SBFrame::GetDescription (SBStream &description)
986{
Greg Clayton96154be2011-11-13 06:57:31 +0000987 Stream &strm = description.ref();
988
Greg Claytona894fe72012-04-05 16:12:35 +0000989 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +0000990 StackFrame *frame = exe_ctx.GetFramePtr();
991 Target *target = exe_ctx.GetTargetPtr();
992 if (frame && target)
Caroline Tice98f930f2010-09-20 05:20:02 +0000993 {
Greg Claytona894fe72012-04-05 16:12:35 +0000994 Process::StopLocker stop_locker;
995 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
996 {
997 Mutex::Locker api_locker (target->GetAPIMutex());
998 frame->DumpUsingSettingsFormat (&strm);
999 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001000 else
1001 {
1002 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1003 if (log)
1004 log->Printf ("SBFrame(%p)::GetDescription () => error: process is running", frame);
1005 }
1006
Caroline Tice98f930f2010-09-20 05:20:02 +00001007 }
1008 else
Greg Clayton96154be2011-11-13 06:57:31 +00001009 strm.PutCString ("No value");
Caroline Tice98f930f2010-09-20 05:20:02 +00001010
1011 return true;
1012}
Greg Clayton66ed2fb2010-10-05 00:00:42 +00001013
Greg Clayton4e9267d2010-12-14 18:39:31 +00001014SBValue
Greg Clayton66ed2fb2010-10-05 00:00:42 +00001015SBFrame::EvaluateExpression (const char *expr)
1016{
Greg Clayton582ed0e2011-06-18 20:06:08 +00001017 SBValue result;
Greg Claytona894fe72012-04-05 16:12:35 +00001018 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +00001019 StackFrame *frame = exe_ctx.GetFramePtr();
1020 Target *target = exe_ctx.GetTargetPtr();
1021 if (frame && target)
Greg Clayton582ed0e2011-06-18 20:06:08 +00001022 {
Greg Clayton289afcb2012-02-18 05:35:26 +00001023 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton582ed0e2011-06-18 20:06:08 +00001024 result = EvaluateExpression (expr, use_dynamic);
1025 }
1026 return result;
Jim Inghame41494a2011-04-16 00:01:13 +00001027}
1028
1029SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +00001030SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value)
Jim Inghame41494a2011-04-16 00:01:13 +00001031{
Greg Clayton4e9267d2010-12-14 18:39:31 +00001032 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Sean Callanan94d255f2010-12-07 22:55:01 +00001033
Greg Clayton4e9267d2010-12-14 18:39:31 +00001034 LogSP expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Greg Claytona66ba462010-10-30 04:51:46 +00001035
Johnny Chenee6e7902011-08-10 22:06:24 +00001036 ExecutionResults exe_results;
Greg Clayton4e9267d2010-12-14 18:39:31 +00001037 SBValue expr_result;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001038 ValueObjectSP expr_value_sp;
Greg Claytona66ba462010-10-30 04:51:46 +00001039
Greg Claytona894fe72012-04-05 16:12:35 +00001040 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +00001041 StackFrame *frame = exe_ctx.GetFramePtr();
1042 Target *target = exe_ctx.GetTargetPtr();
Greg Clayton334d33a2012-01-30 07:41:31 +00001043 if (log)
Greg Clayton289afcb2012-02-18 05:35:26 +00001044 log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\")...", frame, expr);
Greg Clayton334d33a2012-01-30 07:41:31 +00001045
Greg Clayton289afcb2012-02-18 05:35:26 +00001046 if (frame && target)
Greg Clayton66ed2fb2010-10-05 00:00:42 +00001047 {
Greg Claytona894fe72012-04-05 16:12:35 +00001048 Process::StopLocker stop_locker;
1049 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1050 {
Greg Clayton87ac9022011-06-25 04:35:01 +00001051
Greg Claytona894fe72012-04-05 16:12:35 +00001052 Mutex::Locker api_locker (target->GetAPIMutex());
1053
1054
1055 StreamString frame_description;
1056 frame->DumpUsingSettingsFormat (&frame_description);
Greg Clayton87ac9022011-06-25 04:35:01 +00001057
Greg Claytona894fe72012-04-05 16:12:35 +00001058 Host::SetCrashDescriptionWithFormat ("SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
1059 expr, fetch_dynamic_value, frame_description.GetString().c_str());
Greg Clayton427f2902010-12-14 02:59:59 +00001060
Greg Claytona894fe72012-04-05 16:12:35 +00001061 const bool coerce_to_id = false;
1062 const bool unwind_on_error = true;
1063 const bool keep_in_memory = false;
1064
1065 exe_results = target->EvaluateExpression (expr,
1066 frame,
1067 eExecutionPolicyOnlyWhenNeeded,
1068 coerce_to_id,
1069 unwind_on_error,
1070 keep_in_memory,
1071 fetch_dynamic_value,
1072 expr_value_sp);
1073 expr_result.SetSP(expr_value_sp);
1074 Host::SetCrashDescription (NULL);
1075 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001076 else
1077 {
1078 if (log)
1079 log->Printf ("SBFrame(%p)::EvaluateExpression () => error: process is running", frame);
1080 }
Greg Clayton66ed2fb2010-10-05 00:00:42 +00001081 }
Jason Molendac48ca822012-02-21 05:33:55 +00001082
1083#ifndef LLDB_DISABLE_PYTHON
Sean Callanan94d255f2010-12-07 22:55:01 +00001084 if (expr_log)
Jim Inghame41494a2011-04-16 00:01:13 +00001085 expr_log->Printf("** [SBFrame::EvaluateExpression] Expression result is %s, summary %s **",
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001086 expr_result.GetValue(),
1087 expr_result.GetSummary());
Sean Callanan94d255f2010-12-07 22:55:01 +00001088
Greg Claytona66ba462010-10-30 04:51:46 +00001089 if (log)
Greg Clayton289afcb2012-02-18 05:35:26 +00001090 log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)",
1091 frame,
Jim Inghame41494a2011-04-16 00:01:13 +00001092 expr,
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001093 expr_value_sp.get(),
Johnny Chenee6e7902011-08-10 22:06:24 +00001094 exe_results);
Jason Molendac48ca822012-02-21 05:33:55 +00001095#endif
Greg Claytona66ba462010-10-30 04:51:46 +00001096
Greg Clayton49ce6822010-10-31 03:01:06 +00001097 return expr_result;
Greg Clayton66ed2fb2010-10-05 00:00:42 +00001098}
Greg Clayton582ed0e2011-06-18 20:06:08 +00001099
1100bool
1101SBFrame::IsInlined()
1102{
Greg Claytona894fe72012-04-05 16:12:35 +00001103 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +00001104 StackFrame *frame = exe_ctx.GetFramePtr();
1105 Target *target = exe_ctx.GetTargetPtr();
1106 if (frame && target)
Greg Clayton582ed0e2011-06-18 20:06:08 +00001107 {
Greg Claytona894fe72012-04-05 16:12:35 +00001108 Process::StopLocker stop_locker;
1109 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1110 {
1111
1112 Block *block = frame->GetSymbolContext(eSymbolContextBlock).block;
1113 if (block)
1114 return block->GetContainingInlinedBlock () != NULL;
1115 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001116 else
1117 {
1118 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1119 if (log)
1120 log->Printf ("SBFrame(%p)::IsInlined () => error: process is running", frame);
1121 }
1122
Greg Clayton582ed0e2011-06-18 20:06:08 +00001123 }
1124 return false;
1125}
1126
1127const char *
1128SBFrame::GetFunctionName()
1129{
1130 const char *name = NULL;
Greg Claytona894fe72012-04-05 16:12:35 +00001131 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Clayton289afcb2012-02-18 05:35:26 +00001132 StackFrame *frame = exe_ctx.GetFramePtr();
1133 Target *target = exe_ctx.GetTargetPtr();
1134 if (frame && target)
Greg Clayton582ed0e2011-06-18 20:06:08 +00001135 {
Greg Claytona894fe72012-04-05 16:12:35 +00001136 Process::StopLocker stop_locker;
1137 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Greg Clayton582ed0e2011-06-18 20:06:08 +00001138 {
Greg Claytona894fe72012-04-05 16:12:35 +00001139 SymbolContext sc (frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol));
1140 if (sc.block)
Greg Clayton582ed0e2011-06-18 20:06:08 +00001141 {
Greg Claytona894fe72012-04-05 16:12:35 +00001142 Block *inlined_block = sc.block->GetContainingInlinedBlock ();
1143 if (inlined_block)
1144 {
1145 const InlineFunctionInfo* inlined_info = inlined_block->GetInlinedFunctionInfo();
1146 name = inlined_info->GetName().AsCString();
1147 }
Greg Clayton582ed0e2011-06-18 20:06:08 +00001148 }
Greg Claytona894fe72012-04-05 16:12:35 +00001149
1150 if (name == NULL)
1151 {
1152 if (sc.function)
1153 name = sc.function->GetName().GetCString();
1154 }
Greg Clayton582ed0e2011-06-18 20:06:08 +00001155
Greg Claytona894fe72012-04-05 16:12:35 +00001156 if (name == NULL)
1157 {
1158 if (sc.symbol)
1159 name = sc.symbol->GetName().GetCString();
1160 }
Greg Clayton582ed0e2011-06-18 20:06:08 +00001161 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001162 else
1163 {
1164 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1165 if (log)
1166 log->Printf ("SBFrame(%p)::GetFunctionName() => error: process is running", frame);
1167
1168 }
Greg Clayton582ed0e2011-06-18 20:06:08 +00001169 }
1170 return name;
1171}
1172