1254721Semaste//===-- SBFrame.cpp ---------------------------------------------*- C++ -*-===//
2254721Semaste//
3254721Semaste//                     The LLVM Compiler Infrastructure
4254721Semaste//
5254721Semaste// This file is distributed under the University of Illinois Open Source
6254721Semaste// License. See LICENSE.TXT for details.
7254721Semaste//
8254721Semaste//===----------------------------------------------------------------------===//
9254721Semaste
10254721Semaste#include "lldb/API/SBFrame.h"
11254721Semaste
12254721Semaste#include <string>
13254721Semaste#include <algorithm>
14254721Semaste
15254721Semaste#include "lldb/lldb-types.h"
16254721Semaste
17254721Semaste#include "lldb/Core/Address.h"
18254721Semaste#include "lldb/Core/ConstString.h"
19254721Semaste#include "lldb/Core/Log.h"
20254721Semaste#include "lldb/Core/Stream.h"
21254721Semaste#include "lldb/Core/StreamFile.h"
22254721Semaste#include "lldb/Core/ValueObjectRegister.h"
23254721Semaste#include "lldb/Core/ValueObjectVariable.h"
24254721Semaste#include "lldb/Expression/ClangUserExpression.h"
25254721Semaste#include "lldb/Host/Host.h"
26254721Semaste#include "lldb/Symbol/Block.h"
27254721Semaste#include "lldb/Symbol/Function.h"
28254721Semaste#include "lldb/Symbol/Symbol.h"
29254721Semaste#include "lldb/Symbol/SymbolContext.h"
30254721Semaste#include "lldb/Symbol/VariableList.h"
31254721Semaste#include "lldb/Symbol/Variable.h"
32254721Semaste#include "lldb/Target/ExecutionContext.h"
33254721Semaste#include "lldb/Target/Target.h"
34254721Semaste#include "lldb/Target/Process.h"
35254721Semaste#include "lldb/Target/RegisterContext.h"
36254721Semaste#include "lldb/Target/StackFrame.h"
37254721Semaste#include "lldb/Target/StackID.h"
38254721Semaste#include "lldb/Target/Thread.h"
39254721Semaste
40254721Semaste#include "lldb/API/SBDebugger.h"
41254721Semaste#include "lldb/API/SBValue.h"
42254721Semaste#include "lldb/API/SBAddress.h"
43254721Semaste#include "lldb/API/SBExpressionOptions.h"
44254721Semaste#include "lldb/API/SBStream.h"
45254721Semaste#include "lldb/API/SBSymbolContext.h"
46254721Semaste#include "lldb/API/SBThread.h"
47254721Semaste
48254721Semasteusing namespace lldb;
49254721Semasteusing namespace lldb_private;
50254721Semaste
51254721Semaste
52254721SemasteSBFrame::SBFrame () :
53254721Semaste    m_opaque_sp (new ExecutionContextRef())
54254721Semaste{
55254721Semaste}
56254721Semaste
57254721SemasteSBFrame::SBFrame (const StackFrameSP &lldb_object_sp) :
58254721Semaste    m_opaque_sp (new ExecutionContextRef (lldb_object_sp))
59254721Semaste{
60254721Semaste    Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
61254721Semaste
62254721Semaste    if (log)
63254721Semaste    {
64254721Semaste        SBStream sstr;
65254721Semaste        GetDescription (sstr);
66254721Semaste        log->Printf ("SBFrame::SBFrame (sp=%p) => SBFrame(%p): %s",
67254721Semaste                     lldb_object_sp.get(), lldb_object_sp.get(), sstr.GetData());
68254721Semaste
69254721Semaste    }
70254721Semaste}
71254721Semaste
72254721SemasteSBFrame::SBFrame(const SBFrame &rhs) :
73254721Semaste    m_opaque_sp (new ExecutionContextRef (*rhs.m_opaque_sp))
74254721Semaste{
75254721Semaste}
76254721Semaste
77254721Semasteconst SBFrame &
78254721SemasteSBFrame::operator = (const SBFrame &rhs)
79254721Semaste{
80254721Semaste    if (this != &rhs)
81254721Semaste        *m_opaque_sp = *rhs.m_opaque_sp;
82254721Semaste    return *this;
83254721Semaste}
84254721Semaste
85254721SemasteSBFrame::~SBFrame()
86254721Semaste{
87254721Semaste}
88254721Semaste
89254721SemasteStackFrameSP
90254721SemasteSBFrame::GetFrameSP() const
91254721Semaste{
92254721Semaste    if (m_opaque_sp)
93254721Semaste        return m_opaque_sp->GetFrameSP();
94254721Semaste    return StackFrameSP();
95254721Semaste}
96254721Semaste
97254721Semastevoid
98254721SemasteSBFrame::SetFrameSP (const StackFrameSP &lldb_object_sp)
99254721Semaste{
100254721Semaste    return m_opaque_sp->SetFrameSP(lldb_object_sp);
101254721Semaste}
102254721Semaste
103254721Semastebool
104254721SemasteSBFrame::IsValid() const
105254721Semaste{
106254721Semaste    return GetFrameSP().get() != NULL;
107254721Semaste}
108254721Semaste
109254721SemasteSBSymbolContext
110254721SemasteSBFrame::GetSymbolContext (uint32_t resolve_scope) const
111254721Semaste{
112254721Semaste    Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
113254721Semaste    SBSymbolContext sb_sym_ctx;
114254721Semaste    Mutex::Locker api_locker;
115254721Semaste    ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
116254721Semaste
117254721Semaste    StackFrame *frame = NULL;
118254721Semaste    Target *target = exe_ctx.GetTargetPtr();
119254721Semaste    Process *process = exe_ctx.GetProcessPtr();
120254721Semaste    if (target && process)
121254721Semaste    {
122254721Semaste        Process::StopLocker stop_locker;
123254721Semaste        if (stop_locker.TryLock(&process->GetRunLock()))
124254721Semaste        {
125254721Semaste            frame = exe_ctx.GetFramePtr();
126254721Semaste            if (frame)
127254721Semaste            {
128254721Semaste                sb_sym_ctx.SetSymbolContext(&frame->GetSymbolContext (resolve_scope));
129254721Semaste            }
130254721Semaste            else
131254721Semaste            {
132254721Semaste                if (log)
133254721Semaste                    log->Printf ("SBFrame::GetVariables () => error: could not reconstruct frame object for this SBFrame.");
134254721Semaste            }
135254721Semaste        }
136254721Semaste        else
137254721Semaste        {
138254721Semaste            if (log)
139254721Semaste                log->Printf ("SBFrame::GetSymbolContext () => error: process is running");
140254721Semaste        }
141254721Semaste    }
142254721Semaste
143254721Semaste    if (log)
144254721Semaste        log->Printf ("SBFrame(%p)::GetSymbolContext (resolve_scope=0x%8.8x) => SBSymbolContext(%p)",
145254721Semaste                     frame, resolve_scope, sb_sym_ctx.get());
146254721Semaste
147254721Semaste    return sb_sym_ctx;
148254721Semaste}
149254721Semaste
150254721SemasteSBModule
151254721SemasteSBFrame::GetModule () const
152254721Semaste{
153254721Semaste    Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
154254721Semaste    SBModule sb_module;
155254721Semaste    ModuleSP module_sp;
156254721Semaste    Mutex::Locker api_locker;
157254721Semaste    ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
158254721Semaste
159254721Semaste    StackFrame *frame = NULL;
160254721Semaste    Target *target = exe_ctx.GetTargetPtr();
161254721Semaste    Process *process = exe_ctx.GetProcessPtr();
162254721Semaste    if (target && process)
163254721Semaste    {
164254721Semaste        Process::StopLocker stop_locker;
165254721Semaste        if (stop_locker.TryLock(&process->GetRunLock()))
166254721Semaste        {
167254721Semaste            frame = exe_ctx.GetFramePtr();
168254721Semaste            if (frame)
169254721Semaste            {
170254721Semaste                module_sp = frame->GetSymbolContext (eSymbolContextModule).module_sp;
171254721Semaste                sb_module.SetSP (module_sp);
172254721Semaste            }
173254721Semaste            else
174254721Semaste            {
175254721Semaste                if (log)
176254721Semaste                    log->Printf ("SBFrame::GetModule () => error: could not reconstruct frame object for this SBFrame.");
177254721Semaste            }
178254721Semaste        }
179254721Semaste        else
180254721Semaste        {
181254721Semaste            if (log)
182254721Semaste                log->Printf ("SBFrame::GetModule () => error: process is running");
183254721Semaste        }
184254721Semaste    }
185254721Semaste
186254721Semaste    if (log)
187254721Semaste        log->Printf ("SBFrame(%p)::GetModule () => SBModule(%p)",
188254721Semaste                     frame, module_sp.get());
189254721Semaste
190254721Semaste    return sb_module;
191254721Semaste}
192254721Semaste
193254721SemasteSBCompileUnit
194254721SemasteSBFrame::GetCompileUnit () const
195254721Semaste{
196254721Semaste    Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
197254721Semaste    SBCompileUnit sb_comp_unit;
198254721Semaste    Mutex::Locker api_locker;
199254721Semaste    ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
200254721Semaste
201254721Semaste    StackFrame *frame = NULL;
202254721Semaste    Target *target = exe_ctx.GetTargetPtr();
203254721Semaste    Process *process = exe_ctx.GetProcessPtr();
204254721Semaste    if (target && process)
205254721Semaste    {
206254721Semaste        Process::StopLocker stop_locker;
207254721Semaste        if (stop_locker.TryLock(&process->GetRunLock()))
208254721Semaste        {
209254721Semaste            frame = exe_ctx.GetFramePtr();
210254721Semaste            if (frame)
211254721Semaste            {
212254721Semaste                sb_comp_unit.reset (frame->GetSymbolContext (eSymbolContextCompUnit).comp_unit);
213254721Semaste            }
214254721Semaste            else
215254721Semaste            {
216254721Semaste                if (log)
217254721Semaste                    log->Printf ("SBFrame::GetCompileUnit () => error: could not reconstruct frame object for this SBFrame.");
218254721Semaste            }
219254721Semaste        }
220254721Semaste        else
221254721Semaste        {
222254721Semaste            if (log)
223254721Semaste                log->Printf ("SBFrame::GetCompileUnit () => error: process is running");
224254721Semaste        }
225254721Semaste    }
226254721Semaste    if (log)
227254721Semaste        log->Printf ("SBFrame(%p)::GetCompileUnit () => SBCompileUnit(%p)",
228254721Semaste                     frame, sb_comp_unit.get());
229254721Semaste
230254721Semaste    return sb_comp_unit;
231254721Semaste}
232254721Semaste
233254721SemasteSBFunction
234254721SemasteSBFrame::GetFunction () const
235254721Semaste{
236254721Semaste    Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
237254721Semaste    SBFunction sb_function;
238254721Semaste    Mutex::Locker api_locker;
239254721Semaste    ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
240254721Semaste
241254721Semaste    StackFrame *frame = NULL;
242254721Semaste    Target *target = exe_ctx.GetTargetPtr();
243254721Semaste    Process *process = exe_ctx.GetProcessPtr();
244254721Semaste    if (target && process)
245254721Semaste    {
246254721Semaste        Process::StopLocker stop_locker;
247254721Semaste        if (stop_locker.TryLock(&process->GetRunLock()))
248254721Semaste        {
249254721Semaste            frame = exe_ctx.GetFramePtr();
250254721Semaste            if (frame)
251254721Semaste            {
252254721Semaste                sb_function.reset(frame->GetSymbolContext (eSymbolContextFunction).function);
253254721Semaste            }
254254721Semaste            else
255254721Semaste            {
256254721Semaste                if (log)
257254721Semaste                    log->Printf ("SBFrame::GetFunction () => error: could not reconstruct frame object for this SBFrame.");
258254721Semaste            }
259254721Semaste        }
260254721Semaste        else
261254721Semaste        {
262254721Semaste            if (log)
263254721Semaste                log->Printf ("SBFrame::GetFunction () => error: process is running");
264254721Semaste        }
265254721Semaste    }
266254721Semaste    if (log)
267254721Semaste        log->Printf ("SBFrame(%p)::GetFunction () => SBFunction(%p)",
268254721Semaste                     frame, sb_function.get());
269254721Semaste
270254721Semaste    return sb_function;
271254721Semaste}
272254721Semaste
273254721SemasteSBSymbol
274254721SemasteSBFrame::GetSymbol () const
275254721Semaste{
276254721Semaste    Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
277254721Semaste    SBSymbol sb_symbol;
278254721Semaste    Mutex::Locker api_locker;
279254721Semaste    ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
280254721Semaste
281254721Semaste    StackFrame *frame = NULL;
282254721Semaste    Target *target = exe_ctx.GetTargetPtr();
283254721Semaste    Process *process = exe_ctx.GetProcessPtr();
284254721Semaste    if (target && process)
285254721Semaste    {
286254721Semaste        Process::StopLocker stop_locker;
287254721Semaste        if (stop_locker.TryLock(&process->GetRunLock()))
288254721Semaste        {
289254721Semaste            frame = exe_ctx.GetFramePtr();
290254721Semaste            if (frame)
291254721Semaste            {
292254721Semaste                sb_symbol.reset(frame->GetSymbolContext (eSymbolContextSymbol).symbol);
293254721Semaste            }
294254721Semaste            else
295254721Semaste            {
296254721Semaste                if (log)
297254721Semaste                    log->Printf ("SBFrame::GetSymbol () => error: could not reconstruct frame object for this SBFrame.");
298254721Semaste            }
299254721Semaste        }
300254721Semaste        else
301254721Semaste        {
302254721Semaste            if (log)
303254721Semaste                log->Printf ("SBFrame::GetSymbol () => error: process is running");
304254721Semaste        }
305254721Semaste    }
306254721Semaste    if (log)
307254721Semaste        log->Printf ("SBFrame(%p)::GetSymbol () => SBSymbol(%p)",
308254721Semaste                     frame, sb_symbol.get());
309254721Semaste    return sb_symbol;
310254721Semaste}
311254721Semaste
312254721SemasteSBBlock
313254721SemasteSBFrame::GetBlock () const
314254721Semaste{
315254721Semaste    Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
316254721Semaste    SBBlock sb_block;
317254721Semaste    Mutex::Locker api_locker;
318254721Semaste    ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
319254721Semaste
320254721Semaste    StackFrame *frame = NULL;
321254721Semaste    Target *target = exe_ctx.GetTargetPtr();
322254721Semaste    Process *process = exe_ctx.GetProcessPtr();
323254721Semaste    if (target && process)
324254721Semaste    {
325254721Semaste        Process::StopLocker stop_locker;
326254721Semaste        if (stop_locker.TryLock(&process->GetRunLock()))
327254721Semaste        {
328254721Semaste            frame = exe_ctx.GetFramePtr();
329254721Semaste            if (frame)
330254721Semaste            {
331254721Semaste                sb_block.SetPtr (frame->GetSymbolContext (eSymbolContextBlock).block);
332254721Semaste            }
333254721Semaste            else
334254721Semaste            {
335254721Semaste                if (log)
336254721Semaste                    log->Printf ("SBFrame::GetBlock () => error: could not reconstruct frame object for this SBFrame.");
337254721Semaste            }
338254721Semaste        }
339254721Semaste        else
340254721Semaste        {
341254721Semaste            if (log)
342254721Semaste                log->Printf ("SBFrame(%p)::GetBlock () => error: process is running", frame);
343254721Semaste        }
344254721Semaste    }
345254721Semaste    if (log)
346254721Semaste        log->Printf ("SBFrame(%p)::GetBlock () => SBBlock(%p)",
347254721Semaste                     frame, sb_block.GetPtr());
348254721Semaste    return sb_block;
349254721Semaste}
350254721Semaste
351254721SemasteSBBlock
352254721SemasteSBFrame::GetFrameBlock () const
353254721Semaste{
354254721Semaste    SBBlock sb_block;
355254721Semaste    Mutex::Locker api_locker;
356254721Semaste    ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
357254721Semaste
358254721Semaste    StackFrame *frame = NULL;
359254721Semaste    Target *target = exe_ctx.GetTargetPtr();
360254721Semaste    Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
361254721Semaste    Process *process = exe_ctx.GetProcessPtr();
362254721Semaste    if (target && process)
363254721Semaste    {
364254721Semaste        Process::StopLocker stop_locker;
365254721Semaste        if (stop_locker.TryLock(&process->GetRunLock()))
366254721Semaste        {
367254721Semaste            frame = exe_ctx.GetFramePtr();
368254721Semaste            if (frame)
369254721Semaste            {
370254721Semaste                sb_block.SetPtr(frame->GetFrameBlock ());
371254721Semaste            }
372254721Semaste            else
373254721Semaste            {
374254721Semaste                if (log)
375254721Semaste                    log->Printf ("SBFrame::GetFrameBlock () => error: could not reconstruct frame object for this SBFrame.");
376254721Semaste            }
377254721Semaste        }
378254721Semaste        else
379254721Semaste        {
380254721Semaste            if (log)
381254721Semaste                log->Printf ("SBFrame::GetFrameBlock () => error: process is running");
382254721Semaste        }
383254721Semaste    }
384254721Semaste    if (log)
385254721Semaste        log->Printf ("SBFrame(%p)::GetFrameBlock () => SBBlock(%p)",
386254721Semaste                     frame, sb_block.GetPtr());
387254721Semaste    return sb_block;
388254721Semaste}
389254721Semaste
390254721SemasteSBLineEntry
391254721SemasteSBFrame::GetLineEntry () const
392254721Semaste{
393254721Semaste    Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
394254721Semaste    SBLineEntry sb_line_entry;
395254721Semaste    Mutex::Locker api_locker;
396254721Semaste    ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
397254721Semaste
398254721Semaste    StackFrame *frame = NULL;
399254721Semaste    Target *target = exe_ctx.GetTargetPtr();
400254721Semaste    Process *process = exe_ctx.GetProcessPtr();
401254721Semaste    if (target && process)
402254721Semaste    {
403254721Semaste        Process::StopLocker stop_locker;
404254721Semaste        if (stop_locker.TryLock(&process->GetRunLock()))
405254721Semaste        {
406254721Semaste            frame = exe_ctx.GetFramePtr();
407254721Semaste            if (frame)
408254721Semaste            {
409254721Semaste                sb_line_entry.SetLineEntry (frame->GetSymbolContext (eSymbolContextLineEntry).line_entry);
410254721Semaste            }
411254721Semaste            else
412254721Semaste            {
413254721Semaste                if (log)
414254721Semaste                    log->Printf ("SBFrame::GetLineEntry () => error: could not reconstruct frame object for this SBFrame.");
415254721Semaste            }
416254721Semaste        }
417254721Semaste        else
418254721Semaste        {
419254721Semaste            if (log)
420254721Semaste                log->Printf ("SBFrame::GetLineEntry () => error: process is running");
421254721Semaste        }
422254721Semaste    }
423254721Semaste    if (log)
424254721Semaste        log->Printf ("SBFrame(%p)::GetLineEntry () => SBLineEntry(%p)",
425254721Semaste                     frame, sb_line_entry.get());
426254721Semaste    return sb_line_entry;
427254721Semaste}
428254721Semaste
429254721Semasteuint32_t
430254721SemasteSBFrame::GetFrameID () const
431254721Semaste{
432254721Semaste    uint32_t frame_idx = UINT32_MAX;
433254721Semaste
434254721Semaste    ExecutionContext exe_ctx(m_opaque_sp.get());
435254721Semaste    StackFrame *frame = exe_ctx.GetFramePtr();
436254721Semaste    if (frame)
437254721Semaste        frame_idx = frame->GetFrameIndex ();
438254721Semaste
439254721Semaste    Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
440254721Semaste    if (log)
441254721Semaste        log->Printf ("SBFrame(%p)::GetFrameID () => %u",
442254721Semaste                     frame, frame_idx);
443254721Semaste    return frame_idx;
444254721Semaste}
445254721Semaste
446254721Semasteaddr_t
447254721SemasteSBFrame::GetPC () const
448254721Semaste{
449254721Semaste    Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
450254721Semaste    addr_t addr = LLDB_INVALID_ADDRESS;
451254721Semaste    Mutex::Locker api_locker;
452254721Semaste    ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
453254721Semaste
454254721Semaste    StackFrame *frame = NULL;
455254721Semaste    Target *target = exe_ctx.GetTargetPtr();
456254721Semaste    Process *process = exe_ctx.GetProcessPtr();
457254721Semaste    if (target && process)
458254721Semaste    {
459254721Semaste        Process::StopLocker stop_locker;
460254721Semaste        if (stop_locker.TryLock(&process->GetRunLock()))
461254721Semaste        {
462254721Semaste            frame = exe_ctx.GetFramePtr();
463254721Semaste            if (frame)
464254721Semaste            {
465254721Semaste                addr = frame->GetFrameCodeAddress().GetOpcodeLoadAddress (target);
466254721Semaste            }
467254721Semaste            else
468254721Semaste            {
469254721Semaste                if (log)
470254721Semaste                    log->Printf ("SBFrame::GetPC () => error: could not reconstruct frame object for this SBFrame.");
471254721Semaste            }
472254721Semaste        }
473254721Semaste        else
474254721Semaste        {
475254721Semaste            if (log)
476254721Semaste                log->Printf ("SBFrame::GetPC () => error: process is running");
477254721Semaste        }
478254721Semaste    }
479254721Semaste
480254721Semaste    if (log)
481254721Semaste        log->Printf ("SBFrame(%p)::GetPC () => 0x%" PRIx64, frame, addr);
482254721Semaste
483254721Semaste    return addr;
484254721Semaste}
485254721Semaste
486254721Semastebool
487254721SemasteSBFrame::SetPC (addr_t new_pc)
488254721Semaste{
489254721Semaste    Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
490254721Semaste    bool ret_val = false;
491254721Semaste    Mutex::Locker api_locker;
492254721Semaste    ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
493254721Semaste
494254721Semaste    StackFrame *frame = NULL;
495254721Semaste    Target *target = exe_ctx.GetTargetPtr();
496254721Semaste    Process *process = exe_ctx.GetProcessPtr();
497254721Semaste    if (target && process)
498254721Semaste    {
499254721Semaste        Process::StopLocker stop_locker;
500254721Semaste        if (stop_locker.TryLock(&process->GetRunLock()))
501254721Semaste        {
502254721Semaste            frame = exe_ctx.GetFramePtr();
503254721Semaste            if (frame)
504254721Semaste            {
505254721Semaste                ret_val = frame->GetRegisterContext()->SetPC (new_pc);
506254721Semaste            }
507254721Semaste            else
508254721Semaste            {
509254721Semaste                if (log)
510254721Semaste                    log->Printf ("SBFrame::SetPC () => error: could not reconstruct frame object for this SBFrame.");
511254721Semaste            }
512254721Semaste        }
513254721Semaste        else
514254721Semaste        {
515254721Semaste            if (log)
516254721Semaste                log->Printf ("SBFrame::SetPC () => error: process is running");
517254721Semaste        }
518254721Semaste    }
519254721Semaste
520254721Semaste    if (log)
521254721Semaste        log->Printf ("SBFrame(%p)::SetPC (new_pc=0x%" PRIx64 ") => %i",
522254721Semaste                     frame, new_pc, ret_val);
523254721Semaste
524254721Semaste    return ret_val;
525254721Semaste}
526254721Semaste
527254721Semasteaddr_t
528254721SemasteSBFrame::GetSP () const
529254721Semaste{
530254721Semaste    Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
531254721Semaste    addr_t addr = LLDB_INVALID_ADDRESS;
532254721Semaste    Mutex::Locker api_locker;
533254721Semaste    ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
534254721Semaste
535254721Semaste    StackFrame *frame = NULL;
536254721Semaste    Target *target = exe_ctx.GetTargetPtr();
537254721Semaste    Process *process = exe_ctx.GetProcessPtr();
538254721Semaste    if (target && process)
539254721Semaste    {
540254721Semaste        Process::StopLocker stop_locker;
541254721Semaste        if (stop_locker.TryLock(&process->GetRunLock()))
542254721Semaste        {
543254721Semaste            frame = exe_ctx.GetFramePtr();
544254721Semaste            if (frame)
545254721Semaste            {
546254721Semaste                addr = frame->GetRegisterContext()->GetSP();
547254721Semaste            }
548254721Semaste            else
549254721Semaste            {
550254721Semaste                if (log)
551254721Semaste                    log->Printf ("SBFrame::GetSP () => error: could not reconstruct frame object for this SBFrame.");
552254721Semaste            }
553254721Semaste        }
554254721Semaste        else
555254721Semaste        {
556254721Semaste            if (log)
557254721Semaste                log->Printf ("SBFrame::GetSP () => error: process is running");
558254721Semaste        }
559254721Semaste    }
560254721Semaste    if (log)
561254721Semaste        log->Printf ("SBFrame(%p)::GetSP () => 0x%" PRIx64, frame, addr);
562254721Semaste
563254721Semaste    return addr;
564254721Semaste}
565254721Semaste
566254721Semaste
567254721Semasteaddr_t
568254721SemasteSBFrame::GetFP () const
569254721Semaste{
570254721Semaste    Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
571254721Semaste    addr_t addr = LLDB_INVALID_ADDRESS;
572254721Semaste    Mutex::Locker api_locker;
573254721Semaste    ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
574254721Semaste
575254721Semaste    StackFrame *frame = NULL;
576254721Semaste    Target *target = exe_ctx.GetTargetPtr();
577254721Semaste    Process *process = exe_ctx.GetProcessPtr();
578254721Semaste    if (target && process)
579254721Semaste    {
580254721Semaste        Process::StopLocker stop_locker;
581254721Semaste        if (stop_locker.TryLock(&process->GetRunLock()))
582254721Semaste        {
583254721Semaste            frame = exe_ctx.GetFramePtr();
584254721Semaste            if (frame)
585254721Semaste            {
586254721Semaste                addr = frame->GetRegisterContext()->GetFP();
587254721Semaste            }
588254721Semaste            else
589254721Semaste            {
590254721Semaste                if (log)
591254721Semaste                    log->Printf ("SBFrame::GetFP () => error: could not reconstruct frame object for this SBFrame.");
592254721Semaste            }
593254721Semaste        }
594254721Semaste        else
595254721Semaste        {
596254721Semaste            if (log)
597254721Semaste                log->Printf ("SBFrame::GetFP () => error: process is running");
598254721Semaste        }
599254721Semaste    }
600254721Semaste
601254721Semaste    if (log)
602254721Semaste        log->Printf ("SBFrame(%p)::GetFP () => 0x%" PRIx64, frame, addr);
603254721Semaste    return addr;
604254721Semaste}
605254721Semaste
606254721Semaste
607254721SemasteSBAddress
608254721SemasteSBFrame::GetPCAddress () const
609254721Semaste{
610254721Semaste    Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
611254721Semaste    SBAddress sb_addr;
612254721Semaste    Mutex::Locker api_locker;
613254721Semaste    ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
614254721Semaste
615254721Semaste    StackFrame *frame = exe_ctx.GetFramePtr();
616254721Semaste    Target *target = exe_ctx.GetTargetPtr();
617254721Semaste    Process *process = exe_ctx.GetProcessPtr();
618254721Semaste    if (target && process)
619254721Semaste    {
620254721Semaste        Process::StopLocker stop_locker;
621254721Semaste        if (stop_locker.TryLock(&process->GetRunLock()))
622254721Semaste        {
623254721Semaste            frame = exe_ctx.GetFramePtr();
624254721Semaste            if (frame)
625254721Semaste            {
626254721Semaste                sb_addr.SetAddress (&frame->GetFrameCodeAddress());
627254721Semaste            }
628254721Semaste            else
629254721Semaste            {
630254721Semaste                if (log)
631254721Semaste                    log->Printf ("SBFrame::GetPCAddress () => error: could not reconstruct frame object for this SBFrame.");
632254721Semaste            }
633254721Semaste        }
634254721Semaste        else
635254721Semaste        {
636254721Semaste            if (log)
637254721Semaste                log->Printf ("SBFrame::GetPCAddress () => error: process is running");
638254721Semaste        }
639254721Semaste    }
640254721Semaste    if (log)
641254721Semaste        log->Printf ("SBFrame(%p)::GetPCAddress () => SBAddress(%p)", frame, sb_addr.get());
642254721Semaste    return sb_addr;
643254721Semaste}
644254721Semaste
645254721Semastevoid
646254721SemasteSBFrame::Clear()
647254721Semaste{
648254721Semaste    m_opaque_sp->Clear();
649254721Semaste}
650254721Semaste
651254721Semastelldb::SBValue
652254721SemasteSBFrame::GetValueForVariablePath (const char *var_path)
653254721Semaste{
654254721Semaste    SBValue sb_value;
655254721Semaste    ExecutionContext exe_ctx(m_opaque_sp.get());
656254721Semaste    StackFrame *frame = exe_ctx.GetFramePtr();
657254721Semaste    Target *target = exe_ctx.GetTargetPtr();
658254721Semaste    if (frame && target)
659254721Semaste    {
660254721Semaste        lldb::DynamicValueType  use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
661254721Semaste        sb_value = GetValueForVariablePath (var_path, use_dynamic);
662254721Semaste    }
663254721Semaste    return sb_value;
664254721Semaste}
665254721Semaste
666254721Semastelldb::SBValue
667254721SemasteSBFrame::GetValueForVariablePath (const char *var_path, DynamicValueType use_dynamic)
668254721Semaste{
669254721Semaste    SBValue sb_value;
670254721Semaste    Mutex::Locker api_locker;
671254721Semaste    Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
672254721Semaste    if (var_path == NULL || var_path[0] == '\0')
673254721Semaste    {
674254721Semaste        if (log)
675254721Semaste            log->Printf ("SBFrame::GetValueForVariablePath called with empty variable path.");
676254721Semaste        return sb_value;
677254721Semaste    }
678254721Semaste
679254721Semaste    ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
680254721Semaste
681254721Semaste    StackFrame *frame = NULL;
682254721Semaste    Target *target = exe_ctx.GetTargetPtr();
683254721Semaste    Process *process = exe_ctx.GetProcessPtr();
684254721Semaste    if (target && process)
685254721Semaste    {
686254721Semaste        Process::StopLocker stop_locker;
687254721Semaste        if (stop_locker.TryLock(&process->GetRunLock()))
688254721Semaste        {
689254721Semaste            frame = exe_ctx.GetFramePtr();
690254721Semaste            if (frame)
691254721Semaste            {
692254721Semaste                VariableSP var_sp;
693254721Semaste                Error error;
694254721Semaste                ValueObjectSP value_sp (frame->GetValueForVariableExpressionPath (var_path,
695254721Semaste                                                                                  eNoDynamicValues,
696254721Semaste                                                                                  StackFrame::eExpressionPathOptionCheckPtrVsMember | StackFrame::eExpressionPathOptionsAllowDirectIVarAccess,
697254721Semaste                                                                                  var_sp,
698254721Semaste                                                                                  error));
699254721Semaste                sb_value.SetSP(value_sp, use_dynamic);
700254721Semaste            }
701254721Semaste            else
702254721Semaste            {
703254721Semaste                if (log)
704254721Semaste                    log->Printf ("SBFrame::GetValueForVariablePath () => error: could not reconstruct frame object for this SBFrame.");
705254721Semaste            }
706254721Semaste        }
707254721Semaste        else
708254721Semaste        {
709254721Semaste            if (log)
710254721Semaste                log->Printf ("SBFrame::GetValueForVariablePath () => error: process is running");
711254721Semaste        }
712254721Semaste    }
713254721Semaste    return sb_value;
714254721Semaste}
715254721Semaste
716254721SemasteSBValue
717254721SemasteSBFrame::FindVariable (const char *name)
718254721Semaste{
719254721Semaste    SBValue value;
720254721Semaste    ExecutionContext exe_ctx(m_opaque_sp.get());
721254721Semaste    StackFrame *frame = exe_ctx.GetFramePtr();
722254721Semaste    Target *target = exe_ctx.GetTargetPtr();
723254721Semaste    if (frame && target)
724254721Semaste    {
725254721Semaste        lldb::DynamicValueType  use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
726254721Semaste        value = FindVariable (name, use_dynamic);
727254721Semaste    }
728254721Semaste    return value;
729254721Semaste}
730254721Semaste
731254721Semaste
732254721SemasteSBValue
733254721SemasteSBFrame::FindVariable (const char *name, lldb::DynamicValueType use_dynamic)
734254721Semaste{
735254721Semaste    Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
736254721Semaste    VariableSP var_sp;
737254721Semaste    SBValue sb_value;
738254721Semaste
739254721Semaste    if (name == NULL || name[0] == '\0')
740254721Semaste    {
741254721Semaste        if (log)
742254721Semaste            log->Printf ("SBFrame::FindVariable called with empty name");
743254721Semaste        return sb_value;
744254721Semaste    }
745254721Semaste
746254721Semaste    ValueObjectSP value_sp;
747254721Semaste    Mutex::Locker api_locker;
748254721Semaste    ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
749254721Semaste
750254721Semaste    StackFrame *frame = NULL;
751254721Semaste    Target *target = exe_ctx.GetTargetPtr();
752254721Semaste    Process *process = exe_ctx.GetProcessPtr();
753254721Semaste    if (target && process)
754254721Semaste    {
755254721Semaste        Process::StopLocker stop_locker;
756254721Semaste        if (stop_locker.TryLock(&process->GetRunLock()))
757254721Semaste        {
758254721Semaste            frame = exe_ctx.GetFramePtr();
759254721Semaste            if (frame)
760254721Semaste            {
761254721Semaste                VariableList variable_list;
762254721Semaste                SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock));
763254721Semaste
764254721Semaste                if (sc.block)
765254721Semaste                {
766254721Semaste                    const bool can_create = true;
767254721Semaste                    const bool get_parent_variables = true;
768254721Semaste                    const bool stop_if_block_is_inlined_function = true;
769254721Semaste
770254721Semaste                    if (sc.block->AppendVariables (can_create,
771254721Semaste                                                   get_parent_variables,
772254721Semaste                                                   stop_if_block_is_inlined_function,
773254721Semaste                                                   &variable_list))
774254721Semaste                    {
775254721Semaste                        var_sp = variable_list.FindVariable (ConstString(name));
776254721Semaste                    }
777254721Semaste                }
778254721Semaste
779254721Semaste                if (var_sp)
780254721Semaste                {
781254721Semaste                    value_sp = frame->GetValueObjectForFrameVariable(var_sp, eNoDynamicValues);
782254721Semaste                    sb_value.SetSP(value_sp, use_dynamic);
783254721Semaste                }
784254721Semaste            }
785254721Semaste            else
786254721Semaste            {
787254721Semaste                if (log)
788254721Semaste                    log->Printf ("SBFrame::FindVariable () => error: could not reconstruct frame object for this SBFrame.");
789254721Semaste            }
790254721Semaste        }
791254721Semaste        else
792254721Semaste        {
793254721Semaste            if (log)
794254721Semaste                log->Printf ("SBFrame::FindVariable () => error: process is running");
795254721Semaste        }
796254721Semaste    }
797254721Semaste
798254721Semaste    if (log)
799254721Semaste        log->Printf ("SBFrame(%p)::FindVariable (name=\"%s\") => SBValue(%p)",
800254721Semaste                     frame, name, value_sp.get());
801254721Semaste
802254721Semaste    return sb_value;
803254721Semaste}
804254721Semaste
805254721SemasteSBValue
806254721SemasteSBFrame::FindValue (const char *name, ValueType value_type)
807254721Semaste{
808254721Semaste    SBValue value;
809254721Semaste    ExecutionContext exe_ctx(m_opaque_sp.get());
810254721Semaste    StackFrame *frame = exe_ctx.GetFramePtr();
811254721Semaste    Target *target = exe_ctx.GetTargetPtr();
812254721Semaste    if (frame && target)
813254721Semaste    {
814254721Semaste        lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
815254721Semaste        value = FindValue (name, value_type, use_dynamic);
816254721Semaste    }
817254721Semaste    return value;
818254721Semaste}
819254721Semaste
820254721SemasteSBValue
821254721SemasteSBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueType use_dynamic)
822254721Semaste{
823254721Semaste    Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
824254721Semaste    SBValue sb_value;
825254721Semaste
826254721Semaste    if (name == NULL || name[0] == '\0')
827254721Semaste    {
828254721Semaste        if (log)
829254721Semaste            log->Printf ("SBFrame::FindValue called with empty name.");
830254721Semaste        return sb_value;
831254721Semaste    }
832254721Semaste
833254721Semaste    ValueObjectSP value_sp;
834254721Semaste    Mutex::Locker api_locker;
835254721Semaste    ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
836254721Semaste
837254721Semaste    StackFrame *frame = NULL;
838254721Semaste    Target *target = exe_ctx.GetTargetPtr();
839254721Semaste    Process *process = exe_ctx.GetProcessPtr();
840254721Semaste    if (target && process)
841254721Semaste    {
842254721Semaste        Process::StopLocker stop_locker;
843254721Semaste        if (stop_locker.TryLock(&process->GetRunLock()))
844254721Semaste        {
845254721Semaste            frame = exe_ctx.GetFramePtr();
846254721Semaste            if (frame)
847254721Semaste            {
848269024Semaste                VariableList variable_list;
849269024Semaste
850254721Semaste                switch (value_type)
851254721Semaste                {
852254721Semaste                case eValueTypeVariableGlobal:      // global variable
853254721Semaste                case eValueTypeVariableStatic:      // static variable
854254721Semaste                case eValueTypeVariableArgument:    // function argument variables
855254721Semaste                case eValueTypeVariableLocal:       // function local variables
856254721Semaste                    {
857269024Semaste
858254721Semaste                        SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock));
859254721Semaste
860254721Semaste                        const bool can_create = true;
861254721Semaste                        const bool get_parent_variables = true;
862254721Semaste                        const bool stop_if_block_is_inlined_function = true;
863254721Semaste
864254721Semaste                        if (sc.block && sc.block->AppendVariables (can_create,
865254721Semaste                                                                   get_parent_variables,
866254721Semaste                                                                   stop_if_block_is_inlined_function,
867269024Semaste                                                                   &variable_list))
868254721Semaste                        {
869269024Semaste                            if (value_type == eValueTypeVariableGlobal)
870269024Semaste                            {
871269024Semaste                                const bool get_file_globals = true;
872269024Semaste                                VariableList* frame_vars = frame->GetVariableList(get_file_globals);
873269024Semaste                                if (frame_vars)
874269024Semaste                                    frame_vars->AppendVariablesIfUnique(variable_list);
875269024Semaste                            }
876254721Semaste                            ConstString const_name(name);
877269024Semaste                            VariableSP variable_sp(variable_list.FindVariable(const_name,value_type));
878269024Semaste                            if (variable_sp)
879254721Semaste                            {
880269024Semaste                                value_sp = frame->GetValueObjectForFrameVariable (variable_sp, eNoDynamicValues);
881269024Semaste                                sb_value.SetSP (value_sp, use_dynamic);
882269024Semaste                                break;
883254721Semaste                            }
884254721Semaste                        }
885254721Semaste                    }
886254721Semaste                    break;
887254721Semaste
888254721Semaste                case eValueTypeRegister:            // stack frame register value
889254721Semaste                    {
890254721Semaste                        RegisterContextSP reg_ctx (frame->GetRegisterContext());
891254721Semaste                        if (reg_ctx)
892254721Semaste                        {
893254721Semaste                            const uint32_t num_regs = reg_ctx->GetRegisterCount();
894254721Semaste                            for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx)
895254721Semaste                            {
896254721Semaste                                const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
897254721Semaste                                if (reg_info &&
898254721Semaste                                    ((reg_info->name && strcasecmp (reg_info->name, name) == 0) ||
899254721Semaste                                     (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0)))
900254721Semaste                                {
901254721Semaste                                    value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx);
902254721Semaste                                    sb_value.SetSP (value_sp);
903254721Semaste                                    break;
904254721Semaste                                }
905254721Semaste                            }
906254721Semaste                        }
907254721Semaste                    }
908254721Semaste                    break;
909254721Semaste
910254721Semaste                case eValueTypeRegisterSet:         // A collection of stack frame register values
911254721Semaste                    {
912254721Semaste                        RegisterContextSP reg_ctx (frame->GetRegisterContext());
913254721Semaste                        if (reg_ctx)
914254721Semaste                        {
915254721Semaste                            const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
916254721Semaste                            for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
917254721Semaste                            {
918254721Semaste                                const RegisterSet *reg_set = reg_ctx->GetRegisterSet (set_idx);
919254721Semaste                                if (reg_set &&
920254721Semaste                                    ((reg_set->name && strcasecmp (reg_set->name, name) == 0) ||
921254721Semaste                                     (reg_set->short_name && strcasecmp (reg_set->short_name, name) == 0)))
922254721Semaste                                {
923254721Semaste                                    value_sp = ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx);
924254721Semaste                                    sb_value.SetSP (value_sp);
925254721Semaste                                    break;
926254721Semaste                                }
927254721Semaste                            }
928254721Semaste                        }
929254721Semaste                    }
930254721Semaste                    break;
931254721Semaste
932254721Semaste                case eValueTypeConstResult:         // constant result variables
933254721Semaste                    {
934254721Semaste                        ConstString const_name(name);
935254721Semaste                        ClangExpressionVariableSP expr_var_sp (target->GetPersistentVariables().GetVariable (const_name));
936254721Semaste                        if (expr_var_sp)
937254721Semaste                        {
938254721Semaste                            value_sp = expr_var_sp->GetValueObject();
939254721Semaste                            sb_value.SetSP (value_sp, use_dynamic);
940254721Semaste                        }
941254721Semaste                    }
942254721Semaste                    break;
943254721Semaste
944254721Semaste                default:
945254721Semaste                    break;
946254721Semaste                }
947254721Semaste            }
948254721Semaste            else
949254721Semaste            {
950254721Semaste                if (log)
951254721Semaste                    log->Printf ("SBFrame::FindValue () => error: could not reconstruct frame object for this SBFrame.");
952254721Semaste            }
953254721Semaste        }
954254721Semaste        else
955254721Semaste        {
956254721Semaste            if (log)
957254721Semaste                log->Printf ("SBFrame::FindValue () => error: process is running");
958254721Semaste        }
959254721Semaste    }
960254721Semaste
961254721Semaste    if (log)
962254721Semaste        log->Printf ("SBFrame(%p)::FindVariableInScope (name=\"%s\", value_type=%i) => SBValue(%p)",
963254721Semaste                     frame, name, value_type, value_sp.get());
964254721Semaste
965254721Semaste
966254721Semaste    return sb_value;
967254721Semaste}
968254721Semaste
969254721Semastebool
970254721SemasteSBFrame::IsEqual (const SBFrame &that) const
971254721Semaste{
972254721Semaste    lldb::StackFrameSP this_sp = GetFrameSP();
973254721Semaste    lldb::StackFrameSP that_sp = that.GetFrameSP();
974254721Semaste    return (this_sp && that_sp && this_sp->GetStackID() == that_sp->GetStackID());
975254721Semaste}
976254721Semaste
977254721Semastebool
978254721SemasteSBFrame::operator == (const SBFrame &rhs) const
979254721Semaste{
980254721Semaste    return IsEqual(rhs);
981254721Semaste}
982254721Semaste
983254721Semastebool
984254721SemasteSBFrame::operator != (const SBFrame &rhs) const
985254721Semaste{
986254721Semaste    return !IsEqual(rhs);
987254721Semaste}
988254721Semaste
989254721SemasteSBThread
990254721SemasteSBFrame::GetThread () const
991254721Semaste{
992254721Semaste    Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
993254721Semaste
994254721Semaste    ExecutionContext exe_ctx(m_opaque_sp.get());
995254721Semaste    ThreadSP thread_sp (exe_ctx.GetThreadSP());
996254721Semaste    SBThread sb_thread (thread_sp);
997254721Semaste
998254721Semaste    if (log)
999254721Semaste    {
1000254721Semaste        SBStream sstr;
1001254721Semaste        sb_thread.GetDescription (sstr);
1002254721Semaste        log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s",
1003254721Semaste                     exe_ctx.GetFramePtr(),
1004254721Semaste                     thread_sp.get(),
1005254721Semaste                     sstr.GetData());
1006254721Semaste    }
1007254721Semaste
1008254721Semaste    return sb_thread;
1009254721Semaste}
1010254721Semaste
1011254721Semasteconst char *
1012254721SemasteSBFrame::Disassemble () const
1013254721Semaste{
1014254721Semaste    Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1015254721Semaste    const char *disassembly = NULL;
1016254721Semaste    Mutex::Locker api_locker;
1017254721Semaste    ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1018254721Semaste
1019254721Semaste    StackFrame *frame = NULL;
1020254721Semaste    Target *target = exe_ctx.GetTargetPtr();
1021254721Semaste    Process *process = exe_ctx.GetProcessPtr();
1022254721Semaste    if (target && process)
1023254721Semaste    {
1024254721Semaste        Process::StopLocker stop_locker;
1025254721Semaste        if (stop_locker.TryLock(&process->GetRunLock()))
1026254721Semaste        {
1027254721Semaste            frame = exe_ctx.GetFramePtr();
1028254721Semaste            if (frame)
1029254721Semaste            {
1030254721Semaste                disassembly = frame->Disassemble();
1031254721Semaste            }
1032254721Semaste            else
1033254721Semaste            {
1034254721Semaste                if (log)
1035254721Semaste                    log->Printf ("SBFrame::Disassemble () => error: could not reconstruct frame object for this SBFrame.");
1036254721Semaste            }
1037254721Semaste        }
1038254721Semaste        else
1039254721Semaste        {
1040254721Semaste            if (log)
1041254721Semaste                log->Printf ("SBFrame::Disassemble () => error: process is running");
1042254721Semaste        }
1043254721Semaste    }
1044254721Semaste
1045254721Semaste    if (log)
1046254721Semaste        log->Printf ("SBFrame(%p)::Disassemble () => %s", frame, disassembly);
1047254721Semaste
1048254721Semaste    return disassembly;
1049254721Semaste}
1050254721Semaste
1051254721Semaste
1052254721SemasteSBValueList
1053254721SemasteSBFrame::GetVariables (bool arguments,
1054254721Semaste                       bool locals,
1055254721Semaste                       bool statics,
1056254721Semaste                       bool in_scope_only)
1057254721Semaste{
1058254721Semaste    SBValueList value_list;
1059254721Semaste    ExecutionContext exe_ctx(m_opaque_sp.get());
1060254721Semaste    StackFrame *frame = exe_ctx.GetFramePtr();
1061254721Semaste    Target *target = exe_ctx.GetTargetPtr();
1062254721Semaste    if (frame && target)
1063254721Semaste    {
1064254721Semaste        lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
1065254721Semaste        value_list = GetVariables (arguments, locals, statics, in_scope_only, use_dynamic);
1066254721Semaste    }
1067254721Semaste    return value_list;
1068254721Semaste}
1069254721Semaste
1070254721SemasteSBValueList
1071254721SemasteSBFrame::GetVariables (bool arguments,
1072254721Semaste                       bool locals,
1073254721Semaste                       bool statics,
1074254721Semaste                       bool in_scope_only,
1075254721Semaste                       lldb::DynamicValueType  use_dynamic)
1076254721Semaste{
1077254721Semaste    Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1078254721Semaste
1079254721Semaste    SBValueList value_list;
1080254721Semaste    Mutex::Locker api_locker;
1081254721Semaste    ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1082254721Semaste
1083254721Semaste    StackFrame *frame = NULL;
1084254721Semaste    Target *target = exe_ctx.GetTargetPtr();
1085254721Semaste
1086254721Semaste    if (log)
1087254721Semaste        log->Printf ("SBFrame::GetVariables (arguments=%i, locals=%i, statics=%i, in_scope_only=%i)",
1088254721Semaste                     arguments,
1089254721Semaste                     locals,
1090254721Semaste                     statics,
1091254721Semaste                     in_scope_only);
1092254721Semaste
1093254721Semaste    Process *process = exe_ctx.GetProcessPtr();
1094254721Semaste    if (target && process)
1095254721Semaste    {
1096254721Semaste        Process::StopLocker stop_locker;
1097254721Semaste        if (stop_locker.TryLock(&process->GetRunLock()))
1098254721Semaste        {
1099254721Semaste            frame = exe_ctx.GetFramePtr();
1100254721Semaste            if (frame)
1101254721Semaste            {
1102254721Semaste                size_t i;
1103254721Semaste                VariableList *variable_list = NULL;
1104254721Semaste                variable_list = frame->GetVariableList(true);
1105254721Semaste                if (variable_list)
1106254721Semaste                {
1107254721Semaste                    const size_t num_variables = variable_list->GetSize();
1108254721Semaste                    if (num_variables)
1109254721Semaste                    {
1110254721Semaste                        for (i = 0; i < num_variables; ++i)
1111254721Semaste                        {
1112254721Semaste                            VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
1113254721Semaste                            if (variable_sp)
1114254721Semaste                            {
1115254721Semaste                                bool add_variable = false;
1116254721Semaste                                switch (variable_sp->GetScope())
1117254721Semaste                                {
1118254721Semaste                                case eValueTypeVariableGlobal:
1119254721Semaste                                case eValueTypeVariableStatic:
1120254721Semaste                                    add_variable = statics;
1121254721Semaste                                    break;
1122254721Semaste
1123254721Semaste                                case eValueTypeVariableArgument:
1124254721Semaste                                    add_variable = arguments;
1125254721Semaste                                    break;
1126254721Semaste
1127254721Semaste                                case eValueTypeVariableLocal:
1128254721Semaste                                    add_variable = locals;
1129254721Semaste                                    break;
1130254721Semaste
1131254721Semaste                                default:
1132254721Semaste                                    break;
1133254721Semaste                                }
1134254721Semaste                                if (add_variable)
1135254721Semaste                                {
1136254721Semaste                                    if (in_scope_only && !variable_sp->IsInScope(frame))
1137254721Semaste                                        continue;
1138254721Semaste
1139254721Semaste                                    ValueObjectSP valobj_sp(frame->GetValueObjectForFrameVariable (variable_sp, eNoDynamicValues));
1140254721Semaste                                    SBValue value_sb;
1141254721Semaste                                    value_sb.SetSP(valobj_sp,use_dynamic);
1142254721Semaste                                    value_list.Append(value_sb);
1143254721Semaste                                }
1144254721Semaste                            }
1145254721Semaste                        }
1146254721Semaste                    }
1147254721Semaste                }
1148254721Semaste            }
1149254721Semaste            else
1150254721Semaste            {
1151254721Semaste                if (log)
1152254721Semaste                    log->Printf ("SBFrame::GetVariables () => error: could not reconstruct frame object for this SBFrame.");
1153254721Semaste            }
1154254721Semaste        }
1155254721Semaste        else
1156254721Semaste        {
1157254721Semaste            if (log)
1158254721Semaste                log->Printf ("SBFrame::GetVariables () => error: process is running");
1159254721Semaste        }
1160254721Semaste    }
1161254721Semaste
1162254721Semaste    if (log)
1163254721Semaste    {
1164254721Semaste        log->Printf ("SBFrame(%p)::GetVariables (...) => SBValueList(%p)", frame, value_list.opaque_ptr());
1165254721Semaste    }
1166254721Semaste
1167254721Semaste    return value_list;
1168254721Semaste}
1169254721Semaste
1170254721SemasteSBValueList
1171254721SemasteSBFrame::GetRegisters ()
1172254721Semaste{
1173254721Semaste    Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1174254721Semaste
1175254721Semaste    SBValueList value_list;
1176254721Semaste    Mutex::Locker api_locker;
1177254721Semaste    ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1178254721Semaste
1179254721Semaste    StackFrame *frame = NULL;
1180254721Semaste    Target *target = exe_ctx.GetTargetPtr();
1181254721Semaste    Process *process = exe_ctx.GetProcessPtr();
1182254721Semaste    if (target && process)
1183254721Semaste    {
1184254721Semaste        Process::StopLocker stop_locker;
1185254721Semaste        if (stop_locker.TryLock(&process->GetRunLock()))
1186254721Semaste        {
1187254721Semaste            frame = exe_ctx.GetFramePtr();
1188254721Semaste            if (frame)
1189254721Semaste            {
1190254721Semaste                RegisterContextSP reg_ctx (frame->GetRegisterContext());
1191254721Semaste                if (reg_ctx)
1192254721Semaste                {
1193254721Semaste                    const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
1194254721Semaste                    for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
1195254721Semaste                    {
1196254721Semaste                        value_list.Append(ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx));
1197254721Semaste                    }
1198254721Semaste                }
1199254721Semaste            }
1200254721Semaste            else
1201254721Semaste            {
1202254721Semaste                if (log)
1203254721Semaste                    log->Printf ("SBFrame::GetRegisters () => error: could not reconstruct frame object for this SBFrame.");
1204254721Semaste            }
1205254721Semaste        }
1206254721Semaste        else
1207254721Semaste        {
1208254721Semaste            if (log)
1209254721Semaste                log->Printf ("SBFrame::GetRegisters () => error: process is running");
1210254721Semaste        }
1211254721Semaste    }
1212254721Semaste
1213254721Semaste    if (log)
1214254721Semaste        log->Printf ("SBFrame(%p)::GetRegisters () => SBValueList(%p)", frame, value_list.opaque_ptr());
1215254721Semaste
1216254721Semaste    return value_list;
1217254721Semaste}
1218254721Semaste
1219254721SemasteSBValue
1220254721SemasteSBFrame::FindRegister (const char *name)
1221254721Semaste{
1222254721Semaste    Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1223254721Semaste
1224254721Semaste    SBValue result;
1225254721Semaste    ValueObjectSP value_sp;
1226254721Semaste    Mutex::Locker api_locker;
1227254721Semaste    ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1228254721Semaste
1229254721Semaste    StackFrame *frame = NULL;
1230254721Semaste    Target *target = exe_ctx.GetTargetPtr();
1231254721Semaste    Process *process = exe_ctx.GetProcessPtr();
1232254721Semaste    if (target && process)
1233254721Semaste    {
1234254721Semaste        Process::StopLocker stop_locker;
1235254721Semaste        if (stop_locker.TryLock(&process->GetRunLock()))
1236254721Semaste        {
1237254721Semaste            frame = exe_ctx.GetFramePtr();
1238254721Semaste            if (frame)
1239254721Semaste            {
1240254721Semaste                RegisterContextSP reg_ctx (frame->GetRegisterContext());
1241254721Semaste                if (reg_ctx)
1242254721Semaste                {
1243254721Semaste                    const uint32_t num_regs = reg_ctx->GetRegisterCount();
1244254721Semaste                    for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx)
1245254721Semaste                    {
1246254721Semaste                        const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
1247254721Semaste                        if (reg_info &&
1248254721Semaste                            ((reg_info->name && strcasecmp (reg_info->name, name) == 0) ||
1249254721Semaste                             (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0)))
1250254721Semaste                        {
1251254721Semaste                            value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx);
1252254721Semaste                            result.SetSP (value_sp);
1253254721Semaste                            break;
1254254721Semaste                        }
1255254721Semaste                    }
1256254721Semaste                }
1257254721Semaste            }
1258254721Semaste            else
1259254721Semaste            {
1260254721Semaste                if (log)
1261254721Semaste                    log->Printf ("SBFrame::FindRegister () => error: could not reconstruct frame object for this SBFrame.");
1262254721Semaste            }
1263254721Semaste        }
1264254721Semaste        else
1265254721Semaste        {
1266254721Semaste            if (log)
1267254721Semaste                log->Printf ("SBFrame::FindRegister () => error: process is running");
1268254721Semaste        }
1269254721Semaste    }
1270254721Semaste
1271254721Semaste    if (log)
1272254721Semaste        log->Printf ("SBFrame(%p)::FindRegister () => SBValue(%p)", frame, value_sp.get());
1273254721Semaste
1274254721Semaste    return result;
1275254721Semaste}
1276254721Semaste
1277254721Semastebool
1278254721SemasteSBFrame::GetDescription (SBStream &description)
1279254721Semaste{
1280254721Semaste    Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1281254721Semaste    Stream &strm = description.ref();
1282254721Semaste
1283254721Semaste    Mutex::Locker api_locker;
1284254721Semaste    ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1285254721Semaste
1286254721Semaste    StackFrame *frame;
1287254721Semaste    Target *target = exe_ctx.GetTargetPtr();
1288254721Semaste    Process *process = exe_ctx.GetProcessPtr();
1289254721Semaste    if (target && process)
1290254721Semaste    {
1291254721Semaste        Process::StopLocker stop_locker;
1292254721Semaste        if (stop_locker.TryLock(&process->GetRunLock()))
1293254721Semaste        {
1294254721Semaste            frame = exe_ctx.GetFramePtr();
1295254721Semaste            if (frame)
1296254721Semaste            {
1297254721Semaste                frame->DumpUsingSettingsFormat (&strm);
1298254721Semaste            }
1299254721Semaste            else
1300254721Semaste            {
1301254721Semaste                if (log)
1302254721Semaste                    log->Printf ("SBFrame::GetDescription () => error: could not reconstruct frame object for this SBFrame.");
1303254721Semaste            }
1304254721Semaste        }
1305254721Semaste        else
1306254721Semaste        {
1307254721Semaste            if (log)
1308254721Semaste                log->Printf ("SBFrame::GetDescription () => error: process is running");
1309254721Semaste        }
1310254721Semaste
1311254721Semaste    }
1312254721Semaste    else
1313254721Semaste        strm.PutCString ("No value");
1314254721Semaste
1315254721Semaste    return true;
1316254721Semaste}
1317254721Semaste
1318254721SemasteSBValue
1319254721SemasteSBFrame::EvaluateExpression (const char *expr)
1320254721Semaste{
1321254721Semaste    SBValue result;
1322254721Semaste    ExecutionContext exe_ctx(m_opaque_sp.get());
1323254721Semaste    StackFrame *frame = exe_ctx.GetFramePtr();
1324254721Semaste    Target *target = exe_ctx.GetTargetPtr();
1325254721Semaste    if (frame && target)
1326254721Semaste    {
1327254721Semaste        SBExpressionOptions options;
1328254721Semaste        lldb::DynamicValueType fetch_dynamic_value = frame->CalculateTarget()->GetPreferDynamicValue();
1329254721Semaste        options.SetFetchDynamicValue (fetch_dynamic_value);
1330254721Semaste        options.SetUnwindOnError (true);
1331254721Semaste        return EvaluateExpression (expr, options);
1332254721Semaste    }
1333254721Semaste    return result;
1334254721Semaste}
1335254721Semaste
1336254721SemasteSBValue
1337254721SemasteSBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value)
1338254721Semaste{
1339254721Semaste    SBExpressionOptions options;
1340254721Semaste    options.SetFetchDynamicValue (fetch_dynamic_value);
1341254721Semaste    options.SetUnwindOnError (true);
1342254721Semaste    return EvaluateExpression (expr, options);
1343254721Semaste}
1344254721Semaste
1345254721SemasteSBValue
1346254721SemasteSBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value, bool unwind_on_error)
1347254721Semaste{
1348254721Semaste    SBExpressionOptions options;
1349254721Semaste    options.SetFetchDynamicValue (fetch_dynamic_value);
1350254721Semaste    options.SetUnwindOnError (unwind_on_error);
1351254721Semaste    return EvaluateExpression (expr, options);
1352254721Semaste}
1353254721Semaste
1354254721Semastelldb::SBValue
1355254721SemasteSBFrame::EvaluateExpression (const char *expr, const SBExpressionOptions &options)
1356254721Semaste{
1357254721Semaste    Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1358254721Semaste
1359254721Semaste    Log *expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
1360254721Semaste
1361254721Semaste    ExecutionResults exe_results = eExecutionSetupError;
1362254721Semaste    SBValue expr_result;
1363254721Semaste
1364254721Semaste    if (expr == NULL || expr[0] == '\0')
1365254721Semaste    {
1366254721Semaste        if (log)
1367254721Semaste            log->Printf ("SBFrame::EvaluateExpression called with an empty expression");
1368254721Semaste        return expr_result;
1369254721Semaste    }
1370254721Semaste
1371254721Semaste    ValueObjectSP expr_value_sp;
1372254721Semaste
1373254721Semaste    Mutex::Locker api_locker;
1374254721Semaste    ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1375254721Semaste
1376254721Semaste    if (log)
1377254721Semaste        log->Printf ("SBFrame()::EvaluateExpression (expr=\"%s\")...", expr);
1378254721Semaste
1379254721Semaste    StackFrame *frame = NULL;
1380254721Semaste    Target *target = exe_ctx.GetTargetPtr();
1381254721Semaste    Process *process = exe_ctx.GetProcessPtr();
1382254721Semaste
1383254721Semaste    if (target && process)
1384254721Semaste    {
1385254721Semaste        Process::StopLocker stop_locker;
1386254721Semaste        if (stop_locker.TryLock(&process->GetRunLock()))
1387254721Semaste        {
1388254721Semaste            frame = exe_ctx.GetFramePtr();
1389254721Semaste            if (frame)
1390254721Semaste            {
1391269024Semaste                if (target->GetDisplayExpressionsInCrashlogs())
1392269024Semaste                {
1393269024Semaste                    StreamString frame_description;
1394269024Semaste                    frame->DumpUsingSettingsFormat (&frame_description);
1395269024Semaste                    Host::SetCrashDescriptionWithFormat ("SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
1396269024Semaste                                                         expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str());
1397269024Semaste                }
1398269024Semaste
1399269024Semaste                exe_results = target->EvaluateExpression (expr,
1400254721Semaste                                                          frame,
1401254721Semaste                                                          expr_value_sp,
1402254721Semaste                                                          options.ref());
1403254721Semaste                expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
1404269024Semaste
1405269024Semaste                if (target->GetDisplayExpressionsInCrashlogs())
1406269024Semaste                    Host::SetCrashDescription (NULL);
1407254721Semaste            }
1408254721Semaste            else
1409254721Semaste            {
1410254721Semaste                if (log)
1411254721Semaste                    log->Printf ("SBFrame::EvaluateExpression () => error: could not reconstruct frame object for this SBFrame.");
1412254721Semaste            }
1413254721Semaste        }
1414254721Semaste        else
1415254721Semaste        {
1416254721Semaste            if (log)
1417254721Semaste                log->Printf ("SBFrame::EvaluateExpression () => error: process is running");
1418254721Semaste        }
1419254721Semaste    }
1420254721Semaste
1421254721Semaste#ifndef LLDB_DISABLE_PYTHON
1422254721Semaste    if (expr_log)
1423254721Semaste        expr_log->Printf("** [SBFrame::EvaluateExpression] Expression result is %s, summary %s **",
1424254721Semaste                         expr_result.GetValue(),
1425254721Semaste                         expr_result.GetSummary());
1426254721Semaste
1427254721Semaste    if (log)
1428254721Semaste        log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)",
1429254721Semaste                     frame,
1430254721Semaste                     expr,
1431254721Semaste                     expr_value_sp.get(),
1432254721Semaste                     exe_results);
1433254721Semaste#endif
1434254721Semaste
1435254721Semaste    return expr_result;
1436254721Semaste}
1437254721Semaste
1438254721Semastebool
1439254721SemasteSBFrame::IsInlined()
1440254721Semaste{
1441254721Semaste    Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1442254721Semaste    ExecutionContext exe_ctx(m_opaque_sp.get());
1443254721Semaste    StackFrame *frame = NULL;
1444254721Semaste    Target *target = exe_ctx.GetTargetPtr();
1445254721Semaste    Process *process = exe_ctx.GetProcessPtr();
1446254721Semaste    if (target && process)
1447254721Semaste    {
1448254721Semaste        Process::StopLocker stop_locker;
1449254721Semaste        if (stop_locker.TryLock(&process->GetRunLock()))
1450254721Semaste        {
1451254721Semaste            frame = exe_ctx.GetFramePtr();
1452254721Semaste            if (frame)
1453254721Semaste            {
1454254721Semaste
1455254721Semaste                Block *block = frame->GetSymbolContext(eSymbolContextBlock).block;
1456254721Semaste                if (block)
1457254721Semaste                    return block->GetContainingInlinedBlock () != NULL;
1458254721Semaste            }
1459254721Semaste            else
1460254721Semaste            {
1461254721Semaste                if (log)
1462254721Semaste                    log->Printf ("SBFrame::IsInlined () => error: could not reconstruct frame object for this SBFrame.");
1463254721Semaste            }
1464254721Semaste        }
1465254721Semaste        else
1466254721Semaste        {
1467254721Semaste            if (log)
1468254721Semaste                log->Printf ("SBFrame::IsInlined () => error: process is running");
1469254721Semaste        }
1470254721Semaste
1471254721Semaste    }
1472254721Semaste    return false;
1473254721Semaste}
1474254721Semaste
1475254721Semasteconst char *
1476254721SemasteSBFrame::GetFunctionName()
1477254721Semaste{
1478254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1479254721Semaste    const char *name = NULL;
1480254721Semaste    ExecutionContext exe_ctx(m_opaque_sp.get());
1481254721Semaste    StackFrame *frame = NULL;
1482254721Semaste    Target *target = exe_ctx.GetTargetPtr();
1483254721Semaste    Process *process = exe_ctx.GetProcessPtr();
1484254721Semaste    if (target && process)
1485254721Semaste    {
1486254721Semaste        Process::StopLocker stop_locker;
1487254721Semaste        if (stop_locker.TryLock(&process->GetRunLock()))
1488254721Semaste        {
1489254721Semaste            frame = exe_ctx.GetFramePtr();
1490254721Semaste            if (frame)
1491254721Semaste            {
1492254721Semaste                SymbolContext sc (frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol));
1493254721Semaste                if (sc.block)
1494254721Semaste                {
1495254721Semaste                    Block *inlined_block = sc.block->GetContainingInlinedBlock ();
1496254721Semaste                    if (inlined_block)
1497254721Semaste                    {
1498254721Semaste                        const InlineFunctionInfo* inlined_info = inlined_block->GetInlinedFunctionInfo();
1499254721Semaste                        name = inlined_info->GetName().AsCString();
1500254721Semaste                    }
1501254721Semaste                }
1502254721Semaste
1503254721Semaste                if (name == NULL)
1504254721Semaste                {
1505254721Semaste                    if (sc.function)
1506254721Semaste                        name = sc.function->GetName().GetCString();
1507254721Semaste                }
1508254721Semaste
1509254721Semaste                if (name == NULL)
1510254721Semaste                {
1511254721Semaste                    if (sc.symbol)
1512254721Semaste                        name = sc.symbol->GetName().GetCString();
1513254721Semaste                }
1514254721Semaste            }
1515254721Semaste            else
1516254721Semaste            {
1517254721Semaste                if (log)
1518254721Semaste                    log->Printf ("SBFrame::GetFunctionName () => error: could not reconstruct frame object for this SBFrame.");
1519254721Semaste            }
1520254721Semaste        }
1521254721Semaste        else
1522254721Semaste        {
1523254721Semaste            if (log)
1524254721Semaste                log->Printf ("SBFrame::GetFunctionName() => error: process is running");
1525254721Semaste
1526254721Semaste        }
1527254721Semaste    }
1528254721Semaste    return name;
1529254721Semaste}
1530254721Semaste
1531