Saturday, May 28, 2011

Breakpoints behind the scenes


Breakpoints behind the scenes
Software breakpoints
As you may know usually while working on a program, you can set a breakpoint at a specific position in the code. Most of the times when developing for user space it would work and may help you tracing your variables and checking your memory state, so eventually you would find easily the bug. Those breakpoints are called “Software breakpoints”.

So how does software breakpoints works?
With software breakpoints, after setting the break points right at the beginning of running the debugger it first inserts line to your code in each place you have entered a breakpoint.
The line contents is an assembly instruction: INT 3 .

INT is an assembly instruction for x86 processors for generating a software interrupt.
The number is the interrupt type, which can be in range between 0 to 255 (byte value).
The INT 3 instruction is defined for use by debuggers to temporarily replace an instruction in a running program. Actually INT 3 causes an interrupt and calls an interrupt vector set up by the OS.
Alternatively you can invoke the BREAKPOINT macro, which translates to the appropriate architecture-dependent instruction.
So each time you use “software breakpoints” it actually modify the your code,

Which leads us to next question what would we do if we would like to debug a ROM code??

Hardware breakpoints
You may probably have heard about another kind of breakpoint which is called “Hardware breakpoints”, the breakpoint is generated by the Hardware.
Obviously when talking about debugging a ROM code, software breakpoints are now ruled out, it is recommend to use hardware breakpoints, they have no downside. You can simply step and breakpoint on code in ROM and RAM.
Usually on this subject the most well known is JTAG (Joint Test Action Group), which is a hardware-assisted debugging and is powerful, but expensive. You can even use JTAG for burning code onto on-board flash memory, which is pretty neat :-) .
Most evaluation boards on the market comes with a JTAG interface support, you should check before buying one.
Oh by the way a week ago I stumbled upon a video blog showing the kindle 3 inside components. You can see it’s JTAG interface on the following link:
Amazon Kindle 3 Teardown


My beagleboard-xM also supports JTAG, there is a JTAG port for debugging the TI’s ARM processor (the bb-xM JTAG port holds on the board 13 pins).

I haven’t used it yet, but looking forward to use in the future ;-).

It’s essential tool for debugging especially for early stages of the booting process which runs before anything is set up. The JTAG provides a transport mechanism for accessing and debugging the inside target of a CPU. This way you can enjoy debugging your embedded system at the machine instruction level when needed, or (more typically) in terms of high level language source code.
Using JTAG you can debug the processor by single-stepped, setting break points, halting, and accessing registers and data buses. Yah… it opens a whole new world for Debugging and hacking which is pretty thrilling for all the coders out there!

Our time is up for today,
I hope you have enjoyed, so I guess I'll see you on the next post!!

No comments:

Post a Comment

About