Debug of program exit

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Debug of program exit

Jump to solution
1,650 Views
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?

Tags (2)
1 Solution
1,313 Views
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

View solution in original post

0 Kudos
Reply
6 Replies
1,314 Views
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 Kudos
Reply
1,313 Views
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 Kudos
Reply
1,313 Views
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 Kudos
Reply
1,313 Views
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 Kudos
Reply
1,313 Views
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,313 Views
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 Kudos
Reply