blob: 4413689501a83c8d11a40f456501c424b0bf80a0 [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{
Greg Clayton226cce22013-07-08 22:22:41 +000064 return *m_opaque_ap;
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
124uint32_t
125SBFileSpec::GetPath (char *dst_path, size_t dst_len) const
126{
Greg Clayton5160ce52013-03-27 23:08:40 +0000127 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000128
Greg Clayton226cce22013-07-08 22:22:41 +0000129 uint32_t result = m_opaque_ap->GetPath (dst_path, dst_len);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000130
131 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +0000132 log->Printf ("SBFileSpec(%p)::GetPath (dst_path=\"%.*s\", dst_len=%" PRIu64 ") => %u",
Greg Clayton43e0af02012-09-18 18:04:04 +0000133 m_opaque_ap.get(), result, dst_path, (uint64_t)dst_len, result);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000134
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000135 if (result == 0 && dst_path && dst_len > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000136 *dst_path = '\0';
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000137 return result;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000138}
139
140
141const lldb_private::FileSpec *
142SBFileSpec::operator->() const
143{
Greg Clayton66111032010-06-23 01:19:29 +0000144 return m_opaque_ap.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000145}
146
147const lldb_private::FileSpec *
148SBFileSpec::get() const
149{
Greg Clayton66111032010-06-23 01:19:29 +0000150 return m_opaque_ap.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000151}
152
153
154const lldb_private::FileSpec &
155SBFileSpec::operator*() const
156{
Greg Clayton66111032010-06-23 01:19:29 +0000157 return *m_opaque_ap.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000158}
159
160const lldb_private::FileSpec &
161SBFileSpec::ref() const
162{
Greg Clayton66111032010-06-23 01:19:29 +0000163 return *m_opaque_ap.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000164}
165
166
167void
168SBFileSpec::SetFileSpec (const lldb_private::FileSpec& fs)
169{
Greg Clayton226cce22013-07-08 22:22:41 +0000170 *m_opaque_ap = fs;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000171}
172
Caroline Ticedde9cff2010-09-20 05:20:02 +0000173bool
Caroline Ticeceb6b132010-10-26 03:11:13 +0000174SBFileSpec::GetDescription (SBStream &description) const
175{
Greg Claytonda7bc7d2011-11-13 06:57:31 +0000176 Stream &strm = description.ref();
Greg Clayton226cce22013-07-08 22:22:41 +0000177 char path[PATH_MAX];
178 if (m_opaque_ap->GetPath(path, sizeof(path)))
179 strm.PutCString (path);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000180 return true;
181}