Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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" |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 11 | #include "lldb/API/SBStream.h" |
Greg Clayton | 5f54ac3 | 2011-02-08 05:05:52 +0000 | [diff] [blame] | 12 | #include "lldb/Host/FileSpec.h" |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 13 | #include "lldb/Core/Log.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 14 | |
| 15 | using namespace lldb; |
| 16 | using namespace lldb_private; |
| 17 | |
| 18 | |
| 19 | |
| 20 | SBFileSpec::SBFileSpec () : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 21 | m_opaque_ap() |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | { |
| 23 | } |
| 24 | |
| 25 | SBFileSpec::SBFileSpec (const SBFileSpec &rhs) : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 26 | m_opaque_ap() |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 27 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 28 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 29 | |
| 30 | if (rhs.m_opaque_ap.get()) |
| 31 | m_opaque_ap.reset (new FileSpec (rhs.get())); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 32 | |
| 33 | if (log) |
| 34 | { |
| 35 | SBStream sstr; |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 36 | GetDescription (sstr); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 37 | log->Printf ("SBFileSpec::SBFileSpec (const SBFileSpec rhs.ap=%p) => SBFileSpec(%p): %s", |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 38 | rhs.m_opaque_ap.get(), m_opaque_ap.get(), sstr.GetData()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 39 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 40 | } |
| 41 | |
Greg Clayton | 537a7a8 | 2010-10-20 20:54:39 +0000 | [diff] [blame] | 42 | // Deprected!!! |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 43 | SBFileSpec::SBFileSpec (const char *path) : |
Greg Clayton | 537a7a8 | 2010-10-20 20:54:39 +0000 | [diff] [blame] | 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)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 50 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 51 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 52 | |
| 53 | if (log) |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 54 | log->Printf ("SBFileSpec::SBFileSpec (path=\"%s\", resolve=%i) => SBFileSpec(%p)", path, |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 55 | resolve, m_opaque_ap.get()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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()) |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 68 | m_opaque_ap.reset (new lldb_private::FileSpec(*rhs.m_opaque_ap.get())); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 69 | } |
| 70 | return *this; |
| 71 | } |
| 72 | |
| 73 | bool |
| 74 | SBFileSpec::IsValid() const |
| 75 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 76 | return m_opaque_ap.get() != NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | bool |
| 80 | SBFileSpec::Exists () const |
| 81 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 82 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 83 | |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 84 | bool result = false; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 85 | if (m_opaque_ap.get()) |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 86 | result = m_opaque_ap->Exists(); |
| 87 | |
| 88 | if (log) |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 89 | log->Printf ("SBFileSpec(%p)::Exists () => %s", m_opaque_ap.get(), (result ? "true" : "false")); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 90 | |
| 91 | return result; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Caroline Tice | eddffe9 | 2010-09-10 04:48:55 +0000 | [diff] [blame] | 94 | bool |
| 95 | SBFileSpec::ResolveExecutableLocation () |
| 96 | { |
| 97 | if (m_opaque_ap.get()) |
| 98 | return m_opaque_ap->ResolveExecutableLocation (); |
| 99 | return false; |
| 100 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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 * |
Johnny Chen | 4ead2e9 | 2010-08-27 22:35:26 +0000 | [diff] [blame] | 109 | SBFileSpec::GetFilename() const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 110 | { |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 111 | const char *s = NULL; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 112 | if (m_opaque_ap.get()) |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 113 | s = m_opaque_ap->GetFilename().AsCString(); |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 114 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 115 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 116 | if (log) |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 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 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 123 | |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 124 | return s; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | const char * |
| 128 | SBFileSpec::GetDirectory() const |
| 129 | { |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 130 | const char *s = NULL; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 131 | if (m_opaque_ap.get()) |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 132 | s = m_opaque_ap->GetDirectory().AsCString(); |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 133 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 134 | if (log) |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 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 | } |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 141 | return s; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | uint32_t |
| 145 | SBFileSpec::GetPath (char *dst_path, size_t dst_len) const |
| 146 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 147 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 148 | |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 149 | uint32_t result = 0; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 150 | if (m_opaque_ap.get()) |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 151 | result = m_opaque_ap->GetPath (dst_path, dst_len); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 152 | |
| 153 | if (log) |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 154 | log->Printf ("SBFileSpec(%p)::GetPath (dst_path=\"%.*s\", dst_len=%zu) => %u", |
| 155 | m_opaque_ap.get(), result, dst_path, dst_len, result); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 156 | |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 157 | if (result == 0 && dst_path && dst_len > 0) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 158 | *dst_path = '\0'; |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 159 | return result; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | |
| 163 | const lldb_private::FileSpec * |
| 164 | SBFileSpec::operator->() const |
| 165 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 166 | return m_opaque_ap.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | const lldb_private::FileSpec * |
| 170 | SBFileSpec::get() const |
| 171 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 172 | return m_opaque_ap.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | |
| 176 | const lldb_private::FileSpec & |
| 177 | SBFileSpec::operator*() const |
| 178 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 179 | return *m_opaque_ap.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | const lldb_private::FileSpec & |
| 183 | SBFileSpec::ref() const |
| 184 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 185 | return *m_opaque_ap.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | |
| 189 | void |
| 190 | SBFileSpec::SetFileSpec (const lldb_private::FileSpec& fs) |
| 191 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 192 | if (m_opaque_ap.get()) |
| 193 | *m_opaque_ap = fs; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 194 | else |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 195 | m_opaque_ap.reset (new FileSpec (fs)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 196 | } |
| 197 | |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 198 | bool |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 199 | SBFileSpec::GetDescription (SBStream &description) const |
| 200 | { |
| 201 | if (m_opaque_ap.get()) |
| 202 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 203 | char path[PATH_MAX]; |
| 204 | if (m_opaque_ap->GetPath(path, sizeof(path))) |
| 205 | description.Printf ("%s", path); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 206 | } |
| 207 | else |
| 208 | description.Printf ("No value"); |
| 209 | |
| 210 | return true; |
| 211 | } |