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\"", m_opaque_ptr, cstr);
71 log->Printf ("SBFunction(%p)::GetName () => NULL", m_opaque_ptr);
77 SBFunction::GetMangledName () const
79 const char *cstr = NULL;
81 cstr = m_opaque_ptr->GetMangled().GetMangledName().AsCString();
82 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
86 log->Printf ("SBFunction(%p)::GetMangledName () => \"%s\"", m_opaque_ptr, cstr);
88 log->Printf ("SBFunction(%p)::GetMangledName () => NULL", m_opaque_ptr);
94 SBFunction::operator == (const SBFunction &rhs) const
96 return m_opaque_ptr == rhs.m_opaque_ptr;
100 SBFunction::operator != (const SBFunction &rhs) const
102 return m_opaque_ptr != rhs.m_opaque_ptr;
106 SBFunction::GetDescription (SBStream &s)
110 s.Printf ("SBFunction: id = 0x%8.8" PRIx64 ", name = %s",
111 m_opaque_ptr->GetID(),
112 m_opaque_ptr->GetName().AsCString());
113 Type *func_type = m_opaque_ptr->GetType();
115 s.Printf(", type = %s", func_type->GetName().AsCString());
118 s.Printf ("No value");
123 SBFunction::GetInstructions (SBTarget target)
125 return GetInstructions (target, NULL);
129 SBFunction::GetInstructions (SBTarget target, const char *flavor)
131 SBInstructionList sb_instructions;
134 Mutex::Locker api_locker;
135 ExecutionContext exe_ctx;
136 TargetSP target_sp (target.GetSP());
139 api_locker.Lock (target_sp->GetAPIMutex());
140 target_sp->CalculateExecutionContext (exe_ctx);
141 exe_ctx.SetProcessSP(target_sp->GetProcessSP());
143 ModuleSP module_sp (m_opaque_ptr->GetAddressRange().GetBaseAddress().GetModule());
146 const bool prefer_file_cache = false;
147 sb_instructions.SetDisassembler (Disassembler::DisassembleRange (module_sp->GetArchitecture(),
151 m_opaque_ptr->GetAddressRange(),
155 return sb_instructions;
158 lldb_private::Function *
165 SBFunction::reset (lldb_private::Function *lldb_object_ptr)
167 m_opaque_ptr = lldb_object_ptr;
171 SBFunction::GetStartAddress ()
175 addr.SetAddress (&m_opaque_ptr->GetAddressRange().GetBaseAddress());
180 SBFunction::GetEndAddress ()
185 addr_t byte_size = m_opaque_ptr->GetAddressRange().GetByteSize();
188 addr.SetAddress (&m_opaque_ptr->GetAddressRange().GetBaseAddress());
189 addr->Slide (byte_size);
197 SBFunction::GetPrologueByteSize ()
200 return m_opaque_ptr->GetPrologueByteSize();
205 SBFunction::GetType ()
210 Type *function_type = m_opaque_ptr->GetType();
212 sb_type.ref().SetType (function_type->shared_from_this());
218 SBFunction::GetBlock ()
222 sb_block.SetPtr (&m_opaque_ptr->GetBlock (true));