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