Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Mark Kettenis <mark.kettenis@xs4all.nl>
Cc: gdb-patches@sourceware.org
Subject: Re: PING: PATCH: PR backtrace/14646: [x32] backtrace doesn't work
Date: Tue, 09 Oct 2012 16:35:00 -0000	[thread overview]
Message-ID: <CAMe9rOpEqZNjvMR7cm6mBWd1mu_BFjs88mZ3NX15_Ch7bwcHzA@mail.gmail.com> (raw)
In-Reply-To: <201210091547.q99FlrrT005368@glazunov.sibelius.xs4all.nl>

On Tue, Oct 9, 2012 at 8:47 AM, Mark Kettenis <mark.kettenis@xs4all.nl> wrote:
>> Date: Tue, 9 Oct 2012 17:39:45 +0200 (CEST)
>> From: Mark Kettenis <mark.kettenis@xs4all.nl>
>>
>> > Date: Tue, 9 Oct 2012 08:32:17 -0700
>> > From: "H.J. Lu" <hjl.tools@gmail.com>
>> >
>> > On Mon, Oct 08, 2012 at 02:01:42PM -0700, H.J. Lu wrote:
>> > > On Mon, Oct 08, 2012 at 10:47:26PM +0200, Mark Kettenis wrote:
>> > > > > Date: Mon, 8 Oct 2012 13:38:21 -0700
>> > > > > From: "H.J. Lu" <hjl.tools@gmail.com>
>> > > > >
>> > > > > On Mon, Oct 8, 2012 at 1:22 PM, Mark Kettenis <mark.kettenis@xs4all.nl> wrote:
>> > > > > >> Date: Mon, 8 Oct 2012 13:04:03 -0700
>> > > > > >> From: "H.J. Lu" <hjl.tools@gmail.com>
>> > > > > >>
>> > > > > >> On Mon, Oct 8, 2012 at 12:48 PM, Mark Kettenis <mark.kettenis@xs4all.nl> wrote:
>> > > > > >> >> Date: Thu, 4 Oct 2012 06:57:22 -0700
>> > > > > >> >> From: "H.J. Lu" <hjl.tools@gmail.com>
>> > > > > >> >>
>> > > > > >> >> On Wed, Oct 3, 2012 at 11:57 PM, Mark Kettenis <mark.kettenis@xs4all.nl> wrote:
>> > > > > >> >> >
>> > > > > >> >> > Perhaps the user-regs.c mechanism can be used to establish eip -> pc
>> > > > > >> >> > and esp -> sp mappings?
>> > > > > >> >>
>> > > > > >> >> It doesn't help as long as gdbarch_pc_regnum/gdbarch_sp_regnum
>> > > > > >> >> are used for both frame pc/sp value and unwind pc/sp value.  For x32,
>> > > > > >> >> we want eip/esp for frame pc/sp value and rip/rsp for unwind pc/sp
>> > > > > >> >> value.
>> > > > > >> >
>> > > > > >> > That probably means we need to set gdbarch_pc_regnum (and
>> > > > > >> > gdbarch_sp_regnum) to -1 for x32.
>> > > > > >>
>> > > > > >> We can't set gdbarch_pc_regnum/gdbarch_sp_regnum to -1:
>> > > > > >>
>> > > > > >>
>> > > > > >> GNU gdb (GDB) 7.5.50.20121008-cvs
>> > > > > >> Copyright (C) 2012 Free Software Foundation, Inc.
>> > > > > >> License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
>> > > > > >> This is free software: you are free to change and redistribute it.
>> > > > > >> There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
>> > > > > >> and "show warranty" for details.
>> > > > > >> This GDB was configured as "x86_64-unknown-linux-gnu".
>> > > > > >> For bug reporting instructions, please see:
>> > > > > >> <http://www.gnu.org/software/gdb/bugs/>...
>> > > > > >> Reading symbols from
>> > > > > >> /export/build/gnu/glibc-x32/build-x86_64-linux/elf/sln...done.
>> > > > > >> (gdb) b main
>> > > > > >> Breakpoint 1 at 0x400c20: file sln.c, line 50.
>> > > > > >> (gdb) r
>> > > > > >> Starting program: /export/build/gnu/glibc-x32/build-x86_64-linux/elf/sln
>> > > > > >> /export/gnu/import/git/gdb/gdb/regcache.c:1062: internal-error:
>> > > > > >> regcache_read_pc: Unable to find PC
>> > > > > >> A problem internal to GDB has been detected,
>> > > > > >> further debugging may prove unreliable.
>> > > > > >> Quit this debugging session? (y or n)
>> > > > > >
>> > > > > > Well, obviously you'll need to implement gdbarch_read_pc() for this to
>> > > > > > work.  And probably a few more gdbarch methods.
>> > > > >
>> > > > > What do we gain by setting gdbarch_pc_regnum/gdbarch_sp_regnum
>> > > > > to -1?  PC and SP are RIP and RSP for x32.  We need them for
>> > > > > stack unwind.  The only unusual part is they are 64-bit although
>> > > > > x32 is a 32-bit environment.   How about this change?
>> > > >
>> > > > Did you even try that change?
>> > > >
>> > > > > diff --git a/gdb/features/i386/x32-core.xml b/gdb/features/i386/x32-core.xml
>> > > > > index 1e41417..392ce24 100644
>> > > > > --- a/gdb/features/i386/x32-core.xml
>> > > > > +++ b/gdb/features/i386/x32-core.xml
>> > > > > @@ -34,7 +34,7 @@
>> > > > >    <reg name="rsi" bitsize="64" type="int64"/>
>> > > > >    <reg name="rdi" bitsize="64" type="int64"/>
>> > > > >    <reg name="rbp" bitsize="64" type="int64"/>
>> > > > > -  <reg name="rsp" bitsize="64" type="int64"/>
>> > > > > +  <reg name="rsp" bitsize="64" type="data_ptr"/>
>> > > > >    <reg name="r8" bitsize="64" type="int64"/>
>> > > > >    <reg name="r9" bitsize="64" type="int64"/>
>> > > > >    <reg name="r10" bitsize="64" type="int64"/>
>> > > > > @@ -44,7 +44,7 @@
>> > > > >    <reg name="r14" bitsize="64" type="int64"/>
>> > > > >    <reg name="r15" bitsize="64" type="int64"/>
>> > > > >
>> > > > > -  <reg name="rip" bitsize="64" type="uint64"/>
>> > > > > +  <reg name="rip" bitsize="64" type="code_ptr"/>
>> > > > >    <reg name="eflags" bitsize="32" type="i386_eflags"/>
>> > > > >    <reg name="cs" bitsize="32" type="int32"/>
>> > > > >    <reg name="ss" bitsize="32" type="int32"/>
>> > >
>> > > Here is the patch I tried. It fixes PR backtrace/14646 and PR gdb/14647.
>> > >
>> > >
>> > > H.J.
>> > > ---
>> > > 2012-10-08  H.J. Lu  <hongjiu.lu@intel.com>
>> > >
>> > >   PR backtrace/14646
>> > >   PR gdb/14647
>> > >   * amd64-tdep.c (amd64_x32_init_abi): Don't set sp_regnum_from_eax
>> > >   nor pc_regnum_from_eax.
>> > >   * i386-tdep.c (i386_gdbarch_init): Don't use sp_regnum_from_eax
>> > >   nor pc_regnum_from_eax.
>> > >   * i386-tdep.h (gdbarch_tdep): Remove sp_regnum_from_eax and
>> > >   pc_regnum_from_eax.
>> > >   * features/i386/x32-core.xml: Use data_ptr on rsp and use
>> > >   code_ptr on rip.
>> > >   * features/i386/x32-avx-linux.c: Regenerated.
>> > >   * features/i386/x32-avx.c: Likewise.
>> > >   * features/i386/x32-linux.c: Likewise.
>> > >   * features/i386/x32.c: Likewise.
>> > >
>> >
>> > X32 needs to set RSP/RIP to 32-bit.  Othewise, it won't work with gdbserver
>> > since gdbserver will send 64-bit RSP/RIP while gdb sets size of RSP/RIP
>> > to pointer size, which is 32-bit for x32.  It works for x32 since the
>> > upper 32bits of RSP/RIP are always zero for x32.  OK for trunk and 7.5
>> > branch.
>>
>> At least you figured out that your previous diff didn't work all by
>> yourself.  How about actually testing your diffs *before* you mail
>> them out?
>
> Oh, and even if this diff accidentally happens to work, it is a really
> bad idea.  You won't be able to diagnose problems caused by one of the
> upper 32 bits getting set in %rsp or %rip.
>

I will see if I can break RSP/RIP into ESP/EIP and HSP/HIP, similar
to YMM, for x32.

-- 
H.J.


  reply	other threads:[~2012-10-09 16:35 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-03 15:26 H.J. Lu
2012-10-03 15:43 ` Mark Kettenis
2012-10-03 15:59   ` H.J. Lu
2012-10-03 17:03     ` H.J. Lu
2012-10-05  2:08       ` H.J. Lu
     [not found] ` <20121003154712.GH3028@adacore.com>
     [not found]   ` <CAMe9rOreX6NAf08vD8=k4LBGevvTFUd-tqwwWmbsA3iRxxsE2A@mail.gmail.com>
     [not found]     ` <201210040657.q946vJlc006566@glazunov.sibelius.xs4all.nl>
     [not found]       ` <CAMe9rOounZ9e14QeMLvXR64gG5rJxQ9nNxt64YoLW54bx5VtHw@mail.gmail.com>
2012-10-08 19:48         ` Mark Kettenis
2012-10-08 20:04           ` H.J. Lu
2012-10-08 20:22             ` Mark Kettenis
2012-10-08 20:38               ` H.J. Lu
2012-10-08 20:47                 ` Mark Kettenis
2012-10-08 21:01                   ` H.J. Lu
2012-10-09 15:32                     ` H.J. Lu
2012-10-09 15:40                       ` Mark Kettenis
2012-10-09 15:48                         ` Mark Kettenis
2012-10-09 16:35                           ` H.J. Lu [this message]
2012-10-09 16:38                             ` H.J. Lu
2012-10-15 10:10                               ` Mark Kettenis
2012-10-15 20:41                                 ` H.J. Lu
2012-10-11 22:34                           ` H.J. Lu
2012-10-12  8:31                             ` Mark Kettenis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMe9rOpEqZNjvMR7cm6mBWd1mu_BFjs88mZ3NX15_Ch7bwcHzA@mail.gmail.com \
    --to=hjl.tools@gmail.com \
    --cc=gdb-patches@sourceware.org \
    --cc=mark.kettenis@xs4all.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox