0

是否可以从 GCC 以编程方式闯入调试器?

例如,我想要这样的东西: #define STOP_EXECUTION_HERE ??? 当放在一些代码行上时会强制调试器停在那里。有可能吗?我找到了一些解决方案,但我无法使用它,因为在我的嵌入式 ARM 系统上我没有signal.h

(但是我可以使用内联汇编)。

4

3 回答 3

3

What you are trying to do is called software breakpoint

It is very hard to say precisely without knowing how you actually debug. I assume your embedded system runs gdbstub. There are various possibilities how this can be supported:

Use dedicated BKPT instruction

This could be a standard way on your system and debugger to support software breakpoints

Feed invalid instruction to CPU

gdbstub could have placed own UNDEF ARM mode handler placed. If you go this route you must be aware of current CPU mode (ARM or THUMB), because instruction size will be different. Examples of undefined instructions:

ARM: 0xE7F123F4
THUMB: 0xDE56

In runtime CPU mode could be found from the lowest bit of PC register. But the easier way is to know how you compiled object file, where you placed software breakpoint

Use SWI instruction

We did so when used RealView ICE. Most likely this does not apply to you, if you run some OS on your embedded system. SWI is usually used by OS to implement system calls

于 2012-08-07T10:05:37.870 回答
2

通常,最好的方法是通过设备工具链提供的库函数。

我无法对其进行测试,但一般的解决方案可能是插入 ARMBKPT指令。它需要一个直接的参数,你的调试器可能会解释它,可能会产生奇怪的结果。

于 2012-08-07T10:01:59.293 回答
0

您可以从 GDB 运行您的应用程序,并在代码调用中,例如abort. 这将在此时停止您的应用程序。我不确定在那之后是否可以继续。

于 2012-08-07T08:58:37.970 回答