1 //===-- SBCommandReturnObject.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/SBCommandReturnObject.h" 11 #include "lldb/API/SBStream.h" 12 13 #include "lldb/Interpreter/CommandReturnObject.h" 14 15 using namespace lldb; 16 using namespace lldb_private; 17 18 SBCommandReturnObject::SBCommandReturnObject () : 19 m_opaque_ap (new CommandReturnObject ()) 20 { 21 } 22 23 SBCommandReturnObject::~SBCommandReturnObject () 24 { 25 // m_opaque_ap will automatically delete any pointer it owns 26 } 27 28 bool 29 SBCommandReturnObject::IsValid() const 30 { 31 return m_opaque_ap.get() != NULL; 32 } 33 34 35 const char * 36 SBCommandReturnObject::GetOutput () 37 { 38 if (m_opaque_ap.get()) 39 return m_opaque_ap->GetOutputStream().GetData(); 40 return NULL; 41 } 42 43 const char * 44 SBCommandReturnObject::GetError () 45 { 46 if (m_opaque_ap.get()) 47 return m_opaque_ap->GetErrorStream().GetData(); 48 return NULL; 49 } 50 51 size_t 52 SBCommandReturnObject::GetOutputSize () 53 { 54 if (m_opaque_ap.get()) 55 return m_opaque_ap->GetOutputStream().GetSize(); 56 return 0; 57 } 58 59 size_t 60 SBCommandReturnObject::GetErrorSize () 61 { 62 if (m_opaque_ap.get()) 63 return m_opaque_ap->GetErrorStream().GetSize(); 64 return 0; 65 } 66 67 size_t 68 SBCommandReturnObject::PutOutput (FILE *fh) 69 { 70 if (fh) 71 { 72 size_t num_bytes = GetOutputSize (); 73 if (num_bytes) 74 return ::fprintf (fh, "%s", GetOutput()); 75 } 76 return 0; 77 } 78 79 size_t 80 SBCommandReturnObject::PutError (FILE *fh) 81 { 82 if (fh) 83 { 84 size_t num_bytes = GetErrorSize (); 85 if (num_bytes) 86 return ::fprintf (fh, "%s", GetError()); 87 } 88 return 0; 89 } 90 91 void 92 SBCommandReturnObject::Clear() 93 { 94 if (m_opaque_ap.get()) 95 m_opaque_ap->Clear(); 96 } 97 98 lldb::ReturnStatus 99 SBCommandReturnObject::GetStatus() 100 { 101 if (m_opaque_ap.get()) 102 return m_opaque_ap->GetStatus(); 103 return lldb::eReturnStatusInvalid; 104 } 105 106 bool 107 SBCommandReturnObject::Succeeded () 108 { 109 if (m_opaque_ap.get()) 110 return m_opaque_ap->Succeeded(); 111 return false; 112 } 113 114 bool 115 SBCommandReturnObject::HasResult () 116 { 117 if (m_opaque_ap.get()) 118 return m_opaque_ap->HasResult(); 119 return false; 120 } 121 122 void 123 SBCommandReturnObject::AppendMessage (const char *message) 124 { 125 if (m_opaque_ap.get()) 126 m_opaque_ap->AppendMessage (message); 127 } 128 129 CommandReturnObject * 130 SBCommandReturnObject::operator ->() const 131 { 132 return m_opaque_ap.get(); 133 } 134 135 CommandReturnObject * 136 SBCommandReturnObject::get() const 137 { 138 return m_opaque_ap.get(); 139 } 140 141 CommandReturnObject & 142 SBCommandReturnObject::operator *() const 143 { 144 assert(m_opaque_ap.get()); 145 return *(m_opaque_ap.get()); 146 } 147 148 149 CommandReturnObject & 150 SBCommandReturnObject::ref() const 151 { 152 assert(m_opaque_ap.get()); 153 return *(m_opaque_ap.get()); 154 } 155 156 157 void 158 SBCommandReturnObject::SetLLDBObjectPtr (CommandReturnObject *ptr) 159 { 160 if (m_opaque_ap.get()) 161 m_opaque_ap.reset (ptr); 162 } 163 164 bool 165 SBCommandReturnObject::GetDescription (SBStream &description) 166 { 167 if (m_opaque_ap.get()) 168 { 169 description.Printf ("Status: "); 170 lldb::ReturnStatus status = m_opaque_ap->GetStatus(); 171 if (status == lldb::eReturnStatusStarted) 172 description.Printf ("Started"); 173 else if (status == lldb::eReturnStatusInvalid) 174 description.Printf ("Invalid"); 175 else if (m_opaque_ap->Succeeded()) 176 description.Printf ("Success"); 177 else 178 description.Printf ("Fail"); 179 180 if (GetOutputSize() > 0) 181 description.Printf ("\nOutput Message:\n%s", GetOutput()); 182 183 if (GetErrorSize() > 0) 184 description.Printf ("\nError Message:\n%s", GetError()); 185 } 186 else 187 description.Printf ("No value"); 188 189 return true; 190 } 191