blob: da1d32f2e80c6d48a3c1d7c094b7d9842d9c75aa [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"
Greg Claytonb71f3842010-10-05 03:13:51 +000024#include "lldb/Expression/ClangUserExpression.h"
Greg Clayton1ba7c4d2011-06-25 04:35:01 +000025#include "lldb/Host/Host.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026#include "lldb/Symbol/Block.h"
Greg Clayton1f746072012-08-29 21:13:06 +000027#include "lldb/Symbol/Function.h"
28#include "lldb/Symbol/Symbol.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Symbol/SymbolContext.h"
30#include "lldb/Symbol/VariableList.h"
31#include "lldb/Symbol/Variable.h"
32#include "lldb/Target/ExecutionContext.h"
33#include "lldb/Target/Target.h"
34#include "lldb/Target/Process.h"
35#include "lldb/Target/RegisterContext.h"
Jason Molendab57e4a12013-11-04 09:33:30 +000036#include "lldb/Target/StackFrame.h"
Greg Claytonb9556ac2012-01-30 07:41:31 +000037#include "lldb/Target/StackID.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000038#include "lldb/Target/Thread.h"
39
Eli Friedman4c5de692010-06-09 07:44:37 +000040#include "lldb/API/SBDebugger.h"
41#include "lldb/API/SBValue.h"
42#include "lldb/API/SBAddress.h"
Jim Ingham35e1bda2012-10-16 21:41:58 +000043#include "lldb/API/SBExpressionOptions.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000044#include "lldb/API/SBStream.h"
Eli Friedman4c5de692010-06-09 07:44:37 +000045#include "lldb/API/SBSymbolContext.h"
46#include "lldb/API/SBThread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000047
48using namespace lldb;
49using namespace lldb_private;
50
Greg Claytonb9556ac2012-01-30 07:41:31 +000051
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052SBFrame::SBFrame () :
Greg Clayton7fdf9ef2012-04-05 16:12:35 +000053 m_opaque_sp (new ExecutionContextRef())
Chris Lattner30fdc8d2010-06-08 16:52:24 +000054{
55}
56
Jason Molendab57e4a12013-11-04 09:33:30 +000057SBFrame::SBFrame (const StackFrameSP &lldb_object_sp) :
Greg Clayton7fdf9ef2012-04-05 16:12:35 +000058 m_opaque_sp (new ExecutionContextRef (lldb_object_sp))
Chris Lattner30fdc8d2010-06-08 16:52:24 +000059{
Greg Clayton5160ce52013-03-27 23:08:40 +000060 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +000061
62 if (log)
63 {
64 SBStream sstr;
65 GetDescription (sstr);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000066 log->Printf ("SBFrame::SBFrame (sp=%p) => SBFrame(%p): %s",
67 static_cast<void*>(lldb_object_sp.get()),
68 static_cast<void*>(lldb_object_sp.get()), sstr.GetData());
Caroline Ticeceb6b132010-10-26 03:11:13 +000069 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000070}
71
Greg Claytonefabb122010-11-05 23:17:00 +000072SBFrame::SBFrame(const SBFrame &rhs) :
Greg Clayton7fdf9ef2012-04-05 16:12:35 +000073 m_opaque_sp (new ExecutionContextRef (*rhs.m_opaque_sp))
Greg Claytonefabb122010-11-05 23:17:00 +000074{
75}
76
77const SBFrame &
78SBFrame::operator = (const SBFrame &rhs)
79{
80 if (this != &rhs)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +000081 *m_opaque_sp = *rhs.m_opaque_sp;
Greg Claytonefabb122010-11-05 23:17:00 +000082 return *this;
83}
84
Chris Lattner30fdc8d2010-06-08 16:52:24 +000085SBFrame::~SBFrame()
86{
87}
88
Jason Molendab57e4a12013-11-04 09:33:30 +000089StackFrameSP
Greg Claytonb9556ac2012-01-30 07:41:31 +000090SBFrame::GetFrameSP() const
Chris Lattner30fdc8d2010-06-08 16:52:24 +000091{
Greg Claytonaf2589e2012-04-12 20:58:26 +000092 if (m_opaque_sp)
93 return m_opaque_sp->GetFrameSP();
Jason Molendab57e4a12013-11-04 09:33:30 +000094 return StackFrameSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000095}
96
Greg Claytonb9556ac2012-01-30 07:41:31 +000097void
Jason Molendab57e4a12013-11-04 09:33:30 +000098SBFrame::SetFrameSP (const StackFrameSP &lldb_object_sp)
Greg Claytonb9556ac2012-01-30 07:41:31 +000099{
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000100 return m_opaque_sp->SetFrameSP(lldb_object_sp);
Greg Claytonb9556ac2012-01-30 07:41:31 +0000101}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000102
103bool
104SBFrame::IsValid() const
105{
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000106 return GetFrameSP().get() != NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000107}
108
109SBSymbolContext
110SBFrame::GetSymbolContext (uint32_t resolve_scope) const
111{
Greg Clayton5160ce52013-03-27 23:08:40 +0000112 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000113 SBSymbolContext sb_sym_ctx;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000114 Mutex::Locker api_locker;
115 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
116
Jason Molendab57e4a12013-11-04 09:33:30 +0000117 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000118 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000119 Process *process = exe_ctx.GetProcessPtr();
120 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000121 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000122 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000123 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000124 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000125 frame = exe_ctx.GetFramePtr();
126 if (frame)
127 {
128 sb_sym_ctx.SetSymbolContext(&frame->GetSymbolContext (resolve_scope));
129 }
130 else
131 {
132 if (log)
133 log->Printf ("SBFrame::GetVariables () => error: could not reconstruct frame object for this SBFrame.");
134 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000135 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000136 else
137 {
138 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000139 log->Printf ("SBFrame::GetSymbolContext () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000140 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000141 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000142
143 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000144 log->Printf ("SBFrame(%p)::GetSymbolContext (resolve_scope=0x%8.8x) => SBSymbolContext(%p)",
145 static_cast<void*>(frame), resolve_scope,
146 static_cast<void*>(sb_sym_ctx.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000147
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000148 return sb_sym_ctx;
149}
150
151SBModule
152SBFrame::GetModule () const
153{
Greg Clayton5160ce52013-03-27 23:08:40 +0000154 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton72eff182010-12-14 04:58:53 +0000155 SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +0000156 ModuleSP module_sp;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000157 Mutex::Locker api_locker;
158 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
159
Jason Molendab57e4a12013-11-04 09:33:30 +0000160 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000161 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000162 Process *process = exe_ctx.GetProcessPtr();
163 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000164 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000165 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000166 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000167 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000168 frame = exe_ctx.GetFramePtr();
169 if (frame)
170 {
171 module_sp = frame->GetSymbolContext (eSymbolContextModule).module_sp;
172 sb_module.SetSP (module_sp);
173 }
174 else
175 {
176 if (log)
177 log->Printf ("SBFrame::GetModule () => error: could not reconstruct frame object for this SBFrame.");
178 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000179 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000180 else
181 {
182 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000183 log->Printf ("SBFrame::GetModule () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000184 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000185 }
Greg Clayton72eff182010-12-14 04:58:53 +0000186
Greg Clayton48381312010-10-30 04:51:46 +0000187 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000188 log->Printf ("SBFrame(%p)::GetModule () => SBModule(%p)",
189 static_cast<void*>(frame),
190 static_cast<void*>(module_sp.get()));
Greg Clayton48381312010-10-30 04:51:46 +0000191
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000192 return sb_module;
193}
194
195SBCompileUnit
196SBFrame::GetCompileUnit () const
197{
Greg Clayton5160ce52013-03-27 23:08:40 +0000198 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton72eff182010-12-14 04:58:53 +0000199 SBCompileUnit sb_comp_unit;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000200 Mutex::Locker api_locker;
201 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
202
Jason Molendab57e4a12013-11-04 09:33:30 +0000203 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000204 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000205 Process *process = exe_ctx.GetProcessPtr();
206 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000207 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000208 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000209 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000210 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000211 frame = exe_ctx.GetFramePtr();
212 if (frame)
213 {
214 sb_comp_unit.reset (frame->GetSymbolContext (eSymbolContextCompUnit).comp_unit);
215 }
216 else
217 {
218 if (log)
219 log->Printf ("SBFrame::GetCompileUnit () => error: could not reconstruct frame object for this SBFrame.");
220 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000221 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000222 else
223 {
224 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000225 log->Printf ("SBFrame::GetCompileUnit () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000226 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000227 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000228 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000229 log->Printf ("SBFrame(%p)::GetCompileUnit () => SBCompileUnit(%p)",
230 static_cast<void*>(frame),
231 static_cast<void*>(sb_comp_unit.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000232
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000233 return sb_comp_unit;
234}
235
236SBFunction
237SBFrame::GetFunction () const
238{
Greg Clayton5160ce52013-03-27 23:08:40 +0000239 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton72eff182010-12-14 04:58:53 +0000240 SBFunction sb_function;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000241 Mutex::Locker api_locker;
242 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
243
Jason Molendab57e4a12013-11-04 09:33:30 +0000244 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000245 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000246 Process *process = exe_ctx.GetProcessPtr();
247 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000248 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000249 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000250 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000251 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000252 frame = exe_ctx.GetFramePtr();
253 if (frame)
254 {
255 sb_function.reset(frame->GetSymbolContext (eSymbolContextFunction).function);
256 }
257 else
258 {
259 if (log)
260 log->Printf ("SBFrame::GetFunction () => error: could not reconstruct frame object for this SBFrame.");
261 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000262 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000263 else
264 {
265 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000266 log->Printf ("SBFrame::GetFunction () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000267 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000268 }
Greg Clayton48381312010-10-30 04:51:46 +0000269 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000270 log->Printf ("SBFrame(%p)::GetFunction () => SBFunction(%p)",
271 static_cast<void*>(frame),
272 static_cast<void*>(sb_function.get()));
Greg Clayton48381312010-10-30 04:51:46 +0000273
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000274 return sb_function;
275}
276
Greg Clayton3b065572010-10-04 18:37:52 +0000277SBSymbol
278SBFrame::GetSymbol () const
279{
Greg Clayton5160ce52013-03-27 23:08:40 +0000280 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton72eff182010-12-14 04:58:53 +0000281 SBSymbol sb_symbol;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000282 Mutex::Locker api_locker;
283 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
284
Jason Molendab57e4a12013-11-04 09:33:30 +0000285 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000286 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000287 Process *process = exe_ctx.GetProcessPtr();
288 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000289 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000290 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000291 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000292 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000293 frame = exe_ctx.GetFramePtr();
294 if (frame)
295 {
296 sb_symbol.reset(frame->GetSymbolContext (eSymbolContextSymbol).symbol);
297 }
298 else
299 {
300 if (log)
301 log->Printf ("SBFrame::GetSymbol () => error: could not reconstruct frame object for this SBFrame.");
302 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000303 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000304 else
305 {
306 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000307 log->Printf ("SBFrame::GetSymbol () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000308 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000309 }
Greg Clayton48381312010-10-30 04:51:46 +0000310 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000311 log->Printf ("SBFrame(%p)::GetSymbol () => SBSymbol(%p)",
312 static_cast<void*>(frame),
313 static_cast<void*>(sb_symbol.get()));
Greg Clayton3b065572010-10-04 18:37:52 +0000314 return sb_symbol;
315}
316
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000317SBBlock
318SBFrame::GetBlock () const
319{
Greg Clayton5160ce52013-03-27 23:08:40 +0000320 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton72eff182010-12-14 04:58:53 +0000321 SBBlock sb_block;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000322 Mutex::Locker api_locker;
323 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
324
Jason Molendab57e4a12013-11-04 09:33:30 +0000325 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000326 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000327 Process *process = exe_ctx.GetProcessPtr();
328 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000329 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000330 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000331 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000332 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000333 frame = exe_ctx.GetFramePtr();
334 if (frame)
335 {
336 sb_block.SetPtr (frame->GetSymbolContext (eSymbolContextBlock).block);
337 }
338 else
339 {
340 if (log)
341 log->Printf ("SBFrame::GetBlock () => error: could not reconstruct frame object for this SBFrame.");
342 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000343 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000344 else
345 {
346 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000347 log->Printf ("SBFrame(%p)::GetBlock () => error: process is running",
348 static_cast<void*>(frame));
Greg Claytonc9858e42012-04-06 02:17:47 +0000349 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000350 }
Greg Clayton48381312010-10-30 04:51:46 +0000351 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000352 log->Printf ("SBFrame(%p)::GetBlock () => SBBlock(%p)",
353 static_cast<void*>(frame),
354 static_cast<void*>(sb_block.GetPtr()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000355 return sb_block;
356}
357
Greg Clayton95897c62010-09-07 04:20:48 +0000358SBBlock
359SBFrame::GetFrameBlock () const
360{
Greg Clayton72eff182010-12-14 04:58:53 +0000361 SBBlock sb_block;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000362 Mutex::Locker api_locker;
363 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
364
Jason Molendab57e4a12013-11-04 09:33:30 +0000365 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000366 Target *target = exe_ctx.GetTargetPtr();
Greg Clayton5160ce52013-03-27 23:08:40 +0000367 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham7730b9a2012-11-29 00:26:19 +0000368 Process *process = exe_ctx.GetProcessPtr();
369 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000370 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000371 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000372 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000373 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000374 frame = exe_ctx.GetFramePtr();
375 if (frame)
376 {
377 sb_block.SetPtr(frame->GetFrameBlock ());
378 }
379 else
380 {
381 if (log)
382 log->Printf ("SBFrame::GetFrameBlock () => error: could not reconstruct frame object for this SBFrame.");
383 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000384 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000385 else
386 {
387 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000388 log->Printf ("SBFrame::GetFrameBlock () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000389 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000390 }
Greg Clayton48381312010-10-30 04:51:46 +0000391 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000392 log->Printf ("SBFrame(%p)::GetFrameBlock () => SBBlock(%p)",
393 static_cast<void*>(frame),
394 static_cast<void*>(sb_block.GetPtr()));
Greg Clayton95897c62010-09-07 04:20:48 +0000395 return sb_block;
396}
397
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000398SBLineEntry
399SBFrame::GetLineEntry () const
400{
Greg Clayton5160ce52013-03-27 23:08:40 +0000401 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton72eff182010-12-14 04:58:53 +0000402 SBLineEntry sb_line_entry;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000403 Mutex::Locker api_locker;
404 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
405
Jason Molendab57e4a12013-11-04 09:33:30 +0000406 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000407 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000408 Process *process = exe_ctx.GetProcessPtr();
409 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000410 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000411 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000412 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000413 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000414 frame = exe_ctx.GetFramePtr();
415 if (frame)
416 {
417 sb_line_entry.SetLineEntry (frame->GetSymbolContext (eSymbolContextLineEntry).line_entry);
418 }
419 else
420 {
421 if (log)
422 log->Printf ("SBFrame::GetLineEntry () => error: could not reconstruct frame object for this SBFrame.");
423 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000424 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000425 else
426 {
427 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000428 log->Printf ("SBFrame::GetLineEntry () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000429 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000430 }
Greg Clayton48381312010-10-30 04:51:46 +0000431 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000432 log->Printf ("SBFrame(%p)::GetLineEntry () => SBLineEntry(%p)",
433 static_cast<void*>(frame),
434 static_cast<void*>(sb_line_entry.get()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000435 return sb_line_entry;
436}
437
438uint32_t
439SBFrame::GetFrameID () const
440{
Greg Claytonb9556ac2012-01-30 07:41:31 +0000441 uint32_t frame_idx = UINT32_MAX;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000442
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000443 ExecutionContext exe_ctx(m_opaque_sp.get());
Jason Molendab57e4a12013-11-04 09:33:30 +0000444 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000445 if (frame)
Greg Claytond9e416c2012-02-18 05:35:26 +0000446 frame_idx = frame->GetFrameIndex ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000447
Greg Clayton5160ce52013-03-27 23:08:40 +0000448 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000449 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000450 log->Printf ("SBFrame(%p)::GetFrameID () => %u",
451 static_cast<void*>(frame), frame_idx);
Greg Clayton48381312010-10-30 04:51:46 +0000452 return frame_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000453}
454
Greg Clayton69b582f2010-12-14 18:39:31 +0000455addr_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000456SBFrame::GetPC () const
457{
Greg Clayton5160ce52013-03-27 23:08:40 +0000458 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton69b582f2010-12-14 18:39:31 +0000459 addr_t addr = LLDB_INVALID_ADDRESS;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000460 Mutex::Locker api_locker;
461 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
462
Jason Molendab57e4a12013-11-04 09:33:30 +0000463 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000464 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000465 Process *process = exe_ctx.GetProcessPtr();
466 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000467 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000468 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000469 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000470 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000471 frame = exe_ctx.GetFramePtr();
472 if (frame)
473 {
474 addr = frame->GetFrameCodeAddress().GetOpcodeLoadAddress (target);
475 }
476 else
477 {
478 if (log)
479 log->Printf ("SBFrame::GetPC () => error: could not reconstruct frame object for this SBFrame.");
480 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000481 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000482 else
483 {
484 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000485 log->Printf ("SBFrame::GetPC () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000486 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000487 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000488
489 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000490 log->Printf ("SBFrame(%p)::GetPC () => 0x%" PRIx64,
491 static_cast<void*>(frame), addr);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000492
493 return addr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000494}
495
496bool
Greg Clayton69b582f2010-12-14 18:39:31 +0000497SBFrame::SetPC (addr_t new_pc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000498{
Greg Clayton5160ce52013-03-27 23:08:40 +0000499 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000500 bool ret_val = false;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000501 Mutex::Locker api_locker;
502 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
503
Jason Molendab57e4a12013-11-04 09:33:30 +0000504 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000505 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000506 Process *process = exe_ctx.GetProcessPtr();
507 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000508 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000509 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000510 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000511 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000512 frame = exe_ctx.GetFramePtr();
513 if (frame)
514 {
515 ret_val = frame->GetRegisterContext()->SetPC (new_pc);
516 }
517 else
518 {
519 if (log)
520 log->Printf ("SBFrame::SetPC () => error: could not reconstruct frame object for this SBFrame.");
521 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000522 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000523 else
524 {
525 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000526 log->Printf ("SBFrame::SetPC () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000527 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000528 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000529
530 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +0000531 log->Printf ("SBFrame(%p)::SetPC (new_pc=0x%" PRIx64 ") => %i",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000532 static_cast<void*>(frame), new_pc, ret_val);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000533
534 return ret_val;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000535}
536
Greg Clayton69b582f2010-12-14 18:39:31 +0000537addr_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000538SBFrame::GetSP () const
539{
Greg Clayton5160ce52013-03-27 23:08:40 +0000540 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000541 addr_t addr = LLDB_INVALID_ADDRESS;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000542 Mutex::Locker api_locker;
543 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
544
Jason Molendab57e4a12013-11-04 09:33:30 +0000545 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000546 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000547 Process *process = exe_ctx.GetProcessPtr();
548 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000549 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000550 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000551 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000552 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000553 frame = exe_ctx.GetFramePtr();
554 if (frame)
555 {
556 addr = frame->GetRegisterContext()->GetSP();
557 }
558 else
559 {
560 if (log)
561 log->Printf ("SBFrame::GetSP () => error: could not reconstruct frame object for this SBFrame.");
562 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000563 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000564 else
565 {
566 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000567 log->Printf ("SBFrame::GetSP () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000568 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000569 }
Greg Clayton48381312010-10-30 04:51:46 +0000570 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000571 log->Printf ("SBFrame(%p)::GetSP () => 0x%" PRIx64,
572 static_cast<void*>(frame), addr);
Greg Clayton48381312010-10-30 04:51:46 +0000573
574 return addr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000575}
576
577
Greg Clayton69b582f2010-12-14 18:39:31 +0000578addr_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000579SBFrame::GetFP () const
580{
Greg Clayton5160ce52013-03-27 23:08:40 +0000581 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton69b582f2010-12-14 18:39:31 +0000582 addr_t addr = LLDB_INVALID_ADDRESS;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000583 Mutex::Locker api_locker;
584 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
585
Jason Molendab57e4a12013-11-04 09:33:30 +0000586 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000587 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000588 Process *process = exe_ctx.GetProcessPtr();
589 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000590 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000591 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000592 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000593 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000594 frame = exe_ctx.GetFramePtr();
595 if (frame)
596 {
597 addr = frame->GetRegisterContext()->GetFP();
598 }
599 else
600 {
601 if (log)
602 log->Printf ("SBFrame::GetFP () => error: could not reconstruct frame object for this SBFrame.");
603 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000604 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000605 else
606 {
607 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000608 log->Printf ("SBFrame::GetFP () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000609 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000610 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000611
612 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000613 log->Printf ("SBFrame(%p)::GetFP () => 0x%" PRIx64,
614 static_cast<void*>(frame), addr);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000615 return addr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000616}
617
618
619SBAddress
620SBFrame::GetPCAddress () const
621{
Greg Clayton5160ce52013-03-27 23:08:40 +0000622 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000623 SBAddress sb_addr;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000624 Mutex::Locker api_locker;
625 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
626
Jason Molendab57e4a12013-11-04 09:33:30 +0000627 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Claytond9e416c2012-02-18 05:35:26 +0000628 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000629 Process *process = exe_ctx.GetProcessPtr();
630 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000631 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000632 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000633 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000634 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000635 frame = exe_ctx.GetFramePtr();
636 if (frame)
637 {
638 sb_addr.SetAddress (&frame->GetFrameCodeAddress());
639 }
640 else
641 {
642 if (log)
643 log->Printf ("SBFrame::GetPCAddress () => error: could not reconstruct frame object for this SBFrame.");
644 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000645 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000646 else
647 {
648 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000649 log->Printf ("SBFrame::GetPCAddress () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000650 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000651 }
Greg Clayton48381312010-10-30 04:51:46 +0000652 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000653 log->Printf ("SBFrame(%p)::GetPCAddress () => SBAddress(%p)",
654 static_cast<void*>(frame),
655 static_cast<void*>(sb_addr.get()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000656 return sb_addr;
657}
658
659void
660SBFrame::Clear()
661{
Greg Claytonaf2589e2012-04-12 20:58:26 +0000662 m_opaque_sp->Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000663}
664
Greg Clayton7edbdfc2012-02-03 07:02:37 +0000665lldb::SBValue
666SBFrame::GetValueForVariablePath (const char *var_path)
667{
668 SBValue sb_value;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000669 ExecutionContext exe_ctx(m_opaque_sp.get());
Jason Molendab57e4a12013-11-04 09:33:30 +0000670 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Claytond9e416c2012-02-18 05:35:26 +0000671 Target *target = exe_ctx.GetTargetPtr();
672 if (frame && target)
Greg Clayton7edbdfc2012-02-03 07:02:37 +0000673 {
Greg Claytonc9858e42012-04-06 02:17:47 +0000674 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
675 sb_value = GetValueForVariablePath (var_path, use_dynamic);
Greg Clayton7edbdfc2012-02-03 07:02:37 +0000676 }
677 return sb_value;
678}
679
680lldb::SBValue
681SBFrame::GetValueForVariablePath (const char *var_path, DynamicValueType use_dynamic)
682{
683 SBValue sb_value;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000684 Mutex::Locker api_locker;
Greg Clayton5160ce52013-03-27 23:08:40 +0000685 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham7730b9a2012-11-29 00:26:19 +0000686 if (var_path == NULL || var_path[0] == '\0')
687 {
688 if (log)
689 log->Printf ("SBFrame::GetValueForVariablePath called with empty variable path.");
690 return sb_value;
691 }
692
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000693 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
694
Jason Molendab57e4a12013-11-04 09:33:30 +0000695 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000696 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000697 Process *process = exe_ctx.GetProcessPtr();
698 if (target && process)
Greg Clayton7edbdfc2012-02-03 07:02:37 +0000699 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000700 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000701 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000702 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000703 frame = exe_ctx.GetFramePtr();
704 if (frame)
705 {
706 VariableSP var_sp;
707 Error error;
708 ValueObjectSP value_sp (frame->GetValueForVariableExpressionPath (var_path,
709 eNoDynamicValues,
Jason Molendab57e4a12013-11-04 09:33:30 +0000710 StackFrame::eExpressionPathOptionCheckPtrVsMember | StackFrame::eExpressionPathOptionsAllowDirectIVarAccess,
Jim Ingham7730b9a2012-11-29 00:26:19 +0000711 var_sp,
712 error));
713 sb_value.SetSP(value_sp, use_dynamic);
714 }
715 else
716 {
717 if (log)
718 log->Printf ("SBFrame::GetValueForVariablePath () => error: could not reconstruct frame object for this SBFrame.");
719 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000720 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000721 else
722 {
Greg Claytonc9858e42012-04-06 02:17:47 +0000723 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000724 log->Printf ("SBFrame::GetValueForVariablePath () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000725 }
Greg Clayton7edbdfc2012-02-03 07:02:37 +0000726 }
727 return sb_value;
728}
729
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000730SBValue
Greg Clayton69b582f2010-12-14 18:39:31 +0000731SBFrame::FindVariable (const char *name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000732{
Greg Clayton316d4982011-06-18 20:06:08 +0000733 SBValue value;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000734 ExecutionContext exe_ctx(m_opaque_sp.get());
Jason Molendab57e4a12013-11-04 09:33:30 +0000735 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Claytond9e416c2012-02-18 05:35:26 +0000736 Target *target = exe_ctx.GetTargetPtr();
737 if (frame && target)
Greg Clayton316d4982011-06-18 20:06:08 +0000738 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000739 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton316d4982011-06-18 20:06:08 +0000740 value = FindVariable (name, use_dynamic);
741 }
742 return value;
Jim Ingham78a685a2011-04-16 00:01:13 +0000743}
744
745SBValue
Jim Ingham2837b762011-05-04 03:43:18 +0000746SBFrame::FindVariable (const char *name, lldb::DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +0000747{
Greg Clayton5160ce52013-03-27 23:08:40 +0000748 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton69b582f2010-12-14 18:39:31 +0000749 VariableSP var_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +0000750 SBValue sb_value;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000751
752 if (name == NULL || name[0] == '\0')
753 {
754 if (log)
755 log->Printf ("SBFrame::FindVariable called with empty name");
756 return sb_value;
757 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000758
Greg Clayton81e871e2012-02-04 02:27:34 +0000759 ValueObjectSP value_sp;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000760 Mutex::Locker api_locker;
761 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
762
Jason Molendab57e4a12013-11-04 09:33:30 +0000763 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000764 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000765 Process *process = exe_ctx.GetProcessPtr();
766 if (target && process)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000767 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000768 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000769 if (stop_locker.TryLock(&process->GetRunLock()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000770 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000771 frame = exe_ctx.GetFramePtr();
772 if (frame)
Greg Clayton72eff182010-12-14 04:58:53 +0000773 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000774 VariableList variable_list;
775 SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock));
776
777 if (sc.block)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000778 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000779 const bool can_create = true;
780 const bool get_parent_variables = true;
781 const bool stop_if_block_is_inlined_function = true;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000782
Jim Ingham7730b9a2012-11-29 00:26:19 +0000783 if (sc.block->AppendVariables (can_create,
784 get_parent_variables,
785 stop_if_block_is_inlined_function,
786 &variable_list))
787 {
788 var_sp = variable_list.FindVariable (ConstString(name));
789 }
790 }
791
792 if (var_sp)
793 {
794 value_sp = frame->GetValueObjectForFrameVariable(var_sp, eNoDynamicValues);
795 sb_value.SetSP(value_sp, use_dynamic);
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000796 }
797 }
Jim Ingham7730b9a2012-11-29 00:26:19 +0000798 else
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000799 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000800 if (log)
801 log->Printf ("SBFrame::FindVariable () => error: could not reconstruct frame object for this SBFrame.");
Greg Clayton72eff182010-12-14 04:58:53 +0000802 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000803 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000804 else
805 {
806 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000807 log->Printf ("SBFrame::FindVariable () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000808 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000809 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000810
Greg Clayton48381312010-10-30 04:51:46 +0000811 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000812 log->Printf ("SBFrame(%p)::FindVariable (name=\"%s\") => SBValue(%p)",
813 static_cast<void*>(frame), name,
814 static_cast<void*>(value_sp.get()));
Greg Clayton48381312010-10-30 04:51:46 +0000815
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000816 return sb_value;
817}
818
819SBValue
Greg Clayton69b582f2010-12-14 18:39:31 +0000820SBFrame::FindValue (const char *name, ValueType value_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000821{
Greg Clayton316d4982011-06-18 20:06:08 +0000822 SBValue value;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000823 ExecutionContext exe_ctx(m_opaque_sp.get());
Jason Molendab57e4a12013-11-04 09:33:30 +0000824 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Claytond9e416c2012-02-18 05:35:26 +0000825 Target *target = exe_ctx.GetTargetPtr();
826 if (frame && target)
Greg Clayton316d4982011-06-18 20:06:08 +0000827 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000828 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Clayton316d4982011-06-18 20:06:08 +0000829 value = FindValue (name, value_type, use_dynamic);
830 }
831 return value;
Jim Ingham78a685a2011-04-16 00:01:13 +0000832}
833
834SBValue
Jim Ingham2837b762011-05-04 03:43:18 +0000835SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +0000836{
Greg Clayton5160ce52013-03-27 23:08:40 +0000837 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton69b582f2010-12-14 18:39:31 +0000838 SBValue sb_value;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000839
Jim Ingham7730b9a2012-11-29 00:26:19 +0000840 if (name == NULL || name[0] == '\0')
841 {
842 if (log)
843 log->Printf ("SBFrame::FindValue called with empty name.");
844 return sb_value;
845 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000846
Greg Clayton81e871e2012-02-04 02:27:34 +0000847 ValueObjectSP value_sp;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000848 Mutex::Locker api_locker;
849 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
850
Jason Molendab57e4a12013-11-04 09:33:30 +0000851 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000852 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +0000853 Process *process = exe_ctx.GetProcessPtr();
854 if (target && process)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000855 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000856 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000857 if (stop_locker.TryLock(&process->GetRunLock()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000858 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000859 frame = exe_ctx.GetFramePtr();
860 if (frame)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000861 {
Enrico Granata8a2a0df2014-02-19 19:35:13 +0000862 VariableList variable_list;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000863
Jim Ingham7730b9a2012-11-29 00:26:19 +0000864 switch (value_type)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000865 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000866 case eValueTypeVariableGlobal: // global variable
867 case eValueTypeVariableStatic: // static variable
868 case eValueTypeVariableArgument: // function argument variables
869 case eValueTypeVariableLocal: // function local variables
870 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000871 SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock));
Greg Clayton69b582f2010-12-14 18:39:31 +0000872
Jim Ingham7730b9a2012-11-29 00:26:19 +0000873 const bool can_create = true;
874 const bool get_parent_variables = true;
875 const bool stop_if_block_is_inlined_function = true;
Greg Clayton69b582f2010-12-14 18:39:31 +0000876
Jim Ingham7730b9a2012-11-29 00:26:19 +0000877 if (sc.block && sc.block->AppendVariables (can_create,
878 get_parent_variables,
879 stop_if_block_is_inlined_function,
Enrico Granata08a04322014-02-18 23:48:11 +0000880 &variable_list))
Jim Ingham7730b9a2012-11-29 00:26:19 +0000881 {
Enrico Granata8a2a0df2014-02-19 19:35:13 +0000882 if (value_type == eValueTypeVariableGlobal)
883 {
884 const bool get_file_globals = true;
885 VariableList* frame_vars = frame->GetVariableList(get_file_globals);
886 if (frame_vars)
887 frame_vars->AppendVariablesIfUnique(variable_list);
888 }
Jim Ingham7730b9a2012-11-29 00:26:19 +0000889 ConstString const_name(name);
Enrico Granata08a04322014-02-18 23:48:11 +0000890 VariableSP variable_sp(variable_list.FindVariable(const_name,value_type));
891 if (variable_sp)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000892 {
Enrico Granata08a04322014-02-18 23:48:11 +0000893 value_sp = frame->GetValueObjectForFrameVariable (variable_sp, eNoDynamicValues);
894 sb_value.SetSP (value_sp, use_dynamic);
895 break;
Jim Ingham7730b9a2012-11-29 00:26:19 +0000896 }
897 }
898 }
899 break;
900
901 case eValueTypeRegister: // stack frame register value
902 {
903 RegisterContextSP reg_ctx (frame->GetRegisterContext());
904 if (reg_ctx)
905 {
906 const uint32_t num_regs = reg_ctx->GetRegisterCount();
907 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx)
908 {
909 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
910 if (reg_info &&
911 ((reg_info->name && strcasecmp (reg_info->name, name) == 0) ||
912 (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0)))
913 {
914 value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx);
915 sb_value.SetSP (value_sp);
916 break;
917 }
918 }
919 }
920 }
921 break;
922
923 case eValueTypeRegisterSet: // A collection of stack frame register values
924 {
925 RegisterContextSP reg_ctx (frame->GetRegisterContext());
926 if (reg_ctx)
927 {
928 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
929 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
930 {
931 const RegisterSet *reg_set = reg_ctx->GetRegisterSet (set_idx);
932 if (reg_set &&
933 ((reg_set->name && strcasecmp (reg_set->name, name) == 0) ||
934 (reg_set->short_name && strcasecmp (reg_set->short_name, name) == 0)))
935 {
936 value_sp = ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx);
937 sb_value.SetSP (value_sp);
938 break;
939 }
940 }
941 }
942 }
943 break;
944
945 case eValueTypeConstResult: // constant result variables
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000946 {
947 ConstString const_name(name);
Jim Ingham7730b9a2012-11-29 00:26:19 +0000948 ClangExpressionVariableSP expr_var_sp (target->GetPersistentVariables().GetVariable (const_name));
949 if (expr_var_sp)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000950 {
Jim Ingham7730b9a2012-11-29 00:26:19 +0000951 value_sp = expr_var_sp->GetValueObject();
952 sb_value.SetSP (value_sp, use_dynamic);
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000953 }
954 }
Jim Ingham7730b9a2012-11-29 00:26:19 +0000955 break;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000956
Jim Ingham7730b9a2012-11-29 00:26:19 +0000957 default:
958 break;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000959 }
Jim Ingham7730b9a2012-11-29 00:26:19 +0000960 }
961 else
962 {
963 if (log)
964 log->Printf ("SBFrame::FindValue () => error: could not reconstruct frame object for this SBFrame.");
Greg Clayton69b582f2010-12-14 18:39:31 +0000965 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000966 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000967 else
968 {
969 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +0000970 log->Printf ("SBFrame::FindValue () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +0000971 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000972 }
Greg Clayton48381312010-10-30 04:51:46 +0000973
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000974 if (log)
975 log->Printf ("SBFrame(%p)::FindVariableInScope (name=\"%s\", value_type=%i) => SBValue(%p)",
976 static_cast<void*>(frame), name, value_type,
977 static_cast<void*>(value_sp.get()));
978
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000979 return sb_value;
980}
981
982bool
Johnny Chen35e2ab62012-03-05 19:53:24 +0000983SBFrame::IsEqual (const SBFrame &that) const
984{
Jason Molendab57e4a12013-11-04 09:33:30 +0000985 lldb::StackFrameSP this_sp = GetFrameSP();
986 lldb::StackFrameSP that_sp = that.GetFrameSP();
Johnny Chen35e2ab62012-03-05 19:53:24 +0000987 return (this_sp && that_sp && this_sp->GetStackID() == that_sp->GetStackID());
988}
989
990bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000991SBFrame::operator == (const SBFrame &rhs) const
992{
Johnny Chen35e2ab62012-03-05 19:53:24 +0000993 return IsEqual(rhs);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000994}
995
996bool
997SBFrame::operator != (const SBFrame &rhs) const
998{
Johnny Chen35e2ab62012-03-05 19:53:24 +0000999 return !IsEqual(rhs);
Greg Clayton481cef22011-01-21 06:11:58 +00001000}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001001
1002SBThread
1003SBFrame::GetThread () const
1004{
Greg Clayton5160ce52013-03-27 23:08:40 +00001005 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001006
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001007 ExecutionContext exe_ctx(m_opaque_sp.get());
Greg Claytond9e416c2012-02-18 05:35:26 +00001008 ThreadSP thread_sp (exe_ctx.GetThreadSP());
1009 SBThread sb_thread (thread_sp);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001010
1011 if (log)
Caroline Tice750cd172010-10-26 23:49:36 +00001012 {
1013 SBStream sstr;
1014 sb_thread.GetDescription (sstr);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001015 log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s",
1016 static_cast<void*>(exe_ctx.GetFramePtr()),
1017 static_cast<void*>(thread_sp.get()), sstr.GetData());
Caroline Tice750cd172010-10-26 23:49:36 +00001018 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001019
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001020 return sb_thread;
1021}
1022
1023const char *
1024SBFrame::Disassemble () const
1025{
Greg Clayton5160ce52013-03-27 23:08:40 +00001026 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +00001027 const char *disassembly = NULL;
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001028 Mutex::Locker api_locker;
1029 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1030
Jason Molendab57e4a12013-11-04 09:33:30 +00001031 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +00001032 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +00001033 Process *process = exe_ctx.GetProcessPtr();
1034 if (target && process)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001035 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001036 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001037 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001038 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001039 frame = exe_ctx.GetFramePtr();
1040 if (frame)
1041 {
1042 disassembly = frame->Disassemble();
1043 }
1044 else
1045 {
1046 if (log)
1047 log->Printf ("SBFrame::Disassemble () => error: could not reconstruct frame object for this SBFrame.");
1048 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001049 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001050 else
1051 {
1052 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001053 log->Printf ("SBFrame::Disassemble () => error: process is running");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001054 }
Greg Claytonaf67cec2010-12-20 20:49:23 +00001055 }
Greg Clayton48381312010-10-30 04:51:46 +00001056
1057 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001058 log->Printf ("SBFrame(%p)::Disassemble () => %s",
1059 static_cast<void*>(frame), disassembly);
Greg Clayton48381312010-10-30 04:51:46 +00001060
1061 return disassembly;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001062}
1063
1064
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001065SBValueList
1066SBFrame::GetVariables (bool arguments,
1067 bool locals,
1068 bool statics,
1069 bool in_scope_only)
1070{
Greg Clayton316d4982011-06-18 20:06:08 +00001071 SBValueList value_list;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001072 ExecutionContext exe_ctx(m_opaque_sp.get());
Jason Molendab57e4a12013-11-04 09:33:30 +00001073 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Claytond9e416c2012-02-18 05:35:26 +00001074 Target *target = exe_ctx.GetTargetPtr();
1075 if (frame && target)
Greg Clayton316d4982011-06-18 20:06:08 +00001076 {
Greg Claytond9e416c2012-02-18 05:35:26 +00001077 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
Zachary Turnerb3b89222015-02-17 17:42:05 +00001078 value_list = GetVariables (arguments, locals, statics, in_scope_only, use_dynamic);
Greg Clayton316d4982011-06-18 20:06:08 +00001079 }
1080 return value_list;
Jim Ingham78a685a2011-04-16 00:01:13 +00001081}
1082
Enrico Granata560558e2015-02-11 02:35:39 +00001083lldb::SBValueList
1084SBFrame::GetVariables (bool arguments,
1085 bool locals,
1086 bool statics,
1087 bool in_scope_only,
1088 lldb::DynamicValueType use_dynamic)
1089{
1090 ExecutionContext exe_ctx(m_opaque_sp.get());
1091 Target *target = exe_ctx.GetTargetPtr();
Zachary Turnerb3b89222015-02-17 17:42:05 +00001092 bool include_runtime_support_values = target ? target->GetDisplayRuntimeSupportValues() : false;
1093 return GetVariables(arguments,
1094 locals,
1095 statics,
1096 in_scope_only,
1097 include_runtime_support_values,
1098 use_dynamic);
Enrico Granata560558e2015-02-11 02:35:39 +00001099}
1100
Jim Ingham78a685a2011-04-16 00:01:13 +00001101SBValueList
Zachary Turnerb3b89222015-02-17 17:42:05 +00001102SBFrame::GetVariables (bool arguments,
1103 bool locals,
1104 bool statics,
1105 bool in_scope_only,
1106 bool include_runtime_support_values,
1107 lldb::DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00001108{
Greg Clayton5160ce52013-03-27 23:08:40 +00001109 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001110
Greg Claytonb9556ac2012-01-30 07:41:31 +00001111 SBValueList value_list;
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001112 Mutex::Locker api_locker;
1113 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1114
Jason Molendab57e4a12013-11-04 09:33:30 +00001115 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +00001116 Target *target = exe_ctx.GetTargetPtr();
Greg Claytonb9556ac2012-01-30 07:41:31 +00001117
Caroline Ticeceb6b132010-10-26 03:11:13 +00001118 if (log)
Zachary Turnerb3b89222015-02-17 17:42:05 +00001119 log->Printf ("SBFrame::GetVariables (arguments=%i, locals=%i, statics=%i, in_scope_only=%i)",
1120 arguments, locals, statics, in_scope_only);
1121
Jim Ingham7730b9a2012-11-29 00:26:19 +00001122 Process *process = exe_ctx.GetProcessPtr();
1123 if (target && process)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001124 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001125 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001126 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001127 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001128 frame = exe_ctx.GetFramePtr();
1129 if (frame)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001130 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001131 size_t i;
1132 VariableList *variable_list = NULL;
1133 variable_list = frame->GetVariableList(true);
1134 if (variable_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001135 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001136 const size_t num_variables = variable_list->GetSize();
1137 if (num_variables)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001138 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001139 for (i = 0; i < num_variables; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001140 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001141 VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
1142 if (variable_sp)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001143 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001144 bool add_variable = false;
1145 switch (variable_sp->GetScope())
1146 {
1147 case eValueTypeVariableGlobal:
1148 case eValueTypeVariableStatic:
1149 add_variable = statics;
1150 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001151
Jim Ingham7730b9a2012-11-29 00:26:19 +00001152 case eValueTypeVariableArgument:
1153 add_variable = arguments;
1154 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001155
Jim Ingham7730b9a2012-11-29 00:26:19 +00001156 case eValueTypeVariableLocal:
1157 add_variable = locals;
1158 break;
Greg Claytonc982c762010-07-09 20:39:50 +00001159
Jim Ingham7730b9a2012-11-29 00:26:19 +00001160 default:
1161 break;
1162 }
1163 if (add_variable)
1164 {
1165 if (in_scope_only && !variable_sp->IsInScope(frame))
1166 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001167
Jim Ingham7730b9a2012-11-29 00:26:19 +00001168 ValueObjectSP valobj_sp(frame->GetValueObjectForFrameVariable (variable_sp, eNoDynamicValues));
Enrico Granata560558e2015-02-11 02:35:39 +00001169
1170 if (false == include_runtime_support_values &&
1171 valobj_sp &&
1172 true == valobj_sp->IsRuntimeSupportValue())
1173 continue;
1174
Jim Ingham7730b9a2012-11-29 00:26:19 +00001175 SBValue value_sb;
1176 value_sb.SetSP(valobj_sp,use_dynamic);
1177 value_list.Append(value_sb);
1178 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001179 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001180 }
1181 }
1182 }
1183 }
Jim Ingham7730b9a2012-11-29 00:26:19 +00001184 else
1185 {
1186 if (log)
1187 log->Printf ("SBFrame::GetVariables () => error: could not reconstruct frame object for this SBFrame.");
1188 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001189 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001190 else
1191 {
1192 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001193 log->Printf ("SBFrame::GetVariables () => error: process is running");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001194 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001195 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001196
1197 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001198 log->Printf ("SBFrame(%p)::GetVariables (...) => SBValueList(%p)",
1199 static_cast<void*>(frame),
1200 static_cast<void*>(value_list.opaque_ptr()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001201
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001202 return value_list;
1203}
1204
Greg Clayton69b582f2010-12-14 18:39:31 +00001205SBValueList
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001206SBFrame::GetRegisters ()
1207{
Greg Clayton5160ce52013-03-27 23:08:40 +00001208 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001209
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001210 SBValueList value_list;
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001211 Mutex::Locker api_locker;
1212 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1213
Jason Molendab57e4a12013-11-04 09:33:30 +00001214 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +00001215 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +00001216 Process *process = exe_ctx.GetProcessPtr();
1217 if (target && process)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001218 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001219 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001220 if (stop_locker.TryLock(&process->GetRunLock()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001221 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001222 frame = exe_ctx.GetFramePtr();
1223 if (frame)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001224 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001225 RegisterContextSP reg_ctx (frame->GetRegisterContext());
1226 if (reg_ctx)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001227 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001228 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
1229 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
1230 {
1231 value_list.Append(ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx));
1232 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001233 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001234 }
Jim Ingham7730b9a2012-11-29 00:26:19 +00001235 else
1236 {
1237 if (log)
1238 log->Printf ("SBFrame::GetRegisters () => error: could not reconstruct frame object for this SBFrame.");
1239 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001240 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001241 else
1242 {
1243 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001244 log->Printf ("SBFrame::GetRegisters () => error: process is running");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001245 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001246 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001247
1248 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001249 log->Printf ("SBFrame(%p)::GetRegisters () => SBValueList(%p)",
1250 static_cast<void*>(frame),
1251 static_cast<void*>(value_list.opaque_ptr()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001252
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001253 return value_list;
1254}
1255
Jason Molendaad9a53c2013-07-26 02:08:48 +00001256SBValue
1257SBFrame::FindRegister (const char *name)
1258{
1259 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1260
1261 SBValue result;
1262 ValueObjectSP value_sp;
1263 Mutex::Locker api_locker;
1264 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1265
Jason Molendab57e4a12013-11-04 09:33:30 +00001266 StackFrame *frame = NULL;
Jason Molendaad9a53c2013-07-26 02:08:48 +00001267 Target *target = exe_ctx.GetTargetPtr();
1268 Process *process = exe_ctx.GetProcessPtr();
1269 if (target && process)
1270 {
1271 Process::StopLocker stop_locker;
1272 if (stop_locker.TryLock(&process->GetRunLock()))
1273 {
1274 frame = exe_ctx.GetFramePtr();
1275 if (frame)
1276 {
1277 RegisterContextSP reg_ctx (frame->GetRegisterContext());
1278 if (reg_ctx)
1279 {
1280 const uint32_t num_regs = reg_ctx->GetRegisterCount();
1281 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx)
1282 {
1283 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
1284 if (reg_info &&
1285 ((reg_info->name && strcasecmp (reg_info->name, name) == 0) ||
1286 (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0)))
1287 {
1288 value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx);
1289 result.SetSP (value_sp);
1290 break;
1291 }
1292 }
1293 }
1294 }
1295 else
1296 {
1297 if (log)
Jason Molenda5d353842013-07-26 22:52:30 +00001298 log->Printf ("SBFrame::FindRegister () => error: could not reconstruct frame object for this SBFrame.");
Jason Molendaad9a53c2013-07-26 02:08:48 +00001299 }
1300 }
1301 else
1302 {
1303 if (log)
Jason Molenda5d353842013-07-26 22:52:30 +00001304 log->Printf ("SBFrame::FindRegister () => error: process is running");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001305 }
Jason Molendaad9a53c2013-07-26 02:08:48 +00001306 }
1307
1308 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001309 log->Printf ("SBFrame(%p)::FindRegister () => SBValue(%p)",
1310 static_cast<void*>(frame),
1311 static_cast<void*>(value_sp.get()));
Jason Molendaad9a53c2013-07-26 02:08:48 +00001312
1313 return result;
1314}
1315
Caroline Ticedde9cff2010-09-20 05:20:02 +00001316bool
1317SBFrame::GetDescription (SBStream &description)
1318{
Greg Clayton5160ce52013-03-27 23:08:40 +00001319 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001320 Stream &strm = description.ref();
1321
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001322 Mutex::Locker api_locker;
1323 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1324
Jason Molendab57e4a12013-11-04 09:33:30 +00001325 StackFrame *frame;
Greg Claytond9e416c2012-02-18 05:35:26 +00001326 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +00001327 Process *process = exe_ctx.GetProcessPtr();
1328 if (target && process)
Caroline Ticedde9cff2010-09-20 05:20:02 +00001329 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001330 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001331 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001332 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001333 frame = exe_ctx.GetFramePtr();
1334 if (frame)
1335 {
1336 frame->DumpUsingSettingsFormat (&strm);
1337 }
1338 else
1339 {
1340 if (log)
1341 log->Printf ("SBFrame::GetDescription () => error: could not reconstruct frame object for this SBFrame.");
1342 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001343 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001344 else
1345 {
Greg Claytonc9858e42012-04-06 02:17:47 +00001346 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001347 log->Printf ("SBFrame::GetDescription () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +00001348 }
1349
Caroline Ticedde9cff2010-09-20 05:20:02 +00001350 }
1351 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001352 strm.PutCString ("No value");
Caroline Ticedde9cff2010-09-20 05:20:02 +00001353
1354 return true;
1355}
Greg Clayton1d3afba2010-10-05 00:00:42 +00001356
Greg Clayton69b582f2010-12-14 18:39:31 +00001357SBValue
Greg Clayton1d3afba2010-10-05 00:00:42 +00001358SBFrame::EvaluateExpression (const char *expr)
1359{
Greg Clayton316d4982011-06-18 20:06:08 +00001360 SBValue result;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001361 ExecutionContext exe_ctx(m_opaque_sp.get());
Jason Molendab57e4a12013-11-04 09:33:30 +00001362 StackFrame *frame = exe_ctx.GetFramePtr();
Greg Claytond9e416c2012-02-18 05:35:26 +00001363 Target *target = exe_ctx.GetTargetPtr();
1364 if (frame && target)
Greg Clayton316d4982011-06-18 20:06:08 +00001365 {
Jim Ingham35e1bda2012-10-16 21:41:58 +00001366 SBExpressionOptions options;
1367 lldb::DynamicValueType fetch_dynamic_value = frame->CalculateTarget()->GetPreferDynamicValue();
Greg Claytoncced1562012-10-16 22:58:25 +00001368 options.SetFetchDynamicValue (fetch_dynamic_value);
Jim Ingham35e1bda2012-10-16 21:41:58 +00001369 options.SetUnwindOnError (true);
1370 return EvaluateExpression (expr, options);
Greg Clayton316d4982011-06-18 20:06:08 +00001371 }
1372 return result;
Jim Ingham78a685a2011-04-16 00:01:13 +00001373}
1374
1375SBValue
Jim Ingham2837b762011-05-04 03:43:18 +00001376SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value)
Jim Ingham78a685a2011-04-16 00:01:13 +00001377{
Jim Ingham35e1bda2012-10-16 21:41:58 +00001378 SBExpressionOptions options;
Greg Claytoncced1562012-10-16 22:58:25 +00001379 options.SetFetchDynamicValue (fetch_dynamic_value);
Jim Ingham35e1bda2012-10-16 21:41:58 +00001380 options.SetUnwindOnError (true);
1381 return EvaluateExpression (expr, options);
Jim Ingham7ba6e992012-05-11 23:47:32 +00001382}
1383
1384SBValue
1385SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value, bool unwind_on_error)
1386{
Jim Ingham35e1bda2012-10-16 21:41:58 +00001387 SBExpressionOptions options;
Greg Claytoncced1562012-10-16 22:58:25 +00001388 options.SetFetchDynamicValue (fetch_dynamic_value);
Jim Ingham35e1bda2012-10-16 21:41:58 +00001389 options.SetUnwindOnError (unwind_on_error);
1390 return EvaluateExpression (expr, options);
1391}
1392
1393lldb::SBValue
1394SBFrame::EvaluateExpression (const char *expr, const SBExpressionOptions &options)
1395{
Greg Clayton5160ce52013-03-27 23:08:40 +00001396 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001397
Greg Clayton5160ce52013-03-27 23:08:40 +00001398 Log *expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Greg Clayton48381312010-10-30 04:51:46 +00001399
Jim Ingham8646d3c2014-05-05 02:47:44 +00001400 ExpressionResults exe_results = eExpressionSetupError;
Greg Clayton69b582f2010-12-14 18:39:31 +00001401 SBValue expr_result;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001402
Jim Ingham7730b9a2012-11-29 00:26:19 +00001403 if (expr == NULL || expr[0] == '\0')
1404 {
1405 if (log)
1406 log->Printf ("SBFrame::EvaluateExpression called with an empty expression");
1407 return expr_result;
1408 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001409
Greg Clayton81e871e2012-02-04 02:27:34 +00001410 ValueObjectSP expr_value_sp;
Greg Clayton48381312010-10-30 04:51:46 +00001411
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001412 Mutex::Locker api_locker;
1413 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1414
Greg Claytonb9556ac2012-01-30 07:41:31 +00001415 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001416 log->Printf ("SBFrame()::EvaluateExpression (expr=\"%s\")...", expr);
Greg Claytonb9556ac2012-01-30 07:41:31 +00001417
Jason Molendab57e4a12013-11-04 09:33:30 +00001418 StackFrame *frame = NULL;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001419 Target *target = exe_ctx.GetTargetPtr();
1420 Process *process = exe_ctx.GetProcessPtr();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001421
Jim Ingham7730b9a2012-11-29 00:26:19 +00001422 if (target && process)
1423 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001424 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001425 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001426 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001427 frame = exe_ctx.GetFramePtr();
1428 if (frame)
1429 {
Greg Claytonfb6621e2013-12-06 21:59:52 +00001430 if (target->GetDisplayExpressionsInCrashlogs())
1431 {
1432 StreamString frame_description;
1433 frame->DumpUsingSettingsFormat (&frame_description);
1434 Host::SetCrashDescriptionWithFormat ("SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
1435 expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str());
1436 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001437
Greg Claytonfb6621e2013-12-06 21:59:52 +00001438 exe_results = target->EvaluateExpression (expr,
Jim Ingham7730b9a2012-11-29 00:26:19 +00001439 frame,
1440 expr_value_sp,
1441 options.ref());
1442 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
Greg Claytonfb6621e2013-12-06 21:59:52 +00001443
1444 if (target->GetDisplayExpressionsInCrashlogs())
1445 Host::SetCrashDescription (NULL);
Jim Ingham7730b9a2012-11-29 00:26:19 +00001446 }
1447 else
1448 {
1449 if (log)
1450 log->Printf ("SBFrame::EvaluateExpression () => error: could not reconstruct frame object for this SBFrame.");
1451 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001452 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001453 else
1454 {
1455 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001456 log->Printf ("SBFrame::EvaluateExpression () => error: process is running");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001457 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00001458 }
Jason Molendacf7e2dc2012-02-21 05:33:55 +00001459
1460#ifndef LLDB_DISABLE_PYTHON
Sean Callanana162eba2010-12-07 22:55:01 +00001461 if (expr_log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001462 expr_log->Printf("** [SBFrame::EvaluateExpression] Expression result is %s, summary %s **",
1463 expr_result.GetValue(), expr_result.GetSummary());
1464
Greg Clayton48381312010-10-30 04:51:46 +00001465 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001466 log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)",
1467 static_cast<void*>(frame), expr,
1468 static_cast<void*>(expr_value_sp.get()), exe_results);
Jason Molendacf7e2dc2012-02-21 05:33:55 +00001469#endif
Greg Clayton48381312010-10-30 04:51:46 +00001470
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001471 return expr_result;
Greg Clayton1d3afba2010-10-05 00:00:42 +00001472}
Greg Clayton316d4982011-06-18 20:06:08 +00001473
1474bool
1475SBFrame::IsInlined()
1476{
Greg Clayton5160ce52013-03-27 23:08:40 +00001477 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001478 ExecutionContext exe_ctx(m_opaque_sp.get());
Jason Molendab57e4a12013-11-04 09:33:30 +00001479 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +00001480 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +00001481 Process *process = exe_ctx.GetProcessPtr();
1482 if (target && process)
Greg Clayton316d4982011-06-18 20:06:08 +00001483 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001484 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001485 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001486 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001487 frame = exe_ctx.GetFramePtr();
1488 if (frame)
1489 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001490
Jim Ingham7730b9a2012-11-29 00:26:19 +00001491 Block *block = frame->GetSymbolContext(eSymbolContextBlock).block;
1492 if (block)
1493 return block->GetContainingInlinedBlock () != NULL;
1494 }
1495 else
1496 {
1497 if (log)
1498 log->Printf ("SBFrame::IsInlined () => error: could not reconstruct frame object for this SBFrame.");
1499 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001500 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001501 else
1502 {
Greg Claytonc9858e42012-04-06 02:17:47 +00001503 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001504 log->Printf ("SBFrame::IsInlined () => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +00001505 }
1506
Greg Clayton316d4982011-06-18 20:06:08 +00001507 }
1508 return false;
1509}
1510
1511const char *
1512SBFrame::GetFunctionName()
1513{
Greg Clayton5160ce52013-03-27 23:08:40 +00001514 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton316d4982011-06-18 20:06:08 +00001515 const char *name = NULL;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001516 ExecutionContext exe_ctx(m_opaque_sp.get());
Jason Molendab57e4a12013-11-04 09:33:30 +00001517 StackFrame *frame = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +00001518 Target *target = exe_ctx.GetTargetPtr();
Jim Ingham7730b9a2012-11-29 00:26:19 +00001519 Process *process = exe_ctx.GetProcessPtr();
1520 if (target && process)
Greg Clayton316d4982011-06-18 20:06:08 +00001521 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001522 Process::StopLocker stop_locker;
Jim Ingham7730b9a2012-11-29 00:26:19 +00001523 if (stop_locker.TryLock(&process->GetRunLock()))
Greg Clayton316d4982011-06-18 20:06:08 +00001524 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001525 frame = exe_ctx.GetFramePtr();
1526 if (frame)
Greg Clayton316d4982011-06-18 20:06:08 +00001527 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001528 SymbolContext sc (frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol));
1529 if (sc.block)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001530 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001531 Block *inlined_block = sc.block->GetContainingInlinedBlock ();
1532 if (inlined_block)
1533 {
1534 const InlineFunctionInfo* inlined_info = inlined_block->GetInlinedFunctionInfo();
1535 name = inlined_info->GetName().AsCString();
1536 }
1537 }
1538
1539 if (name == NULL)
1540 {
1541 if (sc.function)
1542 name = sc.function->GetName().GetCString();
1543 }
1544
1545 if (name == NULL)
1546 {
1547 if (sc.symbol)
1548 name = sc.symbol->GetName().GetCString();
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001549 }
Greg Clayton316d4982011-06-18 20:06:08 +00001550 }
Jim Ingham7730b9a2012-11-29 00:26:19 +00001551 else
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001552 {
Jim Ingham7730b9a2012-11-29 00:26:19 +00001553 if (log)
1554 log->Printf ("SBFrame::GetFunctionName () => error: could not reconstruct frame object for this SBFrame.");
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001555 }
Greg Clayton316d4982011-06-18 20:06:08 +00001556 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001557 else
1558 {
Greg Claytonc9858e42012-04-06 02:17:47 +00001559 if (log)
Jim Ingham7730b9a2012-11-29 00:26:19 +00001560 log->Printf ("SBFrame::GetFunctionName() => error: process is running");
Greg Claytonc9858e42012-04-06 02:17:47 +00001561
1562 }
Greg Clayton316d4982011-06-18 20:06:08 +00001563 }
1564 return name;
1565}
1566