blob: cdf5a5a2a7698f8e4865464839782b0cd958c412 [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>
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +000013#include <string>
14
15// Other libraries and framework includes
16// Project includes
17#include "lldb/API/SBFrame.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000018
19#include "lldb/lldb-types.h"
20
21#include "lldb/Core/Address.h"
22#include "lldb/Core/ConstString.h"
Caroline Ticeceb6b132010-10-26 03:11:13 +000023#include "lldb/Core/Log.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000024#include "lldb/Core/Stream.h"
25#include "lldb/Core/StreamFile.h"
26#include "lldb/Core/ValueObjectRegister.h"
27#include "lldb/Core/ValueObjectVariable.h"
Sean Callanan4dbb2712015-09-25 20:35:58 +000028#include "Plugins/ExpressionParser/Clang/ClangPersistentVariables.h"
Jim Ingham151c0322015-09-15 21:13:50 +000029#include "lldb/Expression/UserExpression.h"
Greg Clayton1ba7c4d2011-06-25 04:35:01 +000030#include "lldb/Host/Host.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000031#include "lldb/Symbol/Block.h"
Greg Clayton1f746072012-08-29 21:13:06 +000032#include "lldb/Symbol/Function.h"
33#include "lldb/Symbol/Symbol.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000034#include "lldb/Symbol/SymbolContext.h"
35#include "lldb/Symbol/VariableList.h"
36#include "lldb/Symbol/Variable.h"
37#include "lldb/Target/ExecutionContext.h"
38#include "lldb/Target/Target.h"
39#include "lldb/Target/Process.h"
40#include "lldb/Target/RegisterContext.h"
Jason Molendab57e4a12013-11-04 09:33:30 +000041#include "lldb/Target/StackFrame.h"
Greg Claytonb9556ac2012-01-30 07:41:31 +000042#include "lldb/Target/StackID.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000043#include "lldb/Target/Thread.h"
44
Eli Friedman4c5de692010-06-09 07:44:37 +000045#include "lldb/API/SBDebugger.h"
46#include "lldb/API/SBValue.h"
47#include "lldb/API/SBAddress.h"
Jim Ingham35e1bda2012-10-16 21:41:58 +000048#include "lldb/API/SBExpressionOptions.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000049#include "lldb/API/SBStream.h"
Eli Friedman4c5de692010-06-09 07:44:37 +000050#include "lldb/API/SBSymbolContext.h"
51#include "lldb/API/SBThread.h"
Zachary Turner51f96ee2015-02-17 17:55:50 +000052#include "lldb/API/SBVariablesOptions.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000053
54using namespace lldb;
55using namespace lldb_private;
56
57SBFrame::SBFrame () :
Greg Clayton7fdf9ef2012-04-05 16:12:35 +000058 m_opaque_sp (new ExecutionContextRef())
Chris Lattner30fdc8d2010-06-08 16:52:24 +000059{
60}
61
Jason Molendab57e4a12013-11-04 09:33:30 +000062SBFrame::SBFrame (const StackFrameSP &lldb_object_sp) :
Greg Clayton7fdf9ef2012-04-05 16:12:35 +000063 m_opaque_sp (new ExecutionContextRef (lldb_object_sp))
Chris Lattner30fdc8d2010-06-08 16:52:24 +000064{
Greg Clayton5160ce52013-03-27 23:08:40 +000065 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +000066
67 if (log)
68 {
69 SBStream sstr;
70 GetDescription (sstr);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000071 log->Printf ("SBFrame::SBFrame (sp=%p) => SBFrame(%p): %s",
72 static_cast<void*>(lldb_object_sp.get()),
73 static_cast<void*>(lldb_object_sp.get()), sstr.GetData());
Caroline Ticeceb6b132010-10-26 03:11:13 +000074 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000075}
76
Greg Claytonefabb122010-11-05 23:17:00 +000077SBFrame::SBFrame(const SBFrame &rhs) :
Greg Clayton7fdf9ef2012-04-05 16:12:35 +000078 m_opaque_sp (new ExecutionContextRef (*rhs.m_opaque_sp))
Greg Claytonefabb122010-11-05 23:17:00 +000079{
80}
81
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +000082SBFrame::~SBFrame() = default;
83
Greg Claytonefabb122010-11-05 23:17:00 +000084const SBFrame &
85SBFrame::operator = (const SBFrame &rhs)
86{
87 if (this != &rhs)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +000088 *m_opaque_sp = *rhs.m_opaque_sp;
Greg Claytonefabb122010-11-05 23:17:00 +000089 return *this;
90}
91
Jason Molendab57e4a12013-11-04 09:33:30 +000092StackFrameSP
Greg Claytonb9556ac2012-01-30 07:41:31 +000093SBFrame::GetFrameSP() const
Chris Lattner30fdc8d2010-06-08 16:52:24 +000094{
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +000095 return (m_opaque_sp ? m_opaque_sp->GetFrameSP() : StackFrameSP());
Chris Lattner30fdc8d2010-06-08 16:52:24 +000096}
97
Greg Claytonb9556ac2012-01-30 07:41:31 +000098void
Jason Molendab57e4a12013-11-04 09:33:30 +000099SBFrame::SetFrameSP (const StackFrameSP &lldb_object_sp)
Greg Claytonb9556ac2012-01-30 07:41:31 +0000100{
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000101 return m_opaque_sp->SetFrameSP(lldb_object_sp);
Greg Claytonb9556ac2012-01-30 07:41:31 +0000102}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000103
104bool
105SBFrame::IsValid() const
106{
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000107 return GetFrameSP().get() != nullptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000108}
109
110SBSymbolContext
111SBFrame::GetSymbolContext (uint32_t resolve_scope) const
112{
Greg Clayton5160ce52013-03-27 23:08:40 +0000113 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000114 SBSymbolContext sb_sym_ctx;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000115 Mutex::Locker api_locker;
116 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
117
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000118 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +0000119 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000120 Process *process = exe_ctx.GetProcessPtr();
121 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000122 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000123 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000124 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000125 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000126 frame = exe_ctx.GetFramePtr();
127 if (frame)
128 {
129 sb_sym_ctx.SetSymbolContext(&frame->GetSymbolContext (resolve_scope));
130 }
131 else
132 {
133 if (log)
134 log->Printf ("SBFrame::GetVariables () => error: could not reconstruct frame object for this SBFrame.");
135 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000136 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000137 else
138 {
139 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000140 log->Printf ("SBFrame::GetSymbolContext () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000141 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000142 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000143
144 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000145 log->Printf ("SBFrame(%p)::GetSymbolContext (resolve_scope=0x%8.8x) => SBSymbolContext(%p)",
146 static_cast<void*>(frame), resolve_scope,
147 static_cast<void*>(sb_sym_ctx.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000148
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000149 return sb_sym_ctx;
150}
151
152SBModule
153SBFrame::GetModule () const
154{
Greg Clayton5160ce52013-03-27 23:08:40 +0000155 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton72eff182010-12-14 04:58:53 +0000156 SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +0000157 ModuleSP module_sp;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000158 Mutex::Locker api_locker;
159 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
160
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000161 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +0000162 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000163 Process *process = exe_ctx.GetProcessPtr();
164 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000165 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000166 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000167 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000168 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000169 frame = exe_ctx.GetFramePtr();
170 if (frame)
171 {
172 module_sp = frame->GetSymbolContext (eSymbolContextModule).module_sp;
173 sb_module.SetSP (module_sp);
174 }
175 else
176 {
177 if (log)
178 log->Printf ("SBFrame::GetModule () => error: could not reconstruct frame object for this SBFrame.");
179 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000180 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000181 else
182 {
183 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000184 log->Printf ("SBFrame::GetModule () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000185 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000186 }
Greg Clayton72eff182010-12-14 04:58:53 +0000187
Greg Clayton48381312010-10-30 04:51:46 +0000188 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000189 log->Printf ("SBFrame(%p)::GetModule () => SBModule(%p)",
190 static_cast<void*>(frame),
191 static_cast<void*>(module_sp.get()));
Greg Clayton48381312010-10-30 04:51:46 +0000192
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000193 return sb_module;
194}
195
196SBCompileUnit
197SBFrame::GetCompileUnit () const
198{
Greg Clayton5160ce52013-03-27 23:08:40 +0000199 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton72eff182010-12-14 04:58:53 +0000200 SBCompileUnit sb_comp_unit;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000201 Mutex::Locker api_locker;
202 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
203
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000204 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +0000205 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000206 Process *process = exe_ctx.GetProcessPtr();
207 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000208 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000209 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000210 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000211 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000212 frame = exe_ctx.GetFramePtr();
213 if (frame)
214 {
215 sb_comp_unit.reset (frame->GetSymbolContext (eSymbolContextCompUnit).comp_unit);
216 }
217 else
218 {
219 if (log)
220 log->Printf ("SBFrame::GetCompileUnit () => error: could not reconstruct frame object for this SBFrame.");
221 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000222 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000223 else
224 {
225 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000226 log->Printf ("SBFrame::GetCompileUnit () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000227 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000228 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000229 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000230 log->Printf ("SBFrame(%p)::GetCompileUnit () => SBCompileUnit(%p)",
231 static_cast<void*>(frame),
232 static_cast<void*>(sb_comp_unit.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000233
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000234 return sb_comp_unit;
235}
236
237SBFunction
238SBFrame::GetFunction () const
239{
Greg Clayton5160ce52013-03-27 23:08:40 +0000240 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton72eff182010-12-14 04:58:53 +0000241 SBFunction sb_function;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000242 Mutex::Locker api_locker;
243 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
244
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000245 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +0000246 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000247 Process *process = exe_ctx.GetProcessPtr();
248 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000249 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000250 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000251 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000252 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000253 frame = exe_ctx.GetFramePtr();
254 if (frame)
255 {
256 sb_function.reset(frame->GetSymbolContext (eSymbolContextFunction).function);
257 }
258 else
259 {
260 if (log)
261 log->Printf ("SBFrame::GetFunction () => error: could not reconstruct frame object for this SBFrame.");
262 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000263 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000264 else
265 {
266 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000267 log->Printf ("SBFrame::GetFunction () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000268 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000269 }
Greg Clayton48381312010-10-30 04:51:46 +0000270 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000271 log->Printf ("SBFrame(%p)::GetFunction () => SBFunction(%p)",
272 static_cast<void*>(frame),
273 static_cast<void*>(sb_function.get()));
Greg Clayton48381312010-10-30 04:51:46 +0000274
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000275 return sb_function;
276}
277
Greg Clayton3b065572010-10-04 18:37:52 +0000278SBSymbol
279SBFrame::GetSymbol () const
280{
Greg Clayton5160ce52013-03-27 23:08:40 +0000281 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton72eff182010-12-14 04:58:53 +0000282 SBSymbol sb_symbol;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000283 Mutex::Locker api_locker;
284 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
285
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000286 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +0000287 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000288 Process *process = exe_ctx.GetProcessPtr();
289 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000290 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000291 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000292 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000293 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000294 frame = exe_ctx.GetFramePtr();
295 if (frame)
296 {
297 sb_symbol.reset(frame->GetSymbolContext (eSymbolContextSymbol).symbol);
298 }
299 else
300 {
301 if (log)
302 log->Printf ("SBFrame::GetSymbol () => error: could not reconstruct frame object for this SBFrame.");
303 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000304 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000305 else
306 {
307 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000308 log->Printf ("SBFrame::GetSymbol () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000309 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000310 }
Greg Clayton48381312010-10-30 04:51:46 +0000311 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000312 log->Printf ("SBFrame(%p)::GetSymbol () => SBSymbol(%p)",
313 static_cast<void*>(frame),
314 static_cast<void*>(sb_symbol.get()));
Greg Clayton3b065572010-10-04 18:37:52 +0000315 return sb_symbol;
316}
317
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000318SBBlock
319SBFrame::GetBlock () const
320{
Greg Clayton5160ce52013-03-27 23:08:40 +0000321 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton72eff182010-12-14 04:58:53 +0000322 SBBlock sb_block;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000323 Mutex::Locker api_locker;
324 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
325
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000326 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +0000327 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000328 Process *process = exe_ctx.GetProcessPtr();
329 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000330 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000331 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000332 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000333 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000334 frame = exe_ctx.GetFramePtr();
335 if (frame)
336 {
337 sb_block.SetPtr (frame->GetSymbolContext (eSymbolContextBlock).block);
338 }
339 else
340 {
341 if (log)
342 log->Printf ("SBFrame::GetBlock () => error: could not reconstruct frame object for this SBFrame.");
343 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000344 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000345 else
346 {
347 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000348 log->Printf ("SBFrame(%p)::GetBlock () => error: process is running",
349 static_cast<void*>(frame));
Greg Claytonc9858e42012-04-06 02:17:47 +0000350 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000351 }
Greg Clayton48381312010-10-30 04:51:46 +0000352 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000353 log->Printf ("SBFrame(%p)::GetBlock () => SBBlock(%p)",
354 static_cast<void*>(frame),
355 static_cast<void*>(sb_block.GetPtr()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000356 return sb_block;
357}
358
Greg Clayton95897c62010-09-07 04:20:48 +0000359SBBlock
360SBFrame::GetFrameBlock () const
361{
Greg Clayton72eff182010-12-14 04:58:53 +0000362 SBBlock sb_block;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000363 Mutex::Locker api_locker;
364 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
365
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000366 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +0000367 Target *target = exe_ctx.GetTargetPtr();
Greg Clayton5160ce52013-03-27 23:08:40 +0000368 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham7730b9a2012-11-29 00:26:19 +0000369 Process *process = exe_ctx.GetProcessPtr();
370 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000371 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000372 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000373 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000374 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000375 frame = exe_ctx.GetFramePtr();
376 if (frame)
377 {
378 sb_block.SetPtr(frame->GetFrameBlock ());
379 }
380 else
381 {
382 if (log)
383 log->Printf ("SBFrame::GetFrameBlock () => error: could not reconstruct frame object for this SBFrame.");
384 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000385 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000386 else
387 {
388 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000389 log->Printf ("SBFrame::GetFrameBlock () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000390 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000391 }
Greg Clayton48381312010-10-30 04:51:46 +0000392 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000393 log->Printf ("SBFrame(%p)::GetFrameBlock () => SBBlock(%p)",
394 static_cast<void*>(frame),
395 static_cast<void*>(sb_block.GetPtr()));
Greg Clayton95897c62010-09-07 04:20:48 +0000396 return sb_block;
397}
398
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000399SBLineEntry
400SBFrame::GetLineEntry () const
401{
Greg Clayton5160ce52013-03-27 23:08:40 +0000402 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton72eff182010-12-14 04:58:53 +0000403 SBLineEntry sb_line_entry;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000404 Mutex::Locker api_locker;
405 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
406
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000407 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +0000408 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000409 Process *process = exe_ctx.GetProcessPtr();
410 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000411 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000412 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000413 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000414 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000415 frame = exe_ctx.GetFramePtr();
416 if (frame)
417 {
418 sb_line_entry.SetLineEntry (frame->GetSymbolContext (eSymbolContextLineEntry).line_entry);
419 }
420 else
421 {
422 if (log)
423 log->Printf ("SBFrame::GetLineEntry () => error: could not reconstruct frame object for this SBFrame.");
424 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000425 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000426 else
427 {
428 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000429 log->Printf ("SBFrame::GetLineEntry () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000430 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000431 }
Greg Clayton48381312010-10-30 04:51:46 +0000432 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000433 log->Printf ("SBFrame(%p)::GetLineEntry () => SBLineEntry(%p)",
434 static_cast<void*>(frame),
435 static_cast<void*>(sb_line_entry.get()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000436 return sb_line_entry;
437}
438
439uint32_t
440SBFrame::GetFrameID () const
441{
Greg Claytonb9556ac2012-01-30 07:41:31 +0000442 uint32_t frame_idx = UINT32_MAX;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000443
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000444 ExecutionContext exe_ctx(m_opaque_sp.get());
Jason Molendab57e4a12013-11-04 09:33:30 +0000445 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000446 if (frame)
Greg Claytond9e416c2012-02-18 05:35:26 +0000447 frame_idx = frame->GetFrameIndex ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000448
Greg Clayton5160ce52013-03-27 23:08:40 +0000449 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000450 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000451 log->Printf ("SBFrame(%p)::GetFrameID () => %u",
452 static_cast<void*>(frame), frame_idx);
Greg Clayton48381312010-10-30 04:51:46 +0000453 return frame_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000454}
455
Greg Clayton424a5db2015-05-28 03:27:22 +0000456lldb::addr_t
457SBFrame::GetCFA () const
458{
459 ExecutionContext exe_ctx(m_opaque_sp.get());
460 StackFrame *frame = exe_ctx.GetFramePtr();
461 if (frame)
462 return frame->GetStackID().GetCallFrameAddress();
463 return LLDB_INVALID_ADDRESS;
464}
465
Greg Clayton69b582f2010-12-14 18:39:31 +0000466addr_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000467SBFrame::GetPC () const
468{
Greg Clayton5160ce52013-03-27 23:08:40 +0000469 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton69b582f2010-12-14 18:39:31 +0000470 addr_t addr = LLDB_INVALID_ADDRESS;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000471 Mutex::Locker api_locker;
472 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
473
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000474 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +0000475 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000476 Process *process = exe_ctx.GetProcessPtr();
477 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000478 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000479 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000480 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000481 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000482 frame = exe_ctx.GetFramePtr();
483 if (frame)
484 {
Tamas Berghammer25b9f7e2015-09-07 09:58:09 +0000485 addr = frame->GetFrameCodeAddress().GetOpcodeLoadAddress (target, eAddressClassCode);
Jim Ingham7730b9a2012-11-29 00:26:19 +0000486 }
487 else
488 {
489 if (log)
490 log->Printf ("SBFrame::GetPC () => error: could not reconstruct frame object for this SBFrame.");
491 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000492 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000493 else
494 {
495 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000496 log->Printf ("SBFrame::GetPC () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000497 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000498 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000499
500 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000501 log->Printf ("SBFrame(%p)::GetPC () => 0x%" PRIx64,
502 static_cast<void*>(frame), addr);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000503
504 return addr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000505}
506
507bool
Greg Clayton69b582f2010-12-14 18:39:31 +0000508SBFrame::SetPC (addr_t new_pc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000509{
Greg Clayton5160ce52013-03-27 23:08:40 +0000510 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000511 bool ret_val = false;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000512 Mutex::Locker api_locker;
513 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
514
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000515 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +0000516 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000517 Process *process = exe_ctx.GetProcessPtr();
518 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000519 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000520 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000521 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000522 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000523 frame = exe_ctx.GetFramePtr();
524 if (frame)
525 {
526 ret_val = frame->GetRegisterContext()->SetPC (new_pc);
527 }
528 else
529 {
530 if (log)
531 log->Printf ("SBFrame::SetPC () => error: could not reconstruct frame object for this SBFrame.");
532 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000533 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000534 else
535 {
536 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000537 log->Printf ("SBFrame::SetPC () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000538 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000539 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000540
541 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +0000542 log->Printf ("SBFrame(%p)::SetPC (new_pc=0x%" PRIx64 ") => %i",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000543 static_cast<void*>(frame), new_pc, ret_val);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000544
545 return ret_val;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000546}
547
Greg Clayton69b582f2010-12-14 18:39:31 +0000548addr_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000549SBFrame::GetSP () const
550{
Greg Clayton5160ce52013-03-27 23:08:40 +0000551 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000552 addr_t addr = LLDB_INVALID_ADDRESS;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000553 Mutex::Locker api_locker;
554 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
555
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000556 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +0000557 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000558 Process *process = exe_ctx.GetProcessPtr();
559 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000560 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000561 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000562 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000563 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000564 frame = exe_ctx.GetFramePtr();
565 if (frame)
566 {
567 addr = frame->GetRegisterContext()->GetSP();
568 }
569 else
570 {
571 if (log)
572 log->Printf ("SBFrame::GetSP () => error: could not reconstruct frame object for this SBFrame.");
573 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000574 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000575 else
576 {
577 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000578 log->Printf ("SBFrame::GetSP () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000579 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000580 }
Greg Clayton48381312010-10-30 04:51:46 +0000581 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000582 log->Printf ("SBFrame(%p)::GetSP () => 0x%" PRIx64,
583 static_cast<void*>(frame), addr);
Greg Clayton48381312010-10-30 04:51:46 +0000584
585 return addr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000586}
587
Greg Clayton69b582f2010-12-14 18:39:31 +0000588addr_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000589SBFrame::GetFP () const
590{
Greg Clayton5160ce52013-03-27 23:08:40 +0000591 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton69b582f2010-12-14 18:39:31 +0000592 addr_t addr = LLDB_INVALID_ADDRESS;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000593 Mutex::Locker api_locker;
594 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
595
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000596 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +0000597 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000598 Process *process = exe_ctx.GetProcessPtr();
599 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000600 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000601 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000602 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000603 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000604 frame = exe_ctx.GetFramePtr();
605 if (frame)
606 {
607 addr = frame->GetRegisterContext()->GetFP();
608 }
609 else
610 {
611 if (log)
612 log->Printf ("SBFrame::GetFP () => error: could not reconstruct frame object for this SBFrame.");
613 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000614 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000615 else
616 {
617 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000618 log->Printf ("SBFrame::GetFP () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000619 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000620 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000621
622 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000623 log->Printf ("SBFrame(%p)::GetFP () => 0x%" PRIx64,
624 static_cast<void*>(frame), addr);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000625 return addr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000626}
627
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000628SBAddress
629SBFrame::GetPCAddress () const
630{
Greg Clayton5160ce52013-03-27 23:08:40 +0000631 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000632 SBAddress sb_addr;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000633 Mutex::Locker api_locker;
634 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
635
Jason Molendab57e4a12013-11-04 09:33:30 +0000636 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Claytond9e416c2012-02-18 05:35:26 +0000637 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000638 Process *process = exe_ctx.GetProcessPtr();
639 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000640 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000641 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000642 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000643 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000644 frame = exe_ctx.GetFramePtr();
645 if (frame)
646 {
647 sb_addr.SetAddress (&frame->GetFrameCodeAddress());
648 }
649 else
650 {
651 if (log)
652 log->Printf ("SBFrame::GetPCAddress () => error: could not reconstruct frame object for this SBFrame.");
653 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000654 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000655 else
656 {
657 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000658 log->Printf ("SBFrame::GetPCAddress () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000659 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000660 }
Greg Clayton48381312010-10-30 04:51:46 +0000661 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000662 log->Printf ("SBFrame(%p)::GetPCAddress () => SBAddress(%p)",
663 static_cast<void*>(frame),
664 static_cast<void*>(sb_addr.get()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000665 return sb_addr;
666}
667
668void
669SBFrame::Clear()
670{
Greg Claytonaf2589e2012-04-12 20:58:26 +0000671 m_opaque_sp->Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000672}
673
Greg Clayton7edbdfc2012-02-03 07:02:37 +0000674lldb::SBValue
675SBFrame::GetValueForVariablePath (const char *var_path)
676{
677 SBValue sb_value;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000678 ExecutionContext exe_ctx(m_opaque_sp.get());
Jason Molendab57e4a12013-11-04 09:33:30 +0000679 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Claytond9e416c2012-02-18 05:35:26 +0000680 Target *target = exe_ctx.GetTargetPtr();
681 if (frame && target)
Greg Clayton7edbdfc2012-02-03 07:02:37 +0000682 {
Greg Claytonc9858e42012-04-06 02:17:47 +0000683 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
684 sb_value = GetValueForVariablePath (var_path, use_dynamic);
Greg Clayton7edbdfc2012-02-03 07:02:37 +0000685 }
686 return sb_value;
687}
688
689lldb::SBValue
690SBFrame::GetValueForVariablePath (const char *var_path, DynamicValueType use_dynamic)
691{
692 SBValue sb_value;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000693 Mutex::Locker api_locker;
Greg Clayton5160ce52013-03-27 23:08:40 +0000694 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000695 if (var_path == nullptr || var_path[0] == '\0')
Jim Ingham7730b9a2012-11-29 00:26:19 +0000696 {
697 if (log)
698 log->Printf ("SBFrame::GetValueForVariablePath called with empty variable path.");
699 return sb_value;
700 }
701
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000702 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
703
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000704 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +0000705 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000706 Process *process = exe_ctx.GetProcessPtr();
707 if (target && process)
Greg Clayton7edbdfc2012-02-03 07:02:37 +0000708 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000709 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000710 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000711 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000712 frame = exe_ctx.GetFramePtr();
713 if (frame)
714 {
715 VariableSP var_sp;
716 Error error;
717 ValueObjectSP value_sp (frame->GetValueForVariableExpressionPath (var_path,
718 eNoDynamicValues,
Jason Molendab57e4a12013-11-04 09:33:30 +0000719 StackFrame::eExpressionPathOptionCheckPtrVsMember | StackFrame::eExpressionPathOptionsAllowDirectIVarAccess,
Jim Ingham7730b9a2012-11-29 00:26:19 +0000720 var_sp,
721 error));
722 sb_value.SetSP(value_sp, use_dynamic);
723 }
724 else
725 {
726 if (log)
727 log->Printf ("SBFrame::GetValueForVariablePath () => error: could not reconstruct frame object for this SBFrame.");
728 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000729 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000730 else
731 {
Greg Claytonc9858e42012-04-06 02:17:47 +0000732 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000733 log->Printf ("SBFrame::GetValueForVariablePath () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000734 }
Greg Clayton7edbdfc2012-02-03 07:02:37 +0000735 }
736 return sb_value;
737}
738
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000739SBValue
Greg Clayton69b582f2010-12-14 18:39:31 +0000740SBFrame::FindVariable (const char *name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000741{
Greg Clayton316d4982011-06-18 20:06:08 +0000742 SBValue value;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000743 ExecutionContext exe_ctx(m_opaque_sp.get());
Jason Molendab57e4a12013-11-04 09:33:30 +0000744 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Claytond9e416c2012-02-18 05:35:26 +0000745 Target *target = exe_ctx.GetTargetPtr();
746 if (frame && target)
Greg Clayton316d4982011-06-18 20:06:08 +0000747 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000748 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton316d4982011-06-18 20:06:08 +0000749 value = FindVariable (name, use_dynamic);
750 }
751 return value;
Jim Ingham78a685a2011-04-16 00:01:13 +0000752}
753
754SBValue
Jim Ingham2837b762011-05-04 03:43:18 +0000755SBFrame::FindVariable (const char *name, lldb::DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +0000756{
Greg Clayton5160ce52013-03-27 23:08:40 +0000757 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton69b582f2010-12-14 18:39:31 +0000758 VariableSP var_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +0000759 SBValue sb_value;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000760
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000761 if (name == nullptr || name[0] == '\0')
Jim Ingham7730b9a2012-11-29 00:26:19 +0000762 {
763 if (log)
764 log->Printf ("SBFrame::FindVariable called with empty name");
765 return sb_value;
766 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000767
Greg Clayton81e871e2012-02-04 02:27:34 +0000768 ValueObjectSP value_sp;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000769 Mutex::Locker api_locker;
770 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
771
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000772 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +0000773 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000774 Process *process = exe_ctx.GetProcessPtr();
775 if (target && process)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000776 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000777 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000778 if (stop_locker.TryLock(&process->GetRunLock()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000779 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000780 frame = exe_ctx.GetFramePtr();
781 if (frame)
Greg Clayton72eff182010-12-14 04:58:53 +0000782 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000783 VariableList variable_list;
784 SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock));
785
786 if (sc.block)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000787 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000788 const bool can_create = true;
789 const bool get_parent_variables = true;
790 const bool stop_if_block_is_inlined_function = true;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000791
Tamas Berghammer72ac8a82016-02-25 12:23:37 +0000792 if (sc.block->AppendVariables (can_create,
Jim Ingham7730b9a2012-11-29 00:26:19 +0000793 get_parent_variables,
794 stop_if_block_is_inlined_function,
Tamas Berghammer72ac8a82016-02-25 12:23:37 +0000795 [frame](Variable* v) { return v->IsInScope(frame); },
Jim Ingham7730b9a2012-11-29 00:26:19 +0000796 &variable_list))
797 {
798 var_sp = variable_list.FindVariable (ConstString(name));
799 }
800 }
801
802 if (var_sp)
803 {
804 value_sp = frame->GetValueObjectForFrameVariable(var_sp, eNoDynamicValues);
805 sb_value.SetSP(value_sp, use_dynamic);
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000806 }
807 }
Jim Ingham7730b9a2012-11-29 00:26:19 +0000808 else
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000809 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000810 if (log)
811 log->Printf ("SBFrame::FindVariable () => error: could not reconstruct frame object for this SBFrame.");
Greg Clayton72eff182010-12-14 04:58:53 +0000812 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000813 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000814 else
815 {
816 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000817 log->Printf ("SBFrame::FindVariable () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000818 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000819 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000820
Greg Clayton48381312010-10-30 04:51:46 +0000821 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000822 log->Printf ("SBFrame(%p)::FindVariable (name=\"%s\") => SBValue(%p)",
823 static_cast<void*>(frame), name,
824 static_cast<void*>(value_sp.get()));
Greg Clayton48381312010-10-30 04:51:46 +0000825
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000826 return sb_value;
827}
828
829SBValue
Greg Clayton69b582f2010-12-14 18:39:31 +0000830SBFrame::FindValue (const char *name, ValueType value_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000831{
Greg Clayton316d4982011-06-18 20:06:08 +0000832 SBValue value;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000833 ExecutionContext exe_ctx(m_opaque_sp.get());
Jason Molendab57e4a12013-11-04 09:33:30 +0000834 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Claytond9e416c2012-02-18 05:35:26 +0000835 Target *target = exe_ctx.GetTargetPtr();
836 if (frame && target)
Greg Clayton316d4982011-06-18 20:06:08 +0000837 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000838 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton316d4982011-06-18 20:06:08 +0000839 value = FindValue (name, value_type, use_dynamic);
840 }
841 return value;
Jim Ingham78a685a2011-04-16 00:01:13 +0000842}
843
844SBValue
Jim Ingham2837b762011-05-04 03:43:18 +0000845SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +0000846{
Greg Clayton5160ce52013-03-27 23:08:40 +0000847 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton69b582f2010-12-14 18:39:31 +0000848 SBValue sb_value;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000849
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000850 if (name == nullptr || name[0] == '\0')
Jim Ingham7730b9a2012-11-29 00:26:19 +0000851 {
852 if (log)
853 log->Printf ("SBFrame::FindValue called with empty name.");
854 return sb_value;
855 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000856
Greg Clayton81e871e2012-02-04 02:27:34 +0000857 ValueObjectSP value_sp;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000858 Mutex::Locker api_locker;
859 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
860
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000861 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +0000862 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000863 Process *process = exe_ctx.GetProcessPtr();
864 if (target && process)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000865 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000866 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000867 if (stop_locker.TryLock(&process->GetRunLock()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000868 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000869 frame = exe_ctx.GetFramePtr();
870 if (frame)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000871 {
Enrico Granata8a2a0df2014-02-19 19:35:13 +0000872 VariableList variable_list;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000873
Jim Ingham7730b9a2012-11-29 00:26:19 +0000874 switch (value_type)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000875 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000876 case eValueTypeVariableGlobal: // global variable
877 case eValueTypeVariableStatic: // static variable
878 case eValueTypeVariableArgument: // function argument variables
879 case eValueTypeVariableLocal: // function local variables
880 {
Chaoren Lin0efb51a2015-03-19 22:00:13 +0000881 SymbolContext sc(frame->GetSymbolContext(eSymbolContextBlock));
Greg Clayton69b582f2010-12-14 18:39:31 +0000882
Jim Ingham7730b9a2012-11-29 00:26:19 +0000883 const bool can_create = true;
884 const bool get_parent_variables = true;
885 const bool stop_if_block_is_inlined_function = true;
Greg Clayton69b582f2010-12-14 18:39:31 +0000886
Chaoren Lin0efb51a2015-03-19 22:00:13 +0000887 if (sc.block)
888 sc.block->AppendVariables(can_create,
889 get_parent_variables,
890 stop_if_block_is_inlined_function,
Tamas Berghammer72ac8a82016-02-25 12:23:37 +0000891 [frame](Variable* v) { return v->IsInScope(frame); },
Chaoren Lin0efb51a2015-03-19 22:00:13 +0000892 &variable_list);
893 if (value_type == eValueTypeVariableGlobal)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000894 {
Chaoren Lin0efb51a2015-03-19 22:00:13 +0000895 const bool get_file_globals = true;
896 VariableList *frame_vars = frame->GetVariableList(get_file_globals);
897 if (frame_vars)
898 frame_vars->AppendVariablesIfUnique(variable_list);
899 }
900 ConstString const_name(name);
901 VariableSP variable_sp(variable_list.FindVariable(const_name, value_type));
902 if (variable_sp)
903 {
904 value_sp = frame->GetValueObjectForFrameVariable(variable_sp, eNoDynamicValues);
905 sb_value.SetSP(value_sp, use_dynamic);
Jim Ingham7730b9a2012-11-29 00:26:19 +0000906 }
907 }
908 break;
909
910 case eValueTypeRegister: // stack frame register value
911 {
912 RegisterContextSP reg_ctx (frame->GetRegisterContext());
913 if (reg_ctx)
914 {
915 const uint32_t num_regs = reg_ctx->GetRegisterCount();
916 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx)
917 {
918 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
919 if (reg_info &&
920 ((reg_info->name && strcasecmp (reg_info->name, name) == 0) ||
921 (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0)))
922 {
923 value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx);
924 sb_value.SetSP (value_sp);
925 break;
926 }
927 }
928 }
929 }
930 break;
931
932 case eValueTypeRegisterSet: // A collection of stack frame register values
933 {
934 RegisterContextSP reg_ctx (frame->GetRegisterContext());
935 if (reg_ctx)
936 {
937 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
938 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
939 {
940 const RegisterSet *reg_set = reg_ctx->GetRegisterSet (set_idx);
941 if (reg_set &&
942 ((reg_set->name && strcasecmp (reg_set->name, name) == 0) ||
943 (reg_set->short_name && strcasecmp (reg_set->short_name, name) == 0)))
944 {
945 value_sp = ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx);
946 sb_value.SetSP (value_sp);
947 break;
948 }
949 }
950 }
951 }
952 break;
953
954 case eValueTypeConstResult: // constant result variables
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000955 {
956 ConstString const_name(name);
Sean Callanan8f1f9a12015-09-30 19:57:57 +0000957 ExpressionVariableSP expr_var_sp (target->GetPersistentVariable (const_name));
Jim Ingham7730b9a2012-11-29 00:26:19 +0000958 if (expr_var_sp)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000959 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000960 value_sp = expr_var_sp->GetValueObject();
961 sb_value.SetSP (value_sp, use_dynamic);
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000962 }
963 }
Jim Ingham7730b9a2012-11-29 00:26:19 +0000964 break;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000965
Jim Ingham7730b9a2012-11-29 00:26:19 +0000966 default:
967 break;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000968 }
Jim Ingham7730b9a2012-11-29 00:26:19 +0000969 }
970 else
971 {
972 if (log)
973 log->Printf ("SBFrame::FindValue () => error: could not reconstruct frame object for this SBFrame.");
Greg Clayton69b582f2010-12-14 18:39:31 +0000974 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000975 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000976 else
977 {
978 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000979 log->Printf ("SBFrame::FindValue () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000980 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000981 }
Greg Clayton48381312010-10-30 04:51:46 +0000982
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000983 if (log)
984 log->Printf ("SBFrame(%p)::FindVariableInScope (name=\"%s\", value_type=%i) => SBValue(%p)",
985 static_cast<void*>(frame), name, value_type,
986 static_cast<void*>(value_sp.get()));
987
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000988 return sb_value;
989}
990
991bool
Johnny Chen35e2ab62012-03-05 19:53:24 +0000992SBFrame::IsEqual (const SBFrame &that) const
993{
Jason Molendab57e4a12013-11-04 09:33:30 +0000994 lldb::StackFrameSP this_sp = GetFrameSP();
995 lldb::StackFrameSP that_sp = that.GetFrameSP();
Johnny Chen35e2ab62012-03-05 19:53:24 +0000996 return (this_sp && that_sp && this_sp->GetStackID() == that_sp->GetStackID());
997}
998
999bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001000SBFrame::operator == (const SBFrame &rhs) const
1001{
Johnny Chen35e2ab62012-03-05 19:53:24 +00001002 return IsEqual(rhs);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001003}
1004
1005bool
1006SBFrame::operator != (const SBFrame &rhs) const
1007{
Johnny Chen35e2ab62012-03-05 19:53:24 +00001008 return !IsEqual(rhs);
Greg Clayton481cef22011-01-21 06:11:58 +00001009}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001010
1011SBThread
1012SBFrame::GetThread () const
1013{
Greg Clayton5160ce52013-03-27 23:08:40 +00001014 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001015
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001016 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Claytond9e416c2012-02-18 05:35:26 +00001017 ThreadSP thread_sp (exe_ctx.GetThreadSP());
1018 SBThread sb_thread (thread_sp);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001019
1020 if (log)
Caroline Tice750cd172010-10-26 23:49:36 +00001021 {
1022 SBStream sstr;
1023 sb_thread.GetDescription (sstr);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001024 log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s",
1025 static_cast<void*>(exe_ctx.GetFramePtr()),
1026 static_cast<void*>(thread_sp.get()), sstr.GetData());
Caroline Tice750cd172010-10-26 23:49:36 +00001027 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001028
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001029 return sb_thread;
1030}
1031
1032const char *
1033SBFrame::Disassemble () const
1034{
Greg Clayton5160ce52013-03-27 23:08:40 +00001035 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001036 const char *disassembly = nullptr;
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001037 Mutex::Locker api_locker;
1038 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1039
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001040 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +00001041 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +00001042 Process *process = exe_ctx.GetProcessPtr();
1043 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001044 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001045 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001046 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001047 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001048 frame = exe_ctx.GetFramePtr();
1049 if (frame)
1050 {
1051 disassembly = frame->Disassemble();
1052 }
1053 else
1054 {
1055 if (log)
1056 log->Printf ("SBFrame::Disassemble () => error: could not reconstruct frame object for this SBFrame.");
1057 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001058 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001059 else
1060 {
1061 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001062 log->Printf ("SBFrame::Disassemble () => error: process is running");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001063 }
Greg Claytonaf67cec2010-12-20 20:49:23 +00001064 }
Greg Clayton48381312010-10-30 04:51:46 +00001065
1066 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001067 log->Printf ("SBFrame(%p)::Disassemble () => %s",
1068 static_cast<void*>(frame), disassembly);
Greg Clayton48381312010-10-30 04:51:46 +00001069
1070 return disassembly;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001071}
1072
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001073SBValueList
1074SBFrame::GetVariables (bool arguments,
1075 bool locals,
1076 bool statics,
1077 bool in_scope_only)
1078{
Greg Clayton316d4982011-06-18 20:06:08 +00001079 SBValueList value_list;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001080 ExecutionContext exe_ctx(m_opaque_sp.get());
Jason Molendab57e4a12013-11-04 09:33:30 +00001081 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Claytond9e416c2012-02-18 05:35:26 +00001082 Target *target = exe_ctx.GetTargetPtr();
1083 if (frame && target)
Greg Clayton316d4982011-06-18 20:06:08 +00001084 {
Greg Claytond9e416c2012-02-18 05:35:26 +00001085 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
Zachary Turner51f96ee2015-02-17 17:55:50 +00001086 const bool include_runtime_support_values = target ? target->GetDisplayRuntimeSupportValues() : false;
1087
1088 SBVariablesOptions options;
1089 options.SetIncludeArguments(arguments);
1090 options.SetIncludeLocals(locals);
1091 options.SetIncludeStatics(statics);
1092 options.SetInScopeOnly(in_scope_only);
1093 options.SetIncludeRuntimeSupportValues(include_runtime_support_values);
1094 options.SetUseDynamic(use_dynamic);
1095
1096 value_list = GetVariables (options);
Greg Clayton316d4982011-06-18 20:06:08 +00001097 }
1098 return value_list;
Jim Ingham78a685a2011-04-16 00:01:13 +00001099}
1100
Enrico Granata560558e2015-02-11 02:35:39 +00001101lldb::SBValueList
1102SBFrame::GetVariables (bool arguments,
1103 bool locals,
1104 bool statics,
1105 bool in_scope_only,
1106 lldb::DynamicValueType use_dynamic)
1107{
1108 ExecutionContext exe_ctx(m_opaque_sp.get());
1109 Target *target = exe_ctx.GetTargetPtr();
Zachary Turner51f96ee2015-02-17 17:55:50 +00001110 const bool include_runtime_support_values = target ? target->GetDisplayRuntimeSupportValues() : false;
1111 SBVariablesOptions options;
1112 options.SetIncludeArguments(arguments);
1113 options.SetIncludeLocals(locals);
1114 options.SetIncludeStatics(statics);
1115 options.SetInScopeOnly(in_scope_only);
1116 options.SetIncludeRuntimeSupportValues(include_runtime_support_values);
1117 options.SetUseDynamic(use_dynamic);
1118 return GetVariables(options);
Enrico Granata560558e2015-02-11 02:35:39 +00001119}
1120
Jim Ingham78a685a2011-04-16 00:01:13 +00001121SBValueList
Zachary Turner51f96ee2015-02-17 17:55:50 +00001122SBFrame::GetVariables (const lldb::SBVariablesOptions& options)
Jim Ingham78a685a2011-04-16 00:01:13 +00001123{
Greg Clayton5160ce52013-03-27 23:08:40 +00001124 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001125
Greg Claytonb9556ac2012-01-30 07:41:31 +00001126 SBValueList value_list;
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001127 Mutex::Locker api_locker;
1128 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1129
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001130 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +00001131 Target *target = exe_ctx.GetTargetPtr();
Greg Claytonb9556ac2012-01-30 07:41:31 +00001132
Zachary Turner51f96ee2015-02-17 17:55:50 +00001133 const bool statics = options.GetIncludeStatics();
1134 const bool arguments = options.GetIncludeArguments();
1135 const bool locals = options.GetIncludeLocals();
1136 const bool in_scope_only = options.GetInScopeOnly();
1137 const bool include_runtime_support_values = options.GetIncludeRuntimeSupportValues();
1138 const lldb::DynamicValueType use_dynamic = options.GetUseDynamic();
1139
Caroline Ticeceb6b132010-10-26 03:11:13 +00001140 if (log)
Zachary Turner51f96ee2015-02-17 17:55:50 +00001141 log->Printf ("SBFrame::GetVariables (arguments=%i, locals=%i, statics=%i, in_scope_only=%i runtime=%i dynamic=%i)",
1142 arguments, locals,
1143 statics, in_scope_only,
1144 include_runtime_support_values, use_dynamic);
1145
Jim Ingham7730b9a2012-11-29 00:26:19 +00001146 Process *process = exe_ctx.GetProcessPtr();
1147 if (target && process)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001148 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001149 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001150 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001151 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001152 frame = exe_ctx.GetFramePtr();
1153 if (frame)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001154 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001155 size_t i;
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001156 VariableList *variable_list = nullptr;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001157 variable_list = frame->GetVariableList(true);
1158 if (variable_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001159 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001160 const size_t num_variables = variable_list->GetSize();
1161 if (num_variables)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001162 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001163 for (i = 0; i < num_variables; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001164 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001165 VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
1166 if (variable_sp)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001167 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001168 bool add_variable = false;
1169 switch (variable_sp->GetScope())
1170 {
1171 case eValueTypeVariableGlobal:
1172 case eValueTypeVariableStatic:
1173 add_variable = statics;
1174 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001175
Jim Ingham7730b9a2012-11-29 00:26:19 +00001176 case eValueTypeVariableArgument:
1177 add_variable = arguments;
1178 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001179
Jim Ingham7730b9a2012-11-29 00:26:19 +00001180 case eValueTypeVariableLocal:
1181 add_variable = locals;
1182 break;
Greg Claytonc982c762010-07-09 20:39:50 +00001183
Jim Ingham7730b9a2012-11-29 00:26:19 +00001184 default:
1185 break;
1186 }
1187 if (add_variable)
1188 {
1189 if (in_scope_only && !variable_sp->IsInScope(frame))
1190 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001191
Jim Ingham7730b9a2012-11-29 00:26:19 +00001192 ValueObjectSP valobj_sp(frame->GetValueObjectForFrameVariable (variable_sp, eNoDynamicValues));
Enrico Granata560558e2015-02-11 02:35:39 +00001193
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001194 if (!include_runtime_support_values &&
1195 valobj_sp != nullptr &&
1196 valobj_sp->IsRuntimeSupportValue())
Enrico Granata560558e2015-02-11 02:35:39 +00001197 continue;
1198
Jim Ingham7730b9a2012-11-29 00:26:19 +00001199 SBValue value_sb;
1200 value_sb.SetSP(valobj_sp,use_dynamic);
1201 value_list.Append(value_sb);
1202 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001203 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001204 }
1205 }
1206 }
1207 }
Jim Ingham7730b9a2012-11-29 00:26:19 +00001208 else
1209 {
1210 if (log)
1211 log->Printf ("SBFrame::GetVariables () => error: could not reconstruct frame object for this SBFrame.");
1212 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001213 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001214 else
1215 {
1216 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001217 log->Printf ("SBFrame::GetVariables () => error: process is running");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001218 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001219 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001220
1221 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001222 log->Printf ("SBFrame(%p)::GetVariables (...) => SBValueList(%p)",
1223 static_cast<void*>(frame),
1224 static_cast<void*>(value_list.opaque_ptr()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001225
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001226 return value_list;
1227}
1228
Greg Clayton69b582f2010-12-14 18:39:31 +00001229SBValueList
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001230SBFrame::GetRegisters ()
1231{
Greg Clayton5160ce52013-03-27 23:08:40 +00001232 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001233
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001234 SBValueList value_list;
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001235 Mutex::Locker api_locker;
1236 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1237
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001238 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +00001239 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +00001240 Process *process = exe_ctx.GetProcessPtr();
1241 if (target && process)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001242 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001243 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001244 if (stop_locker.TryLock(&process->GetRunLock()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001245 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001246 frame = exe_ctx.GetFramePtr();
1247 if (frame)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001248 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001249 RegisterContextSP reg_ctx (frame->GetRegisterContext());
1250 if (reg_ctx)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001251 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001252 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
1253 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
1254 {
1255 value_list.Append(ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx));
1256 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001257 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001258 }
Jim Ingham7730b9a2012-11-29 00:26:19 +00001259 else
1260 {
1261 if (log)
1262 log->Printf ("SBFrame::GetRegisters () => error: could not reconstruct frame object for this SBFrame.");
1263 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001264 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001265 else
1266 {
1267 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001268 log->Printf ("SBFrame::GetRegisters () => error: process is running");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001269 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001270 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001271
1272 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001273 log->Printf ("SBFrame(%p)::GetRegisters () => SBValueList(%p)",
1274 static_cast<void*>(frame),
1275 static_cast<void*>(value_list.opaque_ptr()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001276
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001277 return value_list;
1278}
1279
Jason Molendaad9a53c2013-07-26 02:08:48 +00001280SBValue
1281SBFrame::FindRegister (const char *name)
1282{
1283 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1284
1285 SBValue result;
1286 ValueObjectSP value_sp;
1287 Mutex::Locker api_locker;
1288 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1289
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001290 StackFrame *frame = nullptr;
Jason Molendaad9a53c2013-07-26 02:08:48 +00001291 Target *target = exe_ctx.GetTargetPtr();
1292 Process *process = exe_ctx.GetProcessPtr();
1293 if (target && process)
1294 {
1295 Process::StopLocker stop_locker;
1296 if (stop_locker.TryLock(&process->GetRunLock()))
1297 {
1298 frame = exe_ctx.GetFramePtr();
1299 if (frame)
1300 {
1301 RegisterContextSP reg_ctx (frame->GetRegisterContext());
1302 if (reg_ctx)
1303 {
1304 const uint32_t num_regs = reg_ctx->GetRegisterCount();
1305 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx)
1306 {
1307 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
1308 if (reg_info &&
1309 ((reg_info->name && strcasecmp (reg_info->name, name) == 0) ||
1310 (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0)))
1311 {
1312 value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx);
1313 result.SetSP (value_sp);
1314 break;
1315 }
1316 }
1317 }
1318 }
1319 else
1320 {
1321 if (log)
Jason Molenda5d353842013-07-26 22:52:30 +00001322 log->Printf ("SBFrame::FindRegister () => error: could not reconstruct frame object for this SBFrame.");
Jason Molendaad9a53c2013-07-26 02:08:48 +00001323 }
1324 }
1325 else
1326 {
1327 if (log)
Jason Molenda5d353842013-07-26 22:52:30 +00001328 log->Printf ("SBFrame::FindRegister () => error: process is running");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001329 }
Jason Molendaad9a53c2013-07-26 02:08:48 +00001330 }
1331
1332 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001333 log->Printf ("SBFrame(%p)::FindRegister () => SBValue(%p)",
1334 static_cast<void*>(frame),
1335 static_cast<void*>(value_sp.get()));
Jason Molendaad9a53c2013-07-26 02:08:48 +00001336
1337 return result;
1338}
1339
Caroline Ticedde9cff2010-09-20 05:20:02 +00001340bool
1341SBFrame::GetDescription (SBStream &description)
1342{
Greg Clayton5160ce52013-03-27 23:08:40 +00001343 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001344 Stream &strm = description.ref();
1345
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001346 Mutex::Locker api_locker;
1347 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1348
Jason Molendab57e4a12013-11-04 09:33:30 +00001349 StackFrame *frame;
Greg Claytond9e416c2012-02-18 05:35:26 +00001350 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +00001351 Process *process = exe_ctx.GetProcessPtr();
1352 if (target && process)
Caroline Ticedde9cff2010-09-20 05:20:02 +00001353 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001354 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001355 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001356 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001357 frame = exe_ctx.GetFramePtr();
1358 if (frame)
1359 {
1360 frame->DumpUsingSettingsFormat (&strm);
1361 }
1362 else
1363 {
1364 if (log)
1365 log->Printf ("SBFrame::GetDescription () => error: could not reconstruct frame object for this SBFrame.");
1366 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001367 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001368 else
1369 {
Greg Claytonc9858e42012-04-06 02:17:47 +00001370 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001371 log->Printf ("SBFrame::GetDescription () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +00001372 }
1373
Caroline Ticedde9cff2010-09-20 05:20:02 +00001374 }
1375 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001376 strm.PutCString ("No value");
Caroline Ticedde9cff2010-09-20 05:20:02 +00001377
1378 return true;
1379}
Greg Clayton1d3afba2010-10-05 00:00:42 +00001380
Greg Clayton69b582f2010-12-14 18:39:31 +00001381SBValue
Greg Clayton1d3afba2010-10-05 00:00:42 +00001382SBFrame::EvaluateExpression (const char *expr)
1383{
Greg Clayton316d4982011-06-18 20:06:08 +00001384 SBValue result;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001385 ExecutionContext exe_ctx(m_opaque_sp.get());
Jason Molendab57e4a12013-11-04 09:33:30 +00001386 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Claytond9e416c2012-02-18 05:35:26 +00001387 Target *target = exe_ctx.GetTargetPtr();
1388 if (frame && target)
Greg Clayton316d4982011-06-18 20:06:08 +00001389 {
Jim Ingham35e1bda2012-10-16 21:41:58 +00001390 SBExpressionOptions options;
1391 lldb::DynamicValueType fetch_dynamic_value = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Claytoncced1562012-10-16 22:58:25 +00001392 options.SetFetchDynamicValue (fetch_dynamic_value);
Jim Ingham35e1bda2012-10-16 21:41:58 +00001393 options.SetUnwindOnError (true);
Eugene Leviant24785bd2016-01-29 10:48:11 +00001394 options.SetIgnoreBreakpoints (true);
Ryan Brown998c8a1c12015-11-02 19:30:40 +00001395 if (target->GetLanguage() != eLanguageTypeUnknown)
1396 options.SetLanguage(target->GetLanguage());
1397 else
1398 options.SetLanguage(frame->GetLanguage());
Jim Ingham35e1bda2012-10-16 21:41:58 +00001399 return EvaluateExpression (expr, options);
Greg Clayton316d4982011-06-18 20:06:08 +00001400 }
1401 return result;
Jim Ingham78a685a2011-04-16 00:01:13 +00001402}
1403
1404SBValue
Jim Ingham2837b762011-05-04 03:43:18 +00001405SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value)
Jim Ingham78a685a2011-04-16 00:01:13 +00001406{
Jim Ingham35e1bda2012-10-16 21:41:58 +00001407 SBExpressionOptions options;
Greg Claytoncced1562012-10-16 22:58:25 +00001408 options.SetFetchDynamicValue (fetch_dynamic_value);
Jim Ingham35e1bda2012-10-16 21:41:58 +00001409 options.SetUnwindOnError (true);
Eugene Leviant24785bd2016-01-29 10:48:11 +00001410 options.SetIgnoreBreakpoints (true);
Ryan Brown998c8a1c12015-11-02 19:30:40 +00001411 ExecutionContext exe_ctx(m_opaque_sp.get());
1412 StackFrame *frame = exe_ctx.GetFramePtr();
1413 Target *target = exe_ctx.GetTargetPtr();
1414 if (target && target->GetLanguage() != eLanguageTypeUnknown)
1415 options.SetLanguage(target->GetLanguage());
1416 else if (frame)
1417 options.SetLanguage(frame->GetLanguage());
Jim Ingham35e1bda2012-10-16 21:41:58 +00001418 return EvaluateExpression (expr, options);
Jim Ingham7ba6e992012-05-11 23:47:32 +00001419}
1420
1421SBValue
1422SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value, bool unwind_on_error)
1423{
Jim Ingham35e1bda2012-10-16 21:41:58 +00001424 SBExpressionOptions options;
Ryan Brown998c8a1c12015-11-02 19:30:40 +00001425 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Claytoncced1562012-10-16 22:58:25 +00001426 options.SetFetchDynamicValue (fetch_dynamic_value);
Jim Ingham35e1bda2012-10-16 21:41:58 +00001427 options.SetUnwindOnError (unwind_on_error);
Eugene Leviant24785bd2016-01-29 10:48:11 +00001428 options.SetIgnoreBreakpoints (true);
Ryan Brown998c8a1c12015-11-02 19:30:40 +00001429 StackFrame *frame = exe_ctx.GetFramePtr();
1430 Target *target = exe_ctx.GetTargetPtr();
1431 if (target && target->GetLanguage() != eLanguageTypeUnknown)
1432 options.SetLanguage(target->GetLanguage());
1433 else if (frame)
1434 options.SetLanguage(frame->GetLanguage());
Jim Ingham35e1bda2012-10-16 21:41:58 +00001435 return EvaluateExpression (expr, options);
1436}
1437
1438lldb::SBValue
1439SBFrame::EvaluateExpression (const char *expr, const SBExpressionOptions &options)
1440{
Greg Clayton5160ce52013-03-27 23:08:40 +00001441 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001442
Saleem Abdulrasool358efd62016-04-21 16:56:02 +00001443#ifndef LLDB_DISABLE_PYTHON
Greg Clayton5160ce52013-03-27 23:08:40 +00001444 Log *expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Saleem Abdulrasool358efd62016-04-21 16:56:02 +00001445#endif
Greg Clayton48381312010-10-30 04:51:46 +00001446
Jim Ingham8646d3c2014-05-05 02:47:44 +00001447 ExpressionResults exe_results = eExpressionSetupError;
Greg Clayton69b582f2010-12-14 18:39:31 +00001448 SBValue expr_result;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001449
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001450 if (expr == nullptr || expr[0] == '\0')
Jim Ingham7730b9a2012-11-29 00:26:19 +00001451 {
1452 if (log)
1453 log->Printf ("SBFrame::EvaluateExpression called with an empty expression");
1454 return expr_result;
1455 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001456
Greg Clayton81e871e2012-02-04 02:27:34 +00001457 ValueObjectSP expr_value_sp;
Greg Clayton48381312010-10-30 04:51:46 +00001458
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001459 Mutex::Locker api_locker;
1460 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1461
Greg Claytonb9556ac2012-01-30 07:41:31 +00001462 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001463 log->Printf ("SBFrame()::EvaluateExpression (expr=\"%s\")...", expr);
Greg Claytonb9556ac2012-01-30 07:41:31 +00001464
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001465 StackFrame *frame = nullptr;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001466 Target *target = exe_ctx.GetTargetPtr();
1467 Process *process = exe_ctx.GetProcessPtr();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001468
Jim Ingham7730b9a2012-11-29 00:26:19 +00001469 if (target && process)
1470 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001471 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001472 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001473 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001474 frame = exe_ctx.GetFramePtr();
1475 if (frame)
1476 {
Greg Claytonfb6621e2013-12-06 21:59:52 +00001477 if (target->GetDisplayExpressionsInCrashlogs())
1478 {
1479 StreamString frame_description;
1480 frame->DumpUsingSettingsFormat (&frame_description);
1481 Host::SetCrashDescriptionWithFormat ("SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
1482 expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str());
1483 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001484
Greg Claytonfb6621e2013-12-06 21:59:52 +00001485 exe_results = target->EvaluateExpression (expr,
Jim Ingham7730b9a2012-11-29 00:26:19 +00001486 frame,
1487 expr_value_sp,
1488 options.ref());
1489 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
Greg Claytonfb6621e2013-12-06 21:59:52 +00001490
1491 if (target->GetDisplayExpressionsInCrashlogs())
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001492 Host::SetCrashDescription(nullptr);
Jim Ingham7730b9a2012-11-29 00:26:19 +00001493 }
1494 else
1495 {
1496 if (log)
1497 log->Printf ("SBFrame::EvaluateExpression () => error: could not reconstruct frame object for this SBFrame.");
1498 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001499 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001500 else
1501 {
1502 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001503 log->Printf ("SBFrame::EvaluateExpression () => error: process is running");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001504 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00001505 }
Jason Molendacf7e2dc2012-02-21 05:33:55 +00001506
1507#ifndef LLDB_DISABLE_PYTHON
Sean Callanana162eba2010-12-07 22:55:01 +00001508 if (expr_log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001509 expr_log->Printf("** [SBFrame::EvaluateExpression] Expression result is %s, summary %s **",
1510 expr_result.GetValue(), expr_result.GetSummary());
1511
Greg Clayton48381312010-10-30 04:51:46 +00001512 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001513 log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)",
1514 static_cast<void*>(frame), expr,
1515 static_cast<void*>(expr_value_sp.get()), exe_results);
Jason Molendacf7e2dc2012-02-21 05:33:55 +00001516#endif
Greg Clayton48381312010-10-30 04:51:46 +00001517
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001518 return expr_result;
Greg Clayton1d3afba2010-10-05 00:00:42 +00001519}
Greg Clayton316d4982011-06-18 20:06:08 +00001520
1521bool
Oleksiy Vyalov6345fe32015-06-24 18:35:36 +00001522SBFrame::IsInlined()
Greg Clayton316d4982011-06-18 20:06:08 +00001523{
Oleksiy Vyalov05f75e92015-06-25 17:41:41 +00001524 return static_cast<const SBFrame*>(this)->IsInlined();
1525}
1526
1527bool
1528SBFrame::IsInlined() const
1529{
Greg Clayton5160ce52013-03-27 23:08:40 +00001530 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001531 ExecutionContext exe_ctx(m_opaque_sp.get());
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001532 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +00001533 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +00001534 Process *process = exe_ctx.GetProcessPtr();
1535 if (target && process)
Greg Clayton316d4982011-06-18 20:06:08 +00001536 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001537 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001538 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001539 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001540 frame = exe_ctx.GetFramePtr();
1541 if (frame)
1542 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001543
Jim Ingham7730b9a2012-11-29 00:26:19 +00001544 Block *block = frame->GetSymbolContext(eSymbolContextBlock).block;
1545 if (block)
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001546 return block->GetContainingInlinedBlock() != nullptr;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001547 }
1548 else
1549 {
1550 if (log)
1551 log->Printf ("SBFrame::IsInlined () => error: could not reconstruct frame object for this SBFrame.");
1552 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001553 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001554 else
1555 {
Greg Claytonc9858e42012-04-06 02:17:47 +00001556 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001557 log->Printf ("SBFrame::IsInlined () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +00001558 }
1559
Greg Clayton316d4982011-06-18 20:06:08 +00001560 }
1561 return false;
1562}
1563
1564const char *
Oleksiy Vyalov6345fe32015-06-24 18:35:36 +00001565SBFrame::GetFunctionName()
Greg Clayton316d4982011-06-18 20:06:08 +00001566{
Oleksiy Vyalov05f75e92015-06-25 17:41:41 +00001567 return static_cast<const SBFrame*>(this)->GetFunctionName();
1568}
1569
1570const char *
1571SBFrame::GetFunctionName() const
1572{
Greg Clayton5160ce52013-03-27 23:08:40 +00001573 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001574 const char *name = nullptr;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001575 ExecutionContext exe_ctx(m_opaque_sp.get());
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001576 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +00001577 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +00001578 Process *process = exe_ctx.GetProcessPtr();
1579 if (target && process)
Greg Clayton316d4982011-06-18 20:06:08 +00001580 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001581 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001582 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton316d4982011-06-18 20:06:08 +00001583 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001584 frame = exe_ctx.GetFramePtr();
1585 if (frame)
Greg Clayton316d4982011-06-18 20:06:08 +00001586 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001587 SymbolContext sc (frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol));
1588 if (sc.block)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001589 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001590 Block *inlined_block = sc.block->GetContainingInlinedBlock ();
1591 if (inlined_block)
1592 {
1593 const InlineFunctionInfo* inlined_info = inlined_block->GetInlinedFunctionInfo();
Greg Claytonddaf6a72015-07-08 22:32:23 +00001594 name = inlined_info->GetName(sc.function->GetLanguage()).AsCString();
Jim Ingham7730b9a2012-11-29 00:26:19 +00001595 }
1596 }
1597
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001598 if (name == nullptr)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001599 {
1600 if (sc.function)
1601 name = sc.function->GetName().GetCString();
1602 }
1603
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001604 if (name == nullptr)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001605 {
1606 if (sc.symbol)
1607 name = sc.symbol->GetName().GetCString();
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001608 }
Greg Clayton316d4982011-06-18 20:06:08 +00001609 }
Jim Ingham7730b9a2012-11-29 00:26:19 +00001610 else
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001611 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001612 if (log)
1613 log->Printf ("SBFrame::GetFunctionName () => error: could not reconstruct frame object for this SBFrame.");
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001614 }
Greg Clayton316d4982011-06-18 20:06:08 +00001615 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001616 else
1617 {
Greg Claytonc9858e42012-04-06 02:17:47 +00001618 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001619 log->Printf ("SBFrame::GetFunctionName() => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +00001620
1621 }
Greg Clayton316d4982011-06-18 20:06:08 +00001622 }
1623 return name;
1624}
Enrico Granatac1f705c2015-07-06 18:28:46 +00001625
1626const char *
1627SBFrame::GetDisplayFunctionName()
1628{
1629 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001630 const char *name = nullptr;
Enrico Granatac1f705c2015-07-06 18:28:46 +00001631 ExecutionContext exe_ctx(m_opaque_sp.get());
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001632 StackFrame *frame = nullptr;
Enrico Granatac1f705c2015-07-06 18:28:46 +00001633 Target *target = exe_ctx.GetTargetPtr();
1634 Process *process = exe_ctx.GetProcessPtr();
1635 if (target && process)
1636 {
1637 Process::StopLocker stop_locker;
1638 if (stop_locker.TryLock(&process->GetRunLock()))
1639 {
1640 frame = exe_ctx.GetFramePtr();
1641 if (frame)
1642 {
1643 SymbolContext sc (frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol));
1644 if (sc.block)
1645 {
1646 Block *inlined_block = sc.block->GetContainingInlinedBlock ();
1647 if (inlined_block)
1648 {
1649 const InlineFunctionInfo* inlined_info = inlined_block->GetInlinedFunctionInfo();
Greg Claytonddaf6a72015-07-08 22:32:23 +00001650 name = inlined_info->GetDisplayName(sc.function->GetLanguage()).AsCString();
Enrico Granatac1f705c2015-07-06 18:28:46 +00001651 }
1652 }
1653
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001654 if (name == nullptr)
Enrico Granatac1f705c2015-07-06 18:28:46 +00001655 {
1656 if (sc.function)
1657 name = sc.function->GetDisplayName().GetCString();
1658 }
1659
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001660 if (name == nullptr)
Enrico Granatac1f705c2015-07-06 18:28:46 +00001661 {
1662 if (sc.symbol)
1663 name = sc.symbol->GetDisplayName().GetCString();
1664 }
1665 }
1666 else
1667 {
1668 if (log)
1669 log->Printf ("SBFrame::GetDisplayFunctionName () => error: could not reconstruct frame object for this SBFrame.");
1670 }
1671 }
1672 else
1673 {
1674 if (log)
1675 log->Printf ("SBFrame::GetDisplayFunctionName() => error: process is running");
1676
1677 }
1678 }
1679 return name;
1680}