[Lldb-commits] [PATCH] D30460: Fix "process load" on new android targets

Pavel Labath via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Feb 28 07:11:39 PST 2017


labath created this revision.
Herald added subscribers: srhines, danalbert, emaste.

On older android targets, we needed a dlopen rename workaround to get
"process load" working. Since API 25 this is not required as the targets
have a proper libdl so with the function names one would expect.

To make this work I've had to remove the const qualifier from the
GetLibdlFunctionDeclarations function (as now the declarations can
depend on the connected target). Since I was already modifying the
prototype (and the lower levels were already converted to StringRef) I
took the oportunity to convert this function as well.


https://reviews.llvm.org/D30460

Files:
  source/Plugins/Platform/Android/PlatformAndroid.cpp
  source/Plugins/Platform/Android/PlatformAndroid.h
  source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
  source/Plugins/Platform/POSIX/PlatformPOSIX.h


Index: source/Plugins/Platform/POSIX/PlatformPOSIX.h
===================================================================
--- source/Plugins/Platform/POSIX/PlatformPOSIX.h
+++ source/Plugins/Platform/POSIX/PlatformPOSIX.h
@@ -195,10 +195,10 @@
 
   lldb_private::Error
   EvaluateLibdlExpression(lldb_private::Process *process, const char *expr_cstr,
-                          const char *expr_prefix,
+                          llvm::StringRef expr_prefix,
                           lldb::ValueObjectSP &result_valobj_sp);
 
-  virtual const char *GetLibdlFunctionDeclarations() const;
+  virtual llvm::StringRef GetLibdlFunctionDeclarations();
 
 private:
   DISALLOW_COPY_AND_ASSIGN(PlatformPOSIX);
Index: source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
===================================================================
--- source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
+++ source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
@@ -880,7 +880,7 @@
 
 Error PlatformPOSIX::EvaluateLibdlExpression(
     lldb_private::Process *process, const char *expr_cstr,
-    const char *expr_prefix, lldb::ValueObjectSP &result_valobj_sp) {
+    llvm::StringRef expr_prefix, lldb::ValueObjectSP &result_valobj_sp) {
   DynamicLoader *loader = process->GetDynamicLoader();
   if (loader) {
     Error error = loader->CanLoadImage();
@@ -940,7 +940,7 @@
                    the_result;
                   )",
               path);
-  const char *prefix = GetLibdlFunctionDeclarations();
+  llvm::StringRef prefix = GetLibdlFunctionDeclarations();
   lldb::ValueObjectSP result_valobj_sp;
   error = EvaluateLibdlExpression(process, expr.GetData(), prefix,
                                   result_valobj_sp);
@@ -988,7 +988,7 @@
 
   StreamString expr;
   expr.Printf("dlclose((void *)0x%" PRIx64 ")", image_addr);
-  const char *prefix = GetLibdlFunctionDeclarations();
+  llvm::StringRef prefix = GetLibdlFunctionDeclarations();
   lldb::ValueObjectSP result_valobj_sp;
   Error error = EvaluateLibdlExpression(process, expr.GetData(), prefix,
                                         result_valobj_sp);
@@ -1020,7 +1020,7 @@
                                   error);
 }
 
-const char *PlatformPOSIX::GetLibdlFunctionDeclarations() const {
+llvm::StringRef PlatformPOSIX::GetLibdlFunctionDeclarations() {
   return R"(
               extern "C" void* dlopen(const char*, int);
               extern "C" void* dlsym(void*, const char*);
Index: source/Plugins/Platform/Android/PlatformAndroid.h
===================================================================
--- source/Plugins/Platform/Android/PlatformAndroid.h
+++ source/Plugins/Platform/Android/PlatformAndroid.h
@@ -76,7 +76,7 @@
   Error DownloadSymbolFile(const lldb::ModuleSP &module_sp,
                            const FileSpec &dst_file_spec) override;
 
-  const char *GetLibdlFunctionDeclarations() const override;
+  llvm::StringRef GetLibdlFunctionDeclarations() override;
 
 private:
   AdbClient::SyncService *GetSyncService(Error &error);
Index: source/Plugins/Platform/Android/PlatformAndroid.cpp
===================================================================
--- source/Plugins/Platform/Android/PlatformAndroid.cpp
+++ source/Plugins/Platform/Android/PlatformAndroid.cpp
@@ -366,13 +366,17 @@
   return m_major_os_version != 0;
 }
 
-const char *PlatformAndroid::GetLibdlFunctionDeclarations() const {
-  return R"(
+llvm::StringRef PlatformAndroid::GetLibdlFunctionDeclarations() {
+  // Older platform versions have the dl function symbols mangled
+  if (GetSdkVersion() < 25)
+    return R"(
               extern "C" void* dlopen(const char*, int) asm("__dl_dlopen");
               extern "C" void* dlsym(void*, const char*) asm("__dl_dlsym");
               extern "C" int   dlclose(void*) asm("__dl_dlclose");
               extern "C" char* dlerror(void) asm("__dl_dlerror");
              )";
+
+  return PlatformPOSIX::GetLibdlFunctionDeclarations();
 }
 
 AdbClient::SyncService *PlatformAndroid::GetSyncService(Error &error) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30460.90028.patch
Type: text/x-patch
Size: 4008 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20170228/86d878cf/attachment.bin>


More information about the lldb-commits mailing list