[Top] [All Lists]

Re: single step in MIPS

To: Nida M <>
Subject: Re: single step in MIPS
From: Ralf Baechle <>
Date: Thu, 7 Sep 2006 05:54:24 +0200
Cc: "Kevin D. Kissell" <>,
In-reply-to: <>
Original-recipient: rfc822;
References: <> <000b01c6cea8$7d480fa0$a803a8c0@Ulysses> <>
User-agent: Mutt/
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
exception handler.

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
at it.


<Prev in Thread] Current Thread [Next in Thread>