1 //===-- SBFrame.cpp ---------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // C Includes
11 // C++ Includes
12 #include <algorithm>
13 #include <set>
14 #include <string>
15 
16 // Other libraries and framework includes
17 // Project includes
18 #include "lldb/API/SBFrame.h"
19 
20 #include "lldb/lldb-types.h"
21 
22 #include "lldb/Core/Address.h"
23 #include "lldb/Core/ConstString.h"
24 #include "lldb/Core/Log.h"
25 #include "lldb/Core/Stream.h"
26 #include "lldb/Core/StreamFile.h"
27 #include "lldb/Core/ValueObjectRegister.h"
28 #include "lldb/Core/ValueObjectVariable.h"
29 #include "Plugins/ExpressionParser/Clang/ClangPersistentVariables.h"
30 #include "lldb/Expression/UserExpression.h"
31 #include "lldb/Host/Host.h"
32 #include "lldb/Symbol/Block.h"
33 #include "lldb/Symbol/Function.h"
34 #include "lldb/Symbol/Symbol.h"
35 #include "lldb/Symbol/SymbolContext.h"
36 #include "lldb/Symbol/VariableList.h"
37 #include "lldb/Symbol/Variable.h"
38 #include "lldb/Target/ExecutionContext.h"
39 #include "lldb/Target/Target.h"
40 #include "lldb/Target/Process.h"
41 #include "lldb/Target/RegisterContext.h"
42 #include "lldb/Target/StackFrame.h"
43 #include "lldb/Target/StackID.h"
44 #include "lldb/Target/Thread.h"
45 
46 #include "lldb/API/SBDebugger.h"
47 #include "lldb/API/SBValue.h"
48 #include "lldb/API/SBAddress.h"
49 #include "lldb/API/SBExpressionOptions.h"
50 #include "lldb/API/SBStream.h"
51 #include "lldb/API/SBSymbolContext.h"
52 #include "lldb/API/SBThread.h"
53 #include "lldb/API/SBVariablesOptions.h"
54 
55 using namespace lldb;
56 using namespace lldb_private;
57 
58 SBFrame::SBFrame () :
59     m_opaque_sp (new ExecutionContextRef())
60 {
61 }
62 
63 SBFrame::SBFrame (const StackFrameSP &lldb_object_sp) :
64     m_opaque_sp (new ExecutionContextRef (lldb_object_sp))
65 {
66     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
67 
68     if (log)
69     {
70         SBStream sstr;
71         GetDescription (sstr);
72         log->Printf ("SBFrame::SBFrame (sp=%p) => SBFrame(%p): %s",
73                      static_cast<void*>(lldb_object_sp.get()),
74                      static_cast<void*>(lldb_object_sp.get()), sstr.GetData());
75     }
76 }
77 
78 SBFrame::SBFrame(const SBFrame &rhs) :
79     m_opaque_sp (new ExecutionContextRef (*rhs.m_opaque_sp))
80 {
81 }
82 
83 SBFrame::~SBFrame() = default;
84 
85 const SBFrame &
86 SBFrame::operator = (const SBFrame &rhs)
87 {
88     if (this != &rhs)
89         *m_opaque_sp = *rhs.m_opaque_sp;
90     return *this;
91 }
92 
93 StackFrameSP
94 SBFrame::GetFrameSP() const
95 {
96     return (m_opaque_sp ? m_opaque_sp->GetFrameSP() : StackFrameSP());
97 }
98 
99 void
100 SBFrame::SetFrameSP (const StackFrameSP &lldb_object_sp)
101 {
102     return m_opaque_sp->SetFrameSP(lldb_object_sp);
103 }
104 
105 bool
106 SBFrame::IsValid() const
107 {
108     return GetFrameSP().get() != nullptr;
109 }
110 
111 SBSymbolContext
112 SBFrame::GetSymbolContext (uint32_t resolve_scope) const
113 {
114     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
115     SBSymbolContext sb_sym_ctx;
116     Mutex::Locker api_locker;
117     ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
118 
119     StackFrame *frame = nullptr;
120     Target *target = exe_ctx.GetTargetPtr();
121     Process *process = exe_ctx.GetProcessPtr();
122     if (target && process)
123     {
124         Process::StopLocker stop_locker;
125         if (stop_locker.TryLock(&process->GetRunLock()))
126         {
127             frame = exe_ctx.GetFramePtr();
128             if (frame)
129             {
130                 sb_sym_ctx.SetSymbolContext(&frame->GetSymbolContext (resolve_scope));
131             }
132             else
133             {
134                 if (log)
135                     log->Printf ("SBFrame::GetVariables () => error: could not reconstruct frame object for this SBFrame.");
136             }
137         }
138         else
139         {
140             if (log)
141                 log->Printf ("SBFrame::GetSymbolContext () => error: process is running");
142         }
143     }
144 
145     if (log)
146         log->Printf ("SBFrame(%p)::GetSymbolContext (resolve_scope=0x%8.8x) => SBSymbolContext(%p)",
147                      static_cast<void*>(frame), resolve_scope,
148                      static_cast<void*>(sb_sym_ctx.get()));
149 
150     return sb_sym_ctx;
151 }
152 
153 SBModule
154 SBFrame::GetModule () const
155 {
156     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
157     SBModule sb_module;
158     ModuleSP module_sp;
159     Mutex::Locker api_locker;
160     ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
161 
162     StackFrame *frame = nullptr;
163     Target *target = exe_ctx.GetTargetPtr();
164     Process *process = exe_ctx.GetProcessPtr();
165     if (target && process)
166     {
167         Process::StopLocker stop_locker;
168         if (stop_locker.TryLock(&process->GetRunLock()))
169         {
170             frame = exe_ctx.GetFramePtr();
171             if (frame)
172             {
173                 module_sp = frame->GetSymbolContext (eSymbolContextModule).module_sp;
174                 sb_module.SetSP (module_sp);
175             }
176             else
177             {
178                 if (log)
179                     log->Printf ("SBFrame::GetModule () => error: could not reconstruct frame object for this SBFrame.");
180             }
181         }
182         else
183         {
184             if (log)
185                 log->Printf ("SBFrame::GetModule () => error: process is running");
186         }
187     }
188 
189     if (log)
190         log->Printf ("SBFrame(%p)::GetModule () => SBModule(%p)",
191                      static_cast<void*>(frame),
192                      static_cast<void*>(module_sp.get()));
193 
194     return sb_module;
195 }
196 
197 SBCompileUnit
198 SBFrame::GetCompileUnit () const
199 {
200     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
201     SBCompileUnit sb_comp_unit;
202     Mutex::Locker api_locker;
203     ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
204 
205     StackFrame *frame = nullptr;
206     Target *target = exe_ctx.GetTargetPtr();
207     Process *process = exe_ctx.GetProcessPtr();
208     if (target && process)
209     {
210         Process::StopLocker stop_locker;
211         if (stop_locker.TryLock(&process->GetRunLock()))
212         {
213             frame = exe_ctx.GetFramePtr();
214             if (frame)
215             {
216                 sb_comp_unit.reset (frame->GetSymbolContext (eSymbolContextCompUnit).comp_unit);
217             }
218             else
219             {
220                 if (log)
221                     log->Printf ("SBFrame::GetCompileUnit () => error: could not reconstruct frame object for this SBFrame.");
222             }
223         }
224         else
225         {
226             if (log)
227                 log->Printf ("SBFrame::GetCompileUnit () => error: process is running");
228         }
229     }
230     if (log)
231         log->Printf ("SBFrame(%p)::GetCompileUnit () => SBCompileUnit(%p)",
232                      static_cast<void*>(frame),
233                      static_cast<void*>(sb_comp_unit.get()));
234 
235     return sb_comp_unit;
236 }
237 
238 SBFunction
239 SBFrame::GetFunction () const
240 {
241     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
242     SBFunction sb_function;
243     Mutex::Locker api_locker;
244     ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
245 
246     StackFrame *frame = nullptr;
247     Target *target = exe_ctx.GetTargetPtr();
248     Process *process = exe_ctx.GetProcessPtr();
249     if (target && process)
250     {
251         Process::StopLocker stop_locker;
252         if (stop_locker.TryLock(&process->GetRunLock()))
253         {
254             frame = exe_ctx.GetFramePtr();
255             if (frame)
256             {
257                 sb_function.reset(frame->GetSymbolContext (eSymbolContextFunction).function);
258             }
259             else
260             {
261                 if (log)
262                     log->Printf ("SBFrame::GetFunction () => error: could not reconstruct frame object for this SBFrame.");
263             }
264         }
265         else
266         {
267             if (log)
268                 log->Printf ("SBFrame::GetFunction () => error: process is running");
269         }
270     }
271     if (log)
272         log->Printf ("SBFrame(%p)::GetFunction () => SBFunction(%p)",
273                      static_cast<void*>(frame),
274                      static_cast<void*>(sb_function.get()));
275 
276     return sb_function;
277 }
278 
279 SBSymbol
280 SBFrame::GetSymbol () const
281 {
282     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
283     SBSymbol sb_symbol;
284     Mutex::Locker api_locker;
285     ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
286 
287     StackFrame *frame = nullptr;
288     Target *target = exe_ctx.GetTargetPtr();
289     Process *process = exe_ctx.GetProcessPtr();
290     if (target && process)
291     {
292         Process::StopLocker stop_locker;
293         if (stop_locker.TryLock(&process->GetRunLock()))
294         {
295             frame = exe_ctx.GetFramePtr();
296             if (frame)
297             {
298                 sb_symbol.reset(frame->GetSymbolContext (eSymbolContextSymbol).symbol);
299             }
300             else
301             {
302                 if (log)
303                     log->Printf ("SBFrame::GetSymbol () => error: could not reconstruct frame object for this SBFrame.");
304             }
305         }
306         else
307         {
308             if (log)
309                 log->Printf ("SBFrame::GetSymbol () => error: process is running");
310         }
311     }
312     if (log)
313         log->Printf ("SBFrame(%p)::GetSymbol () => SBSymbol(%p)",
314                      static_cast<void*>(frame),
315                      static_cast<void*>(sb_symbol.get()));
316     return sb_symbol;
317 }
318 
319 SBBlock
320 SBFrame::GetBlock () const
321 {
322     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
323     SBBlock sb_block;
324     Mutex::Locker api_locker;
325     ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
326 
327     StackFrame *frame = nullptr;
328     Target *target = exe_ctx.GetTargetPtr();
329     Process *process = exe_ctx.GetProcessPtr();
330     if (target && process)
331     {
332         Process::StopLocker stop_locker;
333         if (stop_locker.TryLock(&process->GetRunLock()))
334         {
335             frame = exe_ctx.GetFramePtr();
336             if (frame)
337             {
338                 sb_block.SetPtr (frame->GetSymbolContext (eSymbolContextBlock).block);
339             }
340             else
341             {
342                 if (log)
343                     log->Printf ("SBFrame::GetBlock () => error: could not reconstruct frame object for this SBFrame.");
344             }
345         }
346         else
347         {
348             if (log)
349                 log->Printf ("SBFrame(%p)::GetBlock () => error: process is running",
350                              static_cast<void*>(frame));
351         }
352     }
353     if (log)
354         log->Printf ("SBFrame(%p)::GetBlock () => SBBlock(%p)",
355                      static_cast<void*>(frame),
356                      static_cast<void*>(sb_block.GetPtr()));
357     return sb_block;
358 }
359 
360 SBBlock
361 SBFrame::GetFrameBlock () const
362 {
363     SBBlock sb_block;
364     Mutex::Locker api_locker;
365     ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
366 
367     StackFrame *frame = nullptr;
368     Target *target = exe_ctx.GetTargetPtr();
369     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
370     Process *process = exe_ctx.GetProcessPtr();
371     if (target && process)
372     {
373         Process::StopLocker stop_locker;
374         if (stop_locker.TryLock(&process->GetRunLock()))
375         {
376             frame = exe_ctx.GetFramePtr();
377             if (frame)
378             {
379                 sb_block.SetPtr(frame->GetFrameBlock ());
380             }
381             else
382             {
383                 if (log)
384                     log->Printf ("SBFrame::GetFrameBlock () => error: could not reconstruct frame object for this SBFrame.");
385             }
386         }
387         else
388         {
389             if (log)
390                 log->Printf ("SBFrame::GetFrameBlock () => error: process is running");
391         }
392     }
393     if (log)
394         log->Printf ("SBFrame(%p)::GetFrameBlock () => SBBlock(%p)",
395                      static_cast<void*>(frame),
396                      static_cast<void*>(sb_block.GetPtr()));
397     return sb_block;
398 }
399 
400 SBLineEntry
401 SBFrame::GetLineEntry () const
402 {
403     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
404     SBLineEntry sb_line_entry;
405     Mutex::Locker api_locker;
406     ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
407 
408     StackFrame *frame = nullptr;
409     Target *target = exe_ctx.GetTargetPtr();
410     Process *process = exe_ctx.GetProcessPtr();
411     if (target && process)
412     {
413         Process::StopLocker stop_locker;
414         if (stop_locker.TryLock(&process->GetRunLock()))
415         {
416             frame = exe_ctx.GetFramePtr();
417             if (frame)
418             {
419                 sb_line_entry.SetLineEntry (frame->GetSymbolContext (eSymbolContextLineEntry).line_entry);
420             }
421             else
422             {
423                 if (log)
424                     log->Printf ("SBFrame::GetLineEntry () => error: could not reconstruct frame object for this SBFrame.");
425             }
426         }
427         else
428         {
429             if (log)
430                 log->Printf ("SBFrame::GetLineEntry () => error: process is running");
431         }
432     }
433     if (log)
434         log->Printf ("SBFrame(%p)::GetLineEntry () => SBLineEntry(%p)",
435                      static_cast<void*>(frame),
436                      static_cast<void*>(sb_line_entry.get()));
437     return sb_line_entry;
438 }
439 
440 uint32_t
441 SBFrame::GetFrameID () const
442 {
443     uint32_t frame_idx = UINT32_MAX;
444 
445     ExecutionContext exe_ctx(m_opaque_sp.get());
446     StackFrame *frame = exe_ctx.GetFramePtr();
447     if (frame)
448         frame_idx = frame->GetFrameIndex ();
449 
450     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
451     if (log)
452         log->Printf ("SBFrame(%p)::GetFrameID () => %u",
453                      static_cast<void*>(frame), frame_idx);
454     return frame_idx;
455 }
456 
457 lldb::addr_t
458 SBFrame::GetCFA () const
459 {
460     ExecutionContext exe_ctx(m_opaque_sp.get());
461     StackFrame *frame = exe_ctx.GetFramePtr();
462     if (frame)
463         return frame->GetStackID().GetCallFrameAddress();
464     return LLDB_INVALID_ADDRESS;
465 }
466 
467 addr_t
468 SBFrame::GetPC () const
469 {
470     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
471     addr_t addr = LLDB_INVALID_ADDRESS;
472     Mutex::Locker api_locker;
473     ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
474 
475     StackFrame *frame = nullptr;
476     Target *target = exe_ctx.GetTargetPtr();
477     Process *process = exe_ctx.GetProcessPtr();
478     if (target && process)
479     {
480         Process::StopLocker stop_locker;
481         if (stop_locker.TryLock(&process->GetRunLock()))
482         {
483             frame = exe_ctx.GetFramePtr();
484             if (frame)
485             {
486                 addr = frame->GetFrameCodeAddress().GetOpcodeLoadAddress (target, eAddressClassCode);
487             }
488             else
489             {
490                 if (log)
491                     log->Printf ("SBFrame::GetPC () => error: could not reconstruct frame object for this SBFrame.");
492             }
493         }
494         else
495         {
496             if (log)
497                 log->Printf ("SBFrame::GetPC () => error: process is running");
498         }
499     }
500 
501     if (log)
502         log->Printf ("SBFrame(%p)::GetPC () => 0x%" PRIx64,
503                      static_cast<void*>(frame), addr);
504 
505     return addr;
506 }
507 
508 bool
509 SBFrame::SetPC (addr_t new_pc)
510 {
511     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
512     bool ret_val = false;
513     Mutex::Locker api_locker;
514     ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
515 
516     StackFrame *frame = nullptr;
517     Target *target = exe_ctx.GetTargetPtr();
518     Process *process = exe_ctx.GetProcessPtr();
519     if (target && process)
520     {
521         Process::StopLocker stop_locker;
522         if (stop_locker.TryLock(&process->GetRunLock()))
523         {
524             frame = exe_ctx.GetFramePtr();
525             if (frame)
526             {
527                 ret_val = frame->GetRegisterContext()->SetPC (new_pc);
528             }
529             else
530             {
531                 if (log)
532                     log->Printf ("SBFrame::SetPC () => error: could not reconstruct frame object for this SBFrame.");
533             }
534         }
535         else
536         {
537             if (log)
538                 log->Printf ("SBFrame::SetPC () => error: process is running");
539         }
540     }
541 
542     if (log)
543         log->Printf ("SBFrame(%p)::SetPC (new_pc=0x%" PRIx64 ") => %i",
544                      static_cast<void*>(frame), new_pc, ret_val);
545 
546     return ret_val;
547 }
548 
549 addr_t
550 SBFrame::GetSP () const
551 {
552     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
553     addr_t addr = LLDB_INVALID_ADDRESS;
554     Mutex::Locker api_locker;
555     ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
556 
557     StackFrame *frame = nullptr;
558     Target *target = exe_ctx.GetTargetPtr();
559     Process *process = exe_ctx.GetProcessPtr();
560     if (target && process)
561     {
562         Process::StopLocker stop_locker;
563         if (stop_locker.TryLock(&process->GetRunLock()))
564         {
565             frame = exe_ctx.GetFramePtr();
566             if (frame)
567             {
568                 addr = frame->GetRegisterContext()->GetSP();
569             }
570             else
571             {
572                 if (log)
573                     log->Printf ("SBFrame::GetSP () => error: could not reconstruct frame object for this SBFrame.");
574             }
575         }
576         else
577         {
578             if (log)
579                 log->Printf ("SBFrame::GetSP () => error: process is running");
580         }
581     }
582     if (log)
583         log->Printf ("SBFrame(%p)::GetSP () => 0x%" PRIx64,
584                      static_cast<void*>(frame), addr);
585 
586     return addr;
587 }
588 
589 addr_t
590 SBFrame::GetFP () const
591 {
592     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
593     addr_t addr = LLDB_INVALID_ADDRESS;
594     Mutex::Locker api_locker;
595     ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
596 
597     StackFrame *frame = nullptr;
598     Target *target = exe_ctx.GetTargetPtr();
599     Process *process = exe_ctx.GetProcessPtr();
600     if (target && process)
601     {
602         Process::StopLocker stop_locker;
603         if (stop_locker.TryLock(&process->GetRunLock()))
604         {
605             frame = exe_ctx.GetFramePtr();
606             if (frame)
607             {
608                 addr = frame->GetRegisterContext()->GetFP();
609             }
610             else
611             {
612                 if (log)
613                     log->Printf ("SBFrame::GetFP () => error: could not reconstruct frame object for this SBFrame.");
614             }
615         }
616         else
617         {
618             if (log)
619                 log->Printf ("SBFrame::GetFP () => error: process is running");
620         }
621     }
622 
623     if (log)
624         log->Printf ("SBFrame(%p)::GetFP () => 0x%" PRIx64,
625                      static_cast<void*>(frame), addr);
626     return addr;
627 }
628 
629 SBAddress
630 SBFrame::GetPCAddress () const
631 {
632     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
633     SBAddress sb_addr;
634     Mutex::Locker api_locker;
635     ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
636 
637     StackFrame *frame = exe_ctx.GetFramePtr();
638     Target *target = exe_ctx.GetTargetPtr();
639     Process *process = exe_ctx.GetProcessPtr();
640     if (target && process)
641     {
642         Process::StopLocker stop_locker;
643         if (stop_locker.TryLock(&process->GetRunLock()))
644         {
645             frame = exe_ctx.GetFramePtr();
646             if (frame)
647             {
648                 sb_addr.SetAddress (&frame->GetFrameCodeAddress());
649             }
650             else
651             {
652                 if (log)
653                     log->Printf ("SBFrame::GetPCAddress () => error: could not reconstruct frame object for this SBFrame.");
654             }
655         }
656         else
657         {
658             if (log)
659                 log->Printf ("SBFrame::GetPCAddress () => error: process is running");
660         }
661     }
662     if (log)
663         log->Printf ("SBFrame(%p)::GetPCAddress () => SBAddress(%p)",
664                      static_cast<void*>(frame),
665                      static_cast<void*>(sb_addr.get()));
666     return sb_addr;
667 }
668 
669 void
670 SBFrame::Clear()
671 {
672     m_opaque_sp->Clear();
673 }
674 
675 lldb::SBValue
676 SBFrame::GetValueForVariablePath (const char *var_path)
677 {
678     SBValue sb_value;
679     ExecutionContext exe_ctx(m_opaque_sp.get());
680     StackFrame *frame = exe_ctx.GetFramePtr();
681     Target *target = exe_ctx.GetTargetPtr();
682     if (frame && target)
683     {
684         lldb::DynamicValueType  use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
685         sb_value = GetValueForVariablePath (var_path, use_dynamic);
686     }
687     return sb_value;
688 }
689 
690 lldb::SBValue
691 SBFrame::GetValueForVariablePath (const char *var_path, DynamicValueType use_dynamic)
692 {
693     SBValue sb_value;
694     Mutex::Locker api_locker;
695     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
696     if (var_path == nullptr || var_path[0] == '\0')
697     {
698         if (log)
699             log->Printf ("SBFrame::GetValueForVariablePath called with empty variable path.");
700         return sb_value;
701     }
702 
703     ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
704 
705     StackFrame *frame = nullptr;
706     Target *target = exe_ctx.GetTargetPtr();
707     Process *process = exe_ctx.GetProcessPtr();
708     if (target && process)
709     {
710         Process::StopLocker stop_locker;
711         if (stop_locker.TryLock(&process->GetRunLock()))
712         {
713             frame = exe_ctx.GetFramePtr();
714             if (frame)
715             {
716                 VariableSP var_sp;
717                 Error error;
718                 ValueObjectSP value_sp (frame->GetValueForVariableExpressionPath (var_path,
719                                                                                   eNoDynamicValues,
720                                                                                   StackFrame::eExpressionPathOptionCheckPtrVsMember | StackFrame::eExpressionPathOptionsAllowDirectIVarAccess,
721                                                                                   var_sp,
722                                                                                   error));
723                 sb_value.SetSP(value_sp, use_dynamic);
724             }
725             else
726             {
727                 if (log)
728                     log->Printf ("SBFrame::GetValueForVariablePath () => error: could not reconstruct frame object for this SBFrame.");
729             }
730         }
731         else
732         {
733             if (log)
734                 log->Printf ("SBFrame::GetValueForVariablePath () => error: process is running");
735         }
736     }
737     return sb_value;
738 }
739 
740 SBValue
741 SBFrame::FindVariable (const char *name)
742 {
743     SBValue value;
744     ExecutionContext exe_ctx(m_opaque_sp.get());
745     StackFrame *frame = exe_ctx.GetFramePtr();
746     Target *target = exe_ctx.GetTargetPtr();
747     if (frame && target)
748     {
749         lldb::DynamicValueType  use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
750         value = FindVariable (name, use_dynamic);
751     }
752     return value;
753 }
754 
755 SBValue
756 SBFrame::FindVariable (const char *name, lldb::DynamicValueType use_dynamic)
757 {
758     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
759     VariableSP var_sp;
760     SBValue sb_value;
761 
762     if (name == nullptr || name[0] == '\0')
763     {
764         if (log)
765             log->Printf ("SBFrame::FindVariable called with empty name");
766         return sb_value;
767     }
768 
769     ValueObjectSP value_sp;
770     Mutex::Locker api_locker;
771     ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
772 
773     StackFrame *frame = nullptr;
774     Target *target = exe_ctx.GetTargetPtr();
775     Process *process = exe_ctx.GetProcessPtr();
776     if (target && process)
777     {
778         Process::StopLocker stop_locker;
779         if (stop_locker.TryLock(&process->GetRunLock()))
780         {
781             frame = exe_ctx.GetFramePtr();
782             if (frame)
783             {
784                 VariableList variable_list;
785                 SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock));
786 
787                 if (sc.block)
788                 {
789                     const bool can_create = true;
790                     const bool get_parent_variables = true;
791                     const bool stop_if_block_is_inlined_function = true;
792 
793                     if (sc.block->AppendVariables (can_create,
794                                                    get_parent_variables,
795                                                    stop_if_block_is_inlined_function,
796                                                    [frame](Variable* v) { return v->IsInScope(frame); },
797                                                    &variable_list))
798                     {
799                         var_sp = variable_list.FindVariable (ConstString(name));
800                     }
801                 }
802 
803                 if (var_sp)
804                 {
805                     value_sp = frame->GetValueObjectForFrameVariable(var_sp, eNoDynamicValues);
806                     sb_value.SetSP(value_sp, use_dynamic);
807                 }
808             }
809             else
810             {
811                 if (log)
812                     log->Printf ("SBFrame::FindVariable () => error: could not reconstruct frame object for this SBFrame.");
813             }
814         }
815         else
816         {
817             if (log)
818                 log->Printf ("SBFrame::FindVariable () => error: process is running");
819         }
820     }
821 
822     if (log)
823         log->Printf ("SBFrame(%p)::FindVariable (name=\"%s\") => SBValue(%p)",
824                      static_cast<void*>(frame), name,
825                      static_cast<void*>(value_sp.get()));
826 
827     return sb_value;
828 }
829 
830 SBValue
831 SBFrame::FindValue (const char *name, ValueType value_type)
832 {
833     SBValue value;
834     ExecutionContext exe_ctx(m_opaque_sp.get());
835     StackFrame *frame = exe_ctx.GetFramePtr();
836     Target *target = exe_ctx.GetTargetPtr();
837     if (frame && target)
838     {
839         lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
840         value = FindValue (name, value_type, use_dynamic);
841     }
842     return value;
843 }
844 
845 SBValue
846 SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueType use_dynamic)
847 {
848     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
849     SBValue sb_value;
850 
851     if (name == nullptr || name[0] == '\0')
852     {
853         if (log)
854             log->Printf ("SBFrame::FindValue called with empty name.");
855         return sb_value;
856     }
857 
858     ValueObjectSP value_sp;
859     Mutex::Locker api_locker;
860     ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
861 
862     StackFrame *frame = nullptr;
863     Target *target = exe_ctx.GetTargetPtr();
864     Process *process = exe_ctx.GetProcessPtr();
865     if (target && process)
866     {
867         Process::StopLocker stop_locker;
868         if (stop_locker.TryLock(&process->GetRunLock()))
869         {
870             frame = exe_ctx.GetFramePtr();
871             if (frame)
872             {
873                 VariableList variable_list;
874 
875                 switch (value_type)
876                 {
877                 case eValueTypeVariableGlobal:      // global variable
878                 case eValueTypeVariableStatic:      // static variable
879                 case eValueTypeVariableArgument:    // function argument variables
880                 case eValueTypeVariableLocal:       // function local variables
881                     {
882                         SymbolContext sc(frame->GetSymbolContext(eSymbolContextBlock));
883 
884                         const bool can_create = true;
885                         const bool get_parent_variables = true;
886                         const bool stop_if_block_is_inlined_function = true;
887 
888                         if (sc.block)
889                             sc.block->AppendVariables(can_create,
890                                                       get_parent_variables,
891                                                       stop_if_block_is_inlined_function,
892                                                       [frame](Variable* v) { return v->IsInScope(frame); },
893                                                       &variable_list);
894                         if (value_type == eValueTypeVariableGlobal)
895                         {
896                             const bool get_file_globals = true;
897                             VariableList *frame_vars = frame->GetVariableList(get_file_globals);
898                             if (frame_vars)
899                                 frame_vars->AppendVariablesIfUnique(variable_list);
900                         }
901                         ConstString const_name(name);
902                         VariableSP variable_sp(variable_list.FindVariable(const_name, value_type));
903                         if (variable_sp)
904                         {
905                             value_sp = frame->GetValueObjectForFrameVariable(variable_sp, eNoDynamicValues);
906                             sb_value.SetSP(value_sp, use_dynamic);
907                         }
908                     }
909                     break;
910 
911                 case eValueTypeRegister:            // stack frame register value
912                     {
913                         RegisterContextSP reg_ctx (frame->GetRegisterContext());
914                         if (reg_ctx)
915                         {
916                             const uint32_t num_regs = reg_ctx->GetRegisterCount();
917                             for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx)
918                             {
919                                 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
920                                 if (reg_info &&
921                                     ((reg_info->name && strcasecmp (reg_info->name, name) == 0) ||
922                                      (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0)))
923                                 {
924                                     value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx);
925                                     sb_value.SetSP (value_sp);
926                                     break;
927                                 }
928                             }
929                         }
930                     }
931                     break;
932 
933                 case eValueTypeRegisterSet:         // A collection of stack frame register values
934                     {
935                         RegisterContextSP reg_ctx (frame->GetRegisterContext());
936                         if (reg_ctx)
937                         {
938                             const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
939                             for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
940                             {
941                                 const RegisterSet *reg_set = reg_ctx->GetRegisterSet (set_idx);
942                                 if (reg_set &&
943                                     ((reg_set->name && strcasecmp (reg_set->name, name) == 0) ||
944                                      (reg_set->short_name && strcasecmp (reg_set->short_name, name) == 0)))
945                                 {
946                                     value_sp = ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx);
947                                     sb_value.SetSP (value_sp);
948                                     break;
949                                 }
950                             }
951                         }
952                     }
953                     break;
954 
955                 case eValueTypeConstResult:         // constant result variables
956                     {
957                         ConstString const_name(name);
958                         ExpressionVariableSP expr_var_sp (target->GetPersistentVariable (const_name));
959                         if (expr_var_sp)
960                         {
961                             value_sp = expr_var_sp->GetValueObject();
962                             sb_value.SetSP (value_sp, use_dynamic);
963                         }
964                     }
965                     break;
966 
967                 default:
968                     break;
969                 }
970             }
971             else
972             {
973                 if (log)
974                     log->Printf ("SBFrame::FindValue () => error: could not reconstruct frame object for this SBFrame.");
975             }
976         }
977         else
978         {
979             if (log)
980                 log->Printf ("SBFrame::FindValue () => error: process is running");
981         }
982     }
983 
984     if (log)
985         log->Printf ("SBFrame(%p)::FindVariableInScope (name=\"%s\", value_type=%i) => SBValue(%p)",
986                      static_cast<void*>(frame), name, value_type,
987                      static_cast<void*>(value_sp.get()));
988 
989     return sb_value;
990 }
991 
992 bool
993 SBFrame::IsEqual (const SBFrame &that) const
994 {
995     lldb::StackFrameSP this_sp = GetFrameSP();
996     lldb::StackFrameSP that_sp = that.GetFrameSP();
997     return (this_sp && that_sp && this_sp->GetStackID() == that_sp->GetStackID());
998 }
999 
1000 bool
1001 SBFrame::operator == (const SBFrame &rhs) const
1002 {
1003     return IsEqual(rhs);
1004 }
1005 
1006 bool
1007 SBFrame::operator != (const SBFrame &rhs) const
1008 {
1009     return !IsEqual(rhs);
1010 }
1011 
1012 SBThread
1013 SBFrame::GetThread () const
1014 {
1015     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1016 
1017     ExecutionContext exe_ctx(m_opaque_sp.get());
1018     ThreadSP thread_sp (exe_ctx.GetThreadSP());
1019     SBThread sb_thread (thread_sp);
1020 
1021     if (log)
1022     {
1023         SBStream sstr;
1024         sb_thread.GetDescription (sstr);
1025         log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s",
1026                      static_cast<void*>(exe_ctx.GetFramePtr()),
1027                      static_cast<void*>(thread_sp.get()), sstr.GetData());
1028     }
1029 
1030     return sb_thread;
1031 }
1032 
1033 const char *
1034 SBFrame::Disassemble () const
1035 {
1036     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1037     const char *disassembly = nullptr;
1038     Mutex::Locker api_locker;
1039     ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1040 
1041     StackFrame *frame = nullptr;
1042     Target *target = exe_ctx.GetTargetPtr();
1043     Process *process = exe_ctx.GetProcessPtr();
1044     if (target && process)
1045     {
1046         Process::StopLocker stop_locker;
1047         if (stop_locker.TryLock(&process->GetRunLock()))
1048         {
1049             frame = exe_ctx.GetFramePtr();
1050             if (frame)
1051             {
1052                 disassembly = frame->Disassemble();
1053             }
1054             else
1055             {
1056                 if (log)
1057                     log->Printf ("SBFrame::Disassemble () => error: could not reconstruct frame object for this SBFrame.");
1058             }
1059         }
1060         else
1061         {
1062             if (log)
1063                 log->Printf ("SBFrame::Disassemble () => error: process is running");
1064         }
1065     }
1066 
1067     if (log)
1068         log->Printf ("SBFrame(%p)::Disassemble () => %s",
1069                      static_cast<void*>(frame), disassembly);
1070 
1071     return disassembly;
1072 }
1073 
1074 SBValueList
1075 SBFrame::GetVariables (bool arguments,
1076                        bool locals,
1077                        bool statics,
1078                        bool in_scope_only)
1079 {
1080     SBValueList value_list;
1081     ExecutionContext exe_ctx(m_opaque_sp.get());
1082     StackFrame *frame = exe_ctx.GetFramePtr();
1083     Target *target = exe_ctx.GetTargetPtr();
1084     if (frame && target)
1085     {
1086         lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
1087         const bool include_runtime_support_values = target ? target->GetDisplayRuntimeSupportValues() : false;
1088 
1089         SBVariablesOptions options;
1090         options.SetIncludeArguments(arguments);
1091         options.SetIncludeLocals(locals);
1092         options.SetIncludeStatics(statics);
1093         options.SetInScopeOnly(in_scope_only);
1094         options.SetIncludeRuntimeSupportValues(include_runtime_support_values);
1095         options.SetUseDynamic(use_dynamic);
1096 
1097         value_list = GetVariables (options);
1098     }
1099     return value_list;
1100 }
1101 
1102 lldb::SBValueList
1103 SBFrame::GetVariables (bool arguments,
1104                        bool locals,
1105                        bool statics,
1106                        bool in_scope_only,
1107                        lldb::DynamicValueType  use_dynamic)
1108 {
1109     ExecutionContext exe_ctx(m_opaque_sp.get());
1110     Target *target = exe_ctx.GetTargetPtr();
1111     const bool include_runtime_support_values = target ? target->GetDisplayRuntimeSupportValues() : false;
1112     SBVariablesOptions options;
1113     options.SetIncludeArguments(arguments);
1114     options.SetIncludeLocals(locals);
1115     options.SetIncludeStatics(statics);
1116     options.SetInScopeOnly(in_scope_only);
1117     options.SetIncludeRuntimeSupportValues(include_runtime_support_values);
1118     options.SetUseDynamic(use_dynamic);
1119     return GetVariables(options);
1120 }
1121 
1122 SBValueList
1123 SBFrame::GetVariables (const lldb::SBVariablesOptions& options)
1124 {
1125     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1126 
1127     SBValueList value_list;
1128     Mutex::Locker api_locker;
1129     ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1130 
1131     StackFrame *frame = nullptr;
1132     Target *target = exe_ctx.GetTargetPtr();
1133 
1134     const bool statics = options.GetIncludeStatics();
1135     const bool arguments = options.GetIncludeArguments();
1136     const bool locals = options.GetIncludeLocals();
1137     const bool in_scope_only = options.GetInScopeOnly();
1138     const bool include_runtime_support_values = options.GetIncludeRuntimeSupportValues();
1139     const lldb::DynamicValueType use_dynamic = options.GetUseDynamic();
1140 
1141     if (log)
1142         log->Printf ("SBFrame::GetVariables (arguments=%i, locals=%i, statics=%i, in_scope_only=%i runtime=%i dynamic=%i)",
1143                      arguments, locals,
1144                      statics, in_scope_only,
1145                      include_runtime_support_values, use_dynamic);
1146 
1147     std::set<VariableSP> variable_set;
1148     Process *process = exe_ctx.GetProcessPtr();
1149     if (target && process)
1150     {
1151         Process::StopLocker stop_locker;
1152         if (stop_locker.TryLock(&process->GetRunLock()))
1153         {
1154             frame = exe_ctx.GetFramePtr();
1155             if (frame)
1156             {
1157                 size_t i;
1158                 VariableList *variable_list = nullptr;
1159                 variable_list = frame->GetVariableList(true);
1160                 if (variable_list)
1161                 {
1162                     const size_t num_variables = variable_list->GetSize();
1163                     if (num_variables)
1164                     {
1165                         for (i = 0; i < num_variables; ++i)
1166                         {
1167                             VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
1168                             if (variable_sp)
1169                             {
1170                                 bool add_variable = false;
1171                                 switch (variable_sp->GetScope())
1172                                 {
1173                                 case eValueTypeVariableGlobal:
1174                                 case eValueTypeVariableStatic:
1175                                     add_variable = statics;
1176                                     break;
1177 
1178                                 case eValueTypeVariableArgument:
1179                                     add_variable = arguments;
1180                                     break;
1181 
1182                                 case eValueTypeVariableLocal:
1183                                     add_variable = locals;
1184                                     break;
1185 
1186                                 default:
1187                                     break;
1188                                 }
1189                                 if (add_variable)
1190                                 {
1191                                     // Only add variables once so we don't end up with duplicates
1192                                     if (variable_set.find(variable_sp) == variable_set.end())
1193                                         variable_set.insert(variable_sp);
1194                                     else
1195                                         continue;
1196 
1197                                     if (in_scope_only && !variable_sp->IsInScope(frame))
1198                                         continue;
1199 
1200                                     ValueObjectSP valobj_sp(frame->GetValueObjectForFrameVariable (variable_sp, eNoDynamicValues));
1201 
1202                                     if (!include_runtime_support_values &&
1203                                         valobj_sp != nullptr &&
1204                                         valobj_sp->IsRuntimeSupportValue())
1205                                         continue;
1206 
1207                                     SBValue value_sb;
1208                                     value_sb.SetSP(valobj_sp,use_dynamic);
1209                                     value_list.Append(value_sb);
1210                                 }
1211                             }
1212                         }
1213                     }
1214                 }
1215             }
1216             else
1217             {
1218                 if (log)
1219                     log->Printf ("SBFrame::GetVariables () => error: could not reconstruct frame object for this SBFrame.");
1220             }
1221         }
1222         else
1223         {
1224             if (log)
1225                 log->Printf ("SBFrame::GetVariables () => error: process is running");
1226         }
1227     }
1228 
1229     if (log)
1230         log->Printf ("SBFrame(%p)::GetVariables (...) => SBValueList(%p)",
1231                      static_cast<void*>(frame),
1232                      static_cast<void*>(value_list.opaque_ptr()));
1233 
1234     return value_list;
1235 }
1236 
1237 SBValueList
1238 SBFrame::GetRegisters ()
1239 {
1240     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1241 
1242     SBValueList value_list;
1243     Mutex::Locker api_locker;
1244     ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1245 
1246     StackFrame *frame = nullptr;
1247     Target *target = exe_ctx.GetTargetPtr();
1248     Process *process = exe_ctx.GetProcessPtr();
1249     if (target && process)
1250     {
1251         Process::StopLocker stop_locker;
1252         if (stop_locker.TryLock(&process->GetRunLock()))
1253         {
1254             frame = exe_ctx.GetFramePtr();
1255             if (frame)
1256             {
1257                 RegisterContextSP reg_ctx (frame->GetRegisterContext());
1258                 if (reg_ctx)
1259                 {
1260                     const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
1261                     for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
1262                     {
1263                         value_list.Append(ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx));
1264                     }
1265                 }
1266             }
1267             else
1268             {
1269                 if (log)
1270                     log->Printf ("SBFrame::GetRegisters () => error: could not reconstruct frame object for this SBFrame.");
1271             }
1272         }
1273         else
1274         {
1275             if (log)
1276                 log->Printf ("SBFrame::GetRegisters () => error: process is running");
1277         }
1278     }
1279 
1280     if (log)
1281         log->Printf ("SBFrame(%p)::GetRegisters () => SBValueList(%p)",
1282                      static_cast<void*>(frame),
1283                      static_cast<void*>(value_list.opaque_ptr()));
1284 
1285     return value_list;
1286 }
1287 
1288 SBValue
1289 SBFrame::FindRegister (const char *name)
1290 {
1291     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1292 
1293     SBValue result;
1294     ValueObjectSP value_sp;
1295     Mutex::Locker api_locker;
1296     ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1297 
1298     StackFrame *frame = nullptr;
1299     Target *target = exe_ctx.GetTargetPtr();
1300     Process *process = exe_ctx.GetProcessPtr();
1301     if (target && process)
1302     {
1303         Process::StopLocker stop_locker;
1304         if (stop_locker.TryLock(&process->GetRunLock()))
1305         {
1306             frame = exe_ctx.GetFramePtr();
1307             if (frame)
1308             {
1309                 RegisterContextSP reg_ctx (frame->GetRegisterContext());
1310                 if (reg_ctx)
1311                 {
1312                     const uint32_t num_regs = reg_ctx->GetRegisterCount();
1313                     for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx)
1314                     {
1315                         const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
1316                         if (reg_info &&
1317                             ((reg_info->name && strcasecmp (reg_info->name, name) == 0) ||
1318                              (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0)))
1319                         {
1320                             value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx);
1321                             result.SetSP (value_sp);
1322                             break;
1323                         }
1324                     }
1325                 }
1326             }
1327             else
1328             {
1329                 if (log)
1330                     log->Printf ("SBFrame::FindRegister () => error: could not reconstruct frame object for this SBFrame.");
1331             }
1332         }
1333         else
1334         {
1335             if (log)
1336                 log->Printf ("SBFrame::FindRegister () => error: process is running");
1337         }
1338     }
1339 
1340     if (log)
1341         log->Printf ("SBFrame(%p)::FindRegister () => SBValue(%p)",
1342                      static_cast<void*>(frame),
1343                      static_cast<void*>(value_sp.get()));
1344 
1345     return result;
1346 }
1347 
1348 bool
1349 SBFrame::GetDescription (SBStream &description)
1350 {
1351     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1352     Stream &strm = description.ref();
1353 
1354     Mutex::Locker api_locker;
1355     ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1356 
1357     StackFrame *frame;
1358     Target *target = exe_ctx.GetTargetPtr();
1359     Process *process = exe_ctx.GetProcessPtr();
1360     if (target && process)
1361     {
1362         Process::StopLocker stop_locker;
1363         if (stop_locker.TryLock(&process->GetRunLock()))
1364         {
1365             frame = exe_ctx.GetFramePtr();
1366             if (frame)
1367             {
1368                 frame->DumpUsingSettingsFormat (&strm);
1369             }
1370             else
1371             {
1372                 if (log)
1373                     log->Printf ("SBFrame::GetDescription () => error: could not reconstruct frame object for this SBFrame.");
1374             }
1375         }
1376         else
1377         {
1378             if (log)
1379                 log->Printf ("SBFrame::GetDescription () => error: process is running");
1380         }
1381 
1382     }
1383     else
1384         strm.PutCString ("No value");
1385 
1386     return true;
1387 }
1388 
1389 SBValue
1390 SBFrame::EvaluateExpression (const char *expr)
1391 {
1392     SBValue result;
1393     ExecutionContext exe_ctx(m_opaque_sp.get());
1394     StackFrame *frame = exe_ctx.GetFramePtr();
1395     Target *target = exe_ctx.GetTargetPtr();
1396     if (frame && target)
1397     {
1398         SBExpressionOptions options;
1399         lldb::DynamicValueType fetch_dynamic_value = frame->CalculateTarget()->GetPreferDynamicValue();
1400         options.SetFetchDynamicValue (fetch_dynamic_value);
1401         options.SetUnwindOnError (true);
1402         options.SetIgnoreBreakpoints (true);
1403         if (target->GetLanguage() != eLanguageTypeUnknown)
1404             options.SetLanguage(target->GetLanguage());
1405         else
1406             options.SetLanguage(frame->GetLanguage());
1407         return EvaluateExpression (expr, options);
1408     }
1409     return result;
1410 }
1411 
1412 SBValue
1413 SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value)
1414 {
1415     SBExpressionOptions options;
1416     options.SetFetchDynamicValue (fetch_dynamic_value);
1417     options.SetUnwindOnError (true);
1418     options.SetIgnoreBreakpoints (true);
1419     ExecutionContext exe_ctx(m_opaque_sp.get());
1420     StackFrame *frame = exe_ctx.GetFramePtr();
1421     Target *target = exe_ctx.GetTargetPtr();
1422     if (target && target->GetLanguage() != eLanguageTypeUnknown)
1423         options.SetLanguage(target->GetLanguage());
1424     else if (frame)
1425         options.SetLanguage(frame->GetLanguage());
1426     return EvaluateExpression (expr, options);
1427 }
1428 
1429 SBValue
1430 SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value, bool unwind_on_error)
1431 {
1432     SBExpressionOptions options;
1433     ExecutionContext exe_ctx(m_opaque_sp.get());
1434     options.SetFetchDynamicValue (fetch_dynamic_value);
1435     options.SetUnwindOnError (unwind_on_error);
1436     options.SetIgnoreBreakpoints (true);
1437     StackFrame *frame = exe_ctx.GetFramePtr();
1438     Target *target = exe_ctx.GetTargetPtr();
1439     if (target && target->GetLanguage() != eLanguageTypeUnknown)
1440         options.SetLanguage(target->GetLanguage());
1441     else if (frame)
1442         options.SetLanguage(frame->GetLanguage());
1443     return EvaluateExpression (expr, options);
1444 }
1445 
1446 lldb::SBValue
1447 SBFrame::EvaluateExpression (const char *expr, const SBExpressionOptions &options)
1448 {
1449     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1450 
1451 #ifndef LLDB_DISABLE_PYTHON
1452     Log *expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
1453 #endif
1454 
1455     ExpressionResults exe_results = eExpressionSetupError;
1456     SBValue expr_result;
1457 
1458     if (expr == nullptr || expr[0] == '\0')
1459     {
1460         if (log)
1461             log->Printf ("SBFrame::EvaluateExpression called with an empty expression");
1462         return expr_result;
1463     }
1464 
1465     ValueObjectSP expr_value_sp;
1466 
1467     Mutex::Locker api_locker;
1468     ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1469 
1470     if (log)
1471         log->Printf ("SBFrame()::EvaluateExpression (expr=\"%s\")...", expr);
1472 
1473     StackFrame *frame = nullptr;
1474     Target *target = exe_ctx.GetTargetPtr();
1475     Process *process = exe_ctx.GetProcessPtr();
1476 
1477     if (target && process)
1478     {
1479         Process::StopLocker stop_locker;
1480         if (stop_locker.TryLock(&process->GetRunLock()))
1481         {
1482             frame = exe_ctx.GetFramePtr();
1483             if (frame)
1484             {
1485                 if (target->GetDisplayExpressionsInCrashlogs())
1486                 {
1487                     StreamString frame_description;
1488                     frame->DumpUsingSettingsFormat (&frame_description);
1489                     Host::SetCrashDescriptionWithFormat ("SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
1490                                                          expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str());
1491                 }
1492 
1493                 exe_results = target->EvaluateExpression (expr,
1494                                                           frame,
1495                                                           expr_value_sp,
1496                                                           options.ref());
1497                 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
1498 
1499                 if (target->GetDisplayExpressionsInCrashlogs())
1500                     Host::SetCrashDescription(nullptr);
1501             }
1502             else
1503             {
1504                 if (log)
1505                     log->Printf ("SBFrame::EvaluateExpression () => error: could not reconstruct frame object for this SBFrame.");
1506             }
1507         }
1508         else
1509         {
1510             if (log)
1511                 log->Printf ("SBFrame::EvaluateExpression () => error: process is running");
1512         }
1513     }
1514 
1515 #ifndef LLDB_DISABLE_PYTHON
1516     if (expr_log)
1517         expr_log->Printf("** [SBFrame::EvaluateExpression] Expression result is %s, summary %s **",
1518                          expr_result.GetValue(), expr_result.GetSummary());
1519 
1520     if (log)
1521         log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)",
1522                      static_cast<void*>(frame), expr,
1523                      static_cast<void*>(expr_value_sp.get()), exe_results);
1524 #endif
1525 
1526     return expr_result;
1527 }
1528 
1529 bool
1530 SBFrame::IsInlined()
1531 {
1532     return static_cast<const SBFrame*>(this)->IsInlined();
1533 }
1534 
1535 bool
1536 SBFrame::IsInlined() const
1537 {
1538     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1539     ExecutionContext exe_ctx(m_opaque_sp.get());
1540     StackFrame *frame = nullptr;
1541     Target *target = exe_ctx.GetTargetPtr();
1542     Process *process = exe_ctx.GetProcessPtr();
1543     if (target && process)
1544     {
1545         Process::StopLocker stop_locker;
1546         if (stop_locker.TryLock(&process->GetRunLock()))
1547         {
1548             frame = exe_ctx.GetFramePtr();
1549             if (frame)
1550             {
1551 
1552                 Block *block = frame->GetSymbolContext(eSymbolContextBlock).block;
1553                 if (block)
1554                     return block->GetContainingInlinedBlock() != nullptr;
1555             }
1556             else
1557             {
1558                 if (log)
1559                     log->Printf ("SBFrame::IsInlined () => error: could not reconstruct frame object for this SBFrame.");
1560             }
1561         }
1562         else
1563         {
1564             if (log)
1565                 log->Printf ("SBFrame::IsInlined () => error: process is running");
1566         }
1567 
1568     }
1569     return false;
1570 }
1571 
1572 const char *
1573 SBFrame::GetFunctionName()
1574 {
1575     return static_cast<const SBFrame*>(this)->GetFunctionName();
1576 }
1577 
1578 const char *
1579 SBFrame::GetFunctionName() const
1580 {
1581     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1582     const char *name = nullptr;
1583     ExecutionContext exe_ctx(m_opaque_sp.get());
1584     StackFrame *frame = nullptr;
1585     Target *target = exe_ctx.GetTargetPtr();
1586     Process *process = exe_ctx.GetProcessPtr();
1587     if (target && process)
1588     {
1589         Process::StopLocker stop_locker;
1590         if (stop_locker.TryLock(&process->GetRunLock()))
1591         {
1592             frame = exe_ctx.GetFramePtr();
1593             if (frame)
1594             {
1595                 SymbolContext sc (frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol));
1596                 if (sc.block)
1597                 {
1598                     Block *inlined_block = sc.block->GetContainingInlinedBlock ();
1599                     if (inlined_block)
1600                     {
1601                         const InlineFunctionInfo* inlined_info = inlined_block->GetInlinedFunctionInfo();
1602                         name = inlined_info->GetName(sc.function->GetLanguage()).AsCString();
1603                     }
1604                 }
1605 
1606                 if (name == nullptr)
1607                 {
1608                     if (sc.function)
1609                         name = sc.function->GetName().GetCString();
1610                 }
1611 
1612                 if (name == nullptr)
1613                 {
1614                     if (sc.symbol)
1615                         name = sc.symbol->GetName().GetCString();
1616                 }
1617             }
1618             else
1619             {
1620                 if (log)
1621                     log->Printf ("SBFrame::GetFunctionName () => error: could not reconstruct frame object for this SBFrame.");
1622             }
1623         }
1624         else
1625         {
1626             if (log)
1627                 log->Printf ("SBFrame::GetFunctionName() => error: process is running");
1628 
1629         }
1630     }
1631     return name;
1632 }
1633 
1634 const char *
1635 SBFrame::GetDisplayFunctionName()
1636 {
1637     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1638     const char *name = nullptr;
1639     ExecutionContext exe_ctx(m_opaque_sp.get());
1640     StackFrame *frame = nullptr;
1641     Target *target = exe_ctx.GetTargetPtr();
1642     Process *process = exe_ctx.GetProcessPtr();
1643     if (target && process)
1644     {
1645         Process::StopLocker stop_locker;
1646         if (stop_locker.TryLock(&process->GetRunLock()))
1647         {
1648             frame = exe_ctx.GetFramePtr();
1649             if (frame)
1650             {
1651                 SymbolContext sc (frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol));
1652                 if (sc.block)
1653                 {
1654                     Block *inlined_block = sc.block->GetContainingInlinedBlock ();
1655                     if (inlined_block)
1656                     {
1657                         const InlineFunctionInfo* inlined_info = inlined_block->GetInlinedFunctionInfo();
1658                         name = inlined_info->GetDisplayName(sc.function->GetLanguage()).AsCString();
1659                     }
1660                 }
1661 
1662                 if (name == nullptr)
1663                 {
1664                     if (sc.function)
1665                         name = sc.function->GetDisplayName().GetCString();
1666                 }
1667 
1668                 if (name == nullptr)
1669                 {
1670                     if (sc.symbol)
1671                         name = sc.symbol->GetDisplayName().GetCString();
1672                 }
1673             }
1674             else
1675             {
1676                 if (log)
1677                     log->Printf ("SBFrame::GetDisplayFunctionName () => error: could not reconstruct frame object for this SBFrame.");
1678             }
1679         }
1680         else
1681         {
1682             if (log)
1683                 log->Printf ("SBFrame::GetDisplayFunctionName() => error: process is running");
1684 
1685         }
1686     }
1687     return name;
1688 }
1689