On Mon, Sep 04, 2006 at 10:27:12AM +0530, Nida M wrote:
> Well this is ok ..but I am trying to implement kenel debugger..
> something like system tap.
> And I have started with kprobe..
> where the kernel code execution will be stopped at user specified
> address using break, how do i single step that instruction to decode
> the instruction and print the registers value..?
Insert a breakpoint instruction after the instruction you want to single
step. Anything that triggers an exception but typicall a "break 0" would
be used for debuggers. Branches need special care. Either they need to
be executed in software or breakpoints at both the branch-taken and the
not-taken address need to be inserted.
Just to make this more entertaining, the kernel is a multithreaed piece
of software, even if you only have a single processor and you do not
necessarily want the singlestepping break point to be taken by each
thread / process, so you want to implement some filtering in the
Executing the instruction that has been replaced with a breakpoint takes
an interesting hack as well. Copy that instruction to the stackframe,
perform the necessary cacheflushes so the CPU will actually fetch the
right instruction. Then jump to that instruction. Obviously that needs
to be followed by a jump to the logical next instruction.
And with all those hints I leave the special case of instructions in
branch delay slots to the you, I'm sure you'll find it trivial ;-)
The FPU emulator in the kernel implements this btw. Not for single
stepping but for entirely different reasons but you may want to look