1 /* Native-dependent code for Lynx running on i386's, for GDB.
2 Copyright 1988, 1989, 1991, 1992, 1993
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
27 #include <sys/ptrace.h>
28 #include "/usr/include/sys/wait.h"
30 /* these values indicate the offset of the named register in the econtext
48 /* Currently these are not being used. So set them to 0 */
53 /* this table must line up with REGISTER_NAMES in m-i386.h */
54 static unsigned int regmap
[] =
62 /* Return the address in the core dump or inferior of register REGNO.
63 BLOCKEND is the address of the econtext structure */
66 register_addr (regno
, blockend
)
69 if (regno
< 0 || regno
>= NUM_REGS
)
70 error ("Invalid register number %d.", regno
);
72 return (blockend
+ regmap
[regno
] * sizeof (long));
75 /* Fetch one register. */
78 fetch_register (regno
, offset
, bpid
)
83 char buf
[MAX_REGISTER_RAW_SIZE
];
84 char mess
[128]; /* For messages */
87 regaddr
= register_addr (regno
, offset
);
88 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof (int))
91 *(int *) &buf
[i
] = ptrace (PTRACE_PEEKTHREAD
, bpid
,
92 (PTRACE_ARG3_TYPE
) regaddr
, 0);
93 regaddr
+= sizeof (int);
96 sprintf (mess
, "reading register %s (#%d)", reg_names
[regno
], regno
);
97 perror_with_name (mess
);
100 supply_register (regno
, buf
);
103 /* Store our register values back into the inferior.
104 If REGNO is -1, do this for all registers.
105 Otherwise, REGNO specifies which register (so we can save time). */
108 store_register (regno
, offset
, bpid
)
112 unsigned int regaddr
;
114 extern char registers
[];
117 regaddr
= register_addr (regno
, offset
);
118 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof(int))
121 ptrace (PTRACE_POKEUSER
, bpid
, (PTRACE_ARG3_TYPE
) regaddr
,
122 *(int *) ®isters
[REGISTER_BYTE (regno
) + i
]);
125 sprintf (mess
, "writing register number %d(%d)", regno
, i
);
126 perror_with_name (mess
);
128 regaddr
+= sizeof(int);
132 /* return an offset for use with register_addr() */
139 unsigned int specpage_off
, offset
= (char *) &s
.ecp
- (char *) &s
;
142 specpage_off
= ptrace (PTRACE_THREADUSER
, pid
, (PTRACE_ARG3_TYPE
) 0, 0);
144 perror_with_name ("ptrace");
146 offset
= ptrace (PTRACE_PEEKTHREAD
, pid
, (PTRACE_ARG3_TYPE
) offset
, 0)
149 perror_with_name ("ptrace");
153 /* Fetch all registers, or just one, from the child process. */
156 fetch_inferior_registers (regno
)
159 unsigned int offset
= fetch_offset (inferior_pid
);
163 for (regno
= 0; regno
< NUM_REGS
; regno
++)
164 fetch_register (regno
, offset
, inferior_pid
);
167 fetch_register (regno
, offset
, inferior_pid
);
170 /* Store all registers, or just one, to the child process. */
173 store_inferior_registers (regno
)
176 unsigned int offset
= fetch_offset (inferior_pid
);
180 for (regno
= 0; regno
< NUM_REGS
; regno
++)
181 store_register (regno
, offset
, inferior_pid
);
184 store_register (regno
, offset
, inferior_pid
);
187 /* Extract the register values out of the core file and store
188 them where `read_register' will find them.
190 CORE_REG_SECT points to the register values themselves, read into memory.
191 CORE_REG_SIZE is the size of that area.
192 WHICH says which set of registers we are handling (0 = int, 2 = float
193 on machines where they are discontiguous).
194 REG_ADDR is the offset from u.u_ar0 to the register values relative to
195 core_reg_sect. This is used with old-fashioned core files to
196 locate the registers in a large upage-plus-stack ".reg" section.
197 Original upage address X is at location core_reg_sect+x+reg_addr.
201 fetch_core_registers (core_reg_sect
, core_reg_size
, which
, reg_addr
)
203 unsigned core_reg_size
;
208 unsigned int regno
, addr
;
210 for (regno
= 0; regno
< NUM_REGS
; regno
++)
212 addr
= register_addr (regno
, (char *) &s
.ec
- (char *) &s
);
213 supply_register (regno
, core_reg_sect
+ addr
);
217 /* Wait for child to do something. Return pid of child, or -1 in case
218 of error; store status through argument pointer STATUS. */
233 set_sigint_trap(); /* Causes SIGINT to be passed on to the
243 if (save_errno
== EINTR
)
245 fprintf (stderr
, "Child process unexpectedly missing: %s.\n",
246 safe_strerror (save_errno
));
247 *status
= 42; /* Claim it exited with signal 42 */
251 if (pid
!= PIDGET (inferior_pid
)) /* Some other process?!? */
254 /* thread = WIFTID (*status);*/
255 thread
= *status
>> 16;
257 /* Initial thread value can only be acquired via wait, so we have to
258 resort to this hack. */
260 if (TIDGET (inferior_pid
) == 0)
262 inferior_pid
= BUILDPID (inferior_pid
, thread
);
263 add_thread (inferior_pid
);
266 pid
= BUILDPID (pid
, thread
);
272 /* Return the PC of the caller from the call frame. Assumes the subr prologue
273 has already been executed, and the frame pointer setup. If this is the
274 outermost frame, we check to see if we are in a system call by examining the
275 previous instruction. If so, then the return PC is actually at SP+4 because
276 system calls use a different calling sequence. */
279 i386lynx_saved_pc_after_call (frame
)
280 struct frame_info
*frame
;
283 static const char call_inst
[] = {0x9a, 0, 0, 0, 0, 8, 0}; /* lcall 0x8,0x0 */
285 read_memory (frame
->pc
- 7, opcode
, 7);
286 if (memcmp (opcode
, call_inst
, 7) == 0)
287 return read_memory_integer (read_register (SP_REGNUM
) + 4, 4);
289 return read_memory_integer (read_register (SP_REGNUM
), 4);
292 /* Convert a Lynx process ID to a string. Returns the string in a static
296 i386lynx_pid_to_str (pid
)
301 sprintf (buf
, "process %d thread %d", PIDGET (pid
), TIDGET (pid
));
This page took 0.034933 seconds and 4 git commands to generate.