首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >断点上的OpenOCD出口

断点上的OpenOCD出口
EN

Stack Overflow用户
提问于 2019-09-05 14:40:54
回答 1查看 677关注 0票数 2

我正在STM32F042上开发一个应用程序。我从makefile驱动一切,包括我的单元测试。我使用OpenOCD和ST链接来闪现目标。我的单元测试在主机和目标上运行。主机单元测试驱动程序在成功时从main()返回0,在失败时返回非零,因此makefile知道测试是否通过。makefile在目标上闪烁并启动测试,但不知道它们是成功还是失败。嵌入式测试应用程序打开一个红色LED显示失败,绿色打开通过,所以我知道-现在我想自动化这一步。

我想在代码中设置两个断点,一个在失败处理程序中,一个在main末尾,并告诉OpenOCD,如果它碰到一个或另一个断点,就以零或非零状态退出。

因此,我的问题归结为两个具体的问题:

  1. 要设置断点,我需要知道特定代码行中的PC值。我如何从手臂-gcc工具链中得到这个值?
  2. 是否可以将OpenOCD配置为在特定断点上以特定状态退出?
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-09-27 15:04:25

我的结局是这样的。对于每个目标单元测试,我启动一个OpenOCD服务器并与gdb连接。Gdb运行一个脚本,它设置两个断点,一个用于成功,一个用于失败。如果它碰到任何一个断点,就会关闭OCD服务器,并使用与shell通信成功和失败的代码退出。要在主机上运行相同的测试,我只需将它们编译为常规可执行文件。

Makefile:

代码语言:javascript
复制
# target unit test binaries
foo_tests.elf bar_tests.elf baz_tests.elf bop_tests.elf: unit_test_runner.ao

# disable optimization for target unit test driver to avoid optimizing
# away functions that serve as breakpoint labels
unit_test_runner.ao: CFLAGS += -O0 -g

# link target unit test binaries for semihosting
%_tests.elf: ARM_LDLIBS += -specs=rdimon.specs -lrdimon

# host unit test binaries
foo_tests bar_time_tests baz_tests bop_tests: unit_test_runner.o

# run target unit test binaries through gdb and OpenOCD; redirecting stderr
# leaves printf output from `assert()' clearly visible on the console
%.tut: %.elf
    openocd -f interface/stlink-v2-1.cfg -f target/stm32f0x.cfg 2> $@.log &
    gdb-multiarc -batch-silent -x tut.gdb $< 2> $@-gdb.log

# run host binary
%.run: %
    ./$*

tests: foo_tests.run bar_time_tests.run baz_tests.run bop_tests.run \
       foo_tests.tut bar_time_tests.tut baz_tests.tut bop_tests.tut

tut.gdb:

代码语言:javascript
复制
target remote localhost:3333

monitor arm semihosting enable   # let assert()'s printf() through
monitor reset halt
load
monitor reset init

break success                    # set breakpoint on function `sucess()'
commands                         # on hitting this bp, execute the following:
monitor shutdown                 # shutdown OpenOCD server
quit 0                           # exit GDB with success code
end

break failure                    # set breakpoint on function `sucess()'
commands
monitor shutdown
quit 1                           # exit GDB with failure code
end

continue

unit_test_runner.c:

代码语言:javascript
复制
#include <stdlib.h>

/* These two functions serve as labels where gdb can place
   breakpoints. */
void success() {}
void failure() {}

/* Implementation detail for `assert()' macro */
void assertion_failure(const char *file,
                       int line,
                       const char *function,
                       const char *expression)
{
  printf("assertion failure in %s:%d (%s): `%s'\n",
         file, line, function, expression);
  failure();
  exit(1);
}

/* This function is necessary for ARM semihosting */
extern void initialise_monitor_handles(void);

int main(int argc, char* argv[])
{
#ifdef __arm__
  initialise_monitor_handles();
#endif

  tests();  /* client code implements this function */

  success();
  return 0;
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57807905

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档