From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26181 invoked by alias); 10 Jul 2003 10:05:25 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 26165 invoked from network); 10 Jul 2003 10:05:23 -0000 Received: from unknown (HELO maxipes.logix.cz) (81.0.234.97) by sources.redhat.com with SMTP; 10 Jul 2003 10:05:23 -0000 Received: from suse.cz (styx.suse.cz [213.210.157.162]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "Thawte Freemail Member", Issuer "Personal Freemail RSA 2000.8.30" (not verified)) by maxipes.logix.cz (Postfix) with ESMTP id 9BB192AA3A; Thu, 10 Jul 2003 12:04:48 +0200 (CEST) Message-ID: <3F0D3A5F.60102@suse.cz> Date: Thu, 10 Jul 2003 10:05:00 -0000 From: Michal Ludvig Organization: SuSE CR, s.r.o. User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5a) Gecko/20030610 X-Accept-Language: cs, cz, en MIME-Version: 1.0 To: Mark Kettenis Cc: gdb-patches@sources.redhat.com Subject: Re: [RFA] Re: Analyzing AMD64 corefiles on i386 References: <3F0ABC85.1080700@suse.cz> <200307081445.h68EjBWJ000503@elgar.kettenis.dyndns.org> <3F0BF66A.3080203@suse.cz> <200307091338.h69Dc8u7023807@elgar.kettenis.dyndns.org> In-Reply-To: <200307091338.h69Dc8u7023807@elgar.kettenis.dyndns.org> Content-Type: multipart/mixed; boundary="------------030204000104010203080806" X-SW-Source: 2003-07/txt/msg00211.txt.bz2 This is a multi-part message in MIME format. --------------030204000104010203080806 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Content-length: 878 Mark Kettenis told me that: > > From: Michal Ludvig > > what must be done to enable reading of AMD64 corefiles in a gdb running > > on i386 with --target=amd64? > > > Not as such. We can't allow public functions with the names > supply_gregset and fill_gregset in *-tdep.c files. Therefore these > functions should be renamed, and supply_gregset and fill_gregset > should be kept in your *-nat.c file. You'll probably want to rewrite > those functions such that they call the new functions in *-tdep.c. OK, I renamed them to x86_64_linux_(supply,fill)_gregset. Where should I put the prototypes? I created a new file x86-64-linux-tdep.h but you may prefer to put them to x86-64-tdep.h or directly to x86-64-linux-nat.c. Comments? Michal Ludvig -- * SuSE CR, s.r.o * mludvig@suse.cz * (+420) 296.545.373 * http://www.suse.cz --------------030204000104010203080806 Content-Type: text/plain; name="crosscore-3.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="crosscore-3.diff" Content-length: 9280 2003-07-10 Michal Ludvig * x86-64-linux-nat.c (regmap): Removed. (supply_gregset, fill_gregset): Call x86_64_linux_(fill,supply)_gregset functions. * x86-64-linux-tdep.c (USER_*): New defines. (user_to_gdb_regmap, x86_64_core_fns): New structure. (x86_64_linux_supply_gregset, x86_64_linux_fill_gregset): New functions. (fetch_core_registers): Ditto. (_initialize_x86_64_linux_tdep): Call add_core_fns(). * x86-64-linux-tdep.h: New file. * config/i386/x86-64linux.mh (NATDEPFILES): Remove corelow.o and core-regset.o. * config/i386/x86-64linux.mt (TDEPFILES): Add corelow.o. Index: x86-64-linux-nat.c =================================================================== RCS file: /cvs/src/src/gdb/x86-64-linux-nat.c,v retrieving revision 1.23 diff -u -p -r1.23 x86-64-linux-nat.c --- x86-64-linux-nat.c 31 May 2003 18:00:04 -0000 1.23 +++ x86-64-linux-nat.c 10 Jul 2003 09:52:33 -0000 @@ -38,24 +38,7 @@ #include "gregset.h" #include "x86-64-tdep.h" - -/* The register sets used in GNU/Linux ELF core-dumps are identical to - the register sets used by `ptrace'. The corresponding types are - `elf_gregset_t' for the general-purpose registers (with - `elf_greg_t' the type of a single GP register) and `elf_fpregset_t' - for the floating-point registers. */ - -/* Mapping between the general-purpose registers in `struct user' - format and GDB's register array layout. */ -static int regmap[] = -{ - RAX, RBX, RCX, RDX, - RSI, RDI, RBP, RSP, - R8, R9, R10, R11, - R12, R13, R14, R15, - RIP, EFLAGS, CS, SS, - DS, ES, FS, GS -}; +#include "x86-64-linux-tdep.h" /* Which ptrace request retrieves which registers? These apply to the corresponding SET requests as well. */ @@ -76,11 +59,7 @@ static int regmap[] = void supply_gregset (elf_gregset_t *gregsetp) { - elf_greg_t *regp = (elf_greg_t *) gregsetp; - int i; - - for (i = 0; i < X86_64_NUM_GREGS; i++) - supply_register (i, regp + regmap[i]); + x86_64_linux_supply_gregset ((char *) gregsetp); } /* Fill register REGNO (if it is a general-purpose register) in @@ -90,12 +69,7 @@ supply_gregset (elf_gregset_t *gregsetp) void fill_gregset (elf_gregset_t *gregsetp, int regno) { - elf_greg_t *regp = (elf_greg_t *) gregsetp; - int i; - - for (i = 0; i < X86_64_NUM_GREGS; i++) - if (regno == -1 || regno == i) - regcache_collect (i, regp + regmap[i]); + x86_64_linux_fill_gregset ((char *) gregsetp, regno); } /* Fetch all general-purpose registers from process/thread TID and Index: x86-64-linux-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/x86-64-linux-tdep.c,v retrieving revision 1.19 diff -u -p -r1.19 x86-64-linux-tdep.c --- x86-64-linux-tdep.c 31 May 2003 16:11:47 -0000 1.19 +++ x86-64-linux-tdep.c 10 Jul 2003 09:52:33 -0000 @@ -30,6 +30,116 @@ #include "gdb_string.h" #include "x86-64-tdep.h" +#include "x86-64-linux-tdep.h" + +/* Register indexes to 'struct user' come from . */ + +#define USER_R15 0 +#define USER_R14 1 +#define USER_R13 2 +#define USER_R12 3 +#define USER_RBP 4 +#define USER_RBX 5 +#define USER_R11 6 +#define USER_R10 7 +#define USER_R9 8 +#define USER_R8 9 +#define USER_RAX 10 +#define USER_RCX 11 +#define USER_RDX 12 +#define USER_RSI 13 +#define USER_RDI 14 +#define USER_RIP 16 +#define USER_CS 17 +#define USER_EFLAGS 18 +#define USER_RSP 19 +#define USER_SS 20 +#define USER_DS 23 +#define USER_ES 24 +#define USER_FS 25 +#define USER_GS 26 + +/* Mapping between the general-purpose registers in `struct user' + format and GDB's register array layout. */ + +static int user_to_gdb_regmap[] = +{ + USER_RAX, USER_RBX, USER_RCX, USER_RDX, + USER_RSI, USER_RDI, USER_RBP, USER_RSP, + USER_R8, USER_R9, USER_R10, USER_R11, + USER_R12, USER_R13, USER_R14, USER_R15, + USER_RIP, USER_EFLAGS, USER_CS, USER_SS, + USER_DS, USER_ES, USER_FS, USER_GS +}; + +/* Fill GDB's register array with the general-purpose register values + in *GREGSETP. */ + +void +x86_64_linux_supply_gregset (char *regp) +{ + int i; + + for (i = 0; i < X86_64_NUM_GREGS; i++) + supply_register (i, regp + (user_to_gdb_regmap[i] * 8)); +} + +/* Fill register REGNO (if it is a general-purpose register) in + *GREGSETPS with the value in GDB's register array. If REGNO is -1, + do this for all registers. */ + +void +x86_64_linux_fill_gregset (char *regp, int regno) +{ + int i; + + for (i = 0; i < X86_64_NUM_GREGS; i++) + if (regno == -1 || regno == i) + regcache_collect (i, regp + (user_to_gdb_regmap[i] * 8)); +} + +/* The register sets used in GNU/Linux ELF core-dumps are identical to + the register sets used by `ptrace'. The corresponding types are + `elf_gregset_t' for the general-purpose registers (with + `elf_greg_t' the type of a single GP register) and `elf_fpregset_t' + for the floating-point registers. */ + +static void +fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, + int which, CORE_ADDR ignore) +{ + switch (which) + { + case 0: /* Integer registers. */ + if (core_reg_size != 216) + warning ("Wrong size register set in core file."); + else + x86_64_linux_supply_gregset (core_reg_sect); + break; + + case 2: /* Floating point registers. */ + case 3: /* "Extended" floating point registers. This is gdb-speak + for SSE/SSE2. */ + if (core_reg_size != 512) + warning ("Wrong size XMM register set in core file."); + else + x86_64_supply_fxsave (core_reg_sect); + break; + + default: + /* Don't know what kind of register request this is; just ignore it. */ + break; + } +} + +static struct core_fns x86_64_core_fns = +{ + bfd_target_elf_flavour, /* core_flavour */ + default_check_format, /* check_format */ + default_core_sniffer, /* core_sniffer */ + fetch_core_registers, /* core_read_registers */ + NULL /* next */ +}; #define LINUX_SIGTRAMP_INSN0 0x48 /* mov $NNNNNNNN, %rax */ #define LINUX_SIGTRAMP_OFFSET0 0 @@ -175,6 +285,8 @@ extern void _initialize_x86_64_linux_tde void _initialize_x86_64_linux_tdep (void) { + add_core_fns (&x86_64_core_fns); + gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64, GDB_OSABI_LINUX, x86_64_linux_init_abi); } Index: config/i386/x86-64linux.mh =================================================================== RCS file: /cvs/src/src/gdb/config/i386/x86-64linux.mh,v retrieving revision 1.9 diff -u -p -r1.9 x86-64linux.mh --- config/i386/x86-64linux.mh 15 Jun 2003 20:56:47 -0000 1.9 +++ config/i386/x86-64linux.mh 10 Jul 2003 09:52:33 -0000 @@ -3,8 +3,8 @@ XM_FILE= xm-i386.h NAT_FILE= nm-x86-64linux.h -NATDEPFILES= infptrace.o inftarg.o fork-child.o corelow.o \ - core-regset.o i386-nat.o x86-64-linux-nat.o \ +NATDEPFILES= infptrace.o inftarg.o fork-child.o \ + i386-nat.o x86-64-linux-nat.o \ linux-nat.o \ proc-service.o thread-db.o lin-lwp.o linux-proc.o gcore.o Index: config/i386/x86-64linux.mt =================================================================== RCS file: /cvs/src/src/gdb/config/i386/x86-64linux.mt,v retrieving revision 1.7 diff -u -p -r1.7 x86-64linux.mt --- config/i386/x86-64linux.mt 31 May 2003 08:15:38 -0000 1.7 +++ config/i386/x86-64linux.mt 10 Jul 2003 09:52:33 -0000 @@ -1,7 +1,7 @@ # Target: AMD x86-64 running GNU/Linux TDEPFILES= x86-64-tdep.o x86-64-linux-tdep.o \ i386-tdep.o i387-tdep.o i386-linux-tdep.o \ - solib.o solib-svr4.o solib-legacy.o + solib.o solib-svr4.o solib-legacy.o corelow.o GDB_MULTI_ARCH=GDB_MULTI_ARCH_TM Index: x86-64-linux-tdep.h =================================================================== RCS file: x86-64-linux-tdep.h diff -N x86-64-linux-tdep.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ x86-64-linux-tdep.h 10 Jul 2003 09:58:04 -0000 @@ -0,0 +1,39 @@ +/* Target-dependent code for the x86-64. + + Copyright 2003 + Free Software Foundation, Inc. + + Contributed by Michal Ludvig, SuSE AG. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#ifndef X86_64_LINUX_TDEP_H +#define X86_64_LINUX_TDEP_H + +/* Fill GDB's register array with the general-purpose register values + in *GREGSETP. */ + +void x86_64_linux_supply_gregset (char *regp); + +/* Fill register REGNO (if it is a general-purpose register) in + *GREGSETPS with the value in GDB's register array. If REGNO is -1, + do this for all registers. */ + +void x86_64_linux_fill_gregset (char *regp, int regno); + +#endif /* x86-64-linux-tdep.h */ --------------030204000104010203080806--