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.
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
{
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;
{
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. */
{
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);
/* 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);
}
\f
void
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;
}
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;
#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));
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());
}
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. */
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
{
}
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);
}
/* 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);
return 0;
}
}
+#endif
}
/*
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
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 *) ®isters[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.
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,
+ ®buf[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 */
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*/
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;
}
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;
}
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 */
{
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)
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
/* 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)
{
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 */
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
/* 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;
}
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. */
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
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)));
}
/*
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
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;
}
/* 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);
/* 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,
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 */
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
}
\f
/* Given a value ARG1 (offset by OFFSET bytes)
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. */
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
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);
}
\f
/* Convert C numbers into newly allocated values */
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;
}
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,