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 | { |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 64 | return *m_opaque_ap; |
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 | |
| 124 | uint32_t |
| 125 | SBFileSpec::GetPath (char *dst_path, size_t dst_len) const |
| 126 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 127 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 128 | |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 129 | uint32_t result = m_opaque_ap->GetPath (dst_path, dst_len); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 130 | |
| 131 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 132 | log->Printf ("SBFileSpec(%p)::GetPath (dst_path=\"%.*s\", dst_len=%" PRIu64 ") => %u", |
Greg Clayton | 43e0af0 | 2012-09-18 18:04:04 +0000 | [diff] [blame] | 133 | m_opaque_ap.get(), result, dst_path, (uint64_t)dst_len, result); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 134 | |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 135 | if (result == 0 && dst_path && dst_len > 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 136 | *dst_path = '\0'; |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 137 | return result; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | |
| 141 | const lldb_private::FileSpec * |
| 142 | SBFileSpec::operator->() const |
| 143 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 144 | return m_opaque_ap.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | const lldb_private::FileSpec * |
| 148 | SBFileSpec::get() const |
| 149 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 150 | return m_opaque_ap.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | |
| 154 | const lldb_private::FileSpec & |
| 155 | SBFileSpec::operator*() const |
| 156 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 157 | return *m_opaque_ap.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | const lldb_private::FileSpec & |
| 161 | SBFileSpec::ref() const |
| 162 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 163 | return *m_opaque_ap.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | |
| 167 | void |
| 168 | SBFileSpec::SetFileSpec (const lldb_private::FileSpec& fs) |
| 169 | { |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 170 | *m_opaque_ap = fs; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 171 | } |
| 172 | |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 173 | bool |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 174 | SBFileSpec::GetDescription (SBStream &description) const |
| 175 | { |
Greg Clayton | da7bc7d | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 176 | Stream &strm = description.ref(); |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 177 | char path[PATH_MAX]; |
| 178 | if (m_opaque_ap->GetPath(path, sizeof(path))) |
| 179 | strm.PutCString (path); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 180 | return true; |
| 181 | } |