[Lldb-commits] [PATCH] Search for loaded modules recursively in all system library sub-directories on Android
Oleksiy Vyalov
ovyalov at google.com
Fri Mar 13 17:51:37 PDT 2015
Hi tberghammer,
Search for loaded modules recursively in all system lib sub-directories on Android.
Android native application may load modules from such directories: /system/lib, /system/lib/egl (libEGL_emulation.so,..), /system/lib/hw (gralloc.goldfish.so).
http://reviews.llvm.org/D8338
Files:
source/Host/android/HostInfoAndroid.cpp
Index: source/Host/android/HostInfoAndroid.cpp
===================================================================
--- source/Host/android/HostInfoAndroid.cpp
+++ source/Host/android/HostInfoAndroid.cpp
@@ -9,12 +9,46 @@
#include "lldb/Host/android/HostInfoAndroid.h"
#include "lldb/Host/linux/HostInfoLinux.h"
-#include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/StringRef.h"
+
+#include <sstream>
+#include <string>
+#include <vector>
using namespace lldb_private;
using namespace llvm;
+namespace {
+
+using StringVector = std::vector<std::string>;
+
+FileSpec::EnumerateDirectoryResult
+EnumerateDirectoryCallback(void *baton, FileSpec::FileType file_type, const FileSpec &spec);
+
+void
+EnumerateSubDirs(const char* root_dir, StringVector &paths)
+{
+ paths.push_back(root_dir);
+ FileSpec::EnumerateDirectory(root_dir,
+ true,
+ false,
+ false,
+ EnumerateDirectoryCallback,
+ &paths);
+}
+
+FileSpec::EnumerateDirectoryResult
+EnumerateDirectoryCallback(void *baton, FileSpec::FileType file_type, const FileSpec &spec)
+{
+ StringVector* paths = reinterpret_cast<StringVector*>(baton);
+ const auto file_path = spec.GetPath();
+ if (file_type == FileSpec::eFileTypeDirectory)
+ EnumerateSubDirs(file_path.c_str(), *paths);
+
+ return FileSpec::eEnumerateDirectoryResultNext;
+}
+
+} // namespace
+
void
HostInfoAndroid::ComputeHostArchitectureSupport(ArchSpec &arch_32, ArchSpec &arch_64)
{
@@ -46,7 +80,7 @@
FileSpec
HostInfoAndroid::ResolveLibraryPath(const std::string& module_path, const ArchSpec& arch)
{
- static const char* const ld_library_path_separator = ":";
+ static const char ld_library_path_separator = ':';
static const char* const default_lib32_path[] = {
"/vendor/lib",
"/system/lib",
@@ -61,10 +95,15 @@
if (module_path.empty() || module_path[0] == '/')
return FileSpec(module_path.c_str(), true);
- SmallVector<StringRef, 4> ld_paths;
+ StringVector ld_paths;
if (const char* ld_library_path = ::getenv("LD_LIBRARY_PATH"))
- StringRef(ld_library_path).split(ld_paths, StringRef(ld_library_path_separator), -1, false);
+ {
+ std::istringstream ld_lib_stream(ld_library_path);
+ std::string lib_path;
+ while (std::getline(ld_lib_stream, lib_path, ld_library_path_separator))
+ ld_paths.push_back(lib_path);
+ }
const char* const* default_lib_path = nullptr;
switch (arch.GetAddressByteSize())
@@ -81,11 +120,11 @@
}
for(const char* const* it = default_lib_path; *it; ++it)
- ld_paths.push_back(StringRef(*it));
+ EnumerateSubDirs(*it, ld_paths);
- for (const StringRef& path : ld_paths)
+ for (const auto& path : ld_paths)
{
- FileSpec file_candidate(path.str().c_str(), true);
+ FileSpec file_candidate(path.c_str(), true);
file_candidate.AppendPathComponent(module_path.c_str());
if (file_candidate.Exists())
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8338.21977.patch
Type: text/x-patch
Size: 3130 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20150314/58ac82c4/attachment.bin>
More information about the lldb-commits
mailing list