1ac7ddfbfSEd Maste //===-- SBFrame.cpp ---------------------------------------------*- C++ -*-===//
2ac7ddfbfSEd Maste //
3ac7ddfbfSEd Maste // The LLVM Compiler Infrastructure
4ac7ddfbfSEd Maste //
5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source
6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details.
7ac7ddfbfSEd Maste //
8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===//
9ac7ddfbfSEd Maste
10ac7ddfbfSEd Maste #include <algorithm>
114bb0738eSEd Maste #include <set>
129f2f44ceSEd Maste #include <string>
139f2f44ceSEd Maste
149f2f44ceSEd Maste #include "lldb/API/SBFrame.h"
15ac7ddfbfSEd Maste
16ac7ddfbfSEd Maste #include "lldb/lldb-types.h"
17ac7ddfbfSEd Maste
18435933ddSDimitry Andric #include "Plugins/ExpressionParser/Clang/ClangPersistentVariables.h"
19ac7ddfbfSEd Maste #include "lldb/Core/Address.h"
20ac7ddfbfSEd Maste #include "lldb/Core/StreamFile.h"
21ac7ddfbfSEd Maste #include "lldb/Core/ValueObjectRegister.h"
22ac7ddfbfSEd Maste #include "lldb/Core/ValueObjectVariable.h"
239f2f44ceSEd Maste #include "lldb/Expression/UserExpression.h"
24ac7ddfbfSEd Maste #include "lldb/Host/Host.h"
25ac7ddfbfSEd Maste #include "lldb/Symbol/Block.h"
26ac7ddfbfSEd Maste #include "lldb/Symbol/Function.h"
27ac7ddfbfSEd Maste #include "lldb/Symbol/Symbol.h"
28ac7ddfbfSEd Maste #include "lldb/Symbol/SymbolContext.h"
29ac7ddfbfSEd Maste #include "lldb/Symbol/Variable.h"
30435933ddSDimitry Andric #include "lldb/Symbol/VariableList.h"
31ac7ddfbfSEd Maste #include "lldb/Target/ExecutionContext.h"
32ac7ddfbfSEd Maste #include "lldb/Target/Process.h"
33ac7ddfbfSEd Maste #include "lldb/Target/RegisterContext.h"
34ac7ddfbfSEd Maste #include "lldb/Target/StackFrame.h"
35*b5893f02SDimitry Andric #include "lldb/Target/StackFrameRecognizer.h"
36ac7ddfbfSEd Maste #include "lldb/Target/StackID.h"
37435933ddSDimitry Andric #include "lldb/Target/Target.h"
38ac7ddfbfSEd Maste #include "lldb/Target/Thread.h"
39f678e45dSDimitry Andric #include "lldb/Utility/ConstString.h"
40f678e45dSDimitry Andric #include "lldb/Utility/Log.h"
41f678e45dSDimitry Andric #include "lldb/Utility/Stream.h"
42ac7ddfbfSEd Maste
43ac7ddfbfSEd Maste #include "lldb/API/SBAddress.h"
44435933ddSDimitry Andric #include "lldb/API/SBDebugger.h"
45ac7ddfbfSEd Maste #include "lldb/API/SBExpressionOptions.h"
46ac7ddfbfSEd Maste #include "lldb/API/SBStream.h"
47ac7ddfbfSEd Maste #include "lldb/API/SBSymbolContext.h"
48ac7ddfbfSEd Maste #include "lldb/API/SBThread.h"
49435933ddSDimitry Andric #include "lldb/API/SBValue.h"
501c3bbb01SEd Maste #include "lldb/API/SBVariablesOptions.h"
51ac7ddfbfSEd Maste
52435933ddSDimitry Andric #include "llvm/Support/PrettyStackTrace.h"
53435933ddSDimitry Andric
54ac7ddfbfSEd Maste using namespace lldb;
55ac7ddfbfSEd Maste using namespace lldb_private;
56ac7ddfbfSEd Maste
SBFrame()57435933ddSDimitry Andric SBFrame::SBFrame() : m_opaque_sp(new ExecutionContextRef()) {}
58ac7ddfbfSEd Maste
SBFrame(const StackFrameSP & lldb_object_sp)59435933ddSDimitry Andric SBFrame::SBFrame(const StackFrameSP &lldb_object_sp)
60435933ddSDimitry Andric : m_opaque_sp(new ExecutionContextRef(lldb_object_sp)) {
61ac7ddfbfSEd Maste Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
62ac7ddfbfSEd Maste
63435933ddSDimitry Andric if (log) {
64ac7ddfbfSEd Maste SBStream sstr;
65ac7ddfbfSEd Maste GetDescription(sstr);
66ac7ddfbfSEd Maste log->Printf("SBFrame::SBFrame (sp=%p) => SBFrame(%p): %s",
670127ef0fSEd Maste static_cast<void *>(lldb_object_sp.get()),
680127ef0fSEd Maste static_cast<void *>(lldb_object_sp.get()), sstr.GetData());
69ac7ddfbfSEd Maste }
70ac7ddfbfSEd Maste }
71ac7ddfbfSEd Maste
SBFrame(const SBFrame & rhs)72435933ddSDimitry Andric SBFrame::SBFrame(const SBFrame &rhs)
73435933ddSDimitry Andric : m_opaque_sp(new ExecutionContextRef(*rhs.m_opaque_sp)) {}
74ac7ddfbfSEd Maste
759f2f44ceSEd Maste SBFrame::~SBFrame() = default;
769f2f44ceSEd Maste
operator =(const SBFrame & rhs)77435933ddSDimitry Andric const SBFrame &SBFrame::operator=(const SBFrame &rhs) {
78ac7ddfbfSEd Maste if (this != &rhs)
79ac7ddfbfSEd Maste *m_opaque_sp = *rhs.m_opaque_sp;
80ac7ddfbfSEd Maste return *this;
81ac7ddfbfSEd Maste }
82ac7ddfbfSEd Maste
GetFrameSP() const83435933ddSDimitry Andric StackFrameSP SBFrame::GetFrameSP() const {
849f2f44ceSEd Maste return (m_opaque_sp ? m_opaque_sp->GetFrameSP() : StackFrameSP());
85ac7ddfbfSEd Maste }
86ac7ddfbfSEd Maste
SetFrameSP(const StackFrameSP & lldb_object_sp)87435933ddSDimitry Andric void SBFrame::SetFrameSP(const StackFrameSP &lldb_object_sp) {
88ac7ddfbfSEd Maste return m_opaque_sp->SetFrameSP(lldb_object_sp);
89ac7ddfbfSEd Maste }
90ac7ddfbfSEd Maste
IsValid() const91435933ddSDimitry Andric bool SBFrame::IsValid() const {
924bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
934bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
944bb0738eSEd Maste
954bb0738eSEd Maste Target *target = exe_ctx.GetTargetPtr();
964bb0738eSEd Maste Process *process = exe_ctx.GetProcessPtr();
97435933ddSDimitry Andric if (target && process) {
984bb0738eSEd Maste Process::StopLocker stop_locker;
994bb0738eSEd Maste if (stop_locker.TryLock(&process->GetRunLock()))
1009f2f44ceSEd Maste return GetFrameSP().get() != nullptr;
101ac7ddfbfSEd Maste }
102ac7ddfbfSEd Maste
1034bb0738eSEd Maste // Without a target & process we can't have a valid stack frame.
1044bb0738eSEd Maste return false;
1054bb0738eSEd Maste }
1064bb0738eSEd Maste
GetSymbolContext(uint32_t resolve_scope) const107435933ddSDimitry Andric SBSymbolContext SBFrame::GetSymbolContext(uint32_t resolve_scope) const {
108ac7ddfbfSEd Maste Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
109ac7ddfbfSEd Maste SBSymbolContext sb_sym_ctx;
1104bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
1114bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
112*b5893f02SDimitry Andric SymbolContextItem scope = static_cast<SymbolContextItem>(resolve_scope);
1139f2f44ceSEd Maste StackFrame *frame = nullptr;
114ac7ddfbfSEd Maste Target *target = exe_ctx.GetTargetPtr();
115ac7ddfbfSEd Maste Process *process = exe_ctx.GetProcessPtr();
116435933ddSDimitry Andric if (target && process) {
117ac7ddfbfSEd Maste Process::StopLocker stop_locker;
118435933ddSDimitry Andric if (stop_locker.TryLock(&process->GetRunLock())) {
119ac7ddfbfSEd Maste frame = exe_ctx.GetFramePtr();
120435933ddSDimitry Andric if (frame) {
121*b5893f02SDimitry Andric sb_sym_ctx.SetSymbolContext(&frame->GetSymbolContext(scope));
122435933ddSDimitry Andric } else {
123ac7ddfbfSEd Maste if (log)
124435933ddSDimitry Andric log->Printf("SBFrame::GetVariables () => error: could not "
125435933ddSDimitry Andric "reconstruct frame object for this SBFrame.");
126ac7ddfbfSEd Maste }
127435933ddSDimitry Andric } else {
128ac7ddfbfSEd Maste if (log)
129435933ddSDimitry Andric log->Printf(
130435933ddSDimitry Andric "SBFrame::GetSymbolContext () => error: process is running");
131ac7ddfbfSEd Maste }
132ac7ddfbfSEd Maste }
133ac7ddfbfSEd Maste
134ac7ddfbfSEd Maste if (log)
135435933ddSDimitry Andric log->Printf("SBFrame(%p)::GetSymbolContext (resolve_scope=0x%8.8x) => "
136435933ddSDimitry Andric "SBSymbolContext(%p)",
1370127ef0fSEd Maste static_cast<void *>(frame), resolve_scope,
1380127ef0fSEd Maste static_cast<void *>(sb_sym_ctx.get()));
139ac7ddfbfSEd Maste
140ac7ddfbfSEd Maste return sb_sym_ctx;
141ac7ddfbfSEd Maste }
142ac7ddfbfSEd Maste
GetModule() const143435933ddSDimitry Andric SBModule SBFrame::GetModule() const {
144ac7ddfbfSEd Maste Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
145ac7ddfbfSEd Maste SBModule sb_module;
146ac7ddfbfSEd Maste ModuleSP module_sp;
1474bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
1484bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
149ac7ddfbfSEd Maste
1509f2f44ceSEd Maste StackFrame *frame = nullptr;
151ac7ddfbfSEd Maste Target *target = exe_ctx.GetTargetPtr();
152ac7ddfbfSEd Maste Process *process = exe_ctx.GetProcessPtr();
153435933ddSDimitry Andric if (target && process) {
154ac7ddfbfSEd Maste Process::StopLocker stop_locker;
155435933ddSDimitry Andric if (stop_locker.TryLock(&process->GetRunLock())) {
156ac7ddfbfSEd Maste frame = exe_ctx.GetFramePtr();
157435933ddSDimitry Andric if (frame) {
158ac7ddfbfSEd Maste module_sp = frame->GetSymbolContext(eSymbolContextModule).module_sp;
159ac7ddfbfSEd Maste sb_module.SetSP(module_sp);
160435933ddSDimitry Andric } else {
161ac7ddfbfSEd Maste if (log)
162435933ddSDimitry Andric log->Printf("SBFrame::GetModule () => error: could not reconstruct "
163435933ddSDimitry Andric "frame object for this SBFrame.");
164ac7ddfbfSEd Maste }
165435933ddSDimitry Andric } else {
166ac7ddfbfSEd Maste if (log)
167ac7ddfbfSEd Maste log->Printf("SBFrame::GetModule () => error: process is running");
168ac7ddfbfSEd Maste }
169ac7ddfbfSEd Maste }
170ac7ddfbfSEd Maste
171ac7ddfbfSEd Maste if (log)
172ac7ddfbfSEd Maste log->Printf("SBFrame(%p)::GetModule () => SBModule(%p)",
1730127ef0fSEd Maste static_cast<void *>(frame),
1740127ef0fSEd Maste static_cast<void *>(module_sp.get()));
175ac7ddfbfSEd Maste
176ac7ddfbfSEd Maste return sb_module;
177ac7ddfbfSEd Maste }
178ac7ddfbfSEd Maste
GetCompileUnit() const179435933ddSDimitry Andric SBCompileUnit SBFrame::GetCompileUnit() const {
180ac7ddfbfSEd Maste Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
181ac7ddfbfSEd Maste SBCompileUnit sb_comp_unit;
1824bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
1834bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
184ac7ddfbfSEd Maste
1859f2f44ceSEd Maste StackFrame *frame = nullptr;
186ac7ddfbfSEd Maste Target *target = exe_ctx.GetTargetPtr();
187ac7ddfbfSEd Maste Process *process = exe_ctx.GetProcessPtr();
188435933ddSDimitry Andric if (target && process) {
189ac7ddfbfSEd Maste Process::StopLocker stop_locker;
190435933ddSDimitry Andric if (stop_locker.TryLock(&process->GetRunLock())) {
191ac7ddfbfSEd Maste frame = exe_ctx.GetFramePtr();
192435933ddSDimitry Andric if (frame) {
193435933ddSDimitry Andric sb_comp_unit.reset(
194435933ddSDimitry Andric frame->GetSymbolContext(eSymbolContextCompUnit).comp_unit);
195435933ddSDimitry Andric } else {
196ac7ddfbfSEd Maste if (log)
197435933ddSDimitry Andric log->Printf("SBFrame::GetCompileUnit () => error: could not "
198435933ddSDimitry Andric "reconstruct frame object for this SBFrame.");
199ac7ddfbfSEd Maste }
200435933ddSDimitry Andric } else {
201ac7ddfbfSEd Maste if (log)
202ac7ddfbfSEd Maste log->Printf("SBFrame::GetCompileUnit () => error: process is running");
203ac7ddfbfSEd Maste }
204ac7ddfbfSEd Maste }
205ac7ddfbfSEd Maste if (log)
206ac7ddfbfSEd Maste log->Printf("SBFrame(%p)::GetCompileUnit () => SBCompileUnit(%p)",
2070127ef0fSEd Maste static_cast<void *>(frame),
2080127ef0fSEd Maste static_cast<void *>(sb_comp_unit.get()));
209ac7ddfbfSEd Maste
210ac7ddfbfSEd Maste return sb_comp_unit;
211ac7ddfbfSEd Maste }
212ac7ddfbfSEd Maste
GetFunction() const213435933ddSDimitry Andric SBFunction SBFrame::GetFunction() const {
214ac7ddfbfSEd Maste Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
215ac7ddfbfSEd Maste SBFunction sb_function;
2164bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
2174bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
218ac7ddfbfSEd Maste
2199f2f44ceSEd Maste StackFrame *frame = nullptr;
220ac7ddfbfSEd Maste Target *target = exe_ctx.GetTargetPtr();
221ac7ddfbfSEd Maste Process *process = exe_ctx.GetProcessPtr();
222435933ddSDimitry Andric if (target && process) {
223ac7ddfbfSEd Maste Process::StopLocker stop_locker;
224435933ddSDimitry Andric if (stop_locker.TryLock(&process->GetRunLock())) {
225ac7ddfbfSEd Maste frame = exe_ctx.GetFramePtr();
226435933ddSDimitry Andric if (frame) {
227435933ddSDimitry Andric sb_function.reset(
228435933ddSDimitry Andric frame->GetSymbolContext(eSymbolContextFunction).function);
229435933ddSDimitry Andric } else {
230ac7ddfbfSEd Maste if (log)
231435933ddSDimitry Andric log->Printf("SBFrame::GetFunction () => error: could not reconstruct "
232435933ddSDimitry Andric "frame object for this SBFrame.");
233ac7ddfbfSEd Maste }
234435933ddSDimitry Andric } else {
235ac7ddfbfSEd Maste if (log)
236ac7ddfbfSEd Maste log->Printf("SBFrame::GetFunction () => error: process is running");
237ac7ddfbfSEd Maste }
238ac7ddfbfSEd Maste }
239ac7ddfbfSEd Maste if (log)
240ac7ddfbfSEd Maste log->Printf("SBFrame(%p)::GetFunction () => SBFunction(%p)",
2410127ef0fSEd Maste static_cast<void *>(frame),
2420127ef0fSEd Maste static_cast<void *>(sb_function.get()));
243ac7ddfbfSEd Maste
244ac7ddfbfSEd Maste return sb_function;
245ac7ddfbfSEd Maste }
246ac7ddfbfSEd Maste
GetSymbol() const247435933ddSDimitry Andric SBSymbol SBFrame::GetSymbol() const {
248ac7ddfbfSEd Maste Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
249ac7ddfbfSEd Maste SBSymbol sb_symbol;
2504bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
2514bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
252ac7ddfbfSEd Maste
2539f2f44ceSEd Maste StackFrame *frame = nullptr;
254ac7ddfbfSEd Maste Target *target = exe_ctx.GetTargetPtr();
255ac7ddfbfSEd Maste Process *process = exe_ctx.GetProcessPtr();
256435933ddSDimitry Andric if (target && process) {
257ac7ddfbfSEd Maste Process::StopLocker stop_locker;
258435933ddSDimitry Andric if (stop_locker.TryLock(&process->GetRunLock())) {
259ac7ddfbfSEd Maste frame = exe_ctx.GetFramePtr();
260435933ddSDimitry Andric if (frame) {
261ac7ddfbfSEd Maste sb_symbol.reset(frame->GetSymbolContext(eSymbolContextSymbol).symbol);
262435933ddSDimitry Andric } else {
263ac7ddfbfSEd Maste if (log)
264435933ddSDimitry Andric log->Printf("SBFrame::GetSymbol () => error: could not reconstruct "
265435933ddSDimitry Andric "frame object for this SBFrame.");
266ac7ddfbfSEd Maste }
267435933ddSDimitry Andric } else {
268ac7ddfbfSEd Maste if (log)
269ac7ddfbfSEd Maste log->Printf("SBFrame::GetSymbol () => error: process is running");
270ac7ddfbfSEd Maste }
271ac7ddfbfSEd Maste }
272ac7ddfbfSEd Maste if (log)
273ac7ddfbfSEd Maste log->Printf("SBFrame(%p)::GetSymbol () => SBSymbol(%p)",
2740127ef0fSEd Maste static_cast<void *>(frame),
2750127ef0fSEd Maste static_cast<void *>(sb_symbol.get()));
276ac7ddfbfSEd Maste return sb_symbol;
277ac7ddfbfSEd Maste }
278ac7ddfbfSEd Maste
GetBlock() const279435933ddSDimitry Andric SBBlock SBFrame::GetBlock() const {
280ac7ddfbfSEd Maste Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
281ac7ddfbfSEd Maste SBBlock sb_block;
2824bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
2834bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
284ac7ddfbfSEd Maste
2859f2f44ceSEd Maste StackFrame *frame = nullptr;
286ac7ddfbfSEd Maste Target *target = exe_ctx.GetTargetPtr();
287ac7ddfbfSEd Maste Process *process = exe_ctx.GetProcessPtr();
288435933ddSDimitry Andric if (target && process) {
289ac7ddfbfSEd Maste Process::StopLocker stop_locker;
290435933ddSDimitry Andric if (stop_locker.TryLock(&process->GetRunLock())) {
291ac7ddfbfSEd Maste frame = exe_ctx.GetFramePtr();
292435933ddSDimitry Andric if (frame) {
293ac7ddfbfSEd Maste sb_block.SetPtr(frame->GetSymbolContext(eSymbolContextBlock).block);
294435933ddSDimitry Andric } else {
295ac7ddfbfSEd Maste if (log)
296435933ddSDimitry Andric log->Printf("SBFrame::GetBlock () => error: could not reconstruct "
297435933ddSDimitry Andric "frame object for this SBFrame.");
298ac7ddfbfSEd Maste }
299435933ddSDimitry Andric } else {
300ac7ddfbfSEd Maste if (log)
3010127ef0fSEd Maste log->Printf("SBFrame(%p)::GetBlock () => error: process is running",
3020127ef0fSEd Maste static_cast<void *>(frame));
303ac7ddfbfSEd Maste }
304ac7ddfbfSEd Maste }
305ac7ddfbfSEd Maste if (log)
306ac7ddfbfSEd Maste log->Printf("SBFrame(%p)::GetBlock () => SBBlock(%p)",
3070127ef0fSEd Maste static_cast<void *>(frame),
3080127ef0fSEd Maste static_cast<void *>(sb_block.GetPtr()));
309ac7ddfbfSEd Maste return sb_block;
310ac7ddfbfSEd Maste }
311ac7ddfbfSEd Maste
GetFrameBlock() const312435933ddSDimitry Andric SBBlock SBFrame::GetFrameBlock() const {
313ac7ddfbfSEd Maste SBBlock sb_block;
3144bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
3154bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
316ac7ddfbfSEd Maste
3179f2f44ceSEd Maste StackFrame *frame = nullptr;
318ac7ddfbfSEd Maste Target *target = exe_ctx.GetTargetPtr();
319ac7ddfbfSEd Maste Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
320ac7ddfbfSEd Maste Process *process = exe_ctx.GetProcessPtr();
321435933ddSDimitry Andric if (target && process) {
322ac7ddfbfSEd Maste Process::StopLocker stop_locker;
323435933ddSDimitry Andric if (stop_locker.TryLock(&process->GetRunLock())) {
324ac7ddfbfSEd Maste frame = exe_ctx.GetFramePtr();
325435933ddSDimitry Andric if (frame) {
326ac7ddfbfSEd Maste sb_block.SetPtr(frame->GetFrameBlock());
327435933ddSDimitry Andric } else {
328ac7ddfbfSEd Maste if (log)
329435933ddSDimitry Andric log->Printf("SBFrame::GetFrameBlock () => error: could not "
330435933ddSDimitry Andric "reconstruct frame object for this SBFrame.");
331ac7ddfbfSEd Maste }
332435933ddSDimitry Andric } else {
333ac7ddfbfSEd Maste if (log)
334ac7ddfbfSEd Maste log->Printf("SBFrame::GetFrameBlock () => error: process is running");
335ac7ddfbfSEd Maste }
336ac7ddfbfSEd Maste }
337ac7ddfbfSEd Maste if (log)
338ac7ddfbfSEd Maste log->Printf("SBFrame(%p)::GetFrameBlock () => SBBlock(%p)",
3390127ef0fSEd Maste static_cast<void *>(frame),
3400127ef0fSEd Maste static_cast<void *>(sb_block.GetPtr()));
341ac7ddfbfSEd Maste return sb_block;
342ac7ddfbfSEd Maste }
343ac7ddfbfSEd Maste
GetLineEntry() const344435933ddSDimitry Andric SBLineEntry SBFrame::GetLineEntry() const {
345ac7ddfbfSEd Maste Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
346ac7ddfbfSEd Maste SBLineEntry sb_line_entry;
3474bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
3484bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
349ac7ddfbfSEd Maste
3509f2f44ceSEd Maste StackFrame *frame = nullptr;
351ac7ddfbfSEd Maste Target *target = exe_ctx.GetTargetPtr();
352ac7ddfbfSEd Maste Process *process = exe_ctx.GetProcessPtr();
353435933ddSDimitry Andric if (target && process) {
354ac7ddfbfSEd Maste Process::StopLocker stop_locker;
355435933ddSDimitry Andric if (stop_locker.TryLock(&process->GetRunLock())) {
356ac7ddfbfSEd Maste frame = exe_ctx.GetFramePtr();
357435933ddSDimitry Andric if (frame) {
358435933ddSDimitry Andric sb_line_entry.SetLineEntry(
359435933ddSDimitry Andric frame->GetSymbolContext(eSymbolContextLineEntry).line_entry);
360435933ddSDimitry Andric } else {
361ac7ddfbfSEd Maste if (log)
362435933ddSDimitry Andric log->Printf("SBFrame::GetLineEntry () => error: could not "
363435933ddSDimitry Andric "reconstruct frame object for this SBFrame.");
364ac7ddfbfSEd Maste }
365435933ddSDimitry Andric } else {
366ac7ddfbfSEd Maste if (log)
367ac7ddfbfSEd Maste log->Printf("SBFrame::GetLineEntry () => error: process is running");
368ac7ddfbfSEd Maste }
369ac7ddfbfSEd Maste }
370ac7ddfbfSEd Maste if (log)
371ac7ddfbfSEd Maste log->Printf("SBFrame(%p)::GetLineEntry () => SBLineEntry(%p)",
3720127ef0fSEd Maste static_cast<void *>(frame),
3730127ef0fSEd Maste static_cast<void *>(sb_line_entry.get()));
374ac7ddfbfSEd Maste return sb_line_entry;
375ac7ddfbfSEd Maste }
376ac7ddfbfSEd Maste
GetFrameID() const377435933ddSDimitry Andric uint32_t SBFrame::GetFrameID() const {
378ac7ddfbfSEd Maste uint32_t frame_idx = UINT32_MAX;
379ac7ddfbfSEd Maste
3804bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
3814bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
3824bb0738eSEd Maste
383ac7ddfbfSEd Maste StackFrame *frame = exe_ctx.GetFramePtr();
384ac7ddfbfSEd Maste if (frame)
385ac7ddfbfSEd Maste frame_idx = frame->GetFrameIndex();
386ac7ddfbfSEd Maste
387ac7ddfbfSEd Maste Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
388ac7ddfbfSEd Maste if (log)
389435933ddSDimitry Andric log->Printf("SBFrame(%p)::GetFrameID () => %u", static_cast<void *>(frame),
390435933ddSDimitry Andric frame_idx);
391ac7ddfbfSEd Maste return frame_idx;
392ac7ddfbfSEd Maste }
393ac7ddfbfSEd Maste
GetCFA() const394435933ddSDimitry Andric lldb::addr_t SBFrame::GetCFA() const {
3954bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
3964bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
3974bb0738eSEd Maste
3981c3bbb01SEd Maste StackFrame *frame = exe_ctx.GetFramePtr();
3991c3bbb01SEd Maste if (frame)
4001c3bbb01SEd Maste return frame->GetStackID().GetCallFrameAddress();
4011c3bbb01SEd Maste return LLDB_INVALID_ADDRESS;
4021c3bbb01SEd Maste }
4031c3bbb01SEd Maste
GetPC() const404435933ddSDimitry Andric addr_t SBFrame::GetPC() const {
405ac7ddfbfSEd Maste Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
406ac7ddfbfSEd Maste addr_t addr = LLDB_INVALID_ADDRESS;
4074bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
4084bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
409ac7ddfbfSEd Maste
4109f2f44ceSEd Maste StackFrame *frame = nullptr;
411ac7ddfbfSEd Maste Target *target = exe_ctx.GetTargetPtr();
412ac7ddfbfSEd Maste Process *process = exe_ctx.GetProcessPtr();
413435933ddSDimitry Andric if (target && process) {
414ac7ddfbfSEd Maste Process::StopLocker stop_locker;
415435933ddSDimitry Andric if (stop_locker.TryLock(&process->GetRunLock())) {
416ac7ddfbfSEd Maste frame = exe_ctx.GetFramePtr();
417435933ddSDimitry Andric if (frame) {
418435933ddSDimitry Andric addr = frame->GetFrameCodeAddress().GetOpcodeLoadAddress(
4194ba319b5SDimitry Andric target, AddressClass::eCode);
420435933ddSDimitry Andric } else {
421ac7ddfbfSEd Maste if (log)
422435933ddSDimitry Andric log->Printf("SBFrame::GetPC () => error: could not reconstruct frame "
423435933ddSDimitry Andric "object for this SBFrame.");
424ac7ddfbfSEd Maste }
425435933ddSDimitry Andric } else {
426ac7ddfbfSEd Maste if (log)
427ac7ddfbfSEd Maste log->Printf("SBFrame::GetPC () => error: process is running");
428ac7ddfbfSEd Maste }
429ac7ddfbfSEd Maste }
430ac7ddfbfSEd Maste
431ac7ddfbfSEd Maste if (log)
4320127ef0fSEd Maste log->Printf("SBFrame(%p)::GetPC () => 0x%" PRIx64,
4330127ef0fSEd Maste static_cast<void *>(frame), addr);
434ac7ddfbfSEd Maste
435ac7ddfbfSEd Maste return addr;
436ac7ddfbfSEd Maste }
437ac7ddfbfSEd Maste
SetPC(addr_t new_pc)438435933ddSDimitry Andric bool SBFrame::SetPC(addr_t new_pc) {
439ac7ddfbfSEd Maste Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
440ac7ddfbfSEd Maste bool ret_val = false;
4414bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
4424bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
443ac7ddfbfSEd Maste
4449f2f44ceSEd Maste StackFrame *frame = nullptr;
445ac7ddfbfSEd Maste Target *target = exe_ctx.GetTargetPtr();
446ac7ddfbfSEd Maste Process *process = exe_ctx.GetProcessPtr();
447435933ddSDimitry Andric if (target && process) {
448ac7ddfbfSEd Maste Process::StopLocker stop_locker;
449435933ddSDimitry Andric if (stop_locker.TryLock(&process->GetRunLock())) {
450ac7ddfbfSEd Maste frame = exe_ctx.GetFramePtr();
451435933ddSDimitry Andric if (frame) {
452ac7ddfbfSEd Maste ret_val = frame->GetRegisterContext()->SetPC(new_pc);
453435933ddSDimitry Andric } else {
454ac7ddfbfSEd Maste if (log)
455435933ddSDimitry Andric log->Printf("SBFrame::SetPC () => error: could not reconstruct frame "
456435933ddSDimitry Andric "object for this SBFrame.");
457ac7ddfbfSEd Maste }
458435933ddSDimitry Andric } else {
459ac7ddfbfSEd Maste if (log)
460ac7ddfbfSEd Maste log->Printf("SBFrame::SetPC () => error: process is running");
461ac7ddfbfSEd Maste }
462ac7ddfbfSEd Maste }
463ac7ddfbfSEd Maste
464ac7ddfbfSEd Maste if (log)
465ac7ddfbfSEd Maste log->Printf("SBFrame(%p)::SetPC (new_pc=0x%" PRIx64 ") => %i",
4660127ef0fSEd Maste static_cast<void *>(frame), new_pc, ret_val);
467ac7ddfbfSEd Maste
468ac7ddfbfSEd Maste return ret_val;
469ac7ddfbfSEd Maste }
470ac7ddfbfSEd Maste
GetSP() const471435933ddSDimitry Andric addr_t SBFrame::GetSP() const {
472ac7ddfbfSEd Maste Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
473ac7ddfbfSEd Maste addr_t addr = LLDB_INVALID_ADDRESS;
4744bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
4754bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
476ac7ddfbfSEd Maste
4779f2f44ceSEd Maste StackFrame *frame = nullptr;
478ac7ddfbfSEd Maste Target *target = exe_ctx.GetTargetPtr();
479ac7ddfbfSEd Maste Process *process = exe_ctx.GetProcessPtr();
480435933ddSDimitry Andric if (target && process) {
481ac7ddfbfSEd Maste Process::StopLocker stop_locker;
482435933ddSDimitry Andric if (stop_locker.TryLock(&process->GetRunLock())) {
483ac7ddfbfSEd Maste frame = exe_ctx.GetFramePtr();
484435933ddSDimitry Andric if (frame) {
485ac7ddfbfSEd Maste addr = frame->GetRegisterContext()->GetSP();
486435933ddSDimitry Andric } else {
487ac7ddfbfSEd Maste if (log)
488435933ddSDimitry Andric log->Printf("SBFrame::GetSP () => error: could not reconstruct frame "
489435933ddSDimitry Andric "object for this SBFrame.");
490ac7ddfbfSEd Maste }
491435933ddSDimitry Andric } else {
492ac7ddfbfSEd Maste if (log)
493ac7ddfbfSEd Maste log->Printf("SBFrame::GetSP () => error: process is running");
494ac7ddfbfSEd Maste }
495ac7ddfbfSEd Maste }
496ac7ddfbfSEd Maste if (log)
4970127ef0fSEd Maste log->Printf("SBFrame(%p)::GetSP () => 0x%" PRIx64,
4980127ef0fSEd Maste static_cast<void *>(frame), addr);
499ac7ddfbfSEd Maste
500ac7ddfbfSEd Maste return addr;
501ac7ddfbfSEd Maste }
502ac7ddfbfSEd Maste
GetFP() const503435933ddSDimitry Andric addr_t SBFrame::GetFP() const {
504ac7ddfbfSEd Maste Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
505ac7ddfbfSEd Maste addr_t addr = LLDB_INVALID_ADDRESS;
5064bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
5074bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
508ac7ddfbfSEd Maste
5099f2f44ceSEd Maste StackFrame *frame = nullptr;
510ac7ddfbfSEd Maste Target *target = exe_ctx.GetTargetPtr();
511ac7ddfbfSEd Maste Process *process = exe_ctx.GetProcessPtr();
512435933ddSDimitry Andric if (target && process) {
513ac7ddfbfSEd Maste Process::StopLocker stop_locker;
514435933ddSDimitry Andric if (stop_locker.TryLock(&process->GetRunLock())) {
515ac7ddfbfSEd Maste frame = exe_ctx.GetFramePtr();
516435933ddSDimitry Andric if (frame) {
517ac7ddfbfSEd Maste addr = frame->GetRegisterContext()->GetFP();
518435933ddSDimitry Andric } else {
519ac7ddfbfSEd Maste if (log)
520435933ddSDimitry Andric log->Printf("SBFrame::GetFP () => error: could not reconstruct frame "
521435933ddSDimitry Andric "object for this SBFrame.");
522ac7ddfbfSEd Maste }
523435933ddSDimitry Andric } else {
524ac7ddfbfSEd Maste if (log)
525ac7ddfbfSEd Maste log->Printf("SBFrame::GetFP () => error: process is running");
526ac7ddfbfSEd Maste }
527ac7ddfbfSEd Maste }
528ac7ddfbfSEd Maste
529ac7ddfbfSEd Maste if (log)
5300127ef0fSEd Maste log->Printf("SBFrame(%p)::GetFP () => 0x%" PRIx64,
5310127ef0fSEd Maste static_cast<void *>(frame), addr);
532ac7ddfbfSEd Maste return addr;
533ac7ddfbfSEd Maste }
534ac7ddfbfSEd Maste
GetPCAddress() const535435933ddSDimitry Andric SBAddress SBFrame::GetPCAddress() const {
536ac7ddfbfSEd Maste Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
537ac7ddfbfSEd Maste SBAddress sb_addr;
5384bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
5394bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
540ac7ddfbfSEd Maste
541ac7ddfbfSEd Maste StackFrame *frame = exe_ctx.GetFramePtr();
542ac7ddfbfSEd Maste Target *target = exe_ctx.GetTargetPtr();
543ac7ddfbfSEd Maste Process *process = exe_ctx.GetProcessPtr();
544435933ddSDimitry Andric if (target && process) {
545ac7ddfbfSEd Maste Process::StopLocker stop_locker;
546435933ddSDimitry Andric if (stop_locker.TryLock(&process->GetRunLock())) {
547ac7ddfbfSEd Maste frame = exe_ctx.GetFramePtr();
548435933ddSDimitry Andric if (frame) {
549ac7ddfbfSEd Maste sb_addr.SetAddress(&frame->GetFrameCodeAddress());
550435933ddSDimitry Andric } else {
551ac7ddfbfSEd Maste if (log)
552435933ddSDimitry Andric log->Printf("SBFrame::GetPCAddress () => error: could not "
553435933ddSDimitry Andric "reconstruct frame object for this SBFrame.");
554ac7ddfbfSEd Maste }
555435933ddSDimitry Andric } else {
556ac7ddfbfSEd Maste if (log)
557ac7ddfbfSEd Maste log->Printf("SBFrame::GetPCAddress () => error: process is running");
558ac7ddfbfSEd Maste }
559ac7ddfbfSEd Maste }
560ac7ddfbfSEd Maste if (log)
5610127ef0fSEd Maste log->Printf("SBFrame(%p)::GetPCAddress () => SBAddress(%p)",
562435933ddSDimitry Andric static_cast<void *>(frame), static_cast<void *>(sb_addr.get()));
563ac7ddfbfSEd Maste return sb_addr;
564ac7ddfbfSEd Maste }
565ac7ddfbfSEd Maste
Clear()566435933ddSDimitry Andric void SBFrame::Clear() { m_opaque_sp->Clear(); }
567ac7ddfbfSEd Maste
GetValueForVariablePath(const char * var_path)568435933ddSDimitry Andric lldb::SBValue SBFrame::GetValueForVariablePath(const char *var_path) {
569ac7ddfbfSEd Maste SBValue sb_value;
5704bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
5714bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
5724bb0738eSEd Maste
573ac7ddfbfSEd Maste StackFrame *frame = exe_ctx.GetFramePtr();
574ac7ddfbfSEd Maste Target *target = exe_ctx.GetTargetPtr();
575435933ddSDimitry Andric if (frame && target) {
576435933ddSDimitry Andric lldb::DynamicValueType use_dynamic =
577435933ddSDimitry Andric frame->CalculateTarget()->GetPreferDynamicValue();
578ac7ddfbfSEd Maste sb_value = GetValueForVariablePath(var_path, use_dynamic);
579ac7ddfbfSEd Maste }
580ac7ddfbfSEd Maste return sb_value;
581ac7ddfbfSEd Maste }
582ac7ddfbfSEd Maste
GetValueForVariablePath(const char * var_path,DynamicValueType use_dynamic)583435933ddSDimitry Andric lldb::SBValue SBFrame::GetValueForVariablePath(const char *var_path,
584435933ddSDimitry Andric DynamicValueType use_dynamic) {
585ac7ddfbfSEd Maste SBValue sb_value;
586ac7ddfbfSEd Maste Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
587435933ddSDimitry Andric if (var_path == nullptr || var_path[0] == '\0') {
588ac7ddfbfSEd Maste if (log)
589435933ddSDimitry Andric log->Printf(
590435933ddSDimitry Andric "SBFrame::GetValueForVariablePath called with empty variable path.");
591ac7ddfbfSEd Maste return sb_value;
592ac7ddfbfSEd Maste }
593ac7ddfbfSEd Maste
5944bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
5954bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
596ac7ddfbfSEd Maste
5979f2f44ceSEd Maste StackFrame *frame = nullptr;
598ac7ddfbfSEd Maste Target *target = exe_ctx.GetTargetPtr();
599ac7ddfbfSEd Maste Process *process = exe_ctx.GetProcessPtr();
600435933ddSDimitry Andric if (target && process) {
601ac7ddfbfSEd Maste Process::StopLocker stop_locker;
602435933ddSDimitry Andric if (stop_locker.TryLock(&process->GetRunLock())) {
603ac7ddfbfSEd Maste frame = exe_ctx.GetFramePtr();
604435933ddSDimitry Andric if (frame) {
605ac7ddfbfSEd Maste VariableSP var_sp;
6065517e702SDimitry Andric Status error;
607435933ddSDimitry Andric ValueObjectSP value_sp(frame->GetValueForVariableExpressionPath(
608435933ddSDimitry Andric var_path, eNoDynamicValues,
609435933ddSDimitry Andric StackFrame::eExpressionPathOptionCheckPtrVsMember |
610435933ddSDimitry Andric StackFrame::eExpressionPathOptionsAllowDirectIVarAccess,
611435933ddSDimitry Andric var_sp, error));
612ac7ddfbfSEd Maste sb_value.SetSP(value_sp, use_dynamic);
613435933ddSDimitry Andric } else {
614ac7ddfbfSEd Maste if (log)
615435933ddSDimitry Andric log->Printf("SBFrame::GetValueForVariablePath () => error: could not "
616435933ddSDimitry Andric "reconstruct frame object for this SBFrame.");
617ac7ddfbfSEd Maste }
618435933ddSDimitry Andric } else {
619ac7ddfbfSEd Maste if (log)
620435933ddSDimitry Andric log->Printf(
621435933ddSDimitry Andric "SBFrame::GetValueForVariablePath () => error: process is running");
622ac7ddfbfSEd Maste }
623ac7ddfbfSEd Maste }
624ac7ddfbfSEd Maste return sb_value;
625ac7ddfbfSEd Maste }
626ac7ddfbfSEd Maste
FindVariable(const char * name)627435933ddSDimitry Andric SBValue SBFrame::FindVariable(const char *name) {
628ac7ddfbfSEd Maste SBValue value;
6294bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
6304bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
6314bb0738eSEd Maste
632ac7ddfbfSEd Maste StackFrame *frame = exe_ctx.GetFramePtr();
633ac7ddfbfSEd Maste Target *target = exe_ctx.GetTargetPtr();
634435933ddSDimitry Andric if (frame && target) {
635435933ddSDimitry Andric lldb::DynamicValueType use_dynamic =
636435933ddSDimitry Andric frame->CalculateTarget()->GetPreferDynamicValue();
637ac7ddfbfSEd Maste value = FindVariable(name, use_dynamic);
638ac7ddfbfSEd Maste }
639ac7ddfbfSEd Maste return value;
640ac7ddfbfSEd Maste }
641ac7ddfbfSEd Maste
FindVariable(const char * name,lldb::DynamicValueType use_dynamic)642435933ddSDimitry Andric SBValue SBFrame::FindVariable(const char *name,
643435933ddSDimitry Andric lldb::DynamicValueType use_dynamic) {
644ac7ddfbfSEd Maste Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
645ac7ddfbfSEd Maste VariableSP var_sp;
646ac7ddfbfSEd Maste SBValue sb_value;
647ac7ddfbfSEd Maste
648435933ddSDimitry Andric if (name == nullptr || name[0] == '\0') {
649ac7ddfbfSEd Maste if (log)
650ac7ddfbfSEd Maste log->Printf("SBFrame::FindVariable called with empty name");
651ac7ddfbfSEd Maste return sb_value;
652ac7ddfbfSEd Maste }
653ac7ddfbfSEd Maste
654ac7ddfbfSEd Maste ValueObjectSP value_sp;
6554bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
6564bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
657ac7ddfbfSEd Maste
6589f2f44ceSEd Maste StackFrame *frame = nullptr;
659ac7ddfbfSEd Maste Target *target = exe_ctx.GetTargetPtr();
660ac7ddfbfSEd Maste Process *process = exe_ctx.GetProcessPtr();
661435933ddSDimitry Andric if (target && process) {
662ac7ddfbfSEd Maste Process::StopLocker stop_locker;
663435933ddSDimitry Andric if (stop_locker.TryLock(&process->GetRunLock())) {
664ac7ddfbfSEd Maste frame = exe_ctx.GetFramePtr();
665435933ddSDimitry Andric if (frame) {
666*b5893f02SDimitry Andric value_sp = frame->FindVariable(ConstString(name));
667ac7ddfbfSEd Maste
668*b5893f02SDimitry Andric if (value_sp)
669ac7ddfbfSEd Maste sb_value.SetSP(value_sp, use_dynamic);
670435933ddSDimitry Andric } else {
671ac7ddfbfSEd Maste if (log)
672435933ddSDimitry Andric log->Printf("SBFrame::FindVariable () => error: could not "
673435933ddSDimitry Andric "reconstruct frame object for this SBFrame.");
674ac7ddfbfSEd Maste }
675435933ddSDimitry Andric } else {
676ac7ddfbfSEd Maste if (log)
677ac7ddfbfSEd Maste log->Printf("SBFrame::FindVariable () => error: process is running");
678ac7ddfbfSEd Maste }
679ac7ddfbfSEd Maste }
680ac7ddfbfSEd Maste
681ac7ddfbfSEd Maste if (log)
682ac7ddfbfSEd Maste log->Printf("SBFrame(%p)::FindVariable (name=\"%s\") => SBValue(%p)",
6830127ef0fSEd Maste static_cast<void *>(frame), name,
6840127ef0fSEd Maste static_cast<void *>(value_sp.get()));
685ac7ddfbfSEd Maste
686ac7ddfbfSEd Maste return sb_value;
687ac7ddfbfSEd Maste }
688ac7ddfbfSEd Maste
FindValue(const char * name,ValueType value_type)689435933ddSDimitry Andric SBValue SBFrame::FindValue(const char *name, ValueType value_type) {
690ac7ddfbfSEd Maste SBValue value;
6914bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
6924bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
6934bb0738eSEd Maste
694ac7ddfbfSEd Maste StackFrame *frame = exe_ctx.GetFramePtr();
695ac7ddfbfSEd Maste Target *target = exe_ctx.GetTargetPtr();
696435933ddSDimitry Andric if (frame && target) {
697435933ddSDimitry Andric lldb::DynamicValueType use_dynamic =
698435933ddSDimitry Andric frame->CalculateTarget()->GetPreferDynamicValue();
699ac7ddfbfSEd Maste value = FindValue(name, value_type, use_dynamic);
700ac7ddfbfSEd Maste }
701ac7ddfbfSEd Maste return value;
702ac7ddfbfSEd Maste }
703ac7ddfbfSEd Maste
FindValue(const char * name,ValueType value_type,lldb::DynamicValueType use_dynamic)704435933ddSDimitry Andric SBValue SBFrame::FindValue(const char *name, ValueType value_type,
705435933ddSDimitry Andric lldb::DynamicValueType use_dynamic) {
706ac7ddfbfSEd Maste Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
707ac7ddfbfSEd Maste SBValue sb_value;
708ac7ddfbfSEd Maste
709435933ddSDimitry Andric if (name == nullptr || name[0] == '\0') {
710ac7ddfbfSEd Maste if (log)
711ac7ddfbfSEd Maste log->Printf("SBFrame::FindValue called with empty name.");
712ac7ddfbfSEd Maste return sb_value;
713ac7ddfbfSEd Maste }
714ac7ddfbfSEd Maste
715ac7ddfbfSEd Maste ValueObjectSP value_sp;
7164bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
7174bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
718ac7ddfbfSEd Maste
7199f2f44ceSEd Maste StackFrame *frame = nullptr;
720ac7ddfbfSEd Maste Target *target = exe_ctx.GetTargetPtr();
721ac7ddfbfSEd Maste Process *process = exe_ctx.GetProcessPtr();
722435933ddSDimitry Andric if (target && process) {
723ac7ddfbfSEd Maste Process::StopLocker stop_locker;
724435933ddSDimitry Andric if (stop_locker.TryLock(&process->GetRunLock())) {
725ac7ddfbfSEd Maste frame = exe_ctx.GetFramePtr();
726435933ddSDimitry Andric if (frame) {
7276fcb8242SEd Maste VariableList variable_list;
7286fcb8242SEd Maste
729435933ddSDimitry Andric switch (value_type) {
730ac7ddfbfSEd Maste case eValueTypeVariableGlobal: // global variable
731ac7ddfbfSEd Maste case eValueTypeVariableStatic: // static variable
732ac7ddfbfSEd Maste case eValueTypeVariableArgument: // function argument variables
733ac7ddfbfSEd Maste case eValueTypeVariableLocal: // function local variables
7344bb0738eSEd Maste case eValueTypeVariableThreadLocal: // thread local variables
735ac7ddfbfSEd Maste {
736ac7ddfbfSEd Maste SymbolContext sc(frame->GetSymbolContext(eSymbolContextBlock));
737ac7ddfbfSEd Maste
738ac7ddfbfSEd Maste const bool can_create = true;
739ac7ddfbfSEd Maste const bool get_parent_variables = true;
740ac7ddfbfSEd Maste const bool stop_if_block_is_inlined_function = true;
741ac7ddfbfSEd Maste
7421c3bbb01SEd Maste if (sc.block)
743435933ddSDimitry Andric sc.block->AppendVariables(
744435933ddSDimitry Andric can_create, get_parent_variables,
745435933ddSDimitry Andric stop_if_block_is_inlined_function,
746435933ddSDimitry Andric [frame](Variable *v) { return v->IsInScope(frame); },
747435933ddSDimitry Andric &variable_list);
748435933ddSDimitry Andric if (value_type == eValueTypeVariableGlobal) {
7496fcb8242SEd Maste const bool get_file_globals = true;
7506fcb8242SEd Maste VariableList *frame_vars = frame->GetVariableList(get_file_globals);
7516fcb8242SEd Maste if (frame_vars)
7526fcb8242SEd Maste frame_vars->AppendVariablesIfUnique(variable_list);
7536fcb8242SEd Maste }
754ac7ddfbfSEd Maste ConstString const_name(name);
755435933ddSDimitry Andric VariableSP variable_sp(
756435933ddSDimitry Andric variable_list.FindVariable(const_name, value_type));
757435933ddSDimitry Andric if (variable_sp) {
758435933ddSDimitry Andric value_sp = frame->GetValueObjectForFrameVariable(variable_sp,
759435933ddSDimitry Andric eNoDynamicValues);
760ac7ddfbfSEd Maste sb_value.SetSP(value_sp, use_dynamic);
761ac7ddfbfSEd Maste }
762435933ddSDimitry Andric } break;
763ac7ddfbfSEd Maste
764ac7ddfbfSEd Maste case eValueTypeRegister: // stack frame register value
765ac7ddfbfSEd Maste {
766ac7ddfbfSEd Maste RegisterContextSP reg_ctx(frame->GetRegisterContext());
767435933ddSDimitry Andric if (reg_ctx) {
768ac7ddfbfSEd Maste const uint32_t num_regs = reg_ctx->GetRegisterCount();
769435933ddSDimitry Andric for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx) {
770435933ddSDimitry Andric const RegisterInfo *reg_info =
771435933ddSDimitry Andric reg_ctx->GetRegisterInfoAtIndex(reg_idx);
772ac7ddfbfSEd Maste if (reg_info &&
773ac7ddfbfSEd Maste ((reg_info->name && strcasecmp(reg_info->name, name) == 0) ||
774435933ddSDimitry Andric (reg_info->alt_name &&
775435933ddSDimitry Andric strcasecmp(reg_info->alt_name, name) == 0))) {
776ac7ddfbfSEd Maste value_sp = ValueObjectRegister::Create(frame, reg_ctx, reg_idx);
777ac7ddfbfSEd Maste sb_value.SetSP(value_sp);
778ac7ddfbfSEd Maste break;
779ac7ddfbfSEd Maste }
780ac7ddfbfSEd Maste }
781ac7ddfbfSEd Maste }
782435933ddSDimitry Andric } break;
783ac7ddfbfSEd Maste
784435933ddSDimitry Andric case eValueTypeRegisterSet: // A collection of stack frame register
785435933ddSDimitry Andric // values
786ac7ddfbfSEd Maste {
787ac7ddfbfSEd Maste RegisterContextSP reg_ctx(frame->GetRegisterContext());
788435933ddSDimitry Andric if (reg_ctx) {
789ac7ddfbfSEd Maste const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
790435933ddSDimitry Andric for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx) {
791ac7ddfbfSEd Maste const RegisterSet *reg_set = reg_ctx->GetRegisterSet(set_idx);
792ac7ddfbfSEd Maste if (reg_set &&
793ac7ddfbfSEd Maste ((reg_set->name && strcasecmp(reg_set->name, name) == 0) ||
794435933ddSDimitry Andric (reg_set->short_name &&
795435933ddSDimitry Andric strcasecmp(reg_set->short_name, name) == 0))) {
796435933ddSDimitry Andric value_sp =
797435933ddSDimitry Andric ValueObjectRegisterSet::Create(frame, reg_ctx, set_idx);
798ac7ddfbfSEd Maste sb_value.SetSP(value_sp);
799ac7ddfbfSEd Maste break;
800ac7ddfbfSEd Maste }
801ac7ddfbfSEd Maste }
802ac7ddfbfSEd Maste }
803435933ddSDimitry Andric } break;
804ac7ddfbfSEd Maste
805ac7ddfbfSEd Maste case eValueTypeConstResult: // constant result variables
806ac7ddfbfSEd Maste {
807ac7ddfbfSEd Maste ConstString const_name(name);
808435933ddSDimitry Andric ExpressionVariableSP expr_var_sp(
809435933ddSDimitry Andric target->GetPersistentVariable(const_name));
810435933ddSDimitry Andric if (expr_var_sp) {
811ac7ddfbfSEd Maste value_sp = expr_var_sp->GetValueObject();
812ac7ddfbfSEd Maste sb_value.SetSP(value_sp, use_dynamic);
813ac7ddfbfSEd Maste }
814435933ddSDimitry Andric } break;
815ac7ddfbfSEd Maste
816ac7ddfbfSEd Maste default:
817ac7ddfbfSEd Maste break;
818ac7ddfbfSEd Maste }
819435933ddSDimitry Andric } else {
820ac7ddfbfSEd Maste if (log)
821435933ddSDimitry Andric log->Printf("SBFrame::FindValue () => error: could not reconstruct "
822435933ddSDimitry Andric "frame object for this SBFrame.");
823ac7ddfbfSEd Maste }
824435933ddSDimitry Andric } else {
825ac7ddfbfSEd Maste if (log)
826ac7ddfbfSEd Maste log->Printf("SBFrame::FindValue () => error: process is running");
827ac7ddfbfSEd Maste }
828ac7ddfbfSEd Maste }
829ac7ddfbfSEd Maste
830ac7ddfbfSEd Maste if (log)
831435933ddSDimitry Andric log->Printf("SBFrame(%p)::FindVariableInScope (name=\"%s\", value_type=%i) "
832435933ddSDimitry Andric "=> SBValue(%p)",
8330127ef0fSEd Maste static_cast<void *>(frame), name, value_type,
8340127ef0fSEd Maste static_cast<void *>(value_sp.get()));
835ac7ddfbfSEd Maste
836ac7ddfbfSEd Maste return sb_value;
837ac7ddfbfSEd Maste }
838ac7ddfbfSEd Maste
IsEqual(const SBFrame & that) const839435933ddSDimitry Andric bool SBFrame::IsEqual(const SBFrame &that) const {
840ac7ddfbfSEd Maste lldb::StackFrameSP this_sp = GetFrameSP();
841ac7ddfbfSEd Maste lldb::StackFrameSP that_sp = that.GetFrameSP();
842ac7ddfbfSEd Maste return (this_sp && that_sp && this_sp->GetStackID() == that_sp->GetStackID());
843ac7ddfbfSEd Maste }
844ac7ddfbfSEd Maste
operator ==(const SBFrame & rhs) const845435933ddSDimitry Andric bool SBFrame::operator==(const SBFrame &rhs) const { return IsEqual(rhs); }
846ac7ddfbfSEd Maste
operator !=(const SBFrame & rhs) const847435933ddSDimitry Andric bool SBFrame::operator!=(const SBFrame &rhs) const { return !IsEqual(rhs); }
848ac7ddfbfSEd Maste
GetThread() const849435933ddSDimitry Andric SBThread SBFrame::GetThread() const {
850ac7ddfbfSEd Maste Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
851ac7ddfbfSEd Maste
8524bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
8534bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
8544bb0738eSEd Maste
855ac7ddfbfSEd Maste ThreadSP thread_sp(exe_ctx.GetThreadSP());
856ac7ddfbfSEd Maste SBThread sb_thread(thread_sp);
857ac7ddfbfSEd Maste
858435933ddSDimitry Andric if (log) {
859ac7ddfbfSEd Maste SBStream sstr;
860ac7ddfbfSEd Maste sb_thread.GetDescription(sstr);
861ac7ddfbfSEd Maste log->Printf("SBFrame(%p)::GetThread () => SBThread(%p): %s",
8620127ef0fSEd Maste static_cast<void *>(exe_ctx.GetFramePtr()),
8630127ef0fSEd Maste static_cast<void *>(thread_sp.get()), sstr.GetData());
864ac7ddfbfSEd Maste }
865ac7ddfbfSEd Maste
866ac7ddfbfSEd Maste return sb_thread;
867ac7ddfbfSEd Maste }
868ac7ddfbfSEd Maste
Disassemble() const869435933ddSDimitry Andric const char *SBFrame::Disassemble() const {
870ac7ddfbfSEd Maste Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
8719f2f44ceSEd Maste const char *disassembly = nullptr;
8724bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
8734bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
874ac7ddfbfSEd Maste
8759f2f44ceSEd Maste StackFrame *frame = nullptr;
876ac7ddfbfSEd Maste Target *target = exe_ctx.GetTargetPtr();
877ac7ddfbfSEd Maste Process *process = exe_ctx.GetProcessPtr();
878435933ddSDimitry Andric if (target && process) {
879ac7ddfbfSEd Maste Process::StopLocker stop_locker;
880435933ddSDimitry Andric if (stop_locker.TryLock(&process->GetRunLock())) {
881ac7ddfbfSEd Maste frame = exe_ctx.GetFramePtr();
882435933ddSDimitry Andric if (frame) {
883ac7ddfbfSEd Maste disassembly = frame->Disassemble();
884435933ddSDimitry Andric } else {
885ac7ddfbfSEd Maste if (log)
886435933ddSDimitry Andric log->Printf("SBFrame::Disassemble () => error: could not reconstruct "
887435933ddSDimitry Andric "frame object for this SBFrame.");
888ac7ddfbfSEd Maste }
889435933ddSDimitry Andric } else {
890ac7ddfbfSEd Maste if (log)
891ac7ddfbfSEd Maste log->Printf("SBFrame::Disassemble () => error: process is running");
892ac7ddfbfSEd Maste }
893ac7ddfbfSEd Maste }
894ac7ddfbfSEd Maste
895ac7ddfbfSEd Maste if (log)
896435933ddSDimitry Andric log->Printf("SBFrame(%p)::Disassemble () => %s", static_cast<void *>(frame),
897435933ddSDimitry Andric disassembly);
898ac7ddfbfSEd Maste
899ac7ddfbfSEd Maste return disassembly;
900ac7ddfbfSEd Maste }
901ac7ddfbfSEd Maste
GetVariables(bool arguments,bool locals,bool statics,bool in_scope_only)902435933ddSDimitry Andric SBValueList SBFrame::GetVariables(bool arguments, bool locals, bool statics,
903435933ddSDimitry Andric bool in_scope_only) {
904ac7ddfbfSEd Maste SBValueList value_list;
9054bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
9064bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
9074bb0738eSEd Maste
908ac7ddfbfSEd Maste StackFrame *frame = exe_ctx.GetFramePtr();
909ac7ddfbfSEd Maste Target *target = exe_ctx.GetTargetPtr();
910435933ddSDimitry Andric if (frame && target) {
911435933ddSDimitry Andric lldb::DynamicValueType use_dynamic =
912435933ddSDimitry Andric frame->CalculateTarget()->GetPreferDynamicValue();
913435933ddSDimitry Andric const bool include_runtime_support_values =
914435933ddSDimitry Andric target ? target->GetDisplayRuntimeSupportValues() : false;
9151c3bbb01SEd Maste
9161c3bbb01SEd Maste SBVariablesOptions options;
9171c3bbb01SEd Maste options.SetIncludeArguments(arguments);
9181c3bbb01SEd Maste options.SetIncludeLocals(locals);
9191c3bbb01SEd Maste options.SetIncludeStatics(statics);
9201c3bbb01SEd Maste options.SetInScopeOnly(in_scope_only);
9211c3bbb01SEd Maste options.SetIncludeRuntimeSupportValues(include_runtime_support_values);
9221c3bbb01SEd Maste options.SetUseDynamic(use_dynamic);
9231c3bbb01SEd Maste
9241c3bbb01SEd Maste value_list = GetVariables(options);
925ac7ddfbfSEd Maste }
926ac7ddfbfSEd Maste return value_list;
927ac7ddfbfSEd Maste }
928ac7ddfbfSEd Maste
GetVariables(bool arguments,bool locals,bool statics,bool in_scope_only,lldb::DynamicValueType use_dynamic)929435933ddSDimitry Andric lldb::SBValueList SBFrame::GetVariables(bool arguments, bool locals,
930435933ddSDimitry Andric bool statics, bool in_scope_only,
931435933ddSDimitry Andric lldb::DynamicValueType use_dynamic) {
9324bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
9334bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
9344bb0738eSEd Maste
9351c3bbb01SEd Maste Target *target = exe_ctx.GetTargetPtr();
936435933ddSDimitry Andric const bool include_runtime_support_values =
937435933ddSDimitry Andric target ? target->GetDisplayRuntimeSupportValues() : false;
9381c3bbb01SEd Maste SBVariablesOptions options;
9391c3bbb01SEd Maste options.SetIncludeArguments(arguments);
9401c3bbb01SEd Maste options.SetIncludeLocals(locals);
9411c3bbb01SEd Maste options.SetIncludeStatics(statics);
9421c3bbb01SEd Maste options.SetInScopeOnly(in_scope_only);
9431c3bbb01SEd Maste options.SetIncludeRuntimeSupportValues(include_runtime_support_values);
9441c3bbb01SEd Maste options.SetUseDynamic(use_dynamic);
9451c3bbb01SEd Maste return GetVariables(options);
9461c3bbb01SEd Maste }
9471c3bbb01SEd Maste
GetVariables(const lldb::SBVariablesOptions & options)948435933ddSDimitry Andric SBValueList SBFrame::GetVariables(const lldb::SBVariablesOptions &options) {
949ac7ddfbfSEd Maste Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
950ac7ddfbfSEd Maste
951ac7ddfbfSEd Maste SBValueList value_list;
9524bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
9534bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
954ac7ddfbfSEd Maste
9559f2f44ceSEd Maste StackFrame *frame = nullptr;
956ac7ddfbfSEd Maste Target *target = exe_ctx.GetTargetPtr();
957ac7ddfbfSEd Maste
9581c3bbb01SEd Maste const bool statics = options.GetIncludeStatics();
9591c3bbb01SEd Maste const bool arguments = options.GetIncludeArguments();
960*b5893f02SDimitry Andric const bool recognized_arguments =
961*b5893f02SDimitry Andric options.GetIncludeRecognizedArguments(SBTarget(exe_ctx.GetTargetSP()));
9621c3bbb01SEd Maste const bool locals = options.GetIncludeLocals();
9631c3bbb01SEd Maste const bool in_scope_only = options.GetInScopeOnly();
964435933ddSDimitry Andric const bool include_runtime_support_values =
965435933ddSDimitry Andric options.GetIncludeRuntimeSupportValues();
9661c3bbb01SEd Maste const lldb::DynamicValueType use_dynamic = options.GetUseDynamic();
9671c3bbb01SEd Maste
968ac7ddfbfSEd Maste if (log)
969*b5893f02SDimitry Andric log->Printf(
970*b5893f02SDimitry Andric "SBFrame::GetVariables (arguments=%i, recognized_arguments=%i, "
971*b5893f02SDimitry Andric "locals=%i, statics=%i, in_scope_only=%i runtime=%i dynamic=%i)",
972*b5893f02SDimitry Andric arguments, recognized_arguments, locals, statics, in_scope_only,
9731c3bbb01SEd Maste include_runtime_support_values, use_dynamic);
974ac7ddfbfSEd Maste
9754bb0738eSEd Maste std::set<VariableSP> variable_set;
976ac7ddfbfSEd Maste Process *process = exe_ctx.GetProcessPtr();
977435933ddSDimitry Andric if (target && process) {
978ac7ddfbfSEd Maste Process::StopLocker stop_locker;
979435933ddSDimitry Andric if (stop_locker.TryLock(&process->GetRunLock())) {
980ac7ddfbfSEd Maste frame = exe_ctx.GetFramePtr();
981435933ddSDimitry Andric if (frame) {
982ac7ddfbfSEd Maste size_t i;
9839f2f44ceSEd Maste VariableList *variable_list = nullptr;
984ac7ddfbfSEd Maste variable_list = frame->GetVariableList(true);
985435933ddSDimitry Andric if (variable_list) {
986ac7ddfbfSEd Maste const size_t num_variables = variable_list->GetSize();
987435933ddSDimitry Andric if (num_variables) {
988435933ddSDimitry Andric for (i = 0; i < num_variables; ++i) {
989ac7ddfbfSEd Maste VariableSP variable_sp(variable_list->GetVariableAtIndex(i));
990435933ddSDimitry Andric if (variable_sp) {
991ac7ddfbfSEd Maste bool add_variable = false;
992435933ddSDimitry Andric switch (variable_sp->GetScope()) {
993ac7ddfbfSEd Maste case eValueTypeVariableGlobal:
994ac7ddfbfSEd Maste case eValueTypeVariableStatic:
9954bb0738eSEd Maste case eValueTypeVariableThreadLocal:
996ac7ddfbfSEd Maste add_variable = statics;
997ac7ddfbfSEd Maste break;
998ac7ddfbfSEd Maste
999ac7ddfbfSEd Maste case eValueTypeVariableArgument:
1000ac7ddfbfSEd Maste add_variable = arguments;
1001ac7ddfbfSEd Maste break;
1002ac7ddfbfSEd Maste
1003ac7ddfbfSEd Maste case eValueTypeVariableLocal:
1004ac7ddfbfSEd Maste add_variable = locals;
1005ac7ddfbfSEd Maste break;
1006ac7ddfbfSEd Maste
1007ac7ddfbfSEd Maste default:
1008ac7ddfbfSEd Maste break;
1009ac7ddfbfSEd Maste }
1010435933ddSDimitry Andric if (add_variable) {
10114bb0738eSEd Maste // Only add variables once so we don't end up with duplicates
10124bb0738eSEd Maste if (variable_set.find(variable_sp) == variable_set.end())
10134bb0738eSEd Maste variable_set.insert(variable_sp);
10144bb0738eSEd Maste else
10154bb0738eSEd Maste continue;
10164bb0738eSEd Maste
1017ac7ddfbfSEd Maste if (in_scope_only && !variable_sp->IsInScope(frame))
1018ac7ddfbfSEd Maste continue;
1019ac7ddfbfSEd Maste
1020435933ddSDimitry Andric ValueObjectSP valobj_sp(frame->GetValueObjectForFrameVariable(
1021435933ddSDimitry Andric variable_sp, eNoDynamicValues));
10221c3bbb01SEd Maste
1023435933ddSDimitry Andric if (!include_runtime_support_values && valobj_sp != nullptr &&
10249f2f44ceSEd Maste valobj_sp->IsRuntimeSupportValue())
10251c3bbb01SEd Maste continue;
10261c3bbb01SEd Maste
1027ac7ddfbfSEd Maste SBValue value_sb;
1028ac7ddfbfSEd Maste value_sb.SetSP(valobj_sp, use_dynamic);
1029ac7ddfbfSEd Maste value_list.Append(value_sb);
1030ac7ddfbfSEd Maste }
1031ac7ddfbfSEd Maste }
1032ac7ddfbfSEd Maste }
1033ac7ddfbfSEd Maste }
1034ac7ddfbfSEd Maste }
1035*b5893f02SDimitry Andric if (recognized_arguments) {
1036*b5893f02SDimitry Andric auto recognized_frame = frame->GetRecognizedFrame();
1037*b5893f02SDimitry Andric if (recognized_frame) {
1038*b5893f02SDimitry Andric ValueObjectListSP recognized_arg_list =
1039*b5893f02SDimitry Andric recognized_frame->GetRecognizedArguments();
1040*b5893f02SDimitry Andric if (recognized_arg_list) {
1041*b5893f02SDimitry Andric for (auto &rec_value_sp : recognized_arg_list->GetObjects()) {
1042*b5893f02SDimitry Andric SBValue value_sb;
1043*b5893f02SDimitry Andric value_sb.SetSP(rec_value_sp, use_dynamic);
1044*b5893f02SDimitry Andric value_list.Append(value_sb);
1045*b5893f02SDimitry Andric }
1046*b5893f02SDimitry Andric }
1047*b5893f02SDimitry Andric }
1048*b5893f02SDimitry Andric }
1049435933ddSDimitry Andric } else {
1050ac7ddfbfSEd Maste if (log)
1051435933ddSDimitry Andric log->Printf("SBFrame::GetVariables () => error: could not "
1052435933ddSDimitry Andric "reconstruct frame object for this SBFrame.");
1053ac7ddfbfSEd Maste }
1054435933ddSDimitry Andric } else {
1055ac7ddfbfSEd Maste if (log)
1056ac7ddfbfSEd Maste log->Printf("SBFrame::GetVariables () => error: process is running");
1057ac7ddfbfSEd Maste }
1058ac7ddfbfSEd Maste }
1059ac7ddfbfSEd Maste
1060ac7ddfbfSEd Maste if (log)
10610127ef0fSEd Maste log->Printf("SBFrame(%p)::GetVariables (...) => SBValueList(%p)",
10620127ef0fSEd Maste static_cast<void *>(frame),
10630127ef0fSEd Maste static_cast<void *>(value_list.opaque_ptr()));
1064ac7ddfbfSEd Maste
1065ac7ddfbfSEd Maste return value_list;
1066ac7ddfbfSEd Maste }
1067ac7ddfbfSEd Maste
GetRegisters()1068435933ddSDimitry Andric SBValueList SBFrame::GetRegisters() {
1069ac7ddfbfSEd Maste Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1070ac7ddfbfSEd Maste
1071ac7ddfbfSEd Maste SBValueList value_list;
10724bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
10734bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1074ac7ddfbfSEd Maste
10759f2f44ceSEd Maste StackFrame *frame = nullptr;
1076ac7ddfbfSEd Maste Target *target = exe_ctx.GetTargetPtr();
1077ac7ddfbfSEd Maste Process *process = exe_ctx.GetProcessPtr();
1078435933ddSDimitry Andric if (target && process) {
1079ac7ddfbfSEd Maste Process::StopLocker stop_locker;
1080435933ddSDimitry Andric if (stop_locker.TryLock(&process->GetRunLock())) {
1081ac7ddfbfSEd Maste frame = exe_ctx.GetFramePtr();
1082435933ddSDimitry Andric if (frame) {
1083ac7ddfbfSEd Maste RegisterContextSP reg_ctx(frame->GetRegisterContext());
1084435933ddSDimitry Andric if (reg_ctx) {
1085ac7ddfbfSEd Maste const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
1086435933ddSDimitry Andric for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx) {
1087435933ddSDimitry Andric value_list.Append(
1088435933ddSDimitry Andric ValueObjectRegisterSet::Create(frame, reg_ctx, set_idx));
1089ac7ddfbfSEd Maste }
1090ac7ddfbfSEd Maste }
1091435933ddSDimitry Andric } else {
1092ac7ddfbfSEd Maste if (log)
1093435933ddSDimitry Andric log->Printf("SBFrame::GetRegisters () => error: could not "
1094435933ddSDimitry Andric "reconstruct frame object for this SBFrame.");
1095ac7ddfbfSEd Maste }
1096435933ddSDimitry Andric } else {
1097ac7ddfbfSEd Maste if (log)
1098ac7ddfbfSEd Maste log->Printf("SBFrame::GetRegisters () => error: process is running");
1099ac7ddfbfSEd Maste }
1100ac7ddfbfSEd Maste }
1101ac7ddfbfSEd Maste
1102ac7ddfbfSEd Maste if (log)
11030127ef0fSEd Maste log->Printf("SBFrame(%p)::GetRegisters () => SBValueList(%p)",
11040127ef0fSEd Maste static_cast<void *>(frame),
11050127ef0fSEd Maste static_cast<void *>(value_list.opaque_ptr()));
1106ac7ddfbfSEd Maste
1107ac7ddfbfSEd Maste return value_list;
1108ac7ddfbfSEd Maste }
1109ac7ddfbfSEd Maste
FindRegister(const char * name)1110435933ddSDimitry Andric SBValue SBFrame::FindRegister(const char *name) {
1111ac7ddfbfSEd Maste Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1112ac7ddfbfSEd Maste
1113ac7ddfbfSEd Maste SBValue result;
1114ac7ddfbfSEd Maste ValueObjectSP value_sp;
11154bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
11164bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1117ac7ddfbfSEd Maste
11189f2f44ceSEd Maste StackFrame *frame = nullptr;
1119ac7ddfbfSEd Maste Target *target = exe_ctx.GetTargetPtr();
1120ac7ddfbfSEd Maste Process *process = exe_ctx.GetProcessPtr();
1121435933ddSDimitry Andric if (target && process) {
1122ac7ddfbfSEd Maste Process::StopLocker stop_locker;
1123435933ddSDimitry Andric if (stop_locker.TryLock(&process->GetRunLock())) {
1124ac7ddfbfSEd Maste frame = exe_ctx.GetFramePtr();
1125435933ddSDimitry Andric if (frame) {
1126ac7ddfbfSEd Maste RegisterContextSP reg_ctx(frame->GetRegisterContext());
1127435933ddSDimitry Andric if (reg_ctx) {
1128ac7ddfbfSEd Maste const uint32_t num_regs = reg_ctx->GetRegisterCount();
1129435933ddSDimitry Andric for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx) {
1130435933ddSDimitry Andric const RegisterInfo *reg_info =
1131435933ddSDimitry Andric reg_ctx->GetRegisterInfoAtIndex(reg_idx);
1132ac7ddfbfSEd Maste if (reg_info &&
1133ac7ddfbfSEd Maste ((reg_info->name && strcasecmp(reg_info->name, name) == 0) ||
1134435933ddSDimitry Andric (reg_info->alt_name &&
1135435933ddSDimitry Andric strcasecmp(reg_info->alt_name, name) == 0))) {
1136ac7ddfbfSEd Maste value_sp = ValueObjectRegister::Create(frame, reg_ctx, reg_idx);
1137ac7ddfbfSEd Maste result.SetSP(value_sp);
1138ac7ddfbfSEd Maste break;
1139ac7ddfbfSEd Maste }
1140ac7ddfbfSEd Maste }
1141ac7ddfbfSEd Maste }
1142435933ddSDimitry Andric } else {
1143ac7ddfbfSEd Maste if (log)
1144435933ddSDimitry Andric log->Printf("SBFrame::FindRegister () => error: could not "
1145435933ddSDimitry Andric "reconstruct frame object for this SBFrame.");
1146ac7ddfbfSEd Maste }
1147435933ddSDimitry Andric } else {
1148ac7ddfbfSEd Maste if (log)
1149ac7ddfbfSEd Maste log->Printf("SBFrame::FindRegister () => error: process is running");
1150ac7ddfbfSEd Maste }
1151ac7ddfbfSEd Maste }
1152ac7ddfbfSEd Maste
1153ac7ddfbfSEd Maste if (log)
11540127ef0fSEd Maste log->Printf("SBFrame(%p)::FindRegister () => SBValue(%p)",
11550127ef0fSEd Maste static_cast<void *>(frame),
11560127ef0fSEd Maste static_cast<void *>(value_sp.get()));
1157ac7ddfbfSEd Maste
1158ac7ddfbfSEd Maste return result;
1159ac7ddfbfSEd Maste }
1160ac7ddfbfSEd Maste
GetDescription(SBStream & description)1161435933ddSDimitry Andric bool SBFrame::GetDescription(SBStream &description) {
1162ac7ddfbfSEd Maste Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1163ac7ddfbfSEd Maste Stream &strm = description.ref();
1164ac7ddfbfSEd Maste
11654bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
11664bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1167ac7ddfbfSEd Maste
1168ac7ddfbfSEd Maste StackFrame *frame;
1169ac7ddfbfSEd Maste Target *target = exe_ctx.GetTargetPtr();
1170ac7ddfbfSEd Maste Process *process = exe_ctx.GetProcessPtr();
1171435933ddSDimitry Andric if (target && process) {
1172ac7ddfbfSEd Maste Process::StopLocker stop_locker;
1173435933ddSDimitry Andric if (stop_locker.TryLock(&process->GetRunLock())) {
1174ac7ddfbfSEd Maste frame = exe_ctx.GetFramePtr();
1175435933ddSDimitry Andric if (frame) {
1176ac7ddfbfSEd Maste frame->DumpUsingSettingsFormat(&strm);
1177435933ddSDimitry Andric } else {
1178ac7ddfbfSEd Maste if (log)
1179435933ddSDimitry Andric log->Printf("SBFrame::GetDescription () => error: could not "
1180435933ddSDimitry Andric "reconstruct frame object for this SBFrame.");
1181ac7ddfbfSEd Maste }
1182435933ddSDimitry Andric } else {
1183ac7ddfbfSEd Maste if (log)
1184ac7ddfbfSEd Maste log->Printf("SBFrame::GetDescription () => error: process is running");
1185ac7ddfbfSEd Maste }
1186ac7ddfbfSEd Maste
1187435933ddSDimitry Andric } else
1188ac7ddfbfSEd Maste strm.PutCString("No value");
1189ac7ddfbfSEd Maste
1190ac7ddfbfSEd Maste return true;
1191ac7ddfbfSEd Maste }
1192ac7ddfbfSEd Maste
EvaluateExpression(const char * expr)1193435933ddSDimitry Andric SBValue SBFrame::EvaluateExpression(const char *expr) {
1194ac7ddfbfSEd Maste SBValue result;
11954bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
11964bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
11974bb0738eSEd Maste
1198ac7ddfbfSEd Maste StackFrame *frame = exe_ctx.GetFramePtr();
1199ac7ddfbfSEd Maste Target *target = exe_ctx.GetTargetPtr();
1200435933ddSDimitry Andric if (frame && target) {
1201ac7ddfbfSEd Maste SBExpressionOptions options;
1202435933ddSDimitry Andric lldb::DynamicValueType fetch_dynamic_value =
1203435933ddSDimitry Andric frame->CalculateTarget()->GetPreferDynamicValue();
1204ac7ddfbfSEd Maste options.SetFetchDynamicValue(fetch_dynamic_value);
1205ac7ddfbfSEd Maste options.SetUnwindOnError(true);
12064bb0738eSEd Maste options.SetIgnoreBreakpoints(true);
12079f2f44ceSEd Maste if (target->GetLanguage() != eLanguageTypeUnknown)
12089f2f44ceSEd Maste options.SetLanguage(target->GetLanguage());
12099f2f44ceSEd Maste else
12109f2f44ceSEd Maste options.SetLanguage(frame->GetLanguage());
1211ac7ddfbfSEd Maste return EvaluateExpression(expr, options);
1212ac7ddfbfSEd Maste }
1213ac7ddfbfSEd Maste return result;
1214ac7ddfbfSEd Maste }
1215ac7ddfbfSEd Maste
1216ac7ddfbfSEd Maste SBValue
EvaluateExpression(const char * expr,lldb::DynamicValueType fetch_dynamic_value)1217435933ddSDimitry Andric SBFrame::EvaluateExpression(const char *expr,
1218435933ddSDimitry Andric lldb::DynamicValueType fetch_dynamic_value) {
1219ac7ddfbfSEd Maste SBExpressionOptions options;
1220ac7ddfbfSEd Maste options.SetFetchDynamicValue(fetch_dynamic_value);
1221ac7ddfbfSEd Maste options.SetUnwindOnError(true);
12224bb0738eSEd Maste options.SetIgnoreBreakpoints(true);
12234bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
12244bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
12254bb0738eSEd Maste
12269f2f44ceSEd Maste StackFrame *frame = exe_ctx.GetFramePtr();
12279f2f44ceSEd Maste Target *target = exe_ctx.GetTargetPtr();
12289f2f44ceSEd Maste if (target && target->GetLanguage() != eLanguageTypeUnknown)
12299f2f44ceSEd Maste options.SetLanguage(target->GetLanguage());
12309f2f44ceSEd Maste else if (frame)
12319f2f44ceSEd Maste options.SetLanguage(frame->GetLanguage());
1232ac7ddfbfSEd Maste return EvaluateExpression(expr, options);
1233ac7ddfbfSEd Maste }
1234ac7ddfbfSEd Maste
EvaluateExpression(const char * expr,lldb::DynamicValueType fetch_dynamic_value,bool unwind_on_error)1235435933ddSDimitry Andric SBValue SBFrame::EvaluateExpression(const char *expr,
1236435933ddSDimitry Andric lldb::DynamicValueType fetch_dynamic_value,
1237435933ddSDimitry Andric bool unwind_on_error) {
1238ac7ddfbfSEd Maste SBExpressionOptions options;
12394bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
12404bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
12414bb0738eSEd Maste
1242ac7ddfbfSEd Maste options.SetFetchDynamicValue(fetch_dynamic_value);
1243ac7ddfbfSEd Maste options.SetUnwindOnError(unwind_on_error);
12444bb0738eSEd Maste options.SetIgnoreBreakpoints(true);
12459f2f44ceSEd Maste StackFrame *frame = exe_ctx.GetFramePtr();
12469f2f44ceSEd Maste Target *target = exe_ctx.GetTargetPtr();
12479f2f44ceSEd Maste if (target && target->GetLanguage() != eLanguageTypeUnknown)
12489f2f44ceSEd Maste options.SetLanguage(target->GetLanguage());
12499f2f44ceSEd Maste else if (frame)
12509f2f44ceSEd Maste options.SetLanguage(frame->GetLanguage());
1251ac7ddfbfSEd Maste return EvaluateExpression(expr, options);
1252ac7ddfbfSEd Maste }
1253ac7ddfbfSEd Maste
EvaluateExpression(const char * expr,const SBExpressionOptions & options)1254435933ddSDimitry Andric lldb::SBValue SBFrame::EvaluateExpression(const char *expr,
1255435933ddSDimitry Andric const SBExpressionOptions &options) {
1256ac7ddfbfSEd Maste Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1257ac7ddfbfSEd Maste
12584bb0738eSEd Maste #ifndef LLDB_DISABLE_PYTHON
1259ac7ddfbfSEd Maste Log *expr_log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
12604bb0738eSEd Maste #endif
1261ac7ddfbfSEd Maste
12620127ef0fSEd Maste ExpressionResults exe_results = eExpressionSetupError;
1263ac7ddfbfSEd Maste SBValue expr_result;
1264ac7ddfbfSEd Maste
1265435933ddSDimitry Andric if (expr == nullptr || expr[0] == '\0') {
1266ac7ddfbfSEd Maste if (log)
1267435933ddSDimitry Andric log->Printf(
1268435933ddSDimitry Andric "SBFrame::EvaluateExpression called with an empty expression");
1269ac7ddfbfSEd Maste return expr_result;
1270ac7ddfbfSEd Maste }
1271ac7ddfbfSEd Maste
1272ac7ddfbfSEd Maste ValueObjectSP expr_value_sp;
1273ac7ddfbfSEd Maste
12744bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
12754bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1276ac7ddfbfSEd Maste
1277ac7ddfbfSEd Maste if (log)
1278ac7ddfbfSEd Maste log->Printf("SBFrame()::EvaluateExpression (expr=\"%s\")...", expr);
1279ac7ddfbfSEd Maste
12809f2f44ceSEd Maste StackFrame *frame = nullptr;
1281ac7ddfbfSEd Maste Target *target = exe_ctx.GetTargetPtr();
1282ac7ddfbfSEd Maste Process *process = exe_ctx.GetProcessPtr();
1283ac7ddfbfSEd Maste
1284435933ddSDimitry Andric if (target && process) {
1285ac7ddfbfSEd Maste Process::StopLocker stop_locker;
1286435933ddSDimitry Andric if (stop_locker.TryLock(&process->GetRunLock())) {
1287ac7ddfbfSEd Maste frame = exe_ctx.GetFramePtr();
1288435933ddSDimitry Andric if (frame) {
1289435933ddSDimitry Andric std::unique_ptr<llvm::PrettyStackTraceFormat> stack_trace;
1290435933ddSDimitry Andric if (target->GetDisplayExpressionsInCrashlogs()) {
1291ac7ddfbfSEd Maste StreamString frame_description;
1292ac7ddfbfSEd Maste frame->DumpUsingSettingsFormat(&frame_description);
1293435933ddSDimitry Andric stack_trace = llvm::make_unique<llvm::PrettyStackTraceFormat>(
1294435933ddSDimitry Andric "SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value "
1295435933ddSDimitry Andric "= %u) %s",
1296435933ddSDimitry Andric expr, options.GetFetchDynamicValue(),
1297435933ddSDimitry Andric frame_description.GetData());
129812b93ac6SEd Maste }
129912b93ac6SEd Maste
1300435933ddSDimitry Andric exe_results = target->EvaluateExpression(expr, frame, expr_value_sp,
1301ac7ddfbfSEd Maste options.ref());
1302ac7ddfbfSEd Maste expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
1303435933ddSDimitry Andric } else {
1304ac7ddfbfSEd Maste if (log)
1305435933ddSDimitry Andric log->Printf("SBFrame::EvaluateExpression () => error: could not "
1306435933ddSDimitry Andric "reconstruct frame object for this SBFrame.");
1307ac7ddfbfSEd Maste }
1308435933ddSDimitry Andric } else {
1309ac7ddfbfSEd Maste if (log)
1310435933ddSDimitry Andric log->Printf(
1311435933ddSDimitry Andric "SBFrame::EvaluateExpression () => error: process is running");
1312ac7ddfbfSEd Maste }
1313ac7ddfbfSEd Maste }
1314ac7ddfbfSEd Maste
1315ac7ddfbfSEd Maste #ifndef LLDB_DISABLE_PYTHON
1316ac7ddfbfSEd Maste if (expr_log)
1317435933ddSDimitry Andric expr_log->Printf("** [SBFrame::EvaluateExpression] Expression result is "
1318435933ddSDimitry Andric "%s, summary %s **",
13190127ef0fSEd Maste expr_result.GetValue(), expr_result.GetSummary());
1320ac7ddfbfSEd Maste
1321ac7ddfbfSEd Maste if (log)
1322435933ddSDimitry Andric log->Printf("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) "
1323435933ddSDimitry Andric "(execution result=%d)",
13240127ef0fSEd Maste static_cast<void *>(frame), expr,
13250127ef0fSEd Maste static_cast<void *>(expr_value_sp.get()), exe_results);
1326ac7ddfbfSEd Maste #endif
1327ac7ddfbfSEd Maste
1328ac7ddfbfSEd Maste return expr_result;
1329ac7ddfbfSEd Maste }
1330ac7ddfbfSEd Maste
IsInlined()1331435933ddSDimitry Andric bool SBFrame::IsInlined() {
13321c3bbb01SEd Maste return static_cast<const SBFrame *>(this)->IsInlined();
13331c3bbb01SEd Maste }
13341c3bbb01SEd Maste
IsInlined() const1335435933ddSDimitry Andric bool SBFrame::IsInlined() const {
1336ac7ddfbfSEd Maste Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
13374bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
13384bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
13394bb0738eSEd Maste
13409f2f44ceSEd Maste StackFrame *frame = nullptr;
1341ac7ddfbfSEd Maste Target *target = exe_ctx.GetTargetPtr();
1342ac7ddfbfSEd Maste Process *process = exe_ctx.GetProcessPtr();
1343435933ddSDimitry Andric if (target && process) {
1344ac7ddfbfSEd Maste Process::StopLocker stop_locker;
1345435933ddSDimitry Andric if (stop_locker.TryLock(&process->GetRunLock())) {
1346ac7ddfbfSEd Maste frame = exe_ctx.GetFramePtr();
1347435933ddSDimitry Andric if (frame) {
1348ac7ddfbfSEd Maste
1349ac7ddfbfSEd Maste Block *block = frame->GetSymbolContext(eSymbolContextBlock).block;
1350ac7ddfbfSEd Maste if (block)
13519f2f44ceSEd Maste return block->GetContainingInlinedBlock() != nullptr;
1352435933ddSDimitry Andric } else {
1353ac7ddfbfSEd Maste if (log)
1354435933ddSDimitry Andric log->Printf("SBFrame::IsInlined () => error: could not reconstruct "
1355435933ddSDimitry Andric "frame object for this SBFrame.");
1356ac7ddfbfSEd Maste }
1357435933ddSDimitry Andric } else {
1358ac7ddfbfSEd Maste if (log)
1359ac7ddfbfSEd Maste log->Printf("SBFrame::IsInlined () => error: process is running");
1360ac7ddfbfSEd Maste }
1361ac7ddfbfSEd Maste }
1362ac7ddfbfSEd Maste return false;
1363ac7ddfbfSEd Maste }
1364ac7ddfbfSEd Maste
IsArtificial()1365*b5893f02SDimitry Andric bool SBFrame::IsArtificial() {
1366*b5893f02SDimitry Andric return static_cast<const SBFrame *>(this)->IsArtificial();
1367*b5893f02SDimitry Andric }
1368*b5893f02SDimitry Andric
IsArtificial() const1369*b5893f02SDimitry Andric bool SBFrame::IsArtificial() const {
1370*b5893f02SDimitry Andric std::unique_lock<std::recursive_mutex> lock;
1371*b5893f02SDimitry Andric ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1372*b5893f02SDimitry Andric
1373*b5893f02SDimitry Andric StackFrame *frame = exe_ctx.GetFramePtr();
1374*b5893f02SDimitry Andric if (frame)
1375*b5893f02SDimitry Andric return frame->IsArtificial();
1376*b5893f02SDimitry Andric
1377*b5893f02SDimitry Andric return false;
1378*b5893f02SDimitry Andric }
1379*b5893f02SDimitry Andric
GetFunctionName()1380435933ddSDimitry Andric const char *SBFrame::GetFunctionName() {
13811c3bbb01SEd Maste return static_cast<const SBFrame *>(this)->GetFunctionName();
13821c3bbb01SEd Maste }
13831c3bbb01SEd Maste
GuessLanguage() const1384f678e45dSDimitry Andric lldb::LanguageType SBFrame::GuessLanguage() const {
1385f678e45dSDimitry Andric std::unique_lock<std::recursive_mutex> lock;
1386f678e45dSDimitry Andric ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1387f678e45dSDimitry Andric
1388f678e45dSDimitry Andric StackFrame *frame = nullptr;
1389f678e45dSDimitry Andric Target *target = exe_ctx.GetTargetPtr();
1390f678e45dSDimitry Andric Process *process = exe_ctx.GetProcessPtr();
1391f678e45dSDimitry Andric if (target && process) {
1392f678e45dSDimitry Andric Process::StopLocker stop_locker;
1393f678e45dSDimitry Andric if (stop_locker.TryLock(&process->GetRunLock())) {
1394f678e45dSDimitry Andric frame = exe_ctx.GetFramePtr();
1395f678e45dSDimitry Andric if (frame) {
1396f678e45dSDimitry Andric return frame->GuessLanguage();
1397f678e45dSDimitry Andric }
1398f678e45dSDimitry Andric }
1399f678e45dSDimitry Andric }
1400f678e45dSDimitry Andric return eLanguageTypeUnknown;
1401f678e45dSDimitry Andric }
1402f678e45dSDimitry Andric
GetFunctionName() const1403435933ddSDimitry Andric const char *SBFrame::GetFunctionName() const {
1404ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
14059f2f44ceSEd Maste const char *name = nullptr;
14064bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
14074bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
14084bb0738eSEd Maste
14099f2f44ceSEd Maste StackFrame *frame = nullptr;
1410ac7ddfbfSEd Maste Target *target = exe_ctx.GetTargetPtr();
1411ac7ddfbfSEd Maste Process *process = exe_ctx.GetProcessPtr();
1412435933ddSDimitry Andric if (target && process) {
1413ac7ddfbfSEd Maste Process::StopLocker stop_locker;
1414435933ddSDimitry Andric if (stop_locker.TryLock(&process->GetRunLock())) {
1415ac7ddfbfSEd Maste frame = exe_ctx.GetFramePtr();
1416435933ddSDimitry Andric if (frame) {
1417435933ddSDimitry Andric SymbolContext sc(frame->GetSymbolContext(eSymbolContextFunction |
1418435933ddSDimitry Andric eSymbolContextBlock |
1419435933ddSDimitry Andric eSymbolContextSymbol));
1420435933ddSDimitry Andric if (sc.block) {
1421ac7ddfbfSEd Maste Block *inlined_block = sc.block->GetContainingInlinedBlock();
1422435933ddSDimitry Andric if (inlined_block) {
1423435933ddSDimitry Andric const InlineFunctionInfo *inlined_info =
1424435933ddSDimitry Andric inlined_block->GetInlinedFunctionInfo();
1425435933ddSDimitry Andric name =
1426435933ddSDimitry Andric inlined_info->GetName(sc.function->GetLanguage()).AsCString();
1427ac7ddfbfSEd Maste }
1428ac7ddfbfSEd Maste }
1429ac7ddfbfSEd Maste
1430435933ddSDimitry Andric if (name == nullptr) {
1431ac7ddfbfSEd Maste if (sc.function)
1432ac7ddfbfSEd Maste name = sc.function->GetName().GetCString();
1433ac7ddfbfSEd Maste }
1434ac7ddfbfSEd Maste
1435435933ddSDimitry Andric if (name == nullptr) {
1436ac7ddfbfSEd Maste if (sc.symbol)
1437ac7ddfbfSEd Maste name = sc.symbol->GetName().GetCString();
1438ac7ddfbfSEd Maste }
1439435933ddSDimitry Andric } else {
1440ac7ddfbfSEd Maste if (log)
1441435933ddSDimitry Andric log->Printf("SBFrame::GetFunctionName () => error: could not "
1442435933ddSDimitry Andric "reconstruct frame object for this SBFrame.");
1443ac7ddfbfSEd Maste }
1444435933ddSDimitry Andric } else {
1445ac7ddfbfSEd Maste if (log)
1446ac7ddfbfSEd Maste log->Printf("SBFrame::GetFunctionName() => error: process is running");
1447ac7ddfbfSEd Maste }
1448ac7ddfbfSEd Maste }
1449ac7ddfbfSEd Maste return name;
1450ac7ddfbfSEd Maste }
1451b91a7dfcSDimitry Andric
GetDisplayFunctionName()1452435933ddSDimitry Andric const char *SBFrame::GetDisplayFunctionName() {
1453b91a7dfcSDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
14549f2f44ceSEd Maste const char *name = nullptr;
14554bb0738eSEd Maste
14564bb0738eSEd Maste std::unique_lock<std::recursive_mutex> lock;
14574bb0738eSEd Maste ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
14584bb0738eSEd Maste
14599f2f44ceSEd Maste StackFrame *frame = nullptr;
1460b91a7dfcSDimitry Andric Target *target = exe_ctx.GetTargetPtr();
1461b91a7dfcSDimitry Andric Process *process = exe_ctx.GetProcessPtr();
1462435933ddSDimitry Andric if (target && process) {
1463b91a7dfcSDimitry Andric Process::StopLocker stop_locker;
1464435933ddSDimitry Andric if (stop_locker.TryLock(&process->GetRunLock())) {
1465b91a7dfcSDimitry Andric frame = exe_ctx.GetFramePtr();
1466435933ddSDimitry Andric if (frame) {
1467435933ddSDimitry Andric SymbolContext sc(frame->GetSymbolContext(eSymbolContextFunction |
1468435933ddSDimitry Andric eSymbolContextBlock |
1469435933ddSDimitry Andric eSymbolContextSymbol));
1470435933ddSDimitry Andric if (sc.block) {
1471b91a7dfcSDimitry Andric Block *inlined_block = sc.block->GetContainingInlinedBlock();
1472435933ddSDimitry Andric if (inlined_block) {
1473435933ddSDimitry Andric const InlineFunctionInfo *inlined_info =
1474435933ddSDimitry Andric inlined_block->GetInlinedFunctionInfo();
1475435933ddSDimitry Andric name = inlined_info->GetDisplayName(sc.function->GetLanguage())
1476435933ddSDimitry Andric .AsCString();
1477b91a7dfcSDimitry Andric }
1478b91a7dfcSDimitry Andric }
1479b91a7dfcSDimitry Andric
1480435933ddSDimitry Andric if (name == nullptr) {
1481b91a7dfcSDimitry Andric if (sc.function)
1482b91a7dfcSDimitry Andric name = sc.function->GetDisplayName().GetCString();
1483b91a7dfcSDimitry Andric }
1484b91a7dfcSDimitry Andric
1485435933ddSDimitry Andric if (name == nullptr) {
1486b91a7dfcSDimitry Andric if (sc.symbol)
1487b91a7dfcSDimitry Andric name = sc.symbol->GetDisplayName().GetCString();
1488b91a7dfcSDimitry Andric }
1489435933ddSDimitry Andric } else {
1490b91a7dfcSDimitry Andric if (log)
1491435933ddSDimitry Andric log->Printf("SBFrame::GetDisplayFunctionName () => error: could not "
1492435933ddSDimitry Andric "reconstruct frame object for this SBFrame.");
1493b91a7dfcSDimitry Andric }
1494435933ddSDimitry Andric } else {
1495b91a7dfcSDimitry Andric if (log)
1496435933ddSDimitry Andric log->Printf(
1497435933ddSDimitry Andric "SBFrame::GetDisplayFunctionName() => error: process is running");
1498b91a7dfcSDimitry Andric }
1499b91a7dfcSDimitry Andric }
1500b91a7dfcSDimitry Andric return name;
1501b91a7dfcSDimitry Andric }
1502