1 //===-- SBFrame.cpp ---------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/API/SBFrame.h"
15 #include "lldb/lldb-types.h"
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"
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"
49 using namespace lldb_private;
53 m_opaque_sp (new ExecutionContextRef())
57 SBFrame::SBFrame (const StackFrameSP &lldb_object_sp) :
58 m_opaque_sp (new ExecutionContextRef (lldb_object_sp))
60 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
65 GetDescription (sstr);
66 log->Printf ("SBFrame::SBFrame (sp=%p) => SBFrame(%p): %s",
67 lldb_object_sp.get(), lldb_object_sp.get(), sstr.GetData());
72 SBFrame::SBFrame(const SBFrame &rhs) :
73 m_opaque_sp (new ExecutionContextRef (*rhs.m_opaque_sp))
78 SBFrame::operator = (const SBFrame &rhs)
81 *m_opaque_sp = *rhs.m_opaque_sp;
90 SBFrame::GetFrameSP() const
93 return m_opaque_sp->GetFrameSP();
94 return StackFrameSP();
98 SBFrame::SetFrameSP (const StackFrameSP &lldb_object_sp)
100 return m_opaque_sp->SetFrameSP(lldb_object_sp);
104 SBFrame::IsValid() const
106 return GetFrameSP().get() != NULL;
110 SBFrame::GetSymbolContext (uint32_t resolve_scope) const
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);
117 StackFrame *frame = NULL;
118 Target *target = exe_ctx.GetTargetPtr();
119 Process *process = exe_ctx.GetProcessPtr();
120 if (target && process)
122 Process::StopLocker stop_locker;
123 if (stop_locker.TryLock(&process->GetRunLock()))
125 frame = exe_ctx.GetFramePtr();
128 sb_sym_ctx.SetSymbolContext(&frame->GetSymbolContext (resolve_scope));
133 log->Printf ("SBFrame::GetVariables () => error: could not reconstruct frame object for this SBFrame.");
139 log->Printf ("SBFrame::GetSymbolContext () => error: process is running");
144 log->Printf ("SBFrame(%p)::GetSymbolContext (resolve_scope=0x%8.8x) => SBSymbolContext(%p)",
145 frame, resolve_scope, sb_sym_ctx.get());
151 SBFrame::GetModule () const
153 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
156 Mutex::Locker api_locker;
157 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
159 StackFrame *frame = NULL;
160 Target *target = exe_ctx.GetTargetPtr();
161 Process *process = exe_ctx.GetProcessPtr();
162 if (target && process)
164 Process::StopLocker stop_locker;
165 if (stop_locker.TryLock(&process->GetRunLock()))
167 frame = exe_ctx.GetFramePtr();
170 module_sp = frame->GetSymbolContext (eSymbolContextModule).module_sp;
171 sb_module.SetSP (module_sp);
176 log->Printf ("SBFrame::GetModule () => error: could not reconstruct frame object for this SBFrame.");
182 log->Printf ("SBFrame::GetModule () => error: process is running");
187 log->Printf ("SBFrame(%p)::GetModule () => SBModule(%p)",
188 frame, module_sp.get());
194 SBFrame::GetCompileUnit () const
196 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
197 SBCompileUnit sb_comp_unit;
198 Mutex::Locker api_locker;
199 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
201 StackFrame *frame = NULL;
202 Target *target = exe_ctx.GetTargetPtr();
203 Process *process = exe_ctx.GetProcessPtr();
204 if (target && process)
206 Process::StopLocker stop_locker;
207 if (stop_locker.TryLock(&process->GetRunLock()))
209 frame = exe_ctx.GetFramePtr();
212 sb_comp_unit.reset (frame->GetSymbolContext (eSymbolContextCompUnit).comp_unit);
217 log->Printf ("SBFrame::GetCompileUnit () => error: could not reconstruct frame object for this SBFrame.");
223 log->Printf ("SBFrame::GetCompileUnit () => error: process is running");
227 log->Printf ("SBFrame(%p)::GetCompileUnit () => SBCompileUnit(%p)",
228 frame, sb_comp_unit.get());
234 SBFrame::GetFunction () const
236 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
237 SBFunction sb_function;
238 Mutex::Locker api_locker;
239 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
241 StackFrame *frame = NULL;
242 Target *target = exe_ctx.GetTargetPtr();
243 Process *process = exe_ctx.GetProcessPtr();
244 if (target && process)
246 Process::StopLocker stop_locker;
247 if (stop_locker.TryLock(&process->GetRunLock()))
249 frame = exe_ctx.GetFramePtr();
252 sb_function.reset(frame->GetSymbolContext (eSymbolContextFunction).function);
257 log->Printf ("SBFrame::GetFunction () => error: could not reconstruct frame object for this SBFrame.");
263 log->Printf ("SBFrame::GetFunction () => error: process is running");
267 log->Printf ("SBFrame(%p)::GetFunction () => SBFunction(%p)",
268 frame, sb_function.get());
274 SBFrame::GetSymbol () const
276 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
278 Mutex::Locker api_locker;
279 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
281 StackFrame *frame = NULL;
282 Target *target = exe_ctx.GetTargetPtr();
283 Process *process = exe_ctx.GetProcessPtr();
284 if (target && process)
286 Process::StopLocker stop_locker;
287 if (stop_locker.TryLock(&process->GetRunLock()))
289 frame = exe_ctx.GetFramePtr();
292 sb_symbol.reset(frame->GetSymbolContext (eSymbolContextSymbol).symbol);
297 log->Printf ("SBFrame::GetSymbol () => error: could not reconstruct frame object for this SBFrame.");
303 log->Printf ("SBFrame::GetSymbol () => error: process is running");
307 log->Printf ("SBFrame(%p)::GetSymbol () => SBSymbol(%p)",
308 frame, sb_symbol.get());
313 SBFrame::GetBlock () const
315 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
317 Mutex::Locker api_locker;
318 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
320 StackFrame *frame = NULL;
321 Target *target = exe_ctx.GetTargetPtr();
322 Process *process = exe_ctx.GetProcessPtr();
323 if (target && process)
325 Process::StopLocker stop_locker;
326 if (stop_locker.TryLock(&process->GetRunLock()))
328 frame = exe_ctx.GetFramePtr();
331 sb_block.SetPtr (frame->GetSymbolContext (eSymbolContextBlock).block);
336 log->Printf ("SBFrame::GetBlock () => error: could not reconstruct frame object for this SBFrame.");
342 log->Printf ("SBFrame(%p)::GetBlock () => error: process is running", frame);
346 log->Printf ("SBFrame(%p)::GetBlock () => SBBlock(%p)",
347 frame, sb_block.GetPtr());
352 SBFrame::GetFrameBlock () const
355 Mutex::Locker api_locker;
356 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
358 StackFrame *frame = NULL;
359 Target *target = exe_ctx.GetTargetPtr();
360 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
361 Process *process = exe_ctx.GetProcessPtr();
362 if (target && process)
364 Process::StopLocker stop_locker;
365 if (stop_locker.TryLock(&process->GetRunLock()))
367 frame = exe_ctx.GetFramePtr();
370 sb_block.SetPtr(frame->GetFrameBlock ());
375 log->Printf ("SBFrame::GetFrameBlock () => error: could not reconstruct frame object for this SBFrame.");
381 log->Printf ("SBFrame::GetFrameBlock () => error: process is running");
385 log->Printf ("SBFrame(%p)::GetFrameBlock () => SBBlock(%p)",
386 frame, sb_block.GetPtr());
391 SBFrame::GetLineEntry () const
393 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
394 SBLineEntry sb_line_entry;
395 Mutex::Locker api_locker;
396 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
398 StackFrame *frame = NULL;
399 Target *target = exe_ctx.GetTargetPtr();
400 Process *process = exe_ctx.GetProcessPtr();
401 if (target && process)
403 Process::StopLocker stop_locker;
404 if (stop_locker.TryLock(&process->GetRunLock()))
406 frame = exe_ctx.GetFramePtr();
409 sb_line_entry.SetLineEntry (frame->GetSymbolContext (eSymbolContextLineEntry).line_entry);
414 log->Printf ("SBFrame::GetLineEntry () => error: could not reconstruct frame object for this SBFrame.");
420 log->Printf ("SBFrame::GetLineEntry () => error: process is running");
424 log->Printf ("SBFrame(%p)::GetLineEntry () => SBLineEntry(%p)",
425 frame, sb_line_entry.get());
426 return sb_line_entry;
430 SBFrame::GetFrameID () const
432 uint32_t frame_idx = UINT32_MAX;
434 ExecutionContext exe_ctx(m_opaque_sp.get());
435 StackFrame *frame = exe_ctx.GetFramePtr();
437 frame_idx = frame->GetFrameIndex ();
439 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
441 log->Printf ("SBFrame(%p)::GetFrameID () => %u",
447 SBFrame::GetPC () const
449 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
450 addr_t addr = LLDB_INVALID_ADDRESS;
451 Mutex::Locker api_locker;
452 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
454 StackFrame *frame = NULL;
455 Target *target = exe_ctx.GetTargetPtr();
456 Process *process = exe_ctx.GetProcessPtr();
457 if (target && process)
459 Process::StopLocker stop_locker;
460 if (stop_locker.TryLock(&process->GetRunLock()))
462 frame = exe_ctx.GetFramePtr();
465 addr = frame->GetFrameCodeAddress().GetOpcodeLoadAddress (target);
470 log->Printf ("SBFrame::GetPC () => error: could not reconstruct frame object for this SBFrame.");
476 log->Printf ("SBFrame::GetPC () => error: process is running");
481 log->Printf ("SBFrame(%p)::GetPC () => 0x%" PRIx64, frame, addr);
487 SBFrame::SetPC (addr_t new_pc)
489 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
490 bool ret_val = false;
491 Mutex::Locker api_locker;
492 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
494 StackFrame *frame = NULL;
495 Target *target = exe_ctx.GetTargetPtr();
496 Process *process = exe_ctx.GetProcessPtr();
497 if (target && process)
499 Process::StopLocker stop_locker;
500 if (stop_locker.TryLock(&process->GetRunLock()))
502 frame = exe_ctx.GetFramePtr();
505 ret_val = frame->GetRegisterContext()->SetPC (new_pc);
510 log->Printf ("SBFrame::SetPC () => error: could not reconstruct frame object for this SBFrame.");
516 log->Printf ("SBFrame::SetPC () => error: process is running");
521 log->Printf ("SBFrame(%p)::SetPC (new_pc=0x%" PRIx64 ") => %i",
522 frame, new_pc, ret_val);
528 SBFrame::GetSP () const
530 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
531 addr_t addr = LLDB_INVALID_ADDRESS;
532 Mutex::Locker api_locker;
533 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
535 StackFrame *frame = NULL;
536 Target *target = exe_ctx.GetTargetPtr();
537 Process *process = exe_ctx.GetProcessPtr();
538 if (target && process)
540 Process::StopLocker stop_locker;
541 if (stop_locker.TryLock(&process->GetRunLock()))
543 frame = exe_ctx.GetFramePtr();
546 addr = frame->GetRegisterContext()->GetSP();
551 log->Printf ("SBFrame::GetSP () => error: could not reconstruct frame object for this SBFrame.");
557 log->Printf ("SBFrame::GetSP () => error: process is running");
561 log->Printf ("SBFrame(%p)::GetSP () => 0x%" PRIx64, frame, addr);
568 SBFrame::GetFP () const
570 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
571 addr_t addr = LLDB_INVALID_ADDRESS;
572 Mutex::Locker api_locker;
573 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
575 StackFrame *frame = NULL;
576 Target *target = exe_ctx.GetTargetPtr();
577 Process *process = exe_ctx.GetProcessPtr();
578 if (target && process)
580 Process::StopLocker stop_locker;
581 if (stop_locker.TryLock(&process->GetRunLock()))
583 frame = exe_ctx.GetFramePtr();
586 addr = frame->GetRegisterContext()->GetFP();
591 log->Printf ("SBFrame::GetFP () => error: could not reconstruct frame object for this SBFrame.");
597 log->Printf ("SBFrame::GetFP () => error: process is running");
602 log->Printf ("SBFrame(%p)::GetFP () => 0x%" PRIx64, frame, addr);
608 SBFrame::GetPCAddress () const
610 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
612 Mutex::Locker api_locker;
613 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
615 StackFrame *frame = exe_ctx.GetFramePtr();
616 Target *target = exe_ctx.GetTargetPtr();
617 Process *process = exe_ctx.GetProcessPtr();
618 if (target && process)
620 Process::StopLocker stop_locker;
621 if (stop_locker.TryLock(&process->GetRunLock()))
623 frame = exe_ctx.GetFramePtr();
626 sb_addr.SetAddress (&frame->GetFrameCodeAddress());
631 log->Printf ("SBFrame::GetPCAddress () => error: could not reconstruct frame object for this SBFrame.");
637 log->Printf ("SBFrame::GetPCAddress () => error: process is running");
641 log->Printf ("SBFrame(%p)::GetPCAddress () => SBAddress(%p)", frame, sb_addr.get());
648 m_opaque_sp->Clear();
652 SBFrame::GetValueForVariablePath (const char *var_path)
655 ExecutionContext exe_ctx(m_opaque_sp.get());
656 StackFrame *frame = exe_ctx.GetFramePtr();
657 Target *target = exe_ctx.GetTargetPtr();
660 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
661 sb_value = GetValueForVariablePath (var_path, use_dynamic);
667 SBFrame::GetValueForVariablePath (const char *var_path, DynamicValueType use_dynamic)
670 Mutex::Locker api_locker;
671 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
672 if (var_path == NULL || var_path[0] == '\0')
675 log->Printf ("SBFrame::GetValueForVariablePath called with empty variable path.");
679 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
681 StackFrame *frame = NULL;
682 Target *target = exe_ctx.GetTargetPtr();
683 Process *process = exe_ctx.GetProcessPtr();
684 if (target && process)
686 Process::StopLocker stop_locker;
687 if (stop_locker.TryLock(&process->GetRunLock()))
689 frame = exe_ctx.GetFramePtr();
694 ValueObjectSP value_sp (frame->GetValueForVariableExpressionPath (var_path,
696 StackFrame::eExpressionPathOptionCheckPtrVsMember | StackFrame::eExpressionPathOptionsAllowDirectIVarAccess,
699 sb_value.SetSP(value_sp, use_dynamic);
704 log->Printf ("SBFrame::GetValueForVariablePath () => error: could not reconstruct frame object for this SBFrame.");
710 log->Printf ("SBFrame::GetValueForVariablePath () => error: process is running");
717 SBFrame::FindVariable (const char *name)
720 ExecutionContext exe_ctx(m_opaque_sp.get());
721 StackFrame *frame = exe_ctx.GetFramePtr();
722 Target *target = exe_ctx.GetTargetPtr();
725 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
726 value = FindVariable (name, use_dynamic);
733 SBFrame::FindVariable (const char *name, lldb::DynamicValueType use_dynamic)
735 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
739 if (name == NULL || name[0] == '\0')
742 log->Printf ("SBFrame::FindVariable called with empty name");
746 ValueObjectSP value_sp;
747 Mutex::Locker api_locker;
748 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
750 StackFrame *frame = NULL;
751 Target *target = exe_ctx.GetTargetPtr();
752 Process *process = exe_ctx.GetProcessPtr();
753 if (target && process)
755 Process::StopLocker stop_locker;
756 if (stop_locker.TryLock(&process->GetRunLock()))
758 frame = exe_ctx.GetFramePtr();
761 VariableList variable_list;
762 SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock));
766 const bool can_create = true;
767 const bool get_parent_variables = true;
768 const bool stop_if_block_is_inlined_function = true;
770 if (sc.block->AppendVariables (can_create,
771 get_parent_variables,
772 stop_if_block_is_inlined_function,
775 var_sp = variable_list.FindVariable (ConstString(name));
781 value_sp = frame->GetValueObjectForFrameVariable(var_sp, eNoDynamicValues);
782 sb_value.SetSP(value_sp, use_dynamic);
788 log->Printf ("SBFrame::FindVariable () => error: could not reconstruct frame object for this SBFrame.");
794 log->Printf ("SBFrame::FindVariable () => error: process is running");
799 log->Printf ("SBFrame(%p)::FindVariable (name=\"%s\") => SBValue(%p)",
800 frame, name, value_sp.get());
806 SBFrame::FindValue (const char *name, ValueType value_type)
809 ExecutionContext exe_ctx(m_opaque_sp.get());
810 StackFrame *frame = exe_ctx.GetFramePtr();
811 Target *target = exe_ctx.GetTargetPtr();
814 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
815 value = FindValue (name, value_type, use_dynamic);
821 SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueType use_dynamic)
823 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
826 if (name == NULL || name[0] == '\0')
829 log->Printf ("SBFrame::FindValue called with empty name.");
833 ValueObjectSP value_sp;
834 Mutex::Locker api_locker;
835 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
837 StackFrame *frame = NULL;
838 Target *target = exe_ctx.GetTargetPtr();
839 Process *process = exe_ctx.GetProcessPtr();
840 if (target && process)
842 Process::StopLocker stop_locker;
843 if (stop_locker.TryLock(&process->GetRunLock()))
845 frame = exe_ctx.GetFramePtr();
848 VariableList variable_list;
852 case eValueTypeVariableGlobal: // global variable
853 case eValueTypeVariableStatic: // static variable
854 case eValueTypeVariableArgument: // function argument variables
855 case eValueTypeVariableLocal: // function local variables
858 SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock));
860 const bool can_create = true;
861 const bool get_parent_variables = true;
862 const bool stop_if_block_is_inlined_function = true;
864 if (sc.block && sc.block->AppendVariables (can_create,
865 get_parent_variables,
866 stop_if_block_is_inlined_function,
869 if (value_type == eValueTypeVariableGlobal)
871 const bool get_file_globals = true;
872 VariableList* frame_vars = frame->GetVariableList(get_file_globals);
874 frame_vars->AppendVariablesIfUnique(variable_list);
876 ConstString const_name(name);
877 VariableSP variable_sp(variable_list.FindVariable(const_name,value_type));
880 value_sp = frame->GetValueObjectForFrameVariable (variable_sp, eNoDynamicValues);
881 sb_value.SetSP (value_sp, use_dynamic);
888 case eValueTypeRegister: // stack frame register value
890 RegisterContextSP reg_ctx (frame->GetRegisterContext());
893 const uint32_t num_regs = reg_ctx->GetRegisterCount();
894 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx)
896 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
898 ((reg_info->name && strcasecmp (reg_info->name, name) == 0) ||
899 (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0)))
901 value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx);
902 sb_value.SetSP (value_sp);
910 case eValueTypeRegisterSet: // A collection of stack frame register values
912 RegisterContextSP reg_ctx (frame->GetRegisterContext());
915 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
916 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
918 const RegisterSet *reg_set = reg_ctx->GetRegisterSet (set_idx);
920 ((reg_set->name && strcasecmp (reg_set->name, name) == 0) ||
921 (reg_set->short_name && strcasecmp (reg_set->short_name, name) == 0)))
923 value_sp = ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx);
924 sb_value.SetSP (value_sp);
932 case eValueTypeConstResult: // constant result variables
934 ConstString const_name(name);
935 ClangExpressionVariableSP expr_var_sp (target->GetPersistentVariables().GetVariable (const_name));
938 value_sp = expr_var_sp->GetValueObject();
939 sb_value.SetSP (value_sp, use_dynamic);
951 log->Printf ("SBFrame::FindValue () => error: could not reconstruct frame object for this SBFrame.");
957 log->Printf ("SBFrame::FindValue () => error: process is running");
962 log->Printf ("SBFrame(%p)::FindVariableInScope (name=\"%s\", value_type=%i) => SBValue(%p)",
963 frame, name, value_type, value_sp.get());
970 SBFrame::IsEqual (const SBFrame &that) const
972 lldb::StackFrameSP this_sp = GetFrameSP();
973 lldb::StackFrameSP that_sp = that.GetFrameSP();
974 return (this_sp && that_sp && this_sp->GetStackID() == that_sp->GetStackID());
978 SBFrame::operator == (const SBFrame &rhs) const
984 SBFrame::operator != (const SBFrame &rhs) const
986 return !IsEqual(rhs);
990 SBFrame::GetThread () const
992 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
994 ExecutionContext exe_ctx(m_opaque_sp.get());
995 ThreadSP thread_sp (exe_ctx.GetThreadSP());
996 SBThread sb_thread (thread_sp);
1001 sb_thread.GetDescription (sstr);
1002 log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s",
1003 exe_ctx.GetFramePtr(),
1012 SBFrame::Disassemble () const
1014 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1015 const char *disassembly = NULL;
1016 Mutex::Locker api_locker;
1017 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1019 StackFrame *frame = NULL;
1020 Target *target = exe_ctx.GetTargetPtr();
1021 Process *process = exe_ctx.GetProcessPtr();
1022 if (target && process)
1024 Process::StopLocker stop_locker;
1025 if (stop_locker.TryLock(&process->GetRunLock()))
1027 frame = exe_ctx.GetFramePtr();
1030 disassembly = frame->Disassemble();
1035 log->Printf ("SBFrame::Disassemble () => error: could not reconstruct frame object for this SBFrame.");
1041 log->Printf ("SBFrame::Disassemble () => error: process is running");
1046 log->Printf ("SBFrame(%p)::Disassemble () => %s", frame, disassembly);
1053 SBFrame::GetVariables (bool arguments,
1058 SBValueList value_list;
1059 ExecutionContext exe_ctx(m_opaque_sp.get());
1060 StackFrame *frame = exe_ctx.GetFramePtr();
1061 Target *target = exe_ctx.GetTargetPtr();
1062 if (frame && target)
1064 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
1065 value_list = GetVariables (arguments, locals, statics, in_scope_only, use_dynamic);
1071 SBFrame::GetVariables (bool arguments,
1075 lldb::DynamicValueType use_dynamic)
1077 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1079 SBValueList value_list;
1080 Mutex::Locker api_locker;
1081 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1083 StackFrame *frame = NULL;
1084 Target *target = exe_ctx.GetTargetPtr();
1087 log->Printf ("SBFrame::GetVariables (arguments=%i, locals=%i, statics=%i, in_scope_only=%i)",
1093 Process *process = exe_ctx.GetProcessPtr();
1094 if (target && process)
1096 Process::StopLocker stop_locker;
1097 if (stop_locker.TryLock(&process->GetRunLock()))
1099 frame = exe_ctx.GetFramePtr();
1103 VariableList *variable_list = NULL;
1104 variable_list = frame->GetVariableList(true);
1107 const size_t num_variables = variable_list->GetSize();
1110 for (i = 0; i < num_variables; ++i)
1112 VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
1115 bool add_variable = false;
1116 switch (variable_sp->GetScope())
1118 case eValueTypeVariableGlobal:
1119 case eValueTypeVariableStatic:
1120 add_variable = statics;
1123 case eValueTypeVariableArgument:
1124 add_variable = arguments;
1127 case eValueTypeVariableLocal:
1128 add_variable = locals;
1136 if (in_scope_only && !variable_sp->IsInScope(frame))
1139 ValueObjectSP valobj_sp(frame->GetValueObjectForFrameVariable (variable_sp, eNoDynamicValues));
1141 value_sb.SetSP(valobj_sp,use_dynamic);
1142 value_list.Append(value_sb);
1152 log->Printf ("SBFrame::GetVariables () => error: could not reconstruct frame object for this SBFrame.");
1158 log->Printf ("SBFrame::GetVariables () => error: process is running");
1164 log->Printf ("SBFrame(%p)::GetVariables (...) => SBValueList(%p)", frame, value_list.opaque_ptr());
1171 SBFrame::GetRegisters ()
1173 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1175 SBValueList value_list;
1176 Mutex::Locker api_locker;
1177 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1179 StackFrame *frame = NULL;
1180 Target *target = exe_ctx.GetTargetPtr();
1181 Process *process = exe_ctx.GetProcessPtr();
1182 if (target && process)
1184 Process::StopLocker stop_locker;
1185 if (stop_locker.TryLock(&process->GetRunLock()))
1187 frame = exe_ctx.GetFramePtr();
1190 RegisterContextSP reg_ctx (frame->GetRegisterContext());
1193 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
1194 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
1196 value_list.Append(ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx));
1203 log->Printf ("SBFrame::GetRegisters () => error: could not reconstruct frame object for this SBFrame.");
1209 log->Printf ("SBFrame::GetRegisters () => error: process is running");
1214 log->Printf ("SBFrame(%p)::GetRegisters () => SBValueList(%p)", frame, value_list.opaque_ptr());
1220 SBFrame::FindRegister (const char *name)
1222 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1225 ValueObjectSP value_sp;
1226 Mutex::Locker api_locker;
1227 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1229 StackFrame *frame = NULL;
1230 Target *target = exe_ctx.GetTargetPtr();
1231 Process *process = exe_ctx.GetProcessPtr();
1232 if (target && process)
1234 Process::StopLocker stop_locker;
1235 if (stop_locker.TryLock(&process->GetRunLock()))
1237 frame = exe_ctx.GetFramePtr();
1240 RegisterContextSP reg_ctx (frame->GetRegisterContext());
1243 const uint32_t num_regs = reg_ctx->GetRegisterCount();
1244 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx)
1246 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
1248 ((reg_info->name && strcasecmp (reg_info->name, name) == 0) ||
1249 (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0)))
1251 value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx);
1252 result.SetSP (value_sp);
1261 log->Printf ("SBFrame::FindRegister () => error: could not reconstruct frame object for this SBFrame.");
1267 log->Printf ("SBFrame::FindRegister () => error: process is running");
1272 log->Printf ("SBFrame(%p)::FindRegister () => SBValue(%p)", frame, value_sp.get());
1278 SBFrame::GetDescription (SBStream &description)
1280 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1281 Stream &strm = description.ref();
1283 Mutex::Locker api_locker;
1284 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1287 Target *target = exe_ctx.GetTargetPtr();
1288 Process *process = exe_ctx.GetProcessPtr();
1289 if (target && process)
1291 Process::StopLocker stop_locker;
1292 if (stop_locker.TryLock(&process->GetRunLock()))
1294 frame = exe_ctx.GetFramePtr();
1297 frame->DumpUsingSettingsFormat (&strm);
1302 log->Printf ("SBFrame::GetDescription () => error: could not reconstruct frame object for this SBFrame.");
1308 log->Printf ("SBFrame::GetDescription () => error: process is running");
1313 strm.PutCString ("No value");
1319 SBFrame::EvaluateExpression (const char *expr)
1322 ExecutionContext exe_ctx(m_opaque_sp.get());
1323 StackFrame *frame = exe_ctx.GetFramePtr();
1324 Target *target = exe_ctx.GetTargetPtr();
1325 if (frame && target)
1327 SBExpressionOptions options;
1328 lldb::DynamicValueType fetch_dynamic_value = frame->CalculateTarget()->GetPreferDynamicValue();
1329 options.SetFetchDynamicValue (fetch_dynamic_value);
1330 options.SetUnwindOnError (true);
1331 return EvaluateExpression (expr, options);
1337 SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value)
1339 SBExpressionOptions options;
1340 options.SetFetchDynamicValue (fetch_dynamic_value);
1341 options.SetUnwindOnError (true);
1342 return EvaluateExpression (expr, options);
1346 SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value, bool unwind_on_error)
1348 SBExpressionOptions options;
1349 options.SetFetchDynamicValue (fetch_dynamic_value);
1350 options.SetUnwindOnError (unwind_on_error);
1351 return EvaluateExpression (expr, options);
1355 SBFrame::EvaluateExpression (const char *expr, const SBExpressionOptions &options)
1357 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1359 Log *expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
1361 ExecutionResults exe_results = eExecutionSetupError;
1362 SBValue expr_result;
1364 if (expr == NULL || expr[0] == '\0')
1367 log->Printf ("SBFrame::EvaluateExpression called with an empty expression");
1371 ValueObjectSP expr_value_sp;
1373 Mutex::Locker api_locker;
1374 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1377 log->Printf ("SBFrame()::EvaluateExpression (expr=\"%s\")...", expr);
1379 StackFrame *frame = NULL;
1380 Target *target = exe_ctx.GetTargetPtr();
1381 Process *process = exe_ctx.GetProcessPtr();
1383 if (target && process)
1385 Process::StopLocker stop_locker;
1386 if (stop_locker.TryLock(&process->GetRunLock()))
1388 frame = exe_ctx.GetFramePtr();
1391 if (target->GetDisplayExpressionsInCrashlogs())
1393 StreamString frame_description;
1394 frame->DumpUsingSettingsFormat (&frame_description);
1395 Host::SetCrashDescriptionWithFormat ("SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
1396 expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str());
1399 exe_results = target->EvaluateExpression (expr,
1403 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
1405 if (target->GetDisplayExpressionsInCrashlogs())
1406 Host::SetCrashDescription (NULL);
1411 log->Printf ("SBFrame::EvaluateExpression () => error: could not reconstruct frame object for this SBFrame.");
1417 log->Printf ("SBFrame::EvaluateExpression () => error: process is running");
1421 #ifndef LLDB_DISABLE_PYTHON
1423 expr_log->Printf("** [SBFrame::EvaluateExpression] Expression result is %s, summary %s **",
1424 expr_result.GetValue(),
1425 expr_result.GetSummary());
1428 log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)",
1431 expr_value_sp.get(),
1439 SBFrame::IsInlined()
1441 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1442 ExecutionContext exe_ctx(m_opaque_sp.get());
1443 StackFrame *frame = NULL;
1444 Target *target = exe_ctx.GetTargetPtr();
1445 Process *process = exe_ctx.GetProcessPtr();
1446 if (target && process)
1448 Process::StopLocker stop_locker;
1449 if (stop_locker.TryLock(&process->GetRunLock()))
1451 frame = exe_ctx.GetFramePtr();
1455 Block *block = frame->GetSymbolContext(eSymbolContextBlock).block;
1457 return block->GetContainingInlinedBlock () != NULL;
1462 log->Printf ("SBFrame::IsInlined () => error: could not reconstruct frame object for this SBFrame.");
1468 log->Printf ("SBFrame::IsInlined () => error: process is running");
1476 SBFrame::GetFunctionName()
1478 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1479 const char *name = NULL;
1480 ExecutionContext exe_ctx(m_opaque_sp.get());
1481 StackFrame *frame = NULL;
1482 Target *target = exe_ctx.GetTargetPtr();
1483 Process *process = exe_ctx.GetProcessPtr();
1484 if (target && process)
1486 Process::StopLocker stop_locker;
1487 if (stop_locker.TryLock(&process->GetRunLock()))
1489 frame = exe_ctx.GetFramePtr();
1492 SymbolContext sc (frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol));
1495 Block *inlined_block = sc.block->GetContainingInlinedBlock ();
1498 const InlineFunctionInfo* inlined_info = inlined_block->GetInlinedFunctionInfo();
1499 name = inlined_info->GetName().AsCString();
1506 name = sc.function->GetName().GetCString();
1512 name = sc.symbol->GetName().GetCString();
1518 log->Printf ("SBFrame::GetFunctionName () => error: could not reconstruct frame object for this SBFrame.");
1524 log->Printf ("SBFrame::GetFunctionName() => error: process is running");