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