Debug of program exit

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Debug of program exit

跳至解决方案
1,894 次查看
oaf
Contributor IV

In my world I don't use exit() at all, but sometimes a nasty error could happen inside a library func

which calls exit(). In the comp.c this function is implemented as this:

void _exit(int status)

{

// disable all interrupts, run infinite loop

    __asm("cpsid i");

    while(1);

}

What would be much nicer is if the sw could just enter the debugger. Do I have to patch the source, or is there a

non intrusive way of do this?

标记 (2)
1 解答
1,557 次查看
marek_neuzil
NXP Employee
NXP Employee

Hello,

I have checked the source code file and it is located in KSDK_1.1.0\rtos\mqx\mqx\source\psp\cortex_m\compiler\gcc_arm\comp.c, i.e. this program module is a part of MQX. It is a static source code file and you can modify it.

    

This issue is related to MQX software solution. I will move it.

Best Regards,

Marek Neuzil

在原帖中查看解决方案

0 项奖励
回复
6 回复数
1,558 次查看
marek_neuzil
NXP Employee
NXP Employee

Hello,

I have checked the source code file and it is located in KSDK_1.1.0\rtos\mqx\mqx\source\psp\cortex_m\compiler\gcc_arm\comp.c, i.e. this program module is a part of MQX. It is a static source code file and you can modify it.

    

This issue is related to MQX software solution. I will move it.

Best Regards,

Marek Neuzil

0 项奖励
回复
1,557 次查看
oaf
Contributor IV

Ok,

If I may wish a solution with a function-pointer, weak-link would be better, as you then doesn't have to change the library source.

BTW:what is the assembly instruction for breakpoint?

0 项奖励
回复
1,557 次查看
DavidS
NXP Employee
NXP Employee
   __asm("bkpt 4"); //DES example of using assembly code in "C" source to halt/break in the code.  A debugger can then step over and the resume execution.

Regards,

David

0 项奖励
回复
1,557 次查看
jvasil
Contributor III

In some example code, I've seen this coded with a '0' instead of a '4'.  ARM documentation says:

"The BKPT instruction 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.

In both ARM state and Thumb state, imm is ignored by the ARM hardware. However, a debugger can use it to store additional information about the breakpoint." [ARM Information Center]

So I'm curious if there is any particular reason for using '4'?

I'm also curious about what happens if a bkpt instruction is executed when there is no debugger connected.  I assume this acts similar to either a NOP or a HALT but haven't found a description of this yet.

Thanks,

James

0 项奖励
回复
1,557 次查看
DavidS
NXP Employee
NXP Employee

Hi James,

No particular reason for "4" other than it works.

My testing without debugger has behavior of a HALT.

Regards,

David

1,557 次查看
jvasil
Contributor III

Thanks.  Just FYI, '0' seems to work too.  Guess you COULD look at this value to take some action in the debugger.

Too bad about the behavior--guess that means can't leave bkpt instructions sprinkled in the code!!

0 项奖励
回复