Index: include/lldb/Target/Platform.h =================================================================== --- include/lldb/Target/Platform.h +++ include/lldb/Target/Platform.h @@ -868,6 +868,14 @@ const lldb::UnixSignalsSP & GetUnixSignals(); + + // Android prefixes th functions in lindl.so. Let it specify the prefix used for those + // functions. + virtual const char* + GetDlFunctionPrefix() + { + return ""; + } //------------------------------------------------------------------ /// Locate a queue name given a thread's qaddr Index: source/Plugins/Platform/Android/PlatformAndroid.h =================================================================== --- source/Plugins/Platform/Android/PlatformAndroid.h +++ source/Plugins/Platform/Android/PlatformAndroid.h @@ -73,6 +73,12 @@ const FileSpec& destination, uint32_t uid = UINT32_MAX, uint32_t gid = UINT32_MAX) override; + + const char* + GetDlFunctionPrefix() override + { + return "__dl_"; + } protected: const char * Index: source/Target/Process.cpp =================================================================== --- source/Target/Process.cpp +++ source/Target/Process.cpp @@ -1913,12 +1913,14 @@ expr_options.SetResultIsInternal(true); StreamString expr; + StreamString prefix; + const char* dl_prefix = m_target.GetPlatform()->GetDlFunctionPrefix(); expr.Printf(R"( struct __lldb_dlopen_result { void *image_ptr; const char *error_str; } the_result; - the_result.image_ptr = dlopen ("%s", 2); + the_result.image_ptr = %sdlopen ("%s", 2); if (the_result.image_ptr == (void *) 0x0) { - the_result.error_str = dlerror(); + the_result.error_str = %sdlerror(); } else { @@ -1926,17 +1928,18 @@ } the_result; )", - path); - const char *prefix = R"( - extern "C" void* dlopen (const char *path, int mode); - extern "C" const char *dlerror (void); - )"; + dl_prefix, path, dl_prefix); + prefix.Printf(R"( + extern "C" void* %sdlopen (const char *path, int mode); + extern "C" const char *%sdlerror (void); + )", + dl_prefix, dl_prefix); lldb::ValueObjectSP result_valobj_sp; Error expr_error; ClangUserExpression::Evaluate (exe_ctx, expr_options, expr.GetData(), - prefix, + prefix.GetData(), result_valobj_sp, expr_error); if (expr_error.Success()) @@ -2038,15 +2041,19 @@ expr_options.SetUnwindOnError(true); expr_options.SetIgnoreBreakpoints(true); expr_options.SetExecutionPolicy(eExecutionPolicyAlways); + StreamString expr; - expr.Printf("dlclose ((void *)0x%" PRIx64 ")", image_addr); - const char *prefix = "extern \"C\" int dlclose(void* handle);\n"; + StreamString prefix; + const char* dl_prefix = m_target.GetPlatform()->GetDlFunctionPrefix(); + expr.Printf("%sdlclose ((void *)0x%" PRIx64 ")", dl_prefix, image_addr); + prefix.Printf("extern \"C\" int %sdlclose(void* handle);\n", dl_prefix); + lldb::ValueObjectSP result_valobj_sp; Error expr_error; ClangUserExpression::Evaluate (exe_ctx, expr_options, expr.GetData(), - prefix, + prefix.GetData(), result_valobj_sp, expr_error); if (result_valobj_sp->GetError().Success()) Index: test/functionalities/load_unload/TestLoadUnload.py =================================================================== --- test/functionalities/load_unload/TestLoadUnload.py +++ test/functionalities/load_unload/TestLoadUnload.py @@ -176,7 +176,6 @@ @skipIfFreeBSD # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase support @skipUnlessListedRemote(['android']) - @expectedFailureAndroid # dlopen and dlclose prefixed with "__dl_" on android causing JIT compilation issues def test_lldb_process_load_and_unload_commands(self): """Test that lldb process load/unload command work correctly.""" @@ -198,21 +197,25 @@ shlib_dir = lldb.remote_platform.GetWorkingDirectory() else: shlib_dir = self.mydir - # Make sure that a_function does not exist at this point. - self.expect("image lookup -n a_function", "a_function should not exist yet", - error=True, matching=False, - patterns = ["1 match found .* %s" % shlib_dir]) - if lldb.remote_platform: - dylibName = os.path.join(shlib_dir, 'libloadunload_a.so') - elif self.platformIsDarwin(): + if self.platformIsDarwin(): dylibName = 'libloadunload_a.dylib' else: dylibName = 'libloadunload_a.so' + + if lldb.remote_platform: + dylibPath = os.path.join(shlib_dir, 'libloadunload_a.so') + else: + dylibPath = dylibName + + # Make sure that a_function does not exist at this point. + self.expect("image lookup -n a_function", "a_function should not exist yet", + error=True, matching=False, patterns = ["1 match found"]) + # Use lldb 'process load' to load the dylib. - self.expect("process load %s" % dylibName, "%s loaded correctly" % dylibName, - patterns = ['Loading "%s".*ok' % dylibName, + self.expect("process load %s" % dylibPath, "%s loaded correctly" % dylibPath, + patterns = ['Loading "%s".*ok' % dylibPath, 'Image [0-9]+ loaded']) # Search for and match the "Image ([0-9]+) loaded" pattern. @@ -227,7 +230,7 @@ # Now we should have an entry for a_function. self.expect("image lookup -n a_function", "a_function should now exist", - patterns = ["1 match found .*%s" % shlib_dir]) + patterns = ["1 match found .*%s" % dylibName]) # Use lldb 'process unload' to unload the dylib. self.expect("process unload %s" % index, "%s unloaded correctly" % dylibName,