aboutsummaryrefslogtreecommitdiff
path: root/include/lldb/Host/FileSpec.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/lldb/Host/FileSpec.h')
-rw-r--r--include/lldb/Host/FileSpec.h131
1 files changed, 116 insertions, 15 deletions
diff --git a/include/lldb/Host/FileSpec.h b/include/lldb/Host/FileSpec.h
index 173d948e687b..d0338d41db1b 100644
--- a/include/lldb/Host/FileSpec.h
+++ b/include/lldb/Host/FileSpec.h
@@ -11,6 +11,8 @@
#define liblldb_FileSpec_h_
#if defined(__cplusplus)
+#include <functional>
+
#include "lldb/lldb-private.h"
#include "lldb/Core/ConstString.h"
#include "lldb/Core/STLUtils.h"
@@ -78,6 +80,12 @@ public:
//------------------------------------------------------------------
explicit FileSpec (const char *path, bool resolve_path, PathSyntax syntax = ePathSyntaxHostNative);
+ explicit FileSpec (const char *path, bool resolve_path, ArchSpec arch);
+
+ explicit FileSpec(const std::string &path, bool resolve_path, PathSyntax syntax = ePathSyntaxHostNative);
+
+ explicit FileSpec(const std::string &path, bool resolve_path, ArchSpec arch);
+
//------------------------------------------------------------------
/// Copy constructor
///
@@ -259,7 +267,7 @@ public:
/// The stream to which to dump the object description.
//------------------------------------------------------------------
void
- Dump (Stream *s) const;
+ Dump(Stream *s) const;
//------------------------------------------------------------------
/// Existence test.
@@ -359,16 +367,25 @@ public:
IsSourceImplementationFile () const;
//------------------------------------------------------------------
- /// Returns true if the filespec represents path that is relative
- /// path to the current working directory.
+ /// Returns true if the filespec represents a relative path.
///
/// @return
- /// \b true if the filespec represents a current working
- /// directory relative path, \b false otherwise.
+ /// \b true if the filespec represents a relative path,
+ /// \b false otherwise.
//------------------------------------------------------------------
bool
- IsRelativeToCurrentWorkingDirectory () const;
-
+ IsRelative() const;
+
+ //------------------------------------------------------------------
+ /// Returns true if the filespec represents an absolute path.
+ ///
+ /// @return
+ /// \b true if the filespec represents an absolute path,
+ /// \b false otherwise.
+ //------------------------------------------------------------------
+ bool
+ IsAbsolute() const;
+
TimeValue
GetModificationTime () const;
@@ -408,6 +425,20 @@ public:
std::string
GetPath (bool denormalize = true) const;
+ const char *
+ GetCString(bool denormalize = true) const;
+
+ //------------------------------------------------------------------
+ /// Extract the full path to the file.
+ ///
+ /// Extract the directory and path into an llvm::SmallVectorImpl<>
+ ///
+ /// @return
+ /// Returns a std::string with the directory and filename
+ /// concatenated.
+ //------------------------------------------------------------------
+ void GetPath(llvm::SmallVectorImpl<char> &path, bool denormalize = true) const;
+
//------------------------------------------------------------------
/// Extract the extension of the file.
///
@@ -530,6 +561,45 @@ public:
lldb::DataBufferSP
MemoryMapFileContents (off_t offset = 0, size_t length = SIZE_MAX) const;
+
+ //------------------------------------------------------------------
+ /// Memory map part of, or the entire contents of, a file only if
+ /// the file is local (not on a network mount).
+ ///
+ /// Returns a shared pointer to a data buffer that contains all or
+ /// part of the contents of a file. The data will be memory mapped
+ /// if the file is local and will lazily page in data from the file
+ /// as memory is accessed. If the data is memory mapped, the data
+ /// that is mapped will start \a offset bytes into the file, and
+ /// \a length bytes will be mapped. If \a length is
+ /// greater than the number of bytes available in the file starting
+ /// at \a offset, the number of bytes will be appropriately
+ /// truncated. The final number of bytes that get mapped can be
+ /// verified using the DataBuffer::GetByteSize() function on the return
+ /// shared data pointer object contents.
+ ///
+ /// If the file is on a network mount the data will be read into a
+ /// heap buffer immediately so that accesses to the data won't later
+ /// cause a crash if we touch a page that isn't paged in and the
+ /// network mount has been disconnected or gone away.
+ ///
+ /// @param[in] offset
+ /// The offset in bytes from the beginning of the file where
+ /// memory mapping should begin.
+ ///
+ /// @param[in] length
+ /// The size in bytes that should be mapped starting \a offset
+ /// bytes into the file. If \a length is \c SIZE_MAX, map
+ /// as many bytes as possible.
+ ///
+ /// @return
+ /// A shared pointer to the memory mapped data. This shared
+ /// pointer can contain a NULL DataBuffer pointer, so the contained
+ /// pointer must be checked prior to using it.
+ //------------------------------------------------------------------
+ lldb::DataBufferSP
+ MemoryMapFileContentsIfLocal(off_t file_offset, size_t file_size) const;
+
//------------------------------------------------------------------
/// Read part of, or the entire contents of, a file into a heap based data buffer.
///
@@ -579,9 +649,12 @@ public:
lldb::DataBufferSP
ReadFileContentsAsCString(Error *error_ptr = NULL);
- static void Normalize(llvm::SmallVectorImpl<char> &path, PathSyntax syntax = ePathSyntaxHostNative);
- static void DeNormalize(llvm::SmallVectorImpl<char> &path, PathSyntax syntax = ePathSyntaxHostNative);
-
+ //------------------------------------------------------------------
+ /// Normalize a pathname by collapsing redundant separators and
+ /// up-level references.
+ //------------------------------------------------------------------
+ void
+ NormalizePath ();
//------------------------------------------------------------------
/// Run through the input string, replaying the effect of any ".." and produce
@@ -613,6 +686,15 @@ public:
void
SetFile (const char *path, bool resolve_path, PathSyntax syntax = ePathSyntaxHostNative);
+ void
+ SetFile(const char *path, bool resolve_path, ArchSpec arch);
+
+ void
+ SetFile(const std::string &path, bool resolve_path, PathSyntax syntax = ePathSyntaxHostNative);
+
+ void
+ SetFile(const std::string &path, bool resolve_path, ArchSpec arch);
+
bool
IsResolved () const
{
@@ -668,10 +750,25 @@ public:
FileSpec
CopyByRemovingLastPathComponent () const;
-
+
void
- AppendPathComponent (const char *new_path);
-
+ PrependPathComponent(const char *new_path);
+
+ void
+ PrependPathComponent(const std::string &new_path);
+
+ void
+ PrependPathComponent(const FileSpec &new_path);
+
+ void
+ AppendPathComponent(const char *new_path);
+
+ void
+ AppendPathComponent(const std::string &new_path);
+
+ void
+ AppendPathComponent(const FileSpec &new_path);
+
void
RemoveLastPathComponent ();
@@ -706,8 +803,7 @@ public:
typedef EnumerateDirectoryResult (*EnumerateDirectoryCallbackType) (void *baton,
FileType file_type,
- const FileSpec &spec
-);
+ const FileSpec &spec);
static EnumerateDirectoryResult
EnumerateDirectory (const char *dir_path,
@@ -717,6 +813,11 @@ public:
EnumerateDirectoryCallbackType callback,
void *callback_baton);
+ typedef std::function <EnumerateDirectoryResult(FileType file_type, const FileSpec &spec)> DirectoryCallback;
+
+ static EnumerateDirectoryResult
+ ForEachItemInDirectory (const char *dir_path, DirectoryCallback const &callback);
+
protected:
//------------------------------------------------------------------
// Member variables