* findvar.c, defs.h

({extract,store}_{signed_integer,unsigned_integer,address}):
	New routines to replace SWAP_TARGET_AND_HOST.
	All over: All uses of SWAP_TARGET_AND_HOST on integers replaced.
This commit is contained in:
Jim Kingdon 1993-07-10 01:35:53 +00:00
parent ec1c752b34
commit 34df79fc9d
16 changed files with 197 additions and 489 deletions

View file

@ -1,5 +1,10 @@
Fri Jul 9 12:36:46 1993 Jim Kingdon (kingdon@lioth.cygnus.com) Fri Jul 9 12:36:46 1993 Jim Kingdon (kingdon@lioth.cygnus.com)
* findvar.c, defs.h
({extract,store}_{signed_integer,unsigned_integer,address}):
New routines to replace SWAP_TARGET_AND_HOST.
All over: All uses of SWAP_TARGET_AND_HOST on integers replaced.
* config/sparc/tm-sparc.h: Add comment suggesting that removing * config/sparc/tm-sparc.h: Add comment suggesting that removing
ins and locals from the registers array might clean things up. ins and locals from the registers array might clean things up.

View file

@ -570,10 +570,9 @@ read_register_stack_integer (memaddr, len)
CORE_ADDR memaddr; CORE_ADDR memaddr;
int len; int len;
{ {
long buf; char buf[4];
read_register_stack (memaddr, &buf, NULL, NULL); read_register_stack (memaddr, buf, NULL, NULL);
SWAP_TARGET_AND_HOST (&buf, 4); return extract_signed_integer (buf, 4);
return buf;
} }
/* Copy 4 bytes from GDB memory at MYADDR into inferior memory /* Copy 4 bytes from GDB memory at MYADDR into inferior memory
@ -647,9 +646,7 @@ get_saved_register (raw_buffer, optimized, addrp, frame, regnum, lvalp)
{ {
if (raw_buffer != NULL) if (raw_buffer != NULL)
{ {
*(CORE_ADDR *)raw_buffer = fi->frame; store_address (raw_buffer, REGISTER_RAW_BYTES (regnum), fi->frame);
/* Put it back in target byte order. */
SWAP_TARGET_AND_HOST (raw_buffer, sizeof (CORE_ADDR));
} }
if (lvalp != NULL) if (lvalp != NULL)
*lvalp = not_lval; *lvalp = not_lval;
@ -659,9 +656,7 @@ get_saved_register (raw_buffer, optimized, addrp, frame, regnum, lvalp)
{ {
if (raw_buffer != NULL) if (raw_buffer != NULL)
{ {
*(CORE_ADDR *)raw_buffer = fi->pc; store_address (raw_buffer, REGISTER_RAW_BYTES (regnum), fi->pc);
/* Put it back in target byte order. */
SWAP_TARGET_AND_HOST (raw_buffer, sizeof (CORE_ADDR));
} }
/* Not sure we have to do this. */ /* Not sure we have to do this. */
@ -676,9 +671,8 @@ get_saved_register (raw_buffer, optimized, addrp, frame, regnum, lvalp)
{ {
if (fi->next != NULL) if (fi->next != NULL)
{ {
*(CORE_ADDR *)raw_buffer = fi->next->saved_msp; store_address (raw_buffer, REGISTER_RAW_BYTES (regnum),
/* Put it back in target byte order. */ fi->next->saved_msp);
SWAP_TARGET_AND_HOST (raw_buffer, sizeof (CORE_ADDR));
} }
else else
read_register_gen (MSP_REGNUM, raw_buffer); read_register_gen (MSP_REGNUM, raw_buffer);

View file

@ -209,79 +209,28 @@ write_memory (memaddr, myaddr, len)
/* Read an integer from debugged memory, given address and number of bytes. */ /* Read an integer from debugged memory, given address and number of bytes. */
long LONGEST
read_memory_integer (memaddr, len) read_memory_integer (memaddr, len)
CORE_ADDR memaddr; CORE_ADDR memaddr;
int len; int len;
{ {
char cbuf; char *buf;
short sbuf;
int ibuf;
long lbuf;
if (len == sizeof (char)) buf = alloca (len);
{ read_memory (memaddr, buf, len);
read_memory (memaddr, &cbuf, len); return extract_signed_integer (buf, len);
return cbuf;
}
if (len == sizeof (short))
{
read_memory (memaddr, (char *)&sbuf, len);
SWAP_TARGET_AND_HOST (&sbuf, sizeof (short));
return sbuf;
}
if (len == sizeof (int))
{
read_memory (memaddr, (char *)&ibuf, len);
SWAP_TARGET_AND_HOST (&ibuf, sizeof (int));
return ibuf;
}
if (len == sizeof (lbuf))
{
read_memory (memaddr, (char *)&lbuf, len);
SWAP_TARGET_AND_HOST (&lbuf, sizeof (lbuf));
return lbuf;
}
error ("Cannot handle integers of %d bytes.", len);
return -1; /* for lint */
} }
unsigned LONGEST
unsigned long
read_memory_unsigned_integer (memaddr, len) read_memory_unsigned_integer (memaddr, len)
CORE_ADDR memaddr; CORE_ADDR memaddr;
int len; int len;
{ {
unsigned char cbuf; char *buf;
unsigned short sbuf;
unsigned int ibuf;
unsigned long lbuf;
if (len == sizeof (char)) buf = alloca (len);
{ read_memory (memaddr, buf, len);
read_memory (memaddr, &cbuf, len); return extract_unsigned_integer (buf, len);
return cbuf;
}
if (len == sizeof (short))
{
read_memory (memaddr, (char *)&sbuf, len);
SWAP_TARGET_AND_HOST (&sbuf, sizeof (short));
return sbuf;
}
if (len == sizeof (int))
{
read_memory (memaddr, (char *)&ibuf, len);
SWAP_TARGET_AND_HOST (&ibuf, sizeof (int));
return ibuf;
}
if (len == sizeof (lbuf))
{
read_memory (memaddr, (char *)&lbuf, len);
SWAP_TARGET_AND_HOST (&lbuf, sizeof (lbuf));
return lbuf;
}
error ("Cannot handle unsigned integers of %d bytes.", len);
return -1; /* for lint */
} }
void void

View file

@ -180,10 +180,11 @@ NEXT_PROLOGUE_INSN (addr, lim, pword1)
CORE_ADDR lim; CORE_ADDR lim;
short *pword1; short *pword1;
{ {
char buf[2];
if (addr < lim + 8) if (addr < lim + 8)
{ {
read_memory (addr, pword1, sizeof (*pword1)); read_memory (addr, buf, 2);
SWAP_TARGET_AND_HOST (pword1, sizeof (short)); *pword1 = extract_signed_integer (buf, 2);
return addr + 2; return addr + 2;
} }

View file

@ -897,11 +897,12 @@ CORE_ADDR
skip_prologue(pc) skip_prologue(pc)
CORE_ADDR pc; CORE_ADDR pc;
{ {
int inst; char buf[4];
unsigned long inst;
int status; int status;
status = target_read_memory (pc, (char *)&inst, 4); status = target_read_memory (pc, buf, 4);
SWAP_TARGET_AND_HOST (&inst, sizeof (inst)); inst = extract_unsigned_integer (buf, 4);
if (status != 0) if (status != 0)
return pc; return pc;

View file

@ -23,10 +23,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gdbcore.h" #include "gdbcore.h"
#include "target.h" #include "target.h"
#ifdef USE_PROC_FS /* Target dependent support for /proc */
#include <sys/procfs.h>
#endif
static long static long
i386_get_frame_setup PARAMS ((int)); i386_get_frame_setup PARAMS ((int));
@ -82,9 +78,7 @@ codestream_fill (peek_flag)
codestream_next_addr += CODESTREAM_BUFSIZ; codestream_next_addr += CODESTREAM_BUFSIZ;
codestream_off = 0; codestream_off = 0;
codestream_cnt = CODESTREAM_BUFSIZ; codestream_cnt = CODESTREAM_BUFSIZ;
read_memory (codestream_addr, read_memory (codestream_addr, (char *) codestream_buf, CODESTREAM_BUFSIZ);
(unsigned char *)codestream_buf,
CODESTREAM_BUFSIZ);
if (peek_flag) if (peek_flag)
return (codestream_peek()); return (codestream_peek());
@ -255,8 +249,8 @@ i386_get_frame_setup (pc)
} }
else if (op == 0x81) else if (op == 0x81)
{ {
/* subl with 32 bit immed */ char buf[4];
int locals; /* Maybe it is subl with 32 bit immedediate. */
codestream_get(); codestream_get();
if (codestream_get () != 0xec) if (codestream_get () != 0xec)
/* Some instruction starting with 0x81 other than subl. */ /* Some instruction starting with 0x81 other than subl. */
@ -264,10 +258,9 @@ i386_get_frame_setup (pc)
codestream_seek (codestream_tell () - 2); codestream_seek (codestream_tell () - 2);
return 0; return 0;
} }
/* subl with 32 bit immediate */ /* It is subl with 32 bit immediate. */
codestream_read ((unsigned char *)&locals, 4); codestream_read ((unsigned char *)buf, 4);
SWAP_TARGET_AND_HOST (&locals, 4); return extract_signed_integer (buf, 4);
return (locals);
} }
else else
{ {
@ -276,12 +269,11 @@ i386_get_frame_setup (pc)
} }
else if (op == 0xc8) else if (op == 0xc8)
{ {
char buf[2];
/* enter instruction: arg is 16 bit unsigned immed */ /* enter instruction: arg is 16 bit unsigned immed */
unsigned short slocals; codestream_read ((unsigned char *)buf, 2);
codestream_read ((unsigned char *)&slocals, 2);
SWAP_TARGET_AND_HOST (&slocals, 2);
codestream_get (); /* flush final byte of enter instruction */ codestream_get (); /* flush final byte of enter instruction */
return (slocals); return extract_unsigned_integer (buf, 2);
} }
return (-1); return (-1);
} }
@ -289,20 +281,27 @@ i386_get_frame_setup (pc)
/* Return number of args passed to a frame. /* Return number of args passed to a frame.
Can return -1, meaning no way to tell. */ Can return -1, meaning no way to tell. */
/* on the 386, the instruction following the call could be:
* popl %ecx - one arg
* addl $imm, %esp - imm/4 args; imm may be 8 or 32 bits
* anything else - zero args
*/
int int
i386_frame_num_args (fi) i386_frame_num_args (fi)
struct frame_info *fi; struct frame_info *fi;
{ {
#if 1
return -1;
#else
/* This loses because not only might the compiler not be popping the
args right after the function call, it might be popping args from both
this call and a previous one, and we would say there are more args
than there really are. */
int retpc; int retpc;
unsigned char op; unsigned char op;
struct frame_info *pfi; struct frame_info *pfi;
/* on the 386, the instruction following the call could be:
popl %ecx - one arg
addl $imm, %esp - imm/4 args; imm may be 8 or 32 bits
anything else - zero args */
int frameless; int frameless;
FRAMELESS_FUNCTION_INVOCATION (fi, frameless); FRAMELESS_FUNCTION_INVOCATION (fi, frameless);
@ -352,6 +351,7 @@ i386_frame_num_args (fi)
return 0; return 0;
} }
} }
#endif
} }
/* /*
@ -394,7 +394,7 @@ i386_frame_find_saved_regs (fip, fsrp)
CORE_ADDR adr; CORE_ADDR adr;
int i; int i;
(void) memset (fsrp, 0, sizeof *fsrp); memset (fsrp, 0, sizeof *fsrp);
/* if frame is the end of a dummy, compute where the /* if frame is the end of a dummy, compute where the
* beginning would be * beginning would be
@ -514,137 +514,6 @@ i386_pop_frame ()
read_pc ())); read_pc ()));
} }
#ifdef USE_PROC_FS /* Target dependent support for /proc */
/* The /proc interface divides the target machine's register set up into
two different sets, the general register set (gregset) and the floating
point register set (fpregset). For each set, there is an ioctl to get
the current register set and another ioctl to set the current values.
The actual structure passed through the ioctl interface is, of course,
naturally machine dependent, and is different for each set of registers.
For the i386 for example, the general register set is typically defined
by:
typedef int gregset_t[19]; (in <sys/regset.h>)
#define GS 0 (in <sys/reg.h>)
#define FS 1
...
#define UESP 17
#define SS 18
and the floating point set by:
typedef struct fpregset
{
union
{
struct fpchip_state // fp extension state //
{
int state[27]; // 287/387 saved state //
int status; // status word saved at exception //
} fpchip_state;
struct fp_emul_space // for emulators //
{
char fp_emul[246];
char fp_epad[2];
} fp_emul_space;
int f_fpregs[62]; // union of the above //
} fp_reg_set;
long f_wregs[33]; // saved weitek state //
} fpregset_t;
These routines provide the packing and unpacking of gregset_t and
fpregset_t formatted data.
*/
/* This is a duplicate of the table in i386-xdep.c. */
static int regmap[] =
{
EAX, ECX, EDX, EBX,
UESP, EBP, ESI, EDI,
EIP, EFL, CS, SS,
DS, ES, FS, GS,
};
/* Given a pointer to a general register set in /proc format (gregset_t *),
unpack the register contents and supply them as gdb's idea of the current
register values. */
void
supply_gregset (gregsetp)
gregset_t *gregsetp;
{
register int regno;
register greg_t *regp = (greg_t *) gregsetp;
extern int regmap[];
for (regno = 0 ; regno < NUM_REGS ; regno++)
{
supply_register (regno, (char *) (regp + regmap[regno]));
}
}
void
fill_gregset (gregsetp, regno)
gregset_t *gregsetp;
int regno;
{
int regi;
register greg_t *regp = (greg_t *) gregsetp;
extern char registers[];
extern int regmap[];
for (regi = 0 ; regi < NUM_REGS ; regi++)
{
if ((regno == -1) || (regno == regi))
{
*(regp + regmap[regno]) = *(int *) &registers[REGISTER_BYTE (regi)];
}
}
}
#if defined (FP0_REGNUM)
/* Given a pointer to a floating point register set in /proc format
(fpregset_t *), unpack the register contents and supply them as gdb's
idea of the current floating point register values. */
void
supply_fpregset (fpregsetp)
fpregset_t *fpregsetp;
{
register int regno;
/* FIXME: see m68k-tdep.c for an example, for the m68k. */
}
/* Given a pointer to a floating point register set in /proc format
(fpregset_t *), update the register specified by REGNO from gdb's idea
of the current floating point register set. If REGNO is -1, update
them all. */
void
fill_fpregset (fpregsetp, regno)
fpregset_t *fpregsetp;
int regno;
{
int regi;
char *to;
char *from;
extern char registers[];
/* FIXME: see m68k-tdep.c for an example, for the m68k. */
}
#endif /* defined (FP0_REGNUM) */
#endif /* USE_PROC_FS */
#ifdef GET_LONGJMP_TARGET #ifdef GET_LONGJMP_TARGET
/* Figure out where the longjmp will land. Slurp the args out of the stack. /* Figure out where the longjmp will land. Slurp the args out of the stack.
@ -656,25 +525,65 @@ int
get_longjmp_target(pc) get_longjmp_target(pc)
CORE_ADDR *pc; CORE_ADDR *pc;
{ {
char buf[TARGET_PTR_BIT / TARGET_CHAR_BIT];
CORE_ADDR sp, jb_addr; CORE_ADDR sp, jb_addr;
sp = read_register(SP_REGNUM); sp = read_register (SP_REGNUM);
if (target_read_memory(sp + SP_ARG0, /* Offset of first arg on stack */ if (target_read_memory (sp + SP_ARG0, /* Offset of first arg on stack */
(char *) &jb_addr, buf,
sizeof(CORE_ADDR))) TARGET_PTR_BIT / TARGET_CHAR_BIT))
return 0; return 0;
jb_addr = extract_address (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT);
SWAP_TARGET_AND_HOST(&jb_addr, sizeof(CORE_ADDR)); if (target_read_memory (jb_addr + JB_PC * JB_ELEMENT_SIZE, buf,
TARGET_PTR_BIT / TARGET_CHAR_BIT))
if (target_read_memory(jb_addr + JB_PC * JB_ELEMENT_SIZE, (char *) pc,
sizeof(CORE_ADDR)))
return 0; return 0;
SWAP_TARGET_AND_HOST(pc, sizeof(CORE_ADDR)); *pc = extract_address (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT);
return 1; return 1;
} }
#endif /* GET_LONGJMP_TARGET */ #endif /* GET_LONGJMP_TARGET */
#ifdef I386_AIX_TARGET
/* On AIX, floating point values are returned in floating point registers. */
void
i386_extract_return_value(type, regbuf, valbuf)
struct type *type;
char regbuf[REGISTER_BYTES];
char *valbuf;
{
if (TYPE_CODE_FLT == TYPE_CODE(type))
{
extern struct ext_format ext_format_i387;
double d;
/* 387 %st(0), gcc uses this */
ieee_extended_to_double (&ext_format_i387,
&regbuf[REGISTER_BYTE(FP0_REGNUM)],
&d);
switch (TYPE_LENGTH(type))
{
case 4: /* float */
{
float f = (float) d;
memcpy (valbuf, &f, 4);
break;
}
case 8: /* double */
memcpy (valbuf, &d, 8);
break;
default:
error("Unknown floating point size");
break;
}
}
else
{
memcpy (valbuf, regbuf, TYPE_LENGTH (type));
}
}
#endif /* I386_AIX_TARGET */

View file

@ -135,17 +135,16 @@ next_insn (memaddr, pword1, pword2)
CORE_ADDR memaddr; CORE_ADDR memaddr;
{ {
int len; int len;
unsigned long buf[2]; char buf[8];
/* Read the two (potential) words of the instruction at once, /* Read the two (potential) words of the instruction at once,
to eliminate the overhead of two calls to read_memory (). to eliminate the overhead of two calls to read_memory ().
TODO: read more instructions at once and cache them. */ FIXME: Loses if the first one is readable but the second is not
(e.g. last word of the segment). */
read_memory (memaddr, buf, sizeof (buf)); read_memory (memaddr, buf, 8);
*pword1 = buf[0]; *pword1 = extract_unsigned_integer (buf, 4);
SWAP_TARGET_AND_HOST (pword1, sizeof (long)); *pword2 = extract_unsigned_integer (buf + 4, 4);
*pword2 = buf[1];
SWAP_TARGET_AND_HOST (pword2, sizeof (long));
/* Divide instruction set into classes based on high 4 bits of opcode*/ /* Divide instruction set into classes based on high 4 bits of opcode*/

View file

@ -133,18 +133,19 @@ fill_fpregset (fpregsetp, regno)
This routine returns true on success. */ This routine returns true on success. */
int int
get_longjmp_target(pc) get_longjmp_target (pc)
CORE_ADDR *pc; CORE_ADDR *pc;
{ {
char buf[TARGET_PTR_BIT / TARGET_CHAR_BIT];
CORE_ADDR jb_addr; CORE_ADDR jb_addr;
jb_addr = read_register(A0_REGNUM); jb_addr = read_register (A0_REGNUM);
if (target_read_memory(jb_addr + JB_PC * JB_ELEMENT_SIZE, pc, if (target_read_memory (jb_addr + JB_PC * JB_ELEMENT_SIZE, buf,
sizeof(CORE_ADDR))) TARGET_PTR_BIT / TARGET_CHAR_BIT))
return 0; return 0;
SWAP_TARGET_AND_HOST(pc, sizeof(CORE_ADDR)); *pc = extract_address (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT);
return 1; return 1;
} }

View file

@ -149,14 +149,15 @@ get_longjmp_target(pc)
CORE_ADDR *pc; CORE_ADDR *pc;
{ {
CORE_ADDR jb_addr; CORE_ADDR jb_addr;
char buf[TARGET_PTR_BIT / TARGET_CHAR_BIT];
jb_addr = read_register(A0_REGNUM); jb_addr = read_register (A0_REGNUM);
if (target_read_memory(jb_addr + JB_PC * JB_ELEMENT_SIZE, pc, if (target_read_memory (jb_addr + JB_PC * JB_ELEMENT_SIZE, buf,
sizeof(CORE_ADDR))) TARGET_PTR_BIT / TARGET_CHAR_BIT))
return 0; return 0;
SWAP_TARGET_AND_HOST(pc, sizeof(CORE_ADDR)); *pc = extract_address (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT);
return 1; return 1;
} }

View file

@ -178,12 +178,14 @@ heuristic_proc_desc(start_pc, limit_pc, next_frame)
restart: restart:
frame_size = 0; frame_size = 0;
for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += 4) { for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += 4) {
char buf[4];
unsigned long word; unsigned long word;
int status; int status;
status = read_memory_nobpt (cur_pc, (char *)&word, 4); status = read_memory_nobpt (cur_pc, buf, 4);
if (status) memory_error (status, cur_pc); if (status) memory_error (status, cur_pc);
SWAP_TARGET_AND_HOST (&word, sizeof (word)); word = extract_unsigned_integer (buf, 4);
if ((word & 0xFFFF0000) == 0x27bd0000) /* addiu $sp,$sp,-i */ if ((word & 0xFFFF0000) == 0x27bd0000) /* addiu $sp,$sp,-i */
frame_size += (-word) & 0xFFFF; frame_size += (-word) & 0xFFFF;
else if ((word & 0xFFFF0000) == 0x23bd0000) /* addu $sp,$sp,-i */ else if ((word & 0xFFFF0000) == 0x23bd0000) /* addu $sp,$sp,-i */
@ -636,8 +638,9 @@ mips_print_register (regnum, all)
{ {
long val; long val;
bcopy (raw_buffer, &val, sizeof (long)); val = extract_signed_integer (raw_buffer,
SWAP_TARGET_AND_HOST ((char *)&val, sizeof (long)); REGISTER_RAW_SIZE (regnum));
if (val == 0) if (val == 0)
printf_filtered ("0"); printf_filtered ("0");
else if (all) else if (all)

View file

@ -1061,10 +1061,14 @@ mips_fetch_registers (regno)
if (err) if (err)
error ("Can't read register %d: %s", regno, safe_strerror (errno)); error ("Can't read register %d: %s", regno, safe_strerror (errno));
{
char buf[MAX_REGISTER_RAW_SIZE];
/* We got the number the register holds, but gdb expects to see a /* We got the number the register holds, but gdb expects to see a
value in the target byte ordering. */ value in the target byte ordering. */
SWAP_TARGET_AND_HOST (&val, sizeof (REGISTER_TYPE)); store_unsigned_integer (buf, REGISTER_RAW_SIZE (regno), val);
supply_register (regno, (char *) &val); supply_register (regno, buf);
}
} }
/* Prepare to store registers. The MIPS protocol can store individual /* Prepare to store registers. The MIPS protocol can store individual
@ -1157,7 +1161,7 @@ mips_xfer_memory (memaddr, myaddr, len, write, ignore)
/* Round ending address up; get number of longwords that makes. */ /* Round ending address up; get number of longwords that makes. */
register int count = (((memaddr + len) - addr) + 3) / 4; register int count = (((memaddr + len) - addr) + 3) / 4;
/* Allocate buffer of that many longwords. */ /* Allocate buffer of that many longwords. */
register unsigned int *buffer = (unsigned int *) alloca (count * 4); register char *buffer = alloca (count * 4);
if (write) if (write)
{ {
@ -1165,14 +1169,15 @@ mips_xfer_memory (memaddr, myaddr, len, write, ignore)
if (addr != memaddr || len < 4) if (addr != memaddr || len < 4)
{ {
/* Need part of initial word -- fetch it. */ /* Need part of initial word -- fetch it. */
buffer[0] = mips_fetch_word (addr); store_unsigned_integer (&buffer[0], 4, mips_fetch_word (addr));
SWAP_TARGET_AND_HOST (buffer, 4);
} }
if (count > 1) /* FIXME, avoid if even boundary */ if (count > 1)
{ {
buffer[count - 1] = mips_fetch_word (addr + (count - 1) * 4); /* Need part of last word -- fetch it. FIXME: we do this even
SWAP_TARGET_AND_HOST (buffer + (count - 1) * 4, 4); if we don't need it. */
store_unsigned_integer (&buffer[(count - 1) * 4], 4,
mips_fetch_word (addr + (count - 1) * 4));
} }
/* Copy data to be written over corresponding part of buffer */ /* Copy data to be written over corresponding part of buffer */
@ -1183,8 +1188,8 @@ mips_xfer_memory (memaddr, myaddr, len, write, ignore)
for (i = 0; i < count; i++, addr += 4) for (i = 0; i < count; i++, addr += 4)
{ {
SWAP_TARGET_AND_HOST (buffer + i, 4); mips_store_word (addr, extract_unsigned_integer (&buffer[i*4], 4));
mips_store_word (addr, buffer[i]); /* FIXME: Do we want a QUIT here? */
} }
} }
else else
@ -1192,13 +1197,12 @@ mips_xfer_memory (memaddr, myaddr, len, write, ignore)
/* Read all the longwords */ /* Read all the longwords */
for (i = 0; i < count; i++, addr += 4) for (i = 0; i < count; i++, addr += 4)
{ {
buffer[i] = mips_fetch_word (addr); store_unsigned_integer (&buffer[i*4], 4, mips_fetch_word (addr));
SWAP_TARGET_AND_HOST (buffer + i, 4);
QUIT; QUIT;
} }
/* Copy appropriate bytes out of the buffer. */ /* Copy appropriate bytes out of the buffer. */
memcpy (myaddr, (char *) buffer + (memaddr & (sizeof (int) - 1)), len); memcpy (myaddr, buffer + (memaddr & 3), len);
} }
return len; return len;
} }

View file

@ -187,12 +187,13 @@ single_step (signal)
skip_prologue (pc) skip_prologue (pc)
CORE_ADDR pc; CORE_ADDR pc;
{ {
char buf[4];
unsigned int tmp; unsigned int tmp;
unsigned int op; /* FIXME, assumes instruction size matches host int!!! */ unsigned long op;
if (target_read_memory (pc, (char *)&op, sizeof (op))) if (target_read_memory (pc, buf, 4))
return pc; /* Can't access it -- assume no prologue. */ return pc; /* Can't access it -- assume no prologue. */
SWAP_TARGET_AND_HOST (&op, sizeof (op)); op = extract_unsigned_integer (buf, 4);
/* Assume that subsequent fetches can fail with low probability. */ /* Assume that subsequent fetches can fail with low probability. */

View file

@ -147,8 +147,7 @@ sparc_frame_chain (thisframe)
err = target_read_memory (addr, (char *) &retval, sizeof (REGISTER_TYPE)); err = target_read_memory (addr, (char *) &retval, sizeof (REGISTER_TYPE));
if (err) if (err)
return 0; return 0;
SWAP_TARGET_AND_HOST (&retval, sizeof (retval)); return extract_address (&retval, sizeof (retval));
return retval;
} }
CORE_ADDR CORE_ADDR
@ -167,22 +166,12 @@ frame_saved_pc (frame)
FRAME frame; FRAME frame;
{ {
REGISTER_TYPE retval; REGISTER_TYPE retval;
CORE_ADDR addr,prev_pc; CORE_ADDR addr;
if (get_current_frame () == frame) /* FIXME, debug check. Remove >=gdb-4.6 */
{
if (read_register (SP_REGNUM) != frame->bottom) abort();
}
addr = (frame->bottom + FRAME_SAVED_I0 + addr = (frame->bottom + FRAME_SAVED_I0 +
REGISTER_RAW_SIZE (I7_REGNUM) * (I7_REGNUM - I0_REGNUM)); REGISTER_RAW_SIZE (I7_REGNUM) * (I7_REGNUM - I0_REGNUM));
read_memory (addr, (char *) &retval, sizeof (REGISTER_TYPE)); read_memory (addr, (char *) &retval, sizeof (REGISTER_TYPE));
SWAP_TARGET_AND_HOST (&retval, sizeof (retval)); return PC_ADJUST (extract_address (&retval, sizeof (REGISTER_TYPE)));
/* CORE_ADDR isn't always the same size as REGISTER_TYPE, so convert. */
prev_pc = (CORE_ADDR) retval;
return PC_ADJUST (prev_pc);
} }
/* /*
@ -582,11 +571,12 @@ CORE_ADDR
sparc_pc_adjust(pc) sparc_pc_adjust(pc)
CORE_ADDR pc; CORE_ADDR pc;
{ {
long insn; unsigned long insn;
char buf[4];
int err; int err;
err = target_read_memory (pc + 8, (char *)&insn, sizeof(long)); err = target_read_memory (pc + 8, buf, sizeof(long));
SWAP_TARGET_AND_HOST (&insn, sizeof(long)); insn = extract_unsigned_integer (buf, 4);
if ((err == 0) && (insn & 0xfffffe00) == 0) if ((err == 0) && (insn & 0xfffffe00) == 0)
return pc+12; return pc+12;
else else
@ -769,14 +759,16 @@ get_longjmp_target(pc)
CORE_ADDR *pc; CORE_ADDR *pc;
{ {
CORE_ADDR jb_addr; CORE_ADDR jb_addr;
#define LONGJMP_TARGET_SIZE 4
char buf[LONGJMP_TARGET_SIZE];
jb_addr = read_register(O0_REGNUM); jb_addr = read_register(O0_REGNUM);
if (target_read_memory(jb_addr + JB_PC * JB_ELEMENT_SIZE, (char *) pc, if (target_read_memory(jb_addr + JB_PC * JB_ELEMENT_SIZE, buf,
sizeof(CORE_ADDR))) LONGJMP_TARGET_SIZE))
return 0; return 0;
SWAP_TARGET_AND_HOST(pc, sizeof(CORE_ADDR)); *pc = extract_address (buf, LONGJMP_TARGET_SIZE);
return 1; return 1;
} }

View file

@ -627,13 +627,14 @@ value_ind (arg1)
/* Push one word (the size of object that a register holds). */ /* Push one word (the size of object that a register holds). */
CORE_ADDR CORE_ADDR
push_word (sp, buffer) push_word (sp, word)
CORE_ADDR sp; CORE_ADDR sp;
REGISTER_TYPE buffer; REGISTER_TYPE word;
{ {
register int len = sizeof (REGISTER_TYPE); register int len = sizeof (REGISTER_TYPE);
REGISTER_TYPE buffer;
SWAP_TARGET_AND_HOST (&buffer, len); store_unsigned_integer (&buffer, len, word);
#if 1 INNER_THAN 2 #if 1 INNER_THAN 2
sp -= len; sp -= len;
write_memory (sp, (char *)&buffer, len); write_memory (sp, (char *)&buffer, len);
@ -854,9 +855,9 @@ call_function_by_hand (function, nargs, args)
/* Create a call sequence customized for this function /* Create a call sequence customized for this function
and the number of arguments for it. */ and the number of arguments for it. */
memcpy (dummy1, dummy, sizeof dummy);
for (i = 0; i < sizeof dummy / sizeof (REGISTER_TYPE); i++) for (i = 0; i < sizeof dummy / sizeof (REGISTER_TYPE); i++)
SWAP_TARGET_AND_HOST (&dummy1[i], sizeof (REGISTER_TYPE)); store_unsigned_integer (&dummy1[i], sizeof (REGISTER_TYPE),
(unsigned LONGEST)dummy[i]);
#ifdef GDB_TARGET_IS_HPPA #ifdef GDB_TARGET_IS_HPPA
real_pc = FIX_CALL_DUMMY (dummy1, start_sp, funaddr, nargs, args, real_pc = FIX_CALL_DUMMY (dummy1, start_sp, funaddr, nargs, args,

View file

@ -605,139 +605,22 @@ unpack_long (type, valaddr)
error ("Unexpected type of floating point number."); error ("Unexpected type of floating point number.");
} }
} }
else if (code == TYPE_CODE_INT && nosign) else if ((code == TYPE_CODE_INT || code == TYPE_CODE_CHAR) && nosign)
{ {
if (len == sizeof (char)) return extract_unsigned_integer (valaddr, len);
{
unsigned char retval = * (unsigned char *) valaddr;
/* SWAP_TARGET_AND_HOST (&retval, sizeof (unsigned char)); */
return retval;
} }
else if (code == TYPE_CODE_INT || code == TYPE_CODE_CHAR)
if (len == sizeof (short))
{ {
unsigned short retval; return extract_signed_integer (valaddr, len);
memcpy (&retval, valaddr, sizeof (retval));
SWAP_TARGET_AND_HOST (&retval, sizeof (retval));
return retval;
}
if (len == sizeof (int))
{
unsigned int retval;
memcpy (&retval, valaddr, sizeof (retval));
SWAP_TARGET_AND_HOST (&retval, sizeof (retval));
return retval;
}
if (len == sizeof (long))
{
unsigned long retval;
memcpy (&retval, valaddr, sizeof (retval));
SWAP_TARGET_AND_HOST (&retval, sizeof (retval));
return retval;
}
#ifdef CC_HAS_LONG_LONG
if (len == sizeof (long long))
{
unsigned long long retval;
memcpy (&retval, valaddr, sizeof (retval));
SWAP_TARGET_AND_HOST (&retval, sizeof (retval));
return retval;
}
#endif
else
{
error ("That operation is not possible on an integer of that size.");
}
}
else if (code == TYPE_CODE_INT)
{
if (len == sizeof (char))
{
SIGNED char retval; /* plain chars might be unsigned on host */
memcpy (&retval, valaddr, sizeof (retval));
SWAP_TARGET_AND_HOST (&retval, sizeof (retval));
return retval;
}
if (len == sizeof (short))
{
short retval;
memcpy (&retval, valaddr, sizeof (retval));
SWAP_TARGET_AND_HOST (&retval, sizeof (retval));
return retval;
}
if (len == sizeof (int))
{
int retval;
memcpy (&retval, valaddr, sizeof (retval));
SWAP_TARGET_AND_HOST (&retval, sizeof (retval));
return retval;
}
if (len == sizeof (long))
{
long retval;
memcpy (&retval, valaddr, sizeof (retval));
SWAP_TARGET_AND_HOST (&retval, sizeof (retval));
return retval;
}
#ifdef CC_HAS_LONG_LONG
if (len == sizeof (long long))
{
long long retval;
memcpy (&retval, valaddr, sizeof (retval));
SWAP_TARGET_AND_HOST (&retval, sizeof (retval));
return retval;
}
#endif
else
{
error ("That operation is not possible on an integer of that size.");
}
} }
/* Assume a CORE_ADDR can fit in a LONGEST (for now). Not sure /* Assume a CORE_ADDR can fit in a LONGEST (for now). Not sure
whether we want this to be true eventually. */ whether we want this to be true eventually. */
else if (code == TYPE_CODE_PTR || code == TYPE_CODE_REF) else if (code == TYPE_CODE_PTR || code == TYPE_CODE_REF)
{ {
if (len == sizeof(long)) return extract_address (valaddr, len);
{
unsigned long retval;
memcpy (&retval, valaddr, sizeof(retval));
SWAP_TARGET_AND_HOST (&retval, sizeof(retval));
return retval;
}
else if (len == sizeof(short))
{
unsigned short retval;
memcpy (&retval, valaddr, len);
SWAP_TARGET_AND_HOST (&retval, len);
return retval;
}
else if (len == sizeof(int))
{
unsigned int retval;
memcpy (&retval, valaddr, len);
SWAP_TARGET_AND_HOST (&retval, len);
return retval;
}
#ifdef CC_HAS_LONG_LONG
else if (len == sizeof(long long))
{
unsigned long long retval;
memcpy (&retval, valaddr, len);
SWAP_TARGET_AND_HOST (&retval, len);
return retval;
}
#endif
} }
else if (code == TYPE_CODE_MEMBER) else if (code == TYPE_CODE_MEMBER)
error ("not implemented: member types in unpack_long"); error ("not implemented: member types in unpack_long");
else if (code == TYPE_CODE_CHAR)
return *(unsigned char *)valaddr;
error ("Value not integer or pointer."); error ("Value not integer or pointer.");
return 0; /* For lint -- never reached */ return 0; /* For lint -- never reached */
@ -816,34 +699,9 @@ unpack_pointer (type, valaddr)
struct type *type; struct type *type;
char *valaddr; char *valaddr;
{ {
#if 0
/* The user should be able to use an int (e.g. 0x7892) in contexts
where a pointer is expected. So this doesn't do enough. */
register enum type_code code = TYPE_CODE (type);
register int len = TYPE_LENGTH (type);
if (code == TYPE_CODE_PTR
|| code == TYPE_CODE_REF)
{
if (len == sizeof (CORE_ADDR))
{
CORE_ADDR retval;
memcpy (&retval, valaddr, sizeof (retval));
SWAP_TARGET_AND_HOST (&retval, sizeof (retval));
return retval;
}
error ("Unrecognized pointer size.");
}
else if (code == TYPE_CODE_MEMBER)
error ("not implemented: member types in unpack_pointer");
error ("Value is not a pointer.");
return 0; /* For lint -- never reached */
#else
/* Assume a CORE_ADDR can fit in a LONGEST (for now). Not sure /* Assume a CORE_ADDR can fit in a LONGEST (for now). Not sure
whether we want this to be true eventually. */ whether we want this to be true eventually. */
return unpack_long (type, valaddr); return unpack_long (type, valaddr);
#endif
} }
/* Given a value ARG1 (offset by OFFSET bytes) /* Given a value ARG1 (offset by OFFSET bytes)
@ -1312,8 +1170,7 @@ unpack_field_as_long (type, valaddr, fieldno)
int bitsize = TYPE_FIELD_BITSIZE (type, fieldno); int bitsize = TYPE_FIELD_BITSIZE (type, fieldno);
int lsbcount; int lsbcount;
memcpy (&val, valaddr + bitpos / 8, sizeof (val)); val = extract_unsigned_integer (valaddr + bitpos / 8, sizeof (val));
SWAP_TARGET_AND_HOST (&val, sizeof (val));
/* Extract bits. See comment above. */ /* Extract bits. See comment above. */
@ -1361,8 +1218,7 @@ modify_field (addr, fieldval, bitpos, bitsize)
&& 0 != (fieldval & ~((1<<bitsize)-1))) && 0 != (fieldval & ~((1<<bitsize)-1)))
error ("Value %d does not fit in %d bits.", fieldval, bitsize); error ("Value %d does not fit in %d bits.", fieldval, bitsize);
memcpy (&oword, addr, sizeof oword); oword = extract_signed_integer (addr, sizeof oword);
SWAP_TARGET_AND_HOST (&oword, sizeof oword); /* To host format */
/* Shifting for bit field depends on endianness of the target machine. */ /* Shifting for bit field depends on endianness of the target machine. */
#if BITS_BIG_ENDIAN #if BITS_BIG_ENDIAN
@ -1376,8 +1232,7 @@ modify_field (addr, fieldval, bitpos, bitsize)
oword &= ~((-1) << bitpos); oword &= ~((-1) << bitpos);
oword |= fieldval << bitpos; oword |= fieldval << bitpos;
SWAP_TARGET_AND_HOST (&oword, sizeof oword); /* To target format */ store_signed_integer (addr, sizeof oword, oword);
memcpy (addr, &oword, sizeof oword);
} }
/* Convert C numbers into newly allocated values */ /* Convert C numbers into newly allocated values */
@ -1391,32 +1246,25 @@ value_from_longest (type, num)
register enum type_code code = TYPE_CODE (type); register enum type_code code = TYPE_CODE (type);
register int len = TYPE_LENGTH (type); register int len = TYPE_LENGTH (type);
/* FIXME, we assume that pointers have the same form and byte order as switch (code)
integers, and that all pointers have the same form. */
if (code == TYPE_CODE_INT || code == TYPE_CODE_ENUM ||
code == TYPE_CODE_CHAR || code == TYPE_CODE_PTR ||
code == TYPE_CODE_REF || code == TYPE_CODE_BOOL)
{ {
if (len == sizeof (char)) case TYPE_CODE_INT:
* (char *) VALUE_CONTENTS_RAW (val) = num; case TYPE_CODE_CHAR:
else if (len == sizeof (short)) case TYPE_CODE_ENUM:
* (short *) VALUE_CONTENTS_RAW (val) = num; case TYPE_CODE_BOOL:
else if (len == sizeof (int)) store_signed_integer (VALUE_CONTENTS_RAW (val), len, num);
* (int *) VALUE_CONTENTS_RAW (val) = num; break;
else if (len == sizeof (long))
* (long *) VALUE_CONTENTS_RAW (val) = num; case TYPE_CODE_REF:
else if (len == sizeof (LONGEST)) case TYPE_CODE_PTR:
* (LONGEST *) VALUE_CONTENTS_RAW (val) = num; /* This assumes that all pointers of a given length
else have the same form. */
error ("Integer type encountered with unexpected data length."); store_address (VALUE_CONTENTS_RAW (val), len, (CORE_ADDR) num);
} break;
else
default:
error ("Unexpected type encountered for integer constant."); error ("Unexpected type encountered for integer constant.");
}
/* num was in host byte order. So now put the value's contents
into target byte order. */
SWAP_TARGET_AND_HOST (VALUE_CONTENTS_RAW (val), len);
return val; return val;
} }

View file

@ -233,16 +233,15 @@ NEXT_PROLOGUE_INSN (addr, lim, pword1)
CORE_ADDR lim; CORE_ADDR lim;
short *pword1; short *pword1;
{ {
char buf[2];
if (addr < lim + 8) if (addr < lim + 8)
{ {
read_memory (addr, pword1, sizeof (*pword1)); read_memory (addr, buf, 2);
SWAP_TARGET_AND_HOST (pword1, sizeof (short)); *pword1 = extract_signed_integer (buf, 2);
return addr + 2; return addr + 2;
} }
return 0; return 0;
} }
/* Put here the code to store, into a struct frame_saved_regs, /* Put here the code to store, into a struct frame_saved_regs,