Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ndk-gdb.py fails #3

Closed
jfirebaugh opened this issue Mar 10, 2016 · 10 comments
Closed

ndk-gdb.py fails #3

jfirebaugh opened this issue Mar 10, 2016 · 10 comments
Assignees
Milestone

Comments

@jfirebaugh
Copy link

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).

@DanAlbert DanAlbert added this to the r11a milestone Mar 10, 2016
@jfirebaugh
Copy link
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.

@jmgao
Copy link
Contributor

jmgao commented Mar 10, 2016

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():

@jmgao
Copy link
Contributor

jmgao commented Mar 10, 2016

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


@jfirebaugh
Copy link
Author

👍 Thanks, getting further with those patches.

@jfirebaugh
Copy link
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.

@DanAlbert
Copy link
Member

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?

@jmgao
Copy link
Contributor

jmgao commented Mar 11, 2016

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")

@mitchell-johnson
Copy link

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)

@jmgao
Copy link
Contributor

jmgao commented Mar 14, 2016

Fixed in r11b.

@jmgao jmgao closed this as completed Mar 14, 2016
@DanAlbert
Copy link
Member

DanAlbert pushed a commit that referenced this issue Apr 16, 2016
These weren't updated for the directory reshuffling a while back.

Bug: #3
Change-Id: Ifea9be5d910a1ea2d974eb67f8a079f227d03218
(cherry picked from commit c9b170d)
DanAlbert pushed a commit that referenced this issue Apr 16, 2016
Bug: #3
Change-Id: If10d278c4d4fbf97735227c520e09ef0036741be
(cherry picked from commit bdd35c7)
DanAlbert pushed a commit that referenced this issue Apr 16, 2016
Bug: #3
Change-Id: I23ec52b8612fb4374ea192b93935329f59c36d16
(cherry picked from commit 4555ef3)
DanAlbert pushed a commit that referenced this issue Apr 16, 2016
These weren't updated for the directory reshuffling a while back.

Bug: #3
Change-Id: Ifea9be5d910a1ea2d974eb67f8a079f227d03218
DanAlbert pushed a commit that referenced this issue Apr 16, 2016
Bug: #3
Change-Id: If10d278c4d4fbf97735227c520e09ef0036741be
DanAlbert pushed a commit that referenced this issue Apr 16, 2016
Bug: #3
Change-Id: I23ec52b8612fb4374ea192b93935329f59c36d16
@PvR33 PvR33 mentioned this issue Sep 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants