Skip to contentSkip to conversation

GDB

DISCUSSION [email protected] 2 participants 3 messages Nov 5, 1998 – Nov 9, 1998 MIPS

lore
Share & tools
lore
#0 lore raw

I found that by accident GDB and the kernel were using different ptrace(2) interfaces. After fixing that for example ``info registers'' works ok.

Ralf

#1 lore raw
Quoted 3 lines · On Thu, Nov 05, 1998 at 02:30:15AM +0100, [email protected] wrote:

I found that by accident GDB and the kernel were using different ptrace(2) interfaces. After fixing that for example ``info registers'' works ok.

how about sharing your fix with us ?

Thomas.

Signature · 3 lines
   This device has completely bogus header. Compaq scores again :-|
It's a host bridge, but it should be called ghost bridge instead ;^)
                                        [Martin `MJ' Mares on linux-kernel]
#2 lore raw
Quoted 6 lines · Thomas Bogendoerfer
Quoted 3 lines · On Thu, Nov 05, 1998 at 02:30:15AM +0100, [email protected] wrote:

I found that by accident GDB and the kernel were using different ptrace(2) interfaces. After fixing that for example ``info registers'' works ok.

how about sharing your fix with us ?

Guess too much decaf when I wrote that mail ... Attached the fixed version of mipslinux-nat.c. I've copied all the (corrected!) definitions of the kernel interfaces into mipslinux-nat.c, therefore no more headerfile problems even with old kernel headers installed.

Ralf

/* Low level MIPS/Linux interface, for GDB when running native.
Copyright 1996 Free Software Foundation, Inc. Contributed by David S. Miller ([email protected]) at Rutgers University CAIP Research Center.

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. */

#include "defs.h"
#include "inferior.h"
#include "gdbcore.h"
#include "target.h"
#include "gdb_string.h"
#include "symtab.h"
#include "bfd.h"
#include "symfile.h"
#include "objfiles.h"
#include "command.h"
#include "frame.h"
#include "gnu-regex.h"
#include "inferior.h"
#include "language.h"
#include "gdbcmd.h"
#include <sys/ptrace.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/user.h>

#include <setjmp.h> /* For JB_PC and friends. */

/* This duplicates definitions from <asm/elfcore.h> ... */

/* ELF register definitions */
#define ELF_NGREG 45
#define ELF_NFPREG 33

typedef unsigned long gregset_t [ELF_NGREG];
typedef double fpregset_t [ELF_NFPREG];

/* This duplicates definitions from <asm/elf.h> ... */

/* 0 - 31 are integer registers, 32 - 63 are fp registers. */
#define FPR_BASE 32
#define PC 64
#define CAUSE 65
#define BADVADDR 66
#define MMHI 67
#define MMLO 68
#define FPC_CSR 69
#define FPC_EIR 70

/* End of duplicated definitions */

/* Size of elements in jmpbuf */

#define JB_ELEMENT_SIZE 4

/* Figure out where the longjmp will land.
We expect the first arg to be a pointer to the jmp_buf structure from which we extract the pc (JB_PC) that we will land at. The pc is copied into PC. This routine returns true on success. */

int
get_longjmp_target(pc)

     CORE_ADDR *pc;

{
CORE_ADDR jb_addr;
char buf[TARGET_PTR_BIT / TARGET_CHAR_BIT];

  jb_addr = read_register (A0_REGNUM);

if (target_read_memory (jb_addr + JB_PC * JB_ELEMENT_SIZE, buf,

			  TARGET_PTR_BIT / TARGET_CHAR_BIT))
    return 0;
  *pc = extract_address (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT);

return 1;
}

/*
* See the comment in m68k-tdep.c regarding the utility of these functions. *
* These definitions are from the MIPS SVR4 ABI, so they may work for
* any MIPS SVR4 target.
*/

void
supply_gregset (gregsetp)

     gregset_t *gregsetp;

{
register int regi;
register unsigned int *regp = (unsigned int *) &(*gregsetp)[0]; static char zerobuf[MAX_REGISTER_RAW_SIZE] = {0};

  for (regi = EF_REG0; regi <= EF_LO; regi++)
    supply_register ((regi - EF_REG0), (char *)(regp + regi));

  supply_register(PC_REGNUM, (char *)(regp + EF_CP0_EPC));
  supply_register(CAUSE_REGNUM, (char *)(regp + EF_CP0_CAUSE));
  supply_register(BADVADDR_REGNUM, (char *)(regp + EF_CP0_BADVADDR));
  supply_register(LO_REGNUM, (char *)(regp + EF_LO));
  supply_register(HI_REGNUM, (char *)(regp + EF_HI));

/* Fill inaccessible registers with zero. */
supply_register (FP_REGNUM, zerobuf);
supply_register (UNUSED_REGNUM, zerobuf);
}

void
fill_gregset (gregsetp, regno)

     gregset_t *gregsetp;
     int regno;

{
int regi;
register unsigned int *regp = (unsigned int *) &(*gregsetp)[0];

for (regi = 0; regi <= (EF_SIZE / 4); regi++)

    if ((regno == -1) || (regno == regi))
      *(regp + regi) = *(unsigned int *) &registers[REGISTER_BYTE (regi)];
}

/* Now we do the same thing for floating-point registers.
* We don't bother to condition on FP0_REGNUM since any
* reasonable MIPS configuration has an R3010 in it. *
* Again, see the comments in m68k-tdep.c.
*/

void
supply_fpregset (fpregsetp)

     fpregset_t *fpregsetp;

{
register int regi;
static char zerobuf[MAX_REGISTER_RAW_SIZE] = {0};

for (regi = 0; regi < 32; regi++)
supply_register (FP0_REGNUM + regi,
(char *)&fpregsetp[regi]);

  supply_register (FCRCS_REGNUM, (char *)&fpregsetp[32]);

/* FIXME: how can we supply FCRIR_REGNUM? The ABI doesn't tell us. */ supply_register (FCRIR_REGNUM, zerobuf);
}

void
fill_fpregset (fpregsetp, regno)

     fpregset_t *fpregsetp;
     int regno;

{
int regi;
char *from, *to;

for (regi = FP0_REGNUM; regi < FP0_REGNUM + 32; regi++)

    {
      if ((regno == -1) || (regno == regi))
	{
	  from = (char *) &registers[REGISTER_BYTE (regi)];
	  to = (char *) &(fpregsetp[regi - FP0_REGNUM]);
	  memcpy(to, from, REGISTER_RAW_SIZE (regi));
	}
    }

#if 0
if ((regno == -1) || (regno == FCRCS_REGNUM))

    fpregsetp[32] = *(unsigned int *) &registers[REGISTER_BYTE(FCRCS_REGNUM)];

#endif
}

/* Map gdb internal register number to ptrace ``address''.
These ``addresses'' are defined in <mips/ptrace.h> */

#define REGISTER_PTRACE_ADDR(regno) \
(regno < 32 ? regno \
: regno == PC_REGNUM ? PC \
: regno == CAUSE_REGNUM ? CAUSE \
: regno == HI_REGNUM ? MMHI \
: regno == LO_REGNUM ? MMLO \
: regno == FCRCS_REGNUM ? FPC_CSR \
: regno == FCRIR_REGNUM ? FPC_EIR \
: regno >= FP0_REGNUM ? FPR_BASE + (regno - FP0_REGNUM) \
: 0)

/* Return the ptrace ``address'' of register REGNO. */

CORE_ADDR
register_addr (regno, blockend)

     int regno;
     CORE_ADDR blockend;
{
  if(regno < 0 || regno >= NUM_REGS)
    error ("Bogon register number %d.", regno);

return REGISTER_PTRACE_ADDR (regno);
}