130fdc8d8SChris Lattner //===-- SBFrame.cpp ---------------------------------------------*- C++ -*-===//
230fdc8d8SChris Lattner //
330fdc8d8SChris Lattner //                     The LLVM Compiler Infrastructure
430fdc8d8SChris Lattner //
530fdc8d8SChris Lattner // This file is distributed under the University of Illinois Open Source
630fdc8d8SChris Lattner // License. See LICENSE.TXT for details.
730fdc8d8SChris Lattner //
830fdc8d8SChris Lattner //===----------------------------------------------------------------------===//
930fdc8d8SChris Lattner 
10dbb0abbfSEugene Zelenko // C Includes
11dbb0abbfSEugene Zelenko // C++ Includes
1230fdc8d8SChris Lattner #include <algorithm>
13349213f9SGreg Clayton #include <set>
14dbb0abbfSEugene Zelenko #include <string>
15dbb0abbfSEugene Zelenko 
16dbb0abbfSEugene Zelenko // Other libraries and framework includes
17dbb0abbfSEugene Zelenko // Project includes
18dbb0abbfSEugene Zelenko #include "lldb/API/SBFrame.h"
1930fdc8d8SChris Lattner 
2030fdc8d8SChris Lattner #include "lldb/lldb-types.h"
2130fdc8d8SChris Lattner 
2230fdc8d8SChris Lattner #include "lldb/Core/Address.h"
2330fdc8d8SChris Lattner #include "lldb/Core/ConstString.h"
24ceb6b139SCaroline Tice #include "lldb/Core/Log.h"
2530fdc8d8SChris Lattner #include "lldb/Core/Stream.h"
2630fdc8d8SChris Lattner #include "lldb/Core/StreamFile.h"
2730fdc8d8SChris Lattner #include "lldb/Core/ValueObjectRegister.h"
2830fdc8d8SChris Lattner #include "lldb/Core/ValueObjectVariable.h"
294dbb271fSSean Callanan #include "Plugins/ExpressionParser/Clang/ClangPersistentVariables.h"
30151c032cSJim Ingham #include "lldb/Expression/UserExpression.h"
311ba7c4d0SGreg Clayton #include "lldb/Host/Host.h"
3230fdc8d8SChris Lattner #include "lldb/Symbol/Block.h"
331f746071SGreg Clayton #include "lldb/Symbol/Function.h"
341f746071SGreg Clayton #include "lldb/Symbol/Symbol.h"
3530fdc8d8SChris Lattner #include "lldb/Symbol/SymbolContext.h"
3630fdc8d8SChris Lattner #include "lldb/Symbol/VariableList.h"
3730fdc8d8SChris Lattner #include "lldb/Symbol/Variable.h"
3830fdc8d8SChris Lattner #include "lldb/Target/ExecutionContext.h"
3930fdc8d8SChris Lattner #include "lldb/Target/Target.h"
4030fdc8d8SChris Lattner #include "lldb/Target/Process.h"
4130fdc8d8SChris Lattner #include "lldb/Target/RegisterContext.h"
42b57e4a1bSJason Molenda #include "lldb/Target/StackFrame.h"
43b9556accSGreg Clayton #include "lldb/Target/StackID.h"
4430fdc8d8SChris Lattner #include "lldb/Target/Thread.h"
4530fdc8d8SChris Lattner 
464c5de699SEli Friedman #include "lldb/API/SBDebugger.h"
474c5de699SEli Friedman #include "lldb/API/SBValue.h"
484c5de699SEli Friedman #include "lldb/API/SBAddress.h"
4935e1bda6SJim Ingham #include "lldb/API/SBExpressionOptions.h"
50dde9cff3SCaroline Tice #include "lldb/API/SBStream.h"
514c5de699SEli Friedman #include "lldb/API/SBSymbolContext.h"
524c5de699SEli Friedman #include "lldb/API/SBThread.h"
5351f96eebSZachary Turner #include "lldb/API/SBVariablesOptions.h"
5430fdc8d8SChris Lattner 
5530fdc8d8SChris Lattner using namespace lldb;
5630fdc8d8SChris Lattner using namespace lldb_private;
5730fdc8d8SChris Lattner 
5830fdc8d8SChris Lattner SBFrame::SBFrame () :
597fdf9ef1SGreg Clayton     m_opaque_sp (new ExecutionContextRef())
6030fdc8d8SChris Lattner {
6130fdc8d8SChris Lattner }
6230fdc8d8SChris Lattner 
63b57e4a1bSJason Molenda SBFrame::SBFrame (const StackFrameSP &lldb_object_sp) :
647fdf9ef1SGreg Clayton     m_opaque_sp (new ExecutionContextRef (lldb_object_sp))
6530fdc8d8SChris Lattner {
665160ce5cSGreg Clayton     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
67ceb6b139SCaroline Tice 
68ceb6b139SCaroline Tice     if (log)
69ceb6b139SCaroline Tice     {
70ceb6b139SCaroline Tice         SBStream sstr;
71ceb6b139SCaroline Tice         GetDescription (sstr);
724838131bSGreg Clayton         log->Printf ("SBFrame::SBFrame (sp=%p) => SBFrame(%p): %s",
73324a1036SSaleem Abdulrasool                      static_cast<void*>(lldb_object_sp.get()),
74324a1036SSaleem Abdulrasool                      static_cast<void*>(lldb_object_sp.get()), sstr.GetData());
75ceb6b139SCaroline Tice     }
7630fdc8d8SChris Lattner }
7730fdc8d8SChris Lattner 
78efabb123SGreg Clayton SBFrame::SBFrame(const SBFrame &rhs) :
797fdf9ef1SGreg Clayton     m_opaque_sp (new ExecutionContextRef (*rhs.m_opaque_sp))
80efabb123SGreg Clayton {
81efabb123SGreg Clayton }
82efabb123SGreg Clayton 
83dbb0abbfSEugene Zelenko SBFrame::~SBFrame() = default;
84dbb0abbfSEugene Zelenko 
85efabb123SGreg Clayton const SBFrame &
86efabb123SGreg Clayton SBFrame::operator = (const SBFrame &rhs)
87efabb123SGreg Clayton {
88efabb123SGreg Clayton     if (this != &rhs)
897fdf9ef1SGreg Clayton         *m_opaque_sp = *rhs.m_opaque_sp;
90efabb123SGreg Clayton     return *this;
91efabb123SGreg Clayton }
92efabb123SGreg Clayton 
93b57e4a1bSJason Molenda StackFrameSP
94b9556accSGreg Clayton SBFrame::GetFrameSP() const
95b9556accSGreg Clayton {
96dbb0abbfSEugene Zelenko     return (m_opaque_sp ? m_opaque_sp->GetFrameSP() : StackFrameSP());
97b9556accSGreg Clayton }
9830fdc8d8SChris Lattner 
9930fdc8d8SChris Lattner void
100b57e4a1bSJason Molenda SBFrame::SetFrameSP (const StackFrameSP &lldb_object_sp)
10130fdc8d8SChris Lattner {
1027fdf9ef1SGreg Clayton     return m_opaque_sp->SetFrameSP(lldb_object_sp);
103b9556accSGreg Clayton }
10430fdc8d8SChris Lattner 
10530fdc8d8SChris Lattner bool
10630fdc8d8SChris Lattner SBFrame::IsValid() const
10730fdc8d8SChris Lattner {
108*bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
109*bb19a13cSSaleem Abdulrasool     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1107fa7dc36SJim Ingham 
1117fa7dc36SJim Ingham     Target *target = exe_ctx.GetTargetPtr();
1127fa7dc36SJim Ingham     Process *process = exe_ctx.GetProcessPtr();
1137fa7dc36SJim Ingham     if (target && process)
1147fa7dc36SJim Ingham     {
1157fa7dc36SJim Ingham         Process::StopLocker stop_locker;
1167fa7dc36SJim Ingham         if (stop_locker.TryLock(&process->GetRunLock()))
117dbb0abbfSEugene Zelenko         return GetFrameSP().get() != nullptr;
11830fdc8d8SChris Lattner     }
11930fdc8d8SChris Lattner 
1207fa7dc36SJim Ingham     // Without a target & process we can't have a valid stack frame.
1217fa7dc36SJim Ingham     return false;
1227fa7dc36SJim Ingham }
1237fa7dc36SJim Ingham 
12430fdc8d8SChris Lattner SBSymbolContext
12530fdc8d8SChris Lattner SBFrame::GetSymbolContext (uint32_t resolve_scope) const
12630fdc8d8SChris Lattner {
1275160ce5cSGreg Clayton     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
12830fdc8d8SChris Lattner     SBSymbolContext sb_sym_ctx;
129*bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
130*bb19a13cSSaleem Abdulrasool     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1314fc6cb9cSJim Ingham 
132dbb0abbfSEugene Zelenko     StackFrame *frame = nullptr;
133d9e416c0SGreg Clayton     Target *target = exe_ctx.GetTargetPtr();
1347730b9a4SJim Ingham     Process *process = exe_ctx.GetProcessPtr();
1357730b9a4SJim Ingham     if (target && process)
136af67cecdSGreg Clayton     {
1377fdf9ef1SGreg Clayton         Process::StopLocker stop_locker;
1387730b9a4SJim Ingham         if (stop_locker.TryLock(&process->GetRunLock()))
1397730b9a4SJim Ingham         {
1407730b9a4SJim Ingham             frame = exe_ctx.GetFramePtr();
1417730b9a4SJim Ingham             if (frame)
1427fdf9ef1SGreg Clayton             {
143d9e416c0SGreg Clayton                 sb_sym_ctx.SetSymbolContext(&frame->GetSymbolContext (resolve_scope));
144af67cecdSGreg Clayton             }
145c9858e4dSGreg Clayton             else
146c9858e4dSGreg Clayton             {
147c9858e4dSGreg Clayton                 if (log)
1487730b9a4SJim Ingham                     log->Printf ("SBFrame::GetVariables () => error: could not reconstruct frame object for this SBFrame.");
1497730b9a4SJim Ingham             }
1507730b9a4SJim Ingham         }
1517730b9a4SJim Ingham         else
1527730b9a4SJim Ingham         {
1537730b9a4SJim Ingham             if (log)
1547730b9a4SJim Ingham                 log->Printf ("SBFrame::GetSymbolContext () => error: process is running");
155c9858e4dSGreg Clayton         }
1567fdf9ef1SGreg Clayton     }
157ceb6b139SCaroline Tice 
158ceb6b139SCaroline Tice     if (log)
1594838131bSGreg Clayton         log->Printf ("SBFrame(%p)::GetSymbolContext (resolve_scope=0x%8.8x) => SBSymbolContext(%p)",
160324a1036SSaleem Abdulrasool                      static_cast<void*>(frame), resolve_scope,
161324a1036SSaleem Abdulrasool                      static_cast<void*>(sb_sym_ctx.get()));
162ceb6b139SCaroline Tice 
16330fdc8d8SChris Lattner     return sb_sym_ctx;
16430fdc8d8SChris Lattner }
16530fdc8d8SChris Lattner 
16630fdc8d8SChris Lattner SBModule
16730fdc8d8SChris Lattner SBFrame::GetModule () const
16830fdc8d8SChris Lattner {
1695160ce5cSGreg Clayton     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
17072eff18aSGreg Clayton     SBModule sb_module;
171acdbe816SGreg Clayton     ModuleSP module_sp;
172*bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
173*bb19a13cSSaleem Abdulrasool     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1744fc6cb9cSJim Ingham 
175dbb0abbfSEugene Zelenko     StackFrame *frame = nullptr;
176d9e416c0SGreg Clayton     Target *target = exe_ctx.GetTargetPtr();
1777730b9a4SJim Ingham     Process *process = exe_ctx.GetProcessPtr();
1787730b9a4SJim Ingham     if (target && process)
179af67cecdSGreg Clayton     {
1807fdf9ef1SGreg Clayton         Process::StopLocker stop_locker;
1817730b9a4SJim Ingham         if (stop_locker.TryLock(&process->GetRunLock()))
1827730b9a4SJim Ingham         {
1837730b9a4SJim Ingham             frame = exe_ctx.GetFramePtr();
1847730b9a4SJim Ingham             if (frame)
1857fdf9ef1SGreg Clayton             {
186d9e416c0SGreg Clayton                 module_sp = frame->GetSymbolContext (eSymbolContextModule).module_sp;
187acdbe816SGreg Clayton                 sb_module.SetSP (module_sp);
188af67cecdSGreg Clayton             }
189c9858e4dSGreg Clayton             else
190c9858e4dSGreg Clayton             {
191c9858e4dSGreg Clayton                 if (log)
1927730b9a4SJim Ingham                     log->Printf ("SBFrame::GetModule () => error: could not reconstruct frame object for this SBFrame.");
1937730b9a4SJim Ingham             }
1947730b9a4SJim Ingham         }
1957730b9a4SJim Ingham         else
1967730b9a4SJim Ingham         {
1977730b9a4SJim Ingham             if (log)
1987730b9a4SJim Ingham                 log->Printf ("SBFrame::GetModule () => error: process is running");
199c9858e4dSGreg Clayton         }
2007fdf9ef1SGreg Clayton     }
20172eff18aSGreg Clayton 
2024838131bSGreg Clayton     if (log)
2034838131bSGreg Clayton         log->Printf ("SBFrame(%p)::GetModule () => SBModule(%p)",
204324a1036SSaleem Abdulrasool                      static_cast<void*>(frame),
205324a1036SSaleem Abdulrasool                      static_cast<void*>(module_sp.get()));
2064838131bSGreg Clayton 
20730fdc8d8SChris Lattner     return sb_module;
20830fdc8d8SChris Lattner }
20930fdc8d8SChris Lattner 
21030fdc8d8SChris Lattner SBCompileUnit
21130fdc8d8SChris Lattner SBFrame::GetCompileUnit () const
21230fdc8d8SChris Lattner {
2135160ce5cSGreg Clayton     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
21472eff18aSGreg Clayton     SBCompileUnit sb_comp_unit;
215*bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
216*bb19a13cSSaleem Abdulrasool     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
2174fc6cb9cSJim Ingham 
218dbb0abbfSEugene Zelenko     StackFrame *frame = nullptr;
219d9e416c0SGreg Clayton     Target *target = exe_ctx.GetTargetPtr();
2207730b9a4SJim Ingham     Process *process = exe_ctx.GetProcessPtr();
2217730b9a4SJim Ingham     if (target && process)
222af67cecdSGreg Clayton     {
2237fdf9ef1SGreg Clayton         Process::StopLocker stop_locker;
2247730b9a4SJim Ingham         if (stop_locker.TryLock(&process->GetRunLock()))
2257730b9a4SJim Ingham         {
2267730b9a4SJim Ingham             frame = exe_ctx.GetFramePtr();
2277730b9a4SJim Ingham             if (frame)
2287fdf9ef1SGreg Clayton             {
229d9e416c0SGreg Clayton                 sb_comp_unit.reset (frame->GetSymbolContext (eSymbolContextCompUnit).comp_unit);
230af67cecdSGreg Clayton             }
231c9858e4dSGreg Clayton             else
232c9858e4dSGreg Clayton             {
233ceb6b139SCaroline Tice                 if (log)
2347730b9a4SJim Ingham                     log->Printf ("SBFrame::GetCompileUnit () => error: could not reconstruct frame object for this SBFrame.");
2357730b9a4SJim Ingham             }
2367730b9a4SJim Ingham         }
2377730b9a4SJim Ingham         else
2387730b9a4SJim Ingham         {
2397730b9a4SJim Ingham             if (log)
2407730b9a4SJim Ingham                 log->Printf ("SBFrame::GetCompileUnit () => error: process is running");
241c9858e4dSGreg Clayton         }
242c9858e4dSGreg Clayton     }
243c9858e4dSGreg Clayton     if (log)
244c9858e4dSGreg Clayton         log->Printf ("SBFrame(%p)::GetCompileUnit () => SBCompileUnit(%p)",
245324a1036SSaleem Abdulrasool                      static_cast<void*>(frame),
246324a1036SSaleem Abdulrasool                      static_cast<void*>(sb_comp_unit.get()));
247ceb6b139SCaroline Tice 
24830fdc8d8SChris Lattner     return sb_comp_unit;
24930fdc8d8SChris Lattner }
25030fdc8d8SChris Lattner 
25130fdc8d8SChris Lattner SBFunction
25230fdc8d8SChris Lattner SBFrame::GetFunction () const
25330fdc8d8SChris Lattner {
2545160ce5cSGreg Clayton     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
25572eff18aSGreg Clayton     SBFunction sb_function;
256*bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
257*bb19a13cSSaleem Abdulrasool     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
2584fc6cb9cSJim Ingham 
259dbb0abbfSEugene Zelenko     StackFrame *frame = nullptr;
260d9e416c0SGreg Clayton     Target *target = exe_ctx.GetTargetPtr();
2617730b9a4SJim Ingham     Process *process = exe_ctx.GetProcessPtr();
2627730b9a4SJim Ingham     if (target && process)
263af67cecdSGreg Clayton     {
2647fdf9ef1SGreg Clayton         Process::StopLocker stop_locker;
2657730b9a4SJim Ingham         if (stop_locker.TryLock(&process->GetRunLock()))
2667730b9a4SJim Ingham         {
2677730b9a4SJim Ingham             frame = exe_ctx.GetFramePtr();
2687730b9a4SJim Ingham             if (frame)
2697fdf9ef1SGreg Clayton             {
270d9e416c0SGreg Clayton                 sb_function.reset(frame->GetSymbolContext (eSymbolContextFunction).function);
271af67cecdSGreg Clayton             }
272c9858e4dSGreg Clayton             else
273c9858e4dSGreg Clayton             {
274c9858e4dSGreg Clayton                 if (log)
2757730b9a4SJim Ingham                     log->Printf ("SBFrame::GetFunction () => error: could not reconstruct frame object for this SBFrame.");
2767730b9a4SJim Ingham             }
2777730b9a4SJim Ingham         }
2787730b9a4SJim Ingham         else
2797730b9a4SJim Ingham         {
2807730b9a4SJim Ingham             if (log)
2817730b9a4SJim Ingham                 log->Printf ("SBFrame::GetFunction () => error: process is running");
2827fdf9ef1SGreg Clayton         }
283c9858e4dSGreg Clayton     }
2844838131bSGreg Clayton     if (log)
2854838131bSGreg Clayton         log->Printf ("SBFrame(%p)::GetFunction () => SBFunction(%p)",
286324a1036SSaleem Abdulrasool                      static_cast<void*>(frame),
287324a1036SSaleem Abdulrasool                      static_cast<void*>(sb_function.get()));
2884838131bSGreg Clayton 
28930fdc8d8SChris Lattner     return sb_function;
29030fdc8d8SChris Lattner }
29130fdc8d8SChris Lattner 
2923b06557eSGreg Clayton SBSymbol
2933b06557eSGreg Clayton SBFrame::GetSymbol () const
2943b06557eSGreg Clayton {
2955160ce5cSGreg Clayton     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
29672eff18aSGreg Clayton     SBSymbol sb_symbol;
297*bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
298*bb19a13cSSaleem Abdulrasool     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
2994fc6cb9cSJim Ingham 
300dbb0abbfSEugene Zelenko     StackFrame *frame = nullptr;
301d9e416c0SGreg Clayton     Target *target = exe_ctx.GetTargetPtr();
3027730b9a4SJim Ingham     Process *process = exe_ctx.GetProcessPtr();
3037730b9a4SJim Ingham     if (target && process)
304af67cecdSGreg Clayton     {
3057fdf9ef1SGreg Clayton         Process::StopLocker stop_locker;
3067730b9a4SJim Ingham         if (stop_locker.TryLock(&process->GetRunLock()))
3077730b9a4SJim Ingham         {
3087730b9a4SJim Ingham             frame = exe_ctx.GetFramePtr();
3097730b9a4SJim Ingham             if (frame)
3107fdf9ef1SGreg Clayton             {
311d9e416c0SGreg Clayton                 sb_symbol.reset(frame->GetSymbolContext (eSymbolContextSymbol).symbol);
312af67cecdSGreg Clayton             }
313c9858e4dSGreg Clayton             else
314c9858e4dSGreg Clayton             {
315c9858e4dSGreg Clayton                 if (log)
3167730b9a4SJim Ingham                     log->Printf ("SBFrame::GetSymbol () => error: could not reconstruct frame object for this SBFrame.");
3177730b9a4SJim Ingham             }
3187730b9a4SJim Ingham         }
3197730b9a4SJim Ingham         else
3207730b9a4SJim Ingham         {
3217730b9a4SJim Ingham             if (log)
3227730b9a4SJim Ingham                 log->Printf ("SBFrame::GetSymbol () => error: process is running");
3237fdf9ef1SGreg Clayton         }
324c9858e4dSGreg Clayton     }
3254838131bSGreg Clayton     if (log)
3264838131bSGreg Clayton         log->Printf ("SBFrame(%p)::GetSymbol () => SBSymbol(%p)",
327324a1036SSaleem Abdulrasool                      static_cast<void*>(frame),
328324a1036SSaleem Abdulrasool                      static_cast<void*>(sb_symbol.get()));
3293b06557eSGreg Clayton     return sb_symbol;
3303b06557eSGreg Clayton }
3313b06557eSGreg Clayton 
33230fdc8d8SChris Lattner SBBlock
33330fdc8d8SChris Lattner SBFrame::GetBlock () const
33430fdc8d8SChris Lattner {
3355160ce5cSGreg Clayton     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
33672eff18aSGreg Clayton     SBBlock sb_block;
337*bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
338*bb19a13cSSaleem Abdulrasool     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
3394fc6cb9cSJim Ingham 
340dbb0abbfSEugene Zelenko     StackFrame *frame = nullptr;
341d9e416c0SGreg Clayton     Target *target = exe_ctx.GetTargetPtr();
3427730b9a4SJim Ingham     Process *process = exe_ctx.GetProcessPtr();
3437730b9a4SJim Ingham     if (target && process)
344af67cecdSGreg Clayton     {
3457fdf9ef1SGreg Clayton         Process::StopLocker stop_locker;
3467730b9a4SJim Ingham         if (stop_locker.TryLock(&process->GetRunLock()))
3477730b9a4SJim Ingham         {
3487730b9a4SJim Ingham             frame = exe_ctx.GetFramePtr();
3497730b9a4SJim Ingham             if (frame)
3507fdf9ef1SGreg Clayton             {
351d9e416c0SGreg Clayton                 sb_block.SetPtr (frame->GetSymbolContext (eSymbolContextBlock).block);
352af67cecdSGreg Clayton             }
353c9858e4dSGreg Clayton             else
354c9858e4dSGreg Clayton             {
355c9858e4dSGreg Clayton                 if (log)
3567730b9a4SJim Ingham                     log->Printf ("SBFrame::GetBlock () => error: could not reconstruct frame object for this SBFrame.");
3577730b9a4SJim Ingham             }
3587730b9a4SJim Ingham         }
3597730b9a4SJim Ingham         else
3607730b9a4SJim Ingham         {
3617730b9a4SJim Ingham             if (log)
362324a1036SSaleem Abdulrasool                 log->Printf ("SBFrame(%p)::GetBlock () => error: process is running",
363324a1036SSaleem Abdulrasool                              static_cast<void*>(frame));
3647fdf9ef1SGreg Clayton         }
365c9858e4dSGreg Clayton     }
3664838131bSGreg Clayton     if (log)
3674838131bSGreg Clayton         log->Printf ("SBFrame(%p)::GetBlock () => SBBlock(%p)",
368324a1036SSaleem Abdulrasool                      static_cast<void*>(frame),
369324a1036SSaleem Abdulrasool                      static_cast<void*>(sb_block.GetPtr()));
37030fdc8d8SChris Lattner     return sb_block;
37130fdc8d8SChris Lattner }
37230fdc8d8SChris Lattner 
37395897c6aSGreg Clayton SBBlock
37495897c6aSGreg Clayton SBFrame::GetFrameBlock () const
37595897c6aSGreg Clayton {
37672eff18aSGreg Clayton     SBBlock sb_block;
377*bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
378*bb19a13cSSaleem Abdulrasool     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
3794fc6cb9cSJim Ingham 
380dbb0abbfSEugene Zelenko     StackFrame *frame = nullptr;
381d9e416c0SGreg Clayton     Target *target = exe_ctx.GetTargetPtr();
3825160ce5cSGreg Clayton     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
3837730b9a4SJim Ingham     Process *process = exe_ctx.GetProcessPtr();
3847730b9a4SJim Ingham     if (target && process)
385af67cecdSGreg Clayton     {
3867fdf9ef1SGreg Clayton         Process::StopLocker stop_locker;
3877730b9a4SJim Ingham         if (stop_locker.TryLock(&process->GetRunLock()))
3887730b9a4SJim Ingham         {
3897730b9a4SJim Ingham             frame = exe_ctx.GetFramePtr();
3907730b9a4SJim Ingham             if (frame)
3917fdf9ef1SGreg Clayton             {
392d9e416c0SGreg Clayton                 sb_block.SetPtr(frame->GetFrameBlock ());
393af67cecdSGreg Clayton             }
394c9858e4dSGreg Clayton             else
395c9858e4dSGreg Clayton             {
396c9858e4dSGreg Clayton                 if (log)
3977730b9a4SJim Ingham                     log->Printf ("SBFrame::GetFrameBlock () => error: could not reconstruct frame object for this SBFrame.");
3987730b9a4SJim Ingham             }
3997730b9a4SJim Ingham         }
4007730b9a4SJim Ingham         else
4017730b9a4SJim Ingham         {
4027730b9a4SJim Ingham             if (log)
4037730b9a4SJim Ingham                 log->Printf ("SBFrame::GetFrameBlock () => error: process is running");
4047fdf9ef1SGreg Clayton         }
405c9858e4dSGreg Clayton     }
4064838131bSGreg Clayton     if (log)
4074838131bSGreg Clayton         log->Printf ("SBFrame(%p)::GetFrameBlock () => SBBlock(%p)",
408324a1036SSaleem Abdulrasool                      static_cast<void*>(frame),
409324a1036SSaleem Abdulrasool                      static_cast<void*>(sb_block.GetPtr()));
41095897c6aSGreg Clayton     return sb_block;
41195897c6aSGreg Clayton }
41295897c6aSGreg Clayton 
41330fdc8d8SChris Lattner SBLineEntry
41430fdc8d8SChris Lattner SBFrame::GetLineEntry () const
41530fdc8d8SChris Lattner {
4165160ce5cSGreg Clayton     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
41772eff18aSGreg Clayton     SBLineEntry sb_line_entry;
418*bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
419*bb19a13cSSaleem Abdulrasool     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
4204fc6cb9cSJim Ingham 
421dbb0abbfSEugene Zelenko     StackFrame *frame = nullptr;
422d9e416c0SGreg Clayton     Target *target = exe_ctx.GetTargetPtr();
4237730b9a4SJim Ingham     Process *process = exe_ctx.GetProcessPtr();
4247730b9a4SJim Ingham     if (target && process)
425af67cecdSGreg Clayton     {
4267fdf9ef1SGreg Clayton         Process::StopLocker stop_locker;
4277730b9a4SJim Ingham         if (stop_locker.TryLock(&process->GetRunLock()))
4287730b9a4SJim Ingham         {
4297730b9a4SJim Ingham             frame = exe_ctx.GetFramePtr();
4307730b9a4SJim Ingham             if (frame)
4317fdf9ef1SGreg Clayton             {
432d9e416c0SGreg Clayton                 sb_line_entry.SetLineEntry (frame->GetSymbolContext (eSymbolContextLineEntry).line_entry);
433af67cecdSGreg Clayton             }
434c9858e4dSGreg Clayton             else
435c9858e4dSGreg Clayton             {
436c9858e4dSGreg Clayton                 if (log)
4377730b9a4SJim Ingham                     log->Printf ("SBFrame::GetLineEntry () => error: could not reconstruct frame object for this SBFrame.");
4387730b9a4SJim Ingham             }
4397730b9a4SJim Ingham         }
4407730b9a4SJim Ingham         else
4417730b9a4SJim Ingham         {
4427730b9a4SJim Ingham             if (log)
4437730b9a4SJim Ingham                 log->Printf ("SBFrame::GetLineEntry () => error: process is running");
4447fdf9ef1SGreg Clayton         }
445c9858e4dSGreg Clayton     }
4464838131bSGreg Clayton     if (log)
4474838131bSGreg Clayton         log->Printf ("SBFrame(%p)::GetLineEntry () => SBLineEntry(%p)",
448324a1036SSaleem Abdulrasool                      static_cast<void*>(frame),
449324a1036SSaleem Abdulrasool                      static_cast<void*>(sb_line_entry.get()));
45030fdc8d8SChris Lattner     return sb_line_entry;
45130fdc8d8SChris Lattner }
45230fdc8d8SChris Lattner 
45330fdc8d8SChris Lattner uint32_t
45430fdc8d8SChris Lattner SBFrame::GetFrameID () const
45530fdc8d8SChris Lattner {
456b9556accSGreg Clayton     uint32_t frame_idx = UINT32_MAX;
457b9556accSGreg Clayton 
4587fdf9ef1SGreg Clayton     ExecutionContext exe_ctx(m_opaque_sp.get());
459b57e4a1bSJason Molenda     StackFrame *frame = exe_ctx.GetFramePtr();
4607fdf9ef1SGreg Clayton     if (frame)
461d9e416c0SGreg Clayton         frame_idx = frame->GetFrameIndex ();
4624838131bSGreg Clayton 
4635160ce5cSGreg Clayton     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
4644838131bSGreg Clayton     if (log)
4654838131bSGreg Clayton         log->Printf ("SBFrame(%p)::GetFrameID () => %u",
466324a1036SSaleem Abdulrasool                      static_cast<void*>(frame), frame_idx);
4674838131bSGreg Clayton     return frame_idx;
46830fdc8d8SChris Lattner }
46930fdc8d8SChris Lattner 
470424a5dbcSGreg Clayton lldb::addr_t
471424a5dbcSGreg Clayton SBFrame::GetCFA () const
472424a5dbcSGreg Clayton {
473424a5dbcSGreg Clayton     ExecutionContext exe_ctx(m_opaque_sp.get());
474424a5dbcSGreg Clayton     StackFrame *frame = exe_ctx.GetFramePtr();
475424a5dbcSGreg Clayton     if (frame)
476424a5dbcSGreg Clayton         return frame->GetStackID().GetCallFrameAddress();
477424a5dbcSGreg Clayton     return LLDB_INVALID_ADDRESS;
478424a5dbcSGreg Clayton }
479424a5dbcSGreg Clayton 
48069b582faSGreg Clayton addr_t
48130fdc8d8SChris Lattner SBFrame::GetPC () const
48230fdc8d8SChris Lattner {
4835160ce5cSGreg Clayton     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
48469b582faSGreg Clayton     addr_t addr = LLDB_INVALID_ADDRESS;
485*bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
486*bb19a13cSSaleem Abdulrasool     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
4874fc6cb9cSJim Ingham 
488dbb0abbfSEugene Zelenko     StackFrame *frame = nullptr;
489d9e416c0SGreg Clayton     Target *target = exe_ctx.GetTargetPtr();
4907730b9a4SJim Ingham     Process *process = exe_ctx.GetProcessPtr();
4917730b9a4SJim Ingham     if (target && process)
492af67cecdSGreg Clayton     {
4937fdf9ef1SGreg Clayton         Process::StopLocker stop_locker;
4947730b9a4SJim Ingham         if (stop_locker.TryLock(&process->GetRunLock()))
4957730b9a4SJim Ingham         {
4967730b9a4SJim Ingham             frame = exe_ctx.GetFramePtr();
4977730b9a4SJim Ingham             if (frame)
4987fdf9ef1SGreg Clayton             {
49925b9f7ebSTamas Berghammer                 addr = frame->GetFrameCodeAddress().GetOpcodeLoadAddress (target, eAddressClassCode);
500af67cecdSGreg Clayton             }
501c9858e4dSGreg Clayton             else
502c9858e4dSGreg Clayton             {
503c9858e4dSGreg Clayton                 if (log)
5047730b9a4SJim Ingham                     log->Printf ("SBFrame::GetPC () => error: could not reconstruct frame object for this SBFrame.");
5057730b9a4SJim Ingham             }
5067730b9a4SJim Ingham         }
5077730b9a4SJim Ingham         else
5087730b9a4SJim Ingham         {
5097730b9a4SJim Ingham             if (log)
5107730b9a4SJim Ingham                 log->Printf ("SBFrame::GetPC () => error: process is running");
511c9858e4dSGreg Clayton         }
5127fdf9ef1SGreg Clayton     }
513ceb6b139SCaroline Tice 
514ceb6b139SCaroline Tice     if (log)
515324a1036SSaleem Abdulrasool         log->Printf ("SBFrame(%p)::GetPC () => 0x%" PRIx64,
516324a1036SSaleem Abdulrasool                      static_cast<void*>(frame), addr);
517ceb6b139SCaroline Tice 
518ceb6b139SCaroline Tice     return addr;
51930fdc8d8SChris Lattner }
52030fdc8d8SChris Lattner 
52130fdc8d8SChris Lattner bool
52269b582faSGreg Clayton SBFrame::SetPC (addr_t new_pc)
52330fdc8d8SChris Lattner {
5245160ce5cSGreg Clayton     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
525ceb6b139SCaroline Tice     bool ret_val = false;
526*bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
527*bb19a13cSSaleem Abdulrasool     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
5284fc6cb9cSJim Ingham 
529dbb0abbfSEugene Zelenko     StackFrame *frame = nullptr;
530d9e416c0SGreg Clayton     Target *target = exe_ctx.GetTargetPtr();
5317730b9a4SJim Ingham     Process *process = exe_ctx.GetProcessPtr();
5327730b9a4SJim Ingham     if (target && process)
533af67cecdSGreg Clayton     {
5347fdf9ef1SGreg Clayton         Process::StopLocker stop_locker;
5357730b9a4SJim Ingham         if (stop_locker.TryLock(&process->GetRunLock()))
5367730b9a4SJim Ingham         {
5377730b9a4SJim Ingham             frame = exe_ctx.GetFramePtr();
5387730b9a4SJim Ingham             if (frame)
5397fdf9ef1SGreg Clayton             {
540d9e416c0SGreg Clayton                 ret_val = frame->GetRegisterContext()->SetPC (new_pc);
541af67cecdSGreg Clayton             }
542c9858e4dSGreg Clayton             else
543c9858e4dSGreg Clayton             {
544c9858e4dSGreg Clayton                 if (log)
5457730b9a4SJim Ingham                     log->Printf ("SBFrame::SetPC () => error: could not reconstruct frame object for this SBFrame.");
5467730b9a4SJim Ingham             }
5477730b9a4SJim Ingham         }
5487730b9a4SJim Ingham         else
5497730b9a4SJim Ingham         {
5507730b9a4SJim Ingham             if (log)
5517730b9a4SJim Ingham                 log->Printf ("SBFrame::SetPC () => error: process is running");
552c9858e4dSGreg Clayton         }
5537fdf9ef1SGreg Clayton     }
554ceb6b139SCaroline Tice 
555ceb6b139SCaroline Tice     if (log)
556d01b2953SDaniel Malea         log->Printf ("SBFrame(%p)::SetPC (new_pc=0x%" PRIx64 ") => %i",
557324a1036SSaleem Abdulrasool                      static_cast<void*>(frame), new_pc, ret_val);
558ceb6b139SCaroline Tice 
559ceb6b139SCaroline Tice     return ret_val;
56030fdc8d8SChris Lattner }
56130fdc8d8SChris Lattner 
56269b582faSGreg Clayton addr_t
56330fdc8d8SChris Lattner SBFrame::GetSP () const
56430fdc8d8SChris Lattner {
5655160ce5cSGreg Clayton     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
5664838131bSGreg Clayton     addr_t addr = LLDB_INVALID_ADDRESS;
567*bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
568*bb19a13cSSaleem Abdulrasool     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
5694fc6cb9cSJim Ingham 
570dbb0abbfSEugene Zelenko     StackFrame *frame = nullptr;
571d9e416c0SGreg Clayton     Target *target = exe_ctx.GetTargetPtr();
5727730b9a4SJim Ingham     Process *process = exe_ctx.GetProcessPtr();
5737730b9a4SJim Ingham     if (target && process)
574af67cecdSGreg Clayton     {
5757fdf9ef1SGreg Clayton         Process::StopLocker stop_locker;
5767730b9a4SJim Ingham         if (stop_locker.TryLock(&process->GetRunLock()))
5777730b9a4SJim Ingham         {
5787730b9a4SJim Ingham             frame = exe_ctx.GetFramePtr();
5797730b9a4SJim Ingham             if (frame)
5807fdf9ef1SGreg Clayton             {
581d9e416c0SGreg Clayton                 addr = frame->GetRegisterContext()->GetSP();
582af67cecdSGreg Clayton             }
583c9858e4dSGreg Clayton             else
584c9858e4dSGreg Clayton             {
585c9858e4dSGreg Clayton                 if (log)
5867730b9a4SJim Ingham                     log->Printf ("SBFrame::GetSP () => error: could not reconstruct frame object for this SBFrame.");
5877730b9a4SJim Ingham             }
5887730b9a4SJim Ingham         }
5897730b9a4SJim Ingham         else
5907730b9a4SJim Ingham         {
5917730b9a4SJim Ingham             if (log)
5927730b9a4SJim Ingham                 log->Printf ("SBFrame::GetSP () => error: process is running");
5937fdf9ef1SGreg Clayton         }
594c9858e4dSGreg Clayton     }
5954838131bSGreg Clayton     if (log)
596324a1036SSaleem Abdulrasool         log->Printf ("SBFrame(%p)::GetSP () => 0x%" PRIx64,
597324a1036SSaleem Abdulrasool                      static_cast<void*>(frame), addr);
5984838131bSGreg Clayton 
5994838131bSGreg Clayton     return addr;
60030fdc8d8SChris Lattner }
60130fdc8d8SChris Lattner 
60269b582faSGreg Clayton addr_t
60330fdc8d8SChris Lattner SBFrame::GetFP () const
60430fdc8d8SChris Lattner {
6055160ce5cSGreg Clayton     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
60669b582faSGreg Clayton     addr_t addr = LLDB_INVALID_ADDRESS;
607*bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
608*bb19a13cSSaleem Abdulrasool     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
6094fc6cb9cSJim Ingham 
610dbb0abbfSEugene Zelenko     StackFrame *frame = nullptr;
611d9e416c0SGreg Clayton     Target *target = exe_ctx.GetTargetPtr();
6127730b9a4SJim Ingham     Process *process = exe_ctx.GetProcessPtr();
6137730b9a4SJim Ingham     if (target && process)
614af67cecdSGreg Clayton     {
6157fdf9ef1SGreg Clayton         Process::StopLocker stop_locker;
6167730b9a4SJim Ingham         if (stop_locker.TryLock(&process->GetRunLock()))
6177730b9a4SJim Ingham         {
6187730b9a4SJim Ingham             frame = exe_ctx.GetFramePtr();
6197730b9a4SJim Ingham             if (frame)
6207fdf9ef1SGreg Clayton             {
621d9e416c0SGreg Clayton                 addr = frame->GetRegisterContext()->GetFP();
622af67cecdSGreg Clayton             }
623c9858e4dSGreg Clayton             else
624c9858e4dSGreg Clayton             {
625c9858e4dSGreg Clayton                 if (log)
6267730b9a4SJim Ingham                     log->Printf ("SBFrame::GetFP () => error: could not reconstruct frame object for this SBFrame.");
6277730b9a4SJim Ingham             }
6287730b9a4SJim Ingham         }
6297730b9a4SJim Ingham         else
6307730b9a4SJim Ingham         {
6317730b9a4SJim Ingham             if (log)
6327730b9a4SJim Ingham                 log->Printf ("SBFrame::GetFP () => error: process is running");
633c9858e4dSGreg Clayton         }
6347fdf9ef1SGreg Clayton     }
635ceb6b139SCaroline Tice 
636ceb6b139SCaroline Tice     if (log)
637324a1036SSaleem Abdulrasool         log->Printf ("SBFrame(%p)::GetFP () => 0x%" PRIx64,
638324a1036SSaleem Abdulrasool                      static_cast<void*>(frame), addr);
639ceb6b139SCaroline Tice     return addr;
64030fdc8d8SChris Lattner }
64130fdc8d8SChris Lattner 
64230fdc8d8SChris Lattner SBAddress
64330fdc8d8SChris Lattner SBFrame::GetPCAddress () const
64430fdc8d8SChris Lattner {
6455160ce5cSGreg Clayton     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
64630fdc8d8SChris Lattner     SBAddress sb_addr;
647*bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
648*bb19a13cSSaleem Abdulrasool     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
6494fc6cb9cSJim Ingham 
650b57e4a1bSJason Molenda     StackFrame *frame = exe_ctx.GetFramePtr();
651d9e416c0SGreg Clayton     Target *target = exe_ctx.GetTargetPtr();
6527730b9a4SJim Ingham     Process *process = exe_ctx.GetProcessPtr();
6537730b9a4SJim Ingham     if (target && process)
654af67cecdSGreg Clayton     {
6557fdf9ef1SGreg Clayton         Process::StopLocker stop_locker;
6567730b9a4SJim Ingham         if (stop_locker.TryLock(&process->GetRunLock()))
6577730b9a4SJim Ingham         {
6587730b9a4SJim Ingham             frame = exe_ctx.GetFramePtr();
6597730b9a4SJim Ingham             if (frame)
6607fdf9ef1SGreg Clayton             {
661d9e416c0SGreg Clayton                 sb_addr.SetAddress (&frame->GetFrameCodeAddress());
662af67cecdSGreg Clayton             }
663c9858e4dSGreg Clayton             else
664c9858e4dSGreg Clayton             {
665c9858e4dSGreg Clayton                 if (log)
6667730b9a4SJim Ingham                     log->Printf ("SBFrame::GetPCAddress () => error: could not reconstruct frame object for this SBFrame.");
6677730b9a4SJim Ingham             }
6687730b9a4SJim Ingham         }
6697730b9a4SJim Ingham         else
6707730b9a4SJim Ingham         {
6717730b9a4SJim Ingham             if (log)
6727730b9a4SJim Ingham                 log->Printf ("SBFrame::GetPCAddress () => error: process is running");
6737fdf9ef1SGreg Clayton         }
674c9858e4dSGreg Clayton     }
6754838131bSGreg Clayton     if (log)
676324a1036SSaleem Abdulrasool         log->Printf ("SBFrame(%p)::GetPCAddress () => SBAddress(%p)",
677324a1036SSaleem Abdulrasool                      static_cast<void*>(frame),
678324a1036SSaleem Abdulrasool                      static_cast<void*>(sb_addr.get()));
67930fdc8d8SChris Lattner     return sb_addr;
68030fdc8d8SChris Lattner }
68130fdc8d8SChris Lattner 
68230fdc8d8SChris Lattner void
68330fdc8d8SChris Lattner SBFrame::Clear()
68430fdc8d8SChris Lattner {
685af2589eaSGreg Clayton     m_opaque_sp->Clear();
68630fdc8d8SChris Lattner }
68730fdc8d8SChris Lattner 
6887edbdfc9SGreg Clayton lldb::SBValue
6897edbdfc9SGreg Clayton SBFrame::GetValueForVariablePath (const char *var_path)
6907edbdfc9SGreg Clayton {
6917edbdfc9SGreg Clayton     SBValue sb_value;
6927fdf9ef1SGreg Clayton     ExecutionContext exe_ctx(m_opaque_sp.get());
693b57e4a1bSJason Molenda     StackFrame *frame = exe_ctx.GetFramePtr();
694d9e416c0SGreg Clayton     Target *target = exe_ctx.GetTargetPtr();
695d9e416c0SGreg Clayton     if (frame && target)
6967edbdfc9SGreg Clayton     {
697d9e416c0SGreg Clayton         lldb::DynamicValueType  use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
6987edbdfc9SGreg Clayton         sb_value = GetValueForVariablePath (var_path, use_dynamic);
6997edbdfc9SGreg Clayton     }
7007edbdfc9SGreg Clayton     return sb_value;
7017edbdfc9SGreg Clayton }
7027edbdfc9SGreg Clayton 
7037edbdfc9SGreg Clayton lldb::SBValue
7047edbdfc9SGreg Clayton SBFrame::GetValueForVariablePath (const char *var_path, DynamicValueType use_dynamic)
7057edbdfc9SGreg Clayton {
7067edbdfc9SGreg Clayton     SBValue sb_value;
7075160ce5cSGreg Clayton     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
708dbb0abbfSEugene Zelenko     if (var_path == nullptr || var_path[0] == '\0')
7097730b9a4SJim Ingham     {
7107730b9a4SJim Ingham         if (log)
7117730b9a4SJim Ingham             log->Printf ("SBFrame::GetValueForVariablePath called with empty variable path.");
7127730b9a4SJim Ingham         return sb_value;
7137730b9a4SJim Ingham     }
7147730b9a4SJim Ingham 
715*bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
716*bb19a13cSSaleem Abdulrasool     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
7174fc6cb9cSJim Ingham 
718dbb0abbfSEugene Zelenko     StackFrame *frame = nullptr;
719d9e416c0SGreg Clayton     Target *target = exe_ctx.GetTargetPtr();
7207730b9a4SJim Ingham     Process *process = exe_ctx.GetProcessPtr();
7217730b9a4SJim Ingham     if (target && process)
7227edbdfc9SGreg Clayton     {
7237fdf9ef1SGreg Clayton         Process::StopLocker stop_locker;
7247730b9a4SJim Ingham         if (stop_locker.TryLock(&process->GetRunLock()))
7257730b9a4SJim Ingham         {
7267730b9a4SJim Ingham             frame = exe_ctx.GetFramePtr();
7277730b9a4SJim Ingham             if (frame)
7287fdf9ef1SGreg Clayton             {
7297edbdfc9SGreg Clayton                 VariableSP var_sp;
7307edbdfc9SGreg Clayton                 Error error;
731d9e416c0SGreg Clayton                 ValueObjectSP value_sp (frame->GetValueForVariableExpressionPath (var_path,
732e3e91517SEnrico Granata                                                                                   eNoDynamicValues,
733b57e4a1bSJason Molenda                                                                                   StackFrame::eExpressionPathOptionCheckPtrVsMember | StackFrame::eExpressionPathOptionsAllowDirectIVarAccess,
7347edbdfc9SGreg Clayton                                                                                   var_sp,
7357edbdfc9SGreg Clayton                                                                                   error));
736e3e91517SEnrico Granata                 sb_value.SetSP(value_sp, use_dynamic);
7377edbdfc9SGreg Clayton             }
738c9858e4dSGreg Clayton             else
739c9858e4dSGreg Clayton             {
740c9858e4dSGreg Clayton                 if (log)
7417730b9a4SJim Ingham                     log->Printf ("SBFrame::GetValueForVariablePath () => error: could not reconstruct frame object for this SBFrame.");
7427730b9a4SJim Ingham             }
7437730b9a4SJim Ingham         }
7447730b9a4SJim Ingham         else
7457730b9a4SJim Ingham         {
7467730b9a4SJim Ingham             if (log)
7477730b9a4SJim Ingham                 log->Printf ("SBFrame::GetValueForVariablePath () => error: process is running");
748c9858e4dSGreg Clayton         }
7497fdf9ef1SGreg Clayton     }
7507edbdfc9SGreg Clayton     return sb_value;
7517edbdfc9SGreg Clayton }
7527edbdfc9SGreg Clayton 
75330fdc8d8SChris Lattner SBValue
75469b582faSGreg Clayton SBFrame::FindVariable (const char *name)
75530fdc8d8SChris Lattner {
756316d498bSGreg Clayton     SBValue value;
7577fdf9ef1SGreg Clayton     ExecutionContext exe_ctx(m_opaque_sp.get());
758b57e4a1bSJason Molenda     StackFrame *frame = exe_ctx.GetFramePtr();
759d9e416c0SGreg Clayton     Target *target = exe_ctx.GetTargetPtr();
760d9e416c0SGreg Clayton     if (frame && target)
761316d498bSGreg Clayton     {
762d9e416c0SGreg Clayton         lldb::DynamicValueType  use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
763316d498bSGreg Clayton         value = FindVariable (name, use_dynamic);
764316d498bSGreg Clayton     }
765316d498bSGreg Clayton     return value;
76678a685aaSJim Ingham }
76778a685aaSJim Ingham 
76878a685aaSJim Ingham SBValue
7692837b766SJim Ingham SBFrame::FindVariable (const char *name, lldb::DynamicValueType use_dynamic)
77078a685aaSJim Ingham {
7715160ce5cSGreg Clayton     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
77269b582faSGreg Clayton     VariableSP var_sp;
77358b59f95SJim Ingham     SBValue sb_value;
7747730b9a4SJim Ingham 
775dbb0abbfSEugene Zelenko     if (name == nullptr || name[0] == '\0')
7767730b9a4SJim Ingham     {
7777730b9a4SJim Ingham         if (log)
7787730b9a4SJim Ingham             log->Printf ("SBFrame::FindVariable called with empty name");
7797730b9a4SJim Ingham         return sb_value;
7807730b9a4SJim Ingham     }
7817730b9a4SJim Ingham 
78281e871edSGreg Clayton     ValueObjectSP value_sp;
783*bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
784*bb19a13cSSaleem Abdulrasool     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
7854fc6cb9cSJim Ingham 
786dbb0abbfSEugene Zelenko     StackFrame *frame = nullptr;
787d9e416c0SGreg Clayton     Target *target = exe_ctx.GetTargetPtr();
7887730b9a4SJim Ingham     Process *process = exe_ctx.GetProcessPtr();
7897730b9a4SJim Ingham     if (target && process)
79030fdc8d8SChris Lattner     {
7917fdf9ef1SGreg Clayton         Process::StopLocker stop_locker;
7927730b9a4SJim Ingham         if (stop_locker.TryLock(&process->GetRunLock()))
7937730b9a4SJim Ingham         {
7947730b9a4SJim Ingham             frame = exe_ctx.GetFramePtr();
7957730b9a4SJim Ingham             if (frame)
7967fdf9ef1SGreg Clayton             {
79769b582faSGreg Clayton                 VariableList variable_list;
798d9e416c0SGreg Clayton                 SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock));
79930fdc8d8SChris Lattner 
80072eff18aSGreg Clayton                 if (sc.block)
80130fdc8d8SChris Lattner                 {
80272eff18aSGreg Clayton                     const bool can_create = true;
80372eff18aSGreg Clayton                     const bool get_parent_variables = true;
80472eff18aSGreg Clayton                     const bool stop_if_block_is_inlined_function = true;
80572eff18aSGreg Clayton 
80672eff18aSGreg Clayton                     if (sc.block->AppendVariables (can_create,
80772eff18aSGreg Clayton                                                    get_parent_variables,
80872eff18aSGreg Clayton                                                    stop_if_block_is_inlined_function,
80972ac8a84STamas Berghammer                                                    [frame](Variable* v) { return v->IsInScope(frame); },
81072eff18aSGreg Clayton                                                    &variable_list))
81172eff18aSGreg Clayton                     {
81269b582faSGreg Clayton                         var_sp = variable_list.FindVariable (ConstString(name));
81330fdc8d8SChris Lattner                     }
81472eff18aSGreg Clayton                 }
81530fdc8d8SChris Lattner 
8164838131bSGreg Clayton                 if (var_sp)
81781e871edSGreg Clayton                 {
818e3e91517SEnrico Granata                     value_sp = frame->GetValueObjectForFrameVariable(var_sp, eNoDynamicValues);
819e3e91517SEnrico Granata                     sb_value.SetSP(value_sp, use_dynamic);
82081e871edSGreg Clayton                 }
8217fdf9ef1SGreg Clayton             }
822c9858e4dSGreg Clayton             else
823c9858e4dSGreg Clayton             {
824c9858e4dSGreg Clayton                 if (log)
8257730b9a4SJim Ingham                     log->Printf ("SBFrame::FindVariable () => error: could not reconstruct frame object for this SBFrame.");
8267730b9a4SJim Ingham             }
8277730b9a4SJim Ingham         }
8287730b9a4SJim Ingham         else
8297730b9a4SJim Ingham         {
8307730b9a4SJim Ingham             if (log)
8317730b9a4SJim Ingham                 log->Printf ("SBFrame::FindVariable () => error: process is running");
832c9858e4dSGreg Clayton         }
833316d498bSGreg Clayton     }
834316d498bSGreg Clayton 
8354838131bSGreg Clayton     if (log)
83669b582faSGreg Clayton         log->Printf ("SBFrame(%p)::FindVariable (name=\"%s\") => SBValue(%p)",
837324a1036SSaleem Abdulrasool                      static_cast<void*>(frame), name,
838324a1036SSaleem Abdulrasool                      static_cast<void*>(value_sp.get()));
8394838131bSGreg Clayton 
840dde9cff3SCaroline Tice     return sb_value;
841dde9cff3SCaroline Tice }
842dde9cff3SCaroline Tice 
84330fdc8d8SChris Lattner SBValue
84469b582faSGreg Clayton SBFrame::FindValue (const char *name, ValueType value_type)
84530fdc8d8SChris Lattner {
846316d498bSGreg Clayton     SBValue value;
8477fdf9ef1SGreg Clayton     ExecutionContext exe_ctx(m_opaque_sp.get());
848b57e4a1bSJason Molenda     StackFrame *frame = exe_ctx.GetFramePtr();
849d9e416c0SGreg Clayton     Target *target = exe_ctx.GetTargetPtr();
850d9e416c0SGreg Clayton     if (frame && target)
851316d498bSGreg Clayton     {
852d9e416c0SGreg Clayton         lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
853316d498bSGreg Clayton         value = FindValue (name, value_type, use_dynamic);
854316d498bSGreg Clayton     }
855316d498bSGreg Clayton     return value;
85678a685aaSJim Ingham }
85778a685aaSJim Ingham 
85878a685aaSJim Ingham SBValue
8592837b766SJim Ingham SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueType use_dynamic)
86078a685aaSJim Ingham {
8615160ce5cSGreg Clayton     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
86269b582faSGreg Clayton     SBValue sb_value;
8637730b9a4SJim Ingham 
864dbb0abbfSEugene Zelenko     if (name == nullptr || name[0] == '\0')
8657730b9a4SJim Ingham     {
8667730b9a4SJim Ingham         if (log)
8677730b9a4SJim Ingham             log->Printf ("SBFrame::FindValue called with empty name.");
8687730b9a4SJim Ingham         return sb_value;
8697730b9a4SJim Ingham     }
8707730b9a4SJim Ingham 
87181e871edSGreg Clayton     ValueObjectSP value_sp;
872*bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
873*bb19a13cSSaleem Abdulrasool     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
8744fc6cb9cSJim Ingham 
875dbb0abbfSEugene Zelenko     StackFrame *frame = nullptr;
876d9e416c0SGreg Clayton     Target *target = exe_ctx.GetTargetPtr();
8777730b9a4SJim Ingham     Process *process = exe_ctx.GetProcessPtr();
8787730b9a4SJim Ingham     if (target && process)
87930fdc8d8SChris Lattner     {
8807fdf9ef1SGreg Clayton         Process::StopLocker stop_locker;
8817730b9a4SJim Ingham         if (stop_locker.TryLock(&process->GetRunLock()))
8827730b9a4SJim Ingham         {
8837730b9a4SJim Ingham             frame = exe_ctx.GetFramePtr();
8847730b9a4SJim Ingham             if (frame)
8857fdf9ef1SGreg Clayton             {
8868a2a0dfbSEnrico Granata                 VariableList variable_list;
8878a2a0dfbSEnrico Granata 
88869b582faSGreg Clayton                 switch (value_type)
88930fdc8d8SChris Lattner                 {
89069b582faSGreg Clayton                 case eValueTypeVariableGlobal:      // global variable
89169b582faSGreg Clayton                 case eValueTypeVariableStatic:      // static variable
89269b582faSGreg Clayton                 case eValueTypeVariableArgument:    // function argument variables
89369b582faSGreg Clayton                 case eValueTypeVariableLocal:       // function local variables
89469b582faSGreg Clayton                     {
895d9e416c0SGreg Clayton                         SymbolContext sc(frame->GetSymbolContext(eSymbolContextBlock));
89672eff18aSGreg Clayton 
89772eff18aSGreg Clayton                         const bool can_create = true;
89872eff18aSGreg Clayton                         const bool get_parent_variables = true;
89972eff18aSGreg Clayton                         const bool stop_if_block_is_inlined_function = true;
90072eff18aSGreg Clayton 
9010efb51a0SChaoren Lin                         if (sc.block)
9020efb51a0SChaoren Lin                             sc.block->AppendVariables(can_create,
90372eff18aSGreg Clayton                                                       get_parent_variables,
90472eff18aSGreg Clayton                                                       stop_if_block_is_inlined_function,
90572ac8a84STamas Berghammer                                                       [frame](Variable* v) { return v->IsInScope(frame); },
9060efb51a0SChaoren Lin                                                       &variable_list);
9078a2a0dfbSEnrico Granata                         if (value_type == eValueTypeVariableGlobal)
9088a2a0dfbSEnrico Granata                         {
9098a2a0dfbSEnrico Granata                             const bool get_file_globals = true;
9108a2a0dfbSEnrico Granata                             VariableList *frame_vars = frame->GetVariableList(get_file_globals);
9118a2a0dfbSEnrico Granata                             if (frame_vars)
9128a2a0dfbSEnrico Granata                                 frame_vars->AppendVariablesIfUnique(variable_list);
9138a2a0dfbSEnrico Granata                         }
91469b582faSGreg Clayton                         ConstString const_name(name);
91508a04327SEnrico Granata                         VariableSP variable_sp(variable_list.FindVariable(const_name, value_type));
91608a04327SEnrico Granata                         if (variable_sp)
917beae523aSJohnny Chen                         {
918e3e91517SEnrico Granata                             value_sp = frame->GetValueObjectForFrameVariable(variable_sp, eNoDynamicValues);
919e3e91517SEnrico Granata                             sb_value.SetSP(value_sp, use_dynamic);
92030fdc8d8SChris Lattner                         }
92130fdc8d8SChris Lattner                     }
92269b582faSGreg Clayton                     break;
92369b582faSGreg Clayton 
92469b582faSGreg Clayton                 case eValueTypeRegister:            // stack frame register value
92569b582faSGreg Clayton                     {
926d9e416c0SGreg Clayton                         RegisterContextSP reg_ctx (frame->GetRegisterContext());
92769b582faSGreg Clayton                         if (reg_ctx)
92869b582faSGreg Clayton                         {
92969b582faSGreg Clayton                             const uint32_t num_regs = reg_ctx->GetRegisterCount();
93069b582faSGreg Clayton                             for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx)
93169b582faSGreg Clayton                             {
93269b582faSGreg Clayton                                 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
93369b582faSGreg Clayton                                 if (reg_info &&
93469b582faSGreg Clayton                                     ((reg_info->name && strcasecmp (reg_info->name, name) == 0) ||
93569b582faSGreg Clayton                                      (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0)))
93669b582faSGreg Clayton                                 {
937d9e416c0SGreg Clayton                                     value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx);
93881e871edSGreg Clayton                                     sb_value.SetSP (value_sp);
93981e871edSGreg Clayton                                     break;
94069b582faSGreg Clayton                                 }
94169b582faSGreg Clayton                             }
94269b582faSGreg Clayton                         }
94369b582faSGreg Clayton                     }
94469b582faSGreg Clayton                     break;
94569b582faSGreg Clayton 
94669b582faSGreg Clayton                 case eValueTypeRegisterSet:         // A collection of stack frame register values
94769b582faSGreg Clayton                     {
948d9e416c0SGreg Clayton                         RegisterContextSP reg_ctx (frame->GetRegisterContext());
94969b582faSGreg Clayton                         if (reg_ctx)
95069b582faSGreg Clayton                         {
95169b582faSGreg Clayton                             const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
95269b582faSGreg Clayton                             for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
95369b582faSGreg Clayton                             {
95469b582faSGreg Clayton                                 const RegisterSet *reg_set = reg_ctx->GetRegisterSet (set_idx);
95569b582faSGreg Clayton                                 if (reg_set &&
95669b582faSGreg Clayton                                     ((reg_set->name && strcasecmp (reg_set->name, name) == 0) ||
95769b582faSGreg Clayton                                      (reg_set->short_name && strcasecmp (reg_set->short_name, name) == 0)))
95869b582faSGreg Clayton                                 {
959d9e416c0SGreg Clayton                                     value_sp = ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx);
96081e871edSGreg Clayton                                     sb_value.SetSP (value_sp);
96181e871edSGreg Clayton                                     break;
96269b582faSGreg Clayton                                 }
96369b582faSGreg Clayton                             }
96469b582faSGreg Clayton                         }
96569b582faSGreg Clayton                     }
96669b582faSGreg Clayton                     break;
96769b582faSGreg Clayton 
96869b582faSGreg Clayton                 case eValueTypeConstResult:         // constant result variables
96969b582faSGreg Clayton                     {
97069b582faSGreg Clayton                         ConstString const_name(name);
9718f1f9a1bSSean Callanan                         ExpressionVariableSP expr_var_sp (target->GetPersistentVariable (const_name));
97269b582faSGreg Clayton                         if (expr_var_sp)
97381e871edSGreg Clayton                         {
97481e871edSGreg Clayton                             value_sp = expr_var_sp->GetValueObject();
975e3e91517SEnrico Granata                             sb_value.SetSP (value_sp, use_dynamic);
97681e871edSGreg Clayton                         }
97769b582faSGreg Clayton                     }
97869b582faSGreg Clayton                     break;
97969b582faSGreg Clayton 
98069b582faSGreg Clayton                 default:
98169b582faSGreg Clayton                     break;
98269b582faSGreg Clayton                 }
983beae523aSJohnny Chen             }
984c9858e4dSGreg Clayton             else
985c9858e4dSGreg Clayton             {
986c9858e4dSGreg Clayton                 if (log)
9877730b9a4SJim Ingham                     log->Printf ("SBFrame::FindValue () => error: could not reconstruct frame object for this SBFrame.");
9887730b9a4SJim Ingham             }
9897730b9a4SJim Ingham         }
9907730b9a4SJim Ingham         else
9917730b9a4SJim Ingham         {
9927730b9a4SJim Ingham             if (log)
9937730b9a4SJim Ingham                 log->Printf ("SBFrame::FindValue () => error: process is running");
994c9858e4dSGreg Clayton         }
9957fdf9ef1SGreg Clayton     }
996dde9cff3SCaroline Tice 
9974838131bSGreg Clayton     if (log)
99869b582faSGreg Clayton         log->Printf ("SBFrame(%p)::FindVariableInScope (name=\"%s\", value_type=%i) => SBValue(%p)",
999324a1036SSaleem Abdulrasool                      static_cast<void*>(frame), name, value_type,
1000324a1036SSaleem Abdulrasool                      static_cast<void*>(value_sp.get()));
10014838131bSGreg Clayton 
1002dde9cff3SCaroline Tice     return sb_value;
1003dde9cff3SCaroline Tice }
1004dde9cff3SCaroline Tice 
100530fdc8d8SChris Lattner bool
100635e2ab60SJohnny Chen SBFrame::IsEqual (const SBFrame &that) const
100735e2ab60SJohnny Chen {
1008b57e4a1bSJason Molenda     lldb::StackFrameSP this_sp = GetFrameSP();
1009b57e4a1bSJason Molenda     lldb::StackFrameSP that_sp = that.GetFrameSP();
101035e2ab60SJohnny Chen     return (this_sp && that_sp && this_sp->GetStackID() == that_sp->GetStackID());
101135e2ab60SJohnny Chen }
101235e2ab60SJohnny Chen 
101335e2ab60SJohnny Chen bool
101430fdc8d8SChris Lattner SBFrame::operator == (const SBFrame &rhs) const
101530fdc8d8SChris Lattner {
101635e2ab60SJohnny Chen     return IsEqual(rhs);
101730fdc8d8SChris Lattner }
101830fdc8d8SChris Lattner 
101930fdc8d8SChris Lattner bool
102030fdc8d8SChris Lattner SBFrame::operator != (const SBFrame &rhs) const
102130fdc8d8SChris Lattner {
102235e2ab60SJohnny Chen     return !IsEqual(rhs);
1023481cef25SGreg Clayton }
102430fdc8d8SChris Lattner 
102530fdc8d8SChris Lattner SBThread
102630fdc8d8SChris Lattner SBFrame::GetThread () const
102730fdc8d8SChris Lattner {
10285160ce5cSGreg Clayton     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1029ceb6b139SCaroline Tice 
10307fdf9ef1SGreg Clayton     ExecutionContext exe_ctx(m_opaque_sp.get());
1031d9e416c0SGreg Clayton     ThreadSP thread_sp (exe_ctx.GetThreadSP());
1032d9e416c0SGreg Clayton     SBThread sb_thread (thread_sp);
1033ceb6b139SCaroline Tice 
1034ceb6b139SCaroline Tice     if (log)
1035750cd175SCaroline Tice     {
1036750cd175SCaroline Tice         SBStream sstr;
1037750cd175SCaroline Tice         sb_thread.GetDescription (sstr);
1038d9e416c0SGreg Clayton         log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s",
1039324a1036SSaleem Abdulrasool                      static_cast<void*>(exe_ctx.GetFramePtr()),
1040324a1036SSaleem Abdulrasool                      static_cast<void*>(thread_sp.get()), sstr.GetData());
1041750cd175SCaroline Tice     }
1042ceb6b139SCaroline Tice 
104330fdc8d8SChris Lattner     return sb_thread;
104430fdc8d8SChris Lattner }
104530fdc8d8SChris Lattner 
104630fdc8d8SChris Lattner const char *
104730fdc8d8SChris Lattner SBFrame::Disassemble () const
104830fdc8d8SChris Lattner {
10495160ce5cSGreg Clayton     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1050dbb0abbfSEugene Zelenko     const char *disassembly = nullptr;
1051*bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
1052*bb19a13cSSaleem Abdulrasool     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
10534fc6cb9cSJim Ingham 
1054dbb0abbfSEugene Zelenko     StackFrame *frame = nullptr;
1055d9e416c0SGreg Clayton     Target *target = exe_ctx.GetTargetPtr();
10567730b9a4SJim Ingham     Process *process = exe_ctx.GetProcessPtr();
10577730b9a4SJim Ingham     if (target && process)
1058af67cecdSGreg Clayton     {
10597fdf9ef1SGreg Clayton         Process::StopLocker stop_locker;
10607730b9a4SJim Ingham         if (stop_locker.TryLock(&process->GetRunLock()))
10617730b9a4SJim Ingham         {
10627730b9a4SJim Ingham             frame = exe_ctx.GetFramePtr();
10637730b9a4SJim Ingham             if (frame)
10647fdf9ef1SGreg Clayton             {
1065d9e416c0SGreg Clayton                 disassembly = frame->Disassemble();
1066af67cecdSGreg Clayton             }
1067c9858e4dSGreg Clayton             else
1068c9858e4dSGreg Clayton             {
1069c9858e4dSGreg Clayton                 if (log)
10707730b9a4SJim Ingham                     log->Printf ("SBFrame::Disassemble () => error: could not reconstruct frame object for this SBFrame.");
10717730b9a4SJim Ingham             }
10727730b9a4SJim Ingham         }
10737730b9a4SJim Ingham         else
10747730b9a4SJim Ingham         {
10757730b9a4SJim Ingham             if (log)
10767730b9a4SJim Ingham                 log->Printf ("SBFrame::Disassemble () => error: process is running");
10777fdf9ef1SGreg Clayton         }
1078c9858e4dSGreg Clayton     }
10794838131bSGreg Clayton 
10804838131bSGreg Clayton     if (log)
1081324a1036SSaleem Abdulrasool         log->Printf ("SBFrame(%p)::Disassemble () => %s",
1082324a1036SSaleem Abdulrasool                      static_cast<void*>(frame), disassembly);
10834838131bSGreg Clayton 
10844838131bSGreg Clayton     return disassembly;
108530fdc8d8SChris Lattner }
108630fdc8d8SChris Lattner 
108730fdc8d8SChris Lattner SBValueList
108830fdc8d8SChris Lattner SBFrame::GetVariables (bool arguments,
108930fdc8d8SChris Lattner                        bool locals,
109030fdc8d8SChris Lattner                        bool statics,
109130fdc8d8SChris Lattner                        bool in_scope_only)
109230fdc8d8SChris Lattner {
1093316d498bSGreg Clayton     SBValueList value_list;
10947fdf9ef1SGreg Clayton     ExecutionContext exe_ctx(m_opaque_sp.get());
1095b57e4a1bSJason Molenda     StackFrame *frame = exe_ctx.GetFramePtr();
1096d9e416c0SGreg Clayton     Target *target = exe_ctx.GetTargetPtr();
1097d9e416c0SGreg Clayton     if (frame && target)
1098316d498bSGreg Clayton     {
1099d9e416c0SGreg Clayton         lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
110051f96eebSZachary Turner         const bool include_runtime_support_values = target ? target->GetDisplayRuntimeSupportValues() : false;
110151f96eebSZachary Turner 
110251f96eebSZachary Turner         SBVariablesOptions options;
110351f96eebSZachary Turner         options.SetIncludeArguments(arguments);
110451f96eebSZachary Turner         options.SetIncludeLocals(locals);
110551f96eebSZachary Turner         options.SetIncludeStatics(statics);
110651f96eebSZachary Turner         options.SetInScopeOnly(in_scope_only);
110751f96eebSZachary Turner         options.SetIncludeRuntimeSupportValues(include_runtime_support_values);
110851f96eebSZachary Turner         options.SetUseDynamic(use_dynamic);
110951f96eebSZachary Turner 
111051f96eebSZachary Turner         value_list = GetVariables (options);
1111316d498bSGreg Clayton     }
1112316d498bSGreg Clayton     return value_list;
111378a685aaSJim Ingham }
111478a685aaSJim Ingham 
1115560558ebSEnrico Granata lldb::SBValueList
1116560558ebSEnrico Granata SBFrame::GetVariables (bool arguments,
1117560558ebSEnrico Granata                        bool locals,
1118560558ebSEnrico Granata                        bool statics,
1119560558ebSEnrico Granata                        bool in_scope_only,
1120560558ebSEnrico Granata                        lldb::DynamicValueType  use_dynamic)
1121560558ebSEnrico Granata {
1122560558ebSEnrico Granata     ExecutionContext exe_ctx(m_opaque_sp.get());
1123560558ebSEnrico Granata     Target *target = exe_ctx.GetTargetPtr();
112451f96eebSZachary Turner     const bool include_runtime_support_values = target ? target->GetDisplayRuntimeSupportValues() : false;
112551f96eebSZachary Turner     SBVariablesOptions options;
112651f96eebSZachary Turner     options.SetIncludeArguments(arguments);
112751f96eebSZachary Turner     options.SetIncludeLocals(locals);
112851f96eebSZachary Turner     options.SetIncludeStatics(statics);
112951f96eebSZachary Turner     options.SetInScopeOnly(in_scope_only);
113051f96eebSZachary Turner     options.SetIncludeRuntimeSupportValues(include_runtime_support_values);
113151f96eebSZachary Turner     options.SetUseDynamic(use_dynamic);
113251f96eebSZachary Turner     return GetVariables(options);
1133560558ebSEnrico Granata }
1134560558ebSEnrico Granata 
113578a685aaSJim Ingham SBValueList
113651f96eebSZachary Turner SBFrame::GetVariables (const lldb::SBVariablesOptions& options)
113778a685aaSJim Ingham {
11385160ce5cSGreg Clayton     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1139ceb6b139SCaroline Tice 
1140b9556accSGreg Clayton     SBValueList value_list;
1141*bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
1142*bb19a13cSSaleem Abdulrasool     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
11434fc6cb9cSJim Ingham 
1144dbb0abbfSEugene Zelenko     StackFrame *frame = nullptr;
1145d9e416c0SGreg Clayton     Target *target = exe_ctx.GetTargetPtr();
1146b9556accSGreg Clayton 
114751f96eebSZachary Turner     const bool statics = options.GetIncludeStatics();
114851f96eebSZachary Turner     const bool arguments = options.GetIncludeArguments();
114951f96eebSZachary Turner     const bool locals = options.GetIncludeLocals();
115051f96eebSZachary Turner     const bool in_scope_only = options.GetInScopeOnly();
115151f96eebSZachary Turner     const bool include_runtime_support_values = options.GetIncludeRuntimeSupportValues();
115251f96eebSZachary Turner     const lldb::DynamicValueType use_dynamic = options.GetUseDynamic();
115351f96eebSZachary Turner 
1154ceb6b139SCaroline Tice     if (log)
115551f96eebSZachary Turner         log->Printf ("SBFrame::GetVariables (arguments=%i, locals=%i, statics=%i, in_scope_only=%i runtime=%i dynamic=%i)",
115651f96eebSZachary Turner                      arguments, locals,
115751f96eebSZachary Turner                      statics, in_scope_only,
115851f96eebSZachary Turner                      include_runtime_support_values, use_dynamic);
1159ceb6b139SCaroline Tice 
1160349213f9SGreg Clayton     std::set<VariableSP> variable_set;
11617730b9a4SJim Ingham     Process *process = exe_ctx.GetProcessPtr();
11627730b9a4SJim Ingham     if (target && process)
116330fdc8d8SChris Lattner     {
11647fdf9ef1SGreg Clayton         Process::StopLocker stop_locker;
11657730b9a4SJim Ingham         if (stop_locker.TryLock(&process->GetRunLock()))
11667fdf9ef1SGreg Clayton         {
11677730b9a4SJim Ingham             frame = exe_ctx.GetFramePtr();
11687730b9a4SJim Ingham             if (frame)
11697730b9a4SJim Ingham             {
117030fdc8d8SChris Lattner                 size_t i;
1171dbb0abbfSEugene Zelenko                 VariableList *variable_list = nullptr;
1172d9e416c0SGreg Clayton                 variable_list = frame->GetVariableList(true);
117330fdc8d8SChris Lattner                 if (variable_list)
117430fdc8d8SChris Lattner                 {
117530fdc8d8SChris Lattner                     const size_t num_variables = variable_list->GetSize();
117630fdc8d8SChris Lattner                     if (num_variables)
117730fdc8d8SChris Lattner                     {
117830fdc8d8SChris Lattner                         for (i = 0; i < num_variables; ++i)
117930fdc8d8SChris Lattner                         {
118030fdc8d8SChris Lattner                             VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
118130fdc8d8SChris Lattner                             if (variable_sp)
118230fdc8d8SChris Lattner                             {
118330fdc8d8SChris Lattner                                 bool add_variable = false;
118430fdc8d8SChris Lattner                                 switch (variable_sp->GetScope())
118530fdc8d8SChris Lattner                                 {
118630fdc8d8SChris Lattner                                 case eValueTypeVariableGlobal:
118730fdc8d8SChris Lattner                                 case eValueTypeVariableStatic:
118830fdc8d8SChris Lattner                                     add_variable = statics;
118930fdc8d8SChris Lattner                                     break;
119030fdc8d8SChris Lattner 
119130fdc8d8SChris Lattner                                 case eValueTypeVariableArgument:
119230fdc8d8SChris Lattner                                     add_variable = arguments;
119330fdc8d8SChris Lattner                                     break;
119430fdc8d8SChris Lattner 
119530fdc8d8SChris Lattner                                 case eValueTypeVariableLocal:
119630fdc8d8SChris Lattner                                     add_variable = locals;
119730fdc8d8SChris Lattner                                     break;
1198c982c768SGreg Clayton 
1199c982c768SGreg Clayton                                 default:
1200c982c768SGreg Clayton                                     break;
120130fdc8d8SChris Lattner                                 }
120230fdc8d8SChris Lattner                                 if (add_variable)
120330fdc8d8SChris Lattner                                 {
1204349213f9SGreg Clayton                                     // Only add variables once so we don't end up with duplicates
1205349213f9SGreg Clayton                                     if (variable_set.find(variable_sp) == variable_set.end())
1206349213f9SGreg Clayton                                         variable_set.insert(variable_sp);
1207349213f9SGreg Clayton                                     else
1208349213f9SGreg Clayton                                         continue;
1209349213f9SGreg Clayton 
1210d9e416c0SGreg Clayton                                     if (in_scope_only && !variable_sp->IsInScope(frame))
121130fdc8d8SChris Lattner                                         continue;
121230fdc8d8SChris Lattner 
1213e3e91517SEnrico Granata                                     ValueObjectSP valobj_sp(frame->GetValueObjectForFrameVariable (variable_sp, eNoDynamicValues));
1214560558ebSEnrico Granata 
1215dbb0abbfSEugene Zelenko                                     if (!include_runtime_support_values &&
1216dbb0abbfSEugene Zelenko                                         valobj_sp != nullptr &&
1217dbb0abbfSEugene Zelenko                                         valobj_sp->IsRuntimeSupportValue())
1218560558ebSEnrico Granata                                         continue;
1219560558ebSEnrico Granata 
1220e3e91517SEnrico Granata                                     SBValue value_sb;
1221e3e91517SEnrico Granata                                     value_sb.SetSP(valobj_sp,use_dynamic);
1222e3e91517SEnrico Granata                                     value_list.Append(value_sb);
122330fdc8d8SChris Lattner                                 }
122430fdc8d8SChris Lattner                             }
122530fdc8d8SChris Lattner                         }
122630fdc8d8SChris Lattner                     }
122730fdc8d8SChris Lattner                 }
122830fdc8d8SChris Lattner             }
1229c9858e4dSGreg Clayton             else
1230c9858e4dSGreg Clayton             {
1231c9858e4dSGreg Clayton                 if (log)
12327730b9a4SJim Ingham                     log->Printf ("SBFrame::GetVariables () => error: could not reconstruct frame object for this SBFrame.");
12337730b9a4SJim Ingham             }
12347730b9a4SJim Ingham         }
12357730b9a4SJim Ingham         else
12367730b9a4SJim Ingham         {
12377730b9a4SJim Ingham             if (log)
12387730b9a4SJim Ingham                 log->Printf ("SBFrame::GetVariables () => error: process is running");
1239c9858e4dSGreg Clayton         }
12407fdf9ef1SGreg Clayton     }
1241ceb6b139SCaroline Tice 
1242ceb6b139SCaroline Tice     if (log)
1243324a1036SSaleem Abdulrasool         log->Printf ("SBFrame(%p)::GetVariables (...) => SBValueList(%p)",
1244324a1036SSaleem Abdulrasool                      static_cast<void*>(frame),
1245324a1036SSaleem Abdulrasool                      static_cast<void*>(value_list.opaque_ptr()));
1246ceb6b139SCaroline Tice 
124730fdc8d8SChris Lattner     return value_list;
124830fdc8d8SChris Lattner }
124930fdc8d8SChris Lattner 
125069b582faSGreg Clayton SBValueList
125130fdc8d8SChris Lattner SBFrame::GetRegisters ()
125230fdc8d8SChris Lattner {
12535160ce5cSGreg Clayton     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1254ceb6b139SCaroline Tice 
125530fdc8d8SChris Lattner     SBValueList value_list;
1256*bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
1257*bb19a13cSSaleem Abdulrasool     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
12584fc6cb9cSJim Ingham 
1259dbb0abbfSEugene Zelenko     StackFrame *frame = nullptr;
1260d9e416c0SGreg Clayton     Target *target = exe_ctx.GetTargetPtr();
12617730b9a4SJim Ingham     Process *process = exe_ctx.GetProcessPtr();
12627730b9a4SJim Ingham     if (target && process)
126330fdc8d8SChris Lattner     {
12647fdf9ef1SGreg Clayton         Process::StopLocker stop_locker;
12657730b9a4SJim Ingham         if (stop_locker.TryLock(&process->GetRunLock()))
12667730b9a4SJim Ingham         {
12677730b9a4SJim Ingham             frame = exe_ctx.GetFramePtr();
12687730b9a4SJim Ingham             if (frame)
12697fdf9ef1SGreg Clayton             {
1270d9e416c0SGreg Clayton                 RegisterContextSP reg_ctx (frame->GetRegisterContext());
127130fdc8d8SChris Lattner                 if (reg_ctx)
127230fdc8d8SChris Lattner                 {
127330fdc8d8SChris Lattner                     const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
127430fdc8d8SChris Lattner                     for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
127530fdc8d8SChris Lattner                     {
1276d9e416c0SGreg Clayton                         value_list.Append(ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx));
127730fdc8d8SChris Lattner                     }
127830fdc8d8SChris Lattner                 }
127930fdc8d8SChris Lattner             }
1280c9858e4dSGreg Clayton             else
1281c9858e4dSGreg Clayton             {
1282c9858e4dSGreg Clayton                 if (log)
12837730b9a4SJim Ingham                     log->Printf ("SBFrame::GetRegisters () => error: could not reconstruct frame object for this SBFrame.");
12847730b9a4SJim Ingham             }
12857730b9a4SJim Ingham         }
12867730b9a4SJim Ingham         else
12877730b9a4SJim Ingham         {
12887730b9a4SJim Ingham             if (log)
12897730b9a4SJim Ingham                 log->Printf ("SBFrame::GetRegisters () => error: process is running");
1290c9858e4dSGreg Clayton         }
12917fdf9ef1SGreg Clayton     }
1292ceb6b139SCaroline Tice 
1293ceb6b139SCaroline Tice     if (log)
1294324a1036SSaleem Abdulrasool         log->Printf ("SBFrame(%p)::GetRegisters () => SBValueList(%p)",
1295324a1036SSaleem Abdulrasool                      static_cast<void*>(frame),
1296324a1036SSaleem Abdulrasool                      static_cast<void*>(value_list.opaque_ptr()));
1297ceb6b139SCaroline Tice 
129830fdc8d8SChris Lattner     return value_list;
129930fdc8d8SChris Lattner }
130030fdc8d8SChris Lattner 
1301ad9a53c5SJason Molenda SBValue
1302ad9a53c5SJason Molenda SBFrame::FindRegister (const char *name)
1303ad9a53c5SJason Molenda {
1304ad9a53c5SJason Molenda     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1305ad9a53c5SJason Molenda 
1306ad9a53c5SJason Molenda     SBValue result;
1307ad9a53c5SJason Molenda     ValueObjectSP value_sp;
1308*bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
1309*bb19a13cSSaleem Abdulrasool     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1310ad9a53c5SJason Molenda 
1311dbb0abbfSEugene Zelenko     StackFrame *frame = nullptr;
1312ad9a53c5SJason Molenda     Target *target = exe_ctx.GetTargetPtr();
1313ad9a53c5SJason Molenda     Process *process = exe_ctx.GetProcessPtr();
1314ad9a53c5SJason Molenda     if (target && process)
1315ad9a53c5SJason Molenda     {
1316ad9a53c5SJason Molenda         Process::StopLocker stop_locker;
1317ad9a53c5SJason Molenda         if (stop_locker.TryLock(&process->GetRunLock()))
1318ad9a53c5SJason Molenda         {
1319ad9a53c5SJason Molenda             frame = exe_ctx.GetFramePtr();
1320ad9a53c5SJason Molenda             if (frame)
1321ad9a53c5SJason Molenda             {
1322ad9a53c5SJason Molenda                 RegisterContextSP reg_ctx (frame->GetRegisterContext());
1323ad9a53c5SJason Molenda                 if (reg_ctx)
1324ad9a53c5SJason Molenda                 {
1325ad9a53c5SJason Molenda                     const uint32_t num_regs = reg_ctx->GetRegisterCount();
1326ad9a53c5SJason Molenda                     for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx)
1327ad9a53c5SJason Molenda                     {
1328ad9a53c5SJason Molenda                         const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
1329ad9a53c5SJason Molenda                         if (reg_info &&
1330ad9a53c5SJason Molenda                             ((reg_info->name && strcasecmp (reg_info->name, name) == 0) ||
1331ad9a53c5SJason Molenda                              (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0)))
1332ad9a53c5SJason Molenda                         {
1333ad9a53c5SJason Molenda                             value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx);
1334ad9a53c5SJason Molenda                             result.SetSP (value_sp);
1335ad9a53c5SJason Molenda                             break;
1336ad9a53c5SJason Molenda                         }
1337ad9a53c5SJason Molenda                     }
1338ad9a53c5SJason Molenda                 }
1339ad9a53c5SJason Molenda             }
1340ad9a53c5SJason Molenda             else
1341ad9a53c5SJason Molenda             {
1342ad9a53c5SJason Molenda                 if (log)
13435d353842SJason Molenda                     log->Printf ("SBFrame::FindRegister () => error: could not reconstruct frame object for this SBFrame.");
1344ad9a53c5SJason Molenda             }
1345ad9a53c5SJason Molenda         }
1346ad9a53c5SJason Molenda         else
1347ad9a53c5SJason Molenda         {
1348ad9a53c5SJason Molenda             if (log)
13495d353842SJason Molenda                 log->Printf ("SBFrame::FindRegister () => error: process is running");
1350ad9a53c5SJason Molenda         }
1351ad9a53c5SJason Molenda     }
1352ad9a53c5SJason Molenda 
1353ad9a53c5SJason Molenda     if (log)
1354324a1036SSaleem Abdulrasool         log->Printf ("SBFrame(%p)::FindRegister () => SBValue(%p)",
1355324a1036SSaleem Abdulrasool                      static_cast<void*>(frame),
1356324a1036SSaleem Abdulrasool                      static_cast<void*>(value_sp.get()));
1357ad9a53c5SJason Molenda 
1358ad9a53c5SJason Molenda     return result;
1359ad9a53c5SJason Molenda }
1360ad9a53c5SJason Molenda 
1361dde9cff3SCaroline Tice bool
1362dde9cff3SCaroline Tice SBFrame::GetDescription (SBStream &description)
1363dde9cff3SCaroline Tice {
13645160ce5cSGreg Clayton     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1365da7bc7d0SGreg Clayton     Stream &strm = description.ref();
1366da7bc7d0SGreg Clayton 
1367*bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
1368*bb19a13cSSaleem Abdulrasool     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
13694fc6cb9cSJim Ingham 
1370b57e4a1bSJason Molenda     StackFrame *frame;
1371d9e416c0SGreg Clayton     Target *target = exe_ctx.GetTargetPtr();
13727730b9a4SJim Ingham     Process *process = exe_ctx.GetProcessPtr();
13737730b9a4SJim Ingham     if (target && process)
1374dde9cff3SCaroline Tice     {
13757fdf9ef1SGreg Clayton         Process::StopLocker stop_locker;
13767730b9a4SJim Ingham         if (stop_locker.TryLock(&process->GetRunLock()))
13777730b9a4SJim Ingham         {
13787730b9a4SJim Ingham             frame = exe_ctx.GetFramePtr();
13797730b9a4SJim Ingham             if (frame)
13807fdf9ef1SGreg Clayton             {
1381d9e416c0SGreg Clayton                 frame->DumpUsingSettingsFormat (&strm);
1382dde9cff3SCaroline Tice             }
1383c9858e4dSGreg Clayton             else
1384c9858e4dSGreg Clayton             {
1385c9858e4dSGreg Clayton                 if (log)
13867730b9a4SJim Ingham                     log->Printf ("SBFrame::GetDescription () => error: could not reconstruct frame object for this SBFrame.");
13877730b9a4SJim Ingham             }
13887730b9a4SJim Ingham         }
13897730b9a4SJim Ingham         else
13907730b9a4SJim Ingham         {
13917730b9a4SJim Ingham             if (log)
13927730b9a4SJim Ingham                 log->Printf ("SBFrame::GetDescription () => error: process is running");
1393c9858e4dSGreg Clayton         }
1394c9858e4dSGreg Clayton 
13957fdf9ef1SGreg Clayton     }
1396dde9cff3SCaroline Tice     else
1397da7bc7d0SGreg Clayton         strm.PutCString ("No value");
1398dde9cff3SCaroline Tice 
1399dde9cff3SCaroline Tice     return true;
1400dde9cff3SCaroline Tice }
14011d3afba3SGreg Clayton 
140269b582faSGreg Clayton SBValue
14031d3afba3SGreg Clayton SBFrame::EvaluateExpression (const char *expr)
14041d3afba3SGreg Clayton {
1405316d498bSGreg Clayton     SBValue result;
14067fdf9ef1SGreg Clayton     ExecutionContext exe_ctx(m_opaque_sp.get());
1407b57e4a1bSJason Molenda     StackFrame *frame = exe_ctx.GetFramePtr();
1408d9e416c0SGreg Clayton     Target *target = exe_ctx.GetTargetPtr();
1409d9e416c0SGreg Clayton     if (frame && target)
1410316d498bSGreg Clayton     {
141135e1bda6SJim Ingham         SBExpressionOptions options;
141235e1bda6SJim Ingham         lldb::DynamicValueType fetch_dynamic_value = frame->CalculateTarget()->GetPreferDynamicValue();
1413cced1566SGreg Clayton         options.SetFetchDynamicValue (fetch_dynamic_value);
141435e1bda6SJim Ingham         options.SetUnwindOnError (true);
141524785bd0SEugene Leviant         options.SetIgnoreBreakpoints (true);
1416998c8a1cSRyan Brown         if (target->GetLanguage() != eLanguageTypeUnknown)
1417998c8a1cSRyan Brown             options.SetLanguage(target->GetLanguage());
1418998c8a1cSRyan Brown         else
1419998c8a1cSRyan Brown             options.SetLanguage(frame->GetLanguage());
142035e1bda6SJim Ingham         return EvaluateExpression (expr, options);
1421316d498bSGreg Clayton     }
1422316d498bSGreg Clayton     return result;
142378a685aaSJim Ingham }
142478a685aaSJim Ingham 
142578a685aaSJim Ingham SBValue
14262837b766SJim Ingham SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value)
142778a685aaSJim Ingham {
142835e1bda6SJim Ingham     SBExpressionOptions options;
1429cced1566SGreg Clayton     options.SetFetchDynamicValue (fetch_dynamic_value);
143035e1bda6SJim Ingham     options.SetUnwindOnError (true);
143124785bd0SEugene Leviant     options.SetIgnoreBreakpoints (true);
1432998c8a1cSRyan Brown     ExecutionContext exe_ctx(m_opaque_sp.get());
1433998c8a1cSRyan Brown     StackFrame *frame = exe_ctx.GetFramePtr();
1434998c8a1cSRyan Brown     Target *target = exe_ctx.GetTargetPtr();
1435998c8a1cSRyan Brown     if (target && target->GetLanguage() != eLanguageTypeUnknown)
1436998c8a1cSRyan Brown         options.SetLanguage(target->GetLanguage());
1437998c8a1cSRyan Brown     else if (frame)
1438998c8a1cSRyan Brown         options.SetLanguage(frame->GetLanguage());
143935e1bda6SJim Ingham     return EvaluateExpression (expr, options);
14407ba6e991SJim Ingham }
14417ba6e991SJim Ingham 
14427ba6e991SJim Ingham SBValue
14437ba6e991SJim Ingham SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value, bool unwind_on_error)
14447ba6e991SJim Ingham {
144535e1bda6SJim Ingham     SBExpressionOptions options;
1446998c8a1cSRyan Brown     ExecutionContext exe_ctx(m_opaque_sp.get());
1447cced1566SGreg Clayton     options.SetFetchDynamicValue (fetch_dynamic_value);
144835e1bda6SJim Ingham     options.SetUnwindOnError (unwind_on_error);
144924785bd0SEugene Leviant     options.SetIgnoreBreakpoints (true);
1450998c8a1cSRyan Brown     StackFrame *frame = exe_ctx.GetFramePtr();
1451998c8a1cSRyan Brown     Target *target = exe_ctx.GetTargetPtr();
1452998c8a1cSRyan Brown     if (target && target->GetLanguage() != eLanguageTypeUnknown)
1453998c8a1cSRyan Brown         options.SetLanguage(target->GetLanguage());
1454998c8a1cSRyan Brown     else if (frame)
1455998c8a1cSRyan Brown         options.SetLanguage(frame->GetLanguage());
145635e1bda6SJim Ingham     return EvaluateExpression (expr, options);
145735e1bda6SJim Ingham }
145835e1bda6SJim Ingham 
145935e1bda6SJim Ingham lldb::SBValue
146035e1bda6SJim Ingham SBFrame::EvaluateExpression (const char *expr, const SBExpressionOptions &options)
146135e1bda6SJim Ingham {
14625160ce5cSGreg Clayton     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
14634838131bSGreg Clayton 
1464358efd65SSaleem Abdulrasool #ifndef LLDB_DISABLE_PYTHON
14655160ce5cSGreg Clayton     Log *expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
1466358efd65SSaleem Abdulrasool #endif
1467a162ebafSSean Callanan 
14688646d3c1SJim Ingham     ExpressionResults exe_results = eExpressionSetupError;
146969b582faSGreg Clayton     SBValue expr_result;
14707730b9a4SJim Ingham 
1471dbb0abbfSEugene Zelenko     if (expr == nullptr || expr[0] == '\0')
14727730b9a4SJim Ingham     {
14737730b9a4SJim Ingham         if (log)
14747730b9a4SJim Ingham             log->Printf ("SBFrame::EvaluateExpression called with an empty expression");
14757730b9a4SJim Ingham         return expr_result;
14767730b9a4SJim Ingham     }
14777730b9a4SJim Ingham 
147881e871edSGreg Clayton     ValueObjectSP expr_value_sp;
14794838131bSGreg Clayton 
1480*bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
1481*bb19a13cSSaleem Abdulrasool     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
14824fc6cb9cSJim Ingham 
1483b9556accSGreg Clayton     if (log)
14847730b9a4SJim Ingham         log->Printf ("SBFrame()::EvaluateExpression (expr=\"%s\")...", expr);
1485b9556accSGreg Clayton 
1486dbb0abbfSEugene Zelenko     StackFrame *frame = nullptr;
14877730b9a4SJim Ingham     Target *target = exe_ctx.GetTargetPtr();
14887730b9a4SJim Ingham     Process *process = exe_ctx.GetProcessPtr();
14897730b9a4SJim Ingham 
14907730b9a4SJim Ingham     if (target && process)
14911d3afba3SGreg Clayton     {
14927fdf9ef1SGreg Clayton         Process::StopLocker stop_locker;
14937730b9a4SJim Ingham         if (stop_locker.TryLock(&process->GetRunLock()))
14947730b9a4SJim Ingham         {
14957730b9a4SJim Ingham             frame = exe_ctx.GetFramePtr();
14967730b9a4SJim Ingham             if (frame)
14977fdf9ef1SGreg Clayton             {
1498fb6621efSGreg Clayton                 if (target->GetDisplayExpressionsInCrashlogs())
1499fb6621efSGreg Clayton                 {
15001ba7c4d0SGreg Clayton                     StreamString frame_description;
1501d9e416c0SGreg Clayton                     frame->DumpUsingSettingsFormat (&frame_description);
15021ba7c4d0SGreg Clayton                     Host::SetCrashDescriptionWithFormat ("SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
1503cced1566SGreg Clayton                                                          expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str());
1504fb6621efSGreg Clayton                 }
1505fb6621efSGreg Clayton 
1506d9e416c0SGreg Clayton                 exe_results = target->EvaluateExpression (expr,
1507d9e416c0SGreg Clayton                                                           frame,
1508d4439aa9SEnrico Granata                                                           expr_value_sp,
150935e1bda6SJim Ingham                                                           options.ref());
1510e3e91517SEnrico Granata                 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
1511fb6621efSGreg Clayton 
1512fb6621efSGreg Clayton                 if (target->GetDisplayExpressionsInCrashlogs())
1513dbb0abbfSEugene Zelenko                     Host::SetCrashDescription(nullptr);
15141d3afba3SGreg Clayton             }
1515c9858e4dSGreg Clayton             else
1516c9858e4dSGreg Clayton             {
1517c9858e4dSGreg Clayton                 if (log)
15187730b9a4SJim Ingham                     log->Printf ("SBFrame::EvaluateExpression () => error: could not reconstruct frame object for this SBFrame.");
15197730b9a4SJim Ingham             }
15207730b9a4SJim Ingham         }
15217730b9a4SJim Ingham         else
15227730b9a4SJim Ingham         {
15237730b9a4SJim Ingham             if (log)
15247730b9a4SJim Ingham                 log->Printf ("SBFrame::EvaluateExpression () => error: process is running");
1525c9858e4dSGreg Clayton         }
15267fdf9ef1SGreg Clayton     }
15274838131bSGreg Clayton 
1528cf7e2dc0SJason Molenda #ifndef LLDB_DISABLE_PYTHON
1529a162ebafSSean Callanan     if (expr_log)
153078a685aaSJim Ingham         expr_log->Printf("** [SBFrame::EvaluateExpression] Expression result is %s, summary %s **",
1531324a1036SSaleem Abdulrasool                          expr_result.GetValue(), expr_result.GetSummary());
1532a162ebafSSean Callanan 
15334838131bSGreg Clayton     if (log)
1534d9e416c0SGreg Clayton         log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)",
1535324a1036SSaleem Abdulrasool                      static_cast<void*>(frame), expr,
1536324a1036SSaleem Abdulrasool                      static_cast<void*>(expr_value_sp.get()), exe_results);
1537cf7e2dc0SJason Molenda #endif
15384838131bSGreg Clayton 
1539cfd1acedSGreg Clayton     return expr_result;
15401d3afba3SGreg Clayton }
1541316d498bSGreg Clayton 
1542316d498bSGreg Clayton bool
15436345fe3eSOleksiy Vyalov SBFrame::IsInlined()
1544316d498bSGreg Clayton {
154505f75e9fSOleksiy Vyalov     return static_cast<const SBFrame*>(this)->IsInlined();
154605f75e9fSOleksiy Vyalov }
154705f75e9fSOleksiy Vyalov 
154805f75e9fSOleksiy Vyalov bool
154905f75e9fSOleksiy Vyalov SBFrame::IsInlined() const
155005f75e9fSOleksiy Vyalov {
15515160ce5cSGreg Clayton     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
15527fdf9ef1SGreg Clayton     ExecutionContext exe_ctx(m_opaque_sp.get());
1553dbb0abbfSEugene Zelenko     StackFrame *frame = nullptr;
1554d9e416c0SGreg Clayton     Target *target = exe_ctx.GetTargetPtr();
15557730b9a4SJim Ingham     Process *process = exe_ctx.GetProcessPtr();
15567730b9a4SJim Ingham     if (target && process)
1557316d498bSGreg Clayton     {
15587fdf9ef1SGreg Clayton         Process::StopLocker stop_locker;
15597730b9a4SJim Ingham         if (stop_locker.TryLock(&process->GetRunLock()))
15607730b9a4SJim Ingham         {
15617730b9a4SJim Ingham             frame = exe_ctx.GetFramePtr();
15627730b9a4SJim Ingham             if (frame)
15637fdf9ef1SGreg Clayton             {
15647fdf9ef1SGreg Clayton 
1565d9e416c0SGreg Clayton                 Block *block = frame->GetSymbolContext(eSymbolContextBlock).block;
1566316d498bSGreg Clayton                 if (block)
1567dbb0abbfSEugene Zelenko                     return block->GetContainingInlinedBlock() != nullptr;
1568316d498bSGreg Clayton             }
1569c9858e4dSGreg Clayton             else
1570c9858e4dSGreg Clayton             {
1571c9858e4dSGreg Clayton                 if (log)
15727730b9a4SJim Ingham                     log->Printf ("SBFrame::IsInlined () => error: could not reconstruct frame object for this SBFrame.");
15737730b9a4SJim Ingham             }
15747730b9a4SJim Ingham         }
15757730b9a4SJim Ingham         else
15767730b9a4SJim Ingham         {
15777730b9a4SJim Ingham             if (log)
15787730b9a4SJim Ingham                 log->Printf ("SBFrame::IsInlined () => error: process is running");
1579c9858e4dSGreg Clayton         }
1580c9858e4dSGreg Clayton 
15817fdf9ef1SGreg Clayton     }
1582316d498bSGreg Clayton     return false;
1583316d498bSGreg Clayton }
1584316d498bSGreg Clayton 
1585316d498bSGreg Clayton const char *
15866345fe3eSOleksiy Vyalov SBFrame::GetFunctionName()
1587316d498bSGreg Clayton {
158805f75e9fSOleksiy Vyalov     return static_cast<const SBFrame*>(this)->GetFunctionName();
158905f75e9fSOleksiy Vyalov }
159005f75e9fSOleksiy Vyalov 
159105f75e9fSOleksiy Vyalov const char *
159205f75e9fSOleksiy Vyalov SBFrame::GetFunctionName() const
159305f75e9fSOleksiy Vyalov {
15945160ce5cSGreg Clayton     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1595dbb0abbfSEugene Zelenko     const char *name = nullptr;
15967fdf9ef1SGreg Clayton     ExecutionContext exe_ctx(m_opaque_sp.get());
1597dbb0abbfSEugene Zelenko     StackFrame *frame = nullptr;
1598d9e416c0SGreg Clayton     Target *target = exe_ctx.GetTargetPtr();
15997730b9a4SJim Ingham     Process *process = exe_ctx.GetProcessPtr();
16007730b9a4SJim Ingham     if (target && process)
1601316d498bSGreg Clayton     {
16027fdf9ef1SGreg Clayton         Process::StopLocker stop_locker;
16037730b9a4SJim Ingham         if (stop_locker.TryLock(&process->GetRunLock()))
16047730b9a4SJim Ingham         {
16057730b9a4SJim Ingham             frame = exe_ctx.GetFramePtr();
16067730b9a4SJim Ingham             if (frame)
16077fdf9ef1SGreg Clayton             {
1608d9e416c0SGreg Clayton                 SymbolContext sc (frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol));
1609316d498bSGreg Clayton                 if (sc.block)
1610316d498bSGreg Clayton                 {
1611316d498bSGreg Clayton                     Block *inlined_block = sc.block->GetContainingInlinedBlock ();
1612316d498bSGreg Clayton                     if (inlined_block)
1613316d498bSGreg Clayton                     {
1614316d498bSGreg Clayton                         const InlineFunctionInfo* inlined_info = inlined_block->GetInlinedFunctionInfo();
1615ddaf6a72SGreg Clayton                         name = inlined_info->GetName(sc.function->GetLanguage()).AsCString();
1616316d498bSGreg Clayton                     }
1617316d498bSGreg Clayton                 }
1618316d498bSGreg Clayton 
1619dbb0abbfSEugene Zelenko                 if (name == nullptr)
1620316d498bSGreg Clayton                 {
1621316d498bSGreg Clayton                     if (sc.function)
1622316d498bSGreg Clayton                         name = sc.function->GetName().GetCString();
1623316d498bSGreg Clayton                 }
1624316d498bSGreg Clayton 
1625dbb0abbfSEugene Zelenko                 if (name == nullptr)
1626316d498bSGreg Clayton                 {
1627316d498bSGreg Clayton                     if (sc.symbol)
1628316d498bSGreg Clayton                         name = sc.symbol->GetName().GetCString();
1629316d498bSGreg Clayton                 }
1630316d498bSGreg Clayton             }
1631c9858e4dSGreg Clayton             else
1632c9858e4dSGreg Clayton             {
1633c9858e4dSGreg Clayton                 if (log)
16347730b9a4SJim Ingham                     log->Printf ("SBFrame::GetFunctionName () => error: could not reconstruct frame object for this SBFrame.");
16357730b9a4SJim Ingham             }
16367730b9a4SJim Ingham         }
16377730b9a4SJim Ingham         else
16387730b9a4SJim Ingham         {
16397730b9a4SJim Ingham             if (log)
16407730b9a4SJim Ingham                 log->Printf ("SBFrame::GetFunctionName() => error: process is running");
1641c9858e4dSGreg Clayton 
1642c9858e4dSGreg Clayton         }
16437fdf9ef1SGreg Clayton     }
1644316d498bSGreg Clayton     return name;
1645316d498bSGreg Clayton }
1646c1f705c2SEnrico Granata 
1647c1f705c2SEnrico Granata const char *
1648c1f705c2SEnrico Granata SBFrame::GetDisplayFunctionName()
1649c1f705c2SEnrico Granata {
1650c1f705c2SEnrico Granata     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1651dbb0abbfSEugene Zelenko     const char *name = nullptr;
1652c1f705c2SEnrico Granata     ExecutionContext exe_ctx(m_opaque_sp.get());
1653dbb0abbfSEugene Zelenko     StackFrame *frame = nullptr;
1654c1f705c2SEnrico Granata     Target *target = exe_ctx.GetTargetPtr();
1655c1f705c2SEnrico Granata     Process *process = exe_ctx.GetProcessPtr();
1656c1f705c2SEnrico Granata     if (target && process)
1657c1f705c2SEnrico Granata     {
1658c1f705c2SEnrico Granata         Process::StopLocker stop_locker;
1659c1f705c2SEnrico Granata         if (stop_locker.TryLock(&process->GetRunLock()))
1660c1f705c2SEnrico Granata         {
1661c1f705c2SEnrico Granata             frame = exe_ctx.GetFramePtr();
1662c1f705c2SEnrico Granata             if (frame)
1663c1f705c2SEnrico Granata             {
1664c1f705c2SEnrico Granata                 SymbolContext sc (frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol));
1665c1f705c2SEnrico Granata                 if (sc.block)
1666c1f705c2SEnrico Granata                 {
1667c1f705c2SEnrico Granata                     Block *inlined_block = sc.block->GetContainingInlinedBlock ();
1668c1f705c2SEnrico Granata                     if (inlined_block)
1669c1f705c2SEnrico Granata                     {
1670c1f705c2SEnrico Granata                         const InlineFunctionInfo* inlined_info = inlined_block->GetInlinedFunctionInfo();
1671ddaf6a72SGreg Clayton                         name = inlined_info->GetDisplayName(sc.function->GetLanguage()).AsCString();
1672c1f705c2SEnrico Granata                     }
1673c1f705c2SEnrico Granata                 }
1674c1f705c2SEnrico Granata 
1675dbb0abbfSEugene Zelenko                 if (name == nullptr)
1676c1f705c2SEnrico Granata                 {
1677c1f705c2SEnrico Granata                     if (sc.function)
1678c1f705c2SEnrico Granata                         name = sc.function->GetDisplayName().GetCString();
1679c1f705c2SEnrico Granata                 }
1680c1f705c2SEnrico Granata 
1681dbb0abbfSEugene Zelenko                 if (name == nullptr)
1682c1f705c2SEnrico Granata                 {
1683c1f705c2SEnrico Granata                     if (sc.symbol)
1684c1f705c2SEnrico Granata                         name = sc.symbol->GetDisplayName().GetCString();
1685c1f705c2SEnrico Granata                 }
1686c1f705c2SEnrico Granata             }
1687c1f705c2SEnrico Granata             else
1688c1f705c2SEnrico Granata             {
1689c1f705c2SEnrico Granata                 if (log)
1690c1f705c2SEnrico Granata                     log->Printf ("SBFrame::GetDisplayFunctionName () => error: could not reconstruct frame object for this SBFrame.");
1691c1f705c2SEnrico Granata             }
1692c1f705c2SEnrico Granata         }
1693c1f705c2SEnrico Granata         else
1694c1f705c2SEnrico Granata         {
1695c1f705c2SEnrico Granata             if (log)
1696c1f705c2SEnrico Granata                 log->Printf ("SBFrame::GetDisplayFunctionName() => error: process is running");
1697c1f705c2SEnrico Granata 
1698c1f705c2SEnrico Granata         }
1699c1f705c2SEnrico Granata     }
1700c1f705c2SEnrico Granata     return name;
1701c1f705c2SEnrico Granata }
1702