blob: fc223405eb53f67fab73fe2d942bf24bd4c6aaa3 [file] [log] [blame]
Chris Lattner24943d22010-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
10#include "lldb/API/SBFileSpec.h"
Caroline Tice98f930f2010-09-20 05:20:02 +000011#include "lldb/API/SBStream.h"
Chris Lattner24943d22010-06-08 16:52:24 +000012#include "lldb/Core/FileSpec.h"
Caroline Tice7826c882010-10-26 03:11:13 +000013#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000014
15using namespace lldb;
16using namespace lldb_private;
17
18
19
20SBFileSpec::SBFileSpec () :
Greg Clayton63094e02010-06-23 01:19:29 +000021 m_opaque_ap()
Chris Lattner24943d22010-06-08 16:52:24 +000022{
23}
24
25SBFileSpec::SBFileSpec (const SBFileSpec &rhs) :
Greg Clayton63094e02010-06-23 01:19:29 +000026 m_opaque_ap()
Chris Lattner24943d22010-06-08 16:52:24 +000027{
Caroline Tice61ba7ec2010-10-26 23:49:36 +000028 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
29
30 if (rhs.m_opaque_ap.get())
31 m_opaque_ap.reset (new FileSpec (rhs.get()));
Caroline Tice7826c882010-10-26 03:11:13 +000032
33 if (log)
34 {
35 SBStream sstr;
Caroline Tice61ba7ec2010-10-26 23:49:36 +000036 GetDescription (sstr);
Greg Clayton49ce6822010-10-31 03:01:06 +000037 log->Printf ("SBFileSpec::SBFileSpec (const SBFileSpec rhs.ap=%p) => SBFileSpec(%p): %s",
Caroline Tice61ba7ec2010-10-26 23:49:36 +000038 rhs.m_opaque_ap.get(), m_opaque_ap.get(), sstr.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +000039 }
Chris Lattner24943d22010-06-08 16:52:24 +000040}
41
Greg Clayton537a7a82010-10-20 20:54:39 +000042// Deprected!!!
Chris Lattner24943d22010-06-08 16:52:24 +000043SBFileSpec::SBFileSpec (const char *path) :
Greg Clayton537a7a82010-10-20 20:54:39 +000044 m_opaque_ap(new FileSpec (path, true))
45{
46}
47
48SBFileSpec::SBFileSpec (const char *path, bool resolve) :
49 m_opaque_ap(new FileSpec (path, resolve))
Chris Lattner24943d22010-06-08 16:52:24 +000050{
Caroline Tice61ba7ec2010-10-26 23:49:36 +000051 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +000052
53 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +000054 log->Printf ("SBFileSpec::SBFileSpec (path=\"%s\", resolve=%i) => SBFileSpec(%p)", path,
Greg Clayton3f5ee7f2010-10-29 04:59:35 +000055 resolve, m_opaque_ap.get());
Chris Lattner24943d22010-06-08 16:52:24 +000056}
57
58SBFileSpec::~SBFileSpec ()
59{
60}
61
62const SBFileSpec &
63SBFileSpec::operator = (const SBFileSpec &rhs)
64{
65 if (this != &rhs)
66 {
67 if (rhs.IsValid())
Greg Clayton63094e02010-06-23 01:19:29 +000068 m_opaque_ap.reset (new lldb_private::FileSpec(*rhs.m_opaque_ap.get()));
Chris Lattner24943d22010-06-08 16:52:24 +000069 }
70 return *this;
71}
72
73bool
74SBFileSpec::IsValid() const
75{
Greg Clayton63094e02010-06-23 01:19:29 +000076 return m_opaque_ap.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000077}
78
79bool
80SBFileSpec::Exists () const
81{
Caroline Tice7826c882010-10-26 03:11:13 +000082 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
83
Caroline Tice7826c882010-10-26 03:11:13 +000084 bool result = false;
Greg Clayton63094e02010-06-23 01:19:29 +000085 if (m_opaque_ap.get())
Caroline Tice7826c882010-10-26 03:11:13 +000086 result = m_opaque_ap->Exists();
87
88 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +000089 log->Printf ("SBFileSpec(%p)::Exists () => %s", m_opaque_ap.get(), (result ? "true" : "false"));
Caroline Tice7826c882010-10-26 03:11:13 +000090
91 return result;
Chris Lattner24943d22010-06-08 16:52:24 +000092}
93
Caroline Ticeeddffe92010-09-10 04:48:55 +000094bool
95SBFileSpec::ResolveExecutableLocation ()
96{
97 if (m_opaque_ap.get())
98 return m_opaque_ap->ResolveExecutableLocation ();
99 return false;
100}
Chris Lattner24943d22010-06-08 16:52:24 +0000101
102int
103SBFileSpec::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
108const char *
Johnny Chen4ead2e92010-08-27 22:35:26 +0000109SBFileSpec::GetFilename() const
Chris Lattner24943d22010-06-08 16:52:24 +0000110{
Greg Claytona66ba462010-10-30 04:51:46 +0000111 const char *s = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +0000112 if (m_opaque_ap.get())
Greg Claytona66ba462010-10-30 04:51:46 +0000113 s = m_opaque_ap->GetFilename().AsCString();
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000114
Greg Claytona66ba462010-10-30 04:51:46 +0000115 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +0000116 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +0000117 {
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 Tice7826c882010-10-26 03:11:13 +0000123
Greg Claytona66ba462010-10-30 04:51:46 +0000124 return s;
Chris Lattner24943d22010-06-08 16:52:24 +0000125}
126
127const char *
128SBFileSpec::GetDirectory() const
129{
Greg Claytona66ba462010-10-30 04:51:46 +0000130 const char *s = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +0000131 if (m_opaque_ap.get())
Greg Claytona66ba462010-10-30 04:51:46 +0000132 s = m_opaque_ap->GetDirectory().AsCString();
133 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
134 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +0000135 {
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 Claytona66ba462010-10-30 04:51:46 +0000141 return s;
Chris Lattner24943d22010-06-08 16:52:24 +0000142}
143
144uint32_t
145SBFileSpec::GetPath (char *dst_path, size_t dst_len) const
146{
Caroline Tice7826c882010-10-26 03:11:13 +0000147 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
148
Greg Clayton49ce6822010-10-31 03:01:06 +0000149 uint32_t result = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000150 if (m_opaque_ap.get())
Caroline Tice7826c882010-10-26 03:11:13 +0000151 result = m_opaque_ap->GetPath (dst_path, dst_len);
Caroline Tice7826c882010-10-26 03:11:13 +0000152
153 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +0000154 log->Printf ("SBFileSpec(%p)::GetPath (dst_path=\"%.*s\", dst_len=%zu) => %u",
155 m_opaque_ap.get(), result, dst_path, dst_len, result);
Chris Lattner24943d22010-06-08 16:52:24 +0000156
Greg Clayton49ce6822010-10-31 03:01:06 +0000157 if (result == 0 && dst_path && dst_len > 0)
Chris Lattner24943d22010-06-08 16:52:24 +0000158 *dst_path = '\0';
Greg Clayton49ce6822010-10-31 03:01:06 +0000159 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000160}
161
162
163const lldb_private::FileSpec *
164SBFileSpec::operator->() const
165{
Greg Clayton63094e02010-06-23 01:19:29 +0000166 return m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000167}
168
169const lldb_private::FileSpec *
170SBFileSpec::get() const
171{
Greg Clayton63094e02010-06-23 01:19:29 +0000172 return m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000173}
174
175
176const lldb_private::FileSpec &
177SBFileSpec::operator*() const
178{
Greg Clayton63094e02010-06-23 01:19:29 +0000179 return *m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000180}
181
182const lldb_private::FileSpec &
183SBFileSpec::ref() const
184{
Greg Clayton63094e02010-06-23 01:19:29 +0000185 return *m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000186}
187
188
189void
190SBFileSpec::SetFileSpec (const lldb_private::FileSpec& fs)
191{
Greg Clayton63094e02010-06-23 01:19:29 +0000192 if (m_opaque_ap.get())
193 *m_opaque_ap = fs;
Chris Lattner24943d22010-06-08 16:52:24 +0000194 else
Greg Clayton63094e02010-06-23 01:19:29 +0000195 m_opaque_ap.reset (new FileSpec (fs));
Chris Lattner24943d22010-06-08 16:52:24 +0000196}
197
Caroline Tice98f930f2010-09-20 05:20:02 +0000198bool
Caroline Tice7826c882010-10-26 03:11:13 +0000199SBFileSpec::GetDescription (SBStream &description) const
200{
201 if (m_opaque_ap.get())
202 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000203 char path[PATH_MAX];
204 if (m_opaque_ap->GetPath(path, sizeof(path)))
205 description.Printf ("%s", path);
Caroline Tice7826c882010-10-26 03:11:13 +0000206 }
207 else
208 description.Printf ("No value");
209
210 return true;
211}