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