• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- 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 <limits.h>
11 
12 #include "lldb/API/SBFileSpec.h"
13 #include "lldb/API/SBStream.h"
14 #include "lldb/Host/FileSpec.h"
15 #include "lldb/Core/Log.h"
16 #include "lldb/Core/Stream.h"
17 
18 using namespace lldb;
19 using namespace lldb_private;
20 
21 
22 
SBFileSpec()23 SBFileSpec::SBFileSpec () :
24     m_opaque_ap(new lldb_private::FileSpec())
25 {
26 }
27 
SBFileSpec(const SBFileSpec & rhs)28 SBFileSpec::SBFileSpec (const SBFileSpec &rhs) :
29     m_opaque_ap(new lldb_private::FileSpec(*rhs.m_opaque_ap))
30 {
31 }
32 
SBFileSpec(const lldb_private::FileSpec & fspec)33 SBFileSpec::SBFileSpec (const lldb_private::FileSpec& fspec) :
34     m_opaque_ap(new lldb_private::FileSpec(fspec))
35 {
36 }
37 
38 // Deprected!!!
SBFileSpec(const char * path)39 SBFileSpec::SBFileSpec (const char *path) :
40     m_opaque_ap(new FileSpec (path, true))
41 {
42 }
43 
SBFileSpec(const char * path,bool resolve)44 SBFileSpec::SBFileSpec (const char *path, bool resolve) :
45     m_opaque_ap(new FileSpec (path, resolve))
46 {
47 }
48 
~SBFileSpec()49 SBFileSpec::~SBFileSpec ()
50 {
51 }
52 
53 const SBFileSpec &
operator =(const SBFileSpec & rhs)54 SBFileSpec::operator = (const SBFileSpec &rhs)
55 {
56     if (this != &rhs)
57         *m_opaque_ap = *rhs.m_opaque_ap;
58     return *this;
59 }
60 
61 bool
IsValid() const62 SBFileSpec::IsValid() const
63 {
64     return *m_opaque_ap;
65 }
66 
67 bool
Exists() const68 SBFileSpec::Exists () const
69 {
70     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
71 
72     bool result = m_opaque_ap->Exists();
73 
74     if (log)
75         log->Printf ("SBFileSpec(%p)::Exists () => %s", m_opaque_ap.get(), (result ? "true" : "false"));
76 
77     return result;
78 }
79 
80 bool
ResolveExecutableLocation()81 SBFileSpec::ResolveExecutableLocation ()
82 {
83     return m_opaque_ap->ResolveExecutableLocation ();
84 }
85 
86 int
ResolvePath(const char * src_path,char * dst_path,size_t dst_len)87 SBFileSpec::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 
92 const char *
GetFilename() const93 SBFileSpec::GetFilename() const
94 {
95     const char *s = m_opaque_ap->GetFilename().AsCString();
96 
97     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
98     if (log)
99     {
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     }
105 
106     return s;
107 }
108 
109 const char *
GetDirectory() const110 SBFileSpec::GetDirectory() const
111 {
112     const char *s = m_opaque_ap->GetDirectory().AsCString();
113     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
114     if (log)
115     {
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     }
121     return s;
122 }
123 
124 uint32_t
GetPath(char * dst_path,size_t dst_len) const125 SBFileSpec::GetPath (char *dst_path, size_t dst_len) const
126 {
127     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
128 
129     uint32_t result = m_opaque_ap->GetPath (dst_path, dst_len);
130 
131     if (log)
132         log->Printf ("SBFileSpec(%p)::GetPath (dst_path=\"%.*s\", dst_len=%" PRIu64 ") => %u",
133                      m_opaque_ap.get(), result, dst_path, (uint64_t)dst_len, result);
134 
135     if (result == 0 && dst_path && dst_len > 0)
136         *dst_path = '\0';
137     return result;
138 }
139 
140 
141 const lldb_private::FileSpec *
operator ->() const142 SBFileSpec::operator->() const
143 {
144     return m_opaque_ap.get();
145 }
146 
147 const lldb_private::FileSpec *
get() const148 SBFileSpec::get() const
149 {
150     return m_opaque_ap.get();
151 }
152 
153 
154 const lldb_private::FileSpec &
operator *() const155 SBFileSpec::operator*() const
156 {
157     return *m_opaque_ap.get();
158 }
159 
160 const lldb_private::FileSpec &
ref() const161 SBFileSpec::ref() const
162 {
163     return *m_opaque_ap.get();
164 }
165 
166 
167 void
SetFileSpec(const lldb_private::FileSpec & fs)168 SBFileSpec::SetFileSpec (const lldb_private::FileSpec& fs)
169 {
170     *m_opaque_ap = fs;
171 }
172 
173 bool
GetDescription(SBStream & description) const174 SBFileSpec::GetDescription (SBStream &description) const
175 {
176     Stream &strm = description.ref();
177     char path[PATH_MAX];
178     if (m_opaque_ap->GetPath(path, sizeof(path)))
179         strm.PutCString (path);
180     return true;
181 }
182