blob: 4fd2866c9b05b27f326d637cb121302bce07d1be [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- 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 Wilson8acdbb82011-04-08 13:36:44 +000010#include <limits.h>
11
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012#include "lldb/API/SBFileSpec.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000013#include "lldb/API/SBStream.h"
Greg Clayton53239f02011-02-08 05:05:52 +000014#include "lldb/Host/FileSpec.h"
Caroline Ticeceb6b132010-10-26 03:11:13 +000015#include "lldb/Core/Log.h"
Greg Claytonda7bc7d2011-11-13 06:57:31 +000016#include "lldb/Core/Stream.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017
18using namespace lldb;
19using namespace lldb_private;
20
21
22
23SBFileSpec::SBFileSpec () :
Greg Clayton226cce22013-07-08 22:22:41 +000024 m_opaque_ap(new lldb_private::FileSpec())
Chris Lattner30fdc8d2010-06-08 16:52:24 +000025{
26}
27
28SBFileSpec::SBFileSpec (const SBFileSpec &rhs) :
Greg Clayton226cce22013-07-08 22:22:41 +000029 m_opaque_ap(new lldb_private::FileSpec(*rhs.m_opaque_ap))
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030{
Greg Clayton226cce22013-07-08 22:22:41 +000031}
Caroline Tice750cd172010-10-26 23:49:36 +000032
Greg Clayton226cce22013-07-08 22:22:41 +000033SBFileSpec::SBFileSpec (const lldb_private::FileSpec& fspec) :
34 m_opaque_ap(new lldb_private::FileSpec(fspec))
35{
Chris Lattner30fdc8d2010-06-08 16:52:24 +000036}
37
Greg Clayton274060b2010-10-20 20:54:39 +000038// Deprected!!!
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039SBFileSpec::SBFileSpec (const char *path) :
Greg Clayton274060b2010-10-20 20:54:39 +000040 m_opaque_ap(new FileSpec (path, true))
41{
42}
43
44SBFileSpec::SBFileSpec (const char *path, bool resolve) :
45 m_opaque_ap(new FileSpec (path, resolve))
Chris Lattner30fdc8d2010-06-08 16:52:24 +000046{
47}
48
49SBFileSpec::~SBFileSpec ()
50{
51}
52
53const SBFileSpec &
54SBFileSpec::operator = (const SBFileSpec &rhs)
55{
56 if (this != &rhs)
Greg Clayton226cce22013-07-08 22:22:41 +000057 *m_opaque_ap = *rhs.m_opaque_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000058 return *this;
59}
60
61bool
62SBFileSpec::IsValid() const
63{
Sean Callanan9076c0f2013-10-04 21:35:29 +000064 return m_opaque_ap->operator bool();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000065}
66
67bool
68SBFileSpec::Exists () const
69{
Greg Clayton5160ce52013-03-27 23:08:40 +000070 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +000071
Greg Clayton226cce22013-07-08 22:22:41 +000072 bool result = m_opaque_ap->Exists();
Caroline Ticeceb6b132010-10-26 03:11:13 +000073
74 if (log)
Greg Clayton93aa84e2010-10-29 04:59:35 +000075 log->Printf ("SBFileSpec(%p)::Exists () => %s", m_opaque_ap.get(), (result ? "true" : "false"));
Caroline Ticeceb6b132010-10-26 03:11:13 +000076
77 return result;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000078}
79
Caroline Tice428a9a52010-09-10 04:48:55 +000080bool
81SBFileSpec::ResolveExecutableLocation ()
82{
Greg Clayton226cce22013-07-08 22:22:41 +000083 return m_opaque_ap->ResolveExecutableLocation ();
Caroline Tice428a9a52010-09-10 04:48:55 +000084}
Chris Lattner30fdc8d2010-06-08 16:52:24 +000085
86int
87SBFileSpec::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
92const char *
Johnny Chen23fd10c2010-08-27 22:35:26 +000093SBFileSpec::GetFilename() const
Chris Lattner30fdc8d2010-06-08 16:52:24 +000094{
Greg Clayton226cce22013-07-08 22:22:41 +000095 const char *s = m_opaque_ap->GetFilename().AsCString();
Caroline Tice750cd172010-10-26 23:49:36 +000096
Greg Clayton5160ce52013-03-27 23:08:40 +000097 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +000098 if (log)
Greg Claytoncfd1ace2010-10-31 03:01:06 +000099 {
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 Ticeceb6b132010-10-26 03:11:13 +0000105
Greg Clayton48381312010-10-30 04:51:46 +0000106 return s;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000107}
108
109const char *
110SBFileSpec::GetDirectory() const
111{
Greg Clayton226cce22013-07-08 22:22:41 +0000112 const char *s = m_opaque_ap->GetDirectory().AsCString();
Greg Clayton5160ce52013-03-27 23:08:40 +0000113 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000114 if (log)
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000115 {
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 Clayton48381312010-10-30 04:51:46 +0000121 return s;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000122}
123
Greg Claytonfbb76342013-11-20 21:07:01 +0000124void
125SBFileSpec::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
133void
134SBFileSpec::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 Lattner30fdc8d2010-06-08 16:52:24 +0000142uint32_t
143SBFileSpec::GetPath (char *dst_path, size_t dst_len) const
144{
Greg Clayton5160ce52013-03-27 23:08:40 +0000145 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000146
Greg Clayton226cce22013-07-08 22:22:41 +0000147 uint32_t result = m_opaque_ap->GetPath (dst_path, dst_len);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000148
149 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +0000150 log->Printf ("SBFileSpec(%p)::GetPath (dst_path=\"%.*s\", dst_len=%" PRIu64 ") => %u",
Greg Clayton43e0af02012-09-18 18:04:04 +0000151 m_opaque_ap.get(), result, dst_path, (uint64_t)dst_len, result);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000152
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000153 if (result == 0 && dst_path && dst_len > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000154 *dst_path = '\0';
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000155 return result;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000156}
157
158
159const lldb_private::FileSpec *
160SBFileSpec::operator->() const
161{
Greg Clayton66111032010-06-23 01:19:29 +0000162 return m_opaque_ap.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000163}
164
165const lldb_private::FileSpec *
166SBFileSpec::get() const
167{
Greg Clayton66111032010-06-23 01:19:29 +0000168 return m_opaque_ap.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000169}
170
171
172const lldb_private::FileSpec &
173SBFileSpec::operator*() const
174{
Greg Clayton66111032010-06-23 01:19:29 +0000175 return *m_opaque_ap.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000176}
177
178const lldb_private::FileSpec &
179SBFileSpec::ref() const
180{
Greg Clayton66111032010-06-23 01:19:29 +0000181 return *m_opaque_ap.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000182}
183
184
185void
186SBFileSpec::SetFileSpec (const lldb_private::FileSpec& fs)
187{
Greg Clayton226cce22013-07-08 22:22:41 +0000188 *m_opaque_ap = fs;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000189}
190
Caroline Ticedde9cff2010-09-20 05:20:02 +0000191bool
Caroline Ticeceb6b132010-10-26 03:11:13 +0000192SBFileSpec::GetDescription (SBStream &description) const
193{
Greg Claytonda7bc7d2011-11-13 06:57:31 +0000194 Stream &strm = description.ref();
Greg Clayton226cce22013-07-08 22:22:41 +0000195 char path[PATH_MAX];
196 if (m_opaque_ap->GetPath(path, sizeof(path)))
197 strm.PutCString (path);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000198 return true;
199}