RPI:Gdbserver for Brillo m10 system on Raspberry Pi Zero W

由于Raspberry Pi Zero W上使用的芯片是Broadcom公司的BCM2835, 这个处理器是arm11的架构,而AOSP(brillo-m10-release分支)中预编译的gdbserver需要跑在armv7架构上,所以需要对gdbserver的代码进行重新编译。

$ arm-linux-androideabi-readelf -A prebuilts/misc/android-arm/gdbserver/gdbserver 
Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "ARM v7"
  Tag_CPU_arch: v7
  Tag_CPU_arch_profile: Application
  Tag_ARM_ISA_use: Yes
  Tag_THUMB_ISA_use: Thumb-2
  Tag_FP_arch: VFPv3-D16
  Tag_ABI_PCS_GOT_use: GOT-indirect
  Tag_ABI_PCS_wchar_t: 4
  Tag_ABI_FP_denormal: Needed
  Tag_ABI_FP_exceptions: Needed
  Tag_ABI_FP_number_model: IEEE 754
  Tag_ABI_align_needed: 8-byte
  Tag_ABI_enum_size: int
  Tag_ABI_HardFP_use: SP and DP
  Tag_ABI_optimization_goals: Aggressive Speed
  Tag_CPU_unaligned_access: v6
  Tag_Virtualization_use: TrustZone

 

在prebuilts/misc/android-arm/gdbserver下面有一个README.txt, 通过上面的指导方法,可以很方便地也下载到所需要源代码,将gdbserver重新编译出来:

The Android platform gdb is built as part of the NDK build, from sources at https://android.googlesource.com/toolchain/gdb/.

To build it, follow the steps at https://android.googlesource.com/platform/ndk/+/master/README.md, and run `python checkbuild.py –module gdbserver`.

The current prebuilt version is built from the sources described by the manifest xml file in this directory.

使用Android.mk编译脚本的代码可以从这里下载:

https://github.com/brobwind/rpi0w-brillo-m10-gdbserver

 

在项目中调试的时候,需要将prebuilts/misc/android-arm/gdbserver下面的gdbserver替换掉我们编译出来的版本,不然在使用tools/bdk/debugging/gdbclient.py做在线调试的时候,会将prebuilts/misc/android-arm/gdbserver下的gdbserver推送到设备中,使得在线调试失败:

$ tools/bdk/debugging/gdbclient.py -p 150
Redirecting gdbclient output to /tmp/gdbclient-2012
WARNING:root:couldn't find /mnt/rpi-zero-w/brillo-m10-release/development/scripts/gdb/dalvik.gdb - ART debugging options will not be available

GNU gdb (GDB) 7.10
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
Error: unable to connect to device.
Remote communication error.  Target disconnected.: Connection reset by peer.
(gdb) quit

 

同时由于推送过去的gdbserver没有执行的权限,需要加上执行权限才可正常调试:

def start_gdbserver(device, gdbserver_local_path, gdbserver_remote_path,
                    target_pid, run_cmd, debug_socket, port, user=None):
    """Start gdbserver in the background and forward necessary ports.

    Args:
        device: ADB device to start gdbserver on.
        gdbserver_local_path: Host path to push gdbserver from, can be None.
        gdbserver_remote_path: Device path to push gdbserver to.
        target_pid: PID of device process to attach to.
        run_cmd: Command to run on the device.
        debug_socket: Device path to place gdbserver unix domain socket.
        port: Host port to forward the debug_socket to.
        user: Device user to run gdbserver as.
    
    Returns:
        Popen handle to the `adb shell` process gdbserver was started with.
    """ 
        
    assert target_pid is None or run_cmd is None
    
    # Push gdbserver to the target.
    if gdbserver_local_path is not None:
        device.push(gdbserver_local_path, gdbserver_remote_path)
        device.shell_nocheck(['chmod', '+x', gdbserver_remote_path])

    # Run gdbserver.
    gdbserver_cmd = [gdbserver_remote_path, "--once",
                     "+{}".format(debug_socket)]
        
    if target_pid is not None:
        gdbserver_cmd += ["--attach", str(target_pid)]
    else:   
        gdbserver_cmd += run_cmd

    device.forward("tcp:{}".format(port),
                   "localfilesystem:{}".format(debug_socket))
    atexit.register(lambda: device.forward_remove("tcp:{}".format(port)))
    gdbserver_cmd = get_run_as_cmd(user, gdbserver_cmd)
    
    # Use ppid so that the file path stays the same.
    gdbclient_output_path = os.path.join(tempfile.gettempdir(),
                                         "gdbclient-{}".format(os.getppid()))
    print "Redirecting gdbclient output to {}".format(gdbclient_output_path)
    gdbclient_output = file(gdbclient_output_path, 'w')
    return device.shell_popen(gdbserver_cmd, stdout=gdbclient_output,
                              stderr=gdbclient_output)

或者在本地将gdbserver设为可执行:

$ chmod +x prebuilts/misc/android-arm/gdbserver/gdbserver
  • 相关的参考文档

1。 https://github.com/raspberrypi/documentation/blob/master/hardware/raspberrypi/bcm2835/README.md

发表评论

电子邮件地址不会被公开。 必填项已用*标注