[Lldb-commits] [lldb] r254608 - Remove some duplicated code from PlatformPOSIX/Android
Tamas Berghammer via lldb-commits
lldb-commits at lists.llvm.org
Thu Dec 3 04:58:04 PST 2015
Author: tberghammer
Date: Thu Dec 3 06:58:03 2015
New Revision: 254608
URL: http://llvm.org/viewvc/llvm-project?rev=254608&view=rev
Log:
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.
Differential revision: http://reviews.llvm.org/D15183
Modified:
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
Modified: lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp?rev=254608&r1=254607&r2=254608&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp Thu Dec 3 06:58:03 2015
@@ -377,90 +377,13 @@ PlatformAndroid::GetRemoteOSVersion ()
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 DataBufferHeap(10240,0));
- size_t num_chars = error_str_sp->ReadPointedString (buffer_sp, error, 10240).first;
- if (error.Success() && num_chars > 0)
- error.SetErrorStringWithFormat("dlopen error: %s", buffer_sp->GetBytes());
- else
- error.SetErrorStringWithFormat("dlopen failed for unknown reasons.");
- return LLDB_INVALID_IMAGE_TOKEN;
- }
- }
- error.SetErrorStringWithFormat("unable to load '%s'", path);
- return LLDB_INVALID_IMAGE_TOKEN;
-}
-
-Error
-PlatformAndroid::UnloadImage (lldb_private::Process* process, uint32_t image_token)
-{
- const addr_t image_addr = process->GetImagePtrFromToken(image_token);
- if (image_addr == LLDB_INVALID_ADDRESS)
- return Error("Invalid image token");
-
- StreamString expr;
- expr.Printf("__dl_dlclose((void*)0x%" PRIx64 ")", image_addr);
- const char *prefix = "extern \"C\" int __dl_dlclose(void* handle);\n";
- lldb::ValueObjectSP result_valobj_sp;
- Error error = EvaluateLibdlExpression(process, expr.GetData(), prefix, result_valobj_sp);
- if (error.Fail())
- return error;
-
- if (result_valobj_sp->GetError().Fail())
- return result_valobj_sp->GetError();
-
- Scalar scalar;
- if (result_valobj_sp->ResolveValue(scalar))
- {
- if (scalar.UInt(1))
- return Error("expression failed: \"%s\"", expr.GetData());
- process->ResetImageToken(image_token);
- }
- return Error();
+ 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");
+ )";
}
Modified: lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.h?rev=254608&r1=254607&r2=254608&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.h (original)
+++ lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.h Thu Dec 3 06:58:03 2015
@@ -84,14 +84,6 @@ namespace platform_android {
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 @@ namespace platform_android {
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;
Modified: lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp?rev=254608&r1=254607&r2=254608&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp Thu Dec 3 06:58:03 2015
@@ -918,10 +918,7 @@ PlatformPOSIX::LoadImage(lldb_private::P
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 @@ PlatformPOSIX::UnloadImage (lldb_private
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 @@ PlatformPOSIX::UnloadImage (lldb_private
}
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);
+ )";
+}
Modified: lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.h?rev=254608&r1=254607&r2=254608&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.h (original)
+++ lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.h Thu Dec 3 06:58:03 2015
@@ -191,6 +191,9 @@ protected:
const char *expr_prefix,
lldb::ValueObjectSP& result_valobj_sp);
+ virtual const char*
+ GetLibdlFunctionDeclarations() const;
+
private:
DISALLOW_COPY_AND_ASSIGN (PlatformPOSIX);
};
More information about the lldb-commits
mailing list