From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12263 invoked by alias); 9 Oct 2012 15:48:04 -0000 Received: (qmail 12255 invoked by uid 22791); 9 Oct 2012 15:48:04 -0000 X-SWARE-Spam-Status: No, hits=-4.0 required=5.0 tests=AWL,BAYES_00,KHOP_THREADED,RP_MATCHES_RCVD,TW_AV X-Spam-Check-By: sourceware.org Received: from sibelius.xs4all.nl (HELO glazunov.sibelius.xs4all.nl) (83.163.83.176) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 09 Oct 2012 15:47:58 +0000 Received: from glazunov.sibelius.xs4all.nl (kettenis@localhost [127.0.0.1]) by glazunov.sibelius.xs4all.nl (8.14.5/8.14.3) with ESMTP id q99FlsHn009674; Tue, 9 Oct 2012 17:47:54 +0200 (CEST) Received: (from kettenis@localhost) by glazunov.sibelius.xs4all.nl (8.14.5/8.14.3/Submit) id q99FlrrT005368; Tue, 9 Oct 2012 17:47:53 +0200 (CEST) Date: Tue, 09 Oct 2012 15:48:00 -0000 Message-Id: <201210091547.q99FlrrT005368@glazunov.sibelius.xs4all.nl> From: Mark Kettenis To: mark.kettenis@xs4all.nl CC: hjl.tools@gmail.com, gdb-patches@sourceware.org In-reply-to: <201210091539.q99Fdj3D027359@glazunov.sibelius.xs4all.nl> (message from Mark Kettenis on Tue, 9 Oct 2012 17:39:45 +0200 (CEST)) Subject: Re: PING: PATCH: PR backtrace/14646: [x32] backtrace doesn't work References: <20121003154712.GH3028@adacore.com> <201210040657.q946vJlc006566@glazunov.sibelius.xs4all.nl> <201210081948.q98Jm3D7020175@glazunov.sibelius.xs4all.nl> <201210082022.q98KM82d014759@glazunov.sibelius.xs4all.nl> <201210082047.q98KlQ6V031554@glazunov.sibelius.xs4all.nl> <20121008210142.GA14305@gmail.com> <20121009153217.GA6936@gmail.com> <201210091539.q99Fdj3D027359@glazunov.sibelius.xs4all.nl> Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-10/txt/msg00154.txt.bz2 > Date: Tue, 9 Oct 2012 17:39:45 +0200 (CEST) > From: Mark Kettenis > > > Date: Tue, 9 Oct 2012 08:32:17 -0700 > > From: "H.J. Lu" > > > > 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" > > > > > > > > > > On Mon, Oct 8, 2012 at 1:22 PM, Mark Kettenis wrote: > > > > > >> Date: Mon, 8 Oct 2012 13:04:03 -0700 > > > > > >> From: "H.J. Lu" > > > > > >> > > > > > >> On Mon, Oct 8, 2012 at 12:48 PM, Mark Kettenis wrote: > > > > > >> >> Date: Thu, 4 Oct 2012 06:57:22 -0700 > > > > > >> >> From: "H.J. Lu" > > > > > >> >> > > > > > >> >> On Wed, Oct 3, 2012 at 11:57 PM, Mark Kettenis 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 > > > > > >> 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: > > > > > >> ... > > > > > >> 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 @@ > > > > > > > > > > > > > > > > > > > > - > > > > > + > > > > > > > > > > > > > > > > > > > > @@ -44,7 +44,7 @@ > > > > > > > > > > > > > > > > > > > > - > > > > > + > > > > > > > > > > > > > > > > > > > > > Here is the patch I tried. It fixes PR backtrace/14646 and PR gdb/14647. > > > > > > > > > H.J. > > > --- > > > 2012-10-08 H.J. Lu > > > > > > 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. > > 2012-10-08 H.J. Lu > > > > 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. > > * regformats/i386/x32-avx-linux.dat: Likewise. > > * regformats/i386/x32-avx.dat: Likewise. > > * regformats/i386/x32-linux.dat: Likewise. > > * regformats/i386/x32.dat: Likewise. > > > > diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c > > index 8c5b6cc..9cee464 100644 > > --- a/gdb/amd64-tdep.c > > +++ b/gdb/amd64-tdep.c > > @@ -2943,9 +2943,6 @@ amd64_x32_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) > > tdesc = tdesc_x32; > > tdep->tdesc = tdesc; > > > > - tdep->sp_regnum_from_eax = AMD64_RSP_REGNUM; > > - tdep->pc_regnum_from_eax = AMD64_RIP_REGNUM; > > - > > tdep->num_dword_regs = 17; > > set_tdesc_pseudo_register_type (gdbarch, amd64_x32_pseudo_register_type); > > > > diff --git a/gdb/features/i386/x32-avx-linux.c b/gdb/features/i386/x32-avx-linux.c > > index 1f39610..6efcffb 100644 > > --- a/gdb/features/i386/x32-avx-linux.c > > +++ b/gdb/features/i386/x32-avx-linux.c > > @@ -45,7 +45,7 @@ initialize_tdesc_x32_avx_linux (void) > > tdesc_create_reg (feature, "rsi", 4, 1, NULL, 64, "int64"); > > tdesc_create_reg (feature, "rdi", 5, 1, NULL, 64, "int64"); > > tdesc_create_reg (feature, "rbp", 6, 1, NULL, 64, "int64"); > > - tdesc_create_reg (feature, "rsp", 7, 1, NULL, 64, "int64"); > > + tdesc_create_reg (feature, "rsp", 7, 1, NULL, 32, "data_ptr"); > > tdesc_create_reg (feature, "r8", 8, 1, NULL, 64, "int64"); > > tdesc_create_reg (feature, "r9", 9, 1, NULL, 64, "int64"); > > tdesc_create_reg (feature, "r10", 10, 1, NULL, 64, "int64"); > > @@ -54,7 +54,7 @@ initialize_tdesc_x32_avx_linux (void) > > tdesc_create_reg (feature, "r13", 13, 1, NULL, 64, "int64"); > > tdesc_create_reg (feature, "r14", 14, 1, NULL, 64, "int64"); > > tdesc_create_reg (feature, "r15", 15, 1, NULL, 64, "int64"); > > - tdesc_create_reg (feature, "rip", 16, 1, NULL, 64, "uint64"); > > + tdesc_create_reg (feature, "rip", 16, 1, NULL, 32, "code_ptr"); > > tdesc_create_reg (feature, "eflags", 17, 1, NULL, 32, "i386_eflags"); > > tdesc_create_reg (feature, "cs", 18, 1, NULL, 32, "int32"); > > tdesc_create_reg (feature, "ss", 19, 1, NULL, 32, "int32"); > > diff --git a/gdb/features/i386/x32-avx.c b/gdb/features/i386/x32-avx.c > > index fb7a12c..5b6d835 100644 > > --- a/gdb/features/i386/x32-avx.c > > +++ b/gdb/features/i386/x32-avx.c > > @@ -43,7 +43,7 @@ initialize_tdesc_x32_avx (void) > > tdesc_create_reg (feature, "rsi", 4, 1, NULL, 64, "int64"); > > tdesc_create_reg (feature, "rdi", 5, 1, NULL, 64, "int64"); > > tdesc_create_reg (feature, "rbp", 6, 1, NULL, 64, "int64"); > > - tdesc_create_reg (feature, "rsp", 7, 1, NULL, 64, "int64"); > > + tdesc_create_reg (feature, "rsp", 7, 1, NULL, 32, "data_ptr"); > > tdesc_create_reg (feature, "r8", 8, 1, NULL, 64, "int64"); > > tdesc_create_reg (feature, "r9", 9, 1, NULL, 64, "int64"); > > tdesc_create_reg (feature, "r10", 10, 1, NULL, 64, "int64"); > > @@ -52,7 +52,7 @@ initialize_tdesc_x32_avx (void) > > tdesc_create_reg (feature, "r13", 13, 1, NULL, 64, "int64"); > > tdesc_create_reg (feature, "r14", 14, 1, NULL, 64, "int64"); > > tdesc_create_reg (feature, "r15", 15, 1, NULL, 64, "int64"); > > - tdesc_create_reg (feature, "rip", 16, 1, NULL, 64, "uint64"); > > + tdesc_create_reg (feature, "rip", 16, 1, NULL, 32, "code_ptr"); > > tdesc_create_reg (feature, "eflags", 17, 1, NULL, 32, "i386_eflags"); > > tdesc_create_reg (feature, "cs", 18, 1, NULL, 32, "int32"); > > tdesc_create_reg (feature, "ss", 19, 1, NULL, 32, "int32"); > > diff --git a/gdb/features/i386/x32-core.xml b/gdb/features/i386/x32-core.xml > > index 1e41417..28db826 100644 > > --- a/gdb/features/i386/x32-core.xml > > +++ b/gdb/features/i386/x32-core.xml > > @@ -34,7 +34,7 @@ > > > > > > > > - > > + > > > > > > > > @@ -44,7 +44,7 @@ > > > > > > > > - > > + > > > > > > > > diff --git a/gdb/features/i386/x32-linux.c b/gdb/features/i386/x32-linux.c > > index 387436f..d06fcbf 100644 > > --- a/gdb/features/i386/x32-linux.c > > +++ b/gdb/features/i386/x32-linux.c > > @@ -45,7 +45,7 @@ initialize_tdesc_x32_linux (void) > > tdesc_create_reg (feature, "rsi", 4, 1, NULL, 64, "int64"); > > tdesc_create_reg (feature, "rdi", 5, 1, NULL, 64, "int64"); > > tdesc_create_reg (feature, "rbp", 6, 1, NULL, 64, "int64"); > > - tdesc_create_reg (feature, "rsp", 7, 1, NULL, 64, "int64"); > > + tdesc_create_reg (feature, "rsp", 7, 1, NULL, 32, "data_ptr"); > > tdesc_create_reg (feature, "r8", 8, 1, NULL, 64, "int64"); > > tdesc_create_reg (feature, "r9", 9, 1, NULL, 64, "int64"); > > tdesc_create_reg (feature, "r10", 10, 1, NULL, 64, "int64"); > > @@ -54,7 +54,7 @@ initialize_tdesc_x32_linux (void) > > tdesc_create_reg (feature, "r13", 13, 1, NULL, 64, "int64"); > > tdesc_create_reg (feature, "r14", 14, 1, NULL, 64, "int64"); > > tdesc_create_reg (feature, "r15", 15, 1, NULL, 64, "int64"); > > - tdesc_create_reg (feature, "rip", 16, 1, NULL, 64, "uint64"); > > + tdesc_create_reg (feature, "rip", 16, 1, NULL, 32, "code_ptr"); > > tdesc_create_reg (feature, "eflags", 17, 1, NULL, 32, "i386_eflags"); > > tdesc_create_reg (feature, "cs", 18, 1, NULL, 32, "int32"); > > tdesc_create_reg (feature, "ss", 19, 1, NULL, 32, "int32"); > > diff --git a/gdb/features/i386/x32.c b/gdb/features/i386/x32.c > > index 34e5087..679f767 100644 > > --- a/gdb/features/i386/x32.c > > +++ b/gdb/features/i386/x32.c > > @@ -43,7 +43,7 @@ initialize_tdesc_x32 (void) > > tdesc_create_reg (feature, "rsi", 4, 1, NULL, 64, "int64"); > > tdesc_create_reg (feature, "rdi", 5, 1, NULL, 64, "int64"); > > tdesc_create_reg (feature, "rbp", 6, 1, NULL, 64, "int64"); > > - tdesc_create_reg (feature, "rsp", 7, 1, NULL, 64, "int64"); > > + tdesc_create_reg (feature, "rsp", 7, 1, NULL, 32, "data_ptr"); > > tdesc_create_reg (feature, "r8", 8, 1, NULL, 64, "int64"); > > tdesc_create_reg (feature, "r9", 9, 1, NULL, 64, "int64"); > > tdesc_create_reg (feature, "r10", 10, 1, NULL, 64, "int64"); > > @@ -52,7 +52,7 @@ initialize_tdesc_x32 (void) > > tdesc_create_reg (feature, "r13", 13, 1, NULL, 64, "int64"); > > tdesc_create_reg (feature, "r14", 14, 1, NULL, 64, "int64"); > > tdesc_create_reg (feature, "r15", 15, 1, NULL, 64, "int64"); > > - tdesc_create_reg (feature, "rip", 16, 1, NULL, 64, "uint64"); > > + tdesc_create_reg (feature, "rip", 16, 1, NULL, 32, "code_ptr"); > > tdesc_create_reg (feature, "eflags", 17, 1, NULL, 32, "i386_eflags"); > > tdesc_create_reg (feature, "cs", 18, 1, NULL, 32, "int32"); > > tdesc_create_reg (feature, "ss", 19, 1, NULL, 32, "int32"); > > diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c > > index 84e9794..ddb20aa 100644 > > --- a/gdb/i386-tdep.c > > +++ b/gdb/i386-tdep.c > > @@ -7705,9 +7705,6 @@ i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) > > tdep->num_mmx_regs = 8; > > tdep->num_ymm_regs = 0; > > > > - tdep->sp_regnum_from_eax = -1; > > - tdep->pc_regnum_from_eax = -1; > > - > > tdesc_data = tdesc_data_alloc (); > > > > set_gdbarch_relocate_instruction (gdbarch, i386_relocate_instruction); > > @@ -7752,14 +7749,6 @@ i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) > > /* Support dword pseudo-register if it hasn't been disabled. */ > > tdep->eax_regnum = ymm0_regnum; > > ymm0_regnum += tdep->num_dword_regs; > > - if (tdep->sp_regnum_from_eax != -1) > > - set_gdbarch_sp_regnum (gdbarch, > > - (tdep->eax_regnum > > - + tdep->sp_regnum_from_eax)); > > - if (tdep->pc_regnum_from_eax != -1) > > - set_gdbarch_pc_regnum (gdbarch, > > - (tdep->eax_regnum > > - + tdep->pc_regnum_from_eax)); > > } > > else > > tdep->eax_regnum = -1; > > diff --git a/gdb/i386-tdep.h b/gdb/i386-tdep.h > > index 76afdce..5f233f5 100644 > > --- a/gdb/i386-tdep.h > > +++ b/gdb/i386-tdep.h > > @@ -149,14 +149,6 @@ struct gdbarch_tdep > > of pseudo dword register support. */ > > int eax_regnum; > > > > - /* Register number for SP, relative to %eax. Set this to -1 to > > - indicate the absence of pseudo SP register support. */ > > - int sp_regnum_from_eax; > > - > > - /* Register number for PC, relative to %eax. Set this to -1 to > > - indicate the absence of pseudo PC register support. */ > > - int pc_regnum_from_eax; > > - > > /* Number of core registers. */ > > int num_core_regs; > > > > diff --git a/gdb/regformats/i386/x32-avx-linux.dat b/gdb/regformats/i386/x32-avx-linux.dat > > index 1203806..f142265 100644 > > --- a/gdb/regformats/i386/x32-avx-linux.dat > > +++ b/gdb/regformats/i386/x32-avx-linux.dat > > @@ -9,7 +9,7 @@ expedite:rbp,rsp,rip > > 64:rsi > > 64:rdi > > 64:rbp > > -64:rsp > > +32:rsp > > 64:r8 > > 64:r9 > > 64:r10 > > @@ -18,7 +18,7 @@ expedite:rbp,rsp,rip > > 64:r13 > > 64:r14 > > 64:r15 > > -64:rip > > +32:rip > > 32:eflags > > 32:cs > > 32:ss > > diff --git a/gdb/regformats/i386/x32-avx.dat b/gdb/regformats/i386/x32-avx.dat > > index f13bf28..62e9d4a 100644 > > --- a/gdb/regformats/i386/x32-avx.dat > > +++ b/gdb/regformats/i386/x32-avx.dat > > @@ -9,7 +9,7 @@ expedite:rbp,rsp,rip > > 64:rsi > > 64:rdi > > 64:rbp > > -64:rsp > > +32:rsp > > 64:r8 > > 64:r9 > > 64:r10 > > @@ -18,7 +18,7 @@ expedite:rbp,rsp,rip > > 64:r13 > > 64:r14 > > 64:r15 > > -64:rip > > +32:rip > > 32:eflags > > 32:cs > > 32:ss > > diff --git a/gdb/regformats/i386/x32-linux.dat b/gdb/regformats/i386/x32-linux.dat > > index 6eda64a..8cb27e1 100644 > > --- a/gdb/regformats/i386/x32-linux.dat > > +++ b/gdb/regformats/i386/x32-linux.dat > > @@ -9,7 +9,7 @@ expedite:rbp,rsp,rip > > 64:rsi > > 64:rdi > > 64:rbp > > -64:rsp > > +32:rsp > > 64:r8 > > 64:r9 > > 64:r10 > > @@ -18,7 +18,7 @@ expedite:rbp,rsp,rip > > 64:r13 > > 64:r14 > > 64:r15 > > -64:rip > > +32:rip > > 32:eflags > > 32:cs > > 32:ss > > diff --git a/gdb/regformats/i386/x32.dat b/gdb/regformats/i386/x32.dat > > index 6c63a8a..4bee34e 100644 > > --- a/gdb/regformats/i386/x32.dat > > +++ b/gdb/regformats/i386/x32.dat > > @@ -9,7 +9,7 @@ expedite:rbp,rsp,rip > > 64:rsi > > 64:rdi > > 64:rbp > > -64:rsp > > +32:rsp > > 64:r8 > > 64:r9 > > 64:r10 > > @@ -18,7 +18,7 @@ expedite:rbp,rsp,rip > > 64:r13 > > 64:r14 > > 64:r15 > > -64:rip > > +32:rip > > 32:eflags > > 32:cs > > 32:ss > > >