1 //===-- SBFunction.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/SBFunction.h"
11 #include "lldb/API/SBProcess.h"
12 #include "lldb/API/SBStream.h"
13 #include "lldb/Core/Disassembler.h"
14 #include "lldb/Core/Log.h"
15 #include "lldb/Core/Module.h"
16 #include "lldb/Symbol/CompileUnit.h"
17 #include "lldb/Symbol/Function.h"
18 #include "lldb/Symbol/Type.h"
19 #include "lldb/Symbol/VariableList.h"
20 #include "lldb/Target/ExecutionContext.h"
21 #include "lldb/Target/Target.h"
24 using namespace lldb_private;
26 SBFunction::SBFunction () :
31 SBFunction::SBFunction (lldb_private::Function *lldb_object_ptr) :
32 m_opaque_ptr (lldb_object_ptr)
36 SBFunction::SBFunction (const lldb::SBFunction &rhs) :
37 m_opaque_ptr (rhs.m_opaque_ptr)
42 SBFunction::operator = (const SBFunction &rhs)
44 m_opaque_ptr = rhs.m_opaque_ptr;
48 SBFunction::~SBFunction ()
54 SBFunction::IsValid () const
56 return m_opaque_ptr != NULL;
60 SBFunction::GetName() const
62 const char *cstr = NULL;
64 cstr = m_opaque_ptr->GetName().AsCString();
66 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
70 log->Printf ("SBFunction(%p)::GetName () => \"%s\"",
71 static_cast<void*>(m_opaque_ptr), cstr);
73 log->Printf ("SBFunction(%p)::GetName () => NULL",
74 static_cast<void*>(m_opaque_ptr));
80 SBFunction::GetDisplayName() const
82 const char *cstr = NULL;
84 cstr = m_opaque_ptr->GetMangled().GetDisplayDemangledName(m_opaque_ptr->GetLanguage()).AsCString();
86 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
90 log->Printf ("SBFunction(%p)::GetDisplayName () => \"%s\"",
91 static_cast<void*>(m_opaque_ptr), cstr);
93 log->Printf ("SBFunction(%p)::GetDisplayName () => NULL",
94 static_cast<void*>(m_opaque_ptr));
100 SBFunction::GetMangledName () const
102 const char *cstr = NULL;
104 cstr = m_opaque_ptr->GetMangled().GetMangledName().AsCString();
105 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
109 log->Printf ("SBFunction(%p)::GetMangledName () => \"%s\"",
110 static_cast<void*>(m_opaque_ptr), cstr);
112 log->Printf ("SBFunction(%p)::GetMangledName () => NULL",
113 static_cast<void*>(m_opaque_ptr));
119 SBFunction::operator == (const SBFunction &rhs) const
121 return m_opaque_ptr == rhs.m_opaque_ptr;
125 SBFunction::operator != (const SBFunction &rhs) const
127 return m_opaque_ptr != rhs.m_opaque_ptr;
131 SBFunction::GetDescription (SBStream &s)
135 s.Printf ("SBFunction: id = 0x%8.8" PRIx64 ", name = %s",
136 m_opaque_ptr->GetID(),
137 m_opaque_ptr->GetName().AsCString());
138 Type *func_type = m_opaque_ptr->GetType();
140 s.Printf(", type = %s", func_type->GetName().AsCString());
143 s.Printf ("No value");
148 SBFunction::GetInstructions (SBTarget target)
150 return GetInstructions (target, NULL);
154 SBFunction::GetInstructions (SBTarget target, const char *flavor)
156 SBInstructionList sb_instructions;
159 Mutex::Locker api_locker;
160 ExecutionContext exe_ctx;
161 TargetSP target_sp (target.GetSP());
164 api_locker.Lock (target_sp->GetAPIMutex());
165 target_sp->CalculateExecutionContext (exe_ctx);
166 exe_ctx.SetProcessSP(target_sp->GetProcessSP());
168 ModuleSP module_sp (m_opaque_ptr->GetAddressRange().GetBaseAddress().GetModule());
171 const bool prefer_file_cache = false;
172 sb_instructions.SetDisassembler (Disassembler::DisassembleRange (module_sp->GetArchitecture(),
176 m_opaque_ptr->GetAddressRange(),
180 return sb_instructions;
183 lldb_private::Function *
190 SBFunction::reset (lldb_private::Function *lldb_object_ptr)
192 m_opaque_ptr = lldb_object_ptr;
196 SBFunction::GetStartAddress ()
200 addr.SetAddress (&m_opaque_ptr->GetAddressRange().GetBaseAddress());
205 SBFunction::GetEndAddress ()
210 addr_t byte_size = m_opaque_ptr->GetAddressRange().GetByteSize();
213 addr.SetAddress (&m_opaque_ptr->GetAddressRange().GetBaseAddress());
214 addr->Slide (byte_size);
221 SBFunction::GetArgumentName (uint32_t arg_idx)
225 Block &block = m_opaque_ptr->GetBlock(true);
226 VariableListSP variable_list_sp = block.GetBlockVariableList(true);
227 if (variable_list_sp)
229 VariableList arguments;
230 variable_list_sp->AppendVariablesWithScope (eValueTypeVariableArgument, arguments, true);
231 lldb::VariableSP variable_sp = arguments.GetVariableAtIndex(arg_idx);
233 return variable_sp->GetName().GetCString();
240 SBFunction::GetPrologueByteSize ()
243 return m_opaque_ptr->GetPrologueByteSize();
248 SBFunction::GetType ()
253 Type *function_type = m_opaque_ptr->GetType();
255 sb_type.ref().SetType (function_type->shared_from_this());
261 SBFunction::GetBlock ()
265 sb_block.SetPtr (&m_opaque_ptr->GetBlock (true));
270 SBFunction::GetLanguage ()
274 if (m_opaque_ptr->GetCompileUnit())
275 return m_opaque_ptr->GetCompileUnit()->GetLanguage();
277 return lldb::eLanguageTypeUnknown;
281 SBFunction::GetIsOptimized ()
285 if (m_opaque_ptr->GetCompileUnit())
286 return m_opaque_ptr->GetCompileUnit()->GetIsOptimized();