简体   繁体   English

Eclipse/GDB:硬件复位后如何设置自动断点?

[英]Eclipse/GDB: How to set an automatic breakpoint after hardware reset?

I am using a self-built embedded IDE with Eclipse and GDB - pretty much what this website describes: https://gnu-mcu-eclipse.github.io/我正在使用带有 Eclipse 和 GDB 的自建嵌入式 IDE - 几乎本网站描述的内容: https : //gnu-mcu-eclipse.github.io/

When I use OpenOCD or any other Debug Config (like SEGGER JLink) to flash my STM32F407 hardware, it breaks at the first line of my main.c.当我使用 OpenOCD 或任何其他调试配置(如 SEGGER JLink)来刷新我的 STM32F407 硬件时,它在我的 main.c 的第一行中断。 Nothing unusual.没什么不寻常的。

// ----- main() ---------------------------------------------------------------
int main(void)
{

    //Initialization, if unsuccessful -> quit
    if (!INIT_bInit())
        return 0;

    //infinite Loop
    while (0x1337)
    {
        //Nothing
    }

    //Must not end here
    return 0;
}

//main() 

This might be due to the behaviour setup in the Eclipse OpenOCD debug console.这可能是由于 Eclipse OpenOCD 调试控制台中的行为设置所致。

However, I'd like to have an automatic breakpoint mecahnism as well which halts the program in case there is a但是,我也希望有一个自动断点机制,它会在出现问题时停止程序

  • hard fault or a硬故障或
  • hardware reset硬件复位

As my software generally bases on automatic tasks with void function pointers, I'd like to know when there is a hardfault occurring due to a problem with the function to be called,由于我的软件通常基于带有 void 函数指针的自动任务,我想知道何时由于要调用的函数出现问题而发生硬故障,

But as of now, the only time I notice a HardFault is when I pause my program after a while and check if it ends up in my (custom) Default_FaultHandler (which implements the HardFault_Handler and others).但到目前为止,我唯一注意到 HardFault 的时间是我在一段时间后暂停我的程序并检查它是否以我的(自定义)Default_FaultHandler(它实现了 HardFault_Handler 和其他)结束。

void Default_FaultHandler(void)
{
  while(0xDEAD){} 
}

Same thing with hardware reset.硬件复位也是一样。 No indication, not even an automated (re-)break at main.c.没有迹象,甚至没有在 main.c 上自动(重新)中断。

I know from eclipse-based IDEs like NXP's MCUXpresso or Atollic Studio that it is possible to automatically break the program when any fault handler or a hardware reset is called.我从 NXP 的 MCUXpresso 或 Atollic Studio 等基于 Eclipse 的 IDE 中了解到,当调用任何故障处理程序或硬件重置时,可以自动中断程序。

Any ideas on how to automate the debugging behaviour with my own-built OpenOCD/Eclipse solution?关于如何使用我自己构建的 OpenOCD/Eclipse 解决方案自动化调试行为的任何想法?

Your help is warmly welcome热烈欢迎您的帮助

Cheers干杯

-Henni -亨尼

To analyze your hardfaults you can write a more sophisticated handler, cf https://www.freertos.org/Debugging-Hard-Faults-On-Cortex-M-Microcontrollers.html :要分析您的硬故障,您可以编写一个更复杂的处理程序,参见https://www.freertos.org/Debugging-Hard-Faults-On-Cortex-M-Microcontrollers.html

The implementation of prvGetRegistersFromStack() is shown below. prvGetRegistersFromStack()的实现如下所示。 prvGetRegistersFromStack() copies the register values from the stack into the C variables, then sits in a loop. prvGetRegistersFromStack()将寄存器值从堆栈复制到 C 变量中,然后进入循环。 The variables are named to indicate the register value that they hold.命名变量以指示它们保存的寄存器值。 Other registers will not have changed since the fault occurred, and can be viewed directly in the debugger's CPU register window.其他寄存器自故障发生后不会发生变化,可以直接在调试器的 CPU 寄存器窗口中查看。

Also cf How do I debug unexpected resets in a STM32 device?另请参阅如何调试 STM32 设备中的意外复位?

You can not detect hardware resets because they erase entire memory.您无法检测到硬件重置,因为它们会擦除整个内存。 When booting up again you can find what caused the hardware reset, this is in STM32 how to get last reset status .再次启动时,您可以找到导致硬件复位的原因,这是在STM32中如何获得上次复位状态 Possibly store the result on some permanent memory that is not erased during next hardware reset可能将结果存储在一些永久存储器上,在下次硬件复位期间不会被擦除

If you want to place breakpoint in the suspiciuus function or handler just use如果你想在 suspiciuus 函数或处理程序中放置断点,只需使用

__BKPT();

or if you do not use ARM CMSIS just或者如果您不使用 ARM CMSIS

#define __BKPT(value)                       __ASM volatile ("bkpt "#value)

Example:例子:

void Default_FaultHandler(void)
{
  __BKPT();
  while();
}

When this intrinsic is hit, your debugger will take the controll :)当这个内在函数被击中时,您的调试器将控制:)

I figured out that I haven't offically resolved my problem due to NYE holidays :)我发现由于 NYE 假期我还没有正式解决我的问题 :)

Thanks to ralf htp I was able to solve my initial problem of pre-loaded breakpoints resulting from GDB console options.感谢ralf htp,我能够解决由 GDB 控制台选项导致的预加载断点的初始问题。

To sum the whole thing up: The last link posted solves the OpenOCD version.总结整个事情:发布的最后一个链接解决了 OpenOCD 版本。 https://electronics.stackexchange.com/questions/28593/hardware-breakpoints-on-the-stm32 https://electronics.stackexchange.com/questions/28593/hardware-breakpoints-on-the-stm32

For SEGGER j-link it is对于 SEGGER j-link,它是

break main
break Default_FaultHandler

Both can be added for GDB in Eclipse Debug Configuration (in Startup tab) as follows两者都可以在 Eclipse 调试配置(在启动选项卡中)中为 GDB 添加,如下所示

GDB 启动设置

Works like a charm...奇迹般有效...

Thanks!谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM