Chris Lattner | 30fdc8d | 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 | |
Stephen Wilson | 8acdbb8 | 2011-04-08 13:36:44 +0000 | [diff] [blame] | 10 | #include <limits.h> |
| 11 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 12 | #include "lldb/API/SBFileSpec.h" |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 13 | #include "lldb/API/SBStream.h" |
Greg Clayton | 53239f0 | 2011-02-08 05:05:52 +0000 | [diff] [blame] | 14 | #include "lldb/Host/FileSpec.h" |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 15 | #include "lldb/Core/Log.h" |
Greg Clayton | da7bc7d | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 16 | #include "lldb/Core/Stream.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | |
| 18 | using namespace lldb; |
| 19 | using namespace lldb_private; |
| 20 | |
| 21 | |
| 22 | |
| 23 | SBFileSpec::SBFileSpec () : |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 24 | m_opaque_ap(new lldb_private::FileSpec()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 25 | { |
| 26 | } |
| 27 | |
| 28 | SBFileSpec::SBFileSpec (const SBFileSpec &rhs) : |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 29 | m_opaque_ap(new lldb_private::FileSpec(*rhs.m_opaque_ap)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 30 | { |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 31 | } |
Caroline Tice | 750cd17 | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 32 | |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 33 | SBFileSpec::SBFileSpec (const lldb_private::FileSpec& fspec) : |
| 34 | m_opaque_ap(new lldb_private::FileSpec(fspec)) |
| 35 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 36 | } |
| 37 | |
Greg Clayton | 274060b | 2010-10-20 20:54:39 +0000 | [diff] [blame] | 38 | // Deprected!!! |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 39 | SBFileSpec::SBFileSpec (const char *path) : |
Greg Clayton | 274060b | 2010-10-20 20:54:39 +0000 | [diff] [blame] | 40 | m_opaque_ap(new FileSpec (path, true)) |
| 41 | { |
| 42 | } |
| 43 | |
| 44 | SBFileSpec::SBFileSpec (const char *path, bool resolve) : |
| 45 | m_opaque_ap(new FileSpec (path, resolve)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 46 | { |
| 47 | } |
| 48 | |
| 49 | SBFileSpec::~SBFileSpec () |
| 50 | { |
| 51 | } |
| 52 | |
| 53 | const SBFileSpec & |
| 54 | SBFileSpec::operator = (const SBFileSpec &rhs) |
| 55 | { |
| 56 | if (this != &rhs) |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 57 | *m_opaque_ap = *rhs.m_opaque_ap; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 58 | return *this; |
| 59 | } |
| 60 | |
| 61 | bool |
| 62 | SBFileSpec::IsValid() const |
| 63 | { |
Sean Callanan | 9076c0f | 2013-10-04 21:35:29 +0000 | [diff] [blame] | 64 | return m_opaque_ap->operator bool(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | bool |
| 68 | SBFileSpec::Exists () const |
| 69 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 70 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 71 | |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 72 | bool result = m_opaque_ap->Exists(); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 73 | |
| 74 | if (log) |
Greg Clayton | 93aa84e | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 75 | log->Printf ("SBFileSpec(%p)::Exists () => %s", m_opaque_ap.get(), (result ? "true" : "false")); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 76 | |
| 77 | return result; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Caroline Tice | 428a9a5 | 2010-09-10 04:48:55 +0000 | [diff] [blame] | 80 | bool |
| 81 | SBFileSpec::ResolveExecutableLocation () |
| 82 | { |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 83 | return m_opaque_ap->ResolveExecutableLocation (); |
Caroline Tice | 428a9a5 | 2010-09-10 04:48:55 +0000 | [diff] [blame] | 84 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 85 | |
| 86 | int |
| 87 | SBFileSpec::ResolvePath (const char *src_path, char *dst_path, size_t dst_len) |
| 88 | { |
| 89 | return lldb_private::FileSpec::Resolve (src_path, dst_path, dst_len); |
| 90 | } |
| 91 | |
| 92 | const char * |
Johnny Chen | 23fd10c | 2010-08-27 22:35:26 +0000 | [diff] [blame] | 93 | SBFileSpec::GetFilename() const |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 94 | { |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 95 | const char *s = m_opaque_ap->GetFilename().AsCString(); |
Caroline Tice | 750cd17 | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 96 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 97 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 98 | if (log) |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 99 | { |
| 100 | if (s) |
| 101 | log->Printf ("SBFileSpec(%p)::GetFilename () => \"%s\"", m_opaque_ap.get(), s); |
| 102 | else |
| 103 | log->Printf ("SBFileSpec(%p)::GetFilename () => NULL", m_opaque_ap.get()); |
| 104 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 105 | |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 106 | return s; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | const char * |
| 110 | SBFileSpec::GetDirectory() const |
| 111 | { |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 112 | const char *s = m_opaque_ap->GetDirectory().AsCString(); |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 113 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 114 | if (log) |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 115 | { |
| 116 | if (s) |
| 117 | log->Printf ("SBFileSpec(%p)::GetDirectory () => \"%s\"", m_opaque_ap.get(), s); |
| 118 | else |
| 119 | log->Printf ("SBFileSpec(%p)::GetDirectory () => NULL", m_opaque_ap.get()); |
| 120 | } |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 121 | return s; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 122 | } |
| 123 | |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame^] | 124 | void |
| 125 | SBFileSpec::SetFilename(const char *filename) |
| 126 | { |
| 127 | if (filename && filename[0]) |
| 128 | m_opaque_ap->GetFilename().SetCString(filename); |
| 129 | else |
| 130 | m_opaque_ap->GetFilename().Clear(); |
| 131 | } |
| 132 | |
| 133 | void |
| 134 | SBFileSpec::SetDirectory(const char *directory) |
| 135 | { |
| 136 | if (directory && directory[0]) |
| 137 | m_opaque_ap->GetDirectory().SetCString(directory); |
| 138 | else |
| 139 | m_opaque_ap->GetDirectory().Clear(); |
| 140 | } |
| 141 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 142 | uint32_t |
| 143 | SBFileSpec::GetPath (char *dst_path, size_t dst_len) const |
| 144 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 145 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 146 | |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 147 | uint32_t result = m_opaque_ap->GetPath (dst_path, dst_len); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 148 | |
| 149 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 150 | log->Printf ("SBFileSpec(%p)::GetPath (dst_path=\"%.*s\", dst_len=%" PRIu64 ") => %u", |
Greg Clayton | 43e0af0 | 2012-09-18 18:04:04 +0000 | [diff] [blame] | 151 | m_opaque_ap.get(), result, dst_path, (uint64_t)dst_len, result); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 152 | |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 153 | if (result == 0 && dst_path && dst_len > 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 154 | *dst_path = '\0'; |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 155 | return result; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | |
| 159 | const lldb_private::FileSpec * |
| 160 | SBFileSpec::operator->() const |
| 161 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 162 | return m_opaque_ap.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | const lldb_private::FileSpec * |
| 166 | SBFileSpec::get() const |
| 167 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 168 | return m_opaque_ap.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | |
| 172 | const lldb_private::FileSpec & |
| 173 | SBFileSpec::operator*() const |
| 174 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 175 | return *m_opaque_ap.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | const lldb_private::FileSpec & |
| 179 | SBFileSpec::ref() const |
| 180 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 181 | return *m_opaque_ap.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | |
| 185 | void |
| 186 | SBFileSpec::SetFileSpec (const lldb_private::FileSpec& fs) |
| 187 | { |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 188 | *m_opaque_ap = fs; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 191 | bool |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 192 | SBFileSpec::GetDescription (SBStream &description) const |
| 193 | { |
Greg Clayton | da7bc7d | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 194 | Stream &strm = description.ref(); |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 195 | char path[PATH_MAX]; |
| 196 | if (m_opaque_ap->GetPath(path, sizeof(path))) |
| 197 | strm.PutCString (path); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 198 | return true; |
| 199 | } |