Skip to content

ndk-gdb.py fails #3

Closed
Closed

Description

@jfirebaugh

Output:

Traceback (most recent call last):
  File "prebuilt/darwin-x86_64/bin/ndk-gdb.py", line 38, in <module>
    import gdbrunner
ImportError: No module named gdbrunner

The relevant code is:

NDK_PATH = os.path.normpath(os.path.join(os.path.dirname(__file__), '../..'))
sys.path.append(os.path.join(NDK_PATH, "python-packages"))
import gdbrunner

ndk-gdb.py is at prebuilt/darwin-x86_64/bin/ndk-gdb.py, so this adds $NDK_PATH/prebuilt/darwin-x86_64/bin/../../python-packages, i.e. $NDK_PATH/prebuilt/python-packages. The correct path seems to be $NDK_PATH/python-packages. If I change '../..' to '../../..', it gets further (but still fails).

Activity

  1. added this to the milestone on Mar 10, 2016
  2. jfirebaugh commented on Mar 10, 2016

    @jfirebaugh
    Author

    The next error I encounter is:

    ERROR: Failed to find ndk binary path, should be at './host-tools/bin'
    

    I can't find any directories named "host-tools" in the NDK tree, so I think this is another bug.

  3. jmgao commented on Mar 10, 2016

    @jmgao
    Contributor

    Oops, ndk-gdb.py wasn't updated for some paths moving around. I believe this patch should fix things:

    diff --git a/ndk-gdb.py b/ndk-gdb.py
    index 59071be..25268c6 100755
    --- a/ndk-gdb.py
    +++ b/ndk-gdb.py
    @@ -182,11 +182,7 @@ def extract_launchable(xmlroot):
    
    
     def ndk_bin_path():
    -    path = os.path.join(NDK_PATH, "host-tools", "bin")
    -    if not os.path.exists(path):
    -        error("Failed to find ndk binary path, should be at '{}'".format(path))
    -
    -    return path
    +    return os.path.dirname(os.path.realpath(__file__))
    
    
     def handle_args():
    
  4. jmgao commented on Mar 10, 2016

    @jmgao
    Contributor

    Sorry, this as well:

    diff --git a/ndk-gdb.py b/ndk-gdb.py
    index 25268c6..555e665 100755
    --- a/ndk-gdb.py
    +++ b/ndk-gdb.py
    @@ -32,8 +32,8 @@ import xml.etree.cElementTree as ElementTree
     import logging
    
     # Shared functions across gdbclient.py and ndk-gdb.py.
    -# ndk-gdb is installed to $NDK/host-tools/bin
    -NDK_PATH = os.path.normpath(os.path.join(os.path.dirname(__file__), '../..'))
    +# ndk-gdb is installed to $NDK/prebuilt/<platform>/bin
    +NDK_PATH = os.path.normpath(os.path.join(os.path.dirname(__file__), '../../..'))
     sys.path.append(os.path.join(NDK_PATH, "python-packages"))
     import gdbrunner
    
    
    
  5. jfirebaugh commented on Mar 10, 2016

    @jfirebaugh
    Author

    👍 Thanks, getting further with those patches.

  6. jfirebaugh commented on Mar 10, 2016

    @jfirebaugh
    Author

    Next issue is:

    make: ./build/core/build-local.mk: No such file or directory
    make: *** No rule to make target `./build/core/build-local.mk'.  Stop.
    

    Relevant code is:

        make_args = [args.make_cmd, "--no-print-dir", "-f",
                     os.path.join(NDK_PATH, "build/core/build-local.mk"),
                     "-C", args.project, "DUMP_{}".format(variable)]
    

    It looks like this error is due to the fact that NDK_PATH is a relative path, and ./build/core/build-local.mk is therefore interpreted by make as relative to the project directory given as the -C option.

  7. DanAlbert commented on Mar 10, 2016

    @DanAlbert
    Contributor

    Since the thing that caused this issue was the move from the package root into prebuilts/, does it all work if you undo those patches and just move the script up to the top level?

  8. jmgao commented on Mar 11, 2016

    @jmgao
    Contributor

    Fixed a couple of these bugs, here's are the current differences between master and the r11 release:

    diff --git a/ndk-gdb.py b/ndk-gdb.py
    index 59071be..c8cf560 100755
    --- a/ndk-gdb.py
    +++ b/ndk-gdb.py
    @@ -32,8 +32,8 @@ import xml.etree.cElementTree as ElementTree
     import logging
    
     # Shared functions across gdbclient.py and ndk-gdb.py.
    -# ndk-gdb is installed to $NDK/host-tools/bin
    -NDK_PATH = os.path.normpath(os.path.join(os.path.dirname(__file__), '../..'))
    +# ndk-gdb is installed to $NDK/prebuilt/<platform>/bin
    +NDK_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../..'))
     sys.path.append(os.path.join(NDK_PATH, "python-packages"))
     import gdbrunner
    
    @@ -116,7 +116,7 @@ class ArgumentParser(gdbrunner.ArgumentParser):
                 "--stdcxx-py-pr", dest="stdcxxpypr",
                 help="Use C++ library pretty-printer",
                 choices=["auto", "none", "gnustl", "stlport"],
    -            default="none")
    +            default="auto")
    
    
     def extract_package_name(xmlroot):
    @@ -182,11 +182,7 @@ def extract_launchable(xmlroot):
    
    
     def ndk_bin_path():
    -    path = os.path.join(NDK_PATH, "host-tools", "bin")
    -    if not os.path.exists(path):
    -        error("Failed to find ndk binary path, should be at '{}'".format(path))
    -
    -    return path
    +    return os.path.dirname(os.path.realpath(__file__))
    
    
     def handle_args():
    @@ -235,7 +231,7 @@ def find_project(args):
         manifest_name = "AndroidManifest.xml"
         if args.project is not None:
             log("Using project directory: {}".format(args.project))
    -        args.project = os.path.realpath(args.project)
    +        args.project = os.path.realpath(os.path.expanduser(args.project))
             if not os.path.exists(os.path.join(args.project, manifest_name)):
                 msg = "could not find AndroidManifest.xml in '{}'"
                 error(msg.format(args.project))
    @@ -421,7 +417,7 @@ def get_gdbserver_path(args, package_name, app_data_dir, arch):
    
         # We need to upload our gdbserver
         log("App gdbserver not found at {}, uploading.".format(app_gdbserver_path))
    -    local_path = "{}/gdbserver/{}/gdbserver"
    +    local_path = "{}/prebuilt/android-{}/gdbserver/gdbserver"
         local_path = local_path.format(NDK_PATH, arch)
         remote_path = "/data/local/tmp/{}-gdbserver".format(arch)
         args.device.push(local_path, remote_path)
    @@ -447,15 +443,15 @@ def get_gdbserver_path(args, package_name, app_data_dir, arch):
         return remote_path
    
    
    -def pull_binaries(device, out_dir, is64bit):
    +def pull_binaries(device, out_dir, app_64bit):
         required_files = []
         libraries = ["libc.so", "libm.so", "libdl.so"]
    
    -    if is64bit:
    +    if app_64bit:
             required_files = ["/system/bin/app_process64", "/system/bin/linker64"]
             library_path = "/system/lib64"
         else:
    -        required_files = ["/system/bin/app_process", "/system/bin/linker"]
    +        required_files = ["/system/bin/linker"]
             library_path = "/system/lib"
    
         for library in libraries:
    @@ -470,12 +466,21 @@ def pull_binaries(device, out_dir, is64bit):
             log("Pulling '{}' to '{}'".format(required_file, local_path))
             device.pull(required_file, local_path)
    
    +    # /system/bin/app_process is 32-bit on 32-bit devices, but a symlink to
    +    # app_process64 on 64-bit. If we need the 32-bit version, try to pull
    +    # app_process32, and if that fails, pull app_process.
    +    if not app_64bit:
    +        destination = os.path.realpath(out_dir + "/system/bin/app_process")
    +        try:
    +            device.pull("/system/bin/app_process32", destination)
    +        except:
    +            device.pull("/system/bin/app_process", destination)
    
    -def generate_gdb_script(args, sysroot, binary_path, is64bit, connect_timeout=5):
    +def generate_gdb_script(args, sysroot, binary_path, app_64bit, connect_timeout=5):
         gdb_commands = "file '{}'\n".format(binary_path)
    
         solib_search_path = [sysroot, "{}/system/bin".format(sysroot)]
    -    if is64bit:
    +    if app_64bit:
             solib_search_path.append("{}/system/lib64".format(sysroot))
         else:
             solib_search_path.append("{}/system/lib".format(sysroot))
    @@ -560,7 +565,7 @@ def find_pretty_printer(pretty_printer):
             path = os.path.join("stlport", "stlport")
             function = "register_stlport_printers"
         pp_path = os.path.join(
    -        NDK_PATH, "host-tools", "share", "pretty-printers", path)
    +        ndk_bin_path(), "..", "share", "pretty-printers", path)
         return pp_path, function
    
    
    @@ -636,9 +641,9 @@ def main():
         pid = pids[0]
    
         # Pull the linker, zygote, and notable system libraries
    -    is64bit = "64" in abi
    -    pull_binaries(device, out_dir, is64bit)
    -    if is64bit:
    +    app_64bit = "64" in abi
    +    pull_binaries(device, out_dir, app_64bit)
    +    if app_64bit:
             zygote_path = os.path.join(out_dir, "system", "bin", "app_process64")
         else:
             zygote_path = os.path.join(out_dir, "system", "bin", "app_process")
    @@ -660,6 +665,9 @@ def main():
             def start_jdb():
                 log("Starting jdb to unblock application.")
    
    +            # Give gdbserver some time to attach.
    +            time.sleep(0.5)
    +
                 # Do setup stuff to keep ^C in the parent from killing us.
                 signal.signal(signal.SIGINT, signal.SIG_IGN)
                 windows = sys.platform.startswith("win")
    @@ -686,7 +694,7 @@ def main():
    
    
         # Start gdb.
    -    gdb_commands = generate_gdb_script(args, out_dir, zygote_path, is64bit)
    +    gdb_commands = generate_gdb_script(args, out_dir, zygote_path, app_64bit)
         gdb_flags = []
         if args.tui:
             gdb_flags.append("--tui")
    
  9. mitchell-johnson commented on Mar 11, 2016

    @mitchell-johnson

    I was experiencing the same issues as @jfirebaugh and have been resolved with the patch above when applied to a fresh download of the ndk. (OS X 64bit)

  10. jmgao commented on Mar 14, 2016

    @jmgao
    Contributor

    Fixed in r11b.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions