aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorJim Kingdon <jkingdon@engr.sgi.com>1993-07-10 01:35:53 +0000
committerJim Kingdon <jkingdon@engr.sgi.com>1993-07-10 01:35:53 +0000
commit34df79fc9d631a7cacdb2f9a9e12d5e3f8c6dd1c (patch)
tree90f72ebb31b2efb141be6ccc518e56eb37b0a701 /gdb
parentec1c752b34daada508decf3f978f0796f6008f77 (diff)
downloadgdb-34df79fc9d631a7cacdb2f9a9e12d5e3f8c6dd1c.zip
gdb-34df79fc9d631a7cacdb2f9a9e12d5e3f8c6dd1c.tar.gz
gdb-34df79fc9d631a7cacdb2f9a9e12d5e3f8c6dd1c.tar.bz2
* 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.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/a29k-tdep.c20
-rw-r--r--gdb/core.c71
-rw-r--r--gdb/h8300-tdep.c5
-rw-r--r--gdb/hppa-tdep.c7
-rw-r--r--gdb/i386-tdep.c237
-rw-r--r--gdb/i960-pinsn.c13
-rw-r--r--gdb/irix4-nat.c11
-rw-r--r--gdb/mips-nat.c9
-rw-r--r--gdb/mips-tdep.c13
-rw-r--r--gdb/remote-mips.c34
-rw-r--r--gdb/rs6000-tdep.c7
-rw-r--r--gdb/sparc-tdep.c32
-rw-r--r--gdb/valops.c11
-rw-r--r--gdb/values.c204
-rw-r--r--gdb/z8k-tdep.c7
16 files changed, 197 insertions, 489 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 809ee0c..c937f37 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
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
ins and locals from the registers array might clean things up.
diff --git a/gdb/a29k-tdep.c b/gdb/a29k-tdep.c
index e07148f..42232ce 100644
--- a/gdb/a29k-tdep.c
+++ b/gdb/a29k-tdep.c
@@ -570,10 +570,9 @@ read_register_stack_integer (memaddr, len)
CORE_ADDR memaddr;
int len;
{
- long buf;
- read_register_stack (memaddr, &buf, NULL, NULL);
- SWAP_TARGET_AND_HOST (&buf, 4);
- return buf;
+ char buf[4];
+ read_register_stack (memaddr, buf, NULL, NULL);
+ return extract_signed_integer (buf, 4);
}
/* 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)
{
- *(CORE_ADDR *)raw_buffer = fi->frame;
- /* Put it back in target byte order. */
- SWAP_TARGET_AND_HOST (raw_buffer, sizeof (CORE_ADDR));
+ store_address (raw_buffer, REGISTER_RAW_BYTES (regnum), fi->frame);
}
if (lvalp != NULL)
*lvalp = not_lval;
@@ -659,9 +656,7 @@ get_saved_register (raw_buffer, optimized, addrp, frame, regnum, lvalp)
{
if (raw_buffer != NULL)
{
- *(CORE_ADDR *)raw_buffer = fi->pc;
- /* Put it back in target byte order. */
- SWAP_TARGET_AND_HOST (raw_buffer, sizeof (CORE_ADDR));
+ store_address (raw_buffer, REGISTER_RAW_BYTES (regnum), fi->pc);
}
/* 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)
{
- *(CORE_ADDR *)raw_buffer = fi->next->saved_msp;
- /* Put it back in target byte order. */
- SWAP_TARGET_AND_HOST (raw_buffer, sizeof (CORE_ADDR));
+ store_address (raw_buffer, REGISTER_RAW_BYTES (regnum),
+ fi->next->saved_msp);
}
else
read_register_gen (MSP_REGNUM, raw_buffer);
diff --git a/gdb/core.c b/gdb/core.c
index 6916371..4c60fb7 100644
--- a/gdb/core.c
+++ b/gdb/core.c
@@ -209,79 +209,28 @@ write_memory (memaddr, myaddr, len)
/* Read an integer from debugged memory, given address and number of bytes. */
-long
+LONGEST
read_memory_integer (memaddr, len)
CORE_ADDR memaddr;
int len;
{
- char cbuf;
- short sbuf;
- int ibuf;
- long lbuf;
+ char *buf;
- if (len == sizeof (char))
- {
- read_memory (memaddr, &cbuf, 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 */
+ buf = alloca (len);
+ read_memory (memaddr, buf, len);
+ return extract_signed_integer (buf, len);
}
-
-unsigned long
+unsigned LONGEST
read_memory_unsigned_integer (memaddr, len)
CORE_ADDR memaddr;
int len;
{
- unsigned char cbuf;
- unsigned short sbuf;
- unsigned int ibuf;
- unsigned long lbuf;
+ char *buf;
- if (len == sizeof (char))
- {
- read_memory (memaddr, &cbuf, 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 */
+ buf = alloca (len);
+ read_memory (memaddr, buf, len);
+ return extract_unsigned_integer (buf, len);
}
void
diff --git a/gdb/h8300-tdep.c b/gdb/h8300-tdep.c
index f2a2d02..69a720d 100644
--- a/gdb/h8300-tdep.c
+++ b/gdb/h8300-tdep.c
@@ -180,10 +180,11 @@ NEXT_PROLOGUE_INSN (addr, lim, pword1)
CORE_ADDR lim;
short *pword1;
{
+ char buf[2];
if (addr < lim + 8)
{
- read_memory (addr, pword1, sizeof (*pword1));
- SWAP_TARGET_AND_HOST (pword1, sizeof (short));
+ read_memory (addr, buf, 2);
+ *pword1 = extract_signed_integer (buf, 2);
return addr + 2;
}
diff --git a/gdb/hppa-tdep.c b/gdb/hppa-tdep.c
index 2ae279a..10204bc 100644
--- a/gdb/hppa-tdep.c
+++ b/gdb/hppa-tdep.c
@@ -897,11 +897,12 @@ CORE_ADDR
skip_prologue(pc)
CORE_ADDR pc;
{
- int inst;
+ char buf[4];
+ unsigned long inst;
int status;
- status = target_read_memory (pc, (char *)&inst, 4);
- SWAP_TARGET_AND_HOST (&inst, sizeof (inst));
+ status = target_read_memory (pc, buf, 4);
+ inst = extract_unsigned_integer (buf, 4);
if (status != 0)
return pc;
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index da3f3cb..d6d20b0 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -23,10 +23,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gdbcore.h"
#include "target.h"
-#ifdef USE_PROC_FS /* Target dependent support for /proc */
-#include <sys/procfs.h>
-#endif
-
static long
i386_get_frame_setup PARAMS ((int));
@@ -82,9 +78,7 @@ codestream_fill (peek_flag)
codestream_next_addr += CODESTREAM_BUFSIZ;
codestream_off = 0;
codestream_cnt = CODESTREAM_BUFSIZ;
- read_memory (codestream_addr,
- (unsigned char *)codestream_buf,
- CODESTREAM_BUFSIZ);
+ read_memory (codestream_addr, (char *) codestream_buf, CODESTREAM_BUFSIZ);
if (peek_flag)
return (codestream_peek());
@@ -255,8 +249,8 @@ i386_get_frame_setup (pc)
}
else if (op == 0x81)
{
- /* subl with 32 bit immed */
- int locals;
+ char buf[4];
+ /* Maybe it is subl with 32 bit immedediate. */
codestream_get();
if (codestream_get () != 0xec)
/* Some instruction starting with 0x81 other than subl. */
@@ -264,10 +258,9 @@ i386_get_frame_setup (pc)
codestream_seek (codestream_tell () - 2);
return 0;
}
- /* subl with 32 bit immediate */
- codestream_read ((unsigned char *)&locals, 4);
- SWAP_TARGET_AND_HOST (&locals, 4);
- return (locals);
+ /* It is subl with 32 bit immediate. */
+ codestream_read ((unsigned char *)buf, 4);
+ return extract_signed_integer (buf, 4);
}
else
{
@@ -276,12 +269,11 @@ i386_get_frame_setup (pc)
}
else if (op == 0xc8)
{
+ char buf[2];
/* enter instruction: arg is 16 bit unsigned immed */
- unsigned short slocals;
- codestream_read ((unsigned char *)&slocals, 2);
- SWAP_TARGET_AND_HOST (&slocals, 2);
+ codestream_read ((unsigned char *)buf, 2);
codestream_get (); /* flush final byte of enter instruction */
- return (slocals);
+ return extract_unsigned_integer (buf, 2);
}
return (-1);
}
@@ -289,20 +281,27 @@ i386_get_frame_setup (pc)
/* Return number of args passed to a frame.
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
i386_frame_num_args (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;
unsigned char op;
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;
FRAMELESS_FUNCTION_INVOCATION (fi, frameless);
@@ -352,6 +351,7 @@ i386_frame_num_args (fi)
return 0;
}
}
+#endif
}
/*
@@ -394,7 +394,7 @@ i386_frame_find_saved_regs (fip, fsrp)
CORE_ADDR adr;
int i;
- (void) memset (fsrp, 0, sizeof *fsrp);
+ memset (fsrp, 0, sizeof *fsrp);
/* if frame is the end of a dummy, compute where the
* beginning would be
@@ -514,137 +514,6 @@ i386_pop_frame ()
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
/* Figure out where the longjmp will land. Slurp the args out of the stack.
@@ -656,25 +525,65 @@ int
get_longjmp_target(pc)
CORE_ADDR *pc;
{
+ char buf[TARGET_PTR_BIT / TARGET_CHAR_BIT];
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 */
- (char *) &jb_addr,
- sizeof(CORE_ADDR)))
+ if (target_read_memory (sp + SP_ARG0, /* Offset of first arg on stack */
+ buf,
+ TARGET_PTR_BIT / TARGET_CHAR_BIT))
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, (char *) pc,
- sizeof(CORE_ADDR)))
+ if (target_read_memory (jb_addr + JB_PC * JB_ELEMENT_SIZE, buf,
+ TARGET_PTR_BIT / TARGET_CHAR_BIT))
return 0;
- SWAP_TARGET_AND_HOST(pc, sizeof(CORE_ADDR));
+ *pc = extract_address (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT);
return 1;
}
#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 */
diff --git a/gdb/i960-pinsn.c b/gdb/i960-pinsn.c
index 65446af..941a45c 100644
--- a/gdb/i960-pinsn.c
+++ b/gdb/i960-pinsn.c
@@ -135,17 +135,16 @@ next_insn (memaddr, pword1, pword2)
CORE_ADDR memaddr;
{
int len;
- unsigned long buf[2];
+ char buf[8];
/* Read the two (potential) words of the instruction at once,
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));
- *pword1 = buf[0];
- SWAP_TARGET_AND_HOST (pword1, sizeof (long));
- *pword2 = buf[1];
- SWAP_TARGET_AND_HOST (pword2, sizeof (long));
+ read_memory (memaddr, buf, 8);
+ *pword1 = extract_unsigned_integer (buf, 4);
+ *pword2 = extract_unsigned_integer (buf + 4, 4);
/* Divide instruction set into classes based on high 4 bits of opcode*/
diff --git a/gdb/irix4-nat.c b/gdb/irix4-nat.c
index d2d4258..b7f12f0 100644
--- a/gdb/irix4-nat.c
+++ b/gdb/irix4-nat.c
@@ -133,18 +133,19 @@ fill_fpregset (fpregsetp, regno)
This routine returns true on success. */
int
-get_longjmp_target(pc)
+get_longjmp_target (pc)
CORE_ADDR *pc;
{
+ char buf[TARGET_PTR_BIT / TARGET_CHAR_BIT];
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,
- sizeof(CORE_ADDR)))
+ if (target_read_memory (jb_addr + JB_PC * JB_ELEMENT_SIZE, buf,
+ TARGET_PTR_BIT / TARGET_CHAR_BIT))
return 0;
- SWAP_TARGET_AND_HOST(pc, sizeof(CORE_ADDR));
+ *pc = extract_address (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT);
return 1;
}
diff --git a/gdb/mips-nat.c b/gdb/mips-nat.c
index bcdec87..5e34f92 100644
--- a/gdb/mips-nat.c
+++ b/gdb/mips-nat.c
@@ -149,14 +149,15 @@ 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);
+ jb_addr = read_register (A0_REGNUM);
- if (target_read_memory(jb_addr + JB_PC * JB_ELEMENT_SIZE, pc,
- sizeof(CORE_ADDR)))
+ if (target_read_memory (jb_addr + JB_PC * JB_ELEMENT_SIZE, buf,
+ TARGET_PTR_BIT / TARGET_CHAR_BIT))
return 0;
- SWAP_TARGET_AND_HOST(pc, sizeof(CORE_ADDR));
+ *pc = extract_address (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT);
return 1;
}
diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index 8da1f8a..136c0c1 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -178,12 +178,14 @@ heuristic_proc_desc(start_pc, limit_pc, next_frame)
restart:
frame_size = 0;
for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += 4) {
+ char buf[4];
unsigned long word;
int status;
- status = read_memory_nobpt (cur_pc, (char *)&word, 4);
- if (status) memory_error (status, cur_pc);
- SWAP_TARGET_AND_HOST (&word, sizeof (word));
+ status = read_memory_nobpt (cur_pc, buf, 4);
+ if (status) memory_error (status, cur_pc);
+ word = extract_unsigned_integer (buf, 4);
+
if ((word & 0xFFFF0000) == 0x27bd0000) /* addiu $sp,$sp,-i */
frame_size += (-word) & 0xFFFF;
else if ((word & 0xFFFF0000) == 0x23bd0000) /* addu $sp,$sp,-i */
@@ -636,8 +638,9 @@ mips_print_register (regnum, all)
{
long val;
- bcopy (raw_buffer, &val, sizeof (long));
- SWAP_TARGET_AND_HOST ((char *)&val, sizeof (long));
+ val = extract_signed_integer (raw_buffer,
+ REGISTER_RAW_SIZE (regnum));
+
if (val == 0)
printf_filtered ("0");
else if (all)
diff --git a/gdb/remote-mips.c b/gdb/remote-mips.c
index 23cd5c4..ead760d 100644
--- a/gdb/remote-mips.c
+++ b/gdb/remote-mips.c
@@ -1061,10 +1061,14 @@ mips_fetch_registers (regno)
if (err)
error ("Can't read register %d: %s", regno, safe_strerror (errno));
- /* We got the number the register holds, but gdb expects to see a
- value in the target byte ordering. */
- SWAP_TARGET_AND_HOST (&val, sizeof (REGISTER_TYPE));
- supply_register (regno, (char *) &val);
+ {
+ char buf[MAX_REGISTER_RAW_SIZE];
+
+ /* We got the number the register holds, but gdb expects to see a
+ value in the target byte ordering. */
+ store_unsigned_integer (buf, REGISTER_RAW_SIZE (regno), val);
+ supply_register (regno, buf);
+ }
}
/* 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. */
register int count = (((memaddr + len) - addr) + 3) / 4;
/* Allocate buffer of that many longwords. */
- register unsigned int *buffer = (unsigned int *) alloca (count * 4);
+ register char *buffer = alloca (count * 4);
if (write)
{
@@ -1165,14 +1169,15 @@ mips_xfer_memory (memaddr, myaddr, len, write, ignore)
if (addr != memaddr || len < 4)
{
/* Need part of initial word -- fetch it. */
- buffer[0] = mips_fetch_word (addr);
- SWAP_TARGET_AND_HOST (buffer, 4);
+ store_unsigned_integer (&buffer[0], 4, mips_fetch_word (addr));
}
- if (count > 1) /* FIXME, avoid if even boundary */
+ if (count > 1)
{
- buffer[count - 1] = mips_fetch_word (addr + (count - 1) * 4);
- SWAP_TARGET_AND_HOST (buffer + (count - 1) * 4, 4);
+ /* Need part of last word -- fetch it. FIXME: we do this even
+ 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 */
@@ -1183,8 +1188,8 @@ mips_xfer_memory (memaddr, myaddr, len, write, ignore)
for (i = 0; i < count; i++, addr += 4)
{
- SWAP_TARGET_AND_HOST (buffer + i, 4);
- mips_store_word (addr, buffer[i]);
+ mips_store_word (addr, extract_unsigned_integer (&buffer[i*4], 4));
+ /* FIXME: Do we want a QUIT here? */
}
}
else
@@ -1192,13 +1197,12 @@ mips_xfer_memory (memaddr, myaddr, len, write, ignore)
/* Read all the longwords */
for (i = 0; i < count; i++, addr += 4)
{
- buffer[i] = mips_fetch_word (addr);
- SWAP_TARGET_AND_HOST (buffer + i, 4);
+ store_unsigned_integer (&buffer[i*4], 4, mips_fetch_word (addr));
QUIT;
}
/* Copy appropriate bytes out of the buffer. */
- memcpy (myaddr, (char *) buffer + (memaddr & (sizeof (int) - 1)), len);
+ memcpy (myaddr, buffer + (memaddr & 3), len);
}
return len;
}
diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c
index e783c1e..e8d9af8 100644
--- a/gdb/rs6000-tdep.c
+++ b/gdb/rs6000-tdep.c
@@ -187,12 +187,13 @@ single_step (signal)
skip_prologue (pc)
CORE_ADDR pc;
{
+ char buf[4];
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. */
- SWAP_TARGET_AND_HOST (&op, sizeof (op));
+ op = extract_unsigned_integer (buf, 4);
/* Assume that subsequent fetches can fail with low probability. */
diff --git a/gdb/sparc-tdep.c b/gdb/sparc-tdep.c
index 5bfd263..62e8a18 100644
--- a/gdb/sparc-tdep.c
+++ b/gdb/sparc-tdep.c
@@ -147,8 +147,7 @@ sparc_frame_chain (thisframe)
err = target_read_memory (addr, (char *) &retval, sizeof (REGISTER_TYPE));
if (err)
return 0;
- SWAP_TARGET_AND_HOST (&retval, sizeof (retval));
- return retval;
+ return extract_address (&retval, sizeof (retval));
}
CORE_ADDR
@@ -167,22 +166,12 @@ frame_saved_pc (frame)
FRAME frame;
{
REGISTER_TYPE retval;
- CORE_ADDR addr,prev_pc;
-
- if (get_current_frame () == frame) /* FIXME, debug check. Remove >=gdb-4.6 */
- {
- if (read_register (SP_REGNUM) != frame->bottom) abort();
- }
+ CORE_ADDR addr;
addr = (frame->bottom + FRAME_SAVED_I0 +
REGISTER_RAW_SIZE (I7_REGNUM) * (I7_REGNUM - I0_REGNUM));
read_memory (addr, (char *) &retval, sizeof (REGISTER_TYPE));
- SWAP_TARGET_AND_HOST (&retval, sizeof (retval));
-
- /* CORE_ADDR isn't always the same size as REGISTER_TYPE, so convert. */
-
- prev_pc = (CORE_ADDR) retval;
- return PC_ADJUST (prev_pc);
+ return PC_ADJUST (extract_address (&retval, sizeof (REGISTER_TYPE)));
}
/*
@@ -582,11 +571,12 @@ CORE_ADDR
sparc_pc_adjust(pc)
CORE_ADDR pc;
{
- long insn;
+ unsigned long insn;
+ char buf[4];
int err;
- err = target_read_memory (pc + 8, (char *)&insn, sizeof(long));
- SWAP_TARGET_AND_HOST (&insn, sizeof(long));
+ err = target_read_memory (pc + 8, buf, sizeof(long));
+ insn = extract_unsigned_integer (buf, 4);
if ((err == 0) && (insn & 0xfffffe00) == 0)
return pc+12;
else
@@ -769,14 +759,16 @@ get_longjmp_target(pc)
CORE_ADDR *pc;
{
CORE_ADDR jb_addr;
+#define LONGJMP_TARGET_SIZE 4
+ char buf[LONGJMP_TARGET_SIZE];
jb_addr = read_register(O0_REGNUM);
- if (target_read_memory(jb_addr + JB_PC * JB_ELEMENT_SIZE, (char *) pc,
- sizeof(CORE_ADDR)))
+ if (target_read_memory(jb_addr + JB_PC * JB_ELEMENT_SIZE, buf,
+ LONGJMP_TARGET_SIZE))
return 0;
- SWAP_TARGET_AND_HOST(pc, sizeof(CORE_ADDR));
+ *pc = extract_address (buf, LONGJMP_TARGET_SIZE);
return 1;
}
diff --git a/gdb/valops.c b/gdb/valops.c
index f7775b1..24eefca 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -627,13 +627,14 @@ value_ind (arg1)
/* Push one word (the size of object that a register holds). */
CORE_ADDR
-push_word (sp, buffer)
+push_word (sp, word)
CORE_ADDR sp;
- REGISTER_TYPE buffer;
+ REGISTER_TYPE word;
{
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
sp -= 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
and the number of arguments for it. */
- memcpy (dummy1, dummy, sizeof dummy);
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
real_pc = FIX_CALL_DUMMY (dummy1, start_sp, funaddr, nargs, args,
diff --git a/gdb/values.c b/gdb/values.c
index 76c2429..60c3c08 100644
--- a/gdb/values.c
+++ b/gdb/values.c
@@ -605,139 +605,22 @@ unpack_long (type, valaddr)
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))
- {
- unsigned char retval = * (unsigned char *) valaddr;
- /* SWAP_TARGET_AND_HOST (&retval, sizeof (unsigned char)); */
- return retval;
- }
-
- if (len == sizeof (short))
- {
- unsigned short retval;
- 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.");
- }
+ return extract_unsigned_integer (valaddr, len);
}
- else if (code == TYPE_CODE_INT)
+ else if (code == TYPE_CODE_INT || code == TYPE_CODE_CHAR)
{
- 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.");
- }
+ return extract_signed_integer (valaddr, len);
}
/* Assume a CORE_ADDR can fit in a LONGEST (for now). Not sure
whether we want this to be true eventually. */
else if (code == TYPE_CODE_PTR || code == TYPE_CODE_REF)
{
- if (len == sizeof(long))
- {
- 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
+ return extract_address (valaddr, len);
}
else if (code == TYPE_CODE_MEMBER)
error ("not implemented: member types in unpack_long");
- else if (code == TYPE_CODE_CHAR)
- return *(unsigned char *)valaddr;
error ("Value not integer or pointer.");
return 0; /* For lint -- never reached */
@@ -816,34 +699,9 @@ unpack_pointer (type, valaddr)
struct type *type;
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
whether we want this to be true eventually. */
return unpack_long (type, valaddr);
-#endif
}
/* 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 lsbcount;
- memcpy (&val, valaddr + bitpos / 8, sizeof (val));
- SWAP_TARGET_AND_HOST (&val, sizeof (val));
+ val = extract_unsigned_integer (valaddr + bitpos / 8, sizeof (val));
/* Extract bits. See comment above. */
@@ -1360,9 +1217,8 @@ modify_field (addr, fieldval, bitpos, bitsize)
if (bitsize < (8 * sizeof (fieldval))
&& 0 != (fieldval & ~((1<<bitsize)-1)))
error ("Value %d does not fit in %d bits.", fieldval, bitsize);
-
- memcpy (&oword, addr, sizeof oword);
- SWAP_TARGET_AND_HOST (&oword, sizeof oword); /* To host format */
+
+ oword = extract_signed_integer (addr, sizeof oword);
/* Shifting for bit field depends on endianness of the target machine. */
#if BITS_BIG_ENDIAN
@@ -1376,8 +1232,7 @@ modify_field (addr, fieldval, bitpos, bitsize)
oword &= ~((-1) << bitpos);
oword |= fieldval << bitpos;
- SWAP_TARGET_AND_HOST (&oword, sizeof oword); /* To target format */
- memcpy (addr, &oword, sizeof oword);
+ store_signed_integer (addr, sizeof oword, oword);
}
/* 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 int len = TYPE_LENGTH (type);
- /* FIXME, we assume that pointers have the same form and byte order as
- 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)
+ switch (code)
{
- if (len == sizeof (char))
- * (char *) VALUE_CONTENTS_RAW (val) = num;
- else if (len == sizeof (short))
- * (short *) VALUE_CONTENTS_RAW (val) = num;
- else if (len == sizeof (int))
- * (int *) VALUE_CONTENTS_RAW (val) = num;
- else if (len == sizeof (long))
- * (long *) VALUE_CONTENTS_RAW (val) = num;
- else if (len == sizeof (LONGEST))
- * (LONGEST *) VALUE_CONTENTS_RAW (val) = num;
- else
- error ("Integer type encountered with unexpected data length.");
+ case TYPE_CODE_INT:
+ case TYPE_CODE_CHAR:
+ case TYPE_CODE_ENUM:
+ case TYPE_CODE_BOOL:
+ store_signed_integer (VALUE_CONTENTS_RAW (val), len, num);
+ break;
+
+ case TYPE_CODE_REF:
+ case TYPE_CODE_PTR:
+ /* This assumes that all pointers of a given length
+ have the same form. */
+ store_address (VALUE_CONTENTS_RAW (val), len, (CORE_ADDR) num);
+ break;
+
+ default:
+ error ("Unexpected type encountered for integer constant.");
}
- else
- 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;
}
diff --git a/gdb/z8k-tdep.c b/gdb/z8k-tdep.c
index 2021a2e..6289ac6 100644
--- a/gdb/z8k-tdep.c
+++ b/gdb/z8k-tdep.c
@@ -233,16 +233,15 @@ NEXT_PROLOGUE_INSN (addr, lim, pword1)
CORE_ADDR lim;
short *pword1;
{
+ char buf[2];
if (addr < lim + 8)
{
- read_memory (addr, pword1, sizeof (*pword1));
- SWAP_TARGET_AND_HOST (pword1, sizeof (short));
+ read_memory (addr, buf, 2);
+ *pword1 = extract_signed_integer (buf, 2);
return addr + 2;
}
-
return 0;
-
}
/* Put here the code to store, into a struct frame_saved_regs,