HTC Desire : run-as flaw? 上的 Android native 调试 (ndk-gdb)

标签 android debugging gdb native

我正尝试在我的 HTC Desire 上为我的 Android 项目执行 native 代码调试。 该项目由一层薄薄的 JNI 包装器和 C++ 中的主要 block 组成,使用 ndk-build 编译。设置了可调试标志,我在 HTC Desire 上运行 2.2,并且在我的 PC 上使用 Ubuntu。

所以一个普通的 ndk-gdb --start 返回一个:

ERROR: Could not setup network redirection to gdbserver?
   Maybe using --port=<port> to use a different TCP port might help?

这很奇怪。上网查了一下,发现是ndk-gdb的一个缺陷导致的错误消息错误。如果我运行 ndk-gdb -- start --verbose 我得到这个困惑的错误:

Android NDK installation path: /home/marco/dev/android-ndk
Using specific adb command: /home/marco/dev/android-sdk//platform-tools/adb
ADB version found: Android Debug Bridge version 1.0.26
Using final ADB command: '/home/marco/dev/android-sdk//platform-tools/adb'
Using auto-detected project path: .
Found package name: com.marco83.siege
ABIs targetted by application: armeabi
Device API Level: 8
Device CPU ABIs: armeabi-v7a armeabi
Compatible device ABI: armeabi
Found debuggable flag: true
Found device gdbserver: /data/data/com.marco83.siege/lib/gdbserver
Using gdb setup init: /home/marco/dev/siege_game/trunk/SiegeGameNative/libs/armeabi/gdb.setup
Using toolchain prefix: /home/marco/dev/android-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-
Using app out directory: /home/marco/dev/siege_game/trunk/SiegeGameNative/obj/local/armeabi
Found data directory: 'run-as: Package 'com.marco83.siege' has corrupt installation'
Found first launchable activity: .Main
Launching activity: com.marco83.siege/.Main
## COMMAND: /home/marco/dev/android-sdk//platform-tools/adb shell am start -n com.marco83.siege/.Main
Starting: Intent { cmp=com.marco83.siege/.Main }
Warning: Activity not started, its current task has been brought to the front
## COMMAND: /home/marco/dev/android-sdk//platform-tools/adb shell sleep 2
Found running PID: 844
Launched gdbserver succesfully.
Setup network redirection
## COMMAND: /home/marco/dev/android-sdk//platform-tools/adb forward tcp:5039 localfilesystem:run-as: Package 'com.marco83.siege' has corrupt installation/debug-socket
## COMMAND: /home/marco/dev/android-sdk//platform-tools/adb shell run-as com.marco83.siege lib/gdbserver +debug-socket --attach 844
Android Debug Bridge version 1.0.26

 -d                            - directs command to the only connected USB device
                                 returns an error if more than one USB device is present.
 -e                            - directs command to the only running emulator.
                                 returns an error if more than one emulator is running.
 -s <serial number>            - directs command to the USB device or emulator with
                                 the given serial number. Overrides ANDROID_SERIAL
                                 environment variable.
 -p <product name or path>     - simple product name like 'sooner', or
                                 a relative/absolute path to a product
                                 out directory like 'out/target/product/sooner'.
                                 If -p is not specified, the ANDROID_PRODUCT_OUT
                                 environment variable is used, which must
                                 be an absolute path.
 devices                       - list all connected devices
 connect <host>[:<port>]       - connect to a device via TCP/IP
                                 Port 5555 is used by default if no port number is specified.
 disconnect [<host>[:<port>]]  - disconnect from a TCP/IP device.
                                 Port 5555 is used by default if no port number is specified.
                                 Using this ocmmand with no additional arguments
                                 will disconnect from all connected TCP/IP devices.

device commands:
  adb push <local> <remote>    - copy file/dir to device
  adb pull <remote> [<local>]  - copy file/dir from device
  adb sync [ <directory> ]     - copy host->device only if changed
                                 (-l means list but don't copy)
                                 (see 'adb help all')
  adb shell                    - run remote shell interactively
  adb shell <command>          - run remote shell command
  adb emu <command>            - run emulator console command
  adb logcat [ <filter-spec> ] - View device log
  adb forward <local> <remote> - forward socket connections
                                 forward specs are one of: 
                                   tcp:<port>
                                   localabstract:<unix domain socket name>
                                   localreserved:<unix domain socket name>
                                   localfilesystem:<unix domain socket name>
                                   dev:<character device name>
                                   jdwp:<process pid> (remote only)
  adb jdwp                     - list PIDs of processes hosting a JDWP transport
  adb install [-l] [-r] [-s] <file> - push this package file to the device and install it
                                 ('-l' means forward-lock the app)
                                 ('-r' means reinstall the app, keeping its data)
                                 ('-s' means install on SD card instead of internal storage)
  adb uninstall [-k] <package> - remove this app package from the device
                                 ('-k' means keep the data and cache directories)
  adb bugreport                - return all information from the device
                                 that should be included in a bug report.

  adb help                     - show this help message
  adb version                  - show version num

DATAOPTS:
 (no option)                   - don't touch the data partition
  -w                           - wipe the data partition
  -d                           - flash the data partition

scripting:
  adb wait-for-device          - block until device is online
  adb start-server             - ensure that there is a server running
  adb kill-server              - kill the server if it is running
  adb get-state                - prints: offline | bootloader | device
  adb get-serialno             - prints: <serial-number>
  adb status-window            - continuously print device status for a specified device
  adb remount                  - remounts the /system partition on the device read-write
  adb reboot [bootloader|recovery] - reboots the device, optionally into the bootloader or recovery program
  adb reboot-bootloader        - reboots the device into the bootloader
  adb root                     - restarts the adbd daemon with root permissions
  adb usb                      - restarts the adbd daemon listening on USB
  adb tcpip <port>             - restarts the adbd daemon listening on TCP on the specified port
networking:
  adb ppp <tty> [parameters]   - Run PPP over USB.
 Note: you should not automatically start a PPP connection.
 <tty> refers to the tty for PPP stream. Eg. dev:/dev/omap_csmi_tty1
 [parameters] - Eg. defaultroute debug dump local notty usepeerdns

adb sync notes: adb sync [ <directory> ]
  <localdir> can be interpreted in several ways:

  - If <directory> is not specified, both /system and /data partitions will be updated.

  - If it is "system" or "data", only the corresponding partition
    is updated.

environmental variables:
  ADB_TRACE                    - Print debug information. A comma separated list of the following values
                                 1 or all, adb, sockets, packets, rwx, usb, sync, sysdeps, transport, jdwp
  ANDROID_SERIAL               - The serial number to connect to. -s takes priority over this if given.
  ANDROID_LOG_TAGS             - When used with the logcat option, only these debug tags are printed.
ERROR: Could not setup network redirection to gdbserver?
       Maybe using --port=<port> to use a different TCP port might help?
marco@pacer:~/dev/siege_game/trunk/SiegeGameNative$ run-as: Package 'com.marco83.siege' has corrupt installation

正如您在此处看到的和报告的那样:http://vilimpoc.org/blog/2010/09/23/hello-gdbserver-a-debuggable-jni-example-for-android/由不同的同时输出混合引起;真正的错误应该是

Package 'xxxxx' has corrupt installation

对此错误的进一步调查指出:http://osdir.com/ml/android-ndk/2010-08/msg00263.html

报告了相同的错误,他们说无法在 Desire 上进行 native 调试。问题是 run-as 无法访问/data 文件夹。

除了 root/刷机之外还有什么解决办法吗?为什么 run-as 访问/data? 我在考虑一个天真的解决方案,我将包(objs、libs 等)复制到一个更容易访问的位置(比如在 SD 卡上),然后告诉调试器访问该位置 - 这可行吗?

谢谢 马可

编辑:更新:我使用 unrevoked3 对手机进行了 root。即使我设置了 chmod 0777 data(这可能非常危险),我也会得到同样的错误。正如帖子中第二个链接所报告的,run-as 正在检查/data 是否可访问。如何访问运行源代码?是否可以重新编译它并上传一个修改后的版本来绕过这个检查? (因为我可以将/data 设置为任何人都可以读取)

最佳答案

我通过更改目录“/data/data”的访问权限和所有权解决了 HTC Desire S (2.3.3) 的这个问题:

修复前:

ls -l /data
 (...)
drwxrwxrwx root     root              2012-03-03 19:07 data

在根模式下:

chmod 771 /data/data
chown system.system /data/data

ls -l /data
 (...)
drwxrwx--x system   system            2012-03-03 19:07 data

/data 目录也可能需要更改。

chmod 771 /data
chown system.system /data

关于HTC Desire : run-as flaw? 上的 Android native 调试 (ndk-gdb),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4873124/

相关文章:

linux - 如何配置 gdb 加载符号?

安卓gradle : Error No resource found that matches the given name: attr when refer to an android lib

java - 为什么我无法在 'SettingActivity' 中获取个人资料图片?

wpf - 使用WinDbg分析WPF应用程序中OutOfMemoryException的根本原因

visual-studio-2010 - 如何在 VS2010 RC 中设置我的开发 Web 浏览器?

c++ - 如何在循环后立即打断点?

android - Android 中的两个进程如何使用相同的 SQLite 数据库?

Android 应用使用 Games.getGamesServerAuthCode 从 Oauth 2.0 客户端获取授权码

javascript - 跟踪输入中的更改[type=text]

核心转储分析 gdb : print return address and arguments