實測值通過添加這對活動的成功:
private void startGdbServer() {
try {
new ProcessBuilder()
.command(getFilesDir().getParent() + "/lib/gdbserver", "tcp:5039", "--attach" ,"" + android.os.Process.myPid())
.redirectErrorStream(true)
.start();
} catch (IOException e) {
Log.e(TAG, "IOException failed to start gdbserver");
}
}
然後我包裹startGdbServer在Android服務和更新NDK-GDB腳本啓動服務器,而不是在運行方式命令。
這裏的清單另外:
<service android:enabled="true" android:name="com.apportable.activity.GdbServerService"
android:label="@string/app_name" android:icon="@drawable/icon">
<intent-filter >
<action android:name="apportable.FoundationTests.GdbServerService" />
</intent-filter>
</service>
下面是相關的NDK-gdb的變化(在python):
remote_gdbserver = '/data/data/' + env['APPLICATION_IDENTIFIER'] + '/lib/gdbserver'
print "Attaching to pid " + pid
# Android 4.2 requires the --user 0 option. Earlier versions cannot have it
results = env.Execute([env['ADB'], 'shell', 'am'])
if "--user" in results:
user_option = "--user 0"
else:
user_option = ""
adb.AsyncShell(env, 'am startservice ' + user_option + ' -a ' + env['APPLICATION_IDENTIFIER'] + '.GdbServerService --es gdbserver_name ' + remote_gdbserver + ' --ei gdbserver_port ' + str(env['ANDROID_REMOTE_DEBUG_PORT']))
# HACK: magic number. ensure the gdb server is actually up and running
time.sleep(2) # 1 is usually enough, but not always, like after reboot or with heavy system load
adb.Forward(env, env['ANDROID_LOCAL_DEBUG_PORT'], env['ANDROID_REMOTE_DEBUG_PORT'])
adb.Pull(env, process_path, '/system/bin/app_process')
setup_path = '"' + setup_path + '"'
if env['CGDB'] is not None:
cmd = [env['CGDB'], '-d', env['GDB'], '--', '-x', setup_path]
else:
cmd = [env['GDB'], '-x', setup_path]
env.RunCommand(cmd)
只是爲了完整性...該軟件包安裝在設備上? – CommonsWare
是的。我可以使用adb shell啓動應用程序,但我的開始是-n abc/{activity} –
http://developer.samsung.com/forum/thread/ndk-debugging-with-gdb/77/178834的線索,但不清楚如何更改non-rooted設備的ndk-gdb。 –