along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-#include <stdio.h>
#include "defs.h"
#include "frame.h"
#include "inferior.h"
#include "gdbcore.h"
+#include "target.h"
+
+static long
+i386_get_frame_setup PARAMS ((int));
+
+static void
+i386_follow_jump PARAMS ((void));
+
+static void
+codestream_read PARAMS ((unsigned char *, int));
+
+static void
+codestream_seek PARAMS ((int));
+
+static unsigned char
+codestream_fill PARAMS ((int));
/* helper functions for tm-i386.h */
-/* stdio style buffering to minimize calls to ptrace */
+/* Stdio style buffering was used to minimize calls to ptrace, but this
+ buffering did not take into account that the code section being accessed
+ may not be an even number of buffers long (even if the buffer is only
+ sizeof(int) long). In cases where the code section size happened to
+ be a non-integral number of buffers long, attempting to read the last
+ buffer would fail. Simply using target_read_memory and ignoring errors,
+ rather than read_memory, is not the correct solution, since legitimate
+ access errors would then be totally ignored. To properly handle this
+ situation and continue to use buffering would require that this code
+ be able to determine the minimum code section size granularity (not the
+ alignment of the section itself, since the actual failing case that
+ pointed out this problem had a section alignment of 4 but was not a
+ multiple of 4 bytes long), on a target by target basis, and then
+ adjust it's buffer size accordingly. This is messy, but potentially
+ feasible. It probably needs the bfd library's help and support. For
+ now, the buffer size is set to 1. (FIXME -fnf) */
+
+#define CODESTREAM_BUFSIZ 1 /* Was sizeof(int), see note above. */
static CORE_ADDR codestream_next_addr;
static CORE_ADDR codestream_addr;
-static unsigned char codestream_buf[sizeof (int)];
+static unsigned char codestream_buf[CODESTREAM_BUFSIZ];
static int codestream_off;
static int codestream_cnt;
static unsigned char
codestream_fill (peek_flag)
+ int peek_flag;
{
codestream_addr = codestream_next_addr;
- codestream_next_addr += sizeof (int);
+ codestream_next_addr += CODESTREAM_BUFSIZ;
codestream_off = 0;
- codestream_cnt = sizeof (int);
- read_memory (codestream_addr,
- (unsigned char *)codestream_buf,
- sizeof (int));
+ codestream_cnt = CODESTREAM_BUFSIZ;
+ read_memory (codestream_addr, (char *) codestream_buf, CODESTREAM_BUFSIZ);
if (peek_flag)
return (codestream_peek());
static void
codestream_seek (place)
+ int place;
{
- codestream_next_addr = place & -sizeof (int);
+ codestream_next_addr = place / CODESTREAM_BUFSIZ;
+ codestream_next_addr *= CODESTREAM_BUFSIZ;
codestream_cnt = 0;
codestream_fill (1);
while (codestream_tell() != place)
static void
codestream_read (buf, count)
unsigned char *buf;
+ int count;
{
unsigned char *p;
int i;
}
/* next instruction is a jump, move to target */
-static
+
+static void
i386_follow_jump ()
{
int long_delta;
* if entry sequence doesn't make sense, return -1, and leave
* codestream pointer random
*/
+
static long
i386_get_frame_setup (pc)
+ int pc;
{
unsigned char op;
static unsigned char proto2[4] = { 0x87,0x44,0x24,0x00 };
pos = codestream_tell ();
codestream_read (buf, 4);
- if (bcmp (buf, proto1, 3) == 0)
+ if (memcmp (buf, proto1, 3) == 0)
pos += 3;
- else if (bcmp (buf, proto2, 4) == 0)
+ else if (memcmp (buf, proto2, 4) == 0)
pos += 4;
codestream_seek (pos);
}
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;
+ 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);
nameless arguments. */
return -1;
- pfi = get_prev_frame_info ((fi));
+ pfi = get_prev_frame_info (fi);
if (pfi == 0)
{
/* Note: this can happen if we are looking at the frame for
return 0;
}
}
+#endif
}
/*
* next instruction will be a branch back to the start.
*/
+void
i386_frame_find_saved_regs (fip, fsrp)
struct frame_info *fip;
struct frame_saved_regs *fsrp;
{
long locals;
- unsigned char *p;
unsigned char op;
CORE_ADDR dummy_bottom;
CORE_ADDR adr;
int i;
- bzero (fsrp, sizeof *fsrp);
+ memset (fsrp, 0, sizeof *fsrp);
/* if frame is the end of a dummy, compute where the
* beginning would be
}
/* return pc of first real instruction */
+
+int
i386_skip_prologue (pc)
+ int pc;
{
unsigned char op;
int i;
return (codestream_tell ());
}
+void
i386_push_dummy_frame ()
{
CORE_ADDR sp = read_register (SP_REGNUM);
write_register (SP_REGNUM, sp);
}
+void
i386_pop_frame ()
{
FRAME frame = get_current_frame ();
set_current_frame ( create_new_frame (read_register (FP_REGNUM),
read_pc ()));
}
+
+#ifdef GET_LONGJMP_TARGET
+
+/* Figure out where the longjmp will land. Slurp the args out of the stack.
+ We expect the first arg to be a pointer to the jmp_buf structure from which
+ we extract the pc (JB_PC) that we will land at. The pc is copied into PC.
+ This routine returns true on success. */
+
+int
+get_longjmp_target(pc)
+ CORE_ADDR *pc;
+{
+ char buf[TARGET_PTR_BIT / TARGET_CHAR_BIT];
+ CORE_ADDR sp, jb_addr;
+
+ sp = read_register (SP_REGNUM);
+
+ 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);
+
+ if (target_read_memory (jb_addr + JB_PC * JB_ELEMENT_SIZE, buf,
+ TARGET_PTR_BIT / TARGET_CHAR_BIT))
+ return 0;
+
+ *pc = extract_address (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT);
+
+ return 1;
+}
+
+#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 */