blob: 02a215beb07d69a42949bcdd9f501b6d618a4a67 [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
Jim Ingham7730b9a2012-11-29 00:26:19 +0000792 if (sc.block->AppendVariables (can_create,
793 get_parent_variables,
794 stop_if_block_is_inlined_function,
795 &variable_list))
796 {
797 var_sp = variable_list.FindVariable (ConstString(name));
798 }
799 }
800
801 if (var_sp)
802 {
803 value_sp = frame->GetValueObjectForFrameVariable(var_sp, eNoDynamicValues);
804 sb_value.SetSP(value_sp, use_dynamic);
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000805 }
806 }
Jim Ingham7730b9a2012-11-29 00:26:19 +0000807 else
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000808 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000809 if (log)
810 log->Printf ("SBFrame::FindVariable () => error: could not reconstruct frame object for this SBFrame.");
Greg Clayton72eff182010-12-14 04:58:53 +0000811 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000812 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000813 else
814 {
815 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000816 log->Printf ("SBFrame::FindVariable () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000817 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000818 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000819
Greg Clayton48381312010-10-30 04:51:46 +0000820 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000821 log->Printf ("SBFrame(%p)::FindVariable (name=\"%s\") => SBValue(%p)",
822 static_cast<void*>(frame), name,
823 static_cast<void*>(value_sp.get()));
Greg Clayton48381312010-10-30 04:51:46 +0000824
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000825 return sb_value;
826}
827
828SBValue
Greg Clayton69b582f2010-12-14 18:39:31 +0000829SBFrame::FindValue (const char *name, ValueType value_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000830{
Greg Clayton316d4982011-06-18 20:06:08 +0000831 SBValue value;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000832 ExecutionContext exe_ctx(m_opaque_sp.get());
Jason Molendab57e4a12013-11-04 09:33:30 +0000833 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Claytond9e416c2012-02-18 05:35:26 +0000834 Target *target = exe_ctx.GetTargetPtr();
835 if (frame && target)
Greg Clayton316d4982011-06-18 20:06:08 +0000836 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000837 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton316d4982011-06-18 20:06:08 +0000838 value = FindValue (name, value_type, use_dynamic);
839 }
840 return value;
Jim Ingham78a685a2011-04-16 00:01:13 +0000841}
842
843SBValue
Jim Ingham2837b762011-05-04 03:43:18 +0000844SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +0000845{
Greg Clayton5160ce52013-03-27 23:08:40 +0000846 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton69b582f2010-12-14 18:39:31 +0000847 SBValue sb_value;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000848
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000849 if (name == nullptr || name[0] == '\0')
Jim Ingham7730b9a2012-11-29 00:26:19 +0000850 {
851 if (log)
852 log->Printf ("SBFrame::FindValue called with empty name.");
853 return sb_value;
854 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000855
Greg Clayton81e871e2012-02-04 02:27:34 +0000856 ValueObjectSP value_sp;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000857 Mutex::Locker api_locker;
858 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
859
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +0000860 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +0000861 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000862 Process *process = exe_ctx.GetProcessPtr();
863 if (target && process)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000864 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000865 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000866 if (stop_locker.TryLock(&process->GetRunLock()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000867 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000868 frame = exe_ctx.GetFramePtr();
869 if (frame)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000870 {
Enrico Granata8a2a0df2014-02-19 19:35:13 +0000871 VariableList variable_list;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000872
Jim Ingham7730b9a2012-11-29 00:26:19 +0000873 switch (value_type)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000874 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000875 case eValueTypeVariableGlobal: // global variable
876 case eValueTypeVariableStatic: // static variable
877 case eValueTypeVariableArgument: // function argument variables
878 case eValueTypeVariableLocal: // function local variables
879 {
Chaoren Lin0efb51a2015-03-19 22:00:13 +0000880 SymbolContext sc(frame->GetSymbolContext(eSymbolContextBlock));
Greg Clayton69b582f2010-12-14 18:39:31 +0000881
Jim Ingham7730b9a2012-11-29 00:26:19 +0000882 const bool can_create = true;
883 const bool get_parent_variables = true;
884 const bool stop_if_block_is_inlined_function = true;
Greg Clayton69b582f2010-12-14 18:39:31 +0000885
Chaoren Lin0efb51a2015-03-19 22:00:13 +0000886 if (sc.block)
887 sc.block->AppendVariables(can_create,
888 get_parent_variables,
889 stop_if_block_is_inlined_function,
890 &variable_list);
891 if (value_type == eValueTypeVariableGlobal)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000892 {
Chaoren Lin0efb51a2015-03-19 22:00:13 +0000893 const bool get_file_globals = true;
894 VariableList *frame_vars = frame->GetVariableList(get_file_globals);
895 if (frame_vars)
896 frame_vars->AppendVariablesIfUnique(variable_list);
897 }
898 ConstString const_name(name);
899 VariableSP variable_sp(variable_list.FindVariable(const_name, value_type));
900 if (variable_sp)
901 {
902 value_sp = frame->GetValueObjectForFrameVariable(variable_sp, eNoDynamicValues);
903 sb_value.SetSP(value_sp, use_dynamic);
Jim Ingham7730b9a2012-11-29 00:26:19 +0000904 }
905 }
906 break;
907
908 case eValueTypeRegister: // stack frame register value
909 {
910 RegisterContextSP reg_ctx (frame->GetRegisterContext());
911 if (reg_ctx)
912 {
913 const uint32_t num_regs = reg_ctx->GetRegisterCount();
914 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx)
915 {
916 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
917 if (reg_info &&
918 ((reg_info->name && strcasecmp (reg_info->name, name) == 0) ||
919 (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0)))
920 {
921 value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx);
922 sb_value.SetSP (value_sp);
923 break;
924 }
925 }
926 }
927 }
928 break;
929
930 case eValueTypeRegisterSet: // A collection of stack frame register values
931 {
932 RegisterContextSP reg_ctx (frame->GetRegisterContext());
933 if (reg_ctx)
934 {
935 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
936 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
937 {
938 const RegisterSet *reg_set = reg_ctx->GetRegisterSet (set_idx);
939 if (reg_set &&
940 ((reg_set->name && strcasecmp (reg_set->name, name) == 0) ||
941 (reg_set->short_name && strcasecmp (reg_set->short_name, name) == 0)))
942 {
943 value_sp = ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx);
944 sb_value.SetSP (value_sp);
945 break;
946 }
947 }
948 }
949 }
950 break;
951
952 case eValueTypeConstResult: // constant result variables
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000953 {
954 ConstString const_name(name);
Sean Callanan8f1f9a12015-09-30 19:57:57 +0000955 ExpressionVariableSP expr_var_sp (target->GetPersistentVariable (const_name));
Jim Ingham7730b9a2012-11-29 00:26:19 +0000956 if (expr_var_sp)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000957 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000958 value_sp = expr_var_sp->GetValueObject();
959 sb_value.SetSP (value_sp, use_dynamic);
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000960 }
961 }
Jim Ingham7730b9a2012-11-29 00:26:19 +0000962 break;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000963
Jim Ingham7730b9a2012-11-29 00:26:19 +0000964 default:
965 break;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000966 }
Jim Ingham7730b9a2012-11-29 00:26:19 +0000967 }
968 else
969 {
970 if (log)
971 log->Printf ("SBFrame::FindValue () => error: could not reconstruct frame object for this SBFrame.");
Greg Clayton69b582f2010-12-14 18:39:31 +0000972 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000973 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000974 else
975 {
976 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000977 log->Printf ("SBFrame::FindValue () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000978 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000979 }
Greg Clayton48381312010-10-30 04:51:46 +0000980
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000981 if (log)
982 log->Printf ("SBFrame(%p)::FindVariableInScope (name=\"%s\", value_type=%i) => SBValue(%p)",
983 static_cast<void*>(frame), name, value_type,
984 static_cast<void*>(value_sp.get()));
985
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000986 return sb_value;
987}
988
989bool
Johnny Chen35e2ab62012-03-05 19:53:24 +0000990SBFrame::IsEqual (const SBFrame &that) const
991{
Jason Molendab57e4a12013-11-04 09:33:30 +0000992 lldb::StackFrameSP this_sp = GetFrameSP();
993 lldb::StackFrameSP that_sp = that.GetFrameSP();
Johnny Chen35e2ab62012-03-05 19:53:24 +0000994 return (this_sp && that_sp && this_sp->GetStackID() == that_sp->GetStackID());
995}
996
997bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000998SBFrame::operator == (const SBFrame &rhs) const
999{
Johnny Chen35e2ab62012-03-05 19:53:24 +00001000 return IsEqual(rhs);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001001}
1002
1003bool
1004SBFrame::operator != (const SBFrame &rhs) const
1005{
Johnny Chen35e2ab62012-03-05 19:53:24 +00001006 return !IsEqual(rhs);
Greg Clayton481cef22011-01-21 06:11:58 +00001007}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001008
1009SBThread
1010SBFrame::GetThread () const
1011{
Greg Clayton5160ce52013-03-27 23:08:40 +00001012 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001013
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001014 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Claytond9e416c2012-02-18 05:35:26 +00001015 ThreadSP thread_sp (exe_ctx.GetThreadSP());
1016 SBThread sb_thread (thread_sp);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001017
1018 if (log)
Caroline Tice750cd172010-10-26 23:49:36 +00001019 {
1020 SBStream sstr;
1021 sb_thread.GetDescription (sstr);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001022 log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s",
1023 static_cast<void*>(exe_ctx.GetFramePtr()),
1024 static_cast<void*>(thread_sp.get()), sstr.GetData());
Caroline Tice750cd172010-10-26 23:49:36 +00001025 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001026
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001027 return sb_thread;
1028}
1029
1030const char *
1031SBFrame::Disassemble () const
1032{
Greg Clayton5160ce52013-03-27 23:08:40 +00001033 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001034 const char *disassembly = nullptr;
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001035 Mutex::Locker api_locker;
1036 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1037
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001038 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +00001039 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +00001040 Process *process = exe_ctx.GetProcessPtr();
1041 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001042 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001043 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001044 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001045 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001046 frame = exe_ctx.GetFramePtr();
1047 if (frame)
1048 {
1049 disassembly = frame->Disassemble();
1050 }
1051 else
1052 {
1053 if (log)
1054 log->Printf ("SBFrame::Disassemble () => error: could not reconstruct frame object for this SBFrame.");
1055 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001056 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001057 else
1058 {
1059 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001060 log->Printf ("SBFrame::Disassemble () => error: process is running");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001061 }
Greg Claytonaf67cec2010-12-20 20:49:23 +00001062 }
Greg Clayton48381312010-10-30 04:51:46 +00001063
1064 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001065 log->Printf ("SBFrame(%p)::Disassemble () => %s",
1066 static_cast<void*>(frame), disassembly);
Greg Clayton48381312010-10-30 04:51:46 +00001067
1068 return disassembly;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001069}
1070
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001071SBValueList
1072SBFrame::GetVariables (bool arguments,
1073 bool locals,
1074 bool statics,
1075 bool in_scope_only)
1076{
Greg Clayton316d4982011-06-18 20:06:08 +00001077 SBValueList value_list;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001078 ExecutionContext exe_ctx(m_opaque_sp.get());
Jason Molendab57e4a12013-11-04 09:33:30 +00001079 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Claytond9e416c2012-02-18 05:35:26 +00001080 Target *target = exe_ctx.GetTargetPtr();
1081 if (frame && target)
Greg Clayton316d4982011-06-18 20:06:08 +00001082 {
Greg Claytond9e416c2012-02-18 05:35:26 +00001083 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
Zachary Turner51f96ee2015-02-17 17:55:50 +00001084 const bool include_runtime_support_values = target ? target->GetDisplayRuntimeSupportValues() : false;
1085
1086 SBVariablesOptions options;
1087 options.SetIncludeArguments(arguments);
1088 options.SetIncludeLocals(locals);
1089 options.SetIncludeStatics(statics);
1090 options.SetInScopeOnly(in_scope_only);
1091 options.SetIncludeRuntimeSupportValues(include_runtime_support_values);
1092 options.SetUseDynamic(use_dynamic);
1093
1094 value_list = GetVariables (options);
Greg Clayton316d4982011-06-18 20:06:08 +00001095 }
1096 return value_list;
Jim Ingham78a685a2011-04-16 00:01:13 +00001097}
1098
Enrico Granata560558e2015-02-11 02:35:39 +00001099lldb::SBValueList
1100SBFrame::GetVariables (bool arguments,
1101 bool locals,
1102 bool statics,
1103 bool in_scope_only,
1104 lldb::DynamicValueType use_dynamic)
1105{
1106 ExecutionContext exe_ctx(m_opaque_sp.get());
1107 Target *target = exe_ctx.GetTargetPtr();
Zachary Turner51f96ee2015-02-17 17:55:50 +00001108 const bool include_runtime_support_values = target ? target->GetDisplayRuntimeSupportValues() : false;
1109 SBVariablesOptions options;
1110 options.SetIncludeArguments(arguments);
1111 options.SetIncludeLocals(locals);
1112 options.SetIncludeStatics(statics);
1113 options.SetInScopeOnly(in_scope_only);
1114 options.SetIncludeRuntimeSupportValues(include_runtime_support_values);
1115 options.SetUseDynamic(use_dynamic);
1116 return GetVariables(options);
Enrico Granata560558e2015-02-11 02:35:39 +00001117}
1118
Jim Ingham78a685a2011-04-16 00:01:13 +00001119SBValueList
Zachary Turner51f96ee2015-02-17 17:55:50 +00001120SBFrame::GetVariables (const lldb::SBVariablesOptions& options)
Jim Ingham78a685a2011-04-16 00:01:13 +00001121{
Greg Clayton5160ce52013-03-27 23:08:40 +00001122 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001123
Greg Claytonb9556ac2012-01-30 07:41:31 +00001124 SBValueList value_list;
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001125 Mutex::Locker api_locker;
1126 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1127
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001128 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +00001129 Target *target = exe_ctx.GetTargetPtr();
Greg Claytonb9556ac2012-01-30 07:41:31 +00001130
Zachary Turner51f96ee2015-02-17 17:55:50 +00001131 const bool statics = options.GetIncludeStatics();
1132 const bool arguments = options.GetIncludeArguments();
1133 const bool locals = options.GetIncludeLocals();
1134 const bool in_scope_only = options.GetInScopeOnly();
1135 const bool include_runtime_support_values = options.GetIncludeRuntimeSupportValues();
1136 const lldb::DynamicValueType use_dynamic = options.GetUseDynamic();
1137
Caroline Ticeceb6b132010-10-26 03:11:13 +00001138 if (log)
Zachary Turner51f96ee2015-02-17 17:55:50 +00001139 log->Printf ("SBFrame::GetVariables (arguments=%i, locals=%i, statics=%i, in_scope_only=%i runtime=%i dynamic=%i)",
1140 arguments, locals,
1141 statics, in_scope_only,
1142 include_runtime_support_values, use_dynamic);
1143
Jim Ingham7730b9a2012-11-29 00:26:19 +00001144 Process *process = exe_ctx.GetProcessPtr();
1145 if (target && process)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001146 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001147 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001148 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001149 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001150 frame = exe_ctx.GetFramePtr();
1151 if (frame)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001152 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001153 size_t i;
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001154 VariableList *variable_list = nullptr;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001155 variable_list = frame->GetVariableList(true);
1156 if (variable_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001157 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001158 const size_t num_variables = variable_list->GetSize();
1159 if (num_variables)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001160 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001161 for (i = 0; i < num_variables; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001162 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001163 VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
1164 if (variable_sp)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001165 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001166 bool add_variable = false;
1167 switch (variable_sp->GetScope())
1168 {
1169 case eValueTypeVariableGlobal:
1170 case eValueTypeVariableStatic:
1171 add_variable = statics;
1172 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001173
Jim Ingham7730b9a2012-11-29 00:26:19 +00001174 case eValueTypeVariableArgument:
1175 add_variable = arguments;
1176 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001177
Jim Ingham7730b9a2012-11-29 00:26:19 +00001178 case eValueTypeVariableLocal:
1179 add_variable = locals;
1180 break;
Greg Claytonc982c762010-07-09 20:39:50 +00001181
Jim Ingham7730b9a2012-11-29 00:26:19 +00001182 default:
1183 break;
1184 }
1185 if (add_variable)
1186 {
1187 if (in_scope_only && !variable_sp->IsInScope(frame))
1188 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001189
Jim Ingham7730b9a2012-11-29 00:26:19 +00001190 ValueObjectSP valobj_sp(frame->GetValueObjectForFrameVariable (variable_sp, eNoDynamicValues));
Enrico Granata560558e2015-02-11 02:35:39 +00001191
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001192 if (!include_runtime_support_values &&
1193 valobj_sp != nullptr &&
1194 valobj_sp->IsRuntimeSupportValue())
Enrico Granata560558e2015-02-11 02:35:39 +00001195 continue;
1196
Jim Ingham7730b9a2012-11-29 00:26:19 +00001197 SBValue value_sb;
1198 value_sb.SetSP(valobj_sp,use_dynamic);
1199 value_list.Append(value_sb);
1200 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001201 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001202 }
1203 }
1204 }
1205 }
Jim Ingham7730b9a2012-11-29 00:26:19 +00001206 else
1207 {
1208 if (log)
1209 log->Printf ("SBFrame::GetVariables () => error: could not reconstruct frame object for this SBFrame.");
1210 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001211 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001212 else
1213 {
1214 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001215 log->Printf ("SBFrame::GetVariables () => error: process is running");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001216 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001217 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001218
1219 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001220 log->Printf ("SBFrame(%p)::GetVariables (...) => SBValueList(%p)",
1221 static_cast<void*>(frame),
1222 static_cast<void*>(value_list.opaque_ptr()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001223
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001224 return value_list;
1225}
1226
Greg Clayton69b582f2010-12-14 18:39:31 +00001227SBValueList
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001228SBFrame::GetRegisters ()
1229{
Greg Clayton5160ce52013-03-27 23:08:40 +00001230 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001231
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001232 SBValueList value_list;
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001233 Mutex::Locker api_locker;
1234 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1235
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001236 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +00001237 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +00001238 Process *process = exe_ctx.GetProcessPtr();
1239 if (target && process)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001240 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001241 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001242 if (stop_locker.TryLock(&process->GetRunLock()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001243 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001244 frame = exe_ctx.GetFramePtr();
1245 if (frame)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001246 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001247 RegisterContextSP reg_ctx (frame->GetRegisterContext());
1248 if (reg_ctx)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001249 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001250 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
1251 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
1252 {
1253 value_list.Append(ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx));
1254 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001255 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001256 }
Jim Ingham7730b9a2012-11-29 00:26:19 +00001257 else
1258 {
1259 if (log)
1260 log->Printf ("SBFrame::GetRegisters () => error: could not reconstruct frame object for this SBFrame.");
1261 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001262 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001263 else
1264 {
1265 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001266 log->Printf ("SBFrame::GetRegisters () => error: process is running");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001267 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001268 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001269
1270 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001271 log->Printf ("SBFrame(%p)::GetRegisters () => SBValueList(%p)",
1272 static_cast<void*>(frame),
1273 static_cast<void*>(value_list.opaque_ptr()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001274
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001275 return value_list;
1276}
1277
Jason Molendaad9a53c2013-07-26 02:08:48 +00001278SBValue
1279SBFrame::FindRegister (const char *name)
1280{
1281 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1282
1283 SBValue result;
1284 ValueObjectSP value_sp;
1285 Mutex::Locker api_locker;
1286 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1287
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001288 StackFrame *frame = nullptr;
Jason Molendaad9a53c2013-07-26 02:08:48 +00001289 Target *target = exe_ctx.GetTargetPtr();
1290 Process *process = exe_ctx.GetProcessPtr();
1291 if (target && process)
1292 {
1293 Process::StopLocker stop_locker;
1294 if (stop_locker.TryLock(&process->GetRunLock()))
1295 {
1296 frame = exe_ctx.GetFramePtr();
1297 if (frame)
1298 {
1299 RegisterContextSP reg_ctx (frame->GetRegisterContext());
1300 if (reg_ctx)
1301 {
1302 const uint32_t num_regs = reg_ctx->GetRegisterCount();
1303 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx)
1304 {
1305 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
1306 if (reg_info &&
1307 ((reg_info->name && strcasecmp (reg_info->name, name) == 0) ||
1308 (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0)))
1309 {
1310 value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx);
1311 result.SetSP (value_sp);
1312 break;
1313 }
1314 }
1315 }
1316 }
1317 else
1318 {
1319 if (log)
Jason Molenda5d353842013-07-26 22:52:30 +00001320 log->Printf ("SBFrame::FindRegister () => error: could not reconstruct frame object for this SBFrame.");
Jason Molendaad9a53c2013-07-26 02:08:48 +00001321 }
1322 }
1323 else
1324 {
1325 if (log)
Jason Molenda5d353842013-07-26 22:52:30 +00001326 log->Printf ("SBFrame::FindRegister () => error: process is running");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001327 }
Jason Molendaad9a53c2013-07-26 02:08:48 +00001328 }
1329
1330 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001331 log->Printf ("SBFrame(%p)::FindRegister () => SBValue(%p)",
1332 static_cast<void*>(frame),
1333 static_cast<void*>(value_sp.get()));
Jason Molendaad9a53c2013-07-26 02:08:48 +00001334
1335 return result;
1336}
1337
Caroline Ticedde9cff2010-09-20 05:20:02 +00001338bool
1339SBFrame::GetDescription (SBStream &description)
1340{
Greg Clayton5160ce52013-03-27 23:08:40 +00001341 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001342 Stream &strm = description.ref();
1343
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001344 Mutex::Locker api_locker;
1345 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1346
Jason Molendab57e4a12013-11-04 09:33:30 +00001347 StackFrame *frame;
Greg Claytond9e416c2012-02-18 05:35:26 +00001348 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +00001349 Process *process = exe_ctx.GetProcessPtr();
1350 if (target && process)
Caroline Ticedde9cff2010-09-20 05:20:02 +00001351 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001352 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001353 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001354 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001355 frame = exe_ctx.GetFramePtr();
1356 if (frame)
1357 {
1358 frame->DumpUsingSettingsFormat (&strm);
1359 }
1360 else
1361 {
1362 if (log)
1363 log->Printf ("SBFrame::GetDescription () => error: could not reconstruct frame object for this SBFrame.");
1364 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001365 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001366 else
1367 {
Greg Claytonc9858e42012-04-06 02:17:47 +00001368 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001369 log->Printf ("SBFrame::GetDescription () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +00001370 }
1371
Caroline Ticedde9cff2010-09-20 05:20:02 +00001372 }
1373 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001374 strm.PutCString ("No value");
Caroline Ticedde9cff2010-09-20 05:20:02 +00001375
1376 return true;
1377}
Greg Clayton1d3afba2010-10-05 00:00:42 +00001378
Greg Clayton69b582f2010-12-14 18:39:31 +00001379SBValue
Greg Clayton1d3afba2010-10-05 00:00:42 +00001380SBFrame::EvaluateExpression (const char *expr)
1381{
Greg Clayton316d4982011-06-18 20:06:08 +00001382 SBValue result;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001383 ExecutionContext exe_ctx(m_opaque_sp.get());
Jason Molendab57e4a12013-11-04 09:33:30 +00001384 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Claytond9e416c2012-02-18 05:35:26 +00001385 Target *target = exe_ctx.GetTargetPtr();
1386 if (frame && target)
Greg Clayton316d4982011-06-18 20:06:08 +00001387 {
Jim Ingham35e1bda2012-10-16 21:41:58 +00001388 SBExpressionOptions options;
1389 lldb::DynamicValueType fetch_dynamic_value = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Claytoncced1562012-10-16 22:58:25 +00001390 options.SetFetchDynamicValue (fetch_dynamic_value);
Jim Ingham35e1bda2012-10-16 21:41:58 +00001391 options.SetUnwindOnError (true);
Ryan Brown998c8a1c12015-11-02 19:30:40 +00001392 if (target->GetLanguage() != eLanguageTypeUnknown)
1393 options.SetLanguage(target->GetLanguage());
1394 else
1395 options.SetLanguage(frame->GetLanguage());
Jim Ingham35e1bda2012-10-16 21:41:58 +00001396 return EvaluateExpression (expr, options);
Greg Clayton316d4982011-06-18 20:06:08 +00001397 }
1398 return result;
Jim Ingham78a685a2011-04-16 00:01:13 +00001399}
1400
1401SBValue
Jim Ingham2837b762011-05-04 03:43:18 +00001402SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value)
Jim Ingham78a685a2011-04-16 00:01:13 +00001403{
Jim Ingham35e1bda2012-10-16 21:41:58 +00001404 SBExpressionOptions options;
Greg Claytoncced1562012-10-16 22:58:25 +00001405 options.SetFetchDynamicValue (fetch_dynamic_value);
Jim Ingham35e1bda2012-10-16 21:41:58 +00001406 options.SetUnwindOnError (true);
Ryan Brown998c8a1c12015-11-02 19:30:40 +00001407 ExecutionContext exe_ctx(m_opaque_sp.get());
1408 StackFrame *frame = exe_ctx.GetFramePtr();
1409 Target *target = exe_ctx.GetTargetPtr();
1410 if (target && target->GetLanguage() != eLanguageTypeUnknown)
1411 options.SetLanguage(target->GetLanguage());
1412 else if (frame)
1413 options.SetLanguage(frame->GetLanguage());
Jim Ingham35e1bda2012-10-16 21:41:58 +00001414 return EvaluateExpression (expr, options);
Jim Ingham7ba6e992012-05-11 23:47:32 +00001415}
1416
1417SBValue
1418SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value, bool unwind_on_error)
1419{
Jim Ingham35e1bda2012-10-16 21:41:58 +00001420 SBExpressionOptions options;
Ryan Brown998c8a1c12015-11-02 19:30:40 +00001421 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Claytoncced1562012-10-16 22:58:25 +00001422 options.SetFetchDynamicValue (fetch_dynamic_value);
Jim Ingham35e1bda2012-10-16 21:41:58 +00001423 options.SetUnwindOnError (unwind_on_error);
Ryan Brown998c8a1c12015-11-02 19:30:40 +00001424 StackFrame *frame = exe_ctx.GetFramePtr();
1425 Target *target = exe_ctx.GetTargetPtr();
1426 if (target && target->GetLanguage() != eLanguageTypeUnknown)
1427 options.SetLanguage(target->GetLanguage());
1428 else if (frame)
1429 options.SetLanguage(frame->GetLanguage());
Jim Ingham35e1bda2012-10-16 21:41:58 +00001430 return EvaluateExpression (expr, options);
1431}
1432
1433lldb::SBValue
1434SBFrame::EvaluateExpression (const char *expr, const SBExpressionOptions &options)
1435{
Greg Clayton5160ce52013-03-27 23:08:40 +00001436 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001437
Greg Clayton5160ce52013-03-27 23:08:40 +00001438 Log *expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Greg Clayton48381312010-10-30 04:51:46 +00001439
Jim Ingham8646d3c2014-05-05 02:47:44 +00001440 ExpressionResults exe_results = eExpressionSetupError;
Greg Clayton69b582f2010-12-14 18:39:31 +00001441 SBValue expr_result;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001442
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001443 if (expr == nullptr || expr[0] == '\0')
Jim Ingham7730b9a2012-11-29 00:26:19 +00001444 {
1445 if (log)
1446 log->Printf ("SBFrame::EvaluateExpression called with an empty expression");
1447 return expr_result;
1448 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001449
Greg Clayton81e871e2012-02-04 02:27:34 +00001450 ValueObjectSP expr_value_sp;
Greg Clayton48381312010-10-30 04:51:46 +00001451
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001452 Mutex::Locker api_locker;
1453 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1454
Greg Claytonb9556ac2012-01-30 07:41:31 +00001455 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001456 log->Printf ("SBFrame()::EvaluateExpression (expr=\"%s\")...", expr);
Greg Claytonb9556ac2012-01-30 07:41:31 +00001457
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001458 StackFrame *frame = nullptr;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001459 Target *target = exe_ctx.GetTargetPtr();
1460 Process *process = exe_ctx.GetProcessPtr();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001461
Jim Ingham7730b9a2012-11-29 00:26:19 +00001462 if (target && process)
1463 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001464 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001465 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001466 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001467 frame = exe_ctx.GetFramePtr();
1468 if (frame)
1469 {
Greg Claytonfb6621e2013-12-06 21:59:52 +00001470 if (target->GetDisplayExpressionsInCrashlogs())
1471 {
1472 StreamString frame_description;
1473 frame->DumpUsingSettingsFormat (&frame_description);
1474 Host::SetCrashDescriptionWithFormat ("SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
1475 expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str());
1476 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001477
Greg Claytonfb6621e2013-12-06 21:59:52 +00001478 exe_results = target->EvaluateExpression (expr,
Jim Ingham7730b9a2012-11-29 00:26:19 +00001479 frame,
1480 expr_value_sp,
1481 options.ref());
1482 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
Greg Claytonfb6621e2013-12-06 21:59:52 +00001483
1484 if (target->GetDisplayExpressionsInCrashlogs())
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001485 Host::SetCrashDescription(nullptr);
Jim Ingham7730b9a2012-11-29 00:26:19 +00001486 }
1487 else
1488 {
1489 if (log)
1490 log->Printf ("SBFrame::EvaluateExpression () => error: could not reconstruct frame object for this SBFrame.");
1491 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001492 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001493 else
1494 {
1495 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001496 log->Printf ("SBFrame::EvaluateExpression () => error: process is running");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001497 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00001498 }
Jason Molendacf7e2dc2012-02-21 05:33:55 +00001499
1500#ifndef LLDB_DISABLE_PYTHON
Sean Callanana162eba2010-12-07 22:55:01 +00001501 if (expr_log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001502 expr_log->Printf("** [SBFrame::EvaluateExpression] Expression result is %s, summary %s **",
1503 expr_result.GetValue(), expr_result.GetSummary());
1504
Greg Clayton48381312010-10-30 04:51:46 +00001505 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001506 log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)",
1507 static_cast<void*>(frame), expr,
1508 static_cast<void*>(expr_value_sp.get()), exe_results);
Jason Molendacf7e2dc2012-02-21 05:33:55 +00001509#endif
Greg Clayton48381312010-10-30 04:51:46 +00001510
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001511 return expr_result;
Greg Clayton1d3afba2010-10-05 00:00:42 +00001512}
Greg Clayton316d4982011-06-18 20:06:08 +00001513
1514bool
Oleksiy Vyalov6345fe32015-06-24 18:35:36 +00001515SBFrame::IsInlined()
Greg Clayton316d4982011-06-18 20:06:08 +00001516{
Oleksiy Vyalov05f75e92015-06-25 17:41:41 +00001517 return static_cast<const SBFrame*>(this)->IsInlined();
1518}
1519
1520bool
1521SBFrame::IsInlined() const
1522{
Greg Clayton5160ce52013-03-27 23:08:40 +00001523 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001524 ExecutionContext exe_ctx(m_opaque_sp.get());
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001525 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +00001526 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +00001527 Process *process = exe_ctx.GetProcessPtr();
1528 if (target && process)
Greg Clayton316d4982011-06-18 20:06:08 +00001529 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001530 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001531 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001532 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001533 frame = exe_ctx.GetFramePtr();
1534 if (frame)
1535 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001536
Jim Ingham7730b9a2012-11-29 00:26:19 +00001537 Block *block = frame->GetSymbolContext(eSymbolContextBlock).block;
1538 if (block)
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001539 return block->GetContainingInlinedBlock() != nullptr;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001540 }
1541 else
1542 {
1543 if (log)
1544 log->Printf ("SBFrame::IsInlined () => error: could not reconstruct frame object for this SBFrame.");
1545 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001546 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001547 else
1548 {
Greg Claytonc9858e42012-04-06 02:17:47 +00001549 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001550 log->Printf ("SBFrame::IsInlined () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +00001551 }
1552
Greg Clayton316d4982011-06-18 20:06:08 +00001553 }
1554 return false;
1555}
1556
1557const char *
Oleksiy Vyalov6345fe32015-06-24 18:35:36 +00001558SBFrame::GetFunctionName()
Greg Clayton316d4982011-06-18 20:06:08 +00001559{
Oleksiy Vyalov05f75e92015-06-25 17:41:41 +00001560 return static_cast<const SBFrame*>(this)->GetFunctionName();
1561}
1562
1563const char *
1564SBFrame::GetFunctionName() const
1565{
Greg Clayton5160ce52013-03-27 23:08:40 +00001566 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001567 const char *name = nullptr;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001568 ExecutionContext exe_ctx(m_opaque_sp.get());
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001569 StackFrame *frame = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +00001570 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +00001571 Process *process = exe_ctx.GetProcessPtr();
1572 if (target && process)
Greg Clayton316d4982011-06-18 20:06:08 +00001573 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001574 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001575 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton316d4982011-06-18 20:06:08 +00001576 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001577 frame = exe_ctx.GetFramePtr();
1578 if (frame)
Greg Clayton316d4982011-06-18 20:06:08 +00001579 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001580 SymbolContext sc (frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol));
1581 if (sc.block)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001582 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001583 Block *inlined_block = sc.block->GetContainingInlinedBlock ();
1584 if (inlined_block)
1585 {
1586 const InlineFunctionInfo* inlined_info = inlined_block->GetInlinedFunctionInfo();
Greg Claytonddaf6a72015-07-08 22:32:23 +00001587 name = inlined_info->GetName(sc.function->GetLanguage()).AsCString();
Jim Ingham7730b9a2012-11-29 00:26:19 +00001588 }
1589 }
1590
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001591 if (name == nullptr)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001592 {
1593 if (sc.function)
1594 name = sc.function->GetName().GetCString();
1595 }
1596
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001597 if (name == nullptr)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001598 {
1599 if (sc.symbol)
1600 name = sc.symbol->GetName().GetCString();
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001601 }
Greg Clayton316d4982011-06-18 20:06:08 +00001602 }
Jim Ingham7730b9a2012-11-29 00:26:19 +00001603 else
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001604 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001605 if (log)
1606 log->Printf ("SBFrame::GetFunctionName () => error: could not reconstruct frame object for this SBFrame.");
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001607 }
Greg Clayton316d4982011-06-18 20:06:08 +00001608 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001609 else
1610 {
Greg Claytonc9858e42012-04-06 02:17:47 +00001611 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001612 log->Printf ("SBFrame::GetFunctionName() => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +00001613
1614 }
Greg Clayton316d4982011-06-18 20:06:08 +00001615 }
1616 return name;
1617}
Enrico Granatac1f705c2015-07-06 18:28:46 +00001618
1619const char *
1620SBFrame::GetDisplayFunctionName()
1621{
1622 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001623 const char *name = nullptr;
Enrico Granatac1f705c2015-07-06 18:28:46 +00001624 ExecutionContext exe_ctx(m_opaque_sp.get());
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001625 StackFrame *frame = nullptr;
Enrico Granatac1f705c2015-07-06 18:28:46 +00001626 Target *target = exe_ctx.GetTargetPtr();
1627 Process *process = exe_ctx.GetProcessPtr();
1628 if (target && process)
1629 {
1630 Process::StopLocker stop_locker;
1631 if (stop_locker.TryLock(&process->GetRunLock()))
1632 {
1633 frame = exe_ctx.GetFramePtr();
1634 if (frame)
1635 {
1636 SymbolContext sc (frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol));
1637 if (sc.block)
1638 {
1639 Block *inlined_block = sc.block->GetContainingInlinedBlock ();
1640 if (inlined_block)
1641 {
1642 const InlineFunctionInfo* inlined_info = inlined_block->GetInlinedFunctionInfo();
Greg Claytonddaf6a72015-07-08 22:32:23 +00001643 name = inlined_info->GetDisplayName(sc.function->GetLanguage()).AsCString();
Enrico Granatac1f705c2015-07-06 18:28:46 +00001644 }
1645 }
1646
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001647 if (name == nullptr)
Enrico Granatac1f705c2015-07-06 18:28:46 +00001648 {
1649 if (sc.function)
1650 name = sc.function->GetDisplayName().GetCString();
1651 }
1652
Eugene Zelenkodbb0abb2015-10-31 01:22:59 +00001653 if (name == nullptr)
Enrico Granatac1f705c2015-07-06 18:28:46 +00001654 {
1655 if (sc.symbol)
1656 name = sc.symbol->GetDisplayName().GetCString();
1657 }
1658 }
1659 else
1660 {
1661 if (log)
1662 log->Printf ("SBFrame::GetDisplayFunctionName () => error: could not reconstruct frame object for this SBFrame.");
1663 }
1664 }
1665 else
1666 {
1667 if (log)
1668 log->Printf ("SBFrame::GetDisplayFunctionName() => error: process is running");
1669
1670 }
1671 }
1672 return name;
1673}