SBFunction.cpp revision 5c4c746a3a83c1aad411c6cdc5f9525a4fc2d17e
1//===-- SBFunction.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/SBFunction.h" 11#include "lldb/API/SBProcess.h" 12#include "lldb/API/SBStream.h" 13#include "lldb/Core/Disassembler.h" 14#include "lldb/Core/Module.h" 15#include "lldb/Symbol/CompileUnit.h" 16#include "lldb/Symbol/Function.h" 17#include "lldb/Target/ExecutionContext.h" 18#include "lldb/Target/Target.h" 19 20using namespace lldb; 21using namespace lldb_private; 22 23SBFunction::SBFunction () : 24 m_opaque_ptr (NULL) 25{ 26} 27 28SBFunction::SBFunction (lldb_private::Function *lldb_object_ptr) : 29 m_opaque_ptr (lldb_object_ptr) 30{ 31} 32 33SBFunction::~SBFunction () 34{ 35 m_opaque_ptr = NULL; 36} 37 38bool 39SBFunction::IsValid () const 40{ 41 return m_opaque_ptr != NULL; 42} 43 44const char * 45SBFunction::GetName() const 46{ 47 if (m_opaque_ptr) 48 return m_opaque_ptr->GetMangled().GetName().AsCString(); 49 return NULL; 50} 51 52const char * 53SBFunction::GetMangledName () const 54{ 55 if (m_opaque_ptr) 56 return m_opaque_ptr->GetMangled().GetMangledName().AsCString(); 57 return NULL; 58} 59 60bool 61SBFunction::operator == (const SBFunction &rhs) const 62{ 63 return m_opaque_ptr == rhs.m_opaque_ptr; 64} 65 66bool 67SBFunction::operator != (const SBFunction &rhs) const 68{ 69 return m_opaque_ptr != rhs.m_opaque_ptr; 70} 71 72bool 73SBFunction::GetDescription (SBStream &description) 74{ 75 if (m_opaque_ptr) 76 { 77 description.ref(); 78 m_opaque_ptr->Dump (description.get(), false); 79 } 80 else 81 description.Printf ("No value"); 82 83 return true; 84} 85 86SBInstructionList 87SBFunction::GetInstructions (SBTarget target) 88{ 89 SBInstructionList sb_instructions; 90 if (m_opaque_ptr) 91 { 92 ExecutionContext exe_ctx; 93 if (target.IsValid()) 94 { 95 target->CalculateExecutionContext (exe_ctx); 96 exe_ctx.process = target->GetProcessSP().get(); 97 } 98 Module *module = m_opaque_ptr->GetAddressRange().GetBaseAddress().GetModule(); 99 if (module) 100 { 101 sb_instructions.SetDisassembler (Disassembler::DisassembleRange (module->GetArchitecture(), 102 exe_ctx, 103 m_opaque_ptr->GetAddressRange())); 104 } 105 } 106 return sb_instructions; 107} 108 109 110