SBInstruction.cpp revision 5c4c746a3a83c1aad411c6cdc5f9525a4fc2d17e
1//===-- SBInstruction.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/SBInstruction.h" 11 12#include "lldb/API/SBAddress.h" 13#include "lldb/API/SBInstruction.h" 14#include "lldb/API/SBStream.h" 15 16#include "lldb/Core/Disassembler.h" 17#include "lldb/Core/StreamFile.h" 18 19using namespace lldb; 20using namespace lldb_private; 21 22SBInstruction::SBInstruction () 23{ 24} 25 26SBInstruction::SBInstruction (const lldb::InstructionSP& inst_sp) : 27 m_opaque_sp (inst_sp) 28{ 29} 30 31SBInstruction::~SBInstruction () 32{ 33} 34 35bool 36SBInstruction::IsValid() 37{ 38 return (m_opaque_sp.get() != NULL); 39} 40 41SBAddress 42SBInstruction::GetAddress() 43{ 44 SBAddress sb_addr; 45 if (m_opaque_sp && m_opaque_sp->GetAddress().IsValid()) 46 sb_addr.SetAddress(&m_opaque_sp->GetAddress()); 47 return sb_addr; 48} 49 50size_t 51SBInstruction::GetByteSize () 52{ 53 if (m_opaque_sp) 54 return m_opaque_sp->GetByteSize(); 55 return 0; 56} 57 58bool 59SBInstruction::DoesBranch () 60{ 61 if (m_opaque_sp) 62 return m_opaque_sp->DoesBranch (); 63 return false; 64} 65 66void 67SBInstruction::SetOpaque (const lldb::InstructionSP &inst_sp) 68{ 69 m_opaque_sp = inst_sp; 70} 71 72bool 73SBInstruction::GetDescription (lldb::SBStream &s) 74{ 75 if (m_opaque_sp) 76 { 77 // Use the "ref()" instead of the "get()" accessor in case the SBStream 78 // didn't have a stream already created, one will get created... 79 m_opaque_sp->Dump (&s.ref(), true, NULL, 0, NULL, false); 80 return true; 81 } 82 return false; 83} 84 85void 86SBInstruction::Print (FILE *out) 87{ 88 if (out == NULL) 89 return; 90 91 if (m_opaque_sp) 92 { 93 StreamFile out_stream (out); 94 m_opaque_sp->Dump (&out_stream, true, NULL, 0, NULL, false); 95 } 96} 97