linux-mips
[Top] [All Lists]

Re: single step in MIPS

To: Nida M <nidajm@gmail.com>
Subject: Re: single step in MIPS
From: Ralf Baechle <ralf@linux-mips.org>
Date: Thu, 7 Sep 2006 05:54:24 +0200
Cc: "Kevin D. Kissell" <KevinK@mips.com>, linux-mips@linux-mips.org
In-reply-to: <b01966ec0609032157s35d8c0bdx900956f214c5337b@mail.gmail.com>
Original-recipient: rfc822;linux-mips@linux-mips.org
References: <b01966ec0609020445m693b53cfj87d31a4957627f1a@mail.gmail.com> <000b01c6cea8$7d480fa0$a803a8c0@Ulysses> <b01966ec0609032157s35d8c0bdx900956f214c5337b@mail.gmail.com>
Sender: linux-mips-bounce@linux-mips.org
User-agent: Mutt/1.4.2.1i
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.

  Ralf

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