From 9a13e99e206b8c400f1ea65869f90b8500731c4c Mon Sep 17 00:00:00 2001 From: Stu Grossman Date: Fri, 12 Nov 1993 18:59:43 +0000 Subject: [PATCH] * coff-solib.c (coff_solib_add): Cast result of alloca(). * m68k-tdep.c (m68k_saved_pc_after_call): Get rid of GDB_TARGET_IS_SUN3. Use more general SYSCALL_TRAP macro. * config/m68k/m68klynx.mh (NATDEPFILES): Remove exec.o (it's already in TDEPFILES). * config/m68k/tm-m68k.h (SAVED_PC_AFTER_CALL): Use m68k_saved_pc_after_call. * Remove all Sun3 specific stuff. * (FIX_CALL_DUMMY): Cast arg to bfd_putb32 to unsigned char *. * config/m68k/tm-m68klynx.h: Define SYSCALL_TRAP as trap #10. Disable REMOTE_BREAKPOINT mechanism. * config/m68k/tm-sun3.h: Get rid of GDB_TARGET_IS_SUN3. * Protect from multiple includion. * Move Sun3 specific stuff from tm-m68k.h to here. * Define SYSCALL_TRAP as trap #0. * Remove def of SAVED_PC_AFTER_CALL (now in tm-m68k.h). * gdbserver/low-lynx.c: Redo all register store/fetch stuff to make it portable for 386 and 68k. --- gdb/ChangeLog | 21 ++++++ gdb/coff-solib.c | 2 +- gdb/config/m68k/m68klynx.mh | 2 +- gdb/config/m68k/tm-m68k.h | 45 ++++++------ gdb/config/m68k/tm-m68klynx.h | 9 +++ gdb/config/m68k/tm-sun3.h | 39 ++++++---- gdb/gdbserver/low-lynx.c | 133 ++++++++++++++++++++++++---------- 7 files changed, 176 insertions(+), 75 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 6b733ad2218..1c857f8c324 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,24 @@ +Fri Nov 12 10:39:31 1993 Stu Grossman (grossman at cygnus.com) + + * coff-solib.c (coff_solib_add): Cast result of alloca(). + * m68k-tdep.c (m68k_saved_pc_after_call): Get rid of + GDB_TARGET_IS_SUN3. Use more general SYSCALL_TRAP macro. + * config/m68k/m68klynx.mh (NATDEPFILES): Remove exec.o (it's + already in TDEPFILES). + * config/m68k/tm-m68k.h (SAVED_PC_AFTER_CALL): Use + m68k_saved_pc_after_call. + * Remove all Sun3 specific stuff. + * (FIX_CALL_DUMMY): Cast arg to bfd_putb32 to unsigned char *. + * config/m68k/tm-m68klynx.h: Define SYSCALL_TRAP as trap #10. + Disable REMOTE_BREAKPOINT mechanism. + * config/m68k/tm-sun3.h: Get rid of GDB_TARGET_IS_SUN3. + * Protect from multiple includion. + * Move Sun3 specific stuff from tm-m68k.h to here. + * Define SYSCALL_TRAP as trap #0. + * Remove def of SAVED_PC_AFTER_CALL (now in tm-m68k.h). + * gdbserver/low-lynx.c: Redo all register store/fetch stuff to + make it portable for 386 and 68k. + Fri Nov 12 09:53:26 1993 Jim Kingdon (kingdon@lioth.cygnus.com) * mips-tdep.c (init_extra_frame_info): Check to see whether the diff --git a/gdb/coff-solib.c b/gdb/coff-solib.c index 01ffc9c6347..697fdac2d2a 100644 --- a/gdb/coff-solib.c +++ b/gdb/coff-solib.c @@ -67,7 +67,7 @@ coff_solib_add (arg_string, from_tty, target) libsize = bfd_section_size (exec_bfd, libsect); - lib = alloca (libsize); + lib = (unsigned char *) alloca (libsize); bfd_get_section_contents (exec_bfd, libsect, lib, 0, libsize); diff --git a/gdb/config/m68k/m68klynx.mh b/gdb/config/m68k/m68klynx.mh index 4d80b0b38c1..4f2922c2a64 100644 --- a/gdb/config/m68k/m68klynx.mh +++ b/gdb/config/m68k/m68klynx.mh @@ -2,7 +2,7 @@ XM_FILE= xm-m68klynx.h XDEPFILES= NAT_FILE= nm-m68klynx.h -NATDEPFILES= exec.o infptrace.o inftarg.o fork-child.o corelow.o m68kly-nat.o +NATDEPFILES= fork-child.o infptrace.o inftarg.o corelow.o m68kly-nat.o REGEX=regex.o REGEX1=regex.o GDBSERVER_LIBS= -lbsd diff --git a/gdb/config/m68k/tm-m68k.h b/gdb/config/m68k/tm-m68k.h index 0f4a1653c35..7a8c52a33a6 100644 --- a/gdb/config/m68k/tm-m68k.h +++ b/gdb/config/m68k/tm-m68k.h @@ -42,8 +42,14 @@ extern CORE_ADDR m68k_skip_prologue PARAMS ((CORE_ADDR ip)); the new frame is not set up until the new function executes some instructions. */ +#ifdef __STDC__ +struct frame_info; +#endif + +extern CORE_ADDR m68k_saved_pc_after_call PARAMS ((struct frame_info *)); + #define SAVED_PC_AFTER_CALL(frame) \ -read_memory_integer (read_register (SP_REGNUM), 4) + m68k_saved_pc_after_call(frame) /* Stack grows downward. */ @@ -88,29 +94,22 @@ read_memory_integer (read_register (SP_REGNUM), 4) #define REGISTER_TYPE long -#define REGISTER_BYTES_SUN3 (16*4 + 8 + 8*12 + 3*4 + 4) #define REGISTER_BYTES_FP (16*4 + 8 + 8*12 + 3*4) #define REGISTER_BYTES_NOFP (16*4 + 8) -#if defined (GDB_TARGET_IS_SUN3) - /* Sun3 status includes fpflags, which shows whether the FPU has been used - by the process, and whether the FPU was done with an instruction or - was interrupted in the middle of a long instruction. See - . */ - /* a&d, pc,sr, fp, fpstat, fpflags */ -# define NUM_REGS 31 -# define REGISTER_BYTES (16*4 + 8 + 8*12 + 3*4 + 4) -# define REGISTER_BYTES_OK(b) \ - ((b) == REGISTER_BYTES_SUN3 \ - || (b) == REGISTER_BYTES_FP \ - || (b) == REGISTER_BYTES_NOFP) -#else /* Not sun3. */ -# define NUM_REGS 29 -# define REGISTER_BYTES_OK(b) \ - ((b) == REGISTER_BYTES_FP \ - || (b) == REGISTER_BYTES_NOFP) -# define REGISTER_BYTES (16*4 + 8 + 8*12 + 3*4) -#endif /* Not sun3. */ +#ifndef NUM_REGS +#define NUM_REGS 29 +#endif + +#ifndef REGISTER_BYTES_OK +#define REGISTER_BYTES_OK(b) \ + ((b) == REGISTER_BYTES_FP \ + || (b) == REGISTER_BYTES_NOFP) +#endif + +#ifndef REGISTER_BYTES +#define REGISTER_BYTES (16*4 + 8 + 8*12 + 3*4) +#endif /* Index within `registers' of the first byte of the space for register N. */ @@ -360,8 +359,8 @@ extern const struct ext_format ext_format_68881; We use the BFD routines to store a big-endian value of known size. */ #define FIX_CALL_DUMMY(dummyname, pc, fun, nargs, args, type, gcc_p) \ -{ bfd_putb32 (fun, (char *) dummyname + CALL_DUMMY_START_OFFSET + 2); \ - bfd_putb32 (nargs*4, (char *) dummyname + CALL_DUMMY_START_OFFSET + 8); } +{ bfd_putb32 (fun, (unsigned char *) dummyname + CALL_DUMMY_START_OFFSET + 2); \ + bfd_putb32 (nargs*4, (unsigned char *) dummyname + CALL_DUMMY_START_OFFSET + 8); } /* Push an empty stack frame, to record the current PC, etc. */ diff --git a/gdb/config/m68k/tm-m68klynx.h b/gdb/config/m68k/tm-m68klynx.h index 4fc71a53274..a13c4b6a453 100644 --- a/gdb/config/m68k/tm-m68klynx.h +++ b/gdb/config/m68k/tm-m68klynx.h @@ -20,10 +20,19 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef TM_M68KLYNX_H #define TM_M68KLYNX_H +/* If PC-2 contains this instruction, then we know what we are in a system + call stub, and the return PC is is at SP+4, instead of SP. */ + +#define SYSCALL_TRAP 0x4e4a /* trap #10 */ +#define SYSCALL_TRAP_OFFSET 2 /* PC is after trap instruction */ + /* Use the generic 68k definitions. */ #include "m68k/tm-m68k.h" +/* Disable dumbshit alternate breakpoint mechanism needed by 68k stub. */ +#undef REMOTE_BREAKPOINT + /* Include COFF shared library support. */ #include "coff-solib.h" diff --git a/gdb/config/m68k/tm-sun3.h b/gdb/config/m68k/tm-sun3.h index 716b1947910..87ddc9eb0f3 100644 --- a/gdb/config/m68k/tm-sun3.h +++ b/gdb/config/m68k/tm-sun3.h @@ -17,10 +17,29 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* Let native-versus-cross support code know we are targeting sun3, - and modify registers to include sun3 fpustate register. */ +#ifndef TM_SUN3_H +#define TM_SUN3_H -#define GDB_TARGET_IS_SUN3 1 +/* Sun3 status includes fpflags, which shows whether the FPU has been used + by the process, and whether the FPU was done with an instruction or + was interrupted in the middle of a long instruction. See + . */ +/* a&d, pc,sr, fp, fpstat, fpflags */ + +#define REGISTER_BYTES (16*4 + 8 + 8*12 + 3*4 + 4) + +#define NUM_REGS 31 + +#define REGISTER_BYTES_OK(b) \ + ((b) == REGISTER_BYTES \ + || (b) == REGISTER_BYTES_FP \ + || (b) == REGISTER_BYTES_NOFP) + +/* If PC contains this instruction, then we know what we are in a system + call stub, and the return PC is is at SP+4, instead of SP. */ + +#define SYSCALL_TRAP 0x4e40 /* trap #0 */ +#define SYSCALL_TRAP_OFFSET 0 /* PC points at trap instruction */ #include "m68k/tm-m68k.h" @@ -53,16 +72,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #define GET_LONGJMP_TARGET(ADDR) get_longjmp_target(ADDR) -#undef SAVED_PC_AFTER_CALL - -#ifdef __STDC__ -struct frame_info; -#endif - -extern CORE_ADDR m68k_saved_pc_after_call PARAMS ((struct frame_info *)); - -#define SAVED_PC_AFTER_CALL(frame) \ - m68k_saved_pc_after_call(frame) +/* If sun3 pcc says that a parameter is a short, it's a short. */ +#define BELIEVE_PCC_PROMOTION_TYPE /* Sun /bin/cc gets this right as of SunOS 4.1.x. We need to define BELIEVE_PCC_PROMOTION to get this right now that the code which @@ -92,3 +103,5 @@ extern CORE_ADDR m68k_saved_pc_after_call PARAMS ((struct frame_info *)); #undef SIG_PC_FP_OFFSET #define SIG_PC_FP_OFFSET 324 #define SIG_SP_FP_OFFSET 332 + +#endif /* TM_SUN3_H */ diff --git a/gdb/gdbserver/low-lynx.c b/gdb/gdbserver/low-lynx.c index ae4955c8264..161e86d1730 100644 --- a/gdb/gdbserver/low-lynx.c +++ b/gdb/gdbserver/low-lynx.c @@ -152,53 +152,100 @@ myresume (step, signal) #undef offsetof #define offsetof(TYPE, MEMBER) ((unsigned long) &((TYPE *)0)->MEMBER) -static struct econtext * -lynx_registers_addr() -{ - st_t *stblock; - int ecpoff = offsetof(st_t, ecp); - CORE_ADDR ecp; - - errno = 0; - stblock = (st_t *) ptrace (PTRACE_THREADUSER, inferior_pid, - (PTRACE_ARG3_TYPE)0, 0); - if (errno) - perror_with_name ("PTRACE_THREADUSER"); - - ecp = (CORE_ADDR) ptrace (PTRACE_PEEKTHREAD, inferior_pid, - (PTRACE_ARG3_TYPE)ecpoff, 0); - ecp -= (CORE_ADDR)stblock; - if (errno) - perror_with_name ("lynx_registers_addr(PTRACE_PEEKTHREAD)"); - - return (struct econtext *)ecp; -} +/* Mapping between GDB register #s and offsets into econtext. Must be + consistent with REGISTER_NAMES macro in various tmXXX.h files. */ -static struct econtext *ecp; +#define X(ENTRY)(offsetof(struct econtext, ENTRY)) -/* Mapping between GDB register #s and offsets into econtext. Must be - consistent with REGISTER_NAMES macro in tm-i386v.h. */ +#ifdef I386 +/* Mappings from tm-i386v.h */ -#define X(ENTRY)(offsetof(struct econtext, ENTRY) / 4) -static int regmap[] = { +static int regmap[] = +{ X(eax), X(ecx), X(edx), X(ebx), - X(esp), - X(ebp), + X(esp), /* sp */ + X(ebp), /* fp */ X(esi), X(edi), - X(eip), + X(eip), /* pc */ X(flags), /* ps */ X(cs), X(ss), X(ds), X(es), X(ecode), /* Lynx doesn't give us either fs or gs, so */ - X(fault) /* we just substitute these two in the hopes + X(fault), /* we just substitute these two in the hopes that they are useful. */ - }; +}; +#endif + +#ifdef M68K +/* Mappings from tm-m68k.h */ + +static int regmap[] = +{ + X(regs[0]), /* d0 */ + X(regs[1]), /* d1 */ + X(regs[2]), /* d2 */ + X(regs[3]), /* d3 */ + X(regs[4]), /* d4 */ + X(regs[5]), /* d5 */ + X(regs[6]), /* d6 */ + X(regs[7]), /* d7 */ + X(regs[8]), /* a0 */ + X(regs[9]), /* a1 */ + X(regs[10]), /* a2 */ + X(regs[11]), /* a3 */ + X(regs[12]), /* a4 */ + X(regs[13]), /* a5 */ + X(regs[14]), /* fp */ + 0, /* sp */ + X(status), /* ps */ + X(pc), + + X(fregs[0*3]), /* fp0 */ + X(fregs[1*3]), /* fp1 */ + X(fregs[2*3]), /* fp2 */ + X(fregs[3*3]), /* fp3 */ + X(fregs[4*3]), /* fp4 */ + X(fregs[5*3]), /* fp5 */ + X(fregs[6*3]), /* fp6 */ + X(fregs[7*3]), /* fp7 */ + + X(fcregs[0]), /* fpcontrol */ + X(fcregs[1]), /* fpstatus */ + X(fcregs[2]), /* fpiaddr */ + X(ssw), /* fpcode */ + X(fault), /* fpflags */ +}; +#endif + +/* Return the offset relative to the start of the per-thread data to the + saved context block. */ + +static unsigned long +lynx_registers_addr() +{ + CORE_ADDR stblock; + int ecpoff = offsetof(st_t, ecp); + CORE_ADDR ecp; + + errno = 0; + stblock = (CORE_ADDR) ptrace (PTRACE_THREADUSER, inferior_pid, + (PTRACE_ARG3_TYPE)0, 0); + if (errno) + perror_with_name ("PTRACE_THREADUSER"); + + ecp = (CORE_ADDR) ptrace (PTRACE_PEEKTHREAD, inferior_pid, + (PTRACE_ARG3_TYPE)ecpoff, 0); + if (errno) + perror_with_name ("lynx_registers_addr(PTRACE_PEEKTHREAD)"); + + return ecp - stblock; +} /* Fetch one or more registers from the inferior. REGNO == -1 to get them all. We actually fetch more than requested, when convenient, @@ -210,15 +257,21 @@ fetch_inferior_registers (ignored) { int regno; unsigned long reg; - struct econtext *ecp; + unsigned long ecp; ecp = lynx_registers_addr(); for (regno = 0; regno < NUM_REGS; regno++) { + int ptrace_fun = PTRACE_PEEKTHREAD; + +#ifdef PTRACE_PEEKUSP + ptrace_fun = regno == SP_REGNUM ? PTRACE_PEEKUSP : PTRACE_PEEKTHREAD; +#endif + errno = 0; - reg = ptrace (PTRACE_PEEKTHREAD, inferior_pid, - (PTRACE_ARG3_TYPE) (&ecp->fault + regmap[regno]), 0); + reg = ptrace (ptrace_fun, inferior_pid, + (PTRACE_ARG3_TYPE) (ecp + regmap[regno]), 0); if (errno) perror_with_name ("fetch_inferior_registers(PTRACE_PEEKTHREAD)"); @@ -236,17 +289,23 @@ store_inferior_registers (ignored) { int regno; unsigned long reg; - struct econtext *ecp; + unsigned long ecp; ecp = lynx_registers_addr(); for (regno = 0; regno < NUM_REGS; regno++) { + int ptrace_fun = PTRACE_POKEUSER; + +#ifdef PTRACE_POKEUSP + ptrace_fun = regno == SP_REGNUM ? PTRACE_POKEUSP : PTRACE_POKEUSER; +#endif + reg = *(unsigned long *)®isters[REGISTER_BYTE (regno)]; errno = 0; - ptrace (PTRACE_POKEUSER, inferior_pid, - (PTRACE_ARG3_TYPE) (&ecp->fault + regmap[regno]), reg); + ptrace (ptrace_fun, inferior_pid, + (PTRACE_ARG3_TYPE) (ecp + regmap[regno]), reg); if (errno) perror_with_name ("PTRACE_POKEUSER"); } -- 2.30.2