26

我正在为 STM32 嵌入式系统调试这个软件。在其中一个函数中,我的程序不断遇到某种断点:

SIGTRAP,跟踪/断点陷阱

但是,在 GDB 中,当我这样做时,info breakpoints我得到No breakpoints or watchpoints. 断点实际上对应于我很久以前在另一个版本的可执行文件中设置的断点。当我设置断点时,GDB 告诉我automatically using a hardware breakpoint on read-only memory(或类似的消息)。

我认为硬件断点仍然在我的芯片上,尽管已经加载了新版本的软件。如果确实存在虚假断点,我该如何定位和删除它?

4

5 回答 5

22

Ok. Long answer: Hardware breakpoints are usually set by writing to some special CPU registers. This is done by gdb. If gdb dies, it can left those installed in CPU. I guess your implementation (of gdb) does not either clear or examine those, when it connects to your target. To locate them, you would need to list the contents of hardware breakpoints registers on your CPU (don't know how to do this on STM32). Workaround would be (informed guess) be this: set few HW breakpoints (typically there are only a few, seldom more than 8) using gdb, then remove all of them. This should overwrite and then clean those hw registers. Once you do set those breakpoints (before removing them), do "continue" (just in case, as gdb sets breakpoints only at that time).

于 2012-03-23T15:10:50.757 回答
4

以下帮助了我:

# Ones I hit the SIGTRAP:
(gdb) f 0  # Show the current stack frame of the current thread.
#0  0x4003ed70 in pthread_create@@GLIBC_2.4 () from /opt/CodeSourcery/arm-2011.09/arm-none-linux-gnueabi/libc/lib/libpthread.so.0

# The fragment of interest is the current address: 0x4003ed70.
# Set the hardware assisted breakpoint at the current address:
(gdb) hbreak *0x4003ed70

# Continue execution (without hitting SIGTRAP):
(gdb) c
# Continuing.
于 2017-06-22T19:06:23.040 回答
3

SIGTRAP 应该是正在运行的断点指令。

通过检查您的指令指针来调试它,它很可能指向包含 BKPT 指令的地址(您必须查找实际代码是什么)。

从那里你必须根据堆栈和指令指针向后工作,看看你是否在你期望的位置。导致这种情况的原因可能有很多,从 GDB 插入无法清除的断点指令到内存损坏。

于 2012-03-29T15:29:15.870 回答
1

您正在运行的代码可能包含

int $0x03 ; talking about x86, don't know STM32 mnemo

它调用 SIGTRAP。

于 2012-03-28T14:57:07.333 回答
1

如果添加和删除硬件断点没有帮助,请检查中断向量。

在 Cortex-M 微控制器上,所有处理程序条目都应该有一个奇数地址(ARM Cortex-M FAQ)。如果没有,则触发 INVSTATE 类型的 UsageFault 并停止 MCU。GDB 将此解释为 SIGABRT。

如果其中一个条目具有偶数地址,则检查处理函数是否具有.thumb_func.type指令(NXP Avoid hardfaultHardFault 和 .thumb_func)。

HardFault_Handler 的示例:

.thumb_func
.type HardFault_Handler, %function
HardFault_Handler:
  TST LR, #4
  ITE EQ
  MRSEQ R0, MSP
  MRSNE R0, PSP
  B hard_fault_handler_c
于 2017-10-19T07:53:41.493 回答