[Lldb-commits] [lldb] r180704 - Add a few new methods to FileSpec to make it a little easier to work
Jason Molenda
jmolenda at apple.com
Mon Apr 29 02:46:43 PDT 2013
Author: jmolenda
Date: Mon Apr 29 04:46:43 2013
New Revision: 180704
URL: http://llvm.org/viewvc/llvm-project?rev=180704&view=rev
Log:
Add a few new methods to FileSpec to make it a little easier to work
with directories, without increasing the size of the FileSpec object.
GetPath() returns a std::string of the full pathname of the file.
IsDirectory(), IsPipe(), IsRegularFile(), IsSocket(), and IsSymbolicLink()
can be used instead of getting the FileType() and comparing it to an enum.
Update PlatformDarwinKernel to use these new methods.
Modified:
lldb/trunk/include/lldb/Host/FileSpec.h
lldb/trunk/source/Host/common/FileSpec.cpp
lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
Modified: lldb/trunk/include/lldb/Host/FileSpec.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/FileSpec.h?rev=180704&r1=180703&r2=180704&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/FileSpec.h (original)
+++ lldb/trunk/include/lldb/Host/FileSpec.h Mon Apr 29 04:46:43 2013
@@ -381,6 +381,29 @@ public:
GetPath (char *path, size_t max_path_length) const;
//------------------------------------------------------------------
+ /// Extract the full path to the file.
+ ///
+ /// Extract the directory and path into a std::string, which is returned.
+ ///
+ /// @param[out] path
+ /// The directory + filename returned in this std::string reference.
+ //------------------------------------------------------------------
+ void
+ GetPath (std::string &path) const;
+
+ //------------------------------------------------------------------
+ /// Extract the full path to the file.
+ ///
+ /// Extract the directory and path into a std::string, which is returned.
+ ///
+ /// @return
+ /// Returns a std::string with the directory and filename
+ /// concatenated.
+ //------------------------------------------------------------------
+ std::string&
+ GetPath (void) const;
+
+ //------------------------------------------------------------------
/// Extract the extension of the file.
///
/// Returns a ConstString that represents the extension of the filename
@@ -411,6 +434,36 @@ public:
FileType
GetFileType () const;
+ bool
+ IsDirectory () const
+ {
+ return GetFileType() == FileSpec::eFileTypeDirectory;
+ }
+
+ bool
+ IsPipe () const
+ {
+ return GetFileType() == FileSpec::eFileTypePipe;
+ }
+
+ bool
+ IsRegularFile () const
+ {
+ return GetFileType() == FileSpec::eFileTypeRegular;
+ }
+
+ bool
+ IsSocket () const
+ {
+ return GetFileType() == FileSpec::eFileTypeSocket;
+ }
+
+ bool
+ IsSymbolicLink () const
+ {
+ return GetFileType() == FileSpec::eFileTypeSymbolicLink;
+ }
+
//------------------------------------------------------------------
/// Get the memory cost of this object.
///
Modified: lldb/trunk/source/Host/common/FileSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/FileSpec.cpp?rev=180704&r1=180703&r2=180704&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/FileSpec.cpp (original)
+++ lldb/trunk/source/Host/common/FileSpec.cpp Mon Apr 29 04:46:43 2013
@@ -702,6 +702,33 @@ FileSpec::GetPath(char *path, size_t pat
return 0;
}
+void
+FileSpec::GetPath (std::string &path) const
+{
+ const char *dirname = m_directory.GetCString();
+ const char *filename = m_filename.GetCString();
+ path.clear();
+ if (dirname)
+ {
+ path.append (dirname);
+ if (filename)
+ path.append ("/");
+ }
+ if (filename)
+ {
+ path.append (filename);
+ }
+}
+
+
+std::string&
+FileSpec::GetPath (void) const
+{
+ std::string path;
+ GetPath (path);
+ return path;
+}
+
ConstString
FileSpec::GetFileNameExtension () const
{
@@ -1032,5 +1059,3 @@ FileSpec::IsRelativeToCurrentWorkingDire
}
return false;
}
-
-
Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp?rev=180704&r1=180703&r2=180704&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp Mon Apr 29 04:46:43 2013
@@ -290,11 +290,7 @@ PlatformDarwinKernel::GetStatus (Stream
for (uint32_t i=0; i<num_kext_dirs; ++i)
{
const FileSpec &kext_dir = m_directories_searched[i];
- char pathbuf[PATH_MAX];
- if (kext_dir.GetPath (pathbuf, sizeof (pathbuf)))
- {
- strm.Printf (" Kext directories: [%2u] \"%s\"\n", i, pathbuf);
- }
+ strm.Printf (" Kext directories: [%2u] \"%s\"\n", i, kext_dir.GetPath().c_str());
}
strm.Printf (" Total number of kexts indexed: %d\n", (int) m_name_to_kext_path_map.size());
}
@@ -347,7 +343,7 @@ PlatformDarwinKernel::GetiOSSDKDirectori
char pathbuf[PATH_MAX];
::snprintf (pathbuf, sizeof (pathbuf), "%s/Platforms/iPhoneOS.platform/Developer/SDKs", developer_dir);
FileSpec ios_sdk(pathbuf, true);
- if (ios_sdk.Exists() && ios_sdk.GetFileType() == FileSpec::eFileTypeDirectory)
+ if (ios_sdk.Exists() && ios_sdk.IsDirectory())
{
directories.push_back (ios_sdk);
}
@@ -364,7 +360,7 @@ PlatformDarwinKernel::GetMacSDKDirectori
char pathbuf[PATH_MAX];
::snprintf (pathbuf, sizeof (pathbuf), "%s/Platforms/MacOSX.platform/Developer/SDKs", developer_dir);
FileSpec mac_sdk(pathbuf, true);
- if (mac_sdk.Exists() && mac_sdk.GetFileType() == FileSpec::eFileTypeDirectory)
+ if (mac_sdk.Exists() && mac_sdk.IsDirectory())
{
directories.push_back (mac_sdk);
}
@@ -374,7 +370,7 @@ void
PlatformDarwinKernel::GetGenericSDKDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories)
{
FileSpec generic_sdk("/AppleInternal/Developer/KDKs", true);
- if (generic_sdk.Exists() && generic_sdk.GetFileType() == FileSpec::eFileTypeDirectory)
+ if (generic_sdk.Exists() && generic_sdk.IsDirectory())
{
directories.push_back (generic_sdk);
}
@@ -389,19 +385,19 @@ void
PlatformDarwinKernel::GetMacDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories)
{
FileSpec sle("/System/Library/Extensions", true);
- if (sle.Exists() && sle.GetFileType() == FileSpec::eFileTypeDirectory)
+ if (sle.Exists() && sle.IsDirectory())
{
directories.push_back(sle);
}
FileSpec le("/Library/Extensions", true);
- if (le.Exists() && le.GetFileType() == FileSpec::eFileTypeDirectory)
+ if (le.Exists() && le.IsDirectory())
{
directories.push_back(le);
}
FileSpec kdk("/Volumes/KernelDebugKit", true);
- if (kdk.Exists() && kdk.GetFileType() == FileSpec::eFileTypeDirectory)
+ if (kdk.Exists() && kdk.IsDirectory())
{
directories.push_back(kdk);
}
@@ -418,7 +414,7 @@ PlatformDarwinKernel::GetGenericDirector
char pathbuf[PATH_MAX];
::snprintf (pathbuf, sizeof (pathbuf), "%s/../Symbols", developer_dir);
FileSpec symbols_dir (pathbuf, true);
- if (symbols_dir.Exists() && symbols_dir.GetFileType() == FileSpec::eFileTypeDirectory)
+ if (symbols_dir.Exists() && symbols_dir.IsDirectory())
{
directories.push_back (symbols_dir);
}
@@ -435,22 +431,18 @@ PlatformDarwinKernel::GetUserSpecifiedDi
{
FileSpec dir = user_dirs.GetFileSpecAtIndex (i);
dir.ResolvePath();
- if (dir.Exists() && dir.GetFileType() == FileSpec::eFileTypeDirectory)
+ if (dir.Exists() && dir.IsDirectory())
{
directories.push_back (dir);
possible_sdk_dirs.push_back (dir); // does this directory have a *.sdk or *.kdk that we should look in?
- char dir_pathbuf[PATH_MAX];
- if (dir.GetPath (dir_pathbuf, sizeof (dir_pathbuf)))
+ // Is there a "System/Library/Extensions" subdir of this directory?
+ std::string dir_sle_path = dir.GetPath();
+ dir_sle_path.append ("/System/Library/Extensions");
+ FileSpec dir_sle(dir_sle_path.c_str(), true);
+ if (dir_sle.Exists() && dir_sle.IsDirectory())
{
- // Is there a "System/Library/Extensions" subdir of this directory?
- char pathbuf[PATH_MAX];
- ::snprintf (pathbuf, sizeof (pathbuf), "%s/System/Library/Extensions", dir_pathbuf);
- FileSpec dir_sle(pathbuf, true);
- if (dir_sle.Exists() && dir_sle.GetFileType() == FileSpec::eFileTypeDirectory)
- {
- directories.push_back (dir_sle);
- }
+ directories.push_back (dir_sle);
}
}
}
@@ -467,13 +459,13 @@ PlatformDarwinKernel::SearchSDKsForKextD
for (uint32_t i = 0; i < num_sdks; i++)
{
const FileSpec &sdk_dir = sdk_dirs[i];
- char pathbuf[PATH_MAX];
- if (sdk_dir.GetPath (pathbuf, sizeof (pathbuf)))
+ std::string sdk_dir_path = sdk_dir.GetPath();
+ if (!sdk_dir_path.empty())
{
const bool find_directories = true;
const bool find_files = false;
const bool find_other = false;
- FileSpec::EnumerateDirectory (pathbuf,
+ FileSpec::EnumerateDirectory (sdk_dir_path.c_str(),
find_directories,
find_files,
find_other,
@@ -498,16 +490,12 @@ PlatformDarwinKernel::GetKextDirectories
&& (file_spec.GetFileNameExtension() == ConstString("sdk")
|| file_spec.GetFileNameExtension() == ConstString("kdk")))
{
- char pathbuf[PATH_MAX];
- if (file_spec.GetPath (pathbuf, PATH_MAX))
+ std::string kext_directory_path = file_spec.GetPath();
+ kext_directory_path.append ("/System/Library/Extensions");
+ FileSpec kext_directory (kext_directory_path.c_str(), true);
+ if (kext_directory.Exists() && kext_directory.IsDirectory())
{
- char kext_directory_str[PATH_MAX];
- ::snprintf (kext_directory_str, sizeof (kext_directory_str), "%s/%s", pathbuf, "System/Library/Extensions");
- FileSpec kext_directory (kext_directory_str, true);
- if (kext_directory.Exists() && kext_directory.GetFileType() == FileSpec::eFileTypeDirectory)
- {
- ((std::vector<lldb_private::FileSpec> *)baton)->push_back(kext_directory);
- }
+ ((std::vector<lldb_private::FileSpec> *)baton)->push_back(kext_directory);
}
}
return FileSpec::eEnumerateDirectoryResultNext;
@@ -522,38 +510,30 @@ PlatformDarwinKernel::IndexKextsInDirect
for (uint32_t i = 0; i < num_dirs; i++)
{
const FileSpec &dir = kext_dirs[i];
- char pathbuf[PATH_MAX];
- if (dir.GetPath (pathbuf, sizeof(pathbuf)))
- {
- const bool find_directories = true;
- const bool find_files = false;
- const bool find_other = false;
- FileSpec::EnumerateDirectory (pathbuf,
- find_directories,
- find_files,
- find_other,
- GetKextsInDirectory,
- &kext_bundles);
- }
+ const bool find_directories = true;
+ const bool find_files = false;
+ const bool find_other = false;
+ FileSpec::EnumerateDirectory (dir.GetPath().c_str(),
+ find_directories,
+ find_files,
+ find_other,
+ GetKextsInDirectory,
+ &kext_bundles);
}
const uint32_t num_kexts = kext_bundles.size();
for (uint32_t i = 0; i < num_kexts; i++)
{
const FileSpec &kext = kext_bundles[i];
- char pathbuf[PATH_MAX];
- if (kext.GetPath (pathbuf, sizeof (pathbuf)))
+ CFCBundle bundle (kext.GetPath().c_str());
+ CFStringRef bundle_id (bundle.GetIdentifier());
+ if (bundle_id && CFGetTypeID (bundle_id) == CFStringGetTypeID ())
{
- CFCBundle bundle (pathbuf);
- CFStringRef bundle_id (bundle.GetIdentifier());
- if (bundle_id && CFGetTypeID (bundle_id) == CFStringGetTypeID ())
+ char bundle_id_buf[PATH_MAX];
+ if (CFStringGetCString (bundle_id, bundle_id_buf, sizeof (bundle_id_buf), kCFStringEncodingUTF8))
{
- char bundle_id_buf[PATH_MAX];
- if (CFStringGetCString (bundle_id, bundle_id_buf, sizeof (bundle_id_buf), kCFStringEncodingUTF8))
- {
- ConstString bundle_conststr(bundle_id_buf);
- m_name_to_kext_path_map.insert(std::pair<ConstString, FileSpec>(bundle_conststr, kext));
- }
+ ConstString bundle_conststr(bundle_id_buf);
+ m_name_to_kext_path_map.insert(std::pair<ConstString, FileSpec>(bundle_conststr, kext));
}
}
}
@@ -572,30 +552,30 @@ PlatformDarwinKernel::GetKextsInDirector
if (file_type == FileSpec::eFileTypeDirectory && file_spec.GetFileNameExtension() == ConstString("kext"))
{
((std::vector<lldb_private::FileSpec> *)baton)->push_back(file_spec);
- bool search_inside = false;
- char pathbuf[PATH_MAX];
- ::snprintf (pathbuf, sizeof (pathbuf), "%s/%s/Contents/PlugIns", file_spec.GetDirectory().GetCString(), file_spec.GetFilename().GetCString());
- FileSpec contents_plugins (pathbuf, false);
- if (contents_plugins.Exists() && contents_plugins.GetFileType() == FileSpec::eFileTypeDirectory)
+ std::string kext_bundle_path = file_spec.GetPath();
+ std::string search_here_too;
+ std::string contents_plugins_path = kext_bundle_path + "/Contents/PlugIns";
+ FileSpec contents_plugins (contents_plugins_path.c_str(), false);
+ if (contents_plugins.Exists() && contents_plugins.IsDirectory())
{
- search_inside = true;
+ search_here_too = contents_plugins_path;
}
else
{
- ::snprintf (pathbuf, sizeof (pathbuf), "%s/%s/PlugIns", file_spec.GetDirectory().GetCString(), file_spec.GetFilename().GetCString());
- FileSpec plugins (pathbuf, false);
- if (plugins.Exists() && plugins.GetFileType() == FileSpec::eFileTypeDirectory)
+ std::string plugins_path = kext_bundle_path + "/PlugIns";
+ FileSpec plugins (plugins_path.c_str(), false);
+ if (plugins.Exists() && plugins.IsDirectory())
{
- search_inside = true;
+ search_here_too = plugins_path;
}
}
- if (search_inside)
+ if (!search_here_too.empty())
{
const bool find_directories = true;
const bool find_files = false;
const bool find_other = false;
- FileSpec::EnumerateDirectory (pathbuf,
+ FileSpec::EnumerateDirectory (search_here_too.c_str(),
find_directories,
find_files,
find_other,
@@ -616,10 +596,10 @@ PlatformDarwinKernel::GetSharedModule (c
Error error;
module_sp.reset();
const FileSpec &platform_file = module_spec.GetFileSpec();
- char kext_bundle_id[PATH_MAX];
- if (platform_file.GetPath (kext_bundle_id, sizeof (kext_bundle_id)))
+ std::string kext_bundle_id = platform_file.GetPath();
+ if (!kext_bundle_id.empty())
{
- ConstString kext_bundle_cs(kext_bundle_id);
+ ConstString kext_bundle_cs(kext_bundle_id.c_str());
if (m_name_to_kext_path_map.count(kext_bundle_cs) > 0)
{
for (BundleIDToKextIterator it = m_name_to_kext_path_map.begin (); it != m_name_to_kext_path_map.end (); ++it)
More information about the lldb-commits
mailing list