Forcing a breakpoint from application code

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Forcing a breakpoint from application code

1,016件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by DaveNadler on Sun Feb 02 10:11:39 MST 2014
Background: Experienced programmers know that using "assert" liberally to confirm things like values in expected ranges can save enormous amounts of time debugging, by catching logical errors early rather than waiting for something to blow up downstream of the error. Consequently, we want to force a break into the debugger on an assertion failure (by recoding the "assert" macro).

Will this do the trick?
__asm("BKPT #0\n")  ;  // Break into the debugger

If not, what's the recommended way to do this?

[u]The debugger should stop at this point, and provide full visibility into the local stack and call stack...[/u]

Thanks!
Best Regards, Dave

PS: Sorry I don't have a handy LPCxpresso module and project to try this on...
0 件の賞賛
返信
1 返信

949件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Mon Feb 03 02:00:00 MST 2014
If you link with Redlib (semihost) then you will basically get the assert behaviour you are looking for.

If you want to put your own BKPT instructions into your code, then the latest release of CMSIS (v3.20) provides a macro to do this…

/** \brief  Breakpoint

    This function causes the processor to enter Debug state.
    Debug tools can use this to investigate system state when the instruction at a particular address is reached.

    \param [in]    value  is ignored by the processor.
                   If required, a debugger can use it to store additional information about the breakpoint.
 */
#define __BKPT(value)                       __ASM volatile ("bkpt "#value)


Note that you do need to be careful with this sort of thing, because if you leave such instructions in code that is executed without debug tools attached, then if the BKPT is executed you will get an processor exception triggered.

Regards,
LPCXpresso Support
0 件の賞賛
返信