[Lldb-commits] [PATCH] D15183: Remove some duplicated code from PlatformPOSIX/Android

2015-12-03 Thread Tamas Berghammer via lldb-commits
tberghammer created this revision.
tberghammer added a reviewer: labath.
tberghammer added a subscriber: lldb-commits.
Herald added subscribers: srhines, danalbert, tberghammer, emaste.

Remove some duplicated code from PlatformPOSIX/Android

The code was duplicated to handle the custom symbol name for functions
in libdl.so for android. This change modify the way we handle the issue
to eliminate a lot of duplicated code.

http://reviews.llvm.org/D15183

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
@@ -191,6 +191,9 @@
 const char *expr_prefix,
 lldb::ValueObjectSP& result_valobj_sp);
 
+virtual const char*
+GetLibdlFunctionDeclarations() const;
+
 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
@@ -918,10 +918,7 @@
the_result;
   )",
   path);
-const char *prefix = R"(
-extern "C" void* dlopen (const char *path, int mode);
-extern "C" const char *dlerror (void);
-)";
+const char *prefix = GetLibdlFunctionDeclarations();
 lldb::ValueObjectSP result_valobj_sp;
 error = EvaluateLibdlExpression(process, expr.GetData(), prefix, result_valobj_sp);
 if (error.Fail())
@@ -970,7 +967,7 @@
 
 StreamString expr;
 expr.Printf("dlclose((void *)0x%" PRIx64 ")", image_addr);
-const char *prefix = "extern \"C\" int dlclose(void* handle);\n";
+const char *prefix = GetLibdlFunctionDeclarations();
 lldb::ValueObjectSP result_valobj_sp;
 Error error = EvaluateLibdlExpression(process, expr.GetData(), prefix, result_valobj_sp);
 if (error.Fail())
@@ -988,3 +985,14 @@
 }
 return Error();
 }
+
+const char*
+PlatformPOSIX::GetLibdlFunctionDeclarations() const
+{
+return R"(
+  extern "C" void* dlopen(const char*, int);
+  extern "C" void* dlsym(void*, const char*);
+  extern "C" int   dlclose(void*);
+  extern "C" char* dlerror(void);
+ )";
+}
Index: source/Plugins/Platform/Android/PlatformAndroid.h
===
--- source/Plugins/Platform/Android/PlatformAndroid.h
+++ source/Plugins/Platform/Android/PlatformAndroid.h
@@ -84,14 +84,6 @@
 uint32_t
 GetDefaultMemoryCacheLineSize() override;
 
-uint32_t
-LoadImage (lldb_private::Process* process,
-   const lldb_private::FileSpec& image_spec,
-   lldb_private::Error& error) override;
-
-lldb_private::Error
-UnloadImage (lldb_private::Process* process, uint32_t image_token) override;
-
  protected:
 const char *
 GetCacheHostname () override;
@@ -106,6 +98,9 @@
 DownloadSymbolFile (const lldb::ModuleSP& module_sp,
 const FileSpec& dst_file_spec) override;
 
+const char*
+GetLibdlFunctionDeclarations() const override;
+
 private:
 std::string m_device_id;
 uint32_t m_sdk_version;
Index: source/Plugins/Platform/Android/PlatformAndroid.cpp
===
--- source/Plugins/Platform/Android/PlatformAndroid.cpp
+++ source/Plugins/Platform/Android/PlatformAndroid.cpp
@@ -377,90 +377,13 @@
 return m_major_os_version != 0;
 }
 
-uint32_t
-PlatformAndroid::LoadImage(lldb_private::Process* process, const FileSpec& image_spec, Error& error)
-{
-char path[PATH_MAX];
-image_spec.GetPath(path, sizeof(path));
-
-StreamString expr;
-expr.Printf(R"(
-   struct __lldb_dlopen_result { void *image_ptr; const char *error_str; } the_result;
-   the_result.image_ptr = __dl_dlopen ("%s", 2);
-   if (the_result.image_ptr == (void*)0x0)
-   the_result.error_str = __dl_dlerror();
-   else
-   the_result.error_str = (const char*)0x0;
-   the_result;
-  )",
-  path);
-const char *prefix = R"(
-extern "C" void* __dl_dlopen(const char* path, int mode);
-extern "C" const char *__dl_dlerror(void);
-)";
-lldb::ValueObjectSP result_valobj_sp;
-error = 

Re: [Lldb-commits] [PATCH] D15183: Remove some duplicated code from PlatformPOSIX/Android

2015-12-03 Thread Tamas Berghammer via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL254608: Remove some duplicated code from 
PlatformPOSIX/Android (authored by tberghammer).

Changed prior to commit:
  http://reviews.llvm.org/D15183?vs=41735=41742#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D15183

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

Index: lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
===
--- lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
+++ lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
@@ -918,10 +918,7 @@
the_result;
   )",
   path);
-const char *prefix = R"(
-extern "C" void* dlopen (const char *path, int mode);
-extern "C" const char *dlerror (void);
-)";
+const char *prefix = GetLibdlFunctionDeclarations();
 lldb::ValueObjectSP result_valobj_sp;
 error = EvaluateLibdlExpression(process, expr.GetData(), prefix, result_valobj_sp);
 if (error.Fail())
@@ -970,7 +967,7 @@
 
 StreamString expr;
 expr.Printf("dlclose((void *)0x%" PRIx64 ")", image_addr);
-const char *prefix = "extern \"C\" int dlclose(void* handle);\n";
+const char *prefix = GetLibdlFunctionDeclarations();
 lldb::ValueObjectSP result_valobj_sp;
 Error error = EvaluateLibdlExpression(process, expr.GetData(), prefix, result_valobj_sp);
 if (error.Fail())
@@ -988,3 +985,14 @@
 }
 return Error();
 }
+
+const char*
+PlatformPOSIX::GetLibdlFunctionDeclarations() const
+{
+return R"(
+  extern "C" void* dlopen(const char*, int);
+  extern "C" void* dlsym(void*, const char*);
+  extern "C" int   dlclose(void*);
+  extern "C" char* dlerror(void);
+ )";
+}
Index: lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.h
===
--- lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.h
+++ lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.h
@@ -191,6 +191,9 @@
 const char *expr_prefix,
 lldb::ValueObjectSP& result_valobj_sp);
 
+virtual const char*
+GetLibdlFunctionDeclarations() const;
+
 private:
 DISALLOW_COPY_AND_ASSIGN (PlatformPOSIX);
 };
Index: lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp
===
--- lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp
+++ lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp
@@ -377,90 +377,13 @@
 return m_major_os_version != 0;
 }
 
-uint32_t
-PlatformAndroid::LoadImage(lldb_private::Process* process, const FileSpec& image_spec, Error& error)
+const char*
+PlatformAndroid::GetLibdlFunctionDeclarations() const
 {
-char path[PATH_MAX];
-image_spec.GetPath(path, sizeof(path));
-
-StreamString expr;
-expr.Printf(R"(
-   struct __lldb_dlopen_result { void *image_ptr; const char *error_str; } the_result;
-   the_result.image_ptr = __dl_dlopen ("%s", 2);
-   if (the_result.image_ptr == (void*)0x0)
-   the_result.error_str = __dl_dlerror();
-   else
-   the_result.error_str = (const char*)0x0;
-   the_result;
-  )",
-  path);
-const char *prefix = R"(
-extern "C" void* __dl_dlopen(const char* path, int mode);
-extern "C" const char *__dl_dlerror(void);
-)";
-lldb::ValueObjectSP result_valobj_sp;
-error = EvaluateLibdlExpression(process, expr.GetData(), prefix, result_valobj_sp);
-if (error.Fail())
-return LLDB_INVALID_IMAGE_TOKEN;
-
-error = result_valobj_sp->GetError();
-if (error.Fail())
-return LLDB_INVALID_IMAGE_TOKEN;
-
-Scalar scalar;
-ValueObjectSP image_ptr_sp = result_valobj_sp->GetChildAtIndex(0, true);
-if (!image_ptr_sp || !image_ptr_sp->ResolveValue(scalar))
-{
-error.SetErrorStringWithFormat("unable to load '%s'", path);
-return LLDB_INVALID_IMAGE_TOKEN;
-}
-
-addr_t image_ptr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
-if (image_ptr != 0 && image_ptr != LLDB_INVALID_ADDRESS)
-return process->AddImageToken(image_ptr);
-
-if (image_ptr == 0)
-{
-ValueObjectSP error_str_sp = result_valobj_sp->GetChildAtIndex(1, true);
-if (error_str_sp && error_str_sp->IsCStringContainer(true))
-{
-DataBufferSP buffer_sp(new 

Re: [Lldb-commits] [PATCH] D15183: Remove some duplicated code from PlatformPOSIX/Android

2015-12-03 Thread Jim Ingham via lldb-commits
jingham added a comment.

Cute!  That's much nicer.


Repository:
  rL LLVM

http://reviews.llvm.org/D15183



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits