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