public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH]Call frame debug info for 2.6 kernel
  2004-03-17 21:37 Fixes for .cfi directives for x86_64 kgdb Jim Houston
@ 2004-03-23  0:17 ` George Anzinger
  0 siblings, 0 replies; 5+ messages in thread
From: George Anzinger @ 2004-03-23  0:17 UTC (permalink / raw)
  To: jim.houston; +Cc: Andi Kleen, Andrew Morton, amitkale, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1160 bytes --]

This patch adds call frame debug record generation for entry.S frames.  If used 
with KGDB and gdb 6.0 it allows correct "back trace" (bt) through interrupt, 
system call and trap frames.  Frames that point to user space are tied off, 
those that point to the kernel unwind to the kernel.  It also ties off the 
initial frame in head.S and the idle process stacks for cpus other than cpu0 
(which actually goes back to head.S).  The patch adds one (1) instruction to the 
executable kernel (a few lines to the debug space, however).

The patch requires a gdb that handles CFI expressions, although it takes pains 
to work around a bug in gdb 6.0's expression analizer (the work around is also 
compatable with a correctly working expression analizer as can be found in the 
CVS version of gdb).  AFAIK gdb 6.0 is the first gdb to handle CFI expressions 
so you must use it to make this patch useful.

Use of earlier gdb's with this patch will not be affected (either for good or bad).
-- 
George Anzinger   george@mvista.com
High-res-timers:  http://sourceforge.net/projects/high-res-timers/
Preemption patch: http://www.kernel.org/pub/linux/kernel/people/rml

[-- Attachment #2: kgdb-dwarf-2.6.4-1.0.patch.gz --]
[-- Type: application/x-gzip, Size: 11356 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH]Call frame debug info for 2.6 kernel
       [not found] ` <1CHY0-1Uw-9@gated-at.bofh.it>
@ 2004-03-23  2:04   ` Andi Kleen
  2004-03-23 21:45     ` George Anzinger
  0 siblings, 1 reply; 5+ messages in thread
From: Andi Kleen @ 2004-03-23  2:04 UTC (permalink / raw)
  To: George Anzinger; +Cc: linux-kernel

George Anzinger <george@mvista.com> writes:

> This patch adds call frame debug record generation for entry.S frames.

[...]

Sorry, but that's quite ugly and will be hard to maintain (kinda like
maintaining an own assembler on your own) I think it would be far
better to require recent binutils for DEBUG_INFO builds and use the
.cfi_* mnemonics. They make dwarf2 code *much* simpler and cleaner.

Overall I think it's a good idea to add full dwarf2 annotation to
the i386 kernel, but not without assembler please.

-Andi


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH]Call frame debug info for 2.6 kernel
  2004-03-23  2:04   ` [PATCH]Call frame debug info for 2.6 kernel Andi Kleen
@ 2004-03-23 21:45     ` George Anzinger
  2004-03-24  6:25       ` Andi Kleen
  0 siblings, 1 reply; 5+ messages in thread
From: George Anzinger @ 2004-03-23 21:45 UTC (permalink / raw)
  To: Andi Kleen; +Cc: linux-kernel

Andi Kleen wrote:
> George Anzinger <george@mvista.com> writes:
> 
> 
>>This patch adds call frame debug record generation for entry.S frames.
> 
> 
> [...]
> 
> Sorry, but that's quite ugly and will be hard to maintain (kinda like
> maintaining an own assembler on your own) I think it would be far
> better to require recent binutils for DEBUG_INFO builds and use the
> .cfi_* mnemonics. They make dwarf2 code *much* simpler and cleaner.
> 
> Overall I think it's a good idea to add full dwarf2 annotation to
> the i386 kernel, but not without assembler please.

Hi Andi,

I just knew you would say that :).

I think I have said before that the current .cfi support in the assembler is not 
up to the job.  In fact gdb 6.0 also has a nasty bug that this code works 
around.  The main issue is the ability to use the dwarf2 cfi expression to build 
a call frame that determines if the interrupt/ trap frame returns to user space 
or to the kernel.  I think (I confess I have not tried) this may be doable with 
the .cfi escape op code, but I suspect the result would be just as ugly as this 
patch is.  You would have to roll your own .uleb128 and .sleb128 numbers, for 
example.   Also, you would need to be able to define labels in the dwarf code 
(or intuit how var the assembler is going to put your target and use that offset).

The long and short of it is, to do it at all, you need to have a fair knowledge 
of dwarf2.  Once you get to that, I suspect one way is as good as another.

At this point, the code works with kgdb, which, itself is not in the kernel.  I 
welcome any one who wants to help do it correctly.

-- 
George Anzinger   george@mvista.com
High-res-timers:  http://sourceforge.net/projects/high-res-timers/
Preemption patch: http://www.kernel.org/pub/linux/kernel/people/rml


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH]Call frame debug info for 2.6 kernel
  2004-03-23 21:45     ` George Anzinger
@ 2004-03-24  6:25       ` Andi Kleen
  2004-03-24 16:20         ` George Anzinger
  0 siblings, 1 reply; 5+ messages in thread
From: Andi Kleen @ 2004-03-24  6:25 UTC (permalink / raw)
  To: George Anzinger; +Cc: Andi Kleen, linux-kernel

> The long and short of it is, to do it at all, you need to have a fair 
> knowledge of dwarf2.  Once you get to that, I suspect one way is as good as 
> another.

Did you contact the gdb and binutils maintainers about the problems?
Maybe it can be easily fixed.

-Andi

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH]Call frame debug info for 2.6 kernel
  2004-03-24  6:25       ` Andi Kleen
@ 2004-03-24 16:20         ` George Anzinger
  0 siblings, 0 replies; 5+ messages in thread
From: George Anzinger @ 2004-03-24 16:20 UTC (permalink / raw)
  To: Andi Kleen; +Cc: linux-kernel, Daniel Jacobowitz

Andi Kleen wrote:
>>The long and short of it is, to do it at all, you need to have a fair 
>>knowledge of dwarf2.  Once you get to that, I suspect one way is as good as 
>>another.
> 
> 
> Did you contact the gdb and binutils maintainers about the problems?
> Maybe it can be easily fixed.
> 
I mentioned it to Daniel Jacobowitz.

The problem is what is needed is access to the full dwarf2 expression code. 
Actually only a small sub set is needed here, but I suspect they would only do 
the whole thing, and it is rather rich.  I only implemented about 20% of the 
opcodes.

For example, the way gdb knows that "this is the bottom of the stack" is for the 
CFI address to come back as zero.  Normally this is a stack address.  An 
expression is needed to get zero, and, at least in interrupt / trap handling, 
the expression needs to be conditional.  So, either a new language is invented 
or access is provided to the dwarf2 language, or an abstracted version of it.

The ladder is what I did.  I provided the dwarf2 opcodes with macros that 
wrapped the required boiler plate around them.  I set it up the way C does, i.e. 
as a separate block of asm code, rather than intermixed with the assembly thing 
(which would require relocs to the debug space and back as well as additional 
boiler plate).  This is artifact of how I figured out how to translate the 
dwarf2 spec to real code, i.e. I looked at what C was doing.

The thing is, we are talking assembly code here.  That means that just about 
anything is possible WRT the call frame.

If I had any sway over what the binutils folks do, I would argue for allowing 
dwarf2 code intermixed with inline asm in the C asm() code.  At the moment this 
is very hard (impossible) to do.

An example of what I would like to be able to do is to build a call frame for 
the out of line part of the spin lock.  It would be a very simple frame that 
would just say it was called from the inline part of the spin lock.

As second example is to properly describe the "switch frame" used for context 
switching.  Currently x86 requires frame pointers to cover this, i.e. with frame 
pointers off, gdb can not unwind tasks that are not active, even with dwarf2 
frame stuff.

-- 
George Anzinger   george@mvista.com
High-res-timers:  http://sourceforge.net/projects/high-res-timers/
Preemption patch: http://www.kernel.org/pub/linux/kernel/people/rml


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-03-24 16:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1AR5s-75I-27@gated-at.bofh.it>
     [not found] ` <1CHY0-1Uw-9@gated-at.bofh.it>
2004-03-23  2:04   ` [PATCH]Call frame debug info for 2.6 kernel Andi Kleen
2004-03-23 21:45     ` George Anzinger
2004-03-24  6:25       ` Andi Kleen
2004-03-24 16:20         ` George Anzinger
2004-03-17 21:37 Fixes for .cfi directives for x86_64 kgdb Jim Houston
2004-03-23  0:17 ` [PATCH]Call frame debug info for 2.6 kernel George Anzinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox