0

Is it possible to programmatically break into debugger from GCC?

For example I want something like: #define STOP_EXECUTION_HERE ??? which when put on some code line will force debugger stop there. Is it possible at all ? I found some solution, but i can't use it because on my embedded ARM system I don't have signal.h.

(However I can use inline assembly).

3
  • dereference an invalid address Commented Aug 7, 2012 at 9:43
  • @Jim Balter I need to resume after breakpoint Commented Aug 7, 2012 at 10:18
  • There's no reason why you can't resume after an illegal reference unless your debugger is badly broken. Commented Aug 7, 2012 at 21:54

3 Answers 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

Sign up to request clarification or add additional context in comments.

Comments

2

Normally, the best way to do this is via a library function supplied with your device's toolchain.

I can't test it out, but a general solution might be to insert an ARM BKPT instruction. It takes an immediate argument, which your debugger might interpret, with potentially odd results.

Comments

0

You could run your application from GDB, and in the code call e.g. abort. This will stop your application at that point. I'm not sure if it's possible to continue after that though.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.