Expect
當這個“期望”腳本啟動時,為什麼 gdb 客戶端無法與其 gdb 伺服器通信?
我正在為韌體程式碼庫建構一個持續集成環境,使用 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.
問題可能是gdb伺服器輸出被阻塞了,因為沒有人讀取它,所以gdb客戶端也被阻塞了。您可以
expect
閱讀並忽略 gdb 的其餘輸出expect_background eof exit
這使得最後生成的命令繼續其輸出,直到讀取文件結尾。