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/Target/ExecutionContext.h"
20 #include "lldb/Target/Target.h"
23 using namespace lldb_private;
25 SBFunction::SBFunction () :
30 SBFunction::SBFunction (lldb_private::Function *lldb_object_ptr) :
31 m_opaque_ptr (lldb_object_ptr)
35 SBFunction::SBFunction (const lldb::SBFunction &rhs) :
36 m_opaque_ptr (rhs.m_opaque_ptr)
41 SBFunction::operator = (const SBFunction &rhs)
43 m_opaque_ptr = rhs.m_opaque_ptr;
47 SBFunction::~SBFunction ()
53 SBFunction::IsValid () const
55 return m_opaque_ptr != NULL;
59 SBFunction::GetName() const
61 const char *cstr = NULL;
63 cstr = m_opaque_ptr->GetMangled().GetName().AsCString();
65 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
69 log->Printf ("SBFunction(%p)::GetName () => \"%s\"",
70 static_cast<void*>(m_opaque_ptr), cstr);
72 log->Printf ("SBFunction(%p)::GetName () => NULL",
73 static_cast<void*>(m_opaque_ptr));
79 SBFunction::GetMangledName () const
81 const char *cstr = NULL;
83 cstr = m_opaque_ptr->GetMangled().GetMangledName().AsCString();
84 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
88 log->Printf ("SBFunction(%p)::GetMangledName () => \"%s\"",
89 static_cast<void*>(m_opaque_ptr), cstr);
91 log->Printf ("SBFunction(%p)::GetMangledName () => NULL",
92 static_cast<void*>(m_opaque_ptr));
98 SBFunction::operator == (const SBFunction &rhs) const
100 return m_opaque_ptr == rhs.m_opaque_ptr;
104 SBFunction::operator != (const SBFunction &rhs) const
106 return m_opaque_ptr != rhs.m_opaque_ptr;
110 SBFunction::GetDescription (SBStream &s)
114 s.Printf ("SBFunction: id = 0x%8.8" PRIx64 ", name = %s",
115 m_opaque_ptr->GetID(),
116 m_opaque_ptr->GetName().AsCString());
117 Type *func_type = m_opaque_ptr->GetType();
119 s.Printf(", type = %s", func_type->GetName().AsCString());
122 s.Printf ("No value");
127 SBFunction::GetInstructions (SBTarget target)
129 return GetInstructions (target, NULL);
133 SBFunction::GetInstructions (SBTarget target, const char *flavor)
135 SBInstructionList sb_instructions;
138 Mutex::Locker api_locker;
139 ExecutionContext exe_ctx;
140 TargetSP target_sp (target.GetSP());
143 api_locker.Lock (target_sp->GetAPIMutex());
144 target_sp->CalculateExecutionContext (exe_ctx);
145 exe_ctx.SetProcessSP(target_sp->GetProcessSP());
147 ModuleSP module_sp (m_opaque_ptr->GetAddressRange().GetBaseAddress().GetModule());
150 const bool prefer_file_cache = false;
151 sb_instructions.SetDisassembler (Disassembler::DisassembleRange (module_sp->GetArchitecture(),
155 m_opaque_ptr->GetAddressRange(),
159 return sb_instructions;
162 lldb_private::Function *
169 SBFunction::reset (lldb_private::Function *lldb_object_ptr)
171 m_opaque_ptr = lldb_object_ptr;
175 SBFunction::GetStartAddress ()
179 addr.SetAddress (&m_opaque_ptr->GetAddressRange().GetBaseAddress());
184 SBFunction::GetEndAddress ()
189 addr_t byte_size = m_opaque_ptr->GetAddressRange().GetByteSize();
192 addr.SetAddress (&m_opaque_ptr->GetAddressRange().GetBaseAddress());
193 addr->Slide (byte_size);
201 SBFunction::GetPrologueByteSize ()
204 return m_opaque_ptr->GetPrologueByteSize();
209 SBFunction::GetType ()
214 Type *function_type = m_opaque_ptr->GetType();
216 sb_type.ref().SetType (function_type->shared_from_this());
222 SBFunction::GetBlock ()
226 sb_block.SetPtr (&m_opaque_ptr->GetBlock (true));
231 SBFunction::GetLanguage ()
235 if (m_opaque_ptr->GetCompileUnit())
236 return m_opaque_ptr->GetCompileUnit()->GetLanguage();
238 return lldb::eLanguageTypeUnknown;