blob: a3a503dd6016a59996746813821d3e487907b10f [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"
Chris Lattner24943d22010-06-08 16:52:24 +000016
17using namespace lldb;
18using namespace lldb_private;
19
20
21
22SBFileSpec::SBFileSpec () :
Greg Clayton63094e02010-06-23 01:19:29 +000023 m_opaque_ap()
Chris Lattner24943d22010-06-08 16:52:24 +000024{
25}
26
27SBFileSpec::SBFileSpec (const SBFileSpec &rhs) :
Greg Clayton63094e02010-06-23 01:19:29 +000028 m_opaque_ap()
Chris Lattner24943d22010-06-08 16:52:24 +000029{
Greg Claytone005f2c2010-11-06 01:53:30 +000030 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice61ba7ec2010-10-26 23:49:36 +000031
32 if (rhs.m_opaque_ap.get())
33 m_opaque_ap.reset (new FileSpec (rhs.get()));
Caroline Tice7826c882010-10-26 03:11:13 +000034
35 if (log)
36 {
37 SBStream sstr;
Caroline Tice61ba7ec2010-10-26 23:49:36 +000038 GetDescription (sstr);
Greg Clayton49ce6822010-10-31 03:01:06 +000039 log->Printf ("SBFileSpec::SBFileSpec (const SBFileSpec rhs.ap=%p) => SBFileSpec(%p): %s",
Caroline Tice61ba7ec2010-10-26 23:49:36 +000040 rhs.m_opaque_ap.get(), m_opaque_ap.get(), sstr.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +000041 }
Chris Lattner24943d22010-06-08 16:52:24 +000042}
43
Greg Clayton537a7a82010-10-20 20:54:39 +000044// Deprected!!!
Chris Lattner24943d22010-06-08 16:52:24 +000045SBFileSpec::SBFileSpec (const char *path) :
Greg Clayton537a7a82010-10-20 20:54:39 +000046 m_opaque_ap(new FileSpec (path, true))
47{
48}
49
50SBFileSpec::SBFileSpec (const char *path, bool resolve) :
51 m_opaque_ap(new FileSpec (path, resolve))
Chris Lattner24943d22010-06-08 16:52:24 +000052{
Greg Claytone005f2c2010-11-06 01:53:30 +000053 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +000054
55 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +000056 log->Printf ("SBFileSpec::SBFileSpec (path=\"%s\", resolve=%i) => SBFileSpec(%p)", path,
Greg Clayton3f5ee7f2010-10-29 04:59:35 +000057 resolve, m_opaque_ap.get());
Chris Lattner24943d22010-06-08 16:52:24 +000058}
59
60SBFileSpec::~SBFileSpec ()
61{
62}
63
64const SBFileSpec &
65SBFileSpec::operator = (const SBFileSpec &rhs)
66{
67 if (this != &rhs)
68 {
69 if (rhs.IsValid())
Greg Clayton63094e02010-06-23 01:19:29 +000070 m_opaque_ap.reset (new lldb_private::FileSpec(*rhs.m_opaque_ap.get()));
Chris Lattner24943d22010-06-08 16:52:24 +000071 }
72 return *this;
73}
74
75bool
76SBFileSpec::IsValid() const
77{
Greg Clayton63094e02010-06-23 01:19:29 +000078 return m_opaque_ap.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000079}
80
81bool
82SBFileSpec::Exists () const
83{
Greg Claytone005f2c2010-11-06 01:53:30 +000084 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +000085
Caroline Tice7826c882010-10-26 03:11:13 +000086 bool result = false;
Greg Clayton63094e02010-06-23 01:19:29 +000087 if (m_opaque_ap.get())
Caroline Tice7826c882010-10-26 03:11:13 +000088 result = m_opaque_ap->Exists();
89
90 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +000091 log->Printf ("SBFileSpec(%p)::Exists () => %s", m_opaque_ap.get(), (result ? "true" : "false"));
Caroline Tice7826c882010-10-26 03:11:13 +000092
93 return result;
Chris Lattner24943d22010-06-08 16:52:24 +000094}
95
Caroline Ticeeddffe92010-09-10 04:48:55 +000096bool
97SBFileSpec::ResolveExecutableLocation ()
98{
99 if (m_opaque_ap.get())
100 return m_opaque_ap->ResolveExecutableLocation ();
101 return false;
102}
Chris Lattner24943d22010-06-08 16:52:24 +0000103
104int
105SBFileSpec::ResolvePath (const char *src_path, char *dst_path, size_t dst_len)
106{
107 return lldb_private::FileSpec::Resolve (src_path, dst_path, dst_len);
108}
109
110const char *
Johnny Chen4ead2e92010-08-27 22:35:26 +0000111SBFileSpec::GetFilename() const
Chris Lattner24943d22010-06-08 16:52:24 +0000112{
Greg Claytona66ba462010-10-30 04:51:46 +0000113 const char *s = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +0000114 if (m_opaque_ap.get())
Greg Claytona66ba462010-10-30 04:51:46 +0000115 s = m_opaque_ap->GetFilename().AsCString();
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000116
Greg Claytone005f2c2010-11-06 01:53:30 +0000117 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000118 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +0000119 {
120 if (s)
121 log->Printf ("SBFileSpec(%p)::GetFilename () => \"%s\"", m_opaque_ap.get(), s);
122 else
123 log->Printf ("SBFileSpec(%p)::GetFilename () => NULL", m_opaque_ap.get());
124 }
Caroline Tice7826c882010-10-26 03:11:13 +0000125
Greg Claytona66ba462010-10-30 04:51:46 +0000126 return s;
Chris Lattner24943d22010-06-08 16:52:24 +0000127}
128
129const char *
130SBFileSpec::GetDirectory() const
131{
Greg Claytona66ba462010-10-30 04:51:46 +0000132 const char *s = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +0000133 if (m_opaque_ap.get())
Greg Claytona66ba462010-10-30 04:51:46 +0000134 s = m_opaque_ap->GetDirectory().AsCString();
Greg Claytone005f2c2010-11-06 01:53:30 +0000135 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000136 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +0000137 {
138 if (s)
139 log->Printf ("SBFileSpec(%p)::GetDirectory () => \"%s\"", m_opaque_ap.get(), s);
140 else
141 log->Printf ("SBFileSpec(%p)::GetDirectory () => NULL", m_opaque_ap.get());
142 }
Greg Claytona66ba462010-10-30 04:51:46 +0000143 return s;
Chris Lattner24943d22010-06-08 16:52:24 +0000144}
145
146uint32_t
147SBFileSpec::GetPath (char *dst_path, size_t dst_len) const
148{
Greg Claytone005f2c2010-11-06 01:53:30 +0000149 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000150
Greg Clayton49ce6822010-10-31 03:01:06 +0000151 uint32_t result = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000152 if (m_opaque_ap.get())
Caroline Tice7826c882010-10-26 03:11:13 +0000153 result = m_opaque_ap->GetPath (dst_path, dst_len);
Caroline Tice7826c882010-10-26 03:11:13 +0000154
155 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +0000156 log->Printf ("SBFileSpec(%p)::GetPath (dst_path=\"%.*s\", dst_len=%zu) => %u",
157 m_opaque_ap.get(), result, dst_path, dst_len, result);
Chris Lattner24943d22010-06-08 16:52:24 +0000158
Greg Clayton49ce6822010-10-31 03:01:06 +0000159 if (result == 0 && dst_path && dst_len > 0)
Chris Lattner24943d22010-06-08 16:52:24 +0000160 *dst_path = '\0';
Greg Clayton49ce6822010-10-31 03:01:06 +0000161 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000162}
163
164
165const lldb_private::FileSpec *
166SBFileSpec::operator->() const
167{
Greg Clayton63094e02010-06-23 01:19:29 +0000168 return m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000169}
170
171const lldb_private::FileSpec *
172SBFileSpec::get() const
173{
Greg Clayton63094e02010-06-23 01:19:29 +0000174 return m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000175}
176
177
178const lldb_private::FileSpec &
179SBFileSpec::operator*() const
180{
Greg Clayton63094e02010-06-23 01:19:29 +0000181 return *m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000182}
183
184const lldb_private::FileSpec &
185SBFileSpec::ref() const
186{
Greg Clayton63094e02010-06-23 01:19:29 +0000187 return *m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000188}
189
190
191void
192SBFileSpec::SetFileSpec (const lldb_private::FileSpec& fs)
193{
Greg Clayton63094e02010-06-23 01:19:29 +0000194 if (m_opaque_ap.get())
195 *m_opaque_ap = fs;
Chris Lattner24943d22010-06-08 16:52:24 +0000196 else
Greg Clayton63094e02010-06-23 01:19:29 +0000197 m_opaque_ap.reset (new FileSpec (fs));
Chris Lattner24943d22010-06-08 16:52:24 +0000198}
199
Caroline Tice98f930f2010-09-20 05:20:02 +0000200bool
Caroline Tice7826c882010-10-26 03:11:13 +0000201SBFileSpec::GetDescription (SBStream &description) const
202{
203 if (m_opaque_ap.get())
204 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000205 char path[PATH_MAX];
206 if (m_opaque_ap->GetPath(path, sizeof(path)))
207 description.Printf ("%s", path);
Caroline Tice7826c882010-10-26 03:11:13 +0000208 }
209 else
210 description.Printf ("No value");
211
212 return true;
213}