blob: 224b6663a423a35b1eee62796e9c4b3c67c87d68 [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
Eli Friedman4c5de692010-06-09 07:44:37 +000010#include "lldb/API/SBFrame.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000011
12#include <string>
13#include <algorithm>
14
15#include "lldb/lldb-types.h"
16
17#include "lldb/Core/Address.h"
18#include "lldb/Core/ConstString.h"
Caroline Ticeceb6b132010-10-26 03:11:13 +000019#include "lldb/Core/Log.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020#include "lldb/Core/Stream.h"
21#include "lldb/Core/StreamFile.h"
22#include "lldb/Core/ValueObjectRegister.h"
23#include "lldb/Core/ValueObjectVariable.h"
Zachary Turneraf0f45f2015-03-03 21:05:17 +000024#include "lldb/Expression/ClangPersistentVariables.h"
Greg Claytonb71f3842010-10-05 03:13:51 +000025#include "lldb/Expression/ClangUserExpression.h"
Greg Clayton1ba7c4d2011-06-25 04:35:01 +000026#include "lldb/Host/Host.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027#include "lldb/Symbol/Block.h"
Greg Clayton1f746072012-08-29 21:13:06 +000028#include "lldb/Symbol/Function.h"
29#include "lldb/Symbol/Symbol.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030#include "lldb/Symbol/SymbolContext.h"
31#include "lldb/Symbol/VariableList.h"
32#include "lldb/Symbol/Variable.h"
33#include "lldb/Target/ExecutionContext.h"
34#include "lldb/Target/Target.h"
35#include "lldb/Target/Process.h"
36#include "lldb/Target/RegisterContext.h"
Jason Molendab57e4a12013-11-04 09:33:30 +000037#include "lldb/Target/StackFrame.h"
Greg Claytonb9556ac2012-01-30 07:41:31 +000038#include "lldb/Target/StackID.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039#include "lldb/Target/Thread.h"
40
Eli Friedman4c5de692010-06-09 07:44:37 +000041#include "lldb/API/SBDebugger.h"
42#include "lldb/API/SBValue.h"
43#include "lldb/API/SBAddress.h"
Jim Ingham35e1bda2012-10-16 21:41:58 +000044#include "lldb/API/SBExpressionOptions.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000045#include "lldb/API/SBStream.h"
Eli Friedman4c5de692010-06-09 07:44:37 +000046#include "lldb/API/SBSymbolContext.h"
47#include "lldb/API/SBThread.h"
Zachary Turner51f96ee2015-02-17 17:55:50 +000048#include "lldb/API/SBVariablesOptions.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049
50using namespace lldb;
51using namespace lldb_private;
52
Greg Claytonb9556ac2012-01-30 07:41:31 +000053
Chris Lattner30fdc8d2010-06-08 16:52:24 +000054SBFrame::SBFrame () :
Greg Clayton7fdf9ef2012-04-05 16:12:35 +000055 m_opaque_sp (new ExecutionContextRef())
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056{
57}
58
Jason Molendab57e4a12013-11-04 09:33:30 +000059SBFrame::SBFrame (const StackFrameSP &lldb_object_sp) :
Greg Clayton7fdf9ef2012-04-05 16:12:35 +000060 m_opaque_sp (new ExecutionContextRef (lldb_object_sp))
Chris Lattner30fdc8d2010-06-08 16:52:24 +000061{
Greg Clayton5160ce52013-03-27 23:08:40 +000062 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +000063
64 if (log)
65 {
66 SBStream sstr;
67 GetDescription (sstr);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000068 log->Printf ("SBFrame::SBFrame (sp=%p) => SBFrame(%p): %s",
69 static_cast<void*>(lldb_object_sp.get()),
70 static_cast<void*>(lldb_object_sp.get()), sstr.GetData());
Caroline Ticeceb6b132010-10-26 03:11:13 +000071 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000072}
73
Greg Claytonefabb122010-11-05 23:17:00 +000074SBFrame::SBFrame(const SBFrame &rhs) :
Greg Clayton7fdf9ef2012-04-05 16:12:35 +000075 m_opaque_sp (new ExecutionContextRef (*rhs.m_opaque_sp))
Greg Claytonefabb122010-11-05 23:17:00 +000076{
77}
78
79const SBFrame &
80SBFrame::operator = (const SBFrame &rhs)
81{
82 if (this != &rhs)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +000083 *m_opaque_sp = *rhs.m_opaque_sp;
Greg Claytonefabb122010-11-05 23:17:00 +000084 return *this;
85}
86
Chris Lattner30fdc8d2010-06-08 16:52:24 +000087SBFrame::~SBFrame()
88{
89}
90
Jason Molendab57e4a12013-11-04 09:33:30 +000091StackFrameSP
Greg Claytonb9556ac2012-01-30 07:41:31 +000092SBFrame::GetFrameSP() const
Chris Lattner30fdc8d2010-06-08 16:52:24 +000093{
Greg Claytonaf2589e2012-04-12 20:58:26 +000094 if (m_opaque_sp)
95 return m_opaque_sp->GetFrameSP();
Jason Molendab57e4a12013-11-04 09:33:30 +000096 return StackFrameSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000097}
98
Greg Claytonb9556ac2012-01-30 07:41:31 +000099void
Jason Molendab57e4a12013-11-04 09:33:30 +0000100SBFrame::SetFrameSP (const StackFrameSP &lldb_object_sp)
Greg Claytonb9556ac2012-01-30 07:41:31 +0000101{
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000102 return m_opaque_sp->SetFrameSP(lldb_object_sp);
Greg Claytonb9556ac2012-01-30 07:41:31 +0000103}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000104
105bool
106SBFrame::IsValid() const
107{
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000108 return GetFrameSP().get() != NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000109}
110
111SBSymbolContext
112SBFrame::GetSymbolContext (uint32_t resolve_scope) const
113{
Greg Clayton5160ce52013-03-27 23:08:40 +0000114 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000115 SBSymbolContext sb_sym_ctx;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000116 Mutex::Locker api_locker;
117 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
118
Jason Molendab57e4a12013-11-04 09:33:30 +0000119 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000120 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000121 Process *process = exe_ctx.GetProcessPtr();
122 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000123 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000124 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000125 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000126 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000127 frame = exe_ctx.GetFramePtr();
128 if (frame)
129 {
130 sb_sym_ctx.SetSymbolContext(&frame->GetSymbolContext (resolve_scope));
131 }
132 else
133 {
134 if (log)
135 log->Printf ("SBFrame::GetVariables () => error: could not reconstruct frame object for this SBFrame.");
136 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000137 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000138 else
139 {
140 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000141 log->Printf ("SBFrame::GetSymbolContext () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000142 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000143 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000144
145 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000146 log->Printf ("SBFrame(%p)::GetSymbolContext (resolve_scope=0x%8.8x) => SBSymbolContext(%p)",
147 static_cast<void*>(frame), resolve_scope,
148 static_cast<void*>(sb_sym_ctx.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000149
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000150 return sb_sym_ctx;
151}
152
153SBModule
154SBFrame::GetModule () const
155{
Greg Clayton5160ce52013-03-27 23:08:40 +0000156 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton72eff182010-12-14 04:58:53 +0000157 SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +0000158 ModuleSP module_sp;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000159 Mutex::Locker api_locker;
160 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
161
Jason Molendab57e4a12013-11-04 09:33:30 +0000162 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000163 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000164 Process *process = exe_ctx.GetProcessPtr();
165 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000166 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000167 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000168 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000169 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000170 frame = exe_ctx.GetFramePtr();
171 if (frame)
172 {
173 module_sp = frame->GetSymbolContext (eSymbolContextModule).module_sp;
174 sb_module.SetSP (module_sp);
175 }
176 else
177 {
178 if (log)
179 log->Printf ("SBFrame::GetModule () => error: could not reconstruct frame object for this SBFrame.");
180 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000181 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000182 else
183 {
184 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000185 log->Printf ("SBFrame::GetModule () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000186 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000187 }
Greg Clayton72eff182010-12-14 04:58:53 +0000188
Greg Clayton48381312010-10-30 04:51:46 +0000189 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000190 log->Printf ("SBFrame(%p)::GetModule () => SBModule(%p)",
191 static_cast<void*>(frame),
192 static_cast<void*>(module_sp.get()));
Greg Clayton48381312010-10-30 04:51:46 +0000193
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000194 return sb_module;
195}
196
197SBCompileUnit
198SBFrame::GetCompileUnit () const
199{
Greg Clayton5160ce52013-03-27 23:08:40 +0000200 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton72eff182010-12-14 04:58:53 +0000201 SBCompileUnit sb_comp_unit;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000202 Mutex::Locker api_locker;
203 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
204
Jason Molendab57e4a12013-11-04 09:33:30 +0000205 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000206 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000207 Process *process = exe_ctx.GetProcessPtr();
208 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000209 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000210 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000211 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000212 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000213 frame = exe_ctx.GetFramePtr();
214 if (frame)
215 {
216 sb_comp_unit.reset (frame->GetSymbolContext (eSymbolContextCompUnit).comp_unit);
217 }
218 else
219 {
220 if (log)
221 log->Printf ("SBFrame::GetCompileUnit () => error: could not reconstruct frame object for this SBFrame.");
222 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000223 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000224 else
225 {
226 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000227 log->Printf ("SBFrame::GetCompileUnit () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000228 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000229 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000230 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000231 log->Printf ("SBFrame(%p)::GetCompileUnit () => SBCompileUnit(%p)",
232 static_cast<void*>(frame),
233 static_cast<void*>(sb_comp_unit.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000234
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000235 return sb_comp_unit;
236}
237
238SBFunction
239SBFrame::GetFunction () const
240{
Greg Clayton5160ce52013-03-27 23:08:40 +0000241 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton72eff182010-12-14 04:58:53 +0000242 SBFunction sb_function;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000243 Mutex::Locker api_locker;
244 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
245
Jason Molendab57e4a12013-11-04 09:33:30 +0000246 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000247 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000248 Process *process = exe_ctx.GetProcessPtr();
249 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000250 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000251 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000252 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000253 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000254 frame = exe_ctx.GetFramePtr();
255 if (frame)
256 {
257 sb_function.reset(frame->GetSymbolContext (eSymbolContextFunction).function);
258 }
259 else
260 {
261 if (log)
262 log->Printf ("SBFrame::GetFunction () => error: could not reconstruct frame object for this SBFrame.");
263 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000264 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000265 else
266 {
267 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000268 log->Printf ("SBFrame::GetFunction () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000269 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000270 }
Greg Clayton48381312010-10-30 04:51:46 +0000271 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000272 log->Printf ("SBFrame(%p)::GetFunction () => SBFunction(%p)",
273 static_cast<void*>(frame),
274 static_cast<void*>(sb_function.get()));
Greg Clayton48381312010-10-30 04:51:46 +0000275
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000276 return sb_function;
277}
278
Greg Clayton3b065572010-10-04 18:37:52 +0000279SBSymbol
280SBFrame::GetSymbol () const
281{
Greg Clayton5160ce52013-03-27 23:08:40 +0000282 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton72eff182010-12-14 04:58:53 +0000283 SBSymbol sb_symbol;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000284 Mutex::Locker api_locker;
285 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
286
Jason Molendab57e4a12013-11-04 09:33:30 +0000287 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000288 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000289 Process *process = exe_ctx.GetProcessPtr();
290 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000291 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000292 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000293 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000294 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000295 frame = exe_ctx.GetFramePtr();
296 if (frame)
297 {
298 sb_symbol.reset(frame->GetSymbolContext (eSymbolContextSymbol).symbol);
299 }
300 else
301 {
302 if (log)
303 log->Printf ("SBFrame::GetSymbol () => error: could not reconstruct frame object for this SBFrame.");
304 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000305 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000306 else
307 {
308 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000309 log->Printf ("SBFrame::GetSymbol () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000310 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000311 }
Greg Clayton48381312010-10-30 04:51:46 +0000312 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000313 log->Printf ("SBFrame(%p)::GetSymbol () => SBSymbol(%p)",
314 static_cast<void*>(frame),
315 static_cast<void*>(sb_symbol.get()));
Greg Clayton3b065572010-10-04 18:37:52 +0000316 return sb_symbol;
317}
318
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000319SBBlock
320SBFrame::GetBlock () const
321{
Greg Clayton5160ce52013-03-27 23:08:40 +0000322 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton72eff182010-12-14 04:58:53 +0000323 SBBlock sb_block;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000324 Mutex::Locker api_locker;
325 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
326
Jason Molendab57e4a12013-11-04 09:33:30 +0000327 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000328 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000329 Process *process = exe_ctx.GetProcessPtr();
330 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000331 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000332 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000333 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000334 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000335 frame = exe_ctx.GetFramePtr();
336 if (frame)
337 {
338 sb_block.SetPtr (frame->GetSymbolContext (eSymbolContextBlock).block);
339 }
340 else
341 {
342 if (log)
343 log->Printf ("SBFrame::GetBlock () => error: could not reconstruct frame object for this SBFrame.");
344 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000345 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000346 else
347 {
348 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000349 log->Printf ("SBFrame(%p)::GetBlock () => error: process is running",
350 static_cast<void*>(frame));
Greg Claytonc9858e42012-04-06 02:17:47 +0000351 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000352 }
Greg Clayton48381312010-10-30 04:51:46 +0000353 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000354 log->Printf ("SBFrame(%p)::GetBlock () => SBBlock(%p)",
355 static_cast<void*>(frame),
356 static_cast<void*>(sb_block.GetPtr()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000357 return sb_block;
358}
359
Greg Clayton95897c62010-09-07 04:20:48 +0000360SBBlock
361SBFrame::GetFrameBlock () const
362{
Greg Clayton72eff182010-12-14 04:58:53 +0000363 SBBlock sb_block;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000364 Mutex::Locker api_locker;
365 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
366
Jason Molendab57e4a12013-11-04 09:33:30 +0000367 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000368 Target *target = exe_ctx.GetTargetPtr();
Greg Clayton5160ce52013-03-27 23:08:40 +0000369 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham7730b9a2012-11-29 00:26:19 +0000370 Process *process = exe_ctx.GetProcessPtr();
371 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000372 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000373 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000374 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000375 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000376 frame = exe_ctx.GetFramePtr();
377 if (frame)
378 {
379 sb_block.SetPtr(frame->GetFrameBlock ());
380 }
381 else
382 {
383 if (log)
384 log->Printf ("SBFrame::GetFrameBlock () => error: could not reconstruct frame object for this SBFrame.");
385 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000386 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000387 else
388 {
389 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000390 log->Printf ("SBFrame::GetFrameBlock () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000391 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000392 }
Greg Clayton48381312010-10-30 04:51:46 +0000393 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000394 log->Printf ("SBFrame(%p)::GetFrameBlock () => SBBlock(%p)",
395 static_cast<void*>(frame),
396 static_cast<void*>(sb_block.GetPtr()));
Greg Clayton95897c62010-09-07 04:20:48 +0000397 return sb_block;
398}
399
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000400SBLineEntry
401SBFrame::GetLineEntry () const
402{
Greg Clayton5160ce52013-03-27 23:08:40 +0000403 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton72eff182010-12-14 04:58:53 +0000404 SBLineEntry sb_line_entry;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000405 Mutex::Locker api_locker;
406 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
407
Jason Molendab57e4a12013-11-04 09:33:30 +0000408 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000409 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000410 Process *process = exe_ctx.GetProcessPtr();
411 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000412 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000413 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000414 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000415 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000416 frame = exe_ctx.GetFramePtr();
417 if (frame)
418 {
419 sb_line_entry.SetLineEntry (frame->GetSymbolContext (eSymbolContextLineEntry).line_entry);
420 }
421 else
422 {
423 if (log)
424 log->Printf ("SBFrame::GetLineEntry () => error: could not reconstruct frame object for this SBFrame.");
425 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000426 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000427 else
428 {
429 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000430 log->Printf ("SBFrame::GetLineEntry () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000431 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000432 }
Greg Clayton48381312010-10-30 04:51:46 +0000433 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000434 log->Printf ("SBFrame(%p)::GetLineEntry () => SBLineEntry(%p)",
435 static_cast<void*>(frame),
436 static_cast<void*>(sb_line_entry.get()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000437 return sb_line_entry;
438}
439
440uint32_t
441SBFrame::GetFrameID () const
442{
Greg Claytonb9556ac2012-01-30 07:41:31 +0000443 uint32_t frame_idx = UINT32_MAX;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000444
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000445 ExecutionContext exe_ctx(m_opaque_sp.get());
Jason Molendab57e4a12013-11-04 09:33:30 +0000446 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000447 if (frame)
Greg Claytond9e416c2012-02-18 05:35:26 +0000448 frame_idx = frame->GetFrameIndex ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000449
Greg Clayton5160ce52013-03-27 23:08:40 +0000450 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000451 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000452 log->Printf ("SBFrame(%p)::GetFrameID () => %u",
453 static_cast<void*>(frame), frame_idx);
Greg Clayton48381312010-10-30 04:51:46 +0000454 return frame_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000455}
456
Greg Clayton424a5db2015-05-28 03:27:22 +0000457lldb::addr_t
458SBFrame::GetCFA () const
459{
460 ExecutionContext exe_ctx(m_opaque_sp.get());
461 StackFrame *frame = exe_ctx.GetFramePtr();
462 if (frame)
463 return frame->GetStackID().GetCallFrameAddress();
464 return LLDB_INVALID_ADDRESS;
465}
466
467
Greg Clayton69b582f2010-12-14 18:39:31 +0000468addr_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000469SBFrame::GetPC () const
470{
Greg Clayton5160ce52013-03-27 23:08:40 +0000471 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton69b582f2010-12-14 18:39:31 +0000472 addr_t addr = LLDB_INVALID_ADDRESS;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000473 Mutex::Locker api_locker;
474 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
475
Jason Molendab57e4a12013-11-04 09:33:30 +0000476 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000477 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000478 Process *process = exe_ctx.GetProcessPtr();
479 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000480 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000481 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000482 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000483 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000484 frame = exe_ctx.GetFramePtr();
485 if (frame)
486 {
487 addr = frame->GetFrameCodeAddress().GetOpcodeLoadAddress (target);
488 }
489 else
490 {
491 if (log)
492 log->Printf ("SBFrame::GetPC () => error: could not reconstruct frame object for this SBFrame.");
493 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000494 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000495 else
496 {
497 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000498 log->Printf ("SBFrame::GetPC () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000499 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000500 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000501
502 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000503 log->Printf ("SBFrame(%p)::GetPC () => 0x%" PRIx64,
504 static_cast<void*>(frame), addr);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000505
506 return addr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000507}
508
509bool
Greg Clayton69b582f2010-12-14 18:39:31 +0000510SBFrame::SetPC (addr_t new_pc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000511{
Greg Clayton5160ce52013-03-27 23:08:40 +0000512 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000513 bool ret_val = false;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000514 Mutex::Locker api_locker;
515 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
516
Jason Molendab57e4a12013-11-04 09:33:30 +0000517 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000518 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000519 Process *process = exe_ctx.GetProcessPtr();
520 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000521 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000522 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000523 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000524 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000525 frame = exe_ctx.GetFramePtr();
526 if (frame)
527 {
528 ret_val = frame->GetRegisterContext()->SetPC (new_pc);
529 }
530 else
531 {
532 if (log)
533 log->Printf ("SBFrame::SetPC () => error: could not reconstruct frame object for this SBFrame.");
534 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000535 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000536 else
537 {
538 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000539 log->Printf ("SBFrame::SetPC () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000540 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000541 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000542
543 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +0000544 log->Printf ("SBFrame(%p)::SetPC (new_pc=0x%" PRIx64 ") => %i",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000545 static_cast<void*>(frame), new_pc, ret_val);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000546
547 return ret_val;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000548}
549
Greg Clayton69b582f2010-12-14 18:39:31 +0000550addr_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000551SBFrame::GetSP () const
552{
Greg Clayton5160ce52013-03-27 23:08:40 +0000553 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000554 addr_t addr = LLDB_INVALID_ADDRESS;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000555 Mutex::Locker api_locker;
556 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
557
Jason Molendab57e4a12013-11-04 09:33:30 +0000558 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000559 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000560 Process *process = exe_ctx.GetProcessPtr();
561 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000562 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000563 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000564 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000565 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000566 frame = exe_ctx.GetFramePtr();
567 if (frame)
568 {
569 addr = frame->GetRegisterContext()->GetSP();
570 }
571 else
572 {
573 if (log)
574 log->Printf ("SBFrame::GetSP () => error: could not reconstruct frame object for this SBFrame.");
575 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000576 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000577 else
578 {
579 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000580 log->Printf ("SBFrame::GetSP () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000581 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000582 }
Greg Clayton48381312010-10-30 04:51:46 +0000583 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000584 log->Printf ("SBFrame(%p)::GetSP () => 0x%" PRIx64,
585 static_cast<void*>(frame), addr);
Greg Clayton48381312010-10-30 04:51:46 +0000586
587 return addr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000588}
589
590
Greg Clayton69b582f2010-12-14 18:39:31 +0000591addr_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000592SBFrame::GetFP () const
593{
Greg Clayton5160ce52013-03-27 23:08:40 +0000594 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton69b582f2010-12-14 18:39:31 +0000595 addr_t addr = LLDB_INVALID_ADDRESS;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000596 Mutex::Locker api_locker;
597 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
598
Jason Molendab57e4a12013-11-04 09:33:30 +0000599 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000600 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000601 Process *process = exe_ctx.GetProcessPtr();
602 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000603 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000604 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000605 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000606 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000607 frame = exe_ctx.GetFramePtr();
608 if (frame)
609 {
610 addr = frame->GetRegisterContext()->GetFP();
611 }
612 else
613 {
614 if (log)
615 log->Printf ("SBFrame::GetFP () => error: could not reconstruct frame object for this SBFrame.");
616 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000617 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000618 else
619 {
620 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000621 log->Printf ("SBFrame::GetFP () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000622 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000623 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000624
625 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000626 log->Printf ("SBFrame(%p)::GetFP () => 0x%" PRIx64,
627 static_cast<void*>(frame), addr);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000628 return addr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000629}
630
631
632SBAddress
633SBFrame::GetPCAddress () const
634{
Greg Clayton5160ce52013-03-27 23:08:40 +0000635 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000636 SBAddress sb_addr;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000637 Mutex::Locker api_locker;
638 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
639
Jason Molendab57e4a12013-11-04 09:33:30 +0000640 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Claytond9e416c2012-02-18 05:35:26 +0000641 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000642 Process *process = exe_ctx.GetProcessPtr();
643 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000644 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000645 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000646 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000647 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000648 frame = exe_ctx.GetFramePtr();
649 if (frame)
650 {
651 sb_addr.SetAddress (&frame->GetFrameCodeAddress());
652 }
653 else
654 {
655 if (log)
656 log->Printf ("SBFrame::GetPCAddress () => error: could not reconstruct frame object for this SBFrame.");
657 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000658 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000659 else
660 {
661 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000662 log->Printf ("SBFrame::GetPCAddress () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000663 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000664 }
Greg Clayton48381312010-10-30 04:51:46 +0000665 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000666 log->Printf ("SBFrame(%p)::GetPCAddress () => SBAddress(%p)",
667 static_cast<void*>(frame),
668 static_cast<void*>(sb_addr.get()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000669 return sb_addr;
670}
671
672void
673SBFrame::Clear()
674{
Greg Claytonaf2589e2012-04-12 20:58:26 +0000675 m_opaque_sp->Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000676}
677
Greg Clayton7edbdfc2012-02-03 07:02:37 +0000678lldb::SBValue
679SBFrame::GetValueForVariablePath (const char *var_path)
680{
681 SBValue sb_value;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000682 ExecutionContext exe_ctx(m_opaque_sp.get());
Jason Molendab57e4a12013-11-04 09:33:30 +0000683 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Claytond9e416c2012-02-18 05:35:26 +0000684 Target *target = exe_ctx.GetTargetPtr();
685 if (frame && target)
Greg Clayton7edbdfc2012-02-03 07:02:37 +0000686 {
Greg Claytonc9858e42012-04-06 02:17:47 +0000687 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
688 sb_value = GetValueForVariablePath (var_path, use_dynamic);
Greg Clayton7edbdfc2012-02-03 07:02:37 +0000689 }
690 return sb_value;
691}
692
693lldb::SBValue
694SBFrame::GetValueForVariablePath (const char *var_path, DynamicValueType use_dynamic)
695{
696 SBValue sb_value;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000697 Mutex::Locker api_locker;
Greg Clayton5160ce52013-03-27 23:08:40 +0000698 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham7730b9a2012-11-29 00:26:19 +0000699 if (var_path == NULL || var_path[0] == '\0')
700 {
701 if (log)
702 log->Printf ("SBFrame::GetValueForVariablePath called with empty variable path.");
703 return sb_value;
704 }
705
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000706 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
707
Jason Molendab57e4a12013-11-04 09:33:30 +0000708 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000709 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000710 Process *process = exe_ctx.GetProcessPtr();
711 if (target && process)
Greg Clayton7edbdfc2012-02-03 07:02:37 +0000712 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000713 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000714 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000715 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000716 frame = exe_ctx.GetFramePtr();
717 if (frame)
718 {
719 VariableSP var_sp;
720 Error error;
721 ValueObjectSP value_sp (frame->GetValueForVariableExpressionPath (var_path,
722 eNoDynamicValues,
Jason Molendab57e4a12013-11-04 09:33:30 +0000723 StackFrame::eExpressionPathOptionCheckPtrVsMember | StackFrame::eExpressionPathOptionsAllowDirectIVarAccess,
Jim Ingham7730b9a2012-11-29 00:26:19 +0000724 var_sp,
725 error));
726 sb_value.SetSP(value_sp, use_dynamic);
727 }
728 else
729 {
730 if (log)
731 log->Printf ("SBFrame::GetValueForVariablePath () => error: could not reconstruct frame object for this SBFrame.");
732 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000733 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000734 else
735 {
Greg Claytonc9858e42012-04-06 02:17:47 +0000736 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000737 log->Printf ("SBFrame::GetValueForVariablePath () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000738 }
Greg Clayton7edbdfc2012-02-03 07:02:37 +0000739 }
740 return sb_value;
741}
742
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000743SBValue
Greg Clayton69b582f2010-12-14 18:39:31 +0000744SBFrame::FindVariable (const char *name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000745{
Greg Clayton316d4982011-06-18 20:06:08 +0000746 SBValue value;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000747 ExecutionContext exe_ctx(m_opaque_sp.get());
Jason Molendab57e4a12013-11-04 09:33:30 +0000748 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Claytond9e416c2012-02-18 05:35:26 +0000749 Target *target = exe_ctx.GetTargetPtr();
750 if (frame && target)
Greg Clayton316d4982011-06-18 20:06:08 +0000751 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000752 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton316d4982011-06-18 20:06:08 +0000753 value = FindVariable (name, use_dynamic);
754 }
755 return value;
Jim Ingham78a685a2011-04-16 00:01:13 +0000756}
757
758SBValue
Jim Ingham2837b762011-05-04 03:43:18 +0000759SBFrame::FindVariable (const char *name, lldb::DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +0000760{
Greg Clayton5160ce52013-03-27 23:08:40 +0000761 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton69b582f2010-12-14 18:39:31 +0000762 VariableSP var_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +0000763 SBValue sb_value;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000764
765 if (name == NULL || name[0] == '\0')
766 {
767 if (log)
768 log->Printf ("SBFrame::FindVariable called with empty name");
769 return sb_value;
770 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000771
Greg Clayton81e871e2012-02-04 02:27:34 +0000772 ValueObjectSP value_sp;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000773 Mutex::Locker api_locker;
774 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
775
Jason Molendab57e4a12013-11-04 09:33:30 +0000776 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000777 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000778 Process *process = exe_ctx.GetProcessPtr();
779 if (target && process)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000780 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000781 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000782 if (stop_locker.TryLock(&process->GetRunLock()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000783 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000784 frame = exe_ctx.GetFramePtr();
785 if (frame)
Greg Clayton72eff182010-12-14 04:58:53 +0000786 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000787 VariableList variable_list;
788 SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock));
789
790 if (sc.block)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000791 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000792 const bool can_create = true;
793 const bool get_parent_variables = true;
794 const bool stop_if_block_is_inlined_function = true;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000795
Jim Ingham7730b9a2012-11-29 00:26:19 +0000796 if (sc.block->AppendVariables (can_create,
797 get_parent_variables,
798 stop_if_block_is_inlined_function,
799 &variable_list))
800 {
801 var_sp = variable_list.FindVariable (ConstString(name));
802 }
803 }
804
805 if (var_sp)
806 {
807 value_sp = frame->GetValueObjectForFrameVariable(var_sp, eNoDynamicValues);
808 sb_value.SetSP(value_sp, use_dynamic);
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000809 }
810 }
Jim Ingham7730b9a2012-11-29 00:26:19 +0000811 else
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000812 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000813 if (log)
814 log->Printf ("SBFrame::FindVariable () => error: could not reconstruct frame object for this SBFrame.");
Greg Clayton72eff182010-12-14 04:58:53 +0000815 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000816 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000817 else
818 {
819 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000820 log->Printf ("SBFrame::FindVariable () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000821 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000822 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000823
Greg Clayton48381312010-10-30 04:51:46 +0000824 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000825 log->Printf ("SBFrame(%p)::FindVariable (name=\"%s\") => SBValue(%p)",
826 static_cast<void*>(frame), name,
827 static_cast<void*>(value_sp.get()));
Greg Clayton48381312010-10-30 04:51:46 +0000828
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000829 return sb_value;
830}
831
832SBValue
Greg Clayton69b582f2010-12-14 18:39:31 +0000833SBFrame::FindValue (const char *name, ValueType value_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000834{
Greg Clayton316d4982011-06-18 20:06:08 +0000835 SBValue value;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000836 ExecutionContext exe_ctx(m_opaque_sp.get());
Jason Molendab57e4a12013-11-04 09:33:30 +0000837 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Claytond9e416c2012-02-18 05:35:26 +0000838 Target *target = exe_ctx.GetTargetPtr();
839 if (frame && target)
Greg Clayton316d4982011-06-18 20:06:08 +0000840 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000841 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton316d4982011-06-18 20:06:08 +0000842 value = FindValue (name, value_type, use_dynamic);
843 }
844 return value;
Jim Ingham78a685a2011-04-16 00:01:13 +0000845}
846
847SBValue
Jim Ingham2837b762011-05-04 03:43:18 +0000848SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +0000849{
Greg Clayton5160ce52013-03-27 23:08:40 +0000850 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton69b582f2010-12-14 18:39:31 +0000851 SBValue sb_value;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000852
Jim Ingham7730b9a2012-11-29 00:26:19 +0000853 if (name == NULL || name[0] == '\0')
854 {
855 if (log)
856 log->Printf ("SBFrame::FindValue called with empty name.");
857 return sb_value;
858 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000859
Greg Clayton81e871e2012-02-04 02:27:34 +0000860 ValueObjectSP value_sp;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000861 Mutex::Locker api_locker;
862 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
863
Jason Molendab57e4a12013-11-04 09:33:30 +0000864 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000865 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000866 Process *process = exe_ctx.GetProcessPtr();
867 if (target && process)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000868 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000869 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000870 if (stop_locker.TryLock(&process->GetRunLock()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000871 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000872 frame = exe_ctx.GetFramePtr();
873 if (frame)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000874 {
Enrico Granata8a2a0df2014-02-19 19:35:13 +0000875 VariableList variable_list;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000876
Jim Ingham7730b9a2012-11-29 00:26:19 +0000877 switch (value_type)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000878 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000879 case eValueTypeVariableGlobal: // global variable
880 case eValueTypeVariableStatic: // static variable
881 case eValueTypeVariableArgument: // function argument variables
882 case eValueTypeVariableLocal: // function local variables
883 {
Chaoren Lin0efb51a2015-03-19 22:00:13 +0000884 SymbolContext sc(frame->GetSymbolContext(eSymbolContextBlock));
Greg Clayton69b582f2010-12-14 18:39:31 +0000885
Jim Ingham7730b9a2012-11-29 00:26:19 +0000886 const bool can_create = true;
887 const bool get_parent_variables = true;
888 const bool stop_if_block_is_inlined_function = true;
Greg Clayton69b582f2010-12-14 18:39:31 +0000889
Chaoren Lin0efb51a2015-03-19 22:00:13 +0000890 if (sc.block)
891 sc.block->AppendVariables(can_create,
892 get_parent_variables,
893 stop_if_block_is_inlined_function,
894 &variable_list);
895 if (value_type == eValueTypeVariableGlobal)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000896 {
Chaoren Lin0efb51a2015-03-19 22:00:13 +0000897 const bool get_file_globals = true;
898 VariableList *frame_vars = frame->GetVariableList(get_file_globals);
899 if (frame_vars)
900 frame_vars->AppendVariablesIfUnique(variable_list);
901 }
902 ConstString const_name(name);
903 VariableSP variable_sp(variable_list.FindVariable(const_name, value_type));
904 if (variable_sp)
905 {
906 value_sp = frame->GetValueObjectForFrameVariable(variable_sp, eNoDynamicValues);
907 sb_value.SetSP(value_sp, use_dynamic);
Jim Ingham7730b9a2012-11-29 00:26:19 +0000908 }
909 }
910 break;
911
912 case eValueTypeRegister: // stack frame register value
913 {
914 RegisterContextSP reg_ctx (frame->GetRegisterContext());
915 if (reg_ctx)
916 {
917 const uint32_t num_regs = reg_ctx->GetRegisterCount();
918 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx)
919 {
920 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
921 if (reg_info &&
922 ((reg_info->name && strcasecmp (reg_info->name, name) == 0) ||
923 (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0)))
924 {
925 value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx);
926 sb_value.SetSP (value_sp);
927 break;
928 }
929 }
930 }
931 }
932 break;
933
934 case eValueTypeRegisterSet: // A collection of stack frame register values
935 {
936 RegisterContextSP reg_ctx (frame->GetRegisterContext());
937 if (reg_ctx)
938 {
939 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
940 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
941 {
942 const RegisterSet *reg_set = reg_ctx->GetRegisterSet (set_idx);
943 if (reg_set &&
944 ((reg_set->name && strcasecmp (reg_set->name, name) == 0) ||
945 (reg_set->short_name && strcasecmp (reg_set->short_name, name) == 0)))
946 {
947 value_sp = ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx);
948 sb_value.SetSP (value_sp);
949 break;
950 }
951 }
952 }
953 }
954 break;
955
956 case eValueTypeConstResult: // constant result variables
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000957 {
958 ConstString const_name(name);
Jim Ingham7730b9a2012-11-29 00:26:19 +0000959 ClangExpressionVariableSP expr_var_sp (target->GetPersistentVariables().GetVariable (const_name));
960 if (expr_var_sp)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000961 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000962 value_sp = expr_var_sp->GetValueObject();
963 sb_value.SetSP (value_sp, use_dynamic);
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000964 }
965 }
Jim Ingham7730b9a2012-11-29 00:26:19 +0000966 break;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000967
Jim Ingham7730b9a2012-11-29 00:26:19 +0000968 default:
969 break;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000970 }
Jim Ingham7730b9a2012-11-29 00:26:19 +0000971 }
972 else
973 {
974 if (log)
975 log->Printf ("SBFrame::FindValue () => error: could not reconstruct frame object for this SBFrame.");
Greg Clayton69b582f2010-12-14 18:39:31 +0000976 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000977 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000978 else
979 {
980 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000981 log->Printf ("SBFrame::FindValue () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000982 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000983 }
Greg Clayton48381312010-10-30 04:51:46 +0000984
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000985 if (log)
986 log->Printf ("SBFrame(%p)::FindVariableInScope (name=\"%s\", value_type=%i) => SBValue(%p)",
987 static_cast<void*>(frame), name, value_type,
988 static_cast<void*>(value_sp.get()));
989
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000990 return sb_value;
991}
992
993bool
Johnny Chen35e2ab62012-03-05 19:53:24 +0000994SBFrame::IsEqual (const SBFrame &that) const
995{
Jason Molendab57e4a12013-11-04 09:33:30 +0000996 lldb::StackFrameSP this_sp = GetFrameSP();
997 lldb::StackFrameSP that_sp = that.GetFrameSP();
Johnny Chen35e2ab62012-03-05 19:53:24 +0000998 return (this_sp && that_sp && this_sp->GetStackID() == that_sp->GetStackID());
999}
1000
1001bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001002SBFrame::operator == (const SBFrame &rhs) const
1003{
Johnny Chen35e2ab62012-03-05 19:53:24 +00001004 return IsEqual(rhs);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001005}
1006
1007bool
1008SBFrame::operator != (const SBFrame &rhs) const
1009{
Johnny Chen35e2ab62012-03-05 19:53:24 +00001010 return !IsEqual(rhs);
Greg Clayton481cef22011-01-21 06:11:58 +00001011}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001012
1013SBThread
1014SBFrame::GetThread () const
1015{
Greg Clayton5160ce52013-03-27 23:08:40 +00001016 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001017
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001018 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Claytond9e416c2012-02-18 05:35:26 +00001019 ThreadSP thread_sp (exe_ctx.GetThreadSP());
1020 SBThread sb_thread (thread_sp);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001021
1022 if (log)
Caroline Tice750cd172010-10-26 23:49:36 +00001023 {
1024 SBStream sstr;
1025 sb_thread.GetDescription (sstr);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001026 log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s",
1027 static_cast<void*>(exe_ctx.GetFramePtr()),
1028 static_cast<void*>(thread_sp.get()), sstr.GetData());
Caroline Tice750cd172010-10-26 23:49:36 +00001029 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001030
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001031 return sb_thread;
1032}
1033
1034const char *
1035SBFrame::Disassemble () const
1036{
Greg Clayton5160ce52013-03-27 23:08:40 +00001037 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +00001038 const char *disassembly = NULL;
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001039 Mutex::Locker api_locker;
1040 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1041
Jason Molendab57e4a12013-11-04 09:33:30 +00001042 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +00001043 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +00001044 Process *process = exe_ctx.GetProcessPtr();
1045 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001046 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001047 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001048 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001049 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001050 frame = exe_ctx.GetFramePtr();
1051 if (frame)
1052 {
1053 disassembly = frame->Disassemble();
1054 }
1055 else
1056 {
1057 if (log)
1058 log->Printf ("SBFrame::Disassemble () => error: could not reconstruct frame object for this SBFrame.");
1059 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001060 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001061 else
1062 {
1063 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001064 log->Printf ("SBFrame::Disassemble () => error: process is running");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001065 }
Greg Claytonaf67cec2010-12-20 20:49:23 +00001066 }
Greg Clayton48381312010-10-30 04:51:46 +00001067
1068 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001069 log->Printf ("SBFrame(%p)::Disassemble () => %s",
1070 static_cast<void*>(frame), disassembly);
Greg Clayton48381312010-10-30 04:51:46 +00001071
1072 return disassembly;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001073}
1074
1075
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001076SBValueList
1077SBFrame::GetVariables (bool arguments,
1078 bool locals,
1079 bool statics,
1080 bool in_scope_only)
1081{
Greg Clayton316d4982011-06-18 20:06:08 +00001082 SBValueList value_list;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001083 ExecutionContext exe_ctx(m_opaque_sp.get());
Jason Molendab57e4a12013-11-04 09:33:30 +00001084 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Claytond9e416c2012-02-18 05:35:26 +00001085 Target *target = exe_ctx.GetTargetPtr();
1086 if (frame && target)
Greg Clayton316d4982011-06-18 20:06:08 +00001087 {
Greg Claytond9e416c2012-02-18 05:35:26 +00001088 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
Zachary Turner51f96ee2015-02-17 17:55:50 +00001089 const bool include_runtime_support_values = target ? target->GetDisplayRuntimeSupportValues() : false;
1090
1091 SBVariablesOptions options;
1092 options.SetIncludeArguments(arguments);
1093 options.SetIncludeLocals(locals);
1094 options.SetIncludeStatics(statics);
1095 options.SetInScopeOnly(in_scope_only);
1096 options.SetIncludeRuntimeSupportValues(include_runtime_support_values);
1097 options.SetUseDynamic(use_dynamic);
1098
1099 value_list = GetVariables (options);
Greg Clayton316d4982011-06-18 20:06:08 +00001100 }
1101 return value_list;
Jim Ingham78a685a2011-04-16 00:01:13 +00001102}
1103
Enrico Granata560558e2015-02-11 02:35:39 +00001104lldb::SBValueList
1105SBFrame::GetVariables (bool arguments,
1106 bool locals,
1107 bool statics,
1108 bool in_scope_only,
1109 lldb::DynamicValueType use_dynamic)
1110{
1111 ExecutionContext exe_ctx(m_opaque_sp.get());
1112 Target *target = exe_ctx.GetTargetPtr();
Zachary Turner51f96ee2015-02-17 17:55:50 +00001113 const bool include_runtime_support_values = target ? target->GetDisplayRuntimeSupportValues() : false;
1114 SBVariablesOptions options;
1115 options.SetIncludeArguments(arguments);
1116 options.SetIncludeLocals(locals);
1117 options.SetIncludeStatics(statics);
1118 options.SetInScopeOnly(in_scope_only);
1119 options.SetIncludeRuntimeSupportValues(include_runtime_support_values);
1120 options.SetUseDynamic(use_dynamic);
1121 return GetVariables(options);
Enrico Granata560558e2015-02-11 02:35:39 +00001122}
1123
Jim Ingham78a685a2011-04-16 00:01:13 +00001124SBValueList
Zachary Turner51f96ee2015-02-17 17:55:50 +00001125SBFrame::GetVariables (const lldb::SBVariablesOptions& options)
Jim Ingham78a685a2011-04-16 00:01:13 +00001126{
Greg Clayton5160ce52013-03-27 23:08:40 +00001127 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001128
Greg Claytonb9556ac2012-01-30 07:41:31 +00001129 SBValueList value_list;
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001130 Mutex::Locker api_locker;
1131 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1132
Jason Molendab57e4a12013-11-04 09:33:30 +00001133 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +00001134 Target *target = exe_ctx.GetTargetPtr();
Greg Claytonb9556ac2012-01-30 07:41:31 +00001135
Zachary Turner51f96ee2015-02-17 17:55:50 +00001136 const bool statics = options.GetIncludeStatics();
1137 const bool arguments = options.GetIncludeArguments();
1138 const bool locals = options.GetIncludeLocals();
1139 const bool in_scope_only = options.GetInScopeOnly();
1140 const bool include_runtime_support_values = options.GetIncludeRuntimeSupportValues();
1141 const lldb::DynamicValueType use_dynamic = options.GetUseDynamic();
1142
Caroline Ticeceb6b132010-10-26 03:11:13 +00001143 if (log)
Zachary Turner51f96ee2015-02-17 17:55:50 +00001144 log->Printf ("SBFrame::GetVariables (arguments=%i, locals=%i, statics=%i, in_scope_only=%i runtime=%i dynamic=%i)",
1145 arguments, locals,
1146 statics, in_scope_only,
1147 include_runtime_support_values, use_dynamic);
1148
Jim Ingham7730b9a2012-11-29 00:26:19 +00001149 Process *process = exe_ctx.GetProcessPtr();
1150 if (target && process)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001151 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001152 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001153 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001154 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001155 frame = exe_ctx.GetFramePtr();
1156 if (frame)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001157 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001158 size_t i;
1159 VariableList *variable_list = NULL;
1160 variable_list = frame->GetVariableList(true);
1161 if (variable_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001162 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001163 const size_t num_variables = variable_list->GetSize();
1164 if (num_variables)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001165 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001166 for (i = 0; i < num_variables; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001167 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001168 VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
1169 if (variable_sp)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001170 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001171 bool add_variable = false;
1172 switch (variable_sp->GetScope())
1173 {
1174 case eValueTypeVariableGlobal:
1175 case eValueTypeVariableStatic:
1176 add_variable = statics;
1177 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001178
Jim Ingham7730b9a2012-11-29 00:26:19 +00001179 case eValueTypeVariableArgument:
1180 add_variable = arguments;
1181 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001182
Jim Ingham7730b9a2012-11-29 00:26:19 +00001183 case eValueTypeVariableLocal:
1184 add_variable = locals;
1185 break;
Greg Claytonc982c762010-07-09 20:39:50 +00001186
Jim Ingham7730b9a2012-11-29 00:26:19 +00001187 default:
1188 break;
1189 }
1190 if (add_variable)
1191 {
1192 if (in_scope_only && !variable_sp->IsInScope(frame))
1193 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001194
Jim Ingham7730b9a2012-11-29 00:26:19 +00001195 ValueObjectSP valobj_sp(frame->GetValueObjectForFrameVariable (variable_sp, eNoDynamicValues));
Enrico Granata560558e2015-02-11 02:35:39 +00001196
1197 if (false == include_runtime_support_values &&
1198 valobj_sp &&
1199 true == valobj_sp->IsRuntimeSupportValue())
1200 continue;
1201
Jim Ingham7730b9a2012-11-29 00:26:19 +00001202 SBValue value_sb;
1203 value_sb.SetSP(valobj_sp,use_dynamic);
1204 value_list.Append(value_sb);
1205 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001206 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001207 }
1208 }
1209 }
1210 }
Jim Ingham7730b9a2012-11-29 00:26:19 +00001211 else
1212 {
1213 if (log)
1214 log->Printf ("SBFrame::GetVariables () => error: could not reconstruct frame object for this SBFrame.");
1215 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001216 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001217 else
1218 {
1219 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001220 log->Printf ("SBFrame::GetVariables () => error: process is running");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001221 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001222 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001223
1224 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001225 log->Printf ("SBFrame(%p)::GetVariables (...) => SBValueList(%p)",
1226 static_cast<void*>(frame),
1227 static_cast<void*>(value_list.opaque_ptr()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001228
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001229 return value_list;
1230}
1231
Greg Clayton69b582f2010-12-14 18:39:31 +00001232SBValueList
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001233SBFrame::GetRegisters ()
1234{
Greg Clayton5160ce52013-03-27 23:08:40 +00001235 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001236
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001237 SBValueList value_list;
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001238 Mutex::Locker api_locker;
1239 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1240
Jason Molendab57e4a12013-11-04 09:33:30 +00001241 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +00001242 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +00001243 Process *process = exe_ctx.GetProcessPtr();
1244 if (target && process)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001245 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001246 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001247 if (stop_locker.TryLock(&process->GetRunLock()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001248 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001249 frame = exe_ctx.GetFramePtr();
1250 if (frame)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001251 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001252 RegisterContextSP reg_ctx (frame->GetRegisterContext());
1253 if (reg_ctx)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001254 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001255 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
1256 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
1257 {
1258 value_list.Append(ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx));
1259 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001260 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001261 }
Jim Ingham7730b9a2012-11-29 00:26:19 +00001262 else
1263 {
1264 if (log)
1265 log->Printf ("SBFrame::GetRegisters () => error: could not reconstruct frame object for this SBFrame.");
1266 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001267 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001268 else
1269 {
1270 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001271 log->Printf ("SBFrame::GetRegisters () => error: process is running");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001272 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001273 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001274
1275 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001276 log->Printf ("SBFrame(%p)::GetRegisters () => SBValueList(%p)",
1277 static_cast<void*>(frame),
1278 static_cast<void*>(value_list.opaque_ptr()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001279
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001280 return value_list;
1281}
1282
Jason Molendaad9a53c2013-07-26 02:08:48 +00001283SBValue
1284SBFrame::FindRegister (const char *name)
1285{
1286 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1287
1288 SBValue result;
1289 ValueObjectSP value_sp;
1290 Mutex::Locker api_locker;
1291 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1292
Jason Molendab57e4a12013-11-04 09:33:30 +00001293 StackFrame *frame = NULL;
Jason Molendaad9a53c2013-07-26 02:08:48 +00001294 Target *target = exe_ctx.GetTargetPtr();
1295 Process *process = exe_ctx.GetProcessPtr();
1296 if (target && process)
1297 {
1298 Process::StopLocker stop_locker;
1299 if (stop_locker.TryLock(&process->GetRunLock()))
1300 {
1301 frame = exe_ctx.GetFramePtr();
1302 if (frame)
1303 {
1304 RegisterContextSP reg_ctx (frame->GetRegisterContext());
1305 if (reg_ctx)
1306 {
1307 const uint32_t num_regs = reg_ctx->GetRegisterCount();
1308 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx)
1309 {
1310 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
1311 if (reg_info &&
1312 ((reg_info->name && strcasecmp (reg_info->name, name) == 0) ||
1313 (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0)))
1314 {
1315 value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx);
1316 result.SetSP (value_sp);
1317 break;
1318 }
1319 }
1320 }
1321 }
1322 else
1323 {
1324 if (log)
Jason Molenda5d353842013-07-26 22:52:30 +00001325 log->Printf ("SBFrame::FindRegister () => error: could not reconstruct frame object for this SBFrame.");
Jason Molendaad9a53c2013-07-26 02:08:48 +00001326 }
1327 }
1328 else
1329 {
1330 if (log)
Jason Molenda5d353842013-07-26 22:52:30 +00001331 log->Printf ("SBFrame::FindRegister () => error: process is running");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001332 }
Jason Molendaad9a53c2013-07-26 02:08:48 +00001333 }
1334
1335 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001336 log->Printf ("SBFrame(%p)::FindRegister () => SBValue(%p)",
1337 static_cast<void*>(frame),
1338 static_cast<void*>(value_sp.get()));
Jason Molendaad9a53c2013-07-26 02:08:48 +00001339
1340 return result;
1341}
1342
Caroline Ticedde9cff2010-09-20 05:20:02 +00001343bool
1344SBFrame::GetDescription (SBStream &description)
1345{
Greg Clayton5160ce52013-03-27 23:08:40 +00001346 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001347 Stream &strm = description.ref();
1348
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001349 Mutex::Locker api_locker;
1350 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1351
Jason Molendab57e4a12013-11-04 09:33:30 +00001352 StackFrame *frame;
Greg Claytond9e416c2012-02-18 05:35:26 +00001353 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +00001354 Process *process = exe_ctx.GetProcessPtr();
1355 if (target && process)
Caroline Ticedde9cff2010-09-20 05:20:02 +00001356 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001357 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001358 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001359 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001360 frame = exe_ctx.GetFramePtr();
1361 if (frame)
1362 {
1363 frame->DumpUsingSettingsFormat (&strm);
1364 }
1365 else
1366 {
1367 if (log)
1368 log->Printf ("SBFrame::GetDescription () => error: could not reconstruct frame object for this SBFrame.");
1369 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001370 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001371 else
1372 {
Greg Claytonc9858e42012-04-06 02:17:47 +00001373 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001374 log->Printf ("SBFrame::GetDescription () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +00001375 }
1376
Caroline Ticedde9cff2010-09-20 05:20:02 +00001377 }
1378 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001379 strm.PutCString ("No value");
Caroline Ticedde9cff2010-09-20 05:20:02 +00001380
1381 return true;
1382}
Greg Clayton1d3afba2010-10-05 00:00:42 +00001383
Greg Clayton69b582f2010-12-14 18:39:31 +00001384SBValue
Greg Clayton1d3afba2010-10-05 00:00:42 +00001385SBFrame::EvaluateExpression (const char *expr)
1386{
Greg Clayton316d4982011-06-18 20:06:08 +00001387 SBValue result;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001388 ExecutionContext exe_ctx(m_opaque_sp.get());
Jason Molendab57e4a12013-11-04 09:33:30 +00001389 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Claytond9e416c2012-02-18 05:35:26 +00001390 Target *target = exe_ctx.GetTargetPtr();
1391 if (frame && target)
Greg Clayton316d4982011-06-18 20:06:08 +00001392 {
Jim Ingham35e1bda2012-10-16 21:41:58 +00001393 SBExpressionOptions options;
1394 lldb::DynamicValueType fetch_dynamic_value = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Claytoncced1562012-10-16 22:58:25 +00001395 options.SetFetchDynamicValue (fetch_dynamic_value);
Jim Ingham35e1bda2012-10-16 21:41:58 +00001396 options.SetUnwindOnError (true);
1397 return EvaluateExpression (expr, options);
Greg Clayton316d4982011-06-18 20:06:08 +00001398 }
1399 return result;
Jim Ingham78a685a2011-04-16 00:01:13 +00001400}
1401
1402SBValue
Jim Ingham2837b762011-05-04 03:43:18 +00001403SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value)
Jim Ingham78a685a2011-04-16 00:01:13 +00001404{
Jim Ingham35e1bda2012-10-16 21:41:58 +00001405 SBExpressionOptions options;
Greg Claytoncced1562012-10-16 22:58:25 +00001406 options.SetFetchDynamicValue (fetch_dynamic_value);
Jim Ingham35e1bda2012-10-16 21:41:58 +00001407 options.SetUnwindOnError (true);
1408 return EvaluateExpression (expr, options);
Jim Ingham7ba6e992012-05-11 23:47:32 +00001409}
1410
1411SBValue
1412SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value, bool unwind_on_error)
1413{
Jim Ingham35e1bda2012-10-16 21:41:58 +00001414 SBExpressionOptions options;
Greg Claytoncced1562012-10-16 22:58:25 +00001415 options.SetFetchDynamicValue (fetch_dynamic_value);
Jim Ingham35e1bda2012-10-16 21:41:58 +00001416 options.SetUnwindOnError (unwind_on_error);
1417 return EvaluateExpression (expr, options);
1418}
1419
1420lldb::SBValue
1421SBFrame::EvaluateExpression (const char *expr, const SBExpressionOptions &options)
1422{
Greg Clayton5160ce52013-03-27 23:08:40 +00001423 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001424
Greg Clayton5160ce52013-03-27 23:08:40 +00001425 Log *expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Greg Clayton48381312010-10-30 04:51:46 +00001426
Jim Ingham8646d3c2014-05-05 02:47:44 +00001427 ExpressionResults exe_results = eExpressionSetupError;
Greg Clayton69b582f2010-12-14 18:39:31 +00001428 SBValue expr_result;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001429
Jim Ingham7730b9a2012-11-29 00:26:19 +00001430 if (expr == NULL || expr[0] == '\0')
1431 {
1432 if (log)
1433 log->Printf ("SBFrame::EvaluateExpression called with an empty expression");
1434 return expr_result;
1435 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001436
Greg Clayton81e871e2012-02-04 02:27:34 +00001437 ValueObjectSP expr_value_sp;
Greg Clayton48381312010-10-30 04:51:46 +00001438
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001439 Mutex::Locker api_locker;
1440 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1441
Greg Claytonb9556ac2012-01-30 07:41:31 +00001442 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001443 log->Printf ("SBFrame()::EvaluateExpression (expr=\"%s\")...", expr);
Greg Claytonb9556ac2012-01-30 07:41:31 +00001444
Jason Molendab57e4a12013-11-04 09:33:30 +00001445 StackFrame *frame = NULL;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001446 Target *target = exe_ctx.GetTargetPtr();
1447 Process *process = exe_ctx.GetProcessPtr();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001448
Jim Ingham7730b9a2012-11-29 00:26:19 +00001449 if (target && process)
1450 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001451 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001452 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001453 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001454 frame = exe_ctx.GetFramePtr();
1455 if (frame)
1456 {
Greg Claytonfb6621e2013-12-06 21:59:52 +00001457 if (target->GetDisplayExpressionsInCrashlogs())
1458 {
1459 StreamString frame_description;
1460 frame->DumpUsingSettingsFormat (&frame_description);
1461 Host::SetCrashDescriptionWithFormat ("SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
1462 expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str());
1463 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001464
Greg Claytonfb6621e2013-12-06 21:59:52 +00001465 exe_results = target->EvaluateExpression (expr,
Jim Ingham7730b9a2012-11-29 00:26:19 +00001466 frame,
1467 expr_value_sp,
1468 options.ref());
1469 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
Greg Claytonfb6621e2013-12-06 21:59:52 +00001470
1471 if (target->GetDisplayExpressionsInCrashlogs())
1472 Host::SetCrashDescription (NULL);
Jim Ingham7730b9a2012-11-29 00:26:19 +00001473 }
1474 else
1475 {
1476 if (log)
1477 log->Printf ("SBFrame::EvaluateExpression () => error: could not reconstruct frame object for this SBFrame.");
1478 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001479 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001480 else
1481 {
1482 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001483 log->Printf ("SBFrame::EvaluateExpression () => error: process is running");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001484 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00001485 }
Jason Molendacf7e2dc2012-02-21 05:33:55 +00001486
1487#ifndef LLDB_DISABLE_PYTHON
Sean Callanana162eba2010-12-07 22:55:01 +00001488 if (expr_log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001489 expr_log->Printf("** [SBFrame::EvaluateExpression] Expression result is %s, summary %s **",
1490 expr_result.GetValue(), expr_result.GetSummary());
1491
Greg Clayton48381312010-10-30 04:51:46 +00001492 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001493 log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)",
1494 static_cast<void*>(frame), expr,
1495 static_cast<void*>(expr_value_sp.get()), exe_results);
Jason Molendacf7e2dc2012-02-21 05:33:55 +00001496#endif
Greg Clayton48381312010-10-30 04:51:46 +00001497
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001498 return expr_result;
Greg Clayton1d3afba2010-10-05 00:00:42 +00001499}
Greg Clayton316d4982011-06-18 20:06:08 +00001500
1501bool
Oleksiy Vyalov6345fe32015-06-24 18:35:36 +00001502SBFrame::IsInlined()
Greg Clayton316d4982011-06-18 20:06:08 +00001503{
Greg Clayton5160ce52013-03-27 23:08:40 +00001504 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001505 ExecutionContext exe_ctx(m_opaque_sp.get());
Jason Molendab57e4a12013-11-04 09:33:30 +00001506 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +00001507 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +00001508 Process *process = exe_ctx.GetProcessPtr();
1509 if (target && process)
Greg Clayton316d4982011-06-18 20:06:08 +00001510 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001511 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001512 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001513 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001514 frame = exe_ctx.GetFramePtr();
1515 if (frame)
1516 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001517
Jim Ingham7730b9a2012-11-29 00:26:19 +00001518 Block *block = frame->GetSymbolContext(eSymbolContextBlock).block;
1519 if (block)
1520 return block->GetContainingInlinedBlock () != NULL;
1521 }
1522 else
1523 {
1524 if (log)
1525 log->Printf ("SBFrame::IsInlined () => error: could not reconstruct frame object for this SBFrame.");
1526 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001527 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001528 else
1529 {
Greg Claytonc9858e42012-04-06 02:17:47 +00001530 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001531 log->Printf ("SBFrame::IsInlined () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +00001532 }
1533
Greg Clayton316d4982011-06-18 20:06:08 +00001534 }
1535 return false;
1536}
1537
1538const char *
Oleksiy Vyalov6345fe32015-06-24 18:35:36 +00001539SBFrame::GetFunctionName()
Greg Clayton316d4982011-06-18 20:06:08 +00001540{
Greg Clayton5160ce52013-03-27 23:08:40 +00001541 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton316d4982011-06-18 20:06:08 +00001542 const char *name = NULL;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001543 ExecutionContext exe_ctx(m_opaque_sp.get());
Jason Molendab57e4a12013-11-04 09:33:30 +00001544 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +00001545 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +00001546 Process *process = exe_ctx.GetProcessPtr();
1547 if (target && process)
Greg Clayton316d4982011-06-18 20:06:08 +00001548 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001549 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001550 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton316d4982011-06-18 20:06:08 +00001551 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001552 frame = exe_ctx.GetFramePtr();
1553 if (frame)
Greg Clayton316d4982011-06-18 20:06:08 +00001554 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001555 SymbolContext sc (frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol));
1556 if (sc.block)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001557 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001558 Block *inlined_block = sc.block->GetContainingInlinedBlock ();
1559 if (inlined_block)
1560 {
1561 const InlineFunctionInfo* inlined_info = inlined_block->GetInlinedFunctionInfo();
1562 name = inlined_info->GetName().AsCString();
1563 }
1564 }
1565
1566 if (name == NULL)
1567 {
1568 if (sc.function)
1569 name = sc.function->GetName().GetCString();
1570 }
1571
1572 if (name == NULL)
1573 {
1574 if (sc.symbol)
1575 name = sc.symbol->GetName().GetCString();
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001576 }
Greg Clayton316d4982011-06-18 20:06:08 +00001577 }
Jim Ingham7730b9a2012-11-29 00:26:19 +00001578 else
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001579 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001580 if (log)
1581 log->Printf ("SBFrame::GetFunctionName () => error: could not reconstruct frame object for this SBFrame.");
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001582 }
Greg Clayton316d4982011-06-18 20:06:08 +00001583 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001584 else
1585 {
Greg Claytonc9858e42012-04-06 02:17:47 +00001586 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001587 log->Printf ("SBFrame::GetFunctionName() => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +00001588
1589 }
Greg Clayton316d4982011-06-18 20:06:08 +00001590 }
1591 return name;
1592}
1593