blob: 7ca7c16c2ad31b51bbe32d40220046a53487810c [file] [log] [blame]
Chris Lattner30fdc8d2010-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
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +000010// C Includes
11// C++ Includes
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012#include <algorithm>
Greg Clayton349213f2016-04-29 21:00:38 +000013#include <set>
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +000014#include <string>
15
16// Other libraries and framework includes
17// Project includes
18#include "lldb/API/SBFrame.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019
20#include "lldb/lldb-types.h"
21
22#include "lldb/Core/Address.h"
23#include "lldb/Core/ConstString.h"
Caroline Ticeceb6b132010-10-26 03:11:13 +000024#include "lldb/Core/Log.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000025#include "lldb/Core/Stream.h"
26#include "lldb/Core/StreamFile.h"
27#include "lldb/Core/ValueObjectRegister.h"
28#include "lldb/Core/ValueObjectVariable.h"
Sean Callanan4dbb2712015-09-25 20:35:58 +000029#include "Plugins/ExpressionParser/Clang/ClangPersistentVariables.h"
Jim Ingham151c0322015-09-15 21:13:50 +000030#include "lldb/Expression/UserExpression.h"
Greg Clayton1ba7c4d2011-06-25 04:35:01 +000031#include "lldb/Host/Host.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032#include "lldb/Symbol/Block.h"
Greg Clayton1f746072012-08-29 21:13:06 +000033#include "lldb/Symbol/Function.h"
34#include "lldb/Symbol/Symbol.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035#include "lldb/Symbol/SymbolContext.h"
36#include "lldb/Symbol/VariableList.h"
37#include "lldb/Symbol/Variable.h"
38#include "lldb/Target/ExecutionContext.h"
39#include "lldb/Target/Target.h"
40#include "lldb/Target/Process.h"
41#include "lldb/Target/RegisterContext.h"
Jason Molendab57e4a12013-11-04 09:33:30 +000042#include "lldb/Target/StackFrame.h"
Greg Claytonb9556ac2012-01-30 07:41:31 +000043#include "lldb/Target/StackID.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000044#include "lldb/Target/Thread.h"
45
Eli Friedman4c5de692010-06-09 07:44:37 +000046#include "lldb/API/SBDebugger.h"
47#include "lldb/API/SBValue.h"
48#include "lldb/API/SBAddress.h"
Jim Ingham35e1bda2012-10-16 21:41:58 +000049#include "lldb/API/SBExpressionOptions.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000050#include "lldb/API/SBStream.h"
Eli Friedman4c5de692010-06-09 07:44:37 +000051#include "lldb/API/SBSymbolContext.h"
52#include "lldb/API/SBThread.h"
Zachary Turner51f96ee2015-02-17 17:55:50 +000053#include "lldb/API/SBVariablesOptions.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000054
55using namespace lldb;
56using namespace lldb_private;
57
58SBFrame::SBFrame () :
Greg Clayton7fdf9ef2012-04-05 16:12:35 +000059 m_opaque_sp (new ExecutionContextRef())
Chris Lattner30fdc8d2010-06-08 16:52:24 +000060{
61}
62
Jason Molendab57e4a12013-11-04 09:33:30 +000063SBFrame::SBFrame (const StackFrameSP &lldb_object_sp) :
Greg Clayton7fdf9ef2012-04-05 16:12:35 +000064 m_opaque_sp (new ExecutionContextRef (lldb_object_sp))
Chris Lattner30fdc8d2010-06-08 16:52:24 +000065{
Greg Clayton5160ce52013-03-27 23:08:40 +000066 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +000067
68 if (log)
69 {
70 SBStream sstr;
71 GetDescription (sstr);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000072 log->Printf ("SBFrame::SBFrame (sp=%p) => SBFrame(%p): %s",
73 static_cast<void*>(lldb_object_sp.get()),
74 static_cast<void*>(lldb_object_sp.get()), sstr.GetData());
Caroline Ticeceb6b132010-10-26 03:11:13 +000075 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000076}
77
Greg Claytonefabb122010-11-05 23:17:00 +000078SBFrame::SBFrame(const SBFrame &rhs) :
Greg Clayton7fdf9ef2012-04-05 16:12:35 +000079 m_opaque_sp (new ExecutionContextRef (*rhs.m_opaque_sp))
Greg Claytonefabb122010-11-05 23:17:00 +000080{
81}
82
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +000083SBFrame::~SBFrame() = default;
84
Greg Claytonefabb122010-11-05 23:17:00 +000085const SBFrame &
86SBFrame::operator = (const SBFrame &rhs)
87{
88 if (this != &rhs)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +000089 *m_opaque_sp = *rhs.m_opaque_sp;
Greg Claytonefabb122010-11-05 23:17:00 +000090 return *this;
91}
92
Jason Molendab57e4a12013-11-04 09:33:30 +000093StackFrameSP
Greg Claytonb9556ac2012-01-30 07:41:31 +000094SBFrame::GetFrameSP() const
Chris Lattner30fdc8d2010-06-08 16:52:24 +000095{
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +000096 return (m_opaque_sp ? m_opaque_sp->GetFrameSP() : StackFrameSP());
Chris Lattner30fdc8d2010-06-08 16:52:24 +000097}
98
Greg Claytonb9556ac2012-01-30 07:41:31 +000099void
Jason Molendab57e4a12013-11-04 09:33:30 +0000100SBFrame::SetFrameSP (const StackFrameSP &lldb_object_sp)
Greg Claytonb9556ac2012-01-30 07:41:31 +0000101{
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000102 return m_opaque_sp->SetFrameSP(lldb_object_sp);
Greg Claytonb9556ac2012-01-30 07:41:31 +0000103}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000104
105bool
106SBFrame::IsValid() const
107{
Jim Ingham7fa7dc32016-05-07 00:54:56 +0000108 Mutex::Locker api_locker;
109 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
110
111 Target *target = exe_ctx.GetTargetPtr();
112 Process *process = exe_ctx.GetProcessPtr();
113 if (target && process)
114 {
115 Process::StopLocker stop_locker;
116 if (stop_locker.TryLock(&process->GetRunLock()))
117 return GetFrameSP().get() != nullptr;
118 }
119
120 // Without a target & process we can't have a valid stack frame.
121 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000122}
123
124SBSymbolContext
125SBFrame::GetSymbolContext (uint32_t resolve_scope) const
126{
Greg Clayton5160ce52013-03-27 23:08:40 +0000127 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000128 SBSymbolContext sb_sym_ctx;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000129 Mutex::Locker api_locker;
130 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
131
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000132 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +0000133 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000134 Process *process = exe_ctx.GetProcessPtr();
135 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000136 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000137 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000138 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000139 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000140 frame = exe_ctx.GetFramePtr();
141 if (frame)
142 {
143 sb_sym_ctx.SetSymbolContext(&frame->GetSymbolContext (resolve_scope));
144 }
145 else
146 {
147 if (log)
148 log->Printf ("SBFrame::GetVariables () => error: could not reconstruct frame object for this SBFrame.");
149 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000150 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000151 else
152 {
153 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000154 log->Printf ("SBFrame::GetSymbolContext () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000155 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000156 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000157
158 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000159 log->Printf ("SBFrame(%p)::GetSymbolContext (resolve_scope=0x%8.8x) => SBSymbolContext(%p)",
160 static_cast<void*>(frame), resolve_scope,
161 static_cast<void*>(sb_sym_ctx.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000162
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000163 return sb_sym_ctx;
164}
165
166SBModule
167SBFrame::GetModule () const
168{
Greg Clayton5160ce52013-03-27 23:08:40 +0000169 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton72eff182010-12-14 04:58:53 +0000170 SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +0000171 ModuleSP module_sp;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000172 Mutex::Locker api_locker;
173 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
174
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000175 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +0000176 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000177 Process *process = exe_ctx.GetProcessPtr();
178 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000179 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000180 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000181 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000182 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000183 frame = exe_ctx.GetFramePtr();
184 if (frame)
185 {
186 module_sp = frame->GetSymbolContext (eSymbolContextModule).module_sp;
187 sb_module.SetSP (module_sp);
188 }
189 else
190 {
191 if (log)
192 log->Printf ("SBFrame::GetModule () => error: could not reconstruct frame object for this SBFrame.");
193 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000194 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000195 else
196 {
197 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000198 log->Printf ("SBFrame::GetModule () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000199 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000200 }
Greg Clayton72eff182010-12-14 04:58:53 +0000201
Greg Clayton48381312010-10-30 04:51:46 +0000202 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000203 log->Printf ("SBFrame(%p)::GetModule () => SBModule(%p)",
204 static_cast<void*>(frame),
205 static_cast<void*>(module_sp.get()));
Greg Clayton48381312010-10-30 04:51:46 +0000206
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000207 return sb_module;
208}
209
210SBCompileUnit
211SBFrame::GetCompileUnit () const
212{
Greg Clayton5160ce52013-03-27 23:08:40 +0000213 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton72eff182010-12-14 04:58:53 +0000214 SBCompileUnit sb_comp_unit;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000215 Mutex::Locker api_locker;
216 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
217
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000218 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +0000219 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000220 Process *process = exe_ctx.GetProcessPtr();
221 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000222 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000223 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000224 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000225 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000226 frame = exe_ctx.GetFramePtr();
227 if (frame)
228 {
229 sb_comp_unit.reset (frame->GetSymbolContext (eSymbolContextCompUnit).comp_unit);
230 }
231 else
232 {
233 if (log)
234 log->Printf ("SBFrame::GetCompileUnit () => error: could not reconstruct frame object for this SBFrame.");
235 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000236 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000237 else
238 {
239 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000240 log->Printf ("SBFrame::GetCompileUnit () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000241 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000242 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000243 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000244 log->Printf ("SBFrame(%p)::GetCompileUnit () => SBCompileUnit(%p)",
245 static_cast<void*>(frame),
246 static_cast<void*>(sb_comp_unit.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000247
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000248 return sb_comp_unit;
249}
250
251SBFunction
252SBFrame::GetFunction () const
253{
Greg Clayton5160ce52013-03-27 23:08:40 +0000254 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton72eff182010-12-14 04:58:53 +0000255 SBFunction sb_function;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000256 Mutex::Locker api_locker;
257 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
258
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000259 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +0000260 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000261 Process *process = exe_ctx.GetProcessPtr();
262 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000263 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000264 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000265 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000266 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000267 frame = exe_ctx.GetFramePtr();
268 if (frame)
269 {
270 sb_function.reset(frame->GetSymbolContext (eSymbolContextFunction).function);
271 }
272 else
273 {
274 if (log)
275 log->Printf ("SBFrame::GetFunction () => error: could not reconstruct frame object for this SBFrame.");
276 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000277 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000278 else
279 {
280 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000281 log->Printf ("SBFrame::GetFunction () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000282 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000283 }
Greg Clayton48381312010-10-30 04:51:46 +0000284 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000285 log->Printf ("SBFrame(%p)::GetFunction () => SBFunction(%p)",
286 static_cast<void*>(frame),
287 static_cast<void*>(sb_function.get()));
Greg Clayton48381312010-10-30 04:51:46 +0000288
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000289 return sb_function;
290}
291
Greg Clayton3b065572010-10-04 18:37:52 +0000292SBSymbol
293SBFrame::GetSymbol () const
294{
Greg Clayton5160ce52013-03-27 23:08:40 +0000295 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton72eff182010-12-14 04:58:53 +0000296 SBSymbol sb_symbol;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000297 Mutex::Locker api_locker;
298 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
299
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000300 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +0000301 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000302 Process *process = exe_ctx.GetProcessPtr();
303 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000304 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000305 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000306 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000307 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000308 frame = exe_ctx.GetFramePtr();
309 if (frame)
310 {
311 sb_symbol.reset(frame->GetSymbolContext (eSymbolContextSymbol).symbol);
312 }
313 else
314 {
315 if (log)
316 log->Printf ("SBFrame::GetSymbol () => error: could not reconstruct frame object for this SBFrame.");
317 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000318 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000319 else
320 {
321 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000322 log->Printf ("SBFrame::GetSymbol () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000323 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000324 }
Greg Clayton48381312010-10-30 04:51:46 +0000325 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000326 log->Printf ("SBFrame(%p)::GetSymbol () => SBSymbol(%p)",
327 static_cast<void*>(frame),
328 static_cast<void*>(sb_symbol.get()));
Greg Clayton3b065572010-10-04 18:37:52 +0000329 return sb_symbol;
330}
331
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000332SBBlock
333SBFrame::GetBlock () const
334{
Greg Clayton5160ce52013-03-27 23:08:40 +0000335 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton72eff182010-12-14 04:58:53 +0000336 SBBlock sb_block;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000337 Mutex::Locker api_locker;
338 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
339
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000340 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +0000341 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000342 Process *process = exe_ctx.GetProcessPtr();
343 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000344 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000345 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000346 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000347 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000348 frame = exe_ctx.GetFramePtr();
349 if (frame)
350 {
351 sb_block.SetPtr (frame->GetSymbolContext (eSymbolContextBlock).block);
352 }
353 else
354 {
355 if (log)
356 log->Printf ("SBFrame::GetBlock () => error: could not reconstruct frame object for this SBFrame.");
357 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000358 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000359 else
360 {
361 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000362 log->Printf ("SBFrame(%p)::GetBlock () => error: process is running",
363 static_cast<void*>(frame));
Greg Claytonc9858e42012-04-06 02:17:47 +0000364 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000365 }
Greg Clayton48381312010-10-30 04:51:46 +0000366 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000367 log->Printf ("SBFrame(%p)::GetBlock () => SBBlock(%p)",
368 static_cast<void*>(frame),
369 static_cast<void*>(sb_block.GetPtr()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000370 return sb_block;
371}
372
Greg Clayton95897c62010-09-07 04:20:48 +0000373SBBlock
374SBFrame::GetFrameBlock () const
375{
Greg Clayton72eff182010-12-14 04:58:53 +0000376 SBBlock sb_block;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000377 Mutex::Locker api_locker;
378 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
379
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000380 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +0000381 Target *target = exe_ctx.GetTargetPtr();
Greg Clayton5160ce52013-03-27 23:08:40 +0000382 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham7730b9a2012-11-29 00:26:19 +0000383 Process *process = exe_ctx.GetProcessPtr();
384 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000385 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000386 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000387 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000388 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000389 frame = exe_ctx.GetFramePtr();
390 if (frame)
391 {
392 sb_block.SetPtr(frame->GetFrameBlock ());
393 }
394 else
395 {
396 if (log)
397 log->Printf ("SBFrame::GetFrameBlock () => error: could not reconstruct frame object for this SBFrame.");
398 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000399 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000400 else
401 {
402 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000403 log->Printf ("SBFrame::GetFrameBlock () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000404 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000405 }
Greg Clayton48381312010-10-30 04:51:46 +0000406 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000407 log->Printf ("SBFrame(%p)::GetFrameBlock () => SBBlock(%p)",
408 static_cast<void*>(frame),
409 static_cast<void*>(sb_block.GetPtr()));
Greg Clayton95897c62010-09-07 04:20:48 +0000410 return sb_block;
411}
412
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000413SBLineEntry
414SBFrame::GetLineEntry () const
415{
Greg Clayton5160ce52013-03-27 23:08:40 +0000416 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton72eff182010-12-14 04:58:53 +0000417 SBLineEntry sb_line_entry;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000418 Mutex::Locker api_locker;
419 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
420
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000421 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +0000422 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000423 Process *process = exe_ctx.GetProcessPtr();
424 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000425 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000426 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000427 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000428 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000429 frame = exe_ctx.GetFramePtr();
430 if (frame)
431 {
432 sb_line_entry.SetLineEntry (frame->GetSymbolContext (eSymbolContextLineEntry).line_entry);
433 }
434 else
435 {
436 if (log)
437 log->Printf ("SBFrame::GetLineEntry () => error: could not reconstruct frame object for this SBFrame.");
438 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000439 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000440 else
441 {
442 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000443 log->Printf ("SBFrame::GetLineEntry () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000444 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000445 }
Greg Clayton48381312010-10-30 04:51:46 +0000446 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000447 log->Printf ("SBFrame(%p)::GetLineEntry () => SBLineEntry(%p)",
448 static_cast<void*>(frame),
449 static_cast<void*>(sb_line_entry.get()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000450 return sb_line_entry;
451}
452
453uint32_t
454SBFrame::GetFrameID () const
455{
Greg Claytonb9556ac2012-01-30 07:41:31 +0000456 uint32_t frame_idx = UINT32_MAX;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000457
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000458 ExecutionContext exe_ctx(m_opaque_sp.get());
Jason Molendab57e4a12013-11-04 09:33:30 +0000459 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000460 if (frame)
Greg Claytond9e416c2012-02-18 05:35:26 +0000461 frame_idx = frame->GetFrameIndex ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000462
Greg Clayton5160ce52013-03-27 23:08:40 +0000463 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000464 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000465 log->Printf ("SBFrame(%p)::GetFrameID () => %u",
466 static_cast<void*>(frame), frame_idx);
Greg Clayton48381312010-10-30 04:51:46 +0000467 return frame_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000468}
469
Greg Clayton424a5db2015-05-28 03:27:22 +0000470lldb::addr_t
471SBFrame::GetCFA () const
472{
473 ExecutionContext exe_ctx(m_opaque_sp.get());
474 StackFrame *frame = exe_ctx.GetFramePtr();
475 if (frame)
476 return frame->GetStackID().GetCallFrameAddress();
477 return LLDB_INVALID_ADDRESS;
478}
479
Greg Clayton69b582f2010-12-14 18:39:31 +0000480addr_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000481SBFrame::GetPC () const
482{
Greg Clayton5160ce52013-03-27 23:08:40 +0000483 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton69b582f2010-12-14 18:39:31 +0000484 addr_t addr = LLDB_INVALID_ADDRESS;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000485 Mutex::Locker api_locker;
486 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
487
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000488 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +0000489 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000490 Process *process = exe_ctx.GetProcessPtr();
491 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000492 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000493 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000494 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000495 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000496 frame = exe_ctx.GetFramePtr();
497 if (frame)
498 {
Tamas Berghammer25b9f7e2015-09-07 09:58:09 +0000499 addr = frame->GetFrameCodeAddress().GetOpcodeLoadAddress (target, eAddressClassCode);
Jim Ingham7730b9a2012-11-29 00:26:19 +0000500 }
501 else
502 {
503 if (log)
504 log->Printf ("SBFrame::GetPC () => error: could not reconstruct frame object for this SBFrame.");
505 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000506 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000507 else
508 {
509 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000510 log->Printf ("SBFrame::GetPC () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000511 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000512 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000513
514 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000515 log->Printf ("SBFrame(%p)::GetPC () => 0x%" PRIx64,
516 static_cast<void*>(frame), addr);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000517
518 return addr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000519}
520
521bool
Greg Clayton69b582f2010-12-14 18:39:31 +0000522SBFrame::SetPC (addr_t new_pc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000523{
Greg Clayton5160ce52013-03-27 23:08:40 +0000524 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000525 bool ret_val = false;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000526 Mutex::Locker api_locker;
527 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
528
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000529 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +0000530 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000531 Process *process = exe_ctx.GetProcessPtr();
532 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000533 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000534 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000535 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000536 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000537 frame = exe_ctx.GetFramePtr();
538 if (frame)
539 {
540 ret_val = frame->GetRegisterContext()->SetPC (new_pc);
541 }
542 else
543 {
544 if (log)
545 log->Printf ("SBFrame::SetPC () => error: could not reconstruct frame object for this SBFrame.");
546 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000547 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000548 else
549 {
550 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000551 log->Printf ("SBFrame::SetPC () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000552 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000553 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000554
555 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +0000556 log->Printf ("SBFrame(%p)::SetPC (new_pc=0x%" PRIx64 ") => %i",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000557 static_cast<void*>(frame), new_pc, ret_val);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000558
559 return ret_val;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000560}
561
Greg Clayton69b582f2010-12-14 18:39:31 +0000562addr_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000563SBFrame::GetSP () const
564{
Greg Clayton5160ce52013-03-27 23:08:40 +0000565 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000566 addr_t addr = LLDB_INVALID_ADDRESS;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000567 Mutex::Locker api_locker;
568 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
569
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000570 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +0000571 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000572 Process *process = exe_ctx.GetProcessPtr();
573 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000574 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000575 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000576 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000577 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000578 frame = exe_ctx.GetFramePtr();
579 if (frame)
580 {
581 addr = frame->GetRegisterContext()->GetSP();
582 }
583 else
584 {
585 if (log)
586 log->Printf ("SBFrame::GetSP () => error: could not reconstruct frame object for this SBFrame.");
587 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000588 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000589 else
590 {
591 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000592 log->Printf ("SBFrame::GetSP () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000593 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000594 }
Greg Clayton48381312010-10-30 04:51:46 +0000595 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000596 log->Printf ("SBFrame(%p)::GetSP () => 0x%" PRIx64,
597 static_cast<void*>(frame), addr);
Greg Clayton48381312010-10-30 04:51:46 +0000598
599 return addr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000600}
601
Greg Clayton69b582f2010-12-14 18:39:31 +0000602addr_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000603SBFrame::GetFP () const
604{
Greg Clayton5160ce52013-03-27 23:08:40 +0000605 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton69b582f2010-12-14 18:39:31 +0000606 addr_t addr = LLDB_INVALID_ADDRESS;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000607 Mutex::Locker api_locker;
608 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
609
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000610 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +0000611 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000612 Process *process = exe_ctx.GetProcessPtr();
613 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000614 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000615 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000616 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000617 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000618 frame = exe_ctx.GetFramePtr();
619 if (frame)
620 {
621 addr = frame->GetRegisterContext()->GetFP();
622 }
623 else
624 {
625 if (log)
626 log->Printf ("SBFrame::GetFP () => error: could not reconstruct frame object for this SBFrame.");
627 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000628 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000629 else
630 {
631 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000632 log->Printf ("SBFrame::GetFP () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000633 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000634 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000635
636 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000637 log->Printf ("SBFrame(%p)::GetFP () => 0x%" PRIx64,
638 static_cast<void*>(frame), addr);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000639 return addr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000640}
641
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000642SBAddress
643SBFrame::GetPCAddress () const
644{
Greg Clayton5160ce52013-03-27 23:08:40 +0000645 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000646 SBAddress sb_addr;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000647 Mutex::Locker api_locker;
648 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
649
Jason Molendab57e4a12013-11-04 09:33:30 +0000650 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Claytond9e416c2012-02-18 05:35:26 +0000651 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000652 Process *process = exe_ctx.GetProcessPtr();
653 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000654 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000655 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000656 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000657 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000658 frame = exe_ctx.GetFramePtr();
659 if (frame)
660 {
661 sb_addr.SetAddress (&frame->GetFrameCodeAddress());
662 }
663 else
664 {
665 if (log)
666 log->Printf ("SBFrame::GetPCAddress () => error: could not reconstruct frame object for this SBFrame.");
667 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000668 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000669 else
670 {
671 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000672 log->Printf ("SBFrame::GetPCAddress () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000673 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000674 }
Greg Clayton48381312010-10-30 04:51:46 +0000675 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000676 log->Printf ("SBFrame(%p)::GetPCAddress () => SBAddress(%p)",
677 static_cast<void*>(frame),
678 static_cast<void*>(sb_addr.get()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000679 return sb_addr;
680}
681
682void
683SBFrame::Clear()
684{
Greg Claytonaf2589e2012-04-12 20:58:26 +0000685 m_opaque_sp->Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000686}
687
Greg Clayton7edbdfc2012-02-03 07:02:37 +0000688lldb::SBValue
689SBFrame::GetValueForVariablePath (const char *var_path)
690{
691 SBValue sb_value;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000692 ExecutionContext exe_ctx(m_opaque_sp.get());
Jason Molendab57e4a12013-11-04 09:33:30 +0000693 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Claytond9e416c2012-02-18 05:35:26 +0000694 Target *target = exe_ctx.GetTargetPtr();
695 if (frame && target)
Greg Clayton7edbdfc2012-02-03 07:02:37 +0000696 {
Greg Claytonc9858e42012-04-06 02:17:47 +0000697 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
698 sb_value = GetValueForVariablePath (var_path, use_dynamic);
Greg Clayton7edbdfc2012-02-03 07:02:37 +0000699 }
700 return sb_value;
701}
702
703lldb::SBValue
704SBFrame::GetValueForVariablePath (const char *var_path, DynamicValueType use_dynamic)
705{
706 SBValue sb_value;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000707 Mutex::Locker api_locker;
Greg Clayton5160ce52013-03-27 23:08:40 +0000708 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000709 if (var_path == nullptr || var_path[0] == '\0')
Jim Ingham7730b9a2012-11-29 00:26:19 +0000710 {
711 if (log)
712 log->Printf ("SBFrame::GetValueForVariablePath called with empty variable path.");
713 return sb_value;
714 }
715
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000716 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
717
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000718 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +0000719 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000720 Process *process = exe_ctx.GetProcessPtr();
721 if (target && process)
Greg Clayton7edbdfc2012-02-03 07:02:37 +0000722 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000723 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000724 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000725 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000726 frame = exe_ctx.GetFramePtr();
727 if (frame)
728 {
729 VariableSP var_sp;
730 Error error;
731 ValueObjectSP value_sp (frame->GetValueForVariableExpressionPath (var_path,
732 eNoDynamicValues,
Jason Molendab57e4a12013-11-04 09:33:30 +0000733 StackFrame::eExpressionPathOptionCheckPtrVsMember | StackFrame::eExpressionPathOptionsAllowDirectIVarAccess,
Jim Ingham7730b9a2012-11-29 00:26:19 +0000734 var_sp,
735 error));
736 sb_value.SetSP(value_sp, use_dynamic);
737 }
738 else
739 {
740 if (log)
741 log->Printf ("SBFrame::GetValueForVariablePath () => error: could not reconstruct frame object for this SBFrame.");
742 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000743 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000744 else
745 {
Greg Claytonc9858e42012-04-06 02:17:47 +0000746 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000747 log->Printf ("SBFrame::GetValueForVariablePath () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000748 }
Greg Clayton7edbdfc2012-02-03 07:02:37 +0000749 }
750 return sb_value;
751}
752
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000753SBValue
Greg Clayton69b582f2010-12-14 18:39:31 +0000754SBFrame::FindVariable (const char *name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000755{
Greg Clayton316d4982011-06-18 20:06:08 +0000756 SBValue value;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000757 ExecutionContext exe_ctx(m_opaque_sp.get());
Jason Molendab57e4a12013-11-04 09:33:30 +0000758 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Claytond9e416c2012-02-18 05:35:26 +0000759 Target *target = exe_ctx.GetTargetPtr();
760 if (frame && target)
Greg Clayton316d4982011-06-18 20:06:08 +0000761 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000762 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton316d4982011-06-18 20:06:08 +0000763 value = FindVariable (name, use_dynamic);
764 }
765 return value;
Jim Ingham78a685a2011-04-16 00:01:13 +0000766}
767
768SBValue
Jim Ingham2837b762011-05-04 03:43:18 +0000769SBFrame::FindVariable (const char *name, lldb::DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +0000770{
Greg Clayton5160ce52013-03-27 23:08:40 +0000771 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton69b582f2010-12-14 18:39:31 +0000772 VariableSP var_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +0000773 SBValue sb_value;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000774
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000775 if (name == nullptr || name[0] == '\0')
Jim Ingham7730b9a2012-11-29 00:26:19 +0000776 {
777 if (log)
778 log->Printf ("SBFrame::FindVariable called with empty name");
779 return sb_value;
780 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000781
Greg Clayton81e871e2012-02-04 02:27:34 +0000782 ValueObjectSP value_sp;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000783 Mutex::Locker api_locker;
784 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
785
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000786 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +0000787 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000788 Process *process = exe_ctx.GetProcessPtr();
789 if (target && process)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000790 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000791 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000792 if (stop_locker.TryLock(&process->GetRunLock()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000793 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000794 frame = exe_ctx.GetFramePtr();
795 if (frame)
Greg Clayton72eff182010-12-14 04:58:53 +0000796 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000797 VariableList variable_list;
798 SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock));
799
800 if (sc.block)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000801 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000802 const bool can_create = true;
803 const bool get_parent_variables = true;
804 const bool stop_if_block_is_inlined_function = true;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000805
Tamas Berghammer72ac8a82016-02-25 12:23:37 +0000806 if (sc.block->AppendVariables (can_create,
Jim Ingham7730b9a2012-11-29 00:26:19 +0000807 get_parent_variables,
808 stop_if_block_is_inlined_function,
Tamas Berghammer72ac8a82016-02-25 12:23:37 +0000809 [frame](Variable* v) { return v->IsInScope(frame); },
Jim Ingham7730b9a2012-11-29 00:26:19 +0000810 &variable_list))
811 {
812 var_sp = variable_list.FindVariable (ConstString(name));
813 }
814 }
815
816 if (var_sp)
817 {
818 value_sp = frame->GetValueObjectForFrameVariable(var_sp, eNoDynamicValues);
819 sb_value.SetSP(value_sp, use_dynamic);
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000820 }
821 }
Jim Ingham7730b9a2012-11-29 00:26:19 +0000822 else
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000823 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000824 if (log)
825 log->Printf ("SBFrame::FindVariable () => error: could not reconstruct frame object for this SBFrame.");
Greg Clayton72eff182010-12-14 04:58:53 +0000826 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000827 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000828 else
829 {
830 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000831 log->Printf ("SBFrame::FindVariable () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000832 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000833 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000834
Greg Clayton48381312010-10-30 04:51:46 +0000835 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000836 log->Printf ("SBFrame(%p)::FindVariable (name=\"%s\") => SBValue(%p)",
837 static_cast<void*>(frame), name,
838 static_cast<void*>(value_sp.get()));
Greg Clayton48381312010-10-30 04:51:46 +0000839
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000840 return sb_value;
841}
842
843SBValue
Greg Clayton69b582f2010-12-14 18:39:31 +0000844SBFrame::FindValue (const char *name, ValueType value_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000845{
Greg Clayton316d4982011-06-18 20:06:08 +0000846 SBValue value;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000847 ExecutionContext exe_ctx(m_opaque_sp.get());
Jason Molendab57e4a12013-11-04 09:33:30 +0000848 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Claytond9e416c2012-02-18 05:35:26 +0000849 Target *target = exe_ctx.GetTargetPtr();
850 if (frame && target)
Greg Clayton316d4982011-06-18 20:06:08 +0000851 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000852 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton316d4982011-06-18 20:06:08 +0000853 value = FindValue (name, value_type, use_dynamic);
854 }
855 return value;
Jim Ingham78a685a2011-04-16 00:01:13 +0000856}
857
858SBValue
Jim Ingham2837b762011-05-04 03:43:18 +0000859SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +0000860{
Greg Clayton5160ce52013-03-27 23:08:40 +0000861 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton69b582f2010-12-14 18:39:31 +0000862 SBValue sb_value;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000863
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000864 if (name == nullptr || name[0] == '\0')
Jim Ingham7730b9a2012-11-29 00:26:19 +0000865 {
866 if (log)
867 log->Printf ("SBFrame::FindValue called with empty name.");
868 return sb_value;
869 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000870
Greg Clayton81e871e2012-02-04 02:27:34 +0000871 ValueObjectSP value_sp;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000872 Mutex::Locker api_locker;
873 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
874
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000875 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +0000876 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000877 Process *process = exe_ctx.GetProcessPtr();
878 if (target && process)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000879 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000880 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000881 if (stop_locker.TryLock(&process->GetRunLock()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000882 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000883 frame = exe_ctx.GetFramePtr();
884 if (frame)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000885 {
Enrico Granata8a2a0df2014-02-19 19:35:13 +0000886 VariableList variable_list;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000887
Jim Ingham7730b9a2012-11-29 00:26:19 +0000888 switch (value_type)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000889 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000890 case eValueTypeVariableGlobal: // global variable
891 case eValueTypeVariableStatic: // static variable
892 case eValueTypeVariableArgument: // function argument variables
893 case eValueTypeVariableLocal: // function local variables
894 {
Chaoren Lin0efb51a2015-03-19 22:00:13 +0000895 SymbolContext sc(frame->GetSymbolContext(eSymbolContextBlock));
Greg Clayton69b582f2010-12-14 18:39:31 +0000896
Jim Ingham7730b9a2012-11-29 00:26:19 +0000897 const bool can_create = true;
898 const bool get_parent_variables = true;
899 const bool stop_if_block_is_inlined_function = true;
Greg Clayton69b582f2010-12-14 18:39:31 +0000900
Chaoren Lin0efb51a2015-03-19 22:00:13 +0000901 if (sc.block)
902 sc.block->AppendVariables(can_create,
903 get_parent_variables,
904 stop_if_block_is_inlined_function,
Tamas Berghammer72ac8a82016-02-25 12:23:37 +0000905 [frame](Variable* v) { return v->IsInScope(frame); },
Chaoren Lin0efb51a2015-03-19 22:00:13 +0000906 &variable_list);
907 if (value_type == eValueTypeVariableGlobal)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000908 {
Chaoren Lin0efb51a2015-03-19 22:00:13 +0000909 const bool get_file_globals = true;
910 VariableList *frame_vars = frame->GetVariableList(get_file_globals);
911 if (frame_vars)
912 frame_vars->AppendVariablesIfUnique(variable_list);
913 }
914 ConstString const_name(name);
915 VariableSP variable_sp(variable_list.FindVariable(const_name, value_type));
916 if (variable_sp)
917 {
918 value_sp = frame->GetValueObjectForFrameVariable(variable_sp, eNoDynamicValues);
919 sb_value.SetSP(value_sp, use_dynamic);
Jim Ingham7730b9a2012-11-29 00:26:19 +0000920 }
921 }
922 break;
923
924 case eValueTypeRegister: // stack frame register value
925 {
926 RegisterContextSP reg_ctx (frame->GetRegisterContext());
927 if (reg_ctx)
928 {
929 const uint32_t num_regs = reg_ctx->GetRegisterCount();
930 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx)
931 {
932 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
933 if (reg_info &&
934 ((reg_info->name && strcasecmp (reg_info->name, name) == 0) ||
935 (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0)))
936 {
937 value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx);
938 sb_value.SetSP (value_sp);
939 break;
940 }
941 }
942 }
943 }
944 break;
945
946 case eValueTypeRegisterSet: // A collection of stack frame register values
947 {
948 RegisterContextSP reg_ctx (frame->GetRegisterContext());
949 if (reg_ctx)
950 {
951 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
952 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
953 {
954 const RegisterSet *reg_set = reg_ctx->GetRegisterSet (set_idx);
955 if (reg_set &&
956 ((reg_set->name && strcasecmp (reg_set->name, name) == 0) ||
957 (reg_set->short_name && strcasecmp (reg_set->short_name, name) == 0)))
958 {
959 value_sp = ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx);
960 sb_value.SetSP (value_sp);
961 break;
962 }
963 }
964 }
965 }
966 break;
967
968 case eValueTypeConstResult: // constant result variables
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000969 {
970 ConstString const_name(name);
Sean Callanan8f1f9a12015-09-30 19:57:57 +0000971 ExpressionVariableSP expr_var_sp (target->GetPersistentVariable (const_name));
Jim Ingham7730b9a2012-11-29 00:26:19 +0000972 if (expr_var_sp)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000973 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000974 value_sp = expr_var_sp->GetValueObject();
975 sb_value.SetSP (value_sp, use_dynamic);
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000976 }
977 }
Jim Ingham7730b9a2012-11-29 00:26:19 +0000978 break;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000979
Jim Ingham7730b9a2012-11-29 00:26:19 +0000980 default:
981 break;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000982 }
Jim Ingham7730b9a2012-11-29 00:26:19 +0000983 }
984 else
985 {
986 if (log)
987 log->Printf ("SBFrame::FindValue () => error: could not reconstruct frame object for this SBFrame.");
Greg Clayton69b582f2010-12-14 18:39:31 +0000988 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000989 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000990 else
991 {
992 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000993 log->Printf ("SBFrame::FindValue () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000994 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000995 }
Greg Clayton48381312010-10-30 04:51:46 +0000996
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000997 if (log)
998 log->Printf ("SBFrame(%p)::FindVariableInScope (name=\"%s\", value_type=%i) => SBValue(%p)",
999 static_cast<void*>(frame), name, value_type,
1000 static_cast<void*>(value_sp.get()));
1001
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001002 return sb_value;
1003}
1004
1005bool
Johnny Chen35e2ab62012-03-05 19:53:24 +00001006SBFrame::IsEqual (const SBFrame &that) const
1007{
Jason Molendab57e4a12013-11-04 09:33:30 +00001008 lldb::StackFrameSP this_sp = GetFrameSP();
1009 lldb::StackFrameSP that_sp = that.GetFrameSP();
Johnny Chen35e2ab62012-03-05 19:53:24 +00001010 return (this_sp && that_sp && this_sp->GetStackID() == that_sp->GetStackID());
1011}
1012
1013bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001014SBFrame::operator == (const SBFrame &rhs) const
1015{
Johnny Chen35e2ab62012-03-05 19:53:24 +00001016 return IsEqual(rhs);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001017}
1018
1019bool
1020SBFrame::operator != (const SBFrame &rhs) const
1021{
Johnny Chen35e2ab62012-03-05 19:53:24 +00001022 return !IsEqual(rhs);
Greg Clayton481cef22011-01-21 06:11:58 +00001023}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001024
1025SBThread
1026SBFrame::GetThread () const
1027{
Greg Clayton5160ce52013-03-27 23:08:40 +00001028 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001029
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001030 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Claytond9e416c2012-02-18 05:35:26 +00001031 ThreadSP thread_sp (exe_ctx.GetThreadSP());
1032 SBThread sb_thread (thread_sp);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001033
1034 if (log)
Caroline Tice750cd172010-10-26 23:49:36 +00001035 {
1036 SBStream sstr;
1037 sb_thread.GetDescription (sstr);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001038 log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s",
1039 static_cast<void*>(exe_ctx.GetFramePtr()),
1040 static_cast<void*>(thread_sp.get()), sstr.GetData());
Caroline Tice750cd172010-10-26 23:49:36 +00001041 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001042
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001043 return sb_thread;
1044}
1045
1046const char *
1047SBFrame::Disassemble () const
1048{
Greg Clayton5160ce52013-03-27 23:08:40 +00001049 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001050 const char *disassembly = nullptr;
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001051 Mutex::Locker api_locker;
1052 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1053
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001054 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +00001055 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +00001056 Process *process = exe_ctx.GetProcessPtr();
1057 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001058 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001059 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001060 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001061 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001062 frame = exe_ctx.GetFramePtr();
1063 if (frame)
1064 {
1065 disassembly = frame->Disassemble();
1066 }
1067 else
1068 {
1069 if (log)
1070 log->Printf ("SBFrame::Disassemble () => error: could not reconstruct frame object for this SBFrame.");
1071 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001072 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001073 else
1074 {
1075 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001076 log->Printf ("SBFrame::Disassemble () => error: process is running");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001077 }
Greg Claytonaf67cec2010-12-20 20:49:23 +00001078 }
Greg Clayton48381312010-10-30 04:51:46 +00001079
1080 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001081 log->Printf ("SBFrame(%p)::Disassemble () => %s",
1082 static_cast<void*>(frame), disassembly);
Greg Clayton48381312010-10-30 04:51:46 +00001083
1084 return disassembly;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001085}
1086
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001087SBValueList
1088SBFrame::GetVariables (bool arguments,
1089 bool locals,
1090 bool statics,
1091 bool in_scope_only)
1092{
Greg Clayton316d4982011-06-18 20:06:08 +00001093 SBValueList value_list;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001094 ExecutionContext exe_ctx(m_opaque_sp.get());
Jason Molendab57e4a12013-11-04 09:33:30 +00001095 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Claytond9e416c2012-02-18 05:35:26 +00001096 Target *target = exe_ctx.GetTargetPtr();
1097 if (frame && target)
Greg Clayton316d4982011-06-18 20:06:08 +00001098 {
Greg Claytond9e416c2012-02-18 05:35:26 +00001099 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
Zachary Turner51f96ee2015-02-17 17:55:50 +00001100 const bool include_runtime_support_values = target ? target->GetDisplayRuntimeSupportValues() : false;
1101
1102 SBVariablesOptions options;
1103 options.SetIncludeArguments(arguments);
1104 options.SetIncludeLocals(locals);
1105 options.SetIncludeStatics(statics);
1106 options.SetInScopeOnly(in_scope_only);
1107 options.SetIncludeRuntimeSupportValues(include_runtime_support_values);
1108 options.SetUseDynamic(use_dynamic);
1109
1110 value_list = GetVariables (options);
Greg Clayton316d4982011-06-18 20:06:08 +00001111 }
1112 return value_list;
Jim Ingham78a685a2011-04-16 00:01:13 +00001113}
1114
Enrico Granata560558e2015-02-11 02:35:39 +00001115lldb::SBValueList
1116SBFrame::GetVariables (bool arguments,
1117 bool locals,
1118 bool statics,
1119 bool in_scope_only,
1120 lldb::DynamicValueType use_dynamic)
1121{
1122 ExecutionContext exe_ctx(m_opaque_sp.get());
1123 Target *target = exe_ctx.GetTargetPtr();
Zachary Turner51f96ee2015-02-17 17:55:50 +00001124 const bool include_runtime_support_values = target ? target->GetDisplayRuntimeSupportValues() : false;
1125 SBVariablesOptions options;
1126 options.SetIncludeArguments(arguments);
1127 options.SetIncludeLocals(locals);
1128 options.SetIncludeStatics(statics);
1129 options.SetInScopeOnly(in_scope_only);
1130 options.SetIncludeRuntimeSupportValues(include_runtime_support_values);
1131 options.SetUseDynamic(use_dynamic);
1132 return GetVariables(options);
Enrico Granata560558e2015-02-11 02:35:39 +00001133}
1134
Jim Ingham78a685a2011-04-16 00:01:13 +00001135SBValueList
Zachary Turner51f96ee2015-02-17 17:55:50 +00001136SBFrame::GetVariables (const lldb::SBVariablesOptions& options)
Jim Ingham78a685a2011-04-16 00:01:13 +00001137{
Greg Clayton5160ce52013-03-27 23:08:40 +00001138 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001139
Greg Claytonb9556ac2012-01-30 07:41:31 +00001140 SBValueList value_list;
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001141 Mutex::Locker api_locker;
1142 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1143
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001144 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +00001145 Target *target = exe_ctx.GetTargetPtr();
Greg Claytonb9556ac2012-01-30 07:41:31 +00001146
Zachary Turner51f96ee2015-02-17 17:55:50 +00001147 const bool statics = options.GetIncludeStatics();
1148 const bool arguments = options.GetIncludeArguments();
1149 const bool locals = options.GetIncludeLocals();
1150 const bool in_scope_only = options.GetInScopeOnly();
1151 const bool include_runtime_support_values = options.GetIncludeRuntimeSupportValues();
1152 const lldb::DynamicValueType use_dynamic = options.GetUseDynamic();
1153
Caroline Ticeceb6b132010-10-26 03:11:13 +00001154 if (log)
Zachary Turner51f96ee2015-02-17 17:55:50 +00001155 log->Printf ("SBFrame::GetVariables (arguments=%i, locals=%i, statics=%i, in_scope_only=%i runtime=%i dynamic=%i)",
1156 arguments, locals,
1157 statics, in_scope_only,
1158 include_runtime_support_values, use_dynamic);
Greg Clayton349213f2016-04-29 21:00:38 +00001159
1160 std::set<VariableSP> variable_set;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001161 Process *process = exe_ctx.GetProcessPtr();
1162 if (target && process)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001163 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001164 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001165 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001166 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001167 frame = exe_ctx.GetFramePtr();
1168 if (frame)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001169 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001170 size_t i;
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001171 VariableList *variable_list = nullptr;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001172 variable_list = frame->GetVariableList(true);
1173 if (variable_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001174 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001175 const size_t num_variables = variable_list->GetSize();
1176 if (num_variables)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001177 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001178 for (i = 0; i < num_variables; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001179 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001180 VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
1181 if (variable_sp)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001182 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001183 bool add_variable = false;
1184 switch (variable_sp->GetScope())
1185 {
1186 case eValueTypeVariableGlobal:
1187 case eValueTypeVariableStatic:
1188 add_variable = statics;
1189 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001190
Jim Ingham7730b9a2012-11-29 00:26:19 +00001191 case eValueTypeVariableArgument:
1192 add_variable = arguments;
1193 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001194
Jim Ingham7730b9a2012-11-29 00:26:19 +00001195 case eValueTypeVariableLocal:
1196 add_variable = locals;
1197 break;
Greg Claytonc982c762010-07-09 20:39:50 +00001198
Jim Ingham7730b9a2012-11-29 00:26:19 +00001199 default:
1200 break;
1201 }
1202 if (add_variable)
1203 {
Greg Clayton349213f2016-04-29 21:00:38 +00001204 // Only add variables once so we don't end up with duplicates
1205 if (variable_set.find(variable_sp) == variable_set.end())
1206 variable_set.insert(variable_sp);
1207 else
1208 continue;
1209
Jim Ingham7730b9a2012-11-29 00:26:19 +00001210 if (in_scope_only && !variable_sp->IsInScope(frame))
1211 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001212
Jim Ingham7730b9a2012-11-29 00:26:19 +00001213 ValueObjectSP valobj_sp(frame->GetValueObjectForFrameVariable (variable_sp, eNoDynamicValues));
Enrico Granata560558e2015-02-11 02:35:39 +00001214
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001215 if (!include_runtime_support_values &&
1216 valobj_sp != nullptr &&
1217 valobj_sp->IsRuntimeSupportValue())
Enrico Granata560558e2015-02-11 02:35:39 +00001218 continue;
1219
Jim Ingham7730b9a2012-11-29 00:26:19 +00001220 SBValue value_sb;
1221 value_sb.SetSP(valobj_sp,use_dynamic);
1222 value_list.Append(value_sb);
1223 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001224 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001225 }
1226 }
1227 }
1228 }
Jim Ingham7730b9a2012-11-29 00:26:19 +00001229 else
1230 {
1231 if (log)
1232 log->Printf ("SBFrame::GetVariables () => error: could not reconstruct frame object for this SBFrame.");
1233 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001234 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001235 else
1236 {
1237 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001238 log->Printf ("SBFrame::GetVariables () => error: process is running");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001239 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001240 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001241
1242 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001243 log->Printf ("SBFrame(%p)::GetVariables (...) => SBValueList(%p)",
1244 static_cast<void*>(frame),
1245 static_cast<void*>(value_list.opaque_ptr()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001246
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001247 return value_list;
1248}
1249
Greg Clayton69b582f2010-12-14 18:39:31 +00001250SBValueList
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001251SBFrame::GetRegisters ()
1252{
Greg Clayton5160ce52013-03-27 23:08:40 +00001253 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001254
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001255 SBValueList value_list;
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001256 Mutex::Locker api_locker;
1257 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1258
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001259 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +00001260 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +00001261 Process *process = exe_ctx.GetProcessPtr();
1262 if (target && process)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001263 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001264 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001265 if (stop_locker.TryLock(&process->GetRunLock()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001266 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001267 frame = exe_ctx.GetFramePtr();
1268 if (frame)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001269 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001270 RegisterContextSP reg_ctx (frame->GetRegisterContext());
1271 if (reg_ctx)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001272 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001273 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
1274 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
1275 {
1276 value_list.Append(ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx));
1277 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001278 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001279 }
Jim Ingham7730b9a2012-11-29 00:26:19 +00001280 else
1281 {
1282 if (log)
1283 log->Printf ("SBFrame::GetRegisters () => error: could not reconstruct frame object for this SBFrame.");
1284 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001285 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001286 else
1287 {
1288 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001289 log->Printf ("SBFrame::GetRegisters () => error: process is running");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001290 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001291 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001292
1293 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001294 log->Printf ("SBFrame(%p)::GetRegisters () => SBValueList(%p)",
1295 static_cast<void*>(frame),
1296 static_cast<void*>(value_list.opaque_ptr()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001297
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001298 return value_list;
1299}
1300
Jason Molendaad9a53c2013-07-26 02:08:48 +00001301SBValue
1302SBFrame::FindRegister (const char *name)
1303{
1304 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1305
1306 SBValue result;
1307 ValueObjectSP value_sp;
1308 Mutex::Locker api_locker;
1309 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1310
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001311 StackFrame *frame = nullptr;
Jason Molendaad9a53c2013-07-26 02:08:48 +00001312 Target *target = exe_ctx.GetTargetPtr();
1313 Process *process = exe_ctx.GetProcessPtr();
1314 if (target && process)
1315 {
1316 Process::StopLocker stop_locker;
1317 if (stop_locker.TryLock(&process->GetRunLock()))
1318 {
1319 frame = exe_ctx.GetFramePtr();
1320 if (frame)
1321 {
1322 RegisterContextSP reg_ctx (frame->GetRegisterContext());
1323 if (reg_ctx)
1324 {
1325 const uint32_t num_regs = reg_ctx->GetRegisterCount();
1326 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx)
1327 {
1328 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
1329 if (reg_info &&
1330 ((reg_info->name && strcasecmp (reg_info->name, name) == 0) ||
1331 (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0)))
1332 {
1333 value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx);
1334 result.SetSP (value_sp);
1335 break;
1336 }
1337 }
1338 }
1339 }
1340 else
1341 {
1342 if (log)
Jason Molenda5d353842013-07-26 22:52:30 +00001343 log->Printf ("SBFrame::FindRegister () => error: could not reconstruct frame object for this SBFrame.");
Jason Molendaad9a53c2013-07-26 02:08:48 +00001344 }
1345 }
1346 else
1347 {
1348 if (log)
Jason Molenda5d353842013-07-26 22:52:30 +00001349 log->Printf ("SBFrame::FindRegister () => error: process is running");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001350 }
Jason Molendaad9a53c2013-07-26 02:08:48 +00001351 }
1352
1353 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001354 log->Printf ("SBFrame(%p)::FindRegister () => SBValue(%p)",
1355 static_cast<void*>(frame),
1356 static_cast<void*>(value_sp.get()));
Jason Molendaad9a53c2013-07-26 02:08:48 +00001357
1358 return result;
1359}
1360
Caroline Ticedde9cff2010-09-20 05:20:02 +00001361bool
1362SBFrame::GetDescription (SBStream &description)
1363{
Greg Clayton5160ce52013-03-27 23:08:40 +00001364 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001365 Stream &strm = description.ref();
1366
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001367 Mutex::Locker api_locker;
1368 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1369
Jason Molendab57e4a12013-11-04 09:33:30 +00001370 StackFrame *frame;
Greg Claytond9e416c2012-02-18 05:35:26 +00001371 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +00001372 Process *process = exe_ctx.GetProcessPtr();
1373 if (target && process)
Caroline Ticedde9cff2010-09-20 05:20:02 +00001374 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001375 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001376 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001377 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001378 frame = exe_ctx.GetFramePtr();
1379 if (frame)
1380 {
1381 frame->DumpUsingSettingsFormat (&strm);
1382 }
1383 else
1384 {
1385 if (log)
1386 log->Printf ("SBFrame::GetDescription () => error: could not reconstruct frame object for this SBFrame.");
1387 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001388 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001389 else
1390 {
Greg Claytonc9858e42012-04-06 02:17:47 +00001391 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001392 log->Printf ("SBFrame::GetDescription () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +00001393 }
1394
Caroline Ticedde9cff2010-09-20 05:20:02 +00001395 }
1396 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001397 strm.PutCString ("No value");
Caroline Ticedde9cff2010-09-20 05:20:02 +00001398
1399 return true;
1400}
Greg Clayton1d3afba2010-10-05 00:00:42 +00001401
Greg Clayton69b582f2010-12-14 18:39:31 +00001402SBValue
Greg Clayton1d3afba2010-10-05 00:00:42 +00001403SBFrame::EvaluateExpression (const char *expr)
1404{
Greg Clayton316d4982011-06-18 20:06:08 +00001405 SBValue result;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001406 ExecutionContext exe_ctx(m_opaque_sp.get());
Jason Molendab57e4a12013-11-04 09:33:30 +00001407 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Claytond9e416c2012-02-18 05:35:26 +00001408 Target *target = exe_ctx.GetTargetPtr();
1409 if (frame && target)
Greg Clayton316d4982011-06-18 20:06:08 +00001410 {
Jim Ingham35e1bda2012-10-16 21:41:58 +00001411 SBExpressionOptions options;
1412 lldb::DynamicValueType fetch_dynamic_value = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Claytoncced1562012-10-16 22:58:25 +00001413 options.SetFetchDynamicValue (fetch_dynamic_value);
Jim Ingham35e1bda2012-10-16 21:41:58 +00001414 options.SetUnwindOnError (true);
Eugene Leviant24785bd2016-01-29 10:48:11 +00001415 options.SetIgnoreBreakpoints (true);
Ryan Brown998c8a1c12015-11-02 19:30:40 +00001416 if (target->GetLanguage() != eLanguageTypeUnknown)
1417 options.SetLanguage(target->GetLanguage());
1418 else
1419 options.SetLanguage(frame->GetLanguage());
Jim Ingham35e1bda2012-10-16 21:41:58 +00001420 return EvaluateExpression (expr, options);
Greg Clayton316d4982011-06-18 20:06:08 +00001421 }
1422 return result;
Jim Ingham78a685a2011-04-16 00:01:13 +00001423}
1424
1425SBValue
Jim Ingham2837b762011-05-04 03:43:18 +00001426SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value)
Jim Ingham78a685a2011-04-16 00:01:13 +00001427{
Jim Ingham35e1bda2012-10-16 21:41:58 +00001428 SBExpressionOptions options;
Greg Claytoncced1562012-10-16 22:58:25 +00001429 options.SetFetchDynamicValue (fetch_dynamic_value);
Jim Ingham35e1bda2012-10-16 21:41:58 +00001430 options.SetUnwindOnError (true);
Eugene Leviant24785bd2016-01-29 10:48:11 +00001431 options.SetIgnoreBreakpoints (true);
Ryan Brown998c8a1c12015-11-02 19:30:40 +00001432 ExecutionContext exe_ctx(m_opaque_sp.get());
1433 StackFrame *frame = exe_ctx.GetFramePtr();
1434 Target *target = exe_ctx.GetTargetPtr();
1435 if (target && target->GetLanguage() != eLanguageTypeUnknown)
1436 options.SetLanguage(target->GetLanguage());
1437 else if (frame)
1438 options.SetLanguage(frame->GetLanguage());
Jim Ingham35e1bda2012-10-16 21:41:58 +00001439 return EvaluateExpression (expr, options);
Jim Ingham7ba6e992012-05-11 23:47:32 +00001440}
1441
1442SBValue
1443SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value, bool unwind_on_error)
1444{
Jim Ingham35e1bda2012-10-16 21:41:58 +00001445 SBExpressionOptions options;
Ryan Brown998c8a1c12015-11-02 19:30:40 +00001446 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Claytoncced1562012-10-16 22:58:25 +00001447 options.SetFetchDynamicValue (fetch_dynamic_value);
Jim Ingham35e1bda2012-10-16 21:41:58 +00001448 options.SetUnwindOnError (unwind_on_error);
Eugene Leviant24785bd2016-01-29 10:48:11 +00001449 options.SetIgnoreBreakpoints (true);
Ryan Brown998c8a1c12015-11-02 19:30:40 +00001450 StackFrame *frame = exe_ctx.GetFramePtr();
1451 Target *target = exe_ctx.GetTargetPtr();
1452 if (target && target->GetLanguage() != eLanguageTypeUnknown)
1453 options.SetLanguage(target->GetLanguage());
1454 else if (frame)
1455 options.SetLanguage(frame->GetLanguage());
Jim Ingham35e1bda2012-10-16 21:41:58 +00001456 return EvaluateExpression (expr, options);
1457}
1458
1459lldb::SBValue
1460SBFrame::EvaluateExpression (const char *expr, const SBExpressionOptions &options)
1461{
Greg Clayton5160ce52013-03-27 23:08:40 +00001462 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001463
Saleem Abdulrasool358efd62016-04-21 16:56:02 +00001464#ifndef LLDB_DISABLE_PYTHON
Greg Clayton5160ce52013-03-27 23:08:40 +00001465 Log *expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Saleem Abdulrasool358efd62016-04-21 16:56:02 +00001466#endif
Greg Clayton48381312010-10-30 04:51:46 +00001467
Jim Ingham8646d3c2014-05-05 02:47:44 +00001468 ExpressionResults exe_results = eExpressionSetupError;
Greg Clayton69b582f2010-12-14 18:39:31 +00001469 SBValue expr_result;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001470
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001471 if (expr == nullptr || expr[0] == '\0')
Jim Ingham7730b9a2012-11-29 00:26:19 +00001472 {
1473 if (log)
1474 log->Printf ("SBFrame::EvaluateExpression called with an empty expression");
1475 return expr_result;
1476 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001477
Greg Clayton81e871e2012-02-04 02:27:34 +00001478 ValueObjectSP expr_value_sp;
Greg Clayton48381312010-10-30 04:51:46 +00001479
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001480 Mutex::Locker api_locker;
1481 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1482
Greg Claytonb9556ac2012-01-30 07:41:31 +00001483 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001484 log->Printf ("SBFrame()::EvaluateExpression (expr=\"%s\")...", expr);
Greg Claytonb9556ac2012-01-30 07:41:31 +00001485
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001486 StackFrame *frame = nullptr;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001487 Target *target = exe_ctx.GetTargetPtr();
1488 Process *process = exe_ctx.GetProcessPtr();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001489
Jim Ingham7730b9a2012-11-29 00:26:19 +00001490 if (target && process)
1491 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001492 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001493 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001494 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001495 frame = exe_ctx.GetFramePtr();
1496 if (frame)
1497 {
Greg Claytonfb6621e2013-12-06 21:59:52 +00001498 if (target->GetDisplayExpressionsInCrashlogs())
1499 {
1500 StreamString frame_description;
1501 frame->DumpUsingSettingsFormat (&frame_description);
1502 Host::SetCrashDescriptionWithFormat ("SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
1503 expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str());
1504 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001505
Greg Claytonfb6621e2013-12-06 21:59:52 +00001506 exe_results = target->EvaluateExpression (expr,
Jim Ingham7730b9a2012-11-29 00:26:19 +00001507 frame,
1508 expr_value_sp,
1509 options.ref());
1510 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
Greg Claytonfb6621e2013-12-06 21:59:52 +00001511
1512 if (target->GetDisplayExpressionsInCrashlogs())
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001513 Host::SetCrashDescription(nullptr);
Jim Ingham7730b9a2012-11-29 00:26:19 +00001514 }
1515 else
1516 {
1517 if (log)
1518 log->Printf ("SBFrame::EvaluateExpression () => error: could not reconstruct frame object for this SBFrame.");
1519 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001520 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001521 else
1522 {
1523 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001524 log->Printf ("SBFrame::EvaluateExpression () => error: process is running");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001525 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00001526 }
Jason Molendacf7e2dc2012-02-21 05:33:55 +00001527
1528#ifndef LLDB_DISABLE_PYTHON
Sean Callanana162eba2010-12-07 22:55:01 +00001529 if (expr_log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001530 expr_log->Printf("** [SBFrame::EvaluateExpression] Expression result is %s, summary %s **",
1531 expr_result.GetValue(), expr_result.GetSummary());
1532
Greg Clayton48381312010-10-30 04:51:46 +00001533 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001534 log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)",
1535 static_cast<void*>(frame), expr,
1536 static_cast<void*>(expr_value_sp.get()), exe_results);
Jason Molendacf7e2dc2012-02-21 05:33:55 +00001537#endif
Greg Clayton48381312010-10-30 04:51:46 +00001538
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001539 return expr_result;
Greg Clayton1d3afba2010-10-05 00:00:42 +00001540}
Greg Clayton316d4982011-06-18 20:06:08 +00001541
1542bool
Oleksiy Vyalov6345fe32015-06-24 18:35:36 +00001543SBFrame::IsInlined()
Greg Clayton316d4982011-06-18 20:06:08 +00001544{
Oleksiy Vyalov05f75e92015-06-25 17:41:41 +00001545 return static_cast<const SBFrame*>(this)->IsInlined();
1546}
1547
1548bool
1549SBFrame::IsInlined() const
1550{
Greg Clayton5160ce52013-03-27 23:08:40 +00001551 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001552 ExecutionContext exe_ctx(m_opaque_sp.get());
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001553 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +00001554 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +00001555 Process *process = exe_ctx.GetProcessPtr();
1556 if (target && process)
Greg Clayton316d4982011-06-18 20:06:08 +00001557 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001558 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001559 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001560 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001561 frame = exe_ctx.GetFramePtr();
1562 if (frame)
1563 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001564
Jim Ingham7730b9a2012-11-29 00:26:19 +00001565 Block *block = frame->GetSymbolContext(eSymbolContextBlock).block;
1566 if (block)
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001567 return block->GetContainingInlinedBlock() != nullptr;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001568 }
1569 else
1570 {
1571 if (log)
1572 log->Printf ("SBFrame::IsInlined () => error: could not reconstruct frame object for this SBFrame.");
1573 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001574 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001575 else
1576 {
Greg Claytonc9858e42012-04-06 02:17:47 +00001577 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001578 log->Printf ("SBFrame::IsInlined () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +00001579 }
1580
Greg Clayton316d4982011-06-18 20:06:08 +00001581 }
1582 return false;
1583}
1584
1585const char *
Oleksiy Vyalov6345fe32015-06-24 18:35:36 +00001586SBFrame::GetFunctionName()
Greg Clayton316d4982011-06-18 20:06:08 +00001587{
Oleksiy Vyalov05f75e92015-06-25 17:41:41 +00001588 return static_cast<const SBFrame*>(this)->GetFunctionName();
1589}
1590
1591const char *
1592SBFrame::GetFunctionName() const
1593{
Greg Clayton5160ce52013-03-27 23:08:40 +00001594 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001595 const char *name = nullptr;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001596 ExecutionContext exe_ctx(m_opaque_sp.get());
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001597 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +00001598 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +00001599 Process *process = exe_ctx.GetProcessPtr();
1600 if (target && process)
Greg Clayton316d4982011-06-18 20:06:08 +00001601 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001602 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001603 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton316d4982011-06-18 20:06:08 +00001604 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001605 frame = exe_ctx.GetFramePtr();
1606 if (frame)
Greg Clayton316d4982011-06-18 20:06:08 +00001607 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001608 SymbolContext sc (frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol));
1609 if (sc.block)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001610 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001611 Block *inlined_block = sc.block->GetContainingInlinedBlock ();
1612 if (inlined_block)
1613 {
1614 const InlineFunctionInfo* inlined_info = inlined_block->GetInlinedFunctionInfo();
Greg Claytonddaf6a72015-07-08 22:32:23 +00001615 name = inlined_info->GetName(sc.function->GetLanguage()).AsCString();
Jim Ingham7730b9a2012-11-29 00:26:19 +00001616 }
1617 }
1618
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001619 if (name == nullptr)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001620 {
1621 if (sc.function)
1622 name = sc.function->GetName().GetCString();
1623 }
1624
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001625 if (name == nullptr)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001626 {
1627 if (sc.symbol)
1628 name = sc.symbol->GetName().GetCString();
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001629 }
Greg Clayton316d4982011-06-18 20:06:08 +00001630 }
Jim Ingham7730b9a2012-11-29 00:26:19 +00001631 else
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001632 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001633 if (log)
1634 log->Printf ("SBFrame::GetFunctionName () => error: could not reconstruct frame object for this SBFrame.");
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001635 }
Greg Clayton316d4982011-06-18 20:06:08 +00001636 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001637 else
1638 {
Greg Claytonc9858e42012-04-06 02:17:47 +00001639 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001640 log->Printf ("SBFrame::GetFunctionName() => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +00001641
1642 }
Greg Clayton316d4982011-06-18 20:06:08 +00001643 }
1644 return name;
1645}
Enrico Granatac1f705c2015-07-06 18:28:46 +00001646
1647const char *
1648SBFrame::GetDisplayFunctionName()
1649{
1650 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001651 const char *name = nullptr;
Enrico Granatac1f705c2015-07-06 18:28:46 +00001652 ExecutionContext exe_ctx(m_opaque_sp.get());
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001653 StackFrame *frame = nullptr;
Enrico Granatac1f705c2015-07-06 18:28:46 +00001654 Target *target = exe_ctx.GetTargetPtr();
1655 Process *process = exe_ctx.GetProcessPtr();
1656 if (target && process)
1657 {
1658 Process::StopLocker stop_locker;
1659 if (stop_locker.TryLock(&process->GetRunLock()))
1660 {
1661 frame = exe_ctx.GetFramePtr();
1662 if (frame)
1663 {
1664 SymbolContext sc (frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol));
1665 if (sc.block)
1666 {
1667 Block *inlined_block = sc.block->GetContainingInlinedBlock ();
1668 if (inlined_block)
1669 {
1670 const InlineFunctionInfo* inlined_info = inlined_block->GetInlinedFunctionInfo();
Greg Claytonddaf6a72015-07-08 22:32:23 +00001671 name = inlined_info->GetDisplayName(sc.function->GetLanguage()).AsCString();
Enrico Granatac1f705c2015-07-06 18:28:46 +00001672 }
1673 }
1674
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001675 if (name == nullptr)
Enrico Granatac1f705c2015-07-06 18:28:46 +00001676 {
1677 if (sc.function)
1678 name = sc.function->GetDisplayName().GetCString();
1679 }
1680
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001681 if (name == nullptr)
Enrico Granatac1f705c2015-07-06 18:28:46 +00001682 {
1683 if (sc.symbol)
1684 name = sc.symbol->GetDisplayName().GetCString();
1685 }
1686 }
1687 else
1688 {
1689 if (log)
1690 log->Printf ("SBFrame::GetDisplayFunctionName () => error: could not reconstruct frame object for this SBFrame.");
1691 }
1692 }
1693 else
1694 {
1695 if (log)
1696 log->Printf ("SBFrame::GetDisplayFunctionName() => error: process is running");
1697
1698 }
1699 }
1700 return name;
1701}