1 //===-- SBFileSpec.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/SBFileSpec.h" 11 #include "lldb/API/SBStream.h" 12 #include "lldb/Core/FileSpec.h" 13 #include "lldb/Core/Log.h" 14 15 using namespace lldb; 16 using namespace lldb_private; 17 18 19 20 SBFileSpec::SBFileSpec () : 21 m_opaque_ap() 22 { 23 } 24 25 SBFileSpec::SBFileSpec (const SBFileSpec &rhs) : 26 m_opaque_ap() 27 { 28 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 29 30 if (rhs.m_opaque_ap.get()) 31 m_opaque_ap.reset (new FileSpec (rhs.get())); 32 33 if (log) 34 { 35 SBStream sstr; 36 GetDescription (sstr); 37 log->Printf ("SBFileSpec::SBFileSpec (const SBFileSpec rhs.ap=%p) => SBFileSpec(%p): %s", 38 rhs.m_opaque_ap.get(), m_opaque_ap.get(), sstr.GetData()); 39 } 40 } 41 42 // Deprected!!! 43 SBFileSpec::SBFileSpec (const char *path) : 44 m_opaque_ap(new FileSpec (path, true)) 45 { 46 } 47 48 SBFileSpec::SBFileSpec (const char *path, bool resolve) : 49 m_opaque_ap(new FileSpec (path, resolve)) 50 { 51 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 52 53 if (log) 54 log->Printf ("SBFileSpec::SBFileSpec (path=\"%s\", resolve=%i) => SBFileSpec(%p)", path, 55 resolve, m_opaque_ap.get()); 56 } 57 58 SBFileSpec::~SBFileSpec () 59 { 60 } 61 62 const SBFileSpec & 63 SBFileSpec::operator = (const SBFileSpec &rhs) 64 { 65 if (this != &rhs) 66 { 67 if (rhs.IsValid()) 68 m_opaque_ap.reset (new lldb_private::FileSpec(*rhs.m_opaque_ap.get())); 69 } 70 return *this; 71 } 72 73 bool 74 SBFileSpec::IsValid() const 75 { 76 return m_opaque_ap.get() != NULL; 77 } 78 79 bool 80 SBFileSpec::Exists () const 81 { 82 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 83 84 bool result = false; 85 if (m_opaque_ap.get()) 86 result = m_opaque_ap->Exists(); 87 88 if (log) 89 log->Printf ("SBFileSpec(%p)::Exists () => %s", m_opaque_ap.get(), (result ? "true" : "false")); 90 91 return result; 92 } 93 94 bool 95 SBFileSpec::ResolveExecutableLocation () 96 { 97 if (m_opaque_ap.get()) 98 return m_opaque_ap->ResolveExecutableLocation (); 99 return false; 100 } 101 102 int 103 SBFileSpec::ResolvePath (const char *src_path, char *dst_path, size_t dst_len) 104 { 105 return lldb_private::FileSpec::Resolve (src_path, dst_path, dst_len); 106 } 107 108 const char * 109 SBFileSpec::GetFilename() const 110 { 111 const char *s = NULL; 112 if (m_opaque_ap.get()) 113 s = m_opaque_ap->GetFilename().AsCString(); 114 115 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 116 if (log) 117 { 118 if (s) 119 log->Printf ("SBFileSpec(%p)::GetFilename () => \"%s\"", m_opaque_ap.get(), s); 120 else 121 log->Printf ("SBFileSpec(%p)::GetFilename () => NULL", m_opaque_ap.get()); 122 } 123 124 return s; 125 } 126 127 const char * 128 SBFileSpec::GetDirectory() const 129 { 130 const char *s = NULL; 131 if (m_opaque_ap.get()) 132 s = m_opaque_ap->GetDirectory().AsCString(); 133 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 134 if (log) 135 { 136 if (s) 137 log->Printf ("SBFileSpec(%p)::GetDirectory () => \"%s\"", m_opaque_ap.get(), s); 138 else 139 log->Printf ("SBFileSpec(%p)::GetDirectory () => NULL", m_opaque_ap.get()); 140 } 141 return s; 142 } 143 144 uint32_t 145 SBFileSpec::GetPath (char *dst_path, size_t dst_len) const 146 { 147 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 148 149 uint32_t result = 0; 150 if (m_opaque_ap.get()) 151 result = m_opaque_ap->GetPath (dst_path, dst_len); 152 153 if (log) 154 log->Printf ("SBFileSpec(%p)::GetPath (dst_path=\"%.*s\", dst_len=%zu) => %u", 155 m_opaque_ap.get(), result, dst_path, dst_len, result); 156 157 if (result == 0 && dst_path && dst_len > 0) 158 *dst_path = '\0'; 159 return result; 160 } 161 162 163 const lldb_private::FileSpec * 164 SBFileSpec::operator->() const 165 { 166 return m_opaque_ap.get(); 167 } 168 169 const lldb_private::FileSpec * 170 SBFileSpec::get() const 171 { 172 return m_opaque_ap.get(); 173 } 174 175 176 const lldb_private::FileSpec & 177 SBFileSpec::operator*() const 178 { 179 return *m_opaque_ap.get(); 180 } 181 182 const lldb_private::FileSpec & 183 SBFileSpec::ref() const 184 { 185 return *m_opaque_ap.get(); 186 } 187 188 189 void 190 SBFileSpec::SetFileSpec (const lldb_private::FileSpec& fs) 191 { 192 if (m_opaque_ap.get()) 193 *m_opaque_ap = fs; 194 else 195 m_opaque_ap.reset (new FileSpec (fs)); 196 } 197 198 bool 199 SBFileSpec::GetDescription (SBStream &description) const 200 { 201 if (m_opaque_ap.get()) 202 { 203 char path[PATH_MAX]; 204 if (m_opaque_ap->GetPath(path, sizeof(path))) 205 description.Printf ("%s", path); 206 } 207 else 208 description.Printf ("No value"); 209 210 return true; 211 } 212