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