blob: cabf0905481c0f302cb8fb46d152c7972369edfd [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
Stephen Wilsonec2d9782011-04-08 13:36:44 +000010#include <limits.h>
11
Chris Lattner24943d22010-06-08 16:52:24 +000012#include "lldb/API/SBFileSpec.h"
Caroline Tice98f930f2010-09-20 05:20:02 +000013#include "lldb/API/SBStream.h"
Greg Clayton5f54ac32011-02-08 05:05:52 +000014#include "lldb/Host/FileSpec.h"
Caroline Tice7826c882010-10-26 03:11:13 +000015#include "lldb/Core/Log.h"
Greg Clayton96154be2011-11-13 06:57:31 +000016#include "lldb/Core/Stream.h"
Chris Lattner24943d22010-06-08 16:52:24 +000017
18using namespace lldb;
19using namespace lldb_private;
20
21
22
23SBFileSpec::SBFileSpec () :
Greg Clayton63094e02010-06-23 01:19:29 +000024 m_opaque_ap()
Chris Lattner24943d22010-06-08 16:52:24 +000025{
26}
27
28SBFileSpec::SBFileSpec (const SBFileSpec &rhs) :
Greg Clayton63094e02010-06-23 01:19:29 +000029 m_opaque_ap()
Chris Lattner24943d22010-06-08 16:52:24 +000030{
Greg Claytone005f2c2010-11-06 01:53:30 +000031 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice61ba7ec2010-10-26 23:49:36 +000032
33 if (rhs.m_opaque_ap.get())
34 m_opaque_ap.reset (new FileSpec (rhs.get()));
Caroline Tice7826c882010-10-26 03:11:13 +000035
36 if (log)
37 {
38 SBStream sstr;
Caroline Tice61ba7ec2010-10-26 23:49:36 +000039 GetDescription (sstr);
Greg Clayton49ce6822010-10-31 03:01:06 +000040 log->Printf ("SBFileSpec::SBFileSpec (const SBFileSpec rhs.ap=%p) => SBFileSpec(%p): %s",
Caroline Tice61ba7ec2010-10-26 23:49:36 +000041 rhs.m_opaque_ap.get(), m_opaque_ap.get(), sstr.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +000042 }
Chris Lattner24943d22010-06-08 16:52:24 +000043}
44
Greg Clayton537a7a82010-10-20 20:54:39 +000045// Deprected!!!
Chris Lattner24943d22010-06-08 16:52:24 +000046SBFileSpec::SBFileSpec (const char *path) :
Greg Clayton537a7a82010-10-20 20:54:39 +000047 m_opaque_ap(new FileSpec (path, true))
48{
49}
50
51SBFileSpec::SBFileSpec (const char *path, bool resolve) :
52 m_opaque_ap(new FileSpec (path, resolve))
Chris Lattner24943d22010-06-08 16:52:24 +000053{
Greg Claytone005f2c2010-11-06 01:53:30 +000054 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +000055
56 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +000057 log->Printf ("SBFileSpec::SBFileSpec (path=\"%s\", resolve=%i) => SBFileSpec(%p)", path,
Greg Clayton3f5ee7f2010-10-29 04:59:35 +000058 resolve, m_opaque_ap.get());
Chris Lattner24943d22010-06-08 16:52:24 +000059}
60
61SBFileSpec::~SBFileSpec ()
62{
63}
64
65const SBFileSpec &
66SBFileSpec::operator = (const SBFileSpec &rhs)
67{
68 if (this != &rhs)
69 {
70 if (rhs.IsValid())
Greg Clayton63094e02010-06-23 01:19:29 +000071 m_opaque_ap.reset (new lldb_private::FileSpec(*rhs.m_opaque_ap.get()));
Chris Lattner24943d22010-06-08 16:52:24 +000072 }
73 return *this;
74}
75
76bool
77SBFileSpec::IsValid() const
78{
Greg Clayton63094e02010-06-23 01:19:29 +000079 return m_opaque_ap.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000080}
81
82bool
83SBFileSpec::Exists () const
84{
Greg Claytone005f2c2010-11-06 01:53:30 +000085 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +000086
Caroline Tice7826c882010-10-26 03:11:13 +000087 bool result = false;
Greg Clayton63094e02010-06-23 01:19:29 +000088 if (m_opaque_ap.get())
Caroline Tice7826c882010-10-26 03:11:13 +000089 result = m_opaque_ap->Exists();
90
91 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +000092 log->Printf ("SBFileSpec(%p)::Exists () => %s", m_opaque_ap.get(), (result ? "true" : "false"));
Caroline Tice7826c882010-10-26 03:11:13 +000093
94 return result;
Chris Lattner24943d22010-06-08 16:52:24 +000095}
96
Caroline Ticeeddffe92010-09-10 04:48:55 +000097bool
98SBFileSpec::ResolveExecutableLocation ()
99{
100 if (m_opaque_ap.get())
101 return m_opaque_ap->ResolveExecutableLocation ();
102 return false;
103}
Chris Lattner24943d22010-06-08 16:52:24 +0000104
105int
106SBFileSpec::ResolvePath (const char *src_path, char *dst_path, size_t dst_len)
107{
108 return lldb_private::FileSpec::Resolve (src_path, dst_path, dst_len);
109}
110
111const char *
Johnny Chen4ead2e92010-08-27 22:35:26 +0000112SBFileSpec::GetFilename() const
Chris Lattner24943d22010-06-08 16:52:24 +0000113{
Greg Claytona66ba462010-10-30 04:51:46 +0000114 const char *s = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +0000115 if (m_opaque_ap.get())
Greg Claytona66ba462010-10-30 04:51:46 +0000116 s = m_opaque_ap->GetFilename().AsCString();
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000117
Greg Claytone005f2c2010-11-06 01:53:30 +0000118 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000119 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +0000120 {
121 if (s)
122 log->Printf ("SBFileSpec(%p)::GetFilename () => \"%s\"", m_opaque_ap.get(), s);
123 else
124 log->Printf ("SBFileSpec(%p)::GetFilename () => NULL", m_opaque_ap.get());
125 }
Caroline Tice7826c882010-10-26 03:11:13 +0000126
Greg Claytona66ba462010-10-30 04:51:46 +0000127 return s;
Chris Lattner24943d22010-06-08 16:52:24 +0000128}
129
130const char *
131SBFileSpec::GetDirectory() const
132{
Greg Claytona66ba462010-10-30 04:51:46 +0000133 const char *s = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +0000134 if (m_opaque_ap.get())
Greg Claytona66ba462010-10-30 04:51:46 +0000135 s = m_opaque_ap->GetDirectory().AsCString();
Greg Claytone005f2c2010-11-06 01:53:30 +0000136 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000137 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +0000138 {
139 if (s)
140 log->Printf ("SBFileSpec(%p)::GetDirectory () => \"%s\"", m_opaque_ap.get(), s);
141 else
142 log->Printf ("SBFileSpec(%p)::GetDirectory () => NULL", m_opaque_ap.get());
143 }
Greg Claytona66ba462010-10-30 04:51:46 +0000144 return s;
Chris Lattner24943d22010-06-08 16:52:24 +0000145}
146
147uint32_t
148SBFileSpec::GetPath (char *dst_path, size_t dst_len) const
149{
Greg Claytone005f2c2010-11-06 01:53:30 +0000150 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000151
Greg Clayton49ce6822010-10-31 03:01:06 +0000152 uint32_t result = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000153 if (m_opaque_ap.get())
Caroline Tice7826c882010-10-26 03:11:13 +0000154 result = m_opaque_ap->GetPath (dst_path, dst_len);
Caroline Tice7826c882010-10-26 03:11:13 +0000155
156 if (log)
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000157 log->Printf ("SBFileSpec(%p)::GetPath (dst_path=\"%.*s\", dst_len=%" PRIu64 ") => %u",
Greg Clayton851e30e2012-09-18 18:04:04 +0000158 m_opaque_ap.get(), result, dst_path, (uint64_t)dst_len, result);
Chris Lattner24943d22010-06-08 16:52:24 +0000159
Greg Clayton49ce6822010-10-31 03:01:06 +0000160 if (result == 0 && dst_path && dst_len > 0)
Chris Lattner24943d22010-06-08 16:52:24 +0000161 *dst_path = '\0';
Greg Clayton49ce6822010-10-31 03:01:06 +0000162 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000163}
164
165
166const lldb_private::FileSpec *
167SBFileSpec::operator->() const
168{
Greg Clayton63094e02010-06-23 01:19:29 +0000169 return m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000170}
171
172const lldb_private::FileSpec *
173SBFileSpec::get() const
174{
Greg Clayton63094e02010-06-23 01:19:29 +0000175 return m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000176}
177
178
179const lldb_private::FileSpec &
180SBFileSpec::operator*() const
181{
Greg Clayton63094e02010-06-23 01:19:29 +0000182 return *m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000183}
184
185const lldb_private::FileSpec &
186SBFileSpec::ref() const
187{
Greg Clayton63094e02010-06-23 01:19:29 +0000188 return *m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000189}
190
191
192void
193SBFileSpec::SetFileSpec (const lldb_private::FileSpec& fs)
194{
Greg Clayton63094e02010-06-23 01:19:29 +0000195 if (m_opaque_ap.get())
196 *m_opaque_ap = fs;
Chris Lattner24943d22010-06-08 16:52:24 +0000197 else
Greg Clayton63094e02010-06-23 01:19:29 +0000198 m_opaque_ap.reset (new FileSpec (fs));
Chris Lattner24943d22010-06-08 16:52:24 +0000199}
200
Caroline Tice98f930f2010-09-20 05:20:02 +0000201bool
Caroline Tice7826c882010-10-26 03:11:13 +0000202SBFileSpec::GetDescription (SBStream &description) const
203{
Greg Clayton96154be2011-11-13 06:57:31 +0000204 Stream &strm = description.ref();
Caroline Tice7826c882010-10-26 03:11:13 +0000205 if (m_opaque_ap.get())
206 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000207 char path[PATH_MAX];
208 if (m_opaque_ap->GetPath(path, sizeof(path)))
Greg Clayton96154be2011-11-13 06:57:31 +0000209 strm.PutCString (path);
Caroline Tice7826c882010-10-26 03:11:13 +0000210 }
211 else
Greg Clayton96154be2011-11-13 06:57:31 +0000212 strm.PutCString ("No value");
Caroline Tice7826c882010-10-26 03:11:13 +0000213
214 return true;
215}