[Lldb-commits] [lldb] r228057 - Use basename of main executable in POSIX-DYLD on Android.

Stephane Sezer sas at fb.com
Tue Feb 3 15:07:48 PST 2015


Hey Hans,

Can this be ported to the 3.6 branch of LLDB?

Thanks.

-- 
Stephane Sezer

> On Feb 3, 2015, at 2:48 PM, Stephane Sezer <sas at cd80.net> wrote:
> 
> Author: sas
> Date: Tue Feb  3 16:48:34 2015
> New Revision: 228057
> 
> URL: https://urldefense.proofpoint.com/v1/url?u=http://llvm.org/viewvc/llvm-project?rev%3D228057%26view%3Drev&k=ZVNjlDMF0FElm4dQtryO4A%3D%3D%0A&r=g1GoAnQQskSBaWLJWw6X6w%3D%3D%0A&m=59IdNCzsjVmLCYoH6sIwbxMTZP7uvzg3InmARPWwFS0%3D%0A&s=ec067bbec1642366d5ad451a53f8672fd7785685b36e92dba00dc26b33a9dbba
> Log:
> Use basename of main executable in POSIX-DYLD on Android.
> 
> Summary:
> The Android dynamic linker reports only the basename of each SO entry, so for
> the above check to be successful, we need to compare it to the basename of the
> main executable.
> 
> This also has a nasty side-effect when working with older version of
> Android (verified on platform version 16), and debugging PIE
> executables: the dynamic linker has a bug and reports the load address
> of the main executable (which is a shared object, because PIE) to be 0.
> We then try to update the list of loaded sections for all shared
> objects, including the main executable, and set the load address to 0,
> which breaks everything that relies on resolving addresses in the main
> executable (breakpoints, stepping, etc). This commit also fixes that broken
> behavior when debugging on older Androids. This bug doesn't happen on newer
> Android versions (verified for Android L).
> 
> Test Plan: Run test suite on linux.
> 
> Reviewers: clayborg, tfiala, richard.mitton
> 
> Subscribers: lldb-commits
> 
> Differential Revision: https://urldefense.proofpoint.com/v1/url?u=http://reviews.llvm.org/D7188&k=ZVNjlDMF0FElm4dQtryO4A%3D%3D%0A&r=g1GoAnQQskSBaWLJWw6X6w%3D%3D%0A&m=59IdNCzsjVmLCYoH6sIwbxMTZP7uvzg3InmARPWwFS0%3D%0A&s=bda4554590bf50859e131fc28a01065e0d29a1117e3b852a72eecdef2ecc2d3c
> 
> Modified:
>    lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp
>    lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.h
> 
> Modified: lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp
> URL: https://urldefense.proofpoint.com/v1/url?u=http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp?rev%3D228057%26r1%3D228056%26r2%3D228057%26view%3Ddiff&k=ZVNjlDMF0FElm4dQtryO4A%3D%3D%0A&r=g1GoAnQQskSBaWLJWw6X6w%3D%3D%0A&m=59IdNCzsjVmLCYoH6sIwbxMTZP7uvzg3InmARPWwFS0%3D%0A&s=0cffcd470300f81bb07d25e0c9020b7ad3e6969d9cec3bde446a58fed40b7430
> ==============================================================================
> --- lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp (original)
> +++ lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp Tue Feb  3 16:48:34 2015
> @@ -19,6 +19,8 @@
> #include "lldb/Target/Process.h"
> #include "lldb/Target/Target.h"
> 
> +#include "llvm/Support/Path.h"
> +
> #include "DYLDRendezvous.h"
> 
> using namespace lldb;
> @@ -238,9 +240,7 @@ DYLDRendezvous::UpdateSOEntriesForAdditi
>             return false;
> 
>         // Only add shared libraries and not the executable.
> -        // On Linux this is indicated by an empty path in the entry.
> -        // On FreeBSD it is the name of the executable.
> -        if (entry.path.empty() || ::strcmp(entry.path.c_str(), m_exe_path) == 0)
> +        if (SOEntryIsMainExecutable(entry))
>             continue;
> 
>         pos = std::find(m_soentries.begin(), m_soentries.end(), entry);
> @@ -277,6 +277,28 @@ DYLDRendezvous::UpdateSOEntriesForDeleti
> }
> 
> bool
> +DYLDRendezvous::SOEntryIsMainExecutable(const SOEntry &entry)
> +{
> +    // On Linux the executable is indicated by an empty path in the entry. On
> +    // FreeBSD it is the full path to the executable. On Android, it is the
> +    // basename of the executable.
> +
> +    auto triple = m_process->GetTarget().GetArchitecture().GetTriple();
> +    auto os_type = triple.getOS();
> +    auto env_type = triple.getEnvironment();
> +
> +    switch (os_type) {
> +        case llvm::Triple::FreeBSD:
> +            return ::strcmp(entry.path.c_str(), m_exe_path) == 0;
> +        case llvm::Triple::Linux:
> +            return entry.path.empty() || (env_type == llvm::Triple::Android &&
> +                   llvm::sys::path::filename(m_exe_path) == entry.path);
> +        default:
> +            return false;
> +    }
> +}
> +
> +bool
> DYLDRendezvous::TakeSnapshot(SOEntryList &entry_list)
> {
>     SOEntry entry;
> @@ -290,9 +312,7 @@ DYLDRendezvous::TakeSnapshot(SOEntryList
>             return false;
> 
>         // Only add shared libraries and not the executable.
> -        // On Linux this is indicated by an empty path in the entry.
> -        // On FreeBSD it is the name of the executable.
> -        if (entry.path.empty() || ::strcmp(entry.path.c_str(), m_exe_path) == 0)
> +        if (SOEntryIsMainExecutable(entry))
>             continue;
> 
>         entry_list.push_back(entry);
> 
> Modified: lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.h
> URL: https://urldefense.proofpoint.com/v1/url?u=http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.h?rev%3D228057%26r1%3D228056%26r2%3D228057%26view%3Ddiff&k=ZVNjlDMF0FElm4dQtryO4A%3D%3D%0A&r=g1GoAnQQskSBaWLJWw6X6w%3D%3D%0A&m=59IdNCzsjVmLCYoH6sIwbxMTZP7uvzg3InmARPWwFS0%3D%0A&s=4c0b33cb650b88c145d35e26787b0690b1c10c7cd8459ef9982917fdc0860a60
> ==============================================================================
> --- lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.h (original)
> +++ lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.h Tue Feb  3 16:48:34 2015
> @@ -247,6 +247,9 @@ protected:
>     bool
>     UpdateSOEntriesForDeletion();
> 
> +    bool
> +    SOEntryIsMainExecutable(const SOEntry &entry);
> +
>     /// Reads the current list of shared objects according to the link map
>     /// supplied by the runtime linker.
>     bool
> 
> 
> _______________________________________________
> lldb-commits mailing list
> lldb-commits at cs.uiuc.edu
> https://urldefense.proofpoint.com/v1/url?u=http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits&k=ZVNjlDMF0FElm4dQtryO4A%3D%3D%0A&r=g1GoAnQQskSBaWLJWw6X6w%3D%3D%0A&m=59IdNCzsjVmLCYoH6sIwbxMTZP7uvzg3InmARPWwFS0%3D%0A&s=d9c6255ba0b44c1e2dce881d47aed73a13fefaa87e883b378b2fc548e9db31ef





More information about the lldb-commits mailing list