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