Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
liujiuri
engine
提交
3b1b465a
E
engine
项目概览
liujiuri
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3b1b465a
编写于
2月 19, 2016
作者:
J
Jason Simmons
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2412 from jason-simmons/gdb_launch
Tool for running GDB on the Flutter engine
上级
60d07a7b
978a47e0
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
163 addition
and
0 deletion
+163
-0
sky/tools/flutter_gdb
sky/tools/flutter_gdb
+163
-0
未找到文件。
sky/tools/flutter_gdb
0 → 100755
浏览文件 @
3b1b465a
#!/usr/bin/env python
# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import
argparse
import
os
import
re
import
subprocess
import
sys
"""Tool for starting a GDB client and server to debug a Flutter engine process on an Android device.
Usage:
flutter_gdb server com.example.package_name
flutter_gdb client com.example.package_name
The Android package must be marked as debuggable in its manifest.
The "client" command will copy system libraries from the device to the host
in order to provide debug symbols. If this has already been done on a
previous run for a given device, then you can skip this step by passing
--no-pull-libs.
"""
ADB_LOCAL_PATH
=
'third_party/android_tools/sdk/platform-tools/adb'
def
_get_flutter_root
():
return
os
.
path
.
abspath
(
os
.
path
.
join
(
__file__
,
os
.
pardir
,
os
.
pardir
,
os
.
pardir
))
def
_find_package_pid
(
adb_path
,
package
):
"""Find the pid of the Flutter application process."""
ps_output
=
subprocess
.
check_output
([
adb_path
,
'shell'
,
'ps'
])
ps_match
=
re
.
search
(
'^\S+\s+(\d+).*\s%s'
%
package
,
ps_output
,
re
.
MULTILINE
)
if
not
ps_match
:
print
'Unable to find pid for package %s on device'
%
package
return
None
return
int
(
ps_match
.
group
(
1
))
class
GdbClient
(
object
):
GDB_LOCAL_PATH
=
(
'third_party/android_tools/ndk/toolchains/arm-linux-androideabi-4.9/'
'prebuilt/linux-x86_64/bin/arm-linux-androideabi-gdb'
)
SYSTEM_LIBS_PATH
=
'/tmp/flutter_gdb_device_libs'
def
add_subparser
(
self
,
subparsers
):
parser
=
subparsers
.
add_parser
(
'client'
,
help
=
'run a GDB client'
)
parser
.
add_argument
(
'package'
,
type
=
str
)
parser
.
add_argument
(
'--gdb-port'
,
type
=
int
,
default
=
8888
)
parser
.
add_argument
(
'--no-pull-libs'
,
action
=
"store_false"
,
default
=
True
,
dest
=
"pull_libs"
,
help
=
"Do not copy system libraries from the device to the host"
)
parser
.
set_defaults
(
func
=
self
.
run
)
def
_copy_system_libs
(
self
,
adb_path
,
package
):
"""Copy libraries used by the Flutter process from the device to the host."""
package_pid
=
_find_package_pid
(
adb_path
,
package
)
if
package_pid
is
None
:
return
False
# Find library files that are mapped into the process.
proc_maps
=
subprocess
.
check_output
(
[
adb_path
,
'shell'
,
'run-as'
,
package
,
'cat'
,
'/proc/%d/maps'
%
package_pid
])
proc_libs
=
re
.
findall
(
'(/system/.*\.so)\s*$'
,
proc_maps
,
re
.
MULTILINE
)
device_libs
=
set
(
proc_libs
)
device_libs
.
add
(
'/system/bin/linker'
)
if
not
os
.
path
.
exists
(
GdbClient
.
SYSTEM_LIBS_PATH
):
os
.
makedirs
(
GdbClient
.
SYSTEM_LIBS_PATH
)
dev_null
=
open
(
os
.
devnull
,
'w'
)
for
lib
in
sorted
(
device_libs
):
print
'Copying %s'
%
lib
local_path
=
os
.
path
.
join
(
GdbClient
.
SYSTEM_LIBS_PATH
,
os
.
path
.
basename
(
lib
))
subprocess
.
check_call
([
adb_path
,
'pull'
,
lib
,
local_path
],
stderr
=
dev_null
)
return
True
def
run
(
self
,
args
):
flutter_root
=
_get_flutter_root
()
adb_path
=
os
.
path
.
join
(
flutter_root
,
ADB_LOCAL_PATH
)
if
args
.
pull_libs
:
if
not
self
.
_copy_system_libs
(
adb_path
,
args
.
package
):
return
1
subprocess
.
check_call
(
[
adb_path
,
'forward'
,
'tcp:%d'
%
args
.
gdb_port
,
'tcp:%d'
%
args
.
gdb_port
])
eval_commands
=
[
'target remote localhost:%d'
%
args
.
gdb_port
]
debug_out_path
=
os
.
path
.
join
(
flutter_root
,
'out/android_Debug'
)
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
debug_out_path
,
'libsky_shell.so'
)):
print
'Unable to find libsky_shell.so. Make sure you have completed an android_Debug build'
return
1
eval_commands
.
append
(
'set solib-search-path %s:%s'
%
(
debug_out_path
,
GdbClient
.
SYSTEM_LIBS_PATH
))
exec_command
=
[
os
.
path
.
join
(
flutter_root
,
GdbClient
.
GDB_LOCAL_PATH
)]
for
command
in
eval_commands
:
exec_command
+=
[
'--eval-command'
,
command
]
os
.
execv
(
exec_command
[
0
],
exec_command
)
class
GdbServer
(
object
):
GDB_SERVER_LOCAL_PATH
=
'third_party/android_tools/ndk/prebuilt/android-arm/gdbserver/gdbserver'
GDB_SERVER_DEVICE_TMP_PATH
=
'/data/local/tmp/gdbserver'
def
add_subparser
(
self
,
subparsers
):
parser
=
subparsers
.
add_parser
(
'server'
,
help
=
'run a GDB server on the device'
)
parser
.
add_argument
(
'package'
,
type
=
str
)
parser
.
add_argument
(
'--gdb-port'
,
type
=
int
,
default
=
8888
)
parser
.
set_defaults
(
func
=
self
.
run
)
def
run
(
self
,
args
):
flutter_root
=
_get_flutter_root
()
adb_path
=
os
.
path
.
join
(
flutter_root
,
ADB_LOCAL_PATH
)
package_pid
=
_find_package_pid
(
adb_path
,
args
.
package
)
if
package_pid
is
None
:
return
1
# Copy gdbserver to the package's data directory.
subprocess
.
check_call
([
adb_path
,
'push'
,
os
.
path
.
join
(
flutter_root
,
GdbServer
.
GDB_SERVER_LOCAL_PATH
),
GdbServer
.
GDB_SERVER_DEVICE_TMP_PATH
])
gdb_server_device_path
=
'/data/data/%s/gdbserver'
%
args
.
package
subprocess
.
check_call
([
adb_path
,
'shell'
,
'run-as'
,
args
.
package
,
'cp'
,
GdbServer
.
GDB_SERVER_DEVICE_TMP_PATH
,
gdb_server_device_path
])
# Run gdbserver.
try
:
subprocess
.
call
([
adb_path
,
'shell'
,
'run-as'
,
args
.
package
,
gdb_server_device_path
,
'--attach'
,
':%d'
%
args
.
gdb_port
,
str
(
package_pid
)])
except
KeyboardInterrupt
:
pass
def
main
():
parser
=
argparse
.
ArgumentParser
(
description
=
'Flutter debugger tool'
)
subparsers
=
parser
.
add_subparsers
(
help
=
'sub-command help'
)
commands
=
[
GdbClient
(),
GdbServer
(),
]
for
command
in
commands
:
command
.
add_subparser
(
subparsers
)
args
=
parser
.
parse_args
()
return
args
.
func
(
args
)
if
__name__
==
'__main__'
:
sys
.
exit
(
main
())
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录