我正在为固件代码库构建持续集成环境,使用 Segger JLink 设备对 ARM Cortex M0 进行编程,并使用 gdb 和 Segger 的 RTT 工具在目标上运行测试。
我需要从“期望”开始三个过程:
- gdb 服务器。这侦听来自...的连接
- gdb 客户端。
- Segger 的 RTT 客户端将目标的输出记录到主机终端,这样我就可以看到测试的进展情况。
我对每一个目标都有“制定”目标。当我以人类身份运行测试时,我会为每个测试打开一个终端选项卡。在终端中一一运行,都运行良好。但是,当通过以下“expect”脚本运行时,gdb 客户端将停止在它应该向 gdb 服务器发送内容的位置。为什么?
#!/usr/bin/expect
# Bike Tracker firmware/hardware test. For syntax, see "man expect".
# gdb server
spawn /Applications/SEGGER/JLink/JLinkGDBServer -device nrf51822 -if swd -speed 4000 -port 2331
expect {
-ex "Waiting for GDB connection..."
}
sleep 1
send_user "\nexpect: gdb server running OK\n"
# gdb client
spawn ~/dev/gcc-arm-none-eabi-4_9-2015q1/bin/arm-none-eabi-gdb -x ./_build/.gdbinit ./_build/biketracker_app_s130.elf
sleep 2
set timeout 10
expect {
-ex "(gdb)" {
send "cont"
send "cont"
}
-ex "Operation timed out" {
send_user "expect: Timed out on gdb client. Did the server start OK?\n"
exit 1
}
timeout {
send_user "\nexpect: Timed out on gdb client output.\n"
exit 1
}
}
send_user "\nexpect: gdb client running OK\n"
# Segger RTT client
spawn /Applications/SEGGER/JLink/JLinkRTTClient -device nrf51822 -if swd -speed 4000
# If we do an RX operation on the modem, that takes 6s for the TX and about 30s for the RX.
set timeout 40
expect {
-ex "END_OF_TEST" { exit 0 }
eof { exit 0 }
-ex "ASSERT" {
send_user "\nexpect: A test failed. See RTT output for details.\n"
exit 1
}
timeout {
send_user "\nexpect: Timed out on RTT output.\n"
exit 1
}
}
终端输出:
expect test.expect
spawn /Applications/SEGGER/JLink/JLinkGDBServer -device nrf51822 -if swd -speed 4000 -port 2331
SEGGER J-Link GDB Server V5.12f Command Line Version
JLinkARM.dll V5.12f (DLL compiled May 17 2016 16:04:43)
-----GDB Server start settings-----
GDBInit file: none
GDB Server Listening port: 2331
SWO raw output listening port: 2332
Terminal I/O port: 2333
Accept remote connection: yes
Generate logfile: off
Verify download: off
Init regs on start: off
Silent mode: off
Single run mode: off
Target connection timeout: 0 ms
------J-Link related settings------
J-Link Host interface: USB
J-Link script: none
J-Link settings file: none
------Target related settings------
Target device: nrf51822
Target interface: SWD
Target interface speed: 4000kHz
Target endian: little
Connecting to J-Link...
J-Link is connected.
Firmware: J-Link ARM V8 compiled Nov 28 2014 13:44:46
Hardware: V8.00
S/N: 268006243
OEM: SEGGER-EDU
Feature(s): FlashBP, GDB
Checking target voltage...
Target voltage: 3.04 V
Listening on TCP/IP port 2331
Connecting to target...Connected to target
Waiting for GDB connection...
expect: gdb server running OK
spawn ~/dev/gcc-arm-none-eabi-4_9-2015q1/bin/arm-none-eabi-gdb -x ./_build/.gdbinit ./_build/biketracker_app_s130.elf
GNU gdb (GNU Tools for ARM Embedded Processors) 7.8.0.20150304-cvs
Copyright (C) 2014 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 "--host=x86_64-apple-darwin10 --target=arm-none-eabi".
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"...
Reading symbols from ./_build/biketracker_app_s130.elf...done.
0x0002ecf2 in rx_done_event (bytes=1 '\001', p_data=0x20002cec <rx_buffer> ",") at /Users/Eliot/dev/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/uart/nrf_drv_uart.c:631
631 m_cb.handler(&event,m_cb.p_context);
Loading section .text, size 0x1fbec lma 0x1b000
expect: Timed out on gdb client output.
答案1
问题可能是 gdb 服务器输出被阻止,因为没有人读取它,因此 gdb 客户端也被阻止。您可以expect
使用以下命令读取并忽略 gdb 的其余输出
expect_background eof exit
这使得最后生成的命令继续其输出,直到读取到文件结尾。