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